summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/glsl3/texture-offset-out-of-range.html
blob: 99e698fb6ef232bbb14059927ee470b30196bb84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>GLSL out-of-range texture 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="vshaderInvalidOffset" type="x-shader/x-vertex">#version 300 es
in vec4 a_position;
in vec2 a_in0;
out vec2 v_texCoord;

void main()
{
    gl_Position = a_position;
    v_texCoord = a_in0;
}
</script>
<script id="fshaderInvalidOffset" type="x-shader/x-fragment">#version 300 es
precision mediump float;

in vec2 v_texCoord;
out vec4 my_FragColor;
uniform sampler2D u_sampler;
uniform int x;

void main() {
    my_FragColor = textureOffset(u_sampler, v_texCoord, ivec2(0, $(yoffset)));
}
</script>
<script type="application/javascript">
"use strict";
description("Out-of-range texture offset should not compile.");

var wtu = WebGLTestUtils;

var vshader = wtu.getScript('vshaderInvalidOffset');
var fshaderTemplate = wtu.getScript('fshaderInvalidOffset');

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

if (!gl) {
    testFailed("Unable to initialize WebGL 2.0 context.");
} else {
    var minOffset = gl.getParameter(gl.MIN_PROGRAM_TEXEL_OFFSET);
    var maxOffset = gl.getParameter(gl.MAX_PROGRAM_TEXEL_OFFSET);

    var shaderSrcValidMin = wtu.replaceParams(fshaderTemplate, {'yoffset': minOffset});
    var shaderSrcValidMax = wtu.replaceParams(fshaderTemplate, {'yoffset': maxOffset});
    var shaderSrcBelowMin = wtu.replaceParams(fshaderTemplate, {'yoffset': (minOffset - 1)});
    var shaderSrcAboveMax = wtu.replaceParams(fshaderTemplate, {'yoffset': (maxOffset + 1)});
    var shaderSrcDynamic = wtu.replaceParams(fshaderTemplate, {'yoffset': 'x'});

    GLSLConformanceTester.runTests([
    {
        vShaderSource: vshader,
        fShaderSource: shaderSrcValidMin,
        fShaderSuccess: true,
        linkSuccess: true,
        passMsg: 'Minimum in-range texture offset should compile'
    },
    {
        vShaderSource: vshader,
        fShaderSource: shaderSrcValidMax,
        fShaderSuccess: true,
        linkSuccess: true,
        passMsg: 'Maximum in-range texture offset should compile'
    },
    {
        vShaderSource: vshader,
        fShaderSource: shaderSrcBelowMin,
        fShaderSuccess: false,
        linkSuccess: false,
        passMsg: 'Texture offset below minimum valid value should not compile'
    },
    {
        vShaderSource: vshader,
        fShaderSource: shaderSrcAboveMax,
        fShaderSuccess: false,
        linkSuccess: false,
        passMsg: 'Texture offset above maximum valid value should not compile'
    },
    {
        vShaderSource: vshader,
        fShaderSource: shaderSrcDynamic,
        fShaderSuccess: false,
        linkSuccess: false,
        passMsg: 'Dynamic texture offset should not compile'
    }
    ], 2);
}
</script>
</body>
</html>