OLD | NEW |
| (Empty) |
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
2 "http://www.w3.org/TR/html4/loose.dtd"> | |
3 <html> | |
4 <head> | |
5 <title>WebGL array bounds clamping conformance test.</title> | |
6 <script src="../../../resources/js-test.js"></script> | |
7 <script src="resources/webgl-test.js"> </script> | |
8 </head> | |
9 <body> | |
10 <canvas id="example" width="40" height="40" style="width: 40px; height: 40px;"><
/canvas> | |
11 <div id="description"></div> | |
12 <div id="console"></div> | |
13 <script id="vshader" type="x-shader/x-vertex"> | |
14 #ifdef GL_ES | |
15 precision highp float; | |
16 #endif | |
17 attribute vec4 vPosition; | |
18 attribute float index; | |
19 uniform float shades[8]; | |
20 varying vec4 texColor; | |
21 void main() | |
22 { | |
23 gl_Position = vPosition; | |
24 texColor = vec4(shades[int(index)], 0, 0, 1.0); | |
25 } | |
26 </script> | |
27 | |
28 <script id="fshader" type="x-shader/x-fragment"> | |
29 #ifdef GL_ES | |
30 precision highp float; | |
31 #endif | |
32 varying vec4 texColor; | |
33 void main() | |
34 { | |
35 gl_FragColor = texColor; | |
36 } | |
37 </script> | |
38 | |
39 <script> | |
40 function init() | |
41 { | |
42 if (window.initNonKhronosFramework) | |
43 window.initNonKhronosFramework(false); | |
44 | |
45 debug("Checks that array access in a shader can not read out of bounds"); | |
46 debug(""); | |
47 | |
48 gl = initWebGL("example", "vshader", "fshader", [ "vPosition", "index" ], | |
49 [ 1, 1, 1, 1 ], 1); | |
50 | |
51 gl.disable(gl.DEPTH_TEST); | |
52 gl.disable(gl.BLEND); | |
53 | |
54 var vertexObject = gl.createBuffer(); | |
55 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); | |
56 gl.bufferData(gl.ARRAY_BUFFER, | |
57 new Float32Array([ -1,1,0, 1,1,0, -1,-1,0, | |
58 -1,-1,0, 1,1,0, 1,-1,0 ]), | |
59 gl.STATIC_DRAW); | |
60 gl.enableVertexAttribArray(0); | |
61 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); | |
62 | |
63 var vertexObject = gl.createBuffer(); | |
64 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); | |
65 gl.bufferData(gl.ARRAY_BUFFER, | |
66 // Create an array that exercises well outside the | |
67 // limits on each side, near the limits, and the | |
68 // exact limits. | |
69 // This should be clamped to [0, 0, 0, 7, 7, 7] | |
70 new Float32Array([ -123456789, -1, 0, 7, 8, 123456789]), | |
71 gl.STATIC_DRAW); | |
72 gl.enableVertexAttribArray(1); | |
73 gl.vertexAttribPointer(1, 1, gl.FLOAT, false, 0, 0); | |
74 | |
75 var loc = gl.getUniformLocation(gl.program, "shades"); | |
76 gl.uniform1fv(loc, [0.25, 0.5, 0, 0, 0, 0, 0.75, 1]); | |
77 | |
78 checkRedValue(0, 38, 64, "Top left corner should clamp to index 0"); | |
79 checkRedValue(37, 38, 64, "Inside top right corner should clamp to index 0")
; | |
80 checkRedValue(0, 1, 64, "Inside bottom left corner should clamp to index 0")
; | |
81 | |
82 checkRedValue(38, 0, 255, "Bottom right corner should clamp to index 7"); | |
83 checkRedValue(3, 1, 255, "Outside bottom left corner should clamp to index 7
"); | |
84 checkRedValue(38, 37, 255, "Outside top right corner should clamp to index 7
"); | |
85 | |
86 function checkRedValue(x, y, value, msg) { | |
87 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | |
88 gl.drawArrays(gl.TRIANGLES, 0, 6); | |
89 gl.flush(); | |
90 var buf = new Uint8Array(4); | |
91 gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf); | |
92 if (buf[0] != value || buf[1] != 0 || buf[2] != 0 || buf[3] != 255) { | |
93 debug('expected: rgb(' + value + ', 0, 0, 255) was rgb(' + buf[0] +
', ' + buf[1] + ', ' + buf[2] + ', ' + buf[3] + ')'); | |
94 testFailed(msg); | |
95 return; | |
96 } | |
97 testPassed(msg); | |
98 } | |
99 } | |
100 | |
101 init(); | |
102 </script> | |
103 </body> | |
104 </html> | |
105 | |
OLD | NEW |