1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // Texture upload format tests:
7 // Test all texture unpack/upload formats for sampling correctness.
8 //
9
10 #include "common/mathutil.h"
11 #include "image_util/copyimage.h"
12 #include "test_utils/ANGLETest.h"
13 #include "test_utils/gl_raii.h"
14
15 using namespace angle;
16
17 namespace
18 {
19
20 class TextureUploadFormatTest : public ANGLETest<>
21 {};
22
23 struct TexFormat final
24 {
25 GLenum internalFormat;
26 GLenum unpackFormat;
27 GLenum unpackType;
28
29 TexFormat() = delete;
TexFormat__anonb5ce537a0111::TexFormat30 TexFormat(GLenum internalFormat, GLenum unpackFormat, GLenum unpackType)
31 : internalFormat(internalFormat), unpackFormat(unpackFormat), unpackType(unpackType)
32 {}
33
bytesPerPixel__anonb5ce537a0111::TexFormat34 uint8_t bytesPerPixel() const
35 {
36 uint8_t bytesPerChannel;
37 switch (unpackType)
38 {
39 case GL_UNSIGNED_SHORT_5_6_5:
40 case GL_UNSIGNED_SHORT_4_4_4_4:
41 case GL_UNSIGNED_SHORT_5_5_5_1:
42 return 2;
43
44 case GL_UNSIGNED_INT_2_10_10_10_REV:
45 case GL_UNSIGNED_INT_24_8:
46 case GL_UNSIGNED_INT_10F_11F_11F_REV:
47 case GL_UNSIGNED_INT_5_9_9_9_REV:
48 return 4;
49
50 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
51 return 8;
52
53 case GL_UNSIGNED_BYTE:
54 case GL_BYTE:
55 bytesPerChannel = 1;
56 break;
57
58 case GL_UNSIGNED_SHORT:
59 case GL_SHORT:
60 case GL_HALF_FLOAT:
61 case GL_HALF_FLOAT_OES:
62 bytesPerChannel = 2;
63 break;
64
65 case GL_UNSIGNED_INT:
66 case GL_INT:
67 case GL_FLOAT:
68 bytesPerChannel = 4;
69 break;
70
71 default:
72 assert(false);
73 return 0;
74 }
75
76 switch (unpackFormat)
77 {
78 case GL_RGBA:
79 case GL_RGBA_INTEGER:
80 return bytesPerChannel * 4;
81
82 case GL_RGB:
83 case GL_RGB_INTEGER:
84 return bytesPerChannel * 3;
85
86 case GL_RG:
87 case GL_RG_INTEGER:
88 case GL_LUMINANCE_ALPHA:
89 return bytesPerChannel * 2;
90
91 case GL_RED:
92 case GL_RED_INTEGER:
93 case GL_LUMINANCE:
94 case GL_ALPHA:
95 case GL_DEPTH_COMPONENT:
96 return bytesPerChannel * 1;
97
98 default:
99 assert(false);
100 return 0;
101 }
102 }
103 };
104
105 template <const uint8_t bits>
EncodeNormUint(const float val)106 constexpr uint32_t EncodeNormUint(const float val)
107 {
108 return static_cast<uint32_t>(val * static_cast<float>(UINT32_MAX >> (32 - bits)) +
109 0.5f); // round-half-up
110 }
111
112 } // anonymous namespace
113
114 namespace
115 {
116
117 template <typename DestT, typename SrcT, size_t SrcN>
ZeroAndCopy(DestT & dest,const SrcT (& src)[SrcN])118 void ZeroAndCopy(DestT &dest, const SrcT (&src)[SrcN])
119 {
120 dest.fill(0);
121 memcpy(dest.data(), src, sizeof(SrcT) * SrcN);
122 }
123
EnumStr(const GLenum v)124 std::string EnumStr(const GLenum v)
125 {
126 std::stringstream ret;
127 ret << "0x" << std::hex << v;
128 return ret.str();
129 }
130
131 template <typename ColorT, typename DestT>
EncodeThenZeroAndCopy(DestT & dest,const float srcVals[4])132 void EncodeThenZeroAndCopy(DestT &dest, const float srcVals[4])
133 {
134 ColorF srcValsF(srcVals[0], srcVals[1], srcVals[2], srcVals[3]);
135
136 ColorT encoded;
137 ColorT::writeColor(&encoded, &srcValsF);
138
139 dest.fill(0);
140 memcpy(dest.data(), &encoded, sizeof(ColorT));
141 }
142 } // anonymous namespace
143
144 // Upload (1,2,5,3) to integer formats, and (1,2,5,3)/8.0 to float formats.
145 // Draw a point into a 1x1 renderbuffer and readback the result for comparison with expectations.
146 // Test all internalFormat/unpackFormat/unpackType combinations from ES3.0.
TEST_P(TextureUploadFormatTest,All)147 TEST_P(TextureUploadFormatTest, All)
148 {
149 ANGLE_SKIP_TEST_IF(IsD3D9());
150
151 constexpr char kVertShaderES2[] = R"(
152 void main()
153 {
154 gl_PointSize = 1.0;
155 gl_Position = vec4(0, 0, 0, 1);
156 })";
157 constexpr char kFragShader_Floats[] = R"(
158 precision mediump float;
159 uniform sampler2D uTex;
160
161 void main()
162 {
163 gl_FragColor = texture2D(uTex, vec2(0,0));
164 })";
165 ANGLE_GL_PROGRAM(floatsProg, kVertShaderES2, kFragShader_Floats);
166
167 glDisable(GL_DITHER);
168
169 ASSERT_GL_NO_ERROR();
170
171 // Create the 1x1 framebuffer
172
173 GLRenderbuffer backbufferRB;
174 glBindRenderbuffer(GL_RENDERBUFFER, backbufferRB);
175 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
176 glBindRenderbuffer(GL_RENDERBUFFER, 0);
177
178 GLFramebuffer backbufferFB;
179 glBindFramebuffer(GL_FRAMEBUFFER, backbufferFB);
180 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, backbufferRB);
181 ASSERT_GL_NO_ERROR();
182 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
183
184 glViewport(0, 0, 1, 1);
185
186 // Create and bind our test texture
187
188 GLTexture testTex;
189 glBindTexture(GL_TEXTURE_2D, testTex);
190 // Must be nearest because some texture formats aren't filterable!
191 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
192 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
193
194 ASSERT_GL_NO_ERROR();
195
196 // Initialize our test variables
197
198 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
199 const bool hasSubrectUploads = !glGetError();
200
201 constexpr uint8_t srcIntVals[4] = {1u, 2u, 5u, 3u};
202 constexpr float srcVals[4] = {srcIntVals[0] / 8.0f, srcIntVals[1] / 8.0f, srcIntVals[2] / 8.0f,
203 srcIntVals[3] / 8.0f};
204 constexpr uint8_t refVals[4] = {static_cast<uint8_t>(EncodeNormUint<8>(srcVals[0])),
205 static_cast<uint8_t>(EncodeNormUint<8>(srcVals[1])),
206 static_cast<uint8_t>(EncodeNormUint<8>(srcVals[2])),
207 static_cast<uint8_t>(EncodeNormUint<8>(srcVals[3]))};
208
209 // Test a format with the specified data
210
211 const auto fnTestData = [&](const TexFormat &format, const void *const data, const GLColor &err,
212 const char *const info) {
213 ASSERT_GL_NO_ERROR();
214 glTexImage2D(GL_TEXTURE_2D, 0, format.internalFormat, 1, 1, 0, format.unpackFormat,
215 format.unpackType, data);
216 const auto uploadErr = glGetError();
217 if (uploadErr) // Format might not be supported. (e.g. on ES2)
218 return;
219
220 glClearColor(1, 0, 1, 1);
221 glClear(GL_COLOR_BUFFER_BIT);
222 glDrawArrays(GL_POINTS, 0, 1);
223
224 const auto actual = ReadColor(0, 0);
225
226 GLColor expected;
227 std::optional<GLColor> alternativeExpected;
228 switch (format.unpackFormat)
229 {
230 case GL_RGBA:
231 case GL_RGBA_INTEGER:
232 expected = {refVals[0], refVals[1], refVals[2], refVals[3]};
233 break;
234 case GL_RGB:
235 expected = {refVals[0], refVals[1], refVals[2], 255};
236 break;
237 case GL_RG:
238 expected = {refVals[0], refVals[1], 0, 255};
239 break;
240 case GL_DEPTH_COMPONENT:
241 case GL_DEPTH_STENCIL:
242 expected = {refVals[0], 0, 0, 255};
243 // The green and blue channels are undefined. Some backends treat these textures are
244 // luminance while others return 0 in g/b channels.
245 alternativeExpected = {refVals[0], refVals[0], refVals[0], 255};
246 break;
247 case GL_RED:
248 expected = {refVals[0], 0, 0, 255};
249 break;
250
251 case GL_RGB_INTEGER:
252 expected = {refVals[0], refVals[1], refVals[2], refVals[0]};
253 break;
254 case GL_RG_INTEGER:
255 expected = {refVals[0], refVals[1], 0, refVals[0]};
256 break;
257 case GL_RED_INTEGER:
258 expected = {refVals[0], 0, 0, refVals[0]};
259 break;
260
261 case GL_LUMINANCE_ALPHA:
262 expected = {refVals[0], refVals[0], refVals[0], refVals[1]};
263 break;
264 case GL_LUMINANCE:
265 expected = {refVals[0], refVals[0], refVals[0], 255};
266 break;
267 case GL_ALPHA:
268 expected = {0, 0, 0, refVals[0]};
269 break;
270
271 default:
272 assert(false);
273 }
274
275 ASSERT_GL_NO_ERROR();
276 auto result = actual.ExpectNear(expected, err);
277 if (!result && alternativeExpected.has_value())
278 {
279 result = actual.ExpectNear(*alternativeExpected, err);
280 }
281 EXPECT_TRUE(result) << " [" << EnumStr(format.internalFormat) << "/"
282 << EnumStr(format.unpackFormat) << "/" << EnumStr(format.unpackType)
283 << " " << info << "]";
284 };
285
286 // Provide buffers for test data, and a func to run the test on both the data directly, and on
287 // a basic subrect selection to ensure pixel byte size is calculated correctly.
288 // Possible todo here is to add tests to ensure stride calculation.
289
290 std::array<uint8_t, sizeof(float) * 4> srcBuffer;
291
292 std::array<uint8_t, srcBuffer.size() * 2> subrectBuffer;
293 const auto fnTest = [&](const TexFormat &format, const GLColor &err) {
294 fnTestData(format, srcBuffer.data(), err, "simple");
295
296 if (!hasSubrectUploads)
297 return;
298
299 const auto bytesPerPixel = format.bytesPerPixel();
300
301 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
302
303 subrectBuffer.fill(0);
304 memcpy(subrectBuffer.data() + bytesPerPixel, srcBuffer.data(), bytesPerPixel);
305 fnTestData(format, subrectBuffer.data(), err, "subrect");
306
307 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
308 };
309
310 // Test All The Formats, organized by unpack format and type.
311 // (Combos from GLES 3.0.5 p111-112: Table 3.2: "Valid combinations of format, type, and sized
312 // internalformat.")
313
314 // Start with normalized ints
315 glUseProgram(floatsProg);
316
317 // RGBA+UNSIGNED_BYTE
318 {
319 constexpr uint8_t src[] = {static_cast<uint8_t>(EncodeNormUint<8>(srcVals[0])),
320 static_cast<uint8_t>(EncodeNormUint<8>(srcVals[1])),
321 static_cast<uint8_t>(EncodeNormUint<8>(srcVals[2])),
322 static_cast<uint8_t>(EncodeNormUint<8>(srcVals[3]))};
323 ZeroAndCopy(srcBuffer, src);
324
325 fnTest(TexFormat(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE), {1, 1, 1, 1});
326 fnTest(TexFormat(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE), {8, 8, 8, 255});
327 fnTest(TexFormat(GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE), {16, 16, 16, 16});
328
329 fnTest(TexFormat(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE), {1, 1, 1, 0});
330 fnTest(TexFormat(GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE), {8, 4, 8, 0});
331
332 fnTest(TexFormat(GL_RG8, GL_RG, GL_UNSIGNED_BYTE), {1, 1, 0, 0});
333
334 fnTest(TexFormat(GL_R8, GL_RED, GL_UNSIGNED_BYTE), {1, 0, 0, 0});
335
336 fnTest(TexFormat(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE), {1, 1, 1, 1});
337 fnTest(TexFormat(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE), {1, 1, 1, 0});
338 fnTest(TexFormat(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE), {1, 1, 1, 1});
339 fnTest(TexFormat(GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE), {1, 1, 1, 0});
340 fnTest(TexFormat(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE), {0, 0, 0, 1});
341 if (IsGLExtensionEnabled("GL_OES_required_internalformat"))
342 {
343 fnTest(TexFormat(GL_LUMINANCE4_ALPHA4_OES, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE),
344 {4, 4, 4, 4});
345 fnTest(TexFormat(GL_LUMINANCE8_ALPHA8_OES, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE),
346 {1, 1, 1, 1});
347 fnTest(TexFormat(GL_LUMINANCE8_OES, GL_LUMINANCE, GL_UNSIGNED_BYTE), {1, 1, 1, 0});
348 fnTest(TexFormat(GL_ALPHA8_OES, GL_ALPHA, GL_UNSIGNED_BYTE), {0, 0, 0, 1});
349 }
350 }
351
352 // RGBA+BYTE
353 {
354 constexpr uint8_t src[] = {static_cast<uint8_t>(EncodeNormUint<7>(srcVals[0])),
355 static_cast<uint8_t>(EncodeNormUint<7>(srcVals[1])),
356 static_cast<uint8_t>(EncodeNormUint<7>(srcVals[2])),
357 static_cast<uint8_t>(EncodeNormUint<7>(srcVals[3]))};
358 ZeroAndCopy(srcBuffer, src);
359
360 fnTest(TexFormat(GL_RGBA8_SNORM, GL_RGBA, GL_BYTE), {2, 2, 2, 2});
361 fnTest(TexFormat(GL_RGB8_SNORM, GL_RGB, GL_BYTE), {2, 2, 2, 0});
362 fnTest(TexFormat(GL_RG8_SNORM, GL_RG, GL_BYTE), {2, 2, 0, 0});
363 fnTest(TexFormat(GL_R8_SNORM, GL_RED, GL_BYTE), {2, 0, 0, 0});
364 }
365
366 // RGB+UNSIGNED_SHORT_5_6_5
367 {
368 constexpr uint16_t src[] = {static_cast<uint16_t>((EncodeNormUint<5>(srcVals[0]) << 11) |
369 (EncodeNormUint<6>(srcVals[1]) << 5) |
370 (EncodeNormUint<5>(srcVals[2]) << 0))};
371 ZeroAndCopy(srcBuffer, src);
372
373 fnTest(TexFormat(GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5), {8, 4, 8, 0});
374 fnTest(TexFormat(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5), {8, 4, 8, 0});
375 }
376
377 // RGBA+UNSIGNED_SHORT_4_4_4_4
378 {
379 constexpr uint16_t src[] = {static_cast<uint16_t>(
380 (EncodeNormUint<4>(srcVals[0]) << 12) | (EncodeNormUint<4>(srcVals[1]) << 8) |
381 (EncodeNormUint<4>(srcVals[2]) << 4) | (EncodeNormUint<4>(srcVals[3]) << 0))};
382 ZeroAndCopy(srcBuffer, src);
383
384 fnTest(TexFormat(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4), {16, 16, 16, 16});
385 fnTest(TexFormat(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4), {16, 16, 16, 16});
386 }
387
388 // RGBA+UNSIGNED_SHORT_5_5_5_1
389 {
390 constexpr uint16_t src[] = {static_cast<uint16_t>(
391 (EncodeNormUint<5>(srcVals[0]) << 11) | (EncodeNormUint<5>(srcVals[1]) << 6) |
392 (EncodeNormUint<5>(srcVals[2]) << 1) | (EncodeNormUint<1>(srcVals[3]) << 0))};
393 ZeroAndCopy(srcBuffer, src);
394
395 fnTest(TexFormat(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1), {8, 8, 8, 255});
396 fnTest(TexFormat(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1), {8, 8, 8, 255});
397 }
398
399 // RGBA+UNSIGNED_INT_2_10_10_10_REV
400 {
401 constexpr uint32_t src[] = {
402 (EncodeNormUint<10>(srcVals[0]) << 0) | (EncodeNormUint<10>(srcVals[1]) << 10) |
403 (EncodeNormUint<10>(srcVals[2]) << 20) | (EncodeNormUint<2>(srcVals[3]) << 30)};
404 ZeroAndCopy(srcBuffer, src);
405
406 fnTest(TexFormat(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV), {1, 1, 1, 128});
407 fnTest(TexFormat(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV), {8, 8, 8, 255});
408 fnTest(TexFormat(GL_RGBA, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV), {1, 1, 1, 128});
409 }
410
411 // RGB+UNSIGNED_INT_2_10_10_10_REV
412 {
413 constexpr uint32_t src[] = {
414 (EncodeNormUint<10>(srcVals[0]) << 0) | (EncodeNormUint<10>(srcVals[1]) << 10) |
415 (EncodeNormUint<10>(srcVals[2]) << 20) | (EncodeNormUint<2>(srcVals[3]) << 30)};
416 ZeroAndCopy(srcBuffer, src);
417
418 fnTest(TexFormat(GL_RGB, GL_RGB, GL_UNSIGNED_INT_2_10_10_10_REV), {1, 1, 1, 0});
419 }
420
421 // DEPTH_COMPONENT+UNSIGNED_SHORT
422 {
423 const uint16_t src[] = {static_cast<uint16_t>(EncodeNormUint<16>(srcVals[0]))};
424 ZeroAndCopy(srcBuffer, src);
425
426 fnTest(TexFormat(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT),
427 {1, 0, 0, 0});
428 }
429
430 // DEPTH_COMPONENT+UNSIGNED_INT
431 {
432 constexpr uint32_t src[] = {EncodeNormUint<32>(srcVals[0])};
433 ZeroAndCopy(srcBuffer, src);
434
435 fnTest(TexFormat(GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT), {1, 0, 0, 0});
436 fnTest(TexFormat(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT), {1, 0, 0, 0});
437 }
438
439 // DEPTH_STENCIL+UNSIGNED_INT_24_8
440 {
441 // Drop stencil.
442 constexpr uint32_t src[] = {EncodeNormUint<24>(srcVals[0]) << 8};
443 ZeroAndCopy(srcBuffer, src);
444
445 fnTest(TexFormat(GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8),
446 {1, 0, 0, 0});
447 }
448
449 if (getClientMajorVersion() < 3)
450 return;
451
452 constexpr char kVertShaderES3[] = R"(#version 300 es
453 void main()
454 {
455 gl_PointSize = 1.0;
456 gl_Position = vec4(0, 0, 0, 1);
457 })";
458 constexpr char kFragShader_Ints[] = R"(#version 300 es
459 precision mediump float;
460 uniform highp isampler2D uTex;
461 out vec4 oFragColor;
462
463 void main()
464 {
465 oFragColor = vec4(texture(uTex, vec2(0,0))) / 8.0;
466 })";
467 constexpr char kFragShader_Uints[] = R"(#version 300 es
468 precision mediump float;
469 uniform highp usampler2D uTex;
470 out vec4 oFragColor;
471
472 void main()
473 {
474 oFragColor = vec4(texture(uTex, vec2(0,0))) / 8.0;
475 })";
476 ANGLE_GL_PROGRAM(intsProg, kVertShaderES3, kFragShader_Ints);
477 ANGLE_GL_PROGRAM(uintsProg, kVertShaderES3, kFragShader_Uints);
478
479 // Non-normalized ints
480 glUseProgram(intsProg);
481
482 // RGBA_INTEGER+UNSIGNED_BYTE
483 {
484 constexpr uint8_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
485 ZeroAndCopy(srcBuffer, src);
486
487 fnTest(TexFormat(GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE), {1, 1, 1, 1});
488 fnTest(TexFormat(GL_RGB8I, GL_RGB_INTEGER, GL_BYTE), {1, 1, 1, 1});
489 fnTest(TexFormat(GL_RG8I, GL_RG_INTEGER, GL_BYTE), {1, 1, 1, 1});
490 fnTest(TexFormat(GL_R8I, GL_RED_INTEGER, GL_BYTE), {1, 1, 1, 1});
491 }
492
493 // RGBA_INTEGER+UNSIGNED_SHORT
494 {
495 constexpr uint16_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
496 ZeroAndCopy(srcBuffer, src);
497
498 fnTest(TexFormat(GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT), {1, 1, 1, 1});
499 fnTest(TexFormat(GL_RGB16I, GL_RGB_INTEGER, GL_SHORT), {1, 1, 1, 1});
500 fnTest(TexFormat(GL_RG16I, GL_RG_INTEGER, GL_SHORT), {1, 1, 1, 1});
501 fnTest(TexFormat(GL_R16I, GL_RED_INTEGER, GL_SHORT), {1, 1, 1, 1});
502 }
503
504 // RGBA_INTEGER+UNSIGNED_INT
505 {
506 constexpr uint32_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
507 ZeroAndCopy(srcBuffer, src);
508
509 fnTest(TexFormat(GL_RGBA32I, GL_RGBA_INTEGER, GL_INT), {1, 1, 1, 1});
510 fnTest(TexFormat(GL_RGB32I, GL_RGB_INTEGER, GL_INT), {1, 1, 1, 1});
511 fnTest(TexFormat(GL_RG32I, GL_RG_INTEGER, GL_INT), {1, 1, 1, 1});
512 fnTest(TexFormat(GL_R32I, GL_RED_INTEGER, GL_INT), {1, 1, 1, 1});
513 }
514
515 // Non-normalized uints
516 glUseProgram(uintsProg);
517
518 // RGBA_INTEGER+UNSIGNED_BYTE
519 {
520 constexpr uint8_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
521 ZeroAndCopy(srcBuffer, src);
522
523 fnTest(TexFormat(GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE), {1, 1, 1, 1});
524 fnTest(TexFormat(GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE), {1, 1, 1, 1});
525 fnTest(TexFormat(GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE), {1, 1, 1, 1});
526 fnTest(TexFormat(GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE), {1, 1, 1, 1});
527 }
528
529 // RGBA_INTEGER+UNSIGNED_SHORT
530 {
531 constexpr uint16_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
532 ZeroAndCopy(srcBuffer, src);
533
534 fnTest(TexFormat(GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT), {1, 1, 1, 1});
535 fnTest(TexFormat(GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT), {1, 1, 1, 1});
536 fnTest(TexFormat(GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT), {1, 1, 1, 1});
537 fnTest(TexFormat(GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT), {1, 1, 1, 1});
538 }
539
540 // RGBA_INTEGER+UNSIGNED_INT
541 {
542 constexpr uint32_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
543 ZeroAndCopy(srcBuffer, src);
544
545 fnTest(TexFormat(GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT), {1, 1, 1, 1});
546 fnTest(TexFormat(GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT), {1, 1, 1, 1});
547 fnTest(TexFormat(GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT), {1, 1, 1, 1});
548 fnTest(TexFormat(GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT), {1, 1, 1, 1});
549 }
550
551 // RGBA_INTEGER+UNSIGNED_INT_2_10_10_10_REV
552 {
553 constexpr uint32_t src[] = {static_cast<uint32_t>(srcIntVals[0] << 0) |
554 static_cast<uint32_t>(srcIntVals[1] << 10) |
555 static_cast<uint32_t>(srcIntVals[2] << 20) |
556 static_cast<uint32_t>(srcIntVals[3] << 30)};
557 ZeroAndCopy(srcBuffer, src);
558
559 fnTest(TexFormat(GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV),
560 {1, 1, 1, 1});
561 }
562
563 // True floats
564 glUseProgram(floatsProg);
565
566 // RGBA+HALF_FLOAT
567 {
568 EncodeThenZeroAndCopy<R16G16B16A16F>(srcBuffer, srcVals);
569
570 fnTest(TexFormat(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT), {1, 1, 1, 1});
571
572 fnTest(TexFormat(GL_RGB16F, GL_RGB, GL_HALF_FLOAT), {1, 1, 1, 0});
573 fnTest(TexFormat(GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT), {1, 1, 1, 0});
574 fnTest(TexFormat(GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT), {1, 1, 1, 0});
575
576 fnTest(TexFormat(GL_RG16F, GL_RG, GL_HALF_FLOAT), {1, 1, 0, 0});
577
578 fnTest(TexFormat(GL_R16F, GL_RED, GL_HALF_FLOAT), {1, 0, 0, 0});
579
580 fnTest(TexFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES), {1, 1, 1, 1});
581 fnTest(TexFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES), {1, 1, 1, 0});
582 fnTest(TexFormat(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES), {1, 1, 1, 1});
583 fnTest(TexFormat(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT_OES), {1, 1, 1, 0});
584 fnTest(TexFormat(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT_OES), {0, 0, 0, 1});
585 }
586
587 // RGBA+FLOAT
588 {
589 ZeroAndCopy(srcBuffer, srcVals);
590
591 fnTest(TexFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT), {1, 1, 1, 1});
592 fnTest(TexFormat(GL_RGBA16F, GL_RGBA, GL_FLOAT), {1, 1, 1, 1});
593
594 fnTest(TexFormat(GL_RGB32F, GL_RGB, GL_FLOAT), {1, 1, 1, 0});
595 fnTest(TexFormat(GL_RGB16F, GL_RGB, GL_FLOAT), {1, 1, 1, 0});
596 fnTest(TexFormat(GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT), {1, 1, 1, 0});
597 fnTest(TexFormat(GL_RGB9_E5, GL_RGB, GL_FLOAT), {1, 1, 1, 0});
598
599 fnTest(TexFormat(GL_RG32F, GL_RG, GL_FLOAT), {1, 1, 0, 0});
600 fnTest(TexFormat(GL_RG16F, GL_RG, GL_FLOAT), {1, 1, 0, 0});
601
602 fnTest(TexFormat(GL_R32F, GL_RED, GL_FLOAT), {1, 0, 0, 0});
603 fnTest(TexFormat(GL_R16F, GL_RED, GL_FLOAT), {1, 0, 0, 0});
604 }
605
606 // UNSIGNED_INT_10F_11F_11F_REV
607 {
608 EncodeThenZeroAndCopy<R11G11B10F>(srcBuffer, srcVals);
609
610 fnTest(TexFormat(GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV), {1, 1, 1, 0});
611 }
612
613 // UNSIGNED_INT_5_9_9_9_REV
614 {
615 EncodeThenZeroAndCopy<R9G9B9E5>(srcBuffer, srcVals);
616
617 fnTest(TexFormat(GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV), {1, 1, 1, 0});
618 }
619
620 // DEPTH_COMPONENT+FLOAT
621 {
622 // Skip stencil.
623 constexpr float src[] = {srcVals[0], 0};
624 ZeroAndCopy(srcBuffer, src);
625
626 fnTest(TexFormat(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT), {1, 0, 0, 0});
627 fnTest(TexFormat(GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV),
628 {1, 0, 0, 0});
629 }
630
631 EXPECT_GL_NO_ERROR();
632 }
633
634 ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(TextureUploadFormatTest);
635