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.
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>
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;
25 gl_Position = a_position;
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;
34 o_color0 = vec4(texture(u_sampler0,vec3(v_coord,
0)));
39 description("This test verifies the behavior of copTexSubImage3D with luminance textures.");
42 var wtu
= WebGLTestUtils
;
43 var canvas
= document
.getElementById("canvas");
44 var gl
= wtu
.create3DContext(canvas
, null, 2);
46 function copytexsubimage3D_luma_format() {
64 name
: '3d_luminance_alpha',
65 format
: gl
.LUMINANCE_ALPHA
,
72 testGroup
.forEach(function(testcase
) {
74 debug("Testing copytexsubimage3d_luma_format_" + testcase
.name
);
77 texture
[0] = gl
.createTexture();
78 texture
[1] = gl
.createTexture();
80 var width
= testcase
.width
;
81 var height
= testcase
.height
;
82 var depth
= testcase
.depth
;
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;
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);
95 if (gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) == gl
.FRAMEBUFFER_COMPLETE
) {
96 gl
.bindTexture(gl
.TEXTURE_3D
, texture
[1]);
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);
102 var program
= wtu
.setupProgram(gl
, ["vshader", "fshader_luminance_alpha"], ["a_position", "a_coord"]);
103 wtu
.setupUnitQuad(gl
, 0, 1);
104 wtu
.drawUnitQuad(gl
);
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]);
122 testFailed("framebuffer not complete");
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
);
134 function setUpTexStatus() {
136 gl
.TEXTURE_3D
, gl
.TEXTURE_MIN_FILTER
, gl
.NEAREST
139 gl
.TEXTURE_3D
, gl
.TEXTURE_MAG_FILTER
, gl
.NEAREST
142 gl
.TEXTURE_3D
, gl
.TEXTURE_WRAP_S
, gl
.CLAMP_TO_EDGE
145 gl
.TEXTURE_3D
, gl
.TEXTURE_WRAP_T
, gl
.CLAMP_TO_EDGE
148 gl
.TEXTURE_3D
, gl
.TEXTURE_WRAP_R
, gl
.CLAMP_TO_EDGE
153 testFailed("WebGL context does not exist");
155 testPassed("WebGL context exists");
156 copytexsubimage3D_luma_format();
160 var successfullyParsed
= true;
162 <script src=
"../../../js/js-test-post.js"></script>