gl-fragcoord.html (2208B)
1 <!-- 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. 5 --> 6 7 <!DOCTYPE html> 8 <html> 9 <head> 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> 15 </head> 16 <body> 17 <canvas id="example" width="32" height="32"> 18 </canvas> 19 <div id="description"></div> 20 <div id="console"></div> 21 <script id="vshader" type="x-shader/x-vertex"> 22 attribute vec4 vPosition; 23 void main() 24 { 25 gl_Position = vPosition; 26 } 27 </script> 28 29 <script id="fshader" type="x-shader/x-fragment"> 30 precision mediump float; 31 void main() 32 { 33 gl_FragColor = vec4( 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, 37 1); 38 } 39 </script> 40 41 <script> 42 "use strict"; 43 function init() 44 { 45 description("tests gl_FragCoord"); 46 47 var wtu = WebGLTestUtils; 48 var gl = wtu.create3DContext("example"); 49 var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["vPosition"]); 50 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]), 56 gl.STATIC_DRAW); 57 gl.enableVertexAttribArray(0); 58 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); 59 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"); 63 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); 67 var color = [ 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) 71 ]; 72 var msg = "should be " + color; 73 wtu.checkCanvasRect(gl, xx, yy, 1, 1, color, msg, 4); 74 } 75 } 76 } 77 78 init(); 79 var successfullyParsed = true; 80 </script> 81 <script src="../../../js/js-test-post.js"></script> 82 83 </body> 84 </html>