tex-sub-image-2d-bad-args.html (6897B)
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 <!DOCTYPE html> 7 <html> 8 <head> 9 <meta charset="utf-8"> 10 <link rel="stylesheet" href="../../../resources/js-test-style.css"/> 11 <script src="../../../js/js-test-pre.js"></script> 12 <script src="../../../js/webgl-test-utils.js"></script> 13 </head> 14 <body> 15 <canvas id="testbed" width="16" height="16"></canvas> 16 <canvas id="c" width="16" height="16"></canvas> 17 <div id="description"></div> 18 <div id="console"></div> 19 <script> 20 "use strict"; 21 description('Tests texSubImage2D with bad arguments'); 22 23 var wtu = WebGLTestUtils; 24 var contextVersion = wtu.getDefault3DContextVersion(); 25 var c = document.getElementById("c"); 26 27 var gl = wtu.create3DContext("testbed"); 28 var tex = gl.createTexture(); 29 var maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE); 30 var maxTextureLevel = Math.floor(Math.log2(maxTextureSize)) + 1; 31 32 gl.bindTexture(gl.TEXTURE_2D, tex); 33 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 1, gl.RGBA, gl.UNSIGNED_BYTE, c); 34 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "no previously defined texture image"); 35 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, c); 36 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Setup should succeed"); 37 38 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 1, gl.RGBA, gl.UNSIGNED_BYTE, c); 39 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "y + height > texture height"); 40 gl.texSubImage2D(gl.TEXTURE_2D, 0, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, c); 41 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "x + width > texture width"); 42 gl.texSubImage2D(gl.TEXTURE_2D, 0, -1, 0, gl.RGBA, gl.UNSIGNED_BYTE, c); 43 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "negative x"); 44 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, -1, gl.RGBA, gl.UNSIGNED_BYTE, c); 45 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "negative y"); 46 gl.texSubImage2D(gl.TEXTURE_2D, -1, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, c); 47 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "negative level"); 48 shouldThrow("gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, null)"); 49 wtu.glErrorShouldBe(gl, gl.NO_ERROR); 50 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); 51 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "null pixels"); 52 53 // GL_INVALID_VALUE may be generated if level is greater than log 2 max, where max is the returned value of GL_MAX_TEXTURE_SIZE. 54 // GL_INVALID_OPERATION is generated if the texture array has not been defined by a previous glTexImage2D or glCopyTexImage2D operation whose internalformat matches the format of glTexSubImage2D. 55 gl.texSubImage2D(gl.TEXTURE_2D, maxTextureLevel + 1, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, c); 56 wtu.glErrorShouldBe(gl, [gl.INVALID_VALUE, gl.INVALID_OPERATION], "too high level"); 57 58 gl.texSubImage2D(gl.FLOAT, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, c); 59 wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "bad target"); 60 if (contextVersion > 1) { 61 gl.texSubImage2D(gl.TEXTURE_3D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, c); 62 wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "bad target"); 63 } 64 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, c); 65 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "good args"); 66 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGB, gl.UNSIGNED_BYTE, c); 67 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "format not same as original"); 68 if (contextVersion < 2) { 69 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_SHORT_4_4_4_4, c); 70 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "type not same as original"); 71 } 72 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, c); 73 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "make texture RGB"); 74 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGB, gl.UNSIGNED_BYTE, c); 75 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "format same as original RGB"); 76 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, c); 77 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "format not same as original RGB"); 78 if (contextVersion < 2) { 79 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGB, gl.UNSIGNED_SHORT_5_6_5, c); 80 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "type not same as original RGB"); 81 } 82 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, c); 83 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "make texture RGBA UNSIGNED_BYTE"); 84 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, c); 85 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "format same as original"); 86 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGB, gl.UNSIGNED_BYTE, c); 87 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "format not same as original"); 88 if (contextVersion < 2) { 89 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_SHORT_4_4_4_4, c); 90 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "type not same as original"); 91 } 92 93 // Large canvas will trigger GPU-to-GPU fast path in chrome, 94 // while small canvas will go into normal path, i.e. read pixles from canvas then upload to texture. 95 var largeCanvas = document.createElement("canvas"); 96 largeCanvas.width = 257; 97 largeCanvas.height = 257; 98 var largeCanvasContext = largeCanvas.getContext("2d"); 99 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, largeCanvas); 100 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "make texture RGBA UNSIGNED_BYTE"); 101 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, c); 102 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "format same as original"); 103 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGB, gl.UNSIGNED_BYTE, c); 104 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "format not same as original"); 105 if (contextVersion < 2) { 106 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_SHORT_4_4_4_4, c); 107 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "type not same as original"); 108 } 109 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, largeCanvas); 110 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "format same as original"); 111 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGB, gl.UNSIGNED_BYTE, largeCanvas); 112 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "format not same as original"); 113 if (contextVersion < 2) { 114 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_SHORT_4_4_4_4, largeCanvas); 115 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "type not same as original"); 116 } 117 118 var maxCubeMapTextureSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE); 119 var maxCubeMapTextureLevel = Math.floor(Math.log2(maxCubeMapTextureSize)) + 1; 120 for (var f = 0; f < 6; f++) { 121 var tex = gl.createTexture(); 122 gl.bindTexture(gl.TEXTURE_CUBE_MAP, tex); 123 gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + f, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, c); 124 gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + f, maxCubeMapTextureLevel + 1, 0, 0, gl.RGB, gl.UNSIGNED_BYTE, c); 125 wtu.glErrorShouldBe(gl, [gl.INVALID_VALUE, gl.INVALID_OPERATION], "too high level"); 126 gl.deleteTexture(tex); 127 } 128 129 var successfullyParsed = true; 130 </script> 131 <script src="../../../js/js-test-post.js"></script> 132 </body> 133 </html>