OLD | NEW |
(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 "use strict"; |
| 78 description("This test verifies the functionality of the OES_texture_float exten
sion, if it is available."); |
| 79 |
| 80 debug(""); |
| 81 |
| 82 var wtu = WebGLTestUtils; |
| 83 var canvas = document.getElementById("canvas"); |
| 84 var gl = wtu.create3DContext(canvas); |
| 85 |
| 86 if (!gl) { |
| 87 testFailed("WebGL context does not exist"); |
| 88 } else { |
| 89 testPassed("WebGL context exists"); |
| 90 |
| 91 var texturedShaders = [ |
| 92 wtu.setupSimpleTextureVertexShader(gl), |
| 93 "testFragmentShader" |
| 94 ]; |
| 95 var testProgram = |
| 96 wtu.setupProgram(gl, |
| 97 texturedShaders, |
| 98 ['vPosition', 'texCoord0'], |
| 99 [0, 1]); |
| 100 var quadParameters = wtu.setupUnitQuad(gl, 0, 1); |
| 101 |
| 102 // First verify that allocation of floating-point textures fails if |
| 103 // the extension has not been enabled yet. |
| 104 runTextureCreationTest(testProgram, false); |
| 105 |
| 106 if (!gl.getExtension("OES_texture_float")) { |
| 107 testPassed("No OES_texture_float support -- this is legal"); |
| 108 } else { |
| 109 testPassed("Successfully enabled OES_texture_float extension"); |
| 110 runTextureCreationTest(testProgram, true, gl.RGBA, 4, [10000, 10000, 10000
, 10000]); |
| 111 runTextureCreationTest(testProgram, true, gl.RGB, 3, [10000, 10000, 10000,
0]); |
| 112 runTextureCreationTest(testProgram, true, gl.LUMINANCE, 1, [10000, 10000,
10000, 0]); |
| 113 runTextureCreationTest(testProgram, true, gl.ALPHA, 1, [0, 0, 0, 10000]); |
| 114 runTextureCreationTest(testProgram, true, gl.LUMINANCE_ALPHA, 2, [10000, 1
0000, 10000, 10000]); |
| 115 runRenderTargetTest(testProgram); |
| 116 runUniqueObjectTest(); |
| 117 } |
| 118 } |
| 119 |
| 120 function allocateTexture() |
| 121 { |
| 122 var texture = gl.createTexture(); |
| 123 gl.bindTexture(gl.TEXTURE_2D, texture); |
| 124 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
| 125 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
| 126 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); |
| 127 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); |
| 128 glErrorShouldBe(gl, gl.NO_ERROR, "texture parameter setup should succeed"); |
| 129 return texture; |
| 130 } |
| 131 |
| 132 function checkRenderingResults() |
| 133 { |
| 134 wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green"); |
| 135 } |
| 136 |
| 137 function runTextureCreationTest(testProgram, extensionEnabled, opt_format, opt_n
umChannels, opt_subtractor) |
| 138 { |
| 139 var format = opt_format || gl.RGBA; |
| 140 var numberOfChannels = opt_numChannels || 4; |
| 141 var expectFailure = !extensionEnabled; |
| 142 var subtractor = opt_subtractor || [10000, 10000, 10000, 10000]; |
| 143 |
| 144 debug(""); |
| 145 debug("testing format: " + wtu.glEnumToString(gl, format) + |
| 146 " expect:" + (extensionEnabled ? "success" : "failure")); |
| 147 |
| 148 var texture = allocateTexture(); |
| 149 // Generate data. |
| 150 var width = 2; |
| 151 var height = 2; |
| 152 var data = new Float32Array(width * height * numberOfChannels); |
| 153 for (var ii = 0; ii < data.length; ++ii) { |
| 154 data[ii] = 10000; |
| 155 } |
| 156 gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, format, gl.FLOAT,
data); |
| 157 if (expectFailure) { |
| 158 glErrorShouldBe(gl, gl.INVALID_ENUM, "floating-point texture allocation
must be disallowed if OES_texture_float isn't enabled"); |
| 159 return; |
| 160 } else { |
| 161 glErrorShouldBe(gl, gl.NO_ERROR, "floating-point texture allocation shou
ld succeed if OES_texture_float is enabled"); |
| 162 } |
| 163 // Verify that the texture actually works for sampling and contains the expe
cted data. |
| 164 gl.uniform4fv(gl.getUniformLocation(testProgram, "subtractor"), subtractor); |
| 165 wtu.clearAndDrawUnitQuad(gl); |
| 166 checkRenderingResults(); |
| 167 |
| 168 // Check that linear fails. |
| 169 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); |
| 170 wtu.clearAndDrawUnitQuad(gl); |
| 171 wtu.checkCanvas(gl, [255, 0, 0, 255], "should be red"); |
| 172 } |
| 173 |
| 174 function runRenderTargetTest(testProgram) |
| 175 { |
| 176 debug(""); |
| 177 debug("testing floating-point render targets"); |
| 178 |
| 179 var texture = allocateTexture(); |
| 180 var width = 2; |
| 181 var height = 2; |
| 182 var numberOfChannels = 4; |
| 183 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.FLOAT
, null); |
| 184 glErrorShouldBe(gl, gl.NO_ERROR, "floating-point texture allocation should s
ucceed if OES_texture_float is enabled"); |
| 185 |
| 186 // Try to use this texture as a render target. |
| 187 var fbo = gl.createFramebuffer(); |
| 188 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); |
| 189 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D,
texture, 0); |
| 190 gl.bindTexture(gl.TEXTURE_2D, null); |
| 191 // It is legal for a WebGL implementation exposing the OES_texture_float ext
ension to |
| 192 // support floating-point textures but not as attachments to framebuffer obj
ects. |
| 193 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) { |
| 194 debug("floating-point render targets not supported -- this is legal"); |
| 195 return; |
| 196 } |
| 197 |
| 198 var renderProgram = |
| 199 wtu.setupProgram(gl, |
| 200 ["positionVertexShader", "floatingPointFragmentShader"]
, |
| 201 ['vPosition'], |
| 202 [0]); |
| 203 wtu.clearAndDrawUnitQuad(gl); |
| 204 glErrorShouldBe(gl, gl.NO_ERROR, "rendering to floating-point texture should
succeed"); |
| 205 |
| 206 // Now sample from the floating-point texture and verify we got the correct
values. |
| 207 gl.bindFramebuffer(gl.FRAMEBUFFER, null); |
| 208 gl.bindTexture(gl.TEXTURE_2D, texture); |
| 209 gl.useProgram(testProgram); |
| 210 gl.uniform1i(gl.getUniformLocation(testProgram, "tex"), 0); |
| 211 wtu.clearAndDrawUnitQuad(gl); |
| 212 glErrorShouldBe(gl, gl.NO_ERROR, "rendering from floating-point texture shou
ld succeed"); |
| 213 checkRenderingResults(); |
| 214 } |
| 215 |
| 216 function runUniqueObjectTest() |
| 217 { |
| 218 debug("Testing that getExtension() returns the same object each time"); |
| 219 gl.getExtension("OES_texture_float").myProperty = 2; |
| 220 gc(); |
| 221 shouldBe('gl.getExtension("OES_texture_float").myProperty', '2'); |
| 222 } |
| 223 |
| 224 |
| 225 debug(""); |
| 226 var successfullyParsed = true; |
| 227 </script> |
| 228 <script src="../../resources/js-test-post.js"></script> |
| 229 |
| 230 </body> |
| 231 </html> |
OLD | NEW |