| <!-- |
| |
| /* |
| ** Copyright (c) 2016 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 CopyTexImage Tests</title> |
| <link rel="stylesheet" href="../../../resources/js-test-style.css"/> |
| <script src="../../../js/js-test-pre.js"></script> |
| <script src="../../../js/webgl-test-utils.js"></script> |
| </head> |
| <body> |
| <canvas id="example" width="64" height="64"></canvas> |
| <div id="description"></div> |
| <div id="console"></div> |
| <script> |
| "use strict"; |
| |
| var wtu = WebGLTestUtils; |
| description("This test verifies the functionality of copyTexImage2D."); |
| debug(""); |
| |
| var gl = wtu.create3DContext("example", undefined, 2); |
| |
| function enumToString(value) { |
| return wtu.glEnumToString(gl, value); |
| } |
| |
| function checkFramebuffer(expected) { |
| var actual = gl.checkFramebufferStatus(gl.FRAMEBUFFER); |
| if (expected.indexOf(actual) < 0) { |
| var msg = "checkFramebufferStatus expects ["; |
| for (var index = 0; index < expected.length; ++index) { |
| msg += wtu.glEnumToString(gl, expected[index]); |
| if (index + 1 < expected.length) |
| msg += ", "; |
| } |
| msg += "], was " + wtu.glEnumToString(gl, actual); |
| testFailed(msg); |
| } else { |
| var msg = "checkFramebufferStatus got " + wtu.glEnumToString(gl, actual) + |
| " as expected"; |
| testPassed(msg); |
| } |
| } |
| |
| var testInternalformat = function () { |
| var goodByteFormats = [ |
| "RGB", |
| "RGBA", |
| "LUMINANCE_ALPHA", |
| "LUMINANCE", |
| "ALPHA", |
| "R8", |
| "RG8", |
| "RGB8", |
| "RGBA8", |
| ]; |
| var goodByteFormatsWithUnmatchedComponentSizes = [ |
| "RGB565", |
| "RGBA4", |
| "RGB5_A1", |
| "RGB10_A2", |
| ]; |
| var goodSRGBFormats = [ |
| "SRGB8", |
| "SRGB8_ALPHA8", |
| ]; |
| var goodIntFormats = [ |
| "R32I", |
| "RG32I", |
| "RGBA32I", |
| ]; |
| var goodIntFormatsWithUnmatchedComponentSizes = [ |
| "R8I", |
| "R16I", |
| "RG8I", |
| "RG16I", |
| "RGBA8I", |
| "RGBA16I", |
| ]; |
| var goodUnsignedIntFormats = [ |
| "R32UI", |
| "RG32UI", |
| "RGBA32UI", |
| ]; |
| var goodUnsignedIntFormatsWithUnmatchedComponentSizes = [ |
| "R8UI", |
| "R16UI", |
| "RG8UI", |
| "RG16UI", |
| "RGB10_A2UI", |
| "RGBA8UI", |
| "RGBA16UI", |
| ]; |
| var badByteFormats = [ |
| "R8_SNORM", |
| "RG8_SNORM", |
| "RGB8_SNORM", |
| "RGBA8_SNORM", |
| ]; |
| var badIntFormats = [ |
| "RGB8I", |
| "RGB16I", |
| "RGB32I", |
| ]; |
| var badUnsingedIntFormats = [ |
| "RGB8UI", |
| "RGB16UI", |
| "RGB32UI", |
| ]; |
| var badDepthStencilFormats = [ |
| "DEPTH_COMPONENT16", |
| "DEPTH_COMPONENT24", |
| "DEPTH_COMPONENT32F", |
| "DEPTH24_STENCIL8", |
| ]; |
| |
| var texture = gl.createTexture(); |
| gl.bindTexture(gl.TEXTURE_2D, texture); |
| |
| function testFormat(internalformat, srcTexFormatsTypes, fboAttachmentType, expected, msg) { |
| var fbo = gl.createFramebuffer(); |
| var srcTexture = gl.createTexture(); |
| gl.bindTexture(gl.TEXTURE_2D, srcTexture); |
| gl.texImage2D(gl.TEXTURE_2D, 0, srcTexFormatsTypes.internalformat, 64, 64, 0, srcTexFormatsTypes.format, srcTexFormatsTypes.type, null); |
| gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); |
| gl.framebufferTexture2D(gl.FRAMEBUFFER, fboAttachmentType, gl.TEXTURE_2D, srcTexture, 0); |
| checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]); |
| |
| gl.bindTexture(gl.TEXTURE_2D, texture); |
| gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl[internalformat], 0, 0, 64, 64, 0); |
| wtu.glErrorShouldBe(gl, expected, msg + enumToString(gl[internalformat])); |
| |
| gl.deleteTexture(srcTexture); |
| gl.deleteFramebuffer(fbo); |
| } |
| |
| goodByteFormats.forEach(function(internalformat) { |
| var srcTexFormatsTypes = { internalformat: gl.RGBA, format: gl.RGBA, type: gl.UNSIGNED_BYTE }; |
| testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.NO_ERROR, "copyTexImage2D should succeed for good internalformat "); |
| srcTexFormatsTypes = { internalformat: gl.RGBA8, format: gl.RGBA, type: gl.UNSIGNED_BYTE }; |
| testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.NO_ERROR, "copyTexImage2D should succeed for good internalformat "); |
| }); |
| goodByteFormatsWithUnmatchedComponentSizes.forEach(function(internalformat) { |
| var srcTexFormatsTypes = { internalformat: gl.RGBA8, format: gl.RGBA, type: gl.UNSIGNED_BYTE }; |
| testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.INVALID_OPERATION, |
| "copyTexImage2D should fail for good internalformat with unmatched component sizes "); |
| }); |
| goodSRGBFormats.forEach(function(internalformat) { |
| var srcTexFormatsTypes = { internalformat: gl.SRGB8_ALPHA8, format: gl.RGBA, type: gl.UNSIGNED_BYTE }; |
| testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.NO_ERROR, "copyTexImage2D should succeed for good internalformat "); |
| }); |
| goodIntFormats.forEach(function(internalformat) { |
| var srcTexFormatsTypes = { internalformat: gl.RGBA32I, format: gl.RGBA_INTEGER, type: gl.INT }; |
| testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.NO_ERROR, "copyTexImage2D should succeed for good internalformat "); |
| }); |
| goodIntFormatsWithUnmatchedComponentSizes.forEach(function(internalformat) { |
| var srcTexFormatsTypes = { internalformat: gl.RGBA32I, format: gl.RGBA_INTEGER, type: gl.INT }; |
| testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.INVALID_OPERATION, |
| "copyTexImage2D should fail for good internalformat with unmatched component sizes "); |
| }); |
| goodUnsignedIntFormats.forEach(function(internalformat) { |
| var srcTexFormatsTypes = { internalformat: gl.RGBA32UI, format: gl.RGBA_INTEGER, type: gl.UNSIGNED_INT }; |
| testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.NO_ERROR, "copyTexImage2D should succeed for good internalformat "); |
| }); |
| goodUnsignedIntFormatsWithUnmatchedComponentSizes.forEach(function(internalformat) { |
| var srcTexFormatsTypes = { internalformat: gl.RGBA32UI, format: gl.RGBA_INTEGER, type: gl.UNSIGNED_INT }; |
| testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.INVALID_OPERATION, |
| "copyTexImage2D should fail for good internalformat with unmatched component sizes "); |
| }); |
| |
| badByteFormats.forEach(function(internalformat) { |
| var srcTexFormatsTypes = { internalformat: gl.RGBA8, format: gl.RGBA, type: gl.UNSIGNED_BYTE }; |
| testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.INVALID_ENUM, "copyTexImage2D should fail for bad internalformat "); |
| }); |
| badIntFormats.forEach(function(internalformat) { |
| var srcTexFormatsTypes = { internalformat: gl.RGBA32I, format: gl.RGBA_INTEGER, type: gl.INT }; |
| testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.INVALID_ENUM, "copyTexImage2D should fail for bad internalformat "); |
| }); |
| badUnsingedIntFormats.forEach(function(internalformat) { |
| var srcTexFormatsTypes = { internalformat: gl.RGBA32UI, format: gl.RGBA_INTEGER, type: gl.UNSIGNED_INT }; |
| testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.INVALID_ENUM, "copyTexImage2D should fail for bad internalformat "); |
| }); |
| badDepthStencilFormats.forEach(function(internalformat) { |
| var srcTexFormatsTypes = { internalformat: gl.DEPTH24_STENCIL8, format: gl.DEPTH_STENCIL, type: gl.UNSIGNED_INT_24_8}; |
| testFormat(internalformat, srcTexFormatsTypes, gl.DEPTH_STENCIL_ATTACHMENT, gl.INVALID_ENUM, "copyTexImage2D should fail for bad internalformat "); |
| }); |
| |
| gl.deleteTexture(texture); |
| } |
| |
| if (!gl) { |
| testFailed("WebGL context does not exist"); |
| } else { |
| testPassed("WebGL context exists"); |
| testInternalformat(); |
| } |
| |
| var successfullyParsed = true; |
| </script> |
| <script src="../../../js/js-test-post.js"></script> |
| |
| </body> |
| </html> |