1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/conformance/textures/texture-formats-test.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,251 @@ 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 Texture Format Conformance Tests</title> 1.14 +<link rel="stylesheet" href="../../resources/js-test-style.css"/> 1.15 +<script src="../../resources/desktop-gl-constants.js" type="text/javascript"></script> 1.16 +<script src="../../debug/webgl-debug.js" type="text/javascript"></script> 1.17 +<script src="../../resources/js-test-pre.js"></script> 1.18 +<script src="../resources/webgl-test.js"></script> 1.19 +<script src="../resources/webgl-test-utils.js"></script> 1.20 +</head> 1.21 +<body> 1.22 +<div id="description"></div> 1.23 +<div id="console"></div> 1.24 +<canvas id="canvas2d" width="2" height="2" style="width: 50px; height: 50px; border: 1px solid black;"></canvas> 1.25 +<canvas id="canvas" width="2" height="2" style="width: 100px; height:100px; border: 1px solid black;"> </canvas> 1.26 +<script> 1.27 +description("This test ensures WebGL implementations allow the OpenGL ES 2.0 texture formats and do not allow DesktopGL texture formats."); 1.28 + 1.29 +debug(""); 1.30 +debug("Canvas.getContext"); 1.31 + 1.32 +var wtu = WebGLTestUtils; 1.33 +var gl = wtu.create3DContext(document.getElementById("canvas")); 1.34 +if (!gl) { 1.35 + testFailed("context does not exist"); 1.36 +} else { 1.37 + testPassed("context exists"); 1.38 + if ("WebGLDebugUtils" in window) 1.39 + WebGLDebugUtils.init(gl); 1.40 + else 1.41 + WebGLDebugUtils = false; 1.42 + 1.43 + debug(""); 1.44 + debug("Checking texture formats."); 1.45 + 1.46 + function createTexture(internalFormat, format, opt_border) { 1.47 + var border = (opt_border === undefined) ? 0 : opt_border; 1.48 + var tex = gl.createTexture(); 1.49 + gl.bindTexture(gl.TEXTURE_2D, tex); 1.50 + gl.texImage2D(gl.TEXTURE_2D, 1.51 + 0, // level 1.52 + internalFormat, // internalFormat 1.53 + 16, // width 1.54 + 16, // height 1.55 + border, // border 1.56 + format, // format 1.57 + gl.UNSIGNED_BYTE, // type 1.58 + null); // data 1.59 + } 1.60 + 1.61 + function testValidFormat(internalFormat, formatName) { 1.62 + createTexture(internalFormat, internalFormat); 1.63 + glErrorShouldBe(gl, gl.NO_ERROR, 1.64 + "was able to create texture of " + formatName); 1.65 + } 1.66 + 1.67 + function testInvalidFormat(internalFormat, formatName) { 1.68 + createTexture(internalFormat, internalFormat); 1.69 + var err = gl.getError(); 1.70 + if (err == gl.NO_ERROR) { 1.71 + testFailed("should NOT be able to create texture of type " + formatName); 1.72 + } else if (err == gl.INVALID_OPERATION) { 1.73 + testFailed("should return gl.INVALID_ENUM for type " + formatName); 1.74 + } else if (err == gl.INVALID_ENUM) { 1.75 + testPassed("not able to create invalid format: " + formatName); 1.76 + } 1.77 + } 1.78 + 1.79 + var invalidEnums = [ 1.80 + '1', 1.81 + '2', 1.82 + '3', 1.83 + '4', 1.84 + 'RGB4', 1.85 + 'RGB5', 1.86 + 'RGB8', 1.87 + 'RGB10', 1.88 + 'RGB12', 1.89 + 'RGB16', 1.90 + 'RGBA2', 1.91 + 'RGBA4', 1.92 + 'RGB5_A1', 1.93 + 'RGBA8', 1.94 + 'RGB10_A2', 1.95 + 'RGBA12', 1.96 + 'RGBA16', 1.97 + 'BGR', 1.98 + 'BGRA', 1.99 + 'ALPHA4_EXT', 1.100 + 'ALPHA8_EXT', 1.101 + 'ALPHA12_EXT', 1.102 + 'ALPHA16_EXT', 1.103 + 'COMPRESSED_ALPHA', 1.104 + 'COMPRESSED_LUMINANCE', 1.105 + 'COMPRESSED_LUMINANCE_ALPHA', 1.106 + 'COMPRESSED_INTENSITY', 1.107 + 'COMPRESSED_RGB', 1.108 + 'COMPRESSED_RGBA', 1.109 + 'DEPTH_COMPONENT16', 1.110 + 'DEPTH_COMPONENT24', 1.111 + 'DEPTH_COMPONENT32', 1.112 + 'LUMINANCE4_EXT', 1.113 + 'LUMINANCE8_EXT', 1.114 + 'LUMINANCE12_EXT', 1.115 + 'LUMINANCE16_EXT', 1.116 + 'LUMINANCE4_ALPHA4_EXT', 1.117 + 'LUMINANCE6_ALPHA2_EXT', 1.118 + 'LUMINANCE8_ALPHA8_EXT', 1.119 + 'LUMINANCE12_ALPHA4_EXT', 1.120 + 'LUMINANCE12_ALPHA12_EXT', 1.121 + 'LUMINANCE16_ALPHA16_EXT', 1.122 + 'INTENSITY_EXT', 1.123 + 'INTENSITY4_EXT', 1.124 + 'INTENSITY8_EXT', 1.125 + 'INTENSITY12_EXT', 1.126 + 'INTENSITY16_EXT', 1.127 + 'RGB4_EXT', 1.128 + 'RGB5_EXT', 1.129 + 'RGB8_EXT', 1.130 + 'RGB10_EXT', 1.131 + 'RGB12_EXT', 1.132 + 'RGB16_EXT', 1.133 + 'RGBA2_EXT', 1.134 + 'RGBA4_EXT', 1.135 + 'RGB5_A1_EXT', 1.136 + 'RGBA8_EXT', 1.137 + 'RGB10_A2_EXT', 1.138 + 'RGBA12_EXT', 1.139 + 'RGBA16_EXT', 1.140 + 'SLUMINANCE_EXT', 1.141 + 'SLUMINANCE8_EXT', 1.142 + 'SLUMINANCE_ALPHA_EXT', 1.143 + 'SLUMINANCE8_ALPHA8_EXT', 1.144 + 'SRGB_EXT', 1.145 + 'SRGB8_EXT', 1.146 + 'SRGB_ALPHA_EXT', 1.147 + 'SRGB8_ALPHA8' 1.148 + ]; 1.149 + 1.150 + for (var ii = 0; ii < invalidEnums.length; ++ii) { 1.151 + var formatName = invalidEnums[ii] 1.152 + if (desktopGL[formatName] === undefined) { 1.153 + debug("bad format" + formatName) 1.154 + } else { 1.155 + testInvalidFormat(desktopGL[formatName], "GL_" + formatName); 1.156 + } 1.157 + } 1.158 + 1.159 + var validEnums = [ 1.160 + 'ALPHA', 1.161 + 'RGB', 1.162 + 'RGBA', 1.163 + 'LUMINANCE', 1.164 + 'LUMINANCE_ALPHA' 1.165 + ]; 1.166 + 1.167 + for (var ii = 0; ii < validEnums.length; ++ii) { 1.168 + var formatName = validEnums[ii] 1.169 + testValidFormat(gl[formatName], "gl." + formatName); 1.170 + } 1.171 + 1.172 + debug(""); 1.173 + debug("checking non 0 border parameter to gl.TexImage2D"); 1.174 + createTexture(gl['RGBA'], gl['RGBA'], 1); 1.175 + glErrorShouldBe(gl, gl.INVALID_VALUE, 1.176 + "non 0 border to gl.TexImage2D should return INVALID_VALUE"); 1.177 + 1.178 + 1.179 + function checkTypes() { 1.180 + var canvas = document.getElementById("canvas"); 1.181 + gl = wtu.create3DContext(canvas); 1.182 + var program = wtu.setupTexturedQuad(gl); 1.183 + 1.184 + gl.disable(gl.DEPTH_TEST); 1.185 + gl.disable(gl.BLEND); 1.186 + 1.187 + var tex = gl.createTexture(); 1.188 + gl.bindTexture(gl.TEXTURE_2D, tex); 1.189 + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 1.190 + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 1.191 + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); 1.192 + 1.193 + var loc = gl.getUniformLocation(program, "tex"); 1.194 + gl.uniform1i(loc, 0); 1.195 + 1.196 + function checkType(r, g, b, a, type, format, buf) { 1.197 + var typeName = WebGLDebugUtils ? WebGLDebugUtils.glEnumToString(type) : type; 1.198 + debug(""); 1.199 + debug("checking gl.texImage2D with type: " + typeName); 1.200 + gl.texImage2D(gl.TEXTURE_2D, 1.201 + 0, // level 1.202 + format, // internalFormat 1.203 + 2, // width 1.204 + 2, // height 1.205 + 0, // border 1.206 + format, // format 1.207 + type, // type 1.208 + buf); // data 1.209 + 1.210 + glErrorShouldBe(gl, gl.NO_ERROR, 1.211 + "gl.texImage2D with " + typeName + " should generate NO_ERROR"); 1.212 + 1.213 + wtu.drawQuad(gl, [255, 0, 0, 255]); 1.214 + wtu.checkCanvas(gl, [r,g,b,a], 1.215 + "texture type " + typeName + " should draw with " + 1.216 + r + ", " + g + ", " + b + ", " + a); 1.217 + 1.218 + } 1.219 + checkType(0, 255, 0, 255, gl.UNSIGNED_BYTE, gl.RGBA, 1.220 + new Uint8Array([ 1.221 + 0, 255, 0, 255, 1.222 + 0, 255, 0, 255, 1.223 + 0, 255, 0, 255, 1.224 + 0, 255, 0, 255])); 1.225 + checkType(0, 0, 255, 255, gl.UNSIGNED_SHORT_4_4_4_4, gl.RGBA, 1.226 + new Uint16Array([ 1.227 + 255, 255, 1.228 + 255, 255, 1.229 + 255, 255, 1.230 + 255, 255])); 1.231 + checkType(0, 255, 0, 255, gl.UNSIGNED_SHORT_5_6_5, gl.RGB, 1.232 + new Uint16Array([ 1.233 + 2016, 2016, 1.234 + 2016, 2016, 1.235 + 2016, 2016, 1.236 + 2016, 2016])); 1.237 + checkType(0, 0, 255, 255, gl.UNSIGNED_SHORT_5_5_5_1, gl.RGBA, 1.238 + new Uint16Array([ 1.239 + 63, 63, 1.240 + 63, 63, 1.241 + 63, 63, 1.242 + 63, 63])); 1.243 + } 1.244 + checkTypes(); 1.245 +} 1.246 + 1.247 +debug(""); 1.248 +successfullyParsed = true; 1.249 + 1.250 +</script> 1.251 +<script>finishTest();</script> 1.252 + 1.253 +</body> 1.254 +</html>