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

Side by Side Diff: third_party/webgl/sdk/tests/conformance/extensions/oes-texture-float.html

Issue 10399113: Roll webgl conformance tests to r17874: part 2, adding r17874 (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/
Patch Set: Created 8 years, 7 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
3 /*
4 ** Copyright (c) 2012 The Khronos Group Inc.
5 **
6 ** Permission is hereby granted, free of charge, to any person obtaining a
7 ** copy of this software and/or associated documentation files (the
8 ** "Materials"), to deal in the Materials without restriction, including
9 ** without limitation the rights to use, copy, modify, merge, publish,
10 ** distribute, sublicense, and/or sell copies of the Materials, and to
11 ** permit persons to whom the Materials are furnished to do so, subject to
12 ** the following conditions:
13 **
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
16 **
17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
24 */
25
26 -->
27
28 <!DOCTYPE html>
29 <html>
30 <head>
31 <meta charset="utf-8">
32 <title>WebGL OES_texture_float Conformance Tests</title>
33 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
34 <script src="../../resources/desktop-gl-constants.js" type="text/javascript"></s cript>
35 <script src="../../resources/js-test-pre.js"></script>
36 <script src="../resources/webgl-test.js"></script>
37 <script src="../resources/webgl-test-utils.js"></script>
38 </head>
39 <body>
40 <div id="description"></div>
41 <canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
42 <div id="console"></div>
43 <!-- Shaders for testing floating-point textures -->
44 <script id="testFragmentShader" type="x-shader/x-fragment">
45 precision mediump float;
46 uniform sampler2D tex;
47 uniform vec4 subtractor;
48 varying vec2 texCoord;
49 void main()
50 {
51 vec4 color = texture2D(tex, texCoord);
52 if (abs(color.r - subtractor.r) +
53 abs(color.g - subtractor.g) +
54 abs(color.b - subtractor.b) +
55 abs(color.a - subtractor.a) < 8.0) {
56 gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
57 } else {
58 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
59 }
60 }
61 </script>
62 <!-- Shaders for testing floating-point render targets -->
63 <script id="positionVertexShader" type="x-shader/x-vertex">
64 attribute vec4 vPosition;
65 void main()
66 {
67 gl_Position = vPosition;
68 }
69 </script>
70 <script id="floatingPointFragmentShader" type="x-shader/x-fragment">
71 void main()
72 {
73 gl_FragColor = vec4(10000.0, 10000.0, 10000.0, 10000.0);
74 }
75 </script>
76 <script>
77 description("This test verifies the functionality of the OES_texture_float exten sion, if it is available.");
78
79 debug("");
80
81 var wtu = WebGLTestUtils;
82 var canvas = document.getElementById("canvas");
83 var gl = create3DContext(canvas);
84
85 if (!gl) {
86 testFailed("WebGL context does not exist");
87 } else {
88 testPassed("WebGL context exists");
89
90 var texturedShaders = [
91 wtu.setupSimpleTextureVertexShader(gl),
92 "testFragmentShader"
93 ];
94 var testProgram =
95 wtu.setupProgram(gl,
96 texturedShaders,
97 ['vPosition', 'texCoord0'],
98 [0, 1]);
99 var quadParameters = wtu.setupUnitQuad(gl, 0, 1);
100
101 // First verify that allocation of floating-point textures fails if
102 // the extension has not been enabled yet.
103 runTextureCreationTest(testProgram, false);
104
105 if (!gl.getExtension("OES_texture_float")) {
106 testPassed("No OES_texture_float support -- this is legal");
107 } else {
108 testPassed("Successfully enabled OES_texture_float extension");
109 runTextureCreationTest(testProgram, true, gl.RGBA, 4, [10000, 10000, 10000 , 10000]);
110 runTextureCreationTest(testProgram, true, gl.RGB, 3, [10000, 10000, 10000, 0]);
111 runTextureCreationTest(testProgram, true, gl.LUMINANCE, 1, [10000, 10000, 10000, 0]);
112 runTextureCreationTest(testProgram, true, gl.ALPHA, 1, [0, 0, 0, 10000]);
113 runTextureCreationTest(testProgram, true, gl.LUMINANCE_ALPHA, 2, [10000, 1 0000, 10000, 10000]);
114 runRenderTargetTest(testProgram);
115 runUniqueObjectTest();
116 }
117 }
118
119 // Needs to be global for shouldBe to see it.
120 var pixels;
121
122 function allocateTexture()
123 {
124 var texture = gl.createTexture();
125 gl.bindTexture(gl.TEXTURE_2D, texture);
126 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
127 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
128 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
129 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
130 glErrorShouldBe(gl, gl.NO_ERROR, "texture parameter setup should succeed");
131 return texture;
132 }
133
134 function checkRenderingResults()
135 {
136 wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green");
137 }
138
139 function runTextureCreationTest(testProgram, extensionEnabled, opt_format, opt_n umChannels, opt_subtractor)
140 {
141 var format = opt_format || gl.RGBA;
142 var numberOfChannels = opt_numChannels || 4;
143 var expectFailure = !extensionEnabled;
144 var subtractor = opt_subtractor || [10000, 10000, 10000, 10000];
145
146 debug("");
147 debug("testing format: " + wtu.glEnumToString(gl, format) +
148 " expect:" + (extensionEnabled ? "success" : "failure"));
149
150 var texture = allocateTexture();
151 // Generate data.
152 var width = 2;
153 var height = 2;
154 var data = new Float32Array(width * height * numberOfChannels);
155 for (var ii = 0; ii < data.length; ++ii) {
156 data[ii] = 10000;
157 }
158 gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, format, gl.FLOAT, data);
159 if (expectFailure) {
160 glErrorShouldBe(gl, gl.INVALID_ENUM, "floating-point texture allocation must be disallowed if OES_texture_float isn't enabled");
161 return;
162 } else {
163 glErrorShouldBe(gl, gl.NO_ERROR, "floating-point texture allocation shou ld succeed if OES_texture_float is enabled");
164 }
165 // Verify that the texture actually works for sampling and contains the expe cted data.
166 gl.uniform1i(gl.getUniformLocation(testProgram, "tex"), 0);
167 gl.uniform4fv(gl.getUniformLocation(testProgram, "subtractor"), subtractor);
168 wtu.drawQuad(gl);
169 checkRenderingResults();
170 }
171
172 function runRenderTargetTest(testProgram)
173 {
174 var texture = allocateTexture();
175 var width = 2;
176 var height = 2;
177 var numberOfChannels = 4;
178 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.FLOAT , null);
179 glErrorShouldBe(gl, gl.NO_ERROR, "floating-point texture allocation should s ucceed if OES_texture_float is enabled");
180
181 // Use this texture as a render target.
182 var fbo = gl.createFramebuffer();
183 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
184 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
185 gl.bindTexture(gl.TEXTURE_2D, null);
186 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLE TE");
187 // While strictly speaking it is probably legal for a WebGL implementation t o support
188 // floating-point textures but not as attachments to framebuffer objects, an y such
189 // implementation is so poor that it arguably should not advertise support f or the
190 // OES_texture_float extension. For this reason the conformance test require s that the
191 // framebuffer is complete here.
192 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE)
193 return;
194
195 var renderProgram =
196 wtu.setupProgram(gl,
197 ["positionVertexShader", "floatingPointFragmentShader"] ,
198 ['vPosition'],
199 [0]);
200 wtu.drawQuad(gl);
201 glErrorShouldBe(gl, gl.NO_ERROR, "rendering to floating-point texture should succeed");
202
203 // Now sample from the floating-point texture and verify we got the correct values.
204 gl.bindFramebuffer(gl.FRAMEBUFFER, null);
205 gl.bindTexture(gl.TEXTURE_2D, texture);
206 gl.useProgram(testProgram);
207 gl.uniform1i(gl.getUniformLocation(testProgram, "tex"), 0);
208 wtu.drawQuad(gl);
209 glErrorShouldBe(gl, gl.NO_ERROR, "rendering from floating-point texture shou ld succeed");
210 checkRenderingResults();
211 }
212
213 function runUniqueObjectTest()
214 {
215 debug("Testing that getExtension() returns the same object each time");
216 gl.getExtension("OES_texture_float").myProperty = 2;
217 gc();
218 shouldBe('gl.getExtension("OES_texture_float").myProperty', '2');
219 }
220
221
222 debug("");
223 successfullyParsed = true;
224 </script>
225 <script src="../../resources/js-test-post.js"></script>
226
227 </body>
228 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698