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__anon01506d290111::TexFormat30 TexFormat(GLenum internalFormat, GLenum unpackFormat, GLenum unpackType)
31 : internalFormat(internalFormat), unpackFormat(unpackFormat), unpackType(unpackType)
32 {}
33
bytesPerPixel__anon01506d290111::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 switch (format.unpackFormat)
228 {
229 case GL_RGBA:
230 case GL_RGBA_INTEGER:
231 expected = {refVals[0], refVals[1], refVals[2], refVals[3]};
232 break;
233 case GL_RGB:
234 expected = {refVals[0], refVals[1], refVals[2], 255};
235 break;
236 case GL_RG:
237 expected = {refVals[0], refVals[1], 0, 255};
238 break;
239 case GL_DEPTH_COMPONENT:
240 case GL_DEPTH_STENCIL:
241 // Metal back-end requires swizzle feature to return (depth, 0, 0, 1) from sampling
242 // a depth texture.
243 // http://anglebug.com/5243
244 if (IsMetal() && !IsMetalTextureSwizzleAvailable())
245 {
246 // If texture swizzle is not supported, we should only compare the first
247 // component.
248 expected = {refVals[0], actual[1], actual[2], actual[3]};
249 }
250 else
251 {
252
253 expected = {refVals[0], 0, 0, 255};
254 }
255 break;
256 case GL_RED:
257 expected = {refVals[0], 0, 0, 255};
258 break;
259
260 case GL_RGB_INTEGER:
261 expected = {refVals[0], refVals[1], refVals[2], refVals[0]};
262 break;
263 case GL_RG_INTEGER:
264 expected = {refVals[0], refVals[1], 0, refVals[0]};
265 break;
266 case GL_RED_INTEGER:
267 expected = {refVals[0], 0, 0, refVals[0]};
268 break;
269
270 case GL_LUMINANCE_ALPHA:
271 expected = {refVals[0], refVals[0], refVals[0], refVals[1]};
272 break;
273 case GL_LUMINANCE:
274 expected = {refVals[0], refVals[0], refVals[0], 255};
275 break;
276 case GL_ALPHA:
277 expected = {0, 0, 0, refVals[0]};
278 break;
279
280 default:
281 assert(false);
282 }
283
284 ASSERT_GL_NO_ERROR();
285 auto result = actual.ExpectNear(expected, err);
286 if (!result)
287 {
288 result << " [" << EnumStr(format.internalFormat) << "/" << EnumStr(format.unpackFormat)
289 << "/" << EnumStr(format.unpackType) << " " << info << "]";
290 }
291 EXPECT_TRUE(result);
292 };
293
294 // Provide buffers for test data, and a func to run the test on both the data directly, and on
295 // a basic subrect selection to ensure pixel byte size is calculated correctly.
296 // Possible todo here is to add tests to ensure stride calculation.
297
298 std::array<uint8_t, sizeof(float) * 4> srcBuffer;
299
300 std::array<uint8_t, srcBuffer.size() * 2> subrectBuffer;
301 const auto fnTest = [&](const TexFormat &format, const GLColor &err) {
302 fnTestData(format, srcBuffer.data(), err, "simple");
303
304 if (!hasSubrectUploads)
305 return;
306
307 const auto bytesPerPixel = format.bytesPerPixel();
308
309 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
310
311 subrectBuffer.fill(0);
312 memcpy(subrectBuffer.data() + bytesPerPixel, srcBuffer.data(), bytesPerPixel);
313 fnTestData(format, subrectBuffer.data(), err, "subrect");
314
315 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
316 };
317
318 // Test All The Formats, organized by unpack format and type.
319 // (Combos from GLES 3.0.5 p111-112: Table 3.2: "Valid combinations of format, type, and sized
320 // internalformat.")
321
322 // Start with normalized ints
323 glUseProgram(floatsProg);
324
325 // RGBA+UNSIGNED_BYTE
326 {
327 constexpr uint8_t src[] = {static_cast<uint8_t>(EncodeNormUint<8>(srcVals[0])),
328 static_cast<uint8_t>(EncodeNormUint<8>(srcVals[1])),
329 static_cast<uint8_t>(EncodeNormUint<8>(srcVals[2])),
330 static_cast<uint8_t>(EncodeNormUint<8>(srcVals[3]))};
331 ZeroAndCopy(srcBuffer, src);
332
333 fnTest(TexFormat(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE), {1, 1, 1, 1});
334 fnTest(TexFormat(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE), {8, 8, 8, 255});
335 fnTest(TexFormat(GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE), {16, 16, 16, 16});
336
337 fnTest(TexFormat(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE), {1, 1, 1, 0});
338 fnTest(TexFormat(GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE), {8, 4, 8, 0});
339
340 fnTest(TexFormat(GL_RG8, GL_RG, GL_UNSIGNED_BYTE), {1, 1, 0, 0});
341
342 fnTest(TexFormat(GL_R8, GL_RED, GL_UNSIGNED_BYTE), {1, 0, 0, 0});
343
344 fnTest(TexFormat(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE), {1, 1, 1, 1});
345 fnTest(TexFormat(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE), {1, 1, 1, 0});
346 fnTest(TexFormat(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE), {1, 1, 1, 1});
347 fnTest(TexFormat(GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE), {1, 1, 1, 0});
348 fnTest(TexFormat(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE), {0, 0, 0, 1});
349 }
350
351 // RGBA+BYTE
352 {
353 constexpr uint8_t src[] = {static_cast<uint8_t>(EncodeNormUint<7>(srcVals[0])),
354 static_cast<uint8_t>(EncodeNormUint<7>(srcVals[1])),
355 static_cast<uint8_t>(EncodeNormUint<7>(srcVals[2])),
356 static_cast<uint8_t>(EncodeNormUint<7>(srcVals[3]))};
357 ZeroAndCopy(srcBuffer, src);
358
359 fnTest(TexFormat(GL_RGBA8_SNORM, GL_RGBA, GL_BYTE), {2, 2, 2, 2});
360 fnTest(TexFormat(GL_RGB8_SNORM, GL_RGB, GL_BYTE), {2, 2, 2, 0});
361 fnTest(TexFormat(GL_RG8_SNORM, GL_RG, GL_BYTE), {2, 2, 0, 0});
362 fnTest(TexFormat(GL_R8_SNORM, GL_RED, GL_BYTE), {2, 0, 0, 0});
363 }
364
365 // RGB+UNSIGNED_SHORT_5_6_5
366 {
367 constexpr uint16_t src[] = {static_cast<uint16_t>((EncodeNormUint<5>(srcVals[0]) << 11) |
368 (EncodeNormUint<6>(srcVals[1]) << 5) |
369 (EncodeNormUint<5>(srcVals[2]) << 0))};
370 ZeroAndCopy(srcBuffer, src);
371
372 fnTest(TexFormat(GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5), {8, 4, 8, 0});
373 fnTest(TexFormat(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5), {8, 4, 8, 0});
374 }
375
376 // RGBA+UNSIGNED_SHORT_4_4_4_4
377 {
378 constexpr uint16_t src[] = {static_cast<uint16_t>(
379 (EncodeNormUint<4>(srcVals[0]) << 12) | (EncodeNormUint<4>(srcVals[1]) << 8) |
380 (EncodeNormUint<4>(srcVals[2]) << 4) | (EncodeNormUint<4>(srcVals[3]) << 0))};
381 ZeroAndCopy(srcBuffer, src);
382
383 fnTest(TexFormat(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4), {16, 16, 16, 16});
384 fnTest(TexFormat(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4), {16, 16, 16, 16});
385 }
386
387 // RGBA+UNSIGNED_SHORT_5_5_5_1
388 {
389 constexpr uint16_t src[] = {static_cast<uint16_t>(
390 (EncodeNormUint<5>(srcVals[0]) << 11) | (EncodeNormUint<5>(srcVals[1]) << 6) |
391 (EncodeNormUint<5>(srcVals[2]) << 1) | (EncodeNormUint<1>(srcVals[3]) << 0))};
392 ZeroAndCopy(srcBuffer, src);
393
394 fnTest(TexFormat(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1), {8, 8, 8, 255});
395 }
396
397 // RGBA+UNSIGNED_INT_2_10_10_10_REV
398 {
399 constexpr uint32_t src[] = {
400 (EncodeNormUint<10>(srcVals[0]) << 0) | (EncodeNormUint<10>(srcVals[1]) << 10) |
401 (EncodeNormUint<10>(srcVals[2]) << 20) | (EncodeNormUint<2>(srcVals[3]) << 30)};
402 ZeroAndCopy(srcBuffer, src);
403
404 fnTest(TexFormat(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV), {1, 1, 1, 128});
405 fnTest(TexFormat(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV), {8, 8, 8, 255});
406 fnTest(TexFormat(GL_RGBA, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV), {1, 1, 1, 128});
407 }
408
409 // RGB+UNSIGNED_INT_2_10_10_10_REV
410 {
411 constexpr uint32_t src[] = {
412 (EncodeNormUint<10>(srcVals[0]) << 0) | (EncodeNormUint<10>(srcVals[1]) << 10) |
413 (EncodeNormUint<10>(srcVals[2]) << 20) | (EncodeNormUint<2>(srcVals[3]) << 30)};
414 ZeroAndCopy(srcBuffer, src);
415
416 fnTest(TexFormat(GL_RGB, GL_RGB, GL_UNSIGNED_INT_2_10_10_10_REV), {1, 1, 1, 0});
417 }
418
419 // DEPTH_COMPONENT+UNSIGNED_SHORT
420 {
421 const uint16_t src[] = {static_cast<uint16_t>(EncodeNormUint<16>(srcVals[0]))};
422 ZeroAndCopy(srcBuffer, src);
423
424 fnTest(TexFormat(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT),
425 {1, 0, 0, 0});
426 }
427
428 // DEPTH_COMPONENT+UNSIGNED_INT
429 {
430 constexpr uint32_t src[] = {EncodeNormUint<32>(srcVals[0])};
431 ZeroAndCopy(srcBuffer, src);
432
433 fnTest(TexFormat(GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT), {1, 0, 0, 0});
434 fnTest(TexFormat(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT), {1, 0, 0, 0});
435 }
436
437 // DEPTH_STENCIL+UNSIGNED_INT_24_8
438 {
439 // Drop stencil.
440 constexpr uint32_t src[] = {EncodeNormUint<24>(srcVals[0]) << 8};
441 ZeroAndCopy(srcBuffer, src);
442
443 fnTest(TexFormat(GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8),
444 {1, 0, 0, 0});
445 }
446
447 if (getClientMajorVersion() < 3)
448 return;
449
450 constexpr char kVertShaderES3[] = R"(#version 300 es
451 void main()
452 {
453 gl_PointSize = 1.0;
454 gl_Position = vec4(0, 0, 0, 1);
455 })";
456 constexpr char kFragShader_Ints[] = R"(#version 300 es
457 precision mediump float;
458 uniform highp isampler2D uTex;
459 out vec4 oFragColor;
460
461 void main()
462 {
463 oFragColor = vec4(texture(uTex, vec2(0,0))) / 8.0;
464 })";
465 constexpr char kFragShader_Uints[] = R"(#version 300 es
466 precision mediump float;
467 uniform highp usampler2D uTex;
468 out vec4 oFragColor;
469
470 void main()
471 {
472 oFragColor = vec4(texture(uTex, vec2(0,0))) / 8.0;
473 })";
474 ANGLE_GL_PROGRAM(intsProg, kVertShaderES3, kFragShader_Ints);
475 ANGLE_GL_PROGRAM(uintsProg, kVertShaderES3, kFragShader_Uints);
476
477 // Non-normalized ints
478 glUseProgram(intsProg);
479
480 // RGBA_INTEGER+UNSIGNED_BYTE
481 {
482 constexpr uint8_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
483 ZeroAndCopy(srcBuffer, src);
484
485 fnTest(TexFormat(GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE), {1, 1, 1, 1});
486 fnTest(TexFormat(GL_RGB8I, GL_RGB_INTEGER, GL_BYTE), {1, 1, 1, 1});
487 fnTest(TexFormat(GL_RG8I, GL_RG_INTEGER, GL_BYTE), {1, 1, 1, 1});
488 fnTest(TexFormat(GL_R8I, GL_RED_INTEGER, GL_BYTE), {1, 1, 1, 1});
489 }
490
491 // RGBA_INTEGER+UNSIGNED_SHORT
492 {
493 constexpr uint16_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
494 ZeroAndCopy(srcBuffer, src);
495
496 fnTest(TexFormat(GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT), {1, 1, 1, 1});
497 fnTest(TexFormat(GL_RGB16I, GL_RGB_INTEGER, GL_SHORT), {1, 1, 1, 1});
498 fnTest(TexFormat(GL_RG16I, GL_RG_INTEGER, GL_SHORT), {1, 1, 1, 1});
499 fnTest(TexFormat(GL_R16I, GL_RED_INTEGER, GL_SHORT), {1, 1, 1, 1});
500 }
501
502 // RGBA_INTEGER+UNSIGNED_INT
503 {
504 constexpr uint32_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
505 ZeroAndCopy(srcBuffer, src);
506
507 fnTest(TexFormat(GL_RGBA32I, GL_RGBA_INTEGER, GL_INT), {1, 1, 1, 1});
508 fnTest(TexFormat(GL_RGB32I, GL_RGB_INTEGER, GL_INT), {1, 1, 1, 1});
509 fnTest(TexFormat(GL_RG32I, GL_RG_INTEGER, GL_INT), {1, 1, 1, 1});
510 fnTest(TexFormat(GL_R32I, GL_RED_INTEGER, GL_INT), {1, 1, 1, 1});
511 }
512
513 // Non-normalized uints
514 glUseProgram(uintsProg);
515
516 // RGBA_INTEGER+UNSIGNED_BYTE
517 {
518 constexpr uint8_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
519 ZeroAndCopy(srcBuffer, src);
520
521 fnTest(TexFormat(GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE), {1, 1, 1, 1});
522 fnTest(TexFormat(GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE), {1, 1, 1, 1});
523 fnTest(TexFormat(GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE), {1, 1, 1, 1});
524 fnTest(TexFormat(GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE), {1, 1, 1, 1});
525 }
526
527 // RGBA_INTEGER+UNSIGNED_SHORT
528 {
529 constexpr uint16_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
530 ZeroAndCopy(srcBuffer, src);
531
532 fnTest(TexFormat(GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT), {1, 1, 1, 1});
533 fnTest(TexFormat(GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT), {1, 1, 1, 1});
534 fnTest(TexFormat(GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT), {1, 1, 1, 1});
535 fnTest(TexFormat(GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT), {1, 1, 1, 1});
536 }
537
538 // RGBA_INTEGER+UNSIGNED_INT
539 {
540 constexpr uint32_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
541 ZeroAndCopy(srcBuffer, src);
542
543 fnTest(TexFormat(GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT), {1, 1, 1, 1});
544 fnTest(TexFormat(GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT), {1, 1, 1, 1});
545 fnTest(TexFormat(GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT), {1, 1, 1, 1});
546 fnTest(TexFormat(GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT), {1, 1, 1, 1});
547 }
548
549 // RGBA_INTEGER+UNSIGNED_INT_2_10_10_10_REV
550 {
551 constexpr uint32_t src[] = {static_cast<uint32_t>(srcIntVals[0] << 0) |
552 static_cast<uint32_t>(srcIntVals[1] << 10) |
553 static_cast<uint32_t>(srcIntVals[2] << 20) |
554 static_cast<uint32_t>(srcIntVals[3] << 30)};
555 ZeroAndCopy(srcBuffer, src);
556
557 fnTest(TexFormat(GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV),
558 {1, 1, 1, 1});
559 }
560
561 // True floats
562 glUseProgram(floatsProg);
563
564 // RGBA+HALF_FLOAT
565 {
566 EncodeThenZeroAndCopy<R16G16B16A16F>(srcBuffer, srcVals);
567
568 fnTest(TexFormat(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT), {1, 1, 1, 1});
569
570 fnTest(TexFormat(GL_RGB16F, GL_RGB, GL_HALF_FLOAT), {1, 1, 1, 0});
571 fnTest(TexFormat(GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT), {1, 1, 1, 0});
572 fnTest(TexFormat(GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT), {1, 1, 1, 0});
573
574 fnTest(TexFormat(GL_RG16F, GL_RG, GL_HALF_FLOAT), {1, 1, 0, 0});
575
576 fnTest(TexFormat(GL_R16F, GL_RED, GL_HALF_FLOAT), {1, 0, 0, 0});
577
578 fnTest(TexFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES), {1, 1, 1, 1});
579 fnTest(TexFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES), {1, 1, 1, 0});
580 fnTest(TexFormat(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES), {1, 1, 1, 1});
581 fnTest(TexFormat(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT_OES), {1, 1, 1, 0});
582 fnTest(TexFormat(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT_OES), {0, 0, 0, 1});
583 }
584
585 // RGBA+FLOAT
586 {
587 ZeroAndCopy(srcBuffer, srcVals);
588
589 fnTest(TexFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT), {1, 1, 1, 1});
590 fnTest(TexFormat(GL_RGBA16F, GL_RGBA, GL_FLOAT), {1, 1, 1, 1});
591
592 fnTest(TexFormat(GL_RGB32F, GL_RGB, GL_FLOAT), {1, 1, 1, 0});
593 fnTest(TexFormat(GL_RGB16F, GL_RGB, GL_FLOAT), {1, 1, 1, 0});
594 fnTest(TexFormat(GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT), {1, 1, 1, 0});
595 fnTest(TexFormat(GL_RGB9_E5, GL_RGB, GL_FLOAT), {1, 1, 1, 0});
596
597 fnTest(TexFormat(GL_RG32F, GL_RG, GL_FLOAT), {1, 1, 0, 0});
598 fnTest(TexFormat(GL_RG16F, GL_RG, GL_FLOAT), {1, 1, 0, 0});
599
600 fnTest(TexFormat(GL_R32F, GL_RED, GL_FLOAT), {1, 0, 0, 0});
601 fnTest(TexFormat(GL_R16F, GL_RED, GL_FLOAT), {1, 0, 0, 0});
602 }
603
604 // UNSIGNED_INT_10F_11F_11F_REV
605 {
606 EncodeThenZeroAndCopy<R11G11B10F>(srcBuffer, srcVals);
607
608 fnTest(TexFormat(GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV), {1, 1, 1, 0});
609 }
610
611 // UNSIGNED_INT_5_9_9_9_REV
612 {
613 EncodeThenZeroAndCopy<R9G9B9E5>(srcBuffer, srcVals);
614
615 fnTest(TexFormat(GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV), {1, 1, 1, 0});
616 }
617
618 // DEPTH_COMPONENT+FLOAT
619 {
620 // Skip stencil.
621 constexpr float src[] = {srcVals[0], 0};
622 ZeroAndCopy(srcBuffer, src);
623
624 fnTest(TexFormat(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT), {1, 0, 0, 0});
625 fnTest(TexFormat(GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV),
626 {1, 0, 0, 0});
627 }
628
629 EXPECT_GL_NO_ERROR();
630 }
631
632 ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(TextureUploadFormatTest);
633