OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 |
| 3 /* |
| 4 ** Copyright (c) 2013 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_half_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 <canvas id="canvas2d" style="width: 50px; height: 50px;"> </canvas> |
| 43 <div id="console"></div> |
| 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 half-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 OES_texture_half_float with
null/non-null ArrayBufferView"); |
| 79 |
| 80 debug(""); |
| 81 var wtu = WebGLTestUtils; |
| 82 var canvas = document.getElementById("canvas"); |
| 83 var colorCanvas = document.getElementById("canvas2d"); |
| 84 colorCanvas.width = 2; |
| 85 colorCanvas.height = 2; |
| 86 var ctx = colorCanvas.getContext("2d"); |
| 87 ctx.fillStyle = "rgb(255,0,0)"; |
| 88 ctx.fillRect(0, 0, 2, 2); |
| 89 var gl = wtu.create3DContext(canvas); |
| 90 // This constant must be defined in order to run the texture creation test witho
ut the extension enabled. |
| 91 var halfFloatOESEnum = 0x8D61; |
| 92 var ext = null; |
| 93 |
| 94 if (!gl) { |
| 95 testFailed("WebGL context does not exists"); |
| 96 } else { |
| 97 testPassed("WebGL context exists"); |
| 98 |
| 99 // Verify that allocation of texture fails if extension is not enabled |
| 100 runTextureCreationTest(false); |
| 101 ext = gl.getExtension("OES_texture_half_float") |
| 102 if (!ext) { |
| 103 testPassed("No OES_texture_half_float support. This is legal"); |
| 104 } else { |
| 105 testPassed("Successfully enabled OES_texture_half_float extension"); |
| 106 |
| 107 var program = wtu.setupTexturedQuad(gl); |
| 108 |
| 109 // Check if creation of texture succeed's with various formats and null
ArrayBufferView |
| 110 var formats = [ |
| 111 { format: gl.RGBA, expected: [255, 0, 0, 255], }, |
| 112 { format: gl.RGB, expected: [255, 0, 0, 255], }, |
| 113 { format: gl.LUMINANCE, expected: [255, 255, 255, 255], }, |
| 114 { format: gl.ALPHA, expected: [ 0, 0, 0, 255], }, |
| 115 { format: gl.LUMINANCE_ALPHA, expected: [255, 255, 255, 255], }, |
| 116 ]; |
| 117 formats.forEach(function(f) { |
| 118 runTextureCreationTest(true, f.format, null, f.expected); |
| 119 }); |
| 120 |
| 121 // Texture creation should fail when passed with non-null ArrayBufferVie
w |
| 122 formats.forEach(function(f) { |
| 123 var width = 2; |
| 124 var height = 2; |
| 125 var format = f.format; |
| 126 |
| 127 // Float32Array |
| 128 var float32Data = new Float32Array(width * height * getNumberOfChann
els(format)); |
| 129 for (var ii = 0; ii < float32Data.length; ii++) { |
| 130 float32Data[ii] = 1000; |
| 131 } |
| 132 runTextureCreationTest(true, format, float32Data); |
| 133 |
| 134 // Int16Array |
| 135 var int16Data = new Int16Array(width * height * getNumberOfChannels(
format)); |
| 136 for (var ii = 0; ii < int16Data.length; ii++) { |
| 137 int16Data[ii] = 1000; |
| 138 } |
| 139 runTextureCreationTest(true, format, int16Data); |
| 140 |
| 141 // Uint16Array |
| 142 var uint16Data = new Uint16Array(width * height * getNumberOfChannel
s(format)); |
| 143 for (var ii = 0; ii < uint16Data.length; ii++) { |
| 144 uint16Data[ii] = 1000; |
| 145 } |
| 146 runTextureCreationTest(true, format, uint16Data); |
| 147 }); |
| 148 |
| 149 // Check if attaching texture as FBO target succeeds (Not mandatory) |
| 150 runRenderTargetTest(); |
| 151 // Check of getExtension() returns same object |
| 152 runUniqueObjectTest(); |
| 153 } |
| 154 } |
| 155 |
| 156 function getNumberOfChannels(format) |
| 157 { |
| 158 if (format == gl.RGBA) |
| 159 return 4; |
| 160 else if (format == gl.RGB) |
| 161 return 3; |
| 162 else if (format == gl.LUMINANCE || format == gl.ALPHA) |
| 163 return 1; |
| 164 else if (format == gl.LUMINANCE_ALPHA) |
| 165 return 2; |
| 166 } |
| 167 |
| 168 function getFormatName(format) |
| 169 { |
| 170 if (format == gl.RGBA) |
| 171 return "RGBA"; |
| 172 else if (format == gl.RGB) |
| 173 return "RGB"; |
| 174 else if (format == gl.LUMINANCE) |
| 175 return "LUMINANCE"; |
| 176 else if (format == gl.ALPHA) |
| 177 return "ALPHA"; |
| 178 else if (format == gl.LUMINANCE_ALPHA) |
| 179 return "LUMINANCE_ALPHA"; |
| 180 } |
| 181 |
| 182 function allocateTexture() |
| 183 { |
| 184 var texture = gl.createTexture(); |
| 185 gl.bindTexture(gl.TEXTURE_2D, texture); |
| 186 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
| 187 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
| 188 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); |
| 189 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); |
| 190 glErrorShouldBe(gl, gl.NO_ERROR, "texture parameter setup should succeed"); |
| 191 return texture; |
| 192 } |
| 193 |
| 194 function runTextureCreationTest(extensionEnabled, opt_format, opt_data, opt_expe
cted) |
| 195 { |
| 196 var format = opt_format || gl.RGBA; |
| 197 var data = opt_data || null; |
| 198 var expectSuccess = true; |
| 199 |
| 200 if (!extensionEnabled || data) |
| 201 expectSuccess = false; |
| 202 debug("Testing texture creation with extension " + (extensionEnabled ? "enab
led" : "disabled") + |
| 203 ", format " + getFormatName(format) + ", and data " + (data ? "non-nul
l" : "null") + |
| 204 ". Expect " + (expectSuccess ? "Success" : "Failure")); |
| 205 |
| 206 var texture = allocateTexture(); |
| 207 var width = 2; |
| 208 var height = 2; |
| 209 gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, format, halfFloatO
ESEnum, data); |
| 210 if(!extensionEnabled) { |
| 211 glErrorShouldBe(gl, gl.INVALID_ENUM, "Half floating point texture must b
e diallowed if OES_texture_half_float isn't enabled"); |
| 212 return; |
| 213 } else if (data) { |
| 214 glErrorShouldBe(gl, gl.INVALID_OPERATION, "Half floating point texture a
llocation must be diallowed when ArrayBufferView is not-null"); |
| 215 return; |
| 216 } else { |
| 217 glErrorShouldBe(gl, gl.NO_ERROR, "Half floating point texture allocation
should succeed if OES_texture_half_float is enabled"); |
| 218 |
| 219 gl.texImage2D(gl.TEXTURE_2D, 0, format, format, halfFloatOESEnum, colorC
anvas); |
| 220 wtu.clearAndDrawUnitQuad(gl); |
| 221 wtu.checkCanvas(gl, opt_expected); |
| 222 // Check that linear fails. |
| 223 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); |
| 224 wtu.clearAndDrawUnitQuad(gl); |
| 225 wtu.checkCanvas(gl, [0, 0, 0, 255], "should be black"); |
| 226 } |
| 227 |
| 228 } |
| 229 |
| 230 function checkRenderingResults() |
| 231 { |
| 232 wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green"); |
| 233 } |
| 234 |
| 235 function runRenderTargetTest(testProgram) |
| 236 { |
| 237 debug(""); |
| 238 debug("Testing half floating point render target"); |
| 239 |
| 240 var texture = allocateTexture(); |
| 241 var width = 2; |
| 242 var height = 2; |
| 243 |
| 244 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, ext.HALF
_FLOAT_OES, null); |
| 245 glErrorShouldBe(gl, gl.NO_ERROR, "Half floating point texture allocation sho
uld succeed if OES_texture_half_float is enabled"); |
| 246 |
| 247 // Try to use this texture as render target |
| 248 var fbo = gl.createFramebuffer(); |
| 249 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); |
| 250 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D,
texture, 0); |
| 251 gl.bindTexture(gl.TEXTURE_2D, null); |
| 252 |
| 253 // It is legal for a WebGL implementation exposing the OES_texture_half_floa
t extension to |
| 254 // support half floating point textures but not as attachments to framebuffe
r objects. |
| 255 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) { |
| 256 debug("Half floating point render targets not supported -- this is legal
"); |
| 257 return; |
| 258 } |
| 259 |
| 260 var renderProgram = |
| 261 wtu.setupProgram(gl, |
| 262 ["positionVertexShader", "floatingPointFragmentShader"]
, |
| 263 ['vPosition'], |
| 264 [0]); |
| 265 wtu.drawUnitQuad(gl); |
| 266 glErrorShouldBe(gl, gl.NO_ERROR, "Rendering to half floating point texture s
hould succeed"); |
| 267 |
| 268 // Now sample from the half floating-point texture and verify we got the cor
rect values. |
| 269 var texturedShaders = [ |
| 270 wtu.setupSimpleTextureVertexShader(gl), |
| 271 "testFragmentShader" |
| 272 ]; |
| 273 var testProgram = |
| 274 wtu.setupProgram(gl, |
| 275 [wtu.setupSimpleTextureVertexShader(gl), "testFragmentSh
ader"], |
| 276 ['vPosition', 'texCoord0'], |
| 277 [0, 1]); |
| 278 var quadParameters = wtu.setupUnitQuad(gl, 0, 1); |
| 279 gl.bindFramebuffer(gl.FRAMEBUFFER, null); |
| 280 gl.bindTexture(gl.TEXTURE_2D, texture); |
| 281 gl.useProgram(testProgram); |
| 282 gl.uniform4fv(gl.getUniformLocation(testProgram, "subtractor"), [10000, 1000
0, 10000, 10000]); |
| 283 wtu.drawUnitQuad(gl); |
| 284 glErrorShouldBe(gl, gl.NO_ERROR, "rendering from half floating point texture
should succeed"); |
| 285 checkRenderingResults(); |
| 286 } |
| 287 |
| 288 function runUniqueObjectTest() |
| 289 { |
| 290 debug("Testing that getExtension() returns the same object each time"); |
| 291 gl.getExtension("OES_texture_half_float").myProperty = 2; |
| 292 gc(); |
| 293 shouldBe('gl.getExtension("OES_texture_half_float").myProperty', '2'); |
| 294 } |
| 295 |
| 296 debug(""); |
| 297 var successfullyParsed = true; |
| 298 </script> |
| 299 <script src="../../resources/js-test-post.js"></script> |
| 300 |
| 301 </body> |
| 302 </html> |
OLD | NEW |