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 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 description("This test verifies the functionality of copyTexImage2D.");
27 var gl
= wtu
.create3DContext("example", undefined, 2);
29 function enumToString(value
) {
30 return wtu
.glEnumToString(gl
, value
);
33 function checkFramebuffer(expected
) {
34 var actual
= gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
);
35 if (expected
.indexOf(actual
) < 0) {
36 var msg
= "checkFramebufferStatus expects [";
37 for (var index
= 0; index
< expected
.length
; ++index
) {
38 msg
+= wtu
.glEnumToString(gl
, expected
[index
]);
39 if (index
+ 1 < expected
.length
)
42 msg
+= "], was " + wtu
.glEnumToString(gl
, actual
);
45 var msg
= "checkFramebufferStatus got " + wtu
.glEnumToString(gl
, actual
) +
51 var testInternalformat = function () {
52 var goodUnormFormats
= [
63 var goodUnormFormatsWithUnmatchedComponentSizes
= [
69 var goodSRGBFormats
= [
73 var goodIntFormats
= [
79 var goodIntFormatsWithUnmatchedComponentSizes
= [
89 var goodUnsignedIntFormats
= [
95 var goodUnsignedIntFormatsWithUnmatchedComponentSizes
= [
106 const snormFormats
= [
112 const float16Formats
= [
118 const float32Formats
= [
124 const float11Formats
= [
127 const depthAndOrStencilFormats
= [
130 "DEPTH_COMPONENT32F",
134 var texture
= gl
.createTexture();
135 gl
.bindTexture(gl
.TEXTURE_2D
, texture
);
137 function testFormat(internalformat
, srcTexFormatsTypes
, fboAttachmentType
, expected
, msg
) {
138 var fbo
= gl
.createFramebuffer();
139 var srcTexture
= gl
.createTexture();
140 gl
.bindTexture(gl
.TEXTURE_2D
, srcTexture
);
141 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
[srcTexFormatsTypes
.internalformat
], 64, 64, 0, srcTexFormatsTypes
.format
, srcTexFormatsTypes
.type
, null);
142 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo
);
143 gl
.framebufferTexture2D(gl
.FRAMEBUFFER
, fboAttachmentType
, gl
.TEXTURE_2D
, srcTexture
, 0);
144 checkFramebuffer([gl
.FRAMEBUFFER_COMPLETE
]);
146 gl
.bindTexture(gl
.TEXTURE_2D
, texture
);
147 gl
.copyTexImage2D(gl
.TEXTURE_2D
, 0, gl
[internalformat
], 0, 0, 64, 64, 0);
148 wtu
.glErrorShouldBe(gl
, expected
, msg
+ srcTexFormatsTypes
.internalformat
+ '=>' + internalformat
);
150 gl
.deleteTexture(srcTexture
);
151 gl
.deleteFramebuffer(fbo
);
154 goodUnormFormats
.forEach(function(internalformat
) {
155 var srcTexFormatsTypes
= { internalformat
: "RGBA", format
: gl
.RGBA
, type
: gl
.UNSIGNED_BYTE
};
156 testFormat(internalformat
, srcTexFormatsTypes
, gl
.COLOR_ATTACHMENT0
, gl
.NO_ERROR
, "copyTexImage2D should succeed for good internalformat ");
157 srcTexFormatsTypes
= { internalformat
: "RGBA8", format
: gl
.RGBA
, type
: gl
.UNSIGNED_BYTE
};
158 testFormat(internalformat
, srcTexFormatsTypes
, gl
.COLOR_ATTACHMENT0
, gl
.NO_ERROR
, "copyTexImage2D should succeed for good internalformat ");
160 goodUnormFormatsWithUnmatchedComponentSizes
.forEach(function(internalformat
) {
161 var srcTexFormatsTypes
= { internalformat
: "RGBA8", format
: gl
.RGBA
, type
: gl
.UNSIGNED_BYTE
};
162 testFormat(internalformat
, srcTexFormatsTypes
, gl
.COLOR_ATTACHMENT0
, gl
.INVALID_OPERATION
,
163 "copyTexImage2D should fail for good internalformat with unmatched component sizes ");
166 goodSRGBFormats
.forEach(function(internalformat
) {
167 var srcTexFormatsTypes
= { internalformat
: "SRGB8_ALPHA8", format
: gl
.RGBA
, type
: gl
.UNSIGNED_BYTE
};
168 testFormat(internalformat
, srcTexFormatsTypes
, gl
.COLOR_ATTACHMENT0
, gl
.NO_ERROR
, "copyTexImage2D should succeed for good internalformat ");
171 goodIntFormats
.forEach(function(internalformat
) {
172 var srcTexFormatsTypes
= { internalformat
: "RGBA32I", format
: gl
.RGBA_INTEGER
, type
: gl
.INT
};
173 testFormat(internalformat
, srcTexFormatsTypes
, gl
.COLOR_ATTACHMENT0
, gl
.NO_ERROR
, "copyTexImage2D should succeed for good internalformat ");
175 goodIntFormatsWithUnmatchedComponentSizes
.forEach(function(internalformat
) {
176 var srcTexFormatsTypes
= { internalformat
: "RGBA32I", format
: gl
.RGBA_INTEGER
, type
: gl
.INT
};
177 testFormat(internalformat
, srcTexFormatsTypes
, gl
.COLOR_ATTACHMENT0
, gl
.INVALID_OPERATION
,
178 "copyTexImage2D should fail for good internalformat with unmatched component sizes ");
181 goodUnsignedIntFormats
.forEach(function(internalformat
) {
182 var srcTexFormatsTypes
= { internalformat
: "RGBA32UI", format
: gl
.RGBA_INTEGER
, type
: gl
.UNSIGNED_INT
};
183 testFormat(internalformat
, srcTexFormatsTypes
, gl
.COLOR_ATTACHMENT0
, gl
.NO_ERROR
, "copyTexImage2D should succeed for good internalformat ");
185 goodUnsignedIntFormatsWithUnmatchedComponentSizes
.forEach(function(internalformat
) {
186 var srcTexFormatsTypes
= { internalformat
: "RGBA32UI", format
: gl
.RGBA_INTEGER
, type
: gl
.UNSIGNED_INT
};
187 testFormat(internalformat
, srcTexFormatsTypes
, gl
.COLOR_ATTACHMENT0
, gl
.INVALID_OPERATION
,
188 "copyTexImage2D should fail for good internalformat with unmatched component sizes ");
191 snormFormats
.forEach(function(internalformat
) {
192 const srcTexFormatsTypes
= { internalformat
: "RGBA8", format
: gl
.RGBA
, type
: gl
.UNSIGNED_BYTE
};
193 testFormat(internalformat
, srcTexFormatsTypes
, gl
.COLOR_ATTACHMENT0
, [gl
.INVALID_ENUM
, gl
.INVALID_OPERATION
], "copyTexImage2D should fail for snorm internalformat ");
196 if (gl
.getExtension("EXT_color_buffer_float")) {
197 float16Formats
.forEach(function(internalformat
) {
198 var srcTexFormatsTypes
= { internalformat
: "RGBA16F", format
: gl
.RGBA
, type
: gl
.FLOAT
};
199 testFormat(internalformat
, srcTexFormatsTypes
, gl
.COLOR_ATTACHMENT0
, gl
.NO_ERROR
, "copyTexImage2D should succeed for float16 internalformat ");
201 float32Formats
.forEach(function(internalformat
) {
202 var srcTexFormatsTypes
= { internalformat
: "RGBA32F", format
: gl
.RGBA
, type
: gl
.FLOAT
};
203 testFormat(internalformat
, srcTexFormatsTypes
, gl
.COLOR_ATTACHMENT0
, gl
.NO_ERROR
, "copyTexImage2D should succeed for float32 internalformat ");
205 float11Formats
.forEach(function(internalformat
) {
206 var srcTexFormatsTypes
= { internalformat
: "R11F_G11F_B10F", format
: gl
.RGB
, type
: gl
.FLOAT
};
207 testFormat(internalformat
, srcTexFormatsTypes
, gl
.COLOR_ATTACHMENT0
, gl
.NO_ERROR
, "copyTexImage2D should succeed for R11F_G11F_B10F internalformat ");
210 float32Formats
.concat(float11Formats
).forEach(function(internalformat
) {
211 var srcTexFormatsTypes
= { internalformat
: "RGBA16F", format
: gl
.RGBA
, type
: gl
.FLOAT
};
212 testFormat(internalformat
, srcTexFormatsTypes
, gl
.COLOR_ATTACHMENT0
, gl
.INVALID_OPERATION
,
213 "copyTexImage2D should fail for non-float16 internalformat (unmatched component sizes) ");
215 float16Formats
.concat(float11Formats
).forEach(function(internalformat
) {
216 var srcTexFormatsTypes
= { internalformat
: "RGBA32F", format
: gl
.RGBA
, type
: gl
.FLOAT
};
217 testFormat(internalformat
, srcTexFormatsTypes
, gl
.COLOR_ATTACHMENT0
, gl
.INVALID_OPERATION
,
218 "copyTexImage2D should fail for non-float32 internalformat (unmatched component sizes) ");
220 float16Formats
.concat(float32Formats
).forEach(function(internalformat
) {
221 var srcTexFormatsTypes
= { internalformat
: "R11F_G11F_B10F", format
: gl
.RGB
, type
: gl
.FLOAT
};
222 testFormat(internalformat
, srcTexFormatsTypes
, gl
.COLOR_ATTACHMENT0
, gl
.INVALID_OPERATION
,
223 "copyTexImage2D should fail for non-R11F_G11F_B10F internalformat (unmatched component sizes) ");
227 depthAndOrStencilFormats
.forEach(function(internalformat
) {
228 var srcTexFormatsTypes
= { internalformat
: "DEPTH24_STENCIL8", format
: gl
.DEPTH_STENCIL
, type
: gl
.UNSIGNED_INT_24_8
};
229 testFormat(internalformat
, srcTexFormatsTypes
, gl
.DEPTH_STENCIL_ATTACHMENT
,
230 [gl
.INVALID_ENUM
, gl
.INVALID_OPERATION
],
231 "copyTexImage2D should fail for depth internalformat ");
234 gl
.deleteTexture(texture
);
238 testFailed("WebGL context does not exist");
240 testPassed("WebGL context exists");
241 testInternalformat();
244 var successfullyParsed
= true;
246 <script src=
"../../../js/js-test-post.js"></script>