Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!-- | |
| 2 | |
| 3 /* | |
| 4 ** Copyright (c) 2012 The Khronos Group Inc. | |
|
Ken Russell (switch to Gerrit)
2013/05/13 20:00:35
2013.
| |
| 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_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 --> | |
| 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(4.0, 2.0, 0.5, 1); | |
| 49 } | |
| 50 </script> | |
| 51 <script id="texCubFshader" type="x-shader/x-fragment"> | |
|
Ken Russell (switch to Gerrit)
2013/05/13 20:00:35
Typo here and throughout: texCubFshader -> texCube
| |
| 52 uniform samplerCube tex; | |
| 53 void main() | |
| 54 { | |
| 55 gl_FragColor = textureCube(tex, normalize(vec3(0.5, 0.5, 1))) * vec4(4.0, 2. 0, 0.5, 1); | |
| 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_float_linea r extension, if it is available."); | |
| 69 | |
| 70 debug(""); | |
| 71 | |
| 72 var wtu = WebGLTestUtils; | |
| 73 var canvas = document.getElementById("canvas"); | |
| 74 var gl = wtu.create3DContext(canvas); | |
| 75 if (!gl) { | |
| 76 testFailed("WebGL context does not exist"); | |
| 77 } else { | |
| 78 testPassed("WebGL context exists"); | |
| 79 | |
| 80 if (!gl.getExtension("OES_texture_float")) { | |
| 81 testPassed("No OES_texture_float support -- this is legal"); | |
| 82 } else { | |
| 83 testPassed("Successfully enabled OES_texture_float extension"); | |
| 84 | |
| 85 // Before OES_texture_float_linear extension is enabled | |
| 86 var extensionEabled = false; | |
| 87 runTestSuit(extensionEabled); | |
|
Ken Russell (switch to Gerrit)
2013/05/13 20:00:35
Typo here and throughout: runTestSuit -> runTestSu
| |
| 88 | |
| 89 if (!gl.getExtension("OES_texture_float_linear")) | |
| 90 testPassed("No OES_texture_float_linear support -- this is legal"); | |
| 91 else { | |
| 92 // OES_texture_float_linear extension is enabled | |
| 93 extensionEabled = true; | |
| 94 runTestSuit(extensionEabled); | |
| 95 } | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 function runTestSuit(extensionEabled) | |
|
Ken Russell (switch to Gerrit)
2013/05/13 20:00:35
Typo here and throughout: extensionEabled -> exten
| |
| 100 { | |
| 101 var magF = [gl.NEAREST, gl.LINEAR]; | |
| 102 var minF = [gl.NEAREST, gl.LINEAR, gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST_MIP MAP_LINEAR, gl.LINEAR_MIPMAP_NEAREST, gl.LINEAR_MIPMAP_LINEAR]; | |
| 103 // TEXTURE_2D | |
| 104 var program = wtu.setupProgram(gl, ["positionVertexShader", "testFragmentSha der"]); | |
| 105 gl.useProgram(program); | |
| 106 wtu.setupUnitQuad(gl); | |
| 107 for (var kk = 0; kk < 2; ++kk) { | |
| 108 for (var ii = 0; ii < 6; ++ii) { | |
| 109 var linear = false; | |
| 110 if (magF[kk] == gl.LINEAR || (minF[ii] != gl.NEAREST && minF[ii] != gl.NEAREST_MIPMAP_NEAREST)) | |
| 111 linear = true; | |
| 112 var color = (!extensionEabled && linear) ? [0, 0, 0, 255] : [255, 25 5, 255, 255]; | |
| 113 runEachTest(gl.TEXTURE_2D, magF[kk], minF[ii], linear, extensionEabl ed, color, linear); | |
| 114 } | |
| 115 } | |
| 116 | |
| 117 // TEXTURE_CUBE_MAP | |
| 118 var programCube = wtu.setupProgram(gl, ["positionVertexShader", "texCubFshad er"]); | |
| 119 gl.useProgram(programCube); | |
| 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] : [255, 25 5, 255, 255]; | |
| 127 runEachTest(gl.TEXTURE_CUBE_MAP, magF[kk], minF[ii], linear, extensi onEabled, color, linear); | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 } | |
| 132 | |
| 133 function runEachTest(textureTarget, magFilter, minFilter, linear, extensionEnabl ed, expected, expectFailure) | |
|
Ken Russell (switch to Gerrit)
2013/05/13 20:00:35
The "expectFailure" argument should be removed; se
| |
| 134 { | |
| 135 var format = gl.RGBA; | |
| 136 var numberOfChannels = 4; | |
| 137 debug(""); | |
| 138 debug("testing target: " + wtu.glEnumToString(gl,textureTarget) + | |
| 139 ", testing format: " + wtu.glEnumToString(gl, format) + | |
| 140 ", magFilter is: " + wtu.glEnumToString(gl, magFilter) + | |
| 141 ", minFilter is: " + wtu.glEnumToString(gl, minFilter) + | |
| 142 ", OES_texture_float_linear is " + (extensionEnabled ? "enabled": "no t enabled") | |
| 143 ); | |
| 144 var texture = gl.createTexture(); | |
| 145 // Generate data. | |
| 146 var width = 1; | |
| 147 var height = 1; | |
|
Ken Russell (switch to Gerrit)
2013/05/13 20:00:35
Please use a larger texture, at least 2x2 if not 4
Jun Jiang
2013/05/14 02:04:00
I used size 4x4 in test and changed to 1*1 when up
| |
| 148 var color = [0.25, 0.5, 2.0, 1.0]; | |
| 149 var data = new Float32Array(width * height * numberOfChannels); | |
| 150 for (var ii = 0; ii < width; ++ii) | |
| 151 for (var jj = 0; jj < height; ++jj) | |
| 152 for (var kk = 0; kk < numberOfChannels; kk++) | |
| 153 data[(jj* width + ii)*numberOfChannels + kk] = color[kk]; | |
| 154 | |
| 155 gl.bindTexture(textureTarget, texture); | |
| 156 gl.texParameteri(textureTarget, gl.TEXTURE_MAG_FILTER, magFilter); | |
| 157 gl.texParameteri(textureTarget, gl.TEXTURE_MIN_FILTER, minFilter); | |
| 158 gl.texParameteri(textureTarget, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | |
| 159 gl.texParameteri(textureTarget, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); | |
| 160 | |
| 161 if (textureTarget == gl.TEXTURE_2D) { | |
| 162 gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, format, gl.FLO AT, data); | |
| 163 if (minFilter != gl.NEAREST && minFilter != gl.LINEAR) | |
| 164 gl.generateMipmap(gl.TEXTURE_2D); | |
| 165 } | |
| 166 else if (textureTarget == gl.TEXTURE_CUBE_MAP) { | |
| 167 var targets = [ | |
| 168 gl.TEXTURE_CUBE_MAP_POSITIVE_X, | |
| 169 gl.TEXTURE_CUBE_MAP_NEGATIVE_X, | |
| 170 gl.TEXTURE_CUBE_MAP_POSITIVE_Y, | |
| 171 gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, | |
| 172 gl.TEXTURE_CUBE_MAP_POSITIVE_Z, | |
| 173 gl.TEXTURE_CUBE_MAP_NEGATIVE_Z]; | |
| 174 for (var tt = 0; tt < targets.length; ++tt) { | |
| 175 gl.texImage2D(targets[tt], 0, format, width, height, 0, format, gl.FLOAT, data); | |
| 176 } | |
| 177 if (minFilter != gl.NEAREST && minFilter != gl.LINEAR) | |
| 178 gl.generateMipmap(gl.TEXTURE_CUBE_MAP); | |
| 179 } | |
| 180 // wtu.clearAndDrawUnitQuad(gl); | |
|
Ken Russell (switch to Gerrit)
2013/05/13 20:00:35
Remove commented-out code.
| |
| 181 wtu.drawQuad(gl); | |
| 182 if (!linear) { | |
|
Ken Russell (switch to Gerrit)
2013/05/13 20:00:35
The error checks here are incorrect.
According to
Jun Jiang
2013/05/14 02:04:00
Thanks for your comments.
Here I set the texture s
| |
| 183 glErrorShouldBe(gl, gl.NO_ERROR, "floating-point texture with non-Linear filter would succeed no matter OES_texture_float_linear is enabled or not"); | |
| 184 } else if (expectFailure) { | |
| 185 glErrorShouldBe(gl, gl.NO_ERROR, "floating-point texture with Linear fil ter would produe [0, 0, 0, 1.0] if OES_texture_float_linear isn't enabled"); | |
| 186 } else { | |
| 187 glErrorShouldBe(gl, gl.NO_ERROR, "floating-point texture with Linear fil ter would succeed if OES_texture_float_linear is enabled"); | |
| 188 } | |
| 189 | |
| 190 wtu.checkCanvas(gl, expected, "should be " + expected[0] + "," + expected[1] + "," + expected[2] + "," + expected[3]); | |
| 191 } | |
| 192 | |
| 193 debug(""); | |
| 194 // Needs to be global for shouldBe to see it. | |
| 195 var pixels; | |
| 196 var successfullyParsed = true; | |
| 197 </script> | |
| 198 <script src="../../resources/js-test-post.js"></script> | |
| 199 | |
| 200 </body> | |
| 201 </html> | |
| OLD | NEW |