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 Non-Power of 2 texture conformance test.</title> |
| 33 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 34 <script src="../../resources/js-test-pre.js"></script> |
| 35 <script src="../resources/webgl-test.js"> </script> |
| 36 <script src="../resources/webgl-test-utils.js"> </script> |
| 37 </head> |
| 38 <body> |
| 39 <canvas id="example" width="4" height="4" style="width: 40px; height: 30px;"></c
anvas> |
| 40 <div id="description"></div> |
| 41 <div id="console"></div> |
| 42 <script id="vshader" type="x-shader/x-vertex"> |
| 43 attribute vec4 vPosition; |
| 44 attribute vec2 texCoord0; |
| 45 varying vec2 texCoord; |
| 46 void main() |
| 47 { |
| 48 gl_Position = vPosition; |
| 49 texCoord = texCoord0; |
| 50 } |
| 51 </script> |
| 52 |
| 53 <script id="fshader" type="x-shader/x-fragment"> |
| 54 precision mediump float; |
| 55 uniform samplerCube tex; |
| 56 varying vec2 texCoord; |
| 57 void main() |
| 58 { |
| 59 gl_FragColor = textureCube(tex, normalize(vec3(texCoord, 1))); |
| 60 } |
| 61 </script> |
| 62 <script> |
| 63 description(document.title); |
| 64 var wtu = WebGLTestUtils; |
| 65 var gl = wtu.create3DContext("example"); |
| 66 var program = wtu.setupTexturedQuad(gl); |
| 67 |
| 68 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
| 69 |
| 70 var tex = gl.createTexture(); |
| 71 |
| 72 // Check that an NPOT texture not on level 0 generates INVALID_VALUE |
| 73 wtu.fillTexture(gl, tex, 5, 3, [0, 192, 128, 255], 1); |
| 74 glErrorShouldBe(gl, gl.INVALID_VALUE, |
| 75 "gl.texImage2D with NPOT texture with level > 0 should return INVALID_VALUE"
); |
| 76 |
| 77 // Check that an NPOT texture on level 0 succeeds |
| 78 wtu.fillTexture(gl, tex, 5, 3, [0, 192, 128, 255]); |
| 79 glErrorShouldBe(gl, gl.NO_ERROR, |
| 80 "gl.texImage2D with NPOT texture at level 0 should succeed"); |
| 81 |
| 82 // Check that generateMipmap fails on NPOT |
| 83 gl.generateMipmap(gl.TEXTURE_2D); |
| 84 glErrorShouldBe(gl, gl.INVALID_OPERATION, |
| 85 "gl.generateMipmap with NPOT texture should return INVALID_OPERATION"); |
| 86 |
| 87 var loc = gl.getUniformLocation(program, "tex"); |
| 88 gl.uniform1i(loc, 0); |
| 89 |
| 90 // Check that nothing is drawn if filtering is not correct for NPOT |
| 91 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
| 92 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
| 93 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); |
| 94 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); |
| 95 |
| 96 wtu.drawQuad(gl); |
| 97 wtu.checkCanvas( |
| 98 gl, [0, 0, 0, 255], |
| 99 "NPOT texture with TEXTURE_WRAP set to REPEAT should draw with 0,0,0,255"); |
| 100 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
| 101 |
| 102 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); |
| 103 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); |
| 104 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR)
; |
| 105 |
| 106 wtu.drawQuad(gl); |
| 107 wtu.checkCanvas( |
| 108 gl, [0, 0, 0, 255], |
| 109 "NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with
0,0,0,255"); |
| 110 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
| 111 |
| 112 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); |
| 113 |
| 114 wtu.drawQuad(gl); |
| 115 wtu.checkCanvas( |
| 116 gl, [0, 192, 128, 255], |
| 117 "NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw."); |
| 118 |
| 119 gl.copyTexImage2D(gl.TEXTURE_2D, 1, gl.RGBA, 0, 0, 5, 3, 0); |
| 120 glErrorShouldBe(gl, gl.INVALID_VALUE, |
| 121 "copyTexImage2D with NPOT texture with level > 0 should return INVALID_VALUE
."); |
| 122 |
| 123 // Check that generateMipmap for an POT texture succeeds |
| 124 wtu.fillTexture(gl, tex, 4, 4, [0, 192, 128, 255]); |
| 125 gl.generateMipmap(gl.TEXTURE_2D); |
| 126 glErrorShouldBe(gl, gl.NO_ERROR, |
| 127 "gl.texImage2D and gl.generateMipmap with POT texture at level 0 should succ
eed"); |
| 128 |
| 129 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR); |
| 130 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); |
| 131 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); |
| 132 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); |
| 133 |
| 134 wtu.drawQuad(gl); |
| 135 wtu.checkCanvas( |
| 136 gl, [0, 192, 128, 255], |
| 137 "POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
."); |
| 138 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
| 139 |
| 140 debug(""); |
| 141 debug("check using cubemap"); |
| 142 var program = wtu.setupProgram( |
| 143 gl, ['vshader', 'fshader'], ['vPosition', 'texCoord0'], [0, 1]); |
| 144 var tex = gl.createTexture(); |
| 145 |
| 146 // Check that an NPOT texture not on level 0 generates INVALID_VALUE |
| 147 fillCubeTexture(gl, tex, 5, 3, [0, 192, 128, 255], 1); |
| 148 glErrorShouldBe(gl, gl.INVALID_VALUE, |
| 149 "gl.texImage2D with NPOT texture with level > 0 should return INVALID_VALUE"
); |
| 150 |
| 151 // Check that an NPOT texture on level 0 succeeds |
| 152 fillCubeTexture(gl, tex, 5, 5, [0, 192, 128, 255]); |
| 153 glErrorShouldBe(gl, gl.NO_ERROR, |
| 154 "gl.texImage2D with NPOT texture at level 0 should succeed"); |
| 155 |
| 156 // Check that generateMipmap fails on NPOT |
| 157 gl.generateMipmap(gl.TEXTURE_CUBE_MAP); |
| 158 glErrorShouldBe(gl, gl.INVALID_OPERATION, |
| 159 "gl.generateMipmap with NPOT texture should return INVALID_OPERATION"); |
| 160 |
| 161 var loc = gl.getUniformLocation(program, "tex"); |
| 162 gl.uniform1i(loc, 0); |
| 163 |
| 164 // Check that nothing is drawn if filtering is not correct for NPOT |
| 165 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
| 166 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
| 167 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.REPEAT); |
| 168 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.REPEAT); |
| 169 |
| 170 wtu.drawQuad(gl); |
| 171 wtu.checkCanvas( |
| 172 gl, [0, 0, 0, 255], |
| 173 "NPOT cubemap with TEXTURE_WRAP set to REPEAT should draw with 0,0,0,255"); |
| 174 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
| 175 |
| 176 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); |
| 177 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); |
| 178 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_L
INEAR); |
| 179 |
| 180 wtu.drawQuad(gl); |
| 181 wtu.checkCanvas( |
| 182 gl, [0, 0, 0, 255], |
| 183 "NPOT cubemap with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with
0,0,0,255"); |
| 184 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
| 185 |
| 186 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR); |
| 187 |
| 188 wtu.drawQuad(gl); |
| 189 wtu.checkCanvas( |
| 190 gl, [0, 192, 128, 255], |
| 191 "NPOT cubemap with TEXTURE_MIN_FILTER set to LINEAR should draw."); |
| 192 |
| 193 // Check that an POT texture on level 0 succeeds |
| 194 fillCubeTexture(gl, tex, 4, 4, [0, 192, 128, 255]); |
| 195 glErrorShouldBe(gl, gl.NO_ERROR, |
| 196 "gl.texImage2D with POT texture at level 0 should succeed"); |
| 197 |
| 198 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LI
NEAR); |
| 199 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR); |
| 200 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.REPEAT); |
| 201 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.REPEAT); |
| 202 |
| 203 wtu.drawQuad(gl); |
| 204 wtu.checkCanvas( |
| 205 gl, [0, 0, 0, 255], |
| 206 "POT cubemap with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR but no mips
draw with 0,0,0,255"); |
| 207 |
| 208 // Check that generateMipmap succeeds on POT |
| 209 gl.generateMipmap(gl.TEXTURE_CUBE_MAP); |
| 210 glErrorShouldBe(gl, gl.NO_ERROR, |
| 211 "gl.generateMipmap with POT texture should return succeed"); |
| 212 |
| 213 wtu.drawQuad(gl); |
| 214 wtu.checkCanvas( |
| 215 gl, [0, 192, 128, 255], |
| 216 "POT cubemap with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
."); |
| 217 |
| 218 successfullyParsed = true; |
| 219 |
| 220 function fillCubeTexture(gl, tex, width, height, color, opt_level) { |
| 221 opt_level = opt_level || 0; |
| 222 var canvas = document.createElement('canvas'); |
| 223 canvas.width = width; |
| 224 canvas.height = height; |
| 225 var ctx2d = canvas.getContext('2d'); |
| 226 ctx2d.fillStyle = "rgba(" + color[0] + "," + color[1] + "," + color[2] + "," +
color[3] + ")"; |
| 227 ctx2d.fillRect(0, 0, width, height); |
| 228 gl.bindTexture(gl.TEXTURE_CUBE_MAP, tex); |
| 229 var targets = [ |
| 230 gl.TEXTURE_CUBE_MAP_POSITIVE_X, |
| 231 gl.TEXTURE_CUBE_MAP_NEGATIVE_X, |
| 232 gl.TEXTURE_CUBE_MAP_POSITIVE_Y, |
| 233 gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, |
| 234 gl.TEXTURE_CUBE_MAP_POSITIVE_Z, |
| 235 gl.TEXTURE_CUBE_MAP_NEGATIVE_Z]; |
| 236 for (var tt = 0; tt < targets.length; ++tt) { |
| 237 gl.texImage2D( |
| 238 targets[tt], opt_level, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas); |
| 239 } |
| 240 }; |
| 241 |
| 242 </script> |
| 243 <script src="../../resources/js-test-post.js"></script> |
| 244 |
| 245 </body> |
| 246 </html> |
| 247 |
OLD | NEW |