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 CopyTexImage from/to the same texture 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 <canvas id=
"example" width=
"64" height=
"64"></canvas>
18 <div id=
"description"></div>
19 <div id=
"console"></div>
23 var wtu
= WebGLTestUtils
;
24 // https://bugs.chromium.org/p/chromium/issues/detail?id=797235
25 description("This test verifies CopyTexImage2D works if source/destination images belong to the same texture");
28 var gl
= wtu
.create3DContext("example", undefined, 2);
30 function enumToString(value
) {
31 return wtu
.glEnumToString(gl
, value
);
34 function checkFramebuffer(expected
) {
35 var actual
= gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
);
36 if (expected
.indexOf(actual
) < 0) {
37 var msg
= "checkFramebufferStatus expects [";
38 for (var index
= 0; index
< expected
.length
; ++index
) {
39 msg
+= wtu
.glEnumToString(gl
, expected
[index
]);
40 if (index
+ 1 < expected
.length
)
43 msg
+= "], was " + wtu
.glEnumToString(gl
, actual
);
46 var msg
= "checkFramebufferStatus got " + wtu
.glEnumToString(gl
, actual
) +
52 function checkTextureLevelColor(texture
, level
, level_width
, level_height
, x
, y
, width
, height
, color
) {
53 var fbo
= gl
.createFramebuffer();
54 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo
);
55 var color_renderable_tex
= gl
.createTexture();
56 gl
.bindTexture(gl
.TEXTURE_2D
, color_renderable_tex
);
57 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA8
, level_width
, level_height
, 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
, null);
58 gl
.framebufferTexture2D(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, color_renderable_tex
, 0);
59 checkFramebuffer([gl
.FRAMEBUFFER_COMPLETE
]);
61 var program
= wtu
.setupTexturedQuad(gl
);
62 gl
.bindTexture(gl
.TEXTURE_2D
, texture
);
63 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_BASE_LEVEL
, level
);
64 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MAX_LEVEL
, level
);
65 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.NEAREST
);
66 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MAG_FILTER
, gl
.NEAREST
);
67 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_S
, gl
.REPEAT
);
68 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_T
, gl
.REPEAT
);
69 wtu
.clearAndDrawUnitQuad(gl
);
70 wtu
.checkCanvasRect(gl
, x
, y
, width
, height
, color
);
72 gl
.deleteTexture(color_renderable_tex
);
73 gl
.deleteFramebuffer(fbo
);
74 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "Check texture level color should generate no GL errors.");
77 function testChangeTargetTextureLevelSize() {
79 var fbo
= gl
.createFramebuffer();
80 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo
);
82 var texture
= gl
.createTexture();
83 wtu
.fillTexture(gl
, texture
, 64, 64, [255, 0, 0, 255], 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
, gl
.RGBA8
);
84 gl
.generateMipmap(gl
.TEXTURE_2D
);
85 gl
.framebufferTexture2D(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, texture
, 1);
86 checkFramebuffer([gl
.FRAMEBUFFER_COMPLETE
]);
88 // fbo source texture is |texture| level 1, 32x32. Target is |texture| level 2, 64x64.
89 // Only one quarter of the target 64x64 will come from the source.
90 // Implementations may insert internal commands before copying over 32x32 in order to
91 // initialize undefined three quarters to 0 as WebGL spec requires. This will actually create
92 // a 64x64 image at level 2 and make the fbo incomplete, thus, the copying will fail.
93 gl
.copyTexImage2D(gl
.TEXTURE_2D
, 2, gl
.RGBA8
, 0, 0, 64, 64, 0);
94 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "copyTexImage2D should succeed.");
95 checkFramebuffer([gl
.FRAMEBUFFER_INCOMPLETE_ATTACHMENT
]);
97 checkTextureLevelColor(texture
, 2, 64, 64, 0, 0, 32, 32, [255, 0, 0, 255]);
98 checkTextureLevelColor(texture
, 2, 64, 64, 0, 32, 64, 32, [0, 0, 0, 0]);
99 checkTextureLevelColor(texture
, 2, 64, 64, 32, 32, 32, 32, [0, 0, 0, 0]);
101 gl
.deleteFramebuffer(fbo
);
102 gl
.deleteTexture(texture
);
103 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "Test should generate no GL errors.");
106 function testChangeTargetTextureLevelFormat() {
108 var fbo
= gl
.createFramebuffer();
109 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo
);
111 var texture
= gl
.createTexture();
112 wtu
.fillTexture(gl
, texture
, 64, 64, [255, 0, 0, 255], 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
, gl
.RGBA8
);
113 gl
.generateMipmap(gl
.TEXTURE_2D
);
114 gl
.framebufferTexture2D(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, texture
, 1);
115 checkFramebuffer([gl
.FRAMEBUFFER_COMPLETE
]);
117 // Using LUNIMANCE_ALPHA format may trigger implementations' emulation code path
118 // on desktop core profile GL, which might change level 2 image definition first
119 // and make the fbo incomplete, thus, the actual copying will fail.
120 gl
.copyTexImage2D(gl
.TEXTURE_2D
, 2, gl
.LUMINANCE_ALPHA
, 0, 0, 16, 16, 0);
121 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "copyTexImage2D should succeed.");
122 checkFramebuffer([gl
.FRAMEBUFFER_INCOMPLETE_ATTACHMENT
]);
124 checkTextureLevelColor(texture
, 2, 16, 16, 0, 0, 16, 16, [255, 255, 255, 255]);
126 gl
.deleteFramebuffer(fbo
);
127 gl
.deleteTexture(texture
);
128 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "Test should generate no GL errors.");
132 testFailed("WebGL context does not exist");
134 testPassed("WebGL context exists");
135 testChangeTargetTextureLevelSize();
136 testChangeTargetTextureLevelFormat();
139 var successfullyParsed
= true;
141 <script src=
"../../../js/js-test-post.js"></script>