copy-texture-image-luma-format.html (5244B)
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 CopyTexSubImage 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 <div id="description"></div> 18 <canvas id="canvas" width="64px" height="32px"> </canvas> 19 <div id="console"></div> 20 <script id="vshader" type="x-shader/x-vertex">#version 300 es 21 in highp vec4 a_position; 22 in highp vec2 a_coord; 23 out highp vec2 v_coord; 24 void main(void) { 25 gl_Position = a_position; 26 v_coord = a_coord; 27 } 28 </script> 29 <script id="fshader_luminance_alpha" type="x-shader/x-fragment">#version 300 es 30 in highp vec2 v_coord; 31 uniform highp sampler3D u_sampler0; 32 out highp vec4 o_color0; 33 void main (void) { 34 o_color0 = vec4(texture(u_sampler0,vec3(v_coord, 0))); 35 } 36 </script> 37 <script> 38 "use strict"; 39 description("This test verifies the behavior of copTexSubImage3D with luminance textures."); 40 debug(""); 41 42 var wtu = WebGLTestUtils; 43 var canvas = document.getElementById("canvas"); 44 var gl = wtu.create3DContext(canvas, null, 2); 45 46 function copytexsubimage3D_luma_format() { 47 48 var testGroup = [ 49 { 50 name: '3d_alpha', 51 format: gl.ALPHA, 52 width: 64, 53 height: 32, 54 depth: 2 55 }, 56 { 57 name: '3d_luminance', 58 format: gl.LUMINANCE, 59 width: 64, 60 height: 32, 61 depth: 2 62 }, 63 { 64 name: '3d_luminance_alpha', 65 format: gl.LUMINANCE_ALPHA, 66 width: 64, 67 height: 32, 68 depth: 2 69 } 70 ]; 71 72 testGroup.forEach(function(testcase) { 73 debug(""); 74 debug("Testing copytexsubimage3d_luma_format_" + testcase.name); 75 76 var texture = []; 77 texture[0] = gl.createTexture(); 78 texture[1] = gl.createTexture(); 79 var layer = 0; 80 var width = testcase.width; 81 var height = testcase.height; 82 var depth = testcase.depth; 83 var msg; 84 var uint1 = new Uint8Array(width * height * 4); 85 for (var i = 0; i < uint1.length - 1; ++i) { 86 uint1[i + 1] = (uint1[i] + 10) % 255; 87 } 88 89 gl.bindTexture(gl.TEXTURE_2D, texture[0]); 90 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, uint1); 91 var fbo = gl.createFramebuffer(); 92 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); 93 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture[0], 0); 94 95 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE) { 96 gl.bindTexture(gl.TEXTURE_3D, texture[1]); 97 setUpTexStatus(); 98 gl.texImage3D(gl.TEXTURE_3D, 0, testcase.format, width, height, depth, 0, testcase.format, gl.UNSIGNED_BYTE, null); 99 gl.copyTexSubImage3D(gl.TEXTURE_3D, 0, 0, 0, layer, 0, 0,width, height); 100 gl.bindFramebuffer(gl.FRAMEBUFFER, null); 101 102 var program = wtu.setupProgram(gl, ["vshader", "fshader_luminance_alpha"], ["a_position", "a_coord"]); 103 wtu.setupUnitQuad(gl, 0, 1); 104 wtu.drawUnitQuad(gl); 105 106 for (var y = 0; y < height; ++y) { 107 for (var x = 0; x < width; ++x) { 108 var cur = y * width * 4 + x * 4; 109 if (testcase.format == gl.ALPHA) { 110 wtu.checkCanvasRect(gl, x, y, 1, 1, [ 0, 0, 111 0, uint1[cur + 3]], msg, [1, 1, 1, 1]); 112 } else if (testcase.format == gl.LUMINANCE) { 113 wtu.checkCanvasRect(gl, x, y, 1, 1, [uint1[cur], uint1[cur], 114 uint1[cur], 255], msg, [1, 1, 1, 1]); 115 } else { // gl.LUMINANCE_ALPHA 116 wtu.checkCanvasRect(gl, x, y, 1, 1, [uint1[cur], uint1[cur], 117 uint1[cur], uint1[cur + 3]], msg, [1, 1, 1, 1]); 118 } 119 } 120 } 121 } else { 122 testFailed("framebuffer not complete"); 123 } 124 125 gl.bindTexture(gl.TEXTURE_3D, null); 126 gl.bindFramebuffer(gl.FRAMEBUFFER, null); 127 gl.deleteFramebuffer(fbo); 128 gl.deleteTexture(texture[0]); 129 gl.deleteTexture(texture[1]); 130 gl.deleteProgram(program); 131 }); 132 } 133 134 function setUpTexStatus() { 135 gl.texParameteri( 136 gl.TEXTURE_3D, gl.TEXTURE_MIN_FILTER, gl.NEAREST 137 ); 138 gl.texParameteri( 139 gl.TEXTURE_3D, gl.TEXTURE_MAG_FILTER, gl.NEAREST 140 ); 141 gl.texParameteri( 142 gl.TEXTURE_3D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE 143 ); 144 gl.texParameteri( 145 gl.TEXTURE_3D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE 146 ); 147 gl.texParameteri( 148 gl.TEXTURE_3D, gl.TEXTURE_WRAP_R, gl.CLAMP_TO_EDGE 149 ); 150 } 151 152 if (!gl) { 153 testFailed("WebGL context does not exist"); 154 } else { 155 testPassed("WebGL context exists"); 156 copytexsubimage3D_luma_format(); 157 } 158 159 debug(""); 160 var successfullyParsed = true; 161 </script> 162 <script src="../../../js/js-test-post.js"></script> 163 164 </body> 165 </html>