| <!-- |
| |
| /* |
| ** Copyright (c) 2013 The Khronos Group Inc. |
| ** |
| ** Permission is hereby granted, free of charge, to any person obtaining a |
| ** copy of this software and/or associated documentation files (the |
| ** "Materials"), to deal in the Materials without restriction, including |
| ** without limitation the rights to use, copy, modify, merge, publish, |
| ** distribute, sublicense, and/or sell copies of the Materials, and to |
| ** permit persons to whom the Materials are furnished to do so, subject to |
| ** the following conditions: |
| ** |
| ** The above copyright notice and this permission notice shall be included |
| ** in all copies or substantial portions of the Materials. |
| ** |
| ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| */ |
| |
| --> |
| |
| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <title>WebGL compressed texture size limit conformance test</title> |
| <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| <script src="../../resources/js-test-pre.js"></script> |
| <script src="../resources/webgl-test.js"> </script> |
| <script src="../resources/webgl-test-utils.js"></script> |
| </head> |
| <body> |
| <canvas id="example" width="32" height="32" style="width: 40px; height: 40px;"></canvas> |
| <div id="description"></div> |
| <div id="console"></div> |
| <script> |
| "use strict"; |
| description("Checks size limit of the webgl compressed textures") |
| var canvas; |
| |
| function numLevelsFromSize(size) { |
| var levels = 0; |
| while ((size >> levels) > 0) { |
| ++levels; |
| } |
| return levels; |
| } |
| |
| // More formats can be added here when more texture compression extensions is enabled in WebGL. |
| var validFormats = { |
| COMPRESSED_RGB_S3TC_DXT1_EXT : 0x83F0, |
| COMPRESSED_RGBA_S3TC_DXT1_EXT : 0x83F1, |
| COMPRESSED_RGBA_S3TC_DXT3_EXT : 0x83F2, |
| COMPRESSED_RGBA_S3TC_DXT5_EXT : 0x83F3, |
| }; |
| |
| // format specific restrictions for COMPRESSED_RGB_S3TC_DXT1_EXT and COMPRESSED_RGBA_S3TC_DXT1_EXT |
| // on the byteLength of the ArrayBufferView, pixels |
| function func1 (width, height) |
| { |
| return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 8; |
| } |
| |
| // format specific restrictions for COMPRESSED_RGBA_S3TC_DXT3_EXT and COMPRESSED_RGBA_S3TC_DXT5_EXT |
| // on the byteLength of the ArrayBufferView, pixels |
| function func2 (width, height) |
| { |
| return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16; |
| } |
| |
| var wtu = WebGLTestUtils; |
| var gl = wtu.create3DContext("example"); |
| var tests = [ |
| // More tests can be added here when more texture compression extensions is enabled in WebGL. |
| { extension: "WEBGL_compressed_texture_s3tc", format: validFormats.COMPRESSED_RGB_S3TC_DXT1_EXT, dataType: Uint8Array, func: func1}, |
| { extension: "WEBGL_compressed_texture_s3tc", format: validFormats.COMPRESSED_RGBA_S3TC_DXT1_EXT, dataType: Uint8Array, func: func1}, |
| { extension: "WEBGL_compressed_texture_s3tc", format: validFormats.COMPRESSED_RGBA_S3TC_DXT3_EXT, dataType: Uint8Array, func: func2}, |
| { extension: "WEBGL_compressed_texture_s3tc", format: validFormats.COMPRESSED_RGBA_S3TC_DXT5_EXT, dataType: Uint8Array, func: func2}, |
| ]; |
| |
| // Note: We expressly only use 2 textures because first a texture will be defined |
| // as using all mips of 1 format, then for a moment it will have mixed formats which |
| // may uncover bugs. |
| var targets = [ |
| { target: gl.TEXTURE_2D, |
| maxSize: gl.getParameter(gl.MAX_TEXTURE_SIZE), |
| tex: gl.createTexture(), |
| targets: [gl.TEXTURE_2D] |
| }, |
| { target: gl.TEXTURE_CUBE_MAP, |
| maxSize: gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE), |
| tex: gl.createTexture(), |
| targets: [ |
| gl.TEXTURE_CUBE_MAP_POSITIVE_X, |
| gl.TEXTURE_CUBE_MAP_NEGATIVE_X, |
| gl.TEXTURE_CUBE_MAP_POSITIVE_Y, |
| gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, |
| gl.TEXTURE_CUBE_MAP_POSITIVE_Z, |
| gl.TEXTURE_CUBE_MAP_NEGATIVE_Z |
| ] |
| } |
| ]; |
| |
| gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1); |
| |
| var trg = 0; |
| var tt = 0; |
| runNextTest(); |
| |
| function runNextTest() { |
| var t = targets[trg]; |
| |
| if (tt == 0) { |
| var tex = t.tex; |
| gl.bindTexture(t.target, tex); |
| |
| debug(""); |
| debug("max size for " + wtu.glEnumToString(gl, t.target) + ": " + t.maxSize); |
| var numLevels = numLevelsFromSize(t.maxSize); |
| debug("num levels " + numLevels); |
| } |
| |
| var test = tests[tt]; |
| testFormatType(t, test); |
| ++tt; |
| if (tt == tests.length) { |
| tt = 0; |
| ++trg; |
| if (trg == targets.length) { |
| finishTest(); |
| return; |
| } |
| } |
| wtu.waitForComposite(gl, runNextTest) |
| } |
| |
| function testFormatType(t, test) { |
| debug(""); |
| |
| // Query the extension and store globally so shouldBe can access it |
| var ext = wtu.getExtensionWithKnownPrefixes(gl, test.extension); |
| if (ext) { |
| testPassed("Successfully enabled " + test.extension + " extension"); |
| |
| for (var j = 0; j < t.targets.length; ++j) { |
| var target = t.targets[j]; |
| debug(""); |
| debug(wtu.glEnumToString(gl, target)); |
| var numLevels = numLevelsFromSize(t.maxSize); |
| |
| // positive test |
| for (var i = 0, size = t.maxSize; i < numLevels; i++, size /= 2) { |
| var pixels = new test.dataType(test.func(size, size)); |
| gl.compressedTexImage2D(target, i, test.format, size, size, 0, pixels); |
| glErrorShouldBe(gl, gl.NO_ERROR, "uploading compressed texture should generate NO_ERROR." |
| + "level is " + i + ", size is " + size + "x" + size); |
| } |
| |
| // out of bound test |
| // width or height out of bound |
| var pixelsNegativeTest1 = new test.dataType(test.func(t.maxSize * 2, t.maxSize * 2)); |
| gl.compressedTexImage2D(target, 0, test.format, t.maxSize * 2, t.maxSize * 2, 0, pixelsNegativeTest1); |
| glErrorShouldBe(gl, gl.INVALID_VALUE, "width or height out of bound: should generate INVALID_VALUE." |
| + " level is 0, size is " + (t.maxSize * 2) + "x" + (t.maxSize * 2)); |
| // level out of bound |
| var pixelsNegativeTest2 = new test.dataType(test.func(256, 256)); |
| gl.compressedTexImage2D(target, numLevels, test.format, 256, 256, 0, pixelsNegativeTest2); |
| glErrorShouldBe(gl, gl.INVALID_VALUE, "level out of bound: should generate INVALID_VALUE." |
| + " level is " + numLevels + ", size is 256x256"); |
| //width or height out of bound for specified level |
| gl.compressedTexImage2D(target, numLevels - 1, test.format, 256, 256, 0, pixelsNegativeTest2); |
| glErrorShouldBe(gl, gl.INVALID_VALUE, "width or height out of bound for specified level: should generate INVALID_VALUE." |
| + " level is " + (numLevels - 1) + ", size is 256x256"); |
| } |
| } |
| else |
| testPassed("No " + test.extension + " extension support -- this is legal"); |
| } |
| |
| var successfullyParsed = true; |
| </script> |
| </body> |
| </html> |
| |