Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: conformance/extensions/oes-texture-float.html

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

Powered by Google App Engine
This is Rietveld 408576698