tex-subimage3d-pixel-buffer-bug.html (3007B)
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>Test bug of TexSubImage3D with pixel buffer</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="2" height="2" style="width: 2px; height: 2px;"></canvas> 18 <div id="description"></div> 19 <div id="console"></div> 20 <script id="vshader_texsize" type="x-shader/x-vertex">#version 300 es 21 in vec4 vPosition; 22 void main() 23 { 24 gl_Position = vPosition; 25 } 26 </script> 27 28 <script id="fshader_texsize_3d" type="x-shader/x-fragment">#version 300 es 29 precision mediump float; 30 uniform highp sampler3D tex; 31 uniform int lod; 32 uniform ivec3 texSize; 33 out vec4 fragColor; 34 void main() 35 { 36 fragColor = (textureSize(tex, lod) == texSize ? vec4(1.0, 0.0, 0.0, 1.0) : vec4(0.0, 0.0, 0.0, 1.0)); 37 } 38 </script> 39 40 41 <script> 42 "use strict"; 43 description(document.title); 44 debug("This is a regression test for <a href='https://bugs.chromium.org/p/chromium/issues/detail?id=666384'>Chromium Issue 666384</a>"); 45 debug(""); 46 47 var wtu = WebGLTestUtils; 48 var gl = wtu.create3DContext("example", undefined, 2); 49 50 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); 51 52 function runTest() { 53 wtu.setupUnitQuad(gl, 0, 1); 54 55 var program = wtu.setupProgram( 56 gl, ['vshader_texsize', 'fshader_texsize_3d'], ['vPosition'], [0]); 57 58 var width = 32; 59 var height = 16; 60 var depth = 8; 61 gl.uniform1i(gl.getUniformLocation(program, "tex"), 0); 62 gl.uniform1i(gl.getUniformLocation(program, "lod"), 2); 63 gl.uniform3i(gl.getUniformLocation(program, "texSize"), 8, 4, 2); 64 var tex3d = gl.createTexture(); 65 gl.bindTexture(gl.TEXTURE_3D, tex3d); 66 gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); 67 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texParameter(TEXTURE_MIN_FILTER) should succeed"); 68 gl.texStorage3D(gl.TEXTURE_3D, 4, gl.RGBA8, width, height, depth); 69 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texStorage3D should succeed"); 70 var buffer = gl.createBuffer(); 71 gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, buffer); 72 gl.bufferData(gl.PIXEL_UNPACK_BUFFER, new Uint8Array(width * height * depth * 4), gl.DYNAMIC_DRAW); 73 gl.texSubImage3D(gl.TEXTURE_3D, 0, 0, 0, 0, width, height, depth, gl.RGBA, gl.UNSIGNED_BYTE, 0); 74 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Update texture data with texSubImage3D from pixel buffer should succeed"); 75 gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, null); 76 wtu.clearAndDrawUnitQuad(gl); 77 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "clearAndDrawQuad should succeed"); 78 wtu.checkCanvas(gl, [255, 0, 0, 255], "should draw with [255, 0, 0, 255]"); 79 gl.deleteTexture(tex3d); 80 gl.deleteBuffer(buffer); 81 } 82 83 runTest(); 84 var successfullyParsed = true; 85 86 </script> 87 <script src="../../../js/js-test-post.js"></script> 88 89 </body> 90 </html>