2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <meta charset=
"utf-8">
11 <title>gl-fragcoord Test
</title>
12 <link rel=
"stylesheet" href=
"../../../resources/js-test-style.css"/>
13 <script src=
"../../../js/js-test-pre.js"></script>
14 <script src=
"../../../js/webgl-test-utils.js"> </script>
17 <canvas id=
"example" width=
"32" height=
"32">
19 <div id=
"description"></div>
20 <div id=
"console"></div>
21 <script id=
"vshader" type=
"x-shader/x-vertex">
22 attribute vec4 vPosition;
25 gl_Position = vPosition;
29 <script id=
"fshader" type=
"x-shader/x-fragment">
30 precision mediump float;
34 floor(gl_FragCoord.x *
4.0 /
32.0) /
4.0,
35 floor(gl_FragCoord.y *
4.0 /
32.0) /
4.0,
36 floor(gl_FragCoord.z *
4.0) /
4.0,
45 description("tests gl_FragCoord");
47 var wtu
= WebGLTestUtils
;
48 var gl
= wtu
.create3DContext("example");
49 var program
= wtu
.setupProgram(gl
, ["vshader", "fshader"], ["vPosition"]);
51 var vertexObject
= gl
.createBuffer();
52 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
53 gl
.bufferData(gl
.ARRAY_BUFFER
, new Float32Array(
54 [-1, -1, -1, 1, -1, 0, -1, 1, 0,
55 -1, 1, 0, 1, -1, 0, 1, 1, 1]),
57 gl
.enableVertexAttribArray(0);
58 gl
.vertexAttribPointer(0, 3, gl
.FLOAT
, false, 0, 0);
60 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
61 gl
.drawArrays(gl
.TRIANGLES
, 0, 6);
62 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "no errors from draw");
64 for (var xx
= 0; xx
< 32; xx
+= 4) {
65 for (var yy
= 0; yy
< 32; yy
+= 4) {
66 var zz
= (xx
/ 64) + (yy
/ 64);
68 Math
.floor(Math
.floor(xx
* 4.0 / 32.0) / 4 * 256),
69 Math
.floor(Math
.floor(yy
* 4.0 / 32.0) / 4 * 256),
70 Math
.floor(Math
.floor(zz
* 4.0) / 4 * 256)
72 var msg
= "should be " + color
;
73 wtu
.checkCanvasRect(gl
, xx
, yy
, 1, 1, color
, msg
, 4);
79 var successfullyParsed
= true;
81 <script src=
"../../../js/js-test-post.js"></script>