|
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 |
|
15 <script> |
|
16 var successfullyParsed = false; |
|
17 |
|
18 function init() |
|
19 { |
|
20 if (window.initNonKhronosFramework) { |
|
21 window.initNonKhronosFramework(true); |
|
22 } |
|
23 |
|
24 description('Verify copyTexImage2D and copyTexSubImage2D'); |
|
25 |
|
26 runTest(); |
|
27 } |
|
28 |
|
29 var gl = null; |
|
30 var wtu = WebGLTestUtils; |
|
31 |
|
32 function runTestIteration(antialias) |
|
33 { |
|
34 var canvas = document.getElementById( |
|
35 antialias ? "antialiasOn" : "antialiasOff"); |
|
36 var attribs = antialias ? { antialias: false } : undefined; |
|
37 gl = wtu.create3DContext(canvas, attribs); |
|
38 var program = wtu.setupTexturedQuad(gl); |
|
39 var textureLoc = gl.getUniformLocation(program, "tex"); |
|
40 glErrorShouldBe(gl, gl.NO_ERROR, "During Initialization"); |
|
41 |
|
42 gl.colorMask(1, 1, 1, 1); |
|
43 gl.disable(gl.BLEND); |
|
44 debug('Testing copyTexImage2D'); |
|
45 |
|
46 // Red canvas |
|
47 gl.clearColor(1, 0, 0, 1); |
|
48 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
|
49 |
|
50 var texture = gl.createTexture(); |
|
51 // Bind the texture to texture unit 0 |
|
52 gl.bindTexture(gl.TEXTURE_2D, texture); |
|
53 // Set up texture |
|
54 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); |
|
55 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
|
56 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
|
57 gl.uniform1i(textureLoc, 0); |
|
58 |
|
59 var colors = [ |
|
60 [1, 0, 0, 1], |
|
61 [0, 1, 0, 1], |
|
62 [0, 0, 1, 1], |
|
63 [0.5, 0.5, 0.5, 0.5], |
|
64 ]; |
|
65 var count = 0; |
|
66 for (var yy = -2; yy <= 2; ++yy) { |
|
67 for (var xx = -2; xx <= 2; ++xx) { |
|
68 for (var ii = 0; ii < 2; ++ii) { |
|
69 var texColor = colors[count]; |
|
70 var clearColor = colors[(count + 1) % colors.length]; |
|
71 // clear to some color |
|
72 gl.clearColor(texColor[0], texColor[1], texColor[2], texColor[3]); |
|
73 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
|
74 |
|
75 // copy that color to the texture. |
|
76 switch (ii) { |
|
77 case 0: |
|
78 gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, xx, yy, 2, 2, 0); |
|
79 glErrorShouldBe(gl, gl.NO_ERROR, |
|
80 "using copyTexImage2D: x =" + xx + ", y = " + yy); |
|
81 break; |
|
82 case 1: |
|
83 gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, xx, yy, 2, 2); |
|
84 glErrorShouldBe(gl, gl.NO_ERROR, |
|
85 "using copyTexSubImage2D: x =" + xx + ", y = " + yy); |
|
86 break; |
|
87 } |
|
88 |
|
89 // clear to some other color. |
|
90 gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]); |
|
91 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
|
92 |
|
93 // Draw the triangles |
|
94 wtu.drawQuad(gl); |
|
95 |
|
96 // check the rendering results |
|
97 for (var iy = 0; iy < 2; ++iy) { |
|
98 for (var ix = 0; ix < 2; ++ix) { |
|
99 var x = xx + ix; |
|
100 var y = yy + iy; |
|
101 var expectedColor = (x < 0 || y < 0 || x >= 2 || y >= 2) ? |
|
102 [0,0,0,0] : |
|
103 [Math.floor(255 * texColor[0]), |
|
104 Math.floor(255 * texColor[1]), |
|
105 Math.floor(255 * texColor[2]), |
|
106 Math.floor(255 * texColor[3])]; |
|
107 wtu.checkCanvasRect(gl, ix, iy, 1, 1, expectedColor, |
|
108 "" + ix + ", " + iy + " should render " + expectedColor + " (+/-1)", 1); |
|
109 } |
|
110 } |
|
111 count = (count + 1) % colors.length; |
|
112 } |
|
113 } |
|
114 } |
|
115 |
|
116 debug(""); |
|
117 } |
|
118 |
|
119 function runTest(antialias) |
|
120 { |
|
121 debug("Testing with antialias on"); |
|
122 runTestIteration(true); |
|
123 debug("Testing with antialias off"); |
|
124 runTestIteration(false); |
|
125 |
|
126 finishTest(); |
|
127 } |
|
128 </script> |
|
129 </head> |
|
130 <body onload="init()"> |
|
131 <canvas id="antialiasOn" width="2px" height="2px"></canvas> |
|
132 <canvas id="antialiasOff" width="2px" height="2px"></canvas> |
|
133 <div id="description"></div> |
|
134 <div id="console"></div> |
|
135 </body> |
|
136 </html> |