<!--

/*
** Copyright (c) 2018 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/

-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>GLSL texture offset with non-constant offset test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/glsl-conformance-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script id="fshaderTextureOffset" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;
uniform sampler2D u_sampler;
uniform vec2 u_texCoord;

void main() {
    ivec2 offset = ivec2(0);
    my_FragColor = textureOffset(u_sampler, u_texCoord, offset);
}
</script>
<script id="fshaderTextureProjOffset" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;
uniform sampler2D u_sampler;
uniform vec4 u_texCoord;

void main() {
    ivec2 offset = ivec2(0);
    my_FragColor = textureProjOffset(u_sampler, u_texCoord, offset);
}
</script>
<script id="fshaderTextureLodOffset" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;
uniform sampler2D u_sampler;
uniform vec2 u_texCoord;
uniform float u_lod;

void main() {
    ivec2 offset = ivec2(0);
    my_FragColor = textureLodOffset(u_sampler, u_texCoord, u_lod, offset);
}
</script>
<script id="fshaderTextureProjLodOffset" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;
uniform sampler2D u_sampler;
uniform vec4 u_texCoord;
uniform float u_lod;

void main() {
    ivec2 offset = ivec2(0);
    my_FragColor = textureProjLodOffset(u_sampler, u_texCoord, u_lod, offset);
}
</script>
<script id="fshaderTextureGradOffset" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;
uniform sampler2D u_sampler;
uniform vec2 u_texCoord;
uniform vec2 u_dPdx;
uniform vec2 u_dPdy;

void main() {
    ivec2 offset = ivec2(0);
    my_FragColor = textureGradOffset(u_sampler, u_texCoord, u_dPdx, u_dPdy, offset);
}
</script>
<script id="fshaderTextureProjGradOffset" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;
uniform sampler2D u_sampler;
uniform vec4 u_texCoord;
uniform vec2 u_dPdx;
uniform vec2 u_dPdy;

void main() {
    ivec2 offset = ivec2(0);
    my_FragColor = textureProjGradOffset(u_sampler, u_texCoord, u_dPdx, u_dPdy, offset);
}
</script>
<script id="fshaderTexelFetchOffset" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;
uniform sampler2D u_sampler;
uniform vec2 u_texCoord;
uniform vec2 u_lod;

void main() {
    ivec2 offset = ivec2(0);
    my_FragColor = texelFetchOffset(u_sampler, ivec2(u_texCoord), int(u_lod), offset);
}
</script>
<script type="application/javascript">
"use strict";
description("A non-constant offset is not valid in texture offset functions.");

var wtu = WebGLTestUtils;

var shaderTextureOffsetSrc = wtu.getScript('fshaderTextureOffset');
var shaderTextureLodOffsetSrc = wtu.getScript('fshaderTextureLodOffset');
var shaderTextureGradOffsetSrc = wtu.getScript('fshaderTextureGradOffset');
var shaderTextureProjOffsetSrc = wtu.getScript('fshaderTextureProjOffset');
var shaderTextureProjLodOffsetSrc = wtu.getScript('fshaderTextureProjLodOffset');
var shaderTextureProjGradOffsetSrc = wtu.getScript('fshaderTextureProjGradOffset');
var shaderTexelFetchOffsetSrc = wtu.getScript('fshaderTexelFetchOffset');

var gl = wtu.create3DContext(undefined, undefined, 2);

if (!gl) {
    testFailed("Unable to initialize WebGL 2.0 context.");
} else {
    GLSLConformanceTester.runTests([
    {
        fShaderSource: shaderTextureOffsetSrc,
        fShaderSuccess: false,
        passMsg: 'textureOffset with non-constant offset is invalid'
    },
    {
        fShaderSource: shaderTextureLodOffsetSrc,
        fShaderSuccess: false,
        passMsg: 'textureLodOffset with non-constant offset is invalid'
    },
    {
        fShaderSource: shaderTextureGradOffsetSrc,
        fShaderSuccess: false,
        passMsg: 'textureGradOffset with non-constant offset is invalid'
    },
    {
        fShaderSource: shaderTextureProjOffsetSrc,
        fShaderSuccess: false,
        passMsg: 'textureProjOffset with non-constant offset is invalid'
    },
    {
        fShaderSource: shaderTextureProjLodOffsetSrc,
        fShaderSuccess: false,
         passMsg: 'textureProjLodOffset with non-constant offset is invalid'
    },
    {
        fShaderSource: shaderTextureProjGradOffsetSrc,
        fShaderSuccess: false,
        passMsg: 'textureProjGradOffset with non-constant offset is invalid'
    },
    {
        fShaderSource: shaderTexelFetchOffsetSrc,
        fShaderSuccess: false,
        passMsg: 'texelFetchOffset with non-constant offset is invalid'
    }
    ], 2);
}
</script>
</body>
</html>
