OLD | NEW |
| 1 <!DOCTYPE html> |
1 <html> | 2 <html> |
2 <head> | 3 <head> |
| 4 <meta charset="utf-8"> |
| 5 <link rel="stylesheet" href="../../js/resources/js-test-style.css"/> |
3 <script src="../../js/resources/js-test-pre.js"></script> | 6 <script src="../../js/resources/js-test-pre.js"></script> |
4 <script src="resources/webgl-test.js"></script> | 7 <script src="resources/webgl-test.js"></script> |
5 <script src="resources/webgl-test-utils.js"></script> | 8 <script src="resources/webgl-test-utils.js"></script> |
| 9 <script src="resources/tex-image-and-sub-image-2d-with-image.js"></script> |
6 <script> | 10 <script> |
7 var wtu = WebGLTestUtils; | 11 function testPrologue(gl) { |
8 var gl = null; | 12 return true; |
9 var textureLoc = null; | |
10 | |
11 function init() | |
12 { | |
13 if (window.initNonKhronosFramework) { | |
14 window.initNonKhronosFramework(true); | |
15 } | |
16 | |
17 description('Verify texImage2D and texSubImage2D code paths taking Images'); | |
18 | |
19 var canvas = document.getElementById("example"); | |
20 gl = wtu.create3DContext(canvas); | |
21 var program = wtu.setupTexturedQuad(gl); | |
22 | |
23 gl.clearColor(0,0,0,1); | |
24 gl.clearDepth(1); | |
25 | |
26 textureLoc = gl.getUniformLocation(gl.program, "tex"); | |
27 | |
28 wtu.loadTexture(gl, "resources/red-green.png", runTest); | |
29 } | |
30 | |
31 // These two declarations need to be global for "shouldBe" to see them | |
32 var buf = null; | |
33 var idx = 0; | |
34 var pixel = [0, 0, 0]; | |
35 var correctColor = null; | |
36 | |
37 function runOneIteration(image, useTexSubImage2D, flipY, topColor, bottomColor) | |
38 { | |
39 debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') + | |
40 ' with flipY=' + flipY); | |
41 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | |
42 // Disable any writes to the alpha channel | |
43 gl.colorMask(1, 1, 1, 0); | |
44 var texture = gl.createTexture(); | |
45 // Bind the texture to texture unit 0 | |
46 gl.bindTexture(gl.TEXTURE_2D, texture); | |
47 // Set up texture parameters | |
48 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); | |
49 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); | |
50 // Set up pixel store parameters | |
51 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY); | |
52 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false); | |
53 // Upload the image into the texture | |
54 if (useTexSubImage2D) { | |
55 // Initialize the texture to black first | |
56 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, image.width, image.height, 0, | |
57 gl.RGBA, gl.UNSIGNED_BYTE, null); | |
58 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, imag
e); | |
59 } else { | |
60 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, imag
e); | |
61 } | |
62 | |
63 // Point the uniform sampler to texture unit 0 | |
64 gl.uniform1i(textureLoc, 0); | |
65 // Draw the triangles | |
66 wtu.drawQuad(gl, [0, 0, 0, 255]); | |
67 // Check a few pixels near the top and bottom and make sure they have | |
68 // the right color. | |
69 debug("Checking lower left corner"); | |
70 wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor, | |
71 "shouldBe " + bottomColor); | |
72 debug("Checking upper left corner"); | |
73 wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor, | |
74 "shouldBe " + topColor); | |
75 } | |
76 | |
77 function runTest(image) | |
78 { | |
79 var red = [255, 0, 0]; | |
80 var green = [0, 255, 0]; | |
81 runOneIteration(image, false, true, red, green); | |
82 runOneIteration(image, false, false, green, red); | |
83 runOneIteration(image, true, true, red, green); | |
84 runOneIteration(image, true, false, green, red); | |
85 var epilogue = document.createElement("script"); | |
86 epilogue.onload = finish; | |
87 epilogue.src = "../../js/resources/js-test-post.js"; | |
88 document.body.appendChild(epilogue); | |
89 } | |
90 | |
91 function finish() { | |
92 if (window.nonKhronosFrameworkNotifyDone) { | |
93 window.nonKhronosFrameworkNotifyDone(); | |
94 } | |
95 } | 13 } |
96 </script> | 14 </script> |
97 </head> | 15 </head> |
98 <body onload="init()"> | 16 <body onload='generateTest("RGBA", "UNSIGNED_BYTE", ".", testPrologue)()'> |
99 <canvas id="example" width="32px" height="32px"></canvas> | 17 <canvas id="example" width="32px" height="32px"></canvas> |
100 <div id="description"></div> | 18 <div id="description"></div> |
101 <div id="console"></div> | 19 <div id="console"></div> |
102 </body> | 20 </body> |
103 </html> | 21 </html> |
104 | |
105 | |
OLD | NEW |