Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | <!-- |
michael@0 | 2 | Copyright (c) 2011 The Chromium Authors. All rights reserved. |
michael@0 | 3 | Use of this source code is governed by a BSD-style license that can be |
michael@0 | 4 | found in the LICENSE file. |
michael@0 | 5 | --> |
michael@0 | 6 | <!DOCTYPE html> |
michael@0 | 7 | <html> |
michael@0 | 8 | <head> |
michael@0 | 9 | <meta charset="utf-8"> |
michael@0 | 10 | <title>WebGL Texture Format Conformance Tests</title> |
michael@0 | 11 | <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
michael@0 | 12 | <script src="../../resources/desktop-gl-constants.js" type="text/javascript"></script> |
michael@0 | 13 | <script src="../../debug/webgl-debug.js" type="text/javascript"></script> |
michael@0 | 14 | <script src="../../resources/js-test-pre.js"></script> |
michael@0 | 15 | <script src="../resources/webgl-test.js"></script> |
michael@0 | 16 | <script src="../resources/webgl-test-utils.js"></script> |
michael@0 | 17 | </head> |
michael@0 | 18 | <body> |
michael@0 | 19 | <div id="description"></div> |
michael@0 | 20 | <div id="console"></div> |
michael@0 | 21 | <canvas id="canvas2d" width="2" height="2" style="width: 50px; height: 50px; border: 1px solid black;"></canvas> |
michael@0 | 22 | <canvas id="canvas" width="2" height="2" style="width: 100px; height:100px; border: 1px solid black;"> </canvas> |
michael@0 | 23 | <script> |
michael@0 | 24 | description("This test ensures WebGL implementations allow the OpenGL ES 2.0 texture formats and do not allow DesktopGL texture formats."); |
michael@0 | 25 | |
michael@0 | 26 | debug(""); |
michael@0 | 27 | debug("Canvas.getContext"); |
michael@0 | 28 | |
michael@0 | 29 | var wtu = WebGLTestUtils; |
michael@0 | 30 | var gl = wtu.create3DContext(document.getElementById("canvas")); |
michael@0 | 31 | if (!gl) { |
michael@0 | 32 | testFailed("context does not exist"); |
michael@0 | 33 | } else { |
michael@0 | 34 | testPassed("context exists"); |
michael@0 | 35 | if ("WebGLDebugUtils" in window) |
michael@0 | 36 | WebGLDebugUtils.init(gl); |
michael@0 | 37 | else |
michael@0 | 38 | WebGLDebugUtils = false; |
michael@0 | 39 | |
michael@0 | 40 | debug(""); |
michael@0 | 41 | debug("Checking texture formats."); |
michael@0 | 42 | |
michael@0 | 43 | function createTexture(internalFormat, format, opt_border) { |
michael@0 | 44 | var border = (opt_border === undefined) ? 0 : opt_border; |
michael@0 | 45 | var tex = gl.createTexture(); |
michael@0 | 46 | gl.bindTexture(gl.TEXTURE_2D, tex); |
michael@0 | 47 | gl.texImage2D(gl.TEXTURE_2D, |
michael@0 | 48 | 0, // level |
michael@0 | 49 | internalFormat, // internalFormat |
michael@0 | 50 | 16, // width |
michael@0 | 51 | 16, // height |
michael@0 | 52 | border, // border |
michael@0 | 53 | format, // format |
michael@0 | 54 | gl.UNSIGNED_BYTE, // type |
michael@0 | 55 | null); // data |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | function testValidFormat(internalFormat, formatName) { |
michael@0 | 59 | createTexture(internalFormat, internalFormat); |
michael@0 | 60 | glErrorShouldBe(gl, gl.NO_ERROR, |
michael@0 | 61 | "was able to create texture of " + formatName); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function testInvalidFormat(internalFormat, formatName) { |
michael@0 | 65 | createTexture(internalFormat, internalFormat); |
michael@0 | 66 | var err = gl.getError(); |
michael@0 | 67 | if (err == gl.NO_ERROR) { |
michael@0 | 68 | testFailed("should NOT be able to create texture of type " + formatName); |
michael@0 | 69 | } else if (err == gl.INVALID_OPERATION) { |
michael@0 | 70 | testFailed("should return gl.INVALID_ENUM for type " + formatName); |
michael@0 | 71 | } else if (err == gl.INVALID_ENUM) { |
michael@0 | 72 | testPassed("not able to create invalid format: " + formatName); |
michael@0 | 73 | } |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | var invalidEnums = [ |
michael@0 | 77 | '1', |
michael@0 | 78 | '2', |
michael@0 | 79 | '3', |
michael@0 | 80 | '4', |
michael@0 | 81 | 'RGB4', |
michael@0 | 82 | 'RGB5', |
michael@0 | 83 | 'RGB8', |
michael@0 | 84 | 'RGB10', |
michael@0 | 85 | 'RGB12', |
michael@0 | 86 | 'RGB16', |
michael@0 | 87 | 'RGBA2', |
michael@0 | 88 | 'RGBA4', |
michael@0 | 89 | 'RGB5_A1', |
michael@0 | 90 | 'RGBA8', |
michael@0 | 91 | 'RGB10_A2', |
michael@0 | 92 | 'RGBA12', |
michael@0 | 93 | 'RGBA16', |
michael@0 | 94 | 'BGR', |
michael@0 | 95 | 'BGRA', |
michael@0 | 96 | 'ALPHA4_EXT', |
michael@0 | 97 | 'ALPHA8_EXT', |
michael@0 | 98 | 'ALPHA12_EXT', |
michael@0 | 99 | 'ALPHA16_EXT', |
michael@0 | 100 | 'COMPRESSED_ALPHA', |
michael@0 | 101 | 'COMPRESSED_LUMINANCE', |
michael@0 | 102 | 'COMPRESSED_LUMINANCE_ALPHA', |
michael@0 | 103 | 'COMPRESSED_INTENSITY', |
michael@0 | 104 | 'COMPRESSED_RGB', |
michael@0 | 105 | 'COMPRESSED_RGBA', |
michael@0 | 106 | 'DEPTH_COMPONENT16', |
michael@0 | 107 | 'DEPTH_COMPONENT24', |
michael@0 | 108 | 'DEPTH_COMPONENT32', |
michael@0 | 109 | 'LUMINANCE4_EXT', |
michael@0 | 110 | 'LUMINANCE8_EXT', |
michael@0 | 111 | 'LUMINANCE12_EXT', |
michael@0 | 112 | 'LUMINANCE16_EXT', |
michael@0 | 113 | 'LUMINANCE4_ALPHA4_EXT', |
michael@0 | 114 | 'LUMINANCE6_ALPHA2_EXT', |
michael@0 | 115 | 'LUMINANCE8_ALPHA8_EXT', |
michael@0 | 116 | 'LUMINANCE12_ALPHA4_EXT', |
michael@0 | 117 | 'LUMINANCE12_ALPHA12_EXT', |
michael@0 | 118 | 'LUMINANCE16_ALPHA16_EXT', |
michael@0 | 119 | 'INTENSITY_EXT', |
michael@0 | 120 | 'INTENSITY4_EXT', |
michael@0 | 121 | 'INTENSITY8_EXT', |
michael@0 | 122 | 'INTENSITY12_EXT', |
michael@0 | 123 | 'INTENSITY16_EXT', |
michael@0 | 124 | 'RGB4_EXT', |
michael@0 | 125 | 'RGB5_EXT', |
michael@0 | 126 | 'RGB8_EXT', |
michael@0 | 127 | 'RGB10_EXT', |
michael@0 | 128 | 'RGB12_EXT', |
michael@0 | 129 | 'RGB16_EXT', |
michael@0 | 130 | 'RGBA2_EXT', |
michael@0 | 131 | 'RGBA4_EXT', |
michael@0 | 132 | 'RGB5_A1_EXT', |
michael@0 | 133 | 'RGBA8_EXT', |
michael@0 | 134 | 'RGB10_A2_EXT', |
michael@0 | 135 | 'RGBA12_EXT', |
michael@0 | 136 | 'RGBA16_EXT', |
michael@0 | 137 | 'SLUMINANCE_EXT', |
michael@0 | 138 | 'SLUMINANCE8_EXT', |
michael@0 | 139 | 'SLUMINANCE_ALPHA_EXT', |
michael@0 | 140 | 'SLUMINANCE8_ALPHA8_EXT', |
michael@0 | 141 | 'SRGB_EXT', |
michael@0 | 142 | 'SRGB8_EXT', |
michael@0 | 143 | 'SRGB_ALPHA_EXT', |
michael@0 | 144 | 'SRGB8_ALPHA8' |
michael@0 | 145 | ]; |
michael@0 | 146 | |
michael@0 | 147 | for (var ii = 0; ii < invalidEnums.length; ++ii) { |
michael@0 | 148 | var formatName = invalidEnums[ii] |
michael@0 | 149 | if (desktopGL[formatName] === undefined) { |
michael@0 | 150 | debug("bad format" + formatName) |
michael@0 | 151 | } else { |
michael@0 | 152 | testInvalidFormat(desktopGL[formatName], "GL_" + formatName); |
michael@0 | 153 | } |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | var validEnums = [ |
michael@0 | 157 | 'ALPHA', |
michael@0 | 158 | 'RGB', |
michael@0 | 159 | 'RGBA', |
michael@0 | 160 | 'LUMINANCE', |
michael@0 | 161 | 'LUMINANCE_ALPHA' |
michael@0 | 162 | ]; |
michael@0 | 163 | |
michael@0 | 164 | for (var ii = 0; ii < validEnums.length; ++ii) { |
michael@0 | 165 | var formatName = validEnums[ii] |
michael@0 | 166 | testValidFormat(gl[formatName], "gl." + formatName); |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | debug(""); |
michael@0 | 170 | debug("checking non 0 border parameter to gl.TexImage2D"); |
michael@0 | 171 | createTexture(gl['RGBA'], gl['RGBA'], 1); |
michael@0 | 172 | glErrorShouldBe(gl, gl.INVALID_VALUE, |
michael@0 | 173 | "non 0 border to gl.TexImage2D should return INVALID_VALUE"); |
michael@0 | 174 | |
michael@0 | 175 | |
michael@0 | 176 | function checkTypes() { |
michael@0 | 177 | var canvas = document.getElementById("canvas"); |
michael@0 | 178 | gl = wtu.create3DContext(canvas); |
michael@0 | 179 | var program = wtu.setupTexturedQuad(gl); |
michael@0 | 180 | |
michael@0 | 181 | gl.disable(gl.DEPTH_TEST); |
michael@0 | 182 | gl.disable(gl.BLEND); |
michael@0 | 183 | |
michael@0 | 184 | var tex = gl.createTexture(); |
michael@0 | 185 | gl.bindTexture(gl.TEXTURE_2D, tex); |
michael@0 | 186 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); |
michael@0 | 187 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); |
michael@0 | 188 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); |
michael@0 | 189 | |
michael@0 | 190 | var loc = gl.getUniformLocation(program, "tex"); |
michael@0 | 191 | gl.uniform1i(loc, 0); |
michael@0 | 192 | |
michael@0 | 193 | function checkType(r, g, b, a, type, format, buf) { |
michael@0 | 194 | var typeName = WebGLDebugUtils ? WebGLDebugUtils.glEnumToString(type) : type; |
michael@0 | 195 | debug(""); |
michael@0 | 196 | debug("checking gl.texImage2D with type: " + typeName); |
michael@0 | 197 | gl.texImage2D(gl.TEXTURE_2D, |
michael@0 | 198 | 0, // level |
michael@0 | 199 | format, // internalFormat |
michael@0 | 200 | 2, // width |
michael@0 | 201 | 2, // height |
michael@0 | 202 | 0, // border |
michael@0 | 203 | format, // format |
michael@0 | 204 | type, // type |
michael@0 | 205 | buf); // data |
michael@0 | 206 | |
michael@0 | 207 | glErrorShouldBe(gl, gl.NO_ERROR, |
michael@0 | 208 | "gl.texImage2D with " + typeName + " should generate NO_ERROR"); |
michael@0 | 209 | |
michael@0 | 210 | wtu.drawQuad(gl, [255, 0, 0, 255]); |
michael@0 | 211 | wtu.checkCanvas(gl, [r,g,b,a], |
michael@0 | 212 | "texture type " + typeName + " should draw with " + |
michael@0 | 213 | r + ", " + g + ", " + b + ", " + a); |
michael@0 | 214 | |
michael@0 | 215 | } |
michael@0 | 216 | checkType(0, 255, 0, 255, gl.UNSIGNED_BYTE, gl.RGBA, |
michael@0 | 217 | new Uint8Array([ |
michael@0 | 218 | 0, 255, 0, 255, |
michael@0 | 219 | 0, 255, 0, 255, |
michael@0 | 220 | 0, 255, 0, 255, |
michael@0 | 221 | 0, 255, 0, 255])); |
michael@0 | 222 | checkType(0, 0, 255, 255, gl.UNSIGNED_SHORT_4_4_4_4, gl.RGBA, |
michael@0 | 223 | new Uint16Array([ |
michael@0 | 224 | 255, 255, |
michael@0 | 225 | 255, 255, |
michael@0 | 226 | 255, 255, |
michael@0 | 227 | 255, 255])); |
michael@0 | 228 | checkType(0, 255, 0, 255, gl.UNSIGNED_SHORT_5_6_5, gl.RGB, |
michael@0 | 229 | new Uint16Array([ |
michael@0 | 230 | 2016, 2016, |
michael@0 | 231 | 2016, 2016, |
michael@0 | 232 | 2016, 2016, |
michael@0 | 233 | 2016, 2016])); |
michael@0 | 234 | checkType(0, 0, 255, 255, gl.UNSIGNED_SHORT_5_5_5_1, gl.RGBA, |
michael@0 | 235 | new Uint16Array([ |
michael@0 | 236 | 63, 63, |
michael@0 | 237 | 63, 63, |
michael@0 | 238 | 63, 63, |
michael@0 | 239 | 63, 63])); |
michael@0 | 240 | } |
michael@0 | 241 | checkTypes(); |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | debug(""); |
michael@0 | 245 | successfullyParsed = true; |
michael@0 | 246 | |
michael@0 | 247 | </script> |
michael@0 | 248 | <script>finishTest();</script> |
michael@0 | 249 | |
michael@0 | 250 | </body> |
michael@0 | 251 | </html> |