1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/conformance/textures/texture-npot.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,225 @@ 1.4 +<!-- 1.5 +Copyright (c) 2011 The Chromium Authors. All rights reserved. 1.6 +Use of this source code is governed by a BSD-style license that can be 1.7 +found in the LICENSE file. 1.8 + --> 1.9 +<!DOCTYPE html> 1.10 +<html> 1.11 +<head> 1.12 +<meta charset="utf-8"> 1.13 +<title>WebGL Non-Power of 2 texture conformance test.</title> 1.14 +<link rel="stylesheet" href="../../resources/js-test-style.css"/> 1.15 +<script src="../../resources/js-test-pre.js"></script> 1.16 +<script src="../resources/webgl-test.js"> </script> 1.17 +<script src="../resources/webgl-test-utils.js"> </script> 1.18 +</head> 1.19 +<body> 1.20 +<canvas id="example" width="4" height="4" style="width: 40px; height: 30px;"></canvas> 1.21 +<div id="description"></div> 1.22 +<div id="console"></div> 1.23 +<script id="vshader" type="x-shader/x-vertex"> 1.24 +attribute vec4 vPosition; 1.25 +attribute vec2 texCoord0; 1.26 +varying vec2 texCoord; 1.27 +void main() 1.28 +{ 1.29 + gl_Position = vPosition; 1.30 + texCoord = texCoord0; 1.31 +} 1.32 +</script> 1.33 + 1.34 +<script id="fshader" type="x-shader/x-fragment"> 1.35 +precision mediump float; 1.36 +uniform samplerCube tex; 1.37 +varying vec2 texCoord; 1.38 +void main() 1.39 +{ 1.40 + gl_FragColor = textureCube(tex, normalize(vec3(texCoord, 1))); 1.41 +} 1.42 +</script> 1.43 +<script> 1.44 +description(document.title); 1.45 +var wtu = WebGLTestUtils; 1.46 +var gl = wtu.create3DContext("example"); 1.47 +var program = wtu.setupTexturedQuad(gl); 1.48 + 1.49 +glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); 1.50 + 1.51 +var tex = gl.createTexture(); 1.52 + 1.53 +// Check that an NPOT texture not on level 0 generates INVALID_VALUE 1.54 +wtu.fillTexture(gl, tex, 5, 3, [0, 192, 128, 255], 1); 1.55 +glErrorShouldBe(gl, gl.INVALID_VALUE, 1.56 + "gl.texImage2D with NPOT texture with level > 0 should return INVALID_VALUE"); 1.57 + 1.58 +// Check that an NPOT texture on level 0 succeeds 1.59 +wtu.fillTexture(gl, tex, 5, 3, [0, 192, 128, 255]); 1.60 +glErrorShouldBe(gl, gl.NO_ERROR, 1.61 + "gl.texImage2D with NPOT texture at level 0 should succeed"); 1.62 + 1.63 +// Check that generateMipmap fails on NPOT 1.64 +gl.generateMipmap(gl.TEXTURE_2D); 1.65 +glErrorShouldBe(gl, gl.INVALID_OPERATION, 1.66 + "gl.generateMipmap with NPOT texture should return INVALID_OPERATION"); 1.67 + 1.68 +var loc = gl.getUniformLocation(program, "tex"); 1.69 +gl.uniform1i(loc, 0); 1.70 + 1.71 +// Check that nothing is drawn if filtering is not correct for NPOT 1.72 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); 1.73 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); 1.74 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); 1.75 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); 1.76 + 1.77 +wtu.drawQuad(gl); 1.78 +wtu.checkCanvas( 1.79 + gl, [0, 0, 0, 255], 1.80 + "NPOT texture with TEXTURE_WRAP set to REPEAT should draw with 0,0,0,255"); 1.81 +glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); 1.82 + 1.83 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 1.84 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 1.85 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR); 1.86 + 1.87 +wtu.drawQuad(gl); 1.88 +wtu.checkCanvas( 1.89 + gl, [0, 0, 0, 255], 1.90 + "NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255"); 1.91 +glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); 1.92 + 1.93 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); 1.94 + 1.95 +wtu.drawQuad(gl); 1.96 +wtu.checkCanvas( 1.97 + gl, [0, 192, 128, 255], 1.98 + "NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw."); 1.99 + 1.100 +gl.copyTexImage2D(gl.TEXTURE_2D, 1, gl.RGBA, 0, 0, 5, 3, 0); 1.101 +glErrorShouldBe(gl, gl.INVALID_VALUE, 1.102 + "copyTexImage2D with NPOT texture with level > 0 should return INVALID_VALUE."); 1.103 + 1.104 +// Check that generateMipmap for an POT texture succeeds 1.105 +wtu.fillTexture(gl, tex, 4, 4, [0, 192, 128, 255]); 1.106 +gl.generateMipmap(gl.TEXTURE_2D); 1.107 +glErrorShouldBe(gl, gl.NO_ERROR, 1.108 + "gl.texImage2D and gl.generateMipmap with POT texture at level 0 should succeed"); 1.109 + 1.110 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR); 1.111 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); 1.112 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); 1.113 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); 1.114 + 1.115 +wtu.drawQuad(gl); 1.116 +wtu.checkCanvas( 1.117 + gl, [0, 192, 128, 255], 1.118 + "POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw."); 1.119 +glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); 1.120 + 1.121 +debug(""); 1.122 +debug("check using cubemap"); 1.123 +var program = wtu.setupProgram( 1.124 + gl, ['vshader', 'fshader'], ['vPosition', 'texCoord0'], [0, 1]); 1.125 +var tex = gl.createTexture(); 1.126 + 1.127 +// Check that an NPOT texture not on level 0 generates INVALID_VALUE 1.128 +fillCubeTexture(gl, tex, 5, 3, [0, 192, 128, 255], 1); 1.129 +glErrorShouldBe(gl, gl.INVALID_VALUE, 1.130 + "gl.texImage2D with NPOT texture with level > 0 should return INVALID_VALUE"); 1.131 + 1.132 +// Check that an NPOT texture on level 0 succeeds 1.133 +fillCubeTexture(gl, tex, 5, 5, [0, 192, 128, 255]); 1.134 +glErrorShouldBe(gl, gl.NO_ERROR, 1.135 + "gl.texImage2D with NPOT texture at level 0 should succeed"); 1.136 + 1.137 +// Check that generateMipmap fails on NPOT 1.138 +gl.generateMipmap(gl.TEXTURE_CUBE_MAP); 1.139 +glErrorShouldBe(gl, gl.INVALID_OPERATION, 1.140 + "gl.generateMipmap with NPOT texture should return INVALID_OPERATION"); 1.141 + 1.142 +var loc = gl.getUniformLocation(program, "tex"); 1.143 +gl.uniform1i(loc, 0); 1.144 + 1.145 +// Check that nothing is drawn if filtering is not correct for NPOT 1.146 +gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.NEAREST); 1.147 +gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.NEAREST); 1.148 +gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.REPEAT); 1.149 +gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.REPEAT); 1.150 + 1.151 +wtu.drawQuad(gl); 1.152 +wtu.checkCanvas( 1.153 + gl, [0, 0, 0, 255], 1.154 + "NPOT cubemap with TEXTURE_WRAP set to REPEAT should draw with 0,0,0,255"); 1.155 +glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); 1.156 + 1.157 +gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 1.158 +gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 1.159 +gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR); 1.160 + 1.161 +wtu.drawQuad(gl); 1.162 +wtu.checkCanvas( 1.163 + gl, [0, 0, 0, 255], 1.164 + "NPOT cubemap with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255"); 1.165 +glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); 1.166 + 1.167 +gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR); 1.168 + 1.169 +wtu.drawQuad(gl); 1.170 +wtu.checkCanvas( 1.171 + gl, [0, 192, 128, 255], 1.172 + "NPOT cubemap with TEXTURE_MIN_FILTER set to LINEAR should draw."); 1.173 + 1.174 +// Check that an POT texture on level 0 succeeds 1.175 +fillCubeTexture(gl, tex, 4, 4, [0, 192, 128, 255]); 1.176 +glErrorShouldBe(gl, gl.NO_ERROR, 1.177 + "gl.texImage2D with POT texture at level 0 should succeed"); 1.178 + 1.179 +gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR); 1.180 +gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR); 1.181 +gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.REPEAT); 1.182 +gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.REPEAT); 1.183 + 1.184 +wtu.drawQuad(gl); 1.185 +wtu.checkCanvas( 1.186 + gl, [0, 0, 0, 255], 1.187 + "POT cubemap with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR but no mips draw with 0,0,0,255"); 1.188 + 1.189 +// Check that generateMipmap succeeds on POT 1.190 +gl.generateMipmap(gl.TEXTURE_CUBE_MAP); 1.191 +glErrorShouldBe(gl, gl.NO_ERROR, 1.192 + "gl.generateMipmap with POT texture should return succeed"); 1.193 + 1.194 +wtu.drawQuad(gl); 1.195 +wtu.checkCanvas( 1.196 + gl, [0, 192, 128, 255], 1.197 + "POT cubemap with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw."); 1.198 + 1.199 +successfullyParsed = true; 1.200 + 1.201 +function fillCubeTexture(gl, tex, width, height, color, opt_level) { 1.202 + opt_level = opt_level || 0; 1.203 + var canvas = document.createElement('canvas'); 1.204 + canvas.width = width; 1.205 + canvas.height = height; 1.206 + var ctx2d = canvas.getContext('2d'); 1.207 + ctx2d.fillStyle = "rgba(" + color[0] + "," + color[1] + "," + color[2] + "," + color[3] + ")"; 1.208 + ctx2d.fillRect(0, 0, width, height); 1.209 + gl.bindTexture(gl.TEXTURE_CUBE_MAP, tex); 1.210 + var targets = [ 1.211 + gl.TEXTURE_CUBE_MAP_POSITIVE_X, 1.212 + gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 1.213 + gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 1.214 + gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 1.215 + gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 1.216 + gl.TEXTURE_CUBE_MAP_NEGATIVE_Z]; 1.217 + for (var tt = 0; tt < targets.length; ++tt) { 1.218 + gl.texImage2D( 1.219 + targets[tt], opt_level, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas); 1.220 + } 1.221 +}; 1.222 + 1.223 +</script> 1.224 +<script>finishTest();</script> 1.225 + 1.226 +</body> 1.227 +</html> 1.228 +