tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

copy-texture-image.html (10191B)


      1 <!--
      2 Copyright (c) 2019 The Khronos Group Inc.
      3 Use of this source code is governed by an MIT-style license that can be
      4 found in the LICENSE.txt file.
      5 -->
      6 
      7 <!DOCTYPE html>
      8 <html>
      9 <head>
     10 <meta charset="utf-8">
     11 <title>WebGL CopyTexImage Tests</title>
     12 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
     13 <script src="../../../js/js-test-pre.js"></script>
     14 <script src="../../../js/webgl-test-utils.js"></script>
     15 </head>
     16 <body>
     17 <canvas id="example" width="64" height="64"></canvas>
     18 <div id="description"></div>
     19 <div id="console"></div>
     20 <script>
     21 "use strict";
     22 
     23 var wtu = WebGLTestUtils;
     24 description("This test verifies the functionality of copyTexImage2D.");
     25 debug("");
     26 
     27 var gl = wtu.create3DContext("example", undefined, 2);
     28 
     29 function enumToString(value) {
     30    return wtu.glEnumToString(gl, value);
     31 }
     32 
     33 function checkFramebuffer(expected) {
     34    var actual = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
     35    if (expected.indexOf(actual) < 0) {
     36        var msg = "checkFramebufferStatus expects [";
     37        for (var index = 0; index < expected.length; ++index) {
     38            msg += wtu.glEnumToString(gl, expected[index]);
     39            if (index + 1 < expected.length)
     40                msg += ", ";
     41        }
     42        msg += "], was " + wtu.glEnumToString(gl, actual);
     43        testFailed(msg);
     44    } else {
     45        var msg = "checkFramebufferStatus got " + wtu.glEnumToString(gl, actual) +
     46                  " as expected";
     47        testPassed(msg);
     48    }
     49 }
     50 
     51 var testInternalformat = function () {
     52    var goodUnormFormats = [
     53        "RGB",
     54        "RGBA",
     55        "LUMINANCE_ALPHA",
     56        "LUMINANCE",
     57        "ALPHA",
     58        "R8",
     59        "RG8",
     60        "RGB8",
     61        "RGBA8",
     62    ];
     63    var goodUnormFormatsWithUnmatchedComponentSizes = [
     64        "RGB565",
     65        "RGBA4",
     66        "RGB5_A1",
     67        "RGB10_A2",
     68    ];
     69    var goodSRGBFormats = [
     70        "SRGB8",
     71        "SRGB8_ALPHA8",
     72    ];
     73    var goodIntFormats = [
     74        "R32I",
     75        "RG32I",
     76        "RGB32I",
     77        "RGBA32I",
     78    ];
     79    var goodIntFormatsWithUnmatchedComponentSizes = [
     80        "R8I",
     81        "R16I",
     82        "RG8I",
     83        "RG16I",
     84        "RGB8I",
     85        "RGB16I",
     86        "RGBA8I",
     87        "RGBA16I",
     88    ];
     89    var goodUnsignedIntFormats = [
     90        "R32UI",
     91        "RG32UI",
     92        "RGB32UI",
     93        "RGBA32UI",
     94    ];
     95    var goodUnsignedIntFormatsWithUnmatchedComponentSizes = [
     96        "R8UI",
     97        "R16UI",
     98        "RG8UI",
     99        "RG16UI",
    100        "RGB10_A2UI",
    101        "RGB8UI",
    102        "RGB16UI",
    103        "RGBA8UI",
    104        "RGBA16UI",
    105    ];
    106    const snormFormats = [
    107        "R8_SNORM",
    108        "RG8_SNORM",
    109        "RGB8_SNORM",
    110        "RGBA8_SNORM",
    111    ];
    112    const float16Formats = [
    113        "R16F",
    114        "RG16F",
    115        "RGB16F",
    116        "RGBA16F",
    117    ];
    118    const float32Formats = [
    119        "R32F",
    120        "RG32F",
    121        "RGB32F",
    122        "RGBA32F",
    123    ];
    124    const float11Formats = [
    125        "R11F_G11F_B10F",
    126    ];
    127    const depthAndOrStencilFormats = [
    128        "DEPTH_COMPONENT16",
    129        "DEPTH_COMPONENT24",
    130        "DEPTH_COMPONENT32F",
    131        "DEPTH24_STENCIL8",
    132    ];
    133 
    134    var texture = gl.createTexture();
    135    gl.bindTexture(gl.TEXTURE_2D, texture);
    136 
    137    function testFormat(internalformat, srcTexFormatsTypes, fboAttachmentType, expected, msg) {
    138        var fbo = gl.createFramebuffer();
    139        var srcTexture = gl.createTexture();
    140        gl.bindTexture(gl.TEXTURE_2D, srcTexture);
    141        gl.texImage2D(gl.TEXTURE_2D, 0, gl[srcTexFormatsTypes.internalformat], 64, 64, 0, srcTexFormatsTypes.format, srcTexFormatsTypes.type, null);
    142        gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
    143        gl.framebufferTexture2D(gl.FRAMEBUFFER, fboAttachmentType, gl.TEXTURE_2D, srcTexture, 0);
    144        checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
    145 
    146        gl.bindTexture(gl.TEXTURE_2D, texture);
    147        gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl[internalformat], 0, 0, 64, 64, 0);
    148        wtu.glErrorShouldBe(gl, expected, msg + srcTexFormatsTypes.internalformat + '=>' + internalformat);
    149 
    150        gl.deleteTexture(srcTexture);
    151        gl.deleteFramebuffer(fbo);
    152    }
    153 
    154    goodUnormFormats.forEach(function(internalformat) {
    155        var srcTexFormatsTypes = { internalformat: "RGBA", format: gl.RGBA, type: gl.UNSIGNED_BYTE };
    156        testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.NO_ERROR, "copyTexImage2D should succeed for good internalformat ");
    157        srcTexFormatsTypes = { internalformat: "RGBA8", format: gl.RGBA, type: gl.UNSIGNED_BYTE };
    158        testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.NO_ERROR, "copyTexImage2D should succeed for good internalformat ");
    159    });
    160    goodUnormFormatsWithUnmatchedComponentSizes.forEach(function(internalformat) {
    161        var srcTexFormatsTypes = { internalformat: "RGBA8", format: gl.RGBA, type: gl.UNSIGNED_BYTE };
    162        testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.INVALID_OPERATION,
    163                   "copyTexImage2D should fail for good internalformat with unmatched component sizes  ");
    164    });
    165 
    166    goodSRGBFormats.forEach(function(internalformat) {
    167        var srcTexFormatsTypes = { internalformat: "SRGB8_ALPHA8", format: gl.RGBA, type: gl.UNSIGNED_BYTE };
    168        testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.NO_ERROR, "copyTexImage2D should succeed for good internalformat ");
    169    });
    170 
    171    goodIntFormats.forEach(function(internalformat) {
    172        var srcTexFormatsTypes = { internalformat: "RGBA32I", format: gl.RGBA_INTEGER, type: gl.INT };
    173        testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.NO_ERROR, "copyTexImage2D should succeed for good internalformat ");
    174    });
    175    goodIntFormatsWithUnmatchedComponentSizes.forEach(function(internalformat) {
    176        var srcTexFormatsTypes = { internalformat: "RGBA32I", format: gl.RGBA_INTEGER, type: gl.INT };
    177        testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.INVALID_OPERATION,
    178                   "copyTexImage2D should fail for good internalformat with unmatched component sizes ");
    179    });
    180 
    181    goodUnsignedIntFormats.forEach(function(internalformat) {
    182        var srcTexFormatsTypes = { internalformat: "RGBA32UI", format: gl.RGBA_INTEGER, type: gl.UNSIGNED_INT };
    183        testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.NO_ERROR, "copyTexImage2D should succeed for good internalformat ");
    184    });
    185    goodUnsignedIntFormatsWithUnmatchedComponentSizes.forEach(function(internalformat) {
    186        var srcTexFormatsTypes = { internalformat: "RGBA32UI", format: gl.RGBA_INTEGER, type: gl.UNSIGNED_INT };
    187        testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.INVALID_OPERATION,
    188                   "copyTexImage2D should fail for good internalformat with unmatched component sizes ");
    189    });
    190 
    191    snormFormats.forEach(function(internalformat) {
    192        const srcTexFormatsTypes = { internalformat: "RGBA8", format: gl.RGBA, type: gl.UNSIGNED_BYTE };
    193        testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, [gl.INVALID_ENUM, gl.INVALID_OPERATION], "copyTexImage2D should fail for snorm internalformat ");
    194    });
    195 
    196    if (gl.getExtension("EXT_color_buffer_float")) {
    197        float16Formats.forEach(function(internalformat) {
    198            var srcTexFormatsTypes = { internalformat: "RGBA16F", format: gl.RGBA, type: gl.FLOAT };
    199            testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.NO_ERROR, "copyTexImage2D should succeed for float16 internalformat ");
    200        });
    201        float32Formats.forEach(function(internalformat) {
    202            var srcTexFormatsTypes = { internalformat: "RGBA32F", format: gl.RGBA, type: gl.FLOAT };
    203            testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.NO_ERROR, "copyTexImage2D should succeed for float32 internalformat ");
    204        });
    205        float11Formats.forEach(function(internalformat) {
    206            var srcTexFormatsTypes = { internalformat: "R11F_G11F_B10F", format: gl.RGB, type: gl.FLOAT };
    207            testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.NO_ERROR, "copyTexImage2D should succeed for R11F_G11F_B10F internalformat ");
    208        });
    209 
    210        float32Formats.concat(float11Formats).forEach(function(internalformat) {
    211            var srcTexFormatsTypes = { internalformat: "RGBA16F", format: gl.RGBA, type: gl.FLOAT };
    212            testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.INVALID_OPERATION,
    213                       "copyTexImage2D should fail for non-float16 internalformat (unmatched component sizes) ");
    214        });
    215        float16Formats.concat(float11Formats).forEach(function(internalformat) {
    216            var srcTexFormatsTypes = { internalformat: "RGBA32F", format: gl.RGBA, type: gl.FLOAT };
    217            testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.INVALID_OPERATION,
    218                       "copyTexImage2D should fail for non-float32 internalformat (unmatched component sizes) ");
    219        });
    220        float16Formats.concat(float32Formats).forEach(function(internalformat) {
    221            var srcTexFormatsTypes = { internalformat: "R11F_G11F_B10F", format: gl.RGB, type: gl.FLOAT };
    222            testFormat(internalformat, srcTexFormatsTypes, gl.COLOR_ATTACHMENT0, gl.INVALID_OPERATION,
    223                       "copyTexImage2D should fail for non-R11F_G11F_B10F internalformat (unmatched component sizes) ");
    224        });
    225    }
    226 
    227    depthAndOrStencilFormats.forEach(function(internalformat) {
    228        var srcTexFormatsTypes = { internalformat: "DEPTH24_STENCIL8", format: gl.DEPTH_STENCIL, type: gl.UNSIGNED_INT_24_8};
    229        testFormat(internalformat, srcTexFormatsTypes, gl.DEPTH_STENCIL_ATTACHMENT,
    230                   [gl.INVALID_ENUM, gl.INVALID_OPERATION],
    231                   "copyTexImage2D should fail for depth internalformat ");
    232    });
    233 
    234    gl.deleteTexture(texture);
    235 }
    236 
    237 if (!gl) {
    238    testFailed("WebGL context does not exist");
    239 } else {
    240    testPassed("WebGL context exists");
    241    testInternalformat();
    242 }
    243 
    244 var successfullyParsed = true;
    245 </script>
    246 <script src="../../../js/js-test-post.js"></script>
    247 
    248 </body>
    249 </html>