OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (c) 2009 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 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
7 "http://www.w3.org/TR/html4/loose.dtd"> | |
8 <html> | |
9 <head> | |
10 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
11 <title>WebGL OES_texture_float Conformance Tests</title> | |
12 <link rel="stylesheet" href="../resources/js-test-style.css"/> | |
13 <script src="../resources/desktop-gl-constants.js" type="text/javascript"></scri
pt> | |
14 <script src="../resources/js-test-pre.js"></script> | |
15 <script src="resources/webgl-test.js"></script> | |
16 <script src="resources/webgl-test-utils.js"></script> | |
17 </head> | |
18 <body> | |
19 <div id="description"></div> | |
20 <canvas id="canvas" style="width: 50px; height: 50px;"> </canvas> | |
21 <div id="console"></div> | |
22 <!-- Shaders for testing floating-point textures --> | |
23 <script id="testFragmentShader" type="x-shader/x-fragment"> | |
24 precision mediump float; | |
25 uniform sampler2D tex; | |
26 varying vec2 texCoord; | |
27 void main() | |
28 { | |
29 vec4 color = texture2D(tex, texCoord); | |
30 if (abs(color.r - 10000.0) + | |
31 abs(color.g - 10000.0) + | |
32 abs(color.b - 10000.0) + | |
33 abs(color.a - 10000.0) < 8.0) { | |
34 gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); | |
35 } else { | |
36 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); | |
37 } | |
38 } | |
39 </script> | |
40 <!-- Shaders for testing floating-point render targets --> | |
41 <script id="positionVertexShader" type="x-shader/x-vertex"> | |
42 attribute vec4 vPosition; | |
43 void main() | |
44 { | |
45 gl_Position = vPosition; | |
46 } | |
47 </script> | |
48 <script id="floatingPointFragmentShader" type="x-shader/x-fragment"> | |
49 void main() | |
50 { | |
51 gl_FragColor = vec4(10000.0, 10000.0, 10000.0, 10000.0); | |
52 } | |
53 </script> | |
54 <script> | |
55 description("This test verifies the functionality of the OES_texture_float exten
sion, if it is available."); | |
56 | |
57 debug(""); | |
58 | |
59 var wtu = WebGLTestUtils; | |
60 var canvas = document.getElementById("canvas"); | |
61 var gl = create3DContext(canvas); | |
62 | |
63 if (!gl) { | |
64 testFailed("WebGL context does not exist"); | |
65 } else { | |
66 testPassed("WebGL context exists"); | |
67 | |
68 var texturedShaders = [ | |
69 wtu.setupSimpleTextureVertexShader(gl), | |
70 wtu.loadShaderFromScript(gl, "testFragmentShader") | |
71 ]; | |
72 var testProgram = | |
73 wtu.setupProgram(gl, | |
74 texturedShaders, | |
75 ['vPosition', 'texCoord0'], | |
76 [0, 1]); | |
77 var quadParameters = wtu.setupUnitQuad(gl, 0, 1); | |
78 | |
79 // First verify that allocation of floating-point textures fails if | |
80 // the extension has not been enabled yet. | |
81 runTextureCreationTest(testProgram, false); | |
82 | |
83 if (!gl.getExtension("OES_texture_float")) { | |
84 testPassed("No OES_texture_float support -- this is legal"); | |
85 } else { | |
86 testPassed("Successfully enabled OES_texture_float extension"); | |
87 runTextureCreationTest(testProgram, true); | |
88 runRenderTargetTest(testProgram); | |
89 runUniqueObjectTest(); | |
90 } | |
91 } | |
92 | |
93 // Needs to be global for shouldBe to see it. | |
94 var pixels; | |
95 | |
96 function allocateTexture() | |
97 { | |
98 var texture = gl.createTexture(); | |
99 gl.bindTexture(gl.TEXTURE_2D, texture); | |
100 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); | |
101 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); | |
102 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | |
103 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); | |
104 glErrorShouldBe(gl, gl.NO_ERROR, "texture parameter setup should succeed"); | |
105 return texture; | |
106 } | |
107 | |
108 function checkRenderingResults() | |
109 { | |
110 pixels = new Uint8Array(4); | |
111 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixels); | |
112 // Outputs green if OK, red if not. | |
113 shouldBe("pixels[0]", "0"); | |
114 shouldBe("pixels[1]", "255"); | |
115 shouldBe("pixels[2]", "0"); | |
116 shouldBe("pixels[3]", "255"); | |
117 } | |
118 | |
119 function runTextureCreationTest(testProgram, extensionEnabled) | |
120 { | |
121 var expectFailure = !extensionEnabled; | |
122 | |
123 var texture = allocateTexture(); | |
124 // Generate data. | |
125 var width = 2; | |
126 var height = 2; | |
127 var numberOfChannels = 4; | |
128 var data = new Float32Array(width * height * numberOfChannels); | |
129 for (var ii = 0; ii < data.length; ++ii) { | |
130 data[ii] = 10000; | |
131 } | |
132 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.FLOAT
, data); | |
133 if (expectFailure) { | |
134 glErrorShouldBe(gl, gl.INVALID_ENUM, "floating-point texture allocation
must be disallowed if OES_texture_float isn't enabled"); | |
135 return; | |
136 } else { | |
137 glErrorShouldBe(gl, gl.NO_ERROR, "floating-point texture allocation shou
ld succeed if OES_texture_float is enabled"); | |
138 } | |
139 // Verify that the texture actually works for sampling and contains the expe
cted data. | |
140 gl.uniform1i(gl.getUniformLocation(testProgram, "tex"), 0); | |
141 wtu.drawQuad(gl); | |
142 checkRenderingResults(); | |
143 } | |
144 | |
145 function runRenderTargetTest(testProgram) | |
146 { | |
147 var texture = allocateTexture(); | |
148 var width = 2; | |
149 var height = 2; | |
150 var numberOfChannels = 4; | |
151 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.FLOAT
, null); | |
152 glErrorShouldBe(gl, gl.NO_ERROR, "floating-point texture allocation should s
ucceed if OES_texture_float is enabled"); | |
153 | |
154 // Use this texture as a render target. | |
155 var fbo = gl.createFramebuffer(); | |
156 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); | |
157 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D,
texture, 0); | |
158 gl.bindTexture(gl.TEXTURE_2D, null); | |
159 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLE
TE"); | |
160 // While strictly speaking it is probably legal for a WebGL implementation t
o support | |
161 // floating-point textures but not as attachments to framebuffer objects, an
y such | |
162 // implementation is so poor that it arguably should not advertise support f
or the | |
163 // OES_texture_float extension. For this reason the conformance test require
s that the | |
164 // framebuffer is complete here. | |
165 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) | |
166 return; | |
167 | |
168 var shaders = [ | |
169 wtu.loadShaderFromScript(gl, "positionVertexShader"), | |
170 wtu.loadShaderFromScript(gl, "floatingPointFragmentShader") | |
171 ]; | |
172 var renderProgram = | |
173 wtu.setupProgram(gl, | |
174 shaders, | |
175 ['vPosition'], | |
176 [0]); | |
177 wtu.drawQuad(gl); | |
178 glErrorShouldBe(gl, gl.NO_ERROR, "rendering to floating-point texture should
succeed"); | |
179 | |
180 // Now sample from the floating-point texture and verify we got the correct
values. | |
181 gl.bindFramebuffer(gl.FRAMEBUFFER, null); | |
182 gl.bindTexture(gl.TEXTURE_2D, texture); | |
183 gl.useProgram(testProgram); | |
184 gl.uniform1i(gl.getUniformLocation(testProgram, "tex"), 0); | |
185 wtu.drawQuad(gl); | |
186 glErrorShouldBe(gl, gl.NO_ERROR, "rendering from floating-point texture shou
ld succeed"); | |
187 checkRenderingResults(); | |
188 } | |
189 | |
190 function attemptToForceGC() | |
191 { | |
192 var holderArray = []; | |
193 var tempArray; | |
194 window.tempArray = holderArray; | |
195 for (var i = 0; i < 12; ++i) { | |
196 tempArray = []; | |
197 for (var j = 0; j < 1024 * 1024; ++j) { | |
198 tempArray.push(0); | |
199 } | |
200 holderArray.push(tempArray); | |
201 } | |
202 window.tempArray = null; | |
203 } | |
204 | |
205 function runUniqueObjectTest() | |
206 { | |
207 debug("Testing that getExtension() returns the same object each time"); | |
208 gl.getExtension("OES_texture_float").myProperty = 2; | |
209 if (window.GCController) { | |
210 window.GCController.collect(); | |
211 } else { | |
212 attemptToForceGC(); | |
213 } | |
214 shouldBe('gl.getExtension("OES_texture_float").myProperty', '2'); | |
215 } | |
216 | |
217 | |
218 debug(""); | |
219 successfullyParsed = true; | |
220 </script> | |
221 <script src="../resources/js-test-post.js"></script> | |
222 <script> | |
223 </script> | |
224 | |
225 </body> | |
226 </html> | |
OLD | NEW |