Chromium Code Reviews| 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_half_float_linear 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 --> | |
|
Ken Russell (switch to Gerrit)
2013/05/13 20:00:35
Rather than duplicating this entire test, it would
| |
| 44 <script id="testFragmentShader" type="x-shader/x-fragment"> | |
| 45 uniform sampler2D tex; | |
| 46 void main() | |
| 47 { | |
| 48 gl_FragColor = texture2D(tex, vec2(0.5, 0.5)) * vec4(1.0, 1.0, 1.0, 1.0); | |
| 49 } | |
| 50 </script> | |
| 51 <script id="texCubFshader" type="x-shader/x-fragment"> | |
| 52 uniform samplerCube tex; | |
| 53 void main() | |
| 54 { | |
| 55 gl_FragColor = textureCube(tex, normalize(vec3(0.5, 0.5, 1))) * vec4(1.0, 1.0, 1.0, 1.0); | |
| 56 } | |
| 57 </script> | |
| 58 <!-- Shaders for testing floating-point render targets --> | |
| 59 <script id="positionVertexShader" type="x-shader/x-vertex"> | |
| 60 attribute vec4 vPosition; | |
| 61 void main() | |
| 62 { | |
| 63 gl_Position = vPosition; | |
| 64 } | |
| 65 </script> | |
| 66 <script> | |
| 67 "use strict"; | |
| 68 description("This test verifies the functionality of the OES_texture_half_float_ linear extension, if it is available."); | |
| 69 | |
| 70 debug(""); | |
| 71 // This constant must be defined in order to run the texture creation test witho ut the extension enabled. | |
| 72 var extension = null; | |
| 73 var wtu = WebGLTestUtils; | |
| 74 var canvas = document.getElementById("canvas"); | |
| 75 var gl = wtu.create3DContext(canvas); | |
| 76 if (!gl) { | |
| 77 testFailed("WebGL context does not exist"); | |
| 78 } else { | |
| 79 testPassed("WebGL context exists"); | |
| 80 | |
| 81 if (!(extension = gl.getExtension("OES_texture_half_float"))) { | |
| 82 testPassed("No OES_texture_half_float support -- this is legal"); | |
| 83 } else { | |
| 84 testPassed("Successfully enabled OES_texture_half_float extension"); | |
| 85 | |
| 86 // Before OES_texture_half_float_linear extension is enabled | |
| 87 var extensionEabled = false; | |
| 88 runTestSuit(extensionEabled); | |
| 89 | |
| 90 if (!gl.getExtension("OES_texture_half_float_linear")) | |
| 91 testPassed("No OES_texture_half_float_linear support -- this is legal" ); | |
| 92 else { | |
| 93 // OES_texture_half_float_linear extension is enabled | |
| 94 extensionEabled = true; | |
| 95 runTestSuit(extensionEabled); | |
| 96 } | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 function runTestSuit(extensionEabled) | |
| 101 { | |
| 102 var magF = [gl.NEAREST, gl.LINEAR]; | |
| 103 var minF = [gl.NEAREST, gl.LINEAR, gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST_MIP MAP_LINEAR, gl.LINEAR_MIPMAP_NEAREST, gl.LINEAR_MIPMAP_LINEAR]; | |
| 104 | |
| 105 var program = wtu.setupProgram(gl, ["positionVertexShader", "testFragmentSha der"]); | |
| 106 gl.useProgram(program); | |
| 107 wtu.setupUnitQuad(gl); | |
| 108 for (var kk = 0; kk < 2; ++kk) { | |
| 109 for (var ii = 0; ii < 6; ++ii) { | |
| 110 var linear = false; | |
| 111 if (magF[kk] == gl.LINEAR || (minF[ii] != gl.NEAREST && minF[ii] != gl.NEAREST_MIPMAP_NEAREST)) | |
| 112 linear = true; | |
| 113 var color = (!extensionEabled && linear) ? [0, 0, 0, 255] : [0, 0, 0 , 0]; | |
| 114 runEachTest(gl.TEXTURE_2D, magF[kk], minF[ii], linear, extensionEabl ed, color, linear); | |
| 115 } | |
| 116 } | |
| 117 | |
| 118 var programCub = wtu.setupProgram(gl, ["positionVertexShader", "texCubFshader "]); | |
| 119 gl.useProgram(programCub); | |
| 120 wtu.setupUnitQuad(gl); | |
| 121 for (var kk = 0; kk < 2; ++kk) { | |
| 122 for (var ii = 0; ii < 6; ++ii) { | |
| 123 var linear = false; | |
| 124 if (magF[kk] == gl.LINEAR || (minF[ii] != gl.NEAREST && minF[ii] != gl.NEAREST_MIPMAP_NEAREST)) | |
| 125 linear = true; | |
| 126 var color = (!extensionEabled && linear) ? [0, 0, 0, 255] : [0, 0, 0 , 0]; | |
| 127 runEachTest(gl.TEXTURE_CUBE_MAP, magF[kk], minF[ii], linear, extensi onEabled, color, linear); | |
| 128 } | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 function runEachTest(textureTarget, magFilter, minFilter, linear, extensionEnabl ed, expected, expectFailure) | |
| 133 { | |
| 134 var format = gl.RGBA; | |
| 135 var numberOfChannels = 4; | |
| 136 debug(""); | |
| 137 debug("testing target: " + wtu.glEnumToString(gl,textureTarget) + | |
| 138 ", testing format: " + wtu.glEnumToString(gl, format) + | |
| 139 ", magFilter is: " + wtu.glEnumToString(gl, magFilter) + | |
| 140 ", minFilter is: " + wtu.glEnumToString(gl, minFilter) + | |
| 141 ", OES_texture_float_linear is " + (extensionEnabled ? "enabled": "no t enabled") | |
| 142 ); | |
| 143 var texture = gl.createTexture(); | |
| 144 // Generate data. | |
| 145 var width = 1; | |
| 146 var height = 1; | |
| 147 gl.bindTexture(textureTarget, texture); | |
| 148 gl.texParameteri(textureTarget, gl.TEXTURE_MAG_FILTER, magFilter); | |
| 149 gl.texParameteri(textureTarget, gl.TEXTURE_MIN_FILTER, minFilter); | |
| 150 gl.texParameteri(textureTarget, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | |
| 151 gl.texParameteri(textureTarget, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); | |
| 152 | |
| 153 if (textureTarget == gl.TEXTURE_2D) { | |
| 154 gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, format, extens ion.HALF_FLOAT_OES, null); | |
|
Ken Russell (switch to Gerrit)
2013/05/13 20:00:35
You can work around the fact that there's no Float
| |
| 155 if (minFilter != gl.NEAREST && minFilter != gl.LINEAR) | |
| 156 gl.generateMipmap(gl.TEXTURE_2D); | |
| 157 } | |
| 158 else if (textureTarget == gl.TEXTURE_CUBE_MAP) { | |
| 159 var targets = [ | |
| 160 gl.TEXTURE_CUBE_MAP_POSITIVE_X, | |
| 161 gl.TEXTURE_CUBE_MAP_NEGATIVE_X, | |
| 162 gl.TEXTURE_CUBE_MAP_POSITIVE_Y, | |
| 163 gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, | |
| 164 gl.TEXTURE_CUBE_MAP_POSITIVE_Z, | |
| 165 gl.TEXTURE_CUBE_MAP_NEGATIVE_Z]; | |
| 166 for (var tt = 0; tt < targets.length; ++tt) { | |
| 167 gl.texImage2D(targets[tt], 0, format, width, height, 0, format, extension.HALF_FLOAT_OES, null); | |
| 168 } | |
| 169 if (minFilter != gl.NEAREST && minFilter != gl.LINEAR) | |
| 170 gl.generateMipmap(gl.TEXTURE_CUBE_MAP); | |
| 171 } | |
| 172 // wtu.clearAndDrawUnitQuad(gl); | |
| 173 wtu.drawQuad(gl); | |
| 174 if (!linear) { | |
| 175 glErrorShouldBe(gl, gl.NO_ERROR, "floating-point texture with non-Linear filter would succeed no matter OES_texture_half_float_linear is enabled or not" ); | |
| 176 } else if (expectFailure) { | |
| 177 glErrorShouldBe(gl, gl.NO_ERROR, "floating-point texture with Linear fil ter would produe [0, 0, 0, 1.0] if OES_texture_half_float_linear isn't enabled") ; | |
| 178 } else { | |
| 179 glErrorShouldBe(gl, gl.NO_ERROR, "floating-point texture with Linear fil ter would succeed if OES_texture_half_float_linear is enabled"); | |
| 180 } | |
| 181 | |
| 182 wtu.checkCanvas(gl, expected, "should be " + expected[0] + "," + expected[1] + "," + expected[2] + "," + expected[3]); | |
| 183 } | |
| 184 | |
| 185 debug(""); | |
| 186 // Needs to be global for shouldBe to see it. | |
| 187 var pixels; | |
| 188 var successfullyParsed = true; | |
| 189 </script> | |
| 190 <script src="../../resources/js-test-post.js"></script> | |
| 191 | |
| 192 </body> | |
| 193 </html> | |
| OLD | NEW |