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 "Texture Complete" texture 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 <canvas id="canvas2d" width="16" height="16" style="width: 40px; height: 40px;">
</canvas> | |
12 <div id="description"></div> | |
13 <div id="console"></div> | |
14 <script id="vshader" type="x-shader/x-vertex"> | |
15 #ifdef GL_ES | |
16 precision highp float; | |
17 #endif | |
18 attribute vec4 vPosition; | |
19 attribute vec2 texCoord0; | |
20 varying vec2 texCoord; | |
21 void main() | |
22 { | |
23 gl_Position = vPosition; | |
24 texCoord = texCoord0; | |
25 } | |
26 </script> | |
27 | |
28 <script id="fshader" type="x-shader/x-fragment"> | |
29 #ifdef GL_ES | |
30 precision highp float; | |
31 #endif | |
32 uniform sampler2D tex; | |
33 varying vec2 texCoord; | |
34 void main() | |
35 { | |
36 gl_FragColor = texture2D(tex, texCoord); | |
37 } | |
38 </script> | |
39 | |
40 <script> | |
41 function init() | |
42 { | |
43 if (window.initNonKhronosFramework) { | |
44 window.initNonKhronosFramework(false); | |
45 } | |
46 | |
47 if (window.internals) | |
48 window.internals.settings.setWebGLErrorsToConsoleEnabled(false); | |
49 | |
50 debug("Checks that a texture that is not -texture-complete- does not draw if"+ | |
51 " filtering needs mips"); | |
52 debug(""); | |
53 | |
54 var canvas2d = document.getElementById("canvas2d"); | |
55 var ctx2d = canvas2d.getContext("2d"); | |
56 ctx2d.fillStyle = "rgba(0,192,128,255)"; | |
57 ctx2d.fillRect(0, 0, 16, 16); | |
58 | |
59 gl = initWebGL("example", "vshader", "fshader", [ "vPosition", "texCoord0"], | |
60 [ 0, 0, 0, 1 ], 1); | |
61 | |
62 gl.disable(gl.DEPTH_TEST); | |
63 gl.disable(gl.BLEND); | |
64 | |
65 var vertexObject = gl.createBuffer(); | |
66 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); | |
67 gl.bufferData(gl.ARRAY_BUFFER, | |
68 new Float32Array([ -1,1,0, 1,1,0, -1,-1,0, | |
69 -1,-1,0, 1,1,0, 1,-1,0 ]), | |
70 gl.STATIC_DRAW); | |
71 gl.enableVertexAttribArray(0); | |
72 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); | |
73 | |
74 var vertexObject = gl.createBuffer(); | |
75 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); | |
76 gl.bufferData(gl.ARRAY_BUFFER, | |
77 new Float32Array([ 0,0, 1,0, 0,1, | |
78 0,1, 1,0, 1,1 ]), | |
79 gl.STATIC_DRAW); | |
80 gl.enableVertexAttribArray(1); | |
81 gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0); | |
82 | |
83 var tex = gl.createTexture(); | |
84 gl.bindTexture(gl.TEXTURE_2D, tex); | |
85 // 16x16 texture no mips | |
86 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d); | |
87 | |
88 var loc = gl.getUniformLocation(gl.program, "tex"); | |
89 gl.uniform1i(loc, 0); | |
90 | |
91 checkBuffer(0,0,0,255, | |
92 "texture that is not -texture-complete- when " + | |
93 "TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255"); | |
94 | |
95 function checkBuffer(r, g, b, a, msg) { | |
96 gl.clearColor(1,1,1,1); | |
97 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | |
98 gl.drawArrays(gl.TRIANGLES, 0, 6); | |
99 gl.flush(); | |
100 var buf = new Uint8Array(4 * 4 * 4); | |
101 gl.readPixels(0, 0, 4, 4, gl.RGBA, gl.UNSIGNED_BYTE, buf); | |
102 for (var i = 0; i < 4 * 4; ++i) { | |
103 var offset = i * 4; | |
104 if (buf[offset + 0] != r || | |
105 buf[offset + 1] != g || | |
106 buf[offset + 2] != b || | |
107 buf[offset + 3] != a) { | |
108 debug('expected: ' + r + ', ' + g + ', ' + b + ', ' + a + | |
109 ' was: ' + | |
110 buf[offset + 0] + ', ' + | |
111 buf[offset + 1] + ', ' + | |
112 buf[offset + 2] + ', ' + | |
113 buf[offset + 3]); | |
114 testFailed(msg); | |
115 return; | |
116 } | |
117 } | |
118 testPassed(msg); | |
119 } | |
120 } | |
121 | |
122 init(); | |
123 </script> | |
124 | |
125 | |
126 </body> | |
127 </html> | |
128 | |
OLD | NEW |