OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
3 Use of this source code is governed by a BSD-style license that can be | |
4 found in the LICENSE file. | |
5 --> | |
6 <!DOCTYPE html> | |
7 <html> | |
8 <head> | |
9 <meta charset="utf-8"> | |
10 <link rel="stylesheet" href="../../resources/js-test-style.css"/> | |
11 <script src="../../resources/js-test-pre.js"></script> | |
12 <script src="../resources/webgl-test.js"></script> | |
13 <script src="../resources/webgl-test-utils.js"></script> | |
14 <script> | |
15 var wtu = WebGLTestUtils; | |
16 var gl = null; | |
17 var textureLoc = null; | |
18 var successfullyParsed = false; | |
19 var imgCanvas; | |
20 | |
21 function init() | |
22 { | |
23 if (window.initNonKhronosFramework) { | |
24 window.initNonKhronosFramework(true); | |
25 } | |
26 | |
27 description('Verify texImage2D and texSubImage2D code paths taking Images'); | |
28 | |
29 var canvas = document.getElementById("example"); | |
30 gl = wtu.create3DContext(canvas); | |
31 var program = wtu.setupTexturedQuad(gl); | |
32 | |
33 gl.clearColor(0,0,0,1); | |
34 gl.clearDepth(1); | |
35 | |
36 textureLoc = gl.getUniformLocation(program, "tex"); | |
37 | |
38 wtu.loadTexture(gl, "../resources/red-green.png", runTest); | |
39 } | |
40 | |
41 // These two declarations need to be global for "shouldBe" to see them | |
42 var buf = null; | |
43 var idx = 0; | |
44 var pixel = [0, 0, 0]; | |
45 var correctColor = null; | |
46 | |
47 function runOneIteration(image, useTexSubImage2D, flipY, topColor, bottomColor) | |
48 { | |
49 debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') + | |
50 ' with flipY=' + flipY); | |
51 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | |
52 // Disable any writes to the alpha channel | |
53 gl.colorMask(1, 1, 1, 0); | |
54 var texture = gl.createTexture(); | |
55 // Bind the texture to texture unit 0 | |
56 gl.bindTexture(gl.TEXTURE_2D, texture); | |
57 // Set up texture parameters | |
58 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); | |
59 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); | |
60 // Set up pixel store parameters | |
61 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY); | |
62 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false); | |
63 gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE); | |
64 // Upload the image into the texture | |
65 if (useTexSubImage2D) { | |
66 // Initialize the texture to black first | |
67 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, image.width, image.height, 0, | |
68 gl.RGBA, gl.UNSIGNED_BYTE, null); | |
69 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, imag
e); | |
70 } else { | |
71 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, imag
e); | |
72 } | |
73 | |
74 // Point the uniform sampler to texture unit 0 | |
75 gl.uniform1i(textureLoc, 0); | |
76 // Draw the triangles | |
77 wtu.drawQuad(gl, [0, 0, 0, 255]); | |
78 // Check a few pixels near the top and bottom and make sure they have | |
79 // the right color. | |
80 debug("Checking lower left corner"); | |
81 wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor, | |
82 "shouldBe " + bottomColor); | |
83 debug("Checking upper left corner"); | |
84 wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor, | |
85 "shouldBe " + topColor); | |
86 } | |
87 | |
88 function runTestOnImage(image) { | |
89 var red = [255, 0, 0]; | |
90 var green = [0, 255, 0]; | |
91 runOneIteration(image, false, true, red, green); | |
92 runOneIteration(image, false, false, green, red); | |
93 runOneIteration(image, true, true, red, green); | |
94 runOneIteration(image, true, false, green, red); | |
95 } | |
96 | |
97 function runTest(image) | |
98 { | |
99 runTestOnImage(image); | |
100 | |
101 imgCanvas = document.createElement("canvas"); | |
102 imgCanvas.width = 1; | |
103 imgCanvas.height = 2; | |
104 var imgCtx = imgCanvas.getContext("2d"); | |
105 imgCtx.drawImage(image, 0, 0); | |
106 | |
107 // apparently Image is different than <img>. | |
108 var newImage = new Image(); | |
109 newImage.onload = function() { | |
110 runTest2(newImage); | |
111 }; | |
112 newImage.src = imgCanvas.toDataURL(); | |
113 } | |
114 | |
115 function runTest2(image) { | |
116 runTestOnImage(image); | |
117 | |
118 var newImage = document.createElement("img"); | |
119 newImage.onload = function() { | |
120 runTest3(newImage); | |
121 }; | |
122 newImage.src = imgCanvas.toDataURL(); | |
123 } | |
124 | |
125 function runTest3(image) { | |
126 runTestOnImage(image); | |
127 | |
128 glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors"); | |
129 finishTest(); | |
130 } | |
131 | |
132 </script> | |
133 </head> | |
134 <body onload="init()"> | |
135 <canvas id="example" width="32px" height="32px"></canvas> | |
136 <div id="description"></div> | |
137 <div id="console"></div> | |
138 </body> | |
139 </html> | |
140 | |
141 | |
OLD | NEW |