• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES Utilities
3  * ------------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Texture format utilities.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "gluTextureUtil.hpp"
25 #include "gluRenderContext.hpp"
26 #include "gluContextInfo.hpp"
27 #include "gluTexture.hpp"
28 #include "tcuTextureUtil.hpp"
29 #include "tcuFormatUtil.hpp"
30 #include "glwEnums.hpp"
31 
32 namespace glu
33 {
34 
35 using std::string;
36 
37 /*--------------------------------------------------------------------*//*!
38  * \brief Map tcu::TextureFormat to GL pixel transfer format.
39  *
40  * Maps generic texture format description to GL pixel transfer format.
41  * If no mapping is found, throws tcu::InternalError.
42  *
43  * \param texFormat Generic texture format.
44  * \return GL pixel transfer format.
45  *//*--------------------------------------------------------------------*/
getTransferFormat(tcu::TextureFormat texFormat)46 TransferFormat getTransferFormat(tcu::TextureFormat texFormat)
47 {
48     using tcu::TextureFormat;
49 
50     uint32_t format = GL_NONE;
51     uint32_t type   = GL_NONE;
52     bool isInt      = false;
53 
54     switch (texFormat.type)
55     {
56     case TextureFormat::SIGNED_INT8:
57     case TextureFormat::SIGNED_INT16:
58     case TextureFormat::SIGNED_INT32:
59     case TextureFormat::UNSIGNED_INT8:
60     case TextureFormat::UNSIGNED_INT16:
61     case TextureFormat::UNSIGNED_INT32:
62     case TextureFormat::UNSIGNED_INT_1010102_REV:
63         isInt = true;
64         break;
65 
66     default:
67         isInt = false;
68         break;
69     }
70 
71     switch (texFormat.order)
72     {
73     case TextureFormat::A:
74         format = GL_ALPHA;
75         break;
76     case TextureFormat::L:
77         format = GL_LUMINANCE;
78         break;
79     case TextureFormat::LA:
80         format = GL_LUMINANCE_ALPHA;
81         break;
82     case TextureFormat::R:
83         format = isInt ? GL_RED_INTEGER : GL_RED;
84         break;
85     case TextureFormat::RG:
86         format = isInt ? GL_RG_INTEGER : GL_RG;
87         break;
88     case TextureFormat::RGB:
89         format = isInt ? GL_RGB_INTEGER : GL_RGB;
90         break;
91     case TextureFormat::RGBA:
92         format = isInt ? GL_RGBA_INTEGER : GL_RGBA;
93         break;
94     case TextureFormat::sR:
95         format = GL_RED;
96         break;
97     case TextureFormat::sRG:
98         format = GL_RG;
99         break;
100     case TextureFormat::sRGB:
101         format = GL_RGB;
102         break;
103     case TextureFormat::sRGBA:
104         format = GL_RGBA;
105         break;
106     case TextureFormat::D:
107         format = GL_DEPTH_COMPONENT;
108         break;
109     case TextureFormat::DS:
110         format = GL_DEPTH_STENCIL;
111         break;
112     case TextureFormat::S:
113         format = GL_STENCIL_INDEX;
114         break;
115 
116     case TextureFormat::BGRA:
117         DE_ASSERT(!isInt);
118         format = GL_BGRA;
119         break;
120 
121     default:
122         DE_ASSERT(false);
123     }
124 
125     switch (texFormat.type)
126     {
127     case TextureFormat::SNORM_INT8:
128         type = GL_BYTE;
129         break;
130     case TextureFormat::SNORM_INT16:
131         type = GL_SHORT;
132         break;
133     case TextureFormat::UNORM_INT8:
134         type = GL_UNSIGNED_BYTE;
135         break;
136     case TextureFormat::UNORM_INT16:
137         type = GL_UNSIGNED_SHORT;
138         break;
139     case TextureFormat::UNORM_SHORT_565:
140         type = GL_UNSIGNED_SHORT_5_6_5;
141         break;
142     case TextureFormat::UNORM_SHORT_4444:
143         type = GL_UNSIGNED_SHORT_4_4_4_4;
144         break;
145     case TextureFormat::UNORM_SHORT_5551:
146         type = GL_UNSIGNED_SHORT_5_5_5_1;
147         break;
148     case TextureFormat::SIGNED_INT8:
149         type = GL_BYTE;
150         break;
151     case TextureFormat::SIGNED_INT16:
152         type = GL_SHORT;
153         break;
154     case TextureFormat::SIGNED_INT32:
155         type = GL_INT;
156         break;
157     case TextureFormat::UNSIGNED_INT8:
158         type = GL_UNSIGNED_BYTE;
159         break;
160     case TextureFormat::UNSIGNED_INT16:
161         type = GL_UNSIGNED_SHORT;
162         break;
163     case TextureFormat::UNSIGNED_INT32:
164         type = GL_UNSIGNED_INT;
165         break;
166     case TextureFormat::FLOAT:
167         type = GL_FLOAT;
168         break;
169     case TextureFormat::UNORM_INT_101010:
170         type = GL_UNSIGNED_INT_2_10_10_10_REV;
171         break;
172     case TextureFormat::UNORM_INT_1010102_REV:
173         type = GL_UNSIGNED_INT_2_10_10_10_REV;
174         break;
175     case TextureFormat::UNSIGNED_INT_1010102_REV:
176         type = GL_UNSIGNED_INT_2_10_10_10_REV;
177         break;
178     case TextureFormat::UNSIGNED_INT_11F_11F_10F_REV:
179         type = GL_UNSIGNED_INT_10F_11F_11F_REV;
180         break;
181     case TextureFormat::UNSIGNED_INT_999_E5_REV:
182         type = GL_UNSIGNED_INT_5_9_9_9_REV;
183         break;
184     case TextureFormat::HALF_FLOAT:
185         type = GL_HALF_FLOAT;
186         break;
187     case TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV:
188         type = GL_FLOAT_32_UNSIGNED_INT_24_8_REV;
189         break;
190     case TextureFormat::UNSIGNED_INT_24_8:
191         type = texFormat.order == TextureFormat::D ? GL_UNSIGNED_INT : GL_UNSIGNED_INT_24_8;
192         break;
193 
194     default:
195         throw tcu::InternalError("Can't map texture format to GL transfer format");
196     }
197 
198     return TransferFormat(format, type);
199 }
200 
201 /*--------------------------------------------------------------------*//*!
202  * \brief Map tcu::TextureFormat to GL internal sized format.
203  *
204  * Maps generic texture format description to GL internal format.
205  * If no mapping is found, throws tcu::InternalError.
206  *
207  * \param texFormat Generic texture format.
208  * \return GL sized internal format.
209  *//*--------------------------------------------------------------------*/
getInternalFormat(tcu::TextureFormat texFormat)210 uint32_t getInternalFormat(tcu::TextureFormat texFormat)
211 {
212     DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST < (1 << 16));
213     DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELTYPE_LAST < (1 << 16));
214 
215 #define PACK_FMT(ORDER, TYPE) ((int(ORDER) << 16) | int(TYPE))
216 #define FMT_CASE(ORDER, TYPE) PACK_FMT(tcu::TextureFormat::ORDER, tcu::TextureFormat::TYPE)
217 
218     switch (PACK_FMT(texFormat.order, texFormat.type))
219     {
220     case FMT_CASE(RGBA, UNORM_SHORT_5551):
221         return GL_RGB5_A1;
222     case FMT_CASE(RGBA, UNORM_SHORT_4444):
223         return GL_RGBA4;
224     case FMT_CASE(RGB, UNORM_SHORT_565):
225         return GL_RGB565;
226     case FMT_CASE(D, UNORM_INT16):
227         return GL_DEPTH_COMPONENT16;
228     case FMT_CASE(S, UNSIGNED_INT8):
229         return GL_STENCIL_INDEX8;
230 
231     case FMT_CASE(RGBA, FLOAT):
232         return GL_RGBA32F;
233     case FMT_CASE(RGBA, SIGNED_INT32):
234         return GL_RGBA32I;
235     case FMT_CASE(RGBA, UNSIGNED_INT32):
236         return GL_RGBA32UI;
237     case FMT_CASE(RGBA, UNORM_INT16):
238         return GL_RGBA16;
239     case FMT_CASE(RGBA, SNORM_INT16):
240         return GL_RGBA16_SNORM;
241     case FMT_CASE(RGBA, HALF_FLOAT):
242         return GL_RGBA16F;
243     case FMT_CASE(RGBA, SIGNED_INT16):
244         return GL_RGBA16I;
245     case FMT_CASE(RGBA, UNSIGNED_INT16):
246         return GL_RGBA16UI;
247     case FMT_CASE(RGBA, UNORM_INT8):
248         return GL_RGBA8;
249     case FMT_CASE(RGBA, SIGNED_INT8):
250         return GL_RGBA8I;
251     case FMT_CASE(RGBA, UNSIGNED_INT8):
252         return GL_RGBA8UI;
253     case FMT_CASE(sRGBA, UNORM_INT8):
254         return GL_SRGB8_ALPHA8;
255     case FMT_CASE(RGBA, UNORM_INT_1010102_REV):
256         return GL_RGB10_A2;
257     case FMT_CASE(RGBA, UNSIGNED_INT_1010102_REV):
258         return GL_RGB10_A2UI;
259     case FMT_CASE(RGBA, SNORM_INT8):
260         return GL_RGBA8_SNORM;
261 
262     case FMT_CASE(RGB, UNORM_INT8):
263         return GL_RGB8;
264     case FMT_CASE(RGB, UNSIGNED_INT_11F_11F_10F_REV):
265         return GL_R11F_G11F_B10F;
266     case FMT_CASE(RGB, FLOAT):
267         return GL_RGB32F;
268     case FMT_CASE(RGB, SIGNED_INT32):
269         return GL_RGB32I;
270     case FMT_CASE(RGB, UNSIGNED_INT32):
271         return GL_RGB32UI;
272     case FMT_CASE(RGB, UNORM_INT16):
273         return GL_RGB16;
274     case FMT_CASE(RGB, SNORM_INT16):
275         return GL_RGB16_SNORM;
276     case FMT_CASE(RGB, HALF_FLOAT):
277         return GL_RGB16F;
278     case FMT_CASE(RGB, SIGNED_INT16):
279         return GL_RGB16I;
280     case FMT_CASE(RGB, UNSIGNED_INT16):
281         return GL_RGB16UI;
282     case FMT_CASE(RGB, SNORM_INT8):
283         return GL_RGB8_SNORM;
284     case FMT_CASE(RGB, SIGNED_INT8):
285         return GL_RGB8I;
286     case FMT_CASE(RGB, UNSIGNED_INT8):
287         return GL_RGB8UI;
288     case FMT_CASE(sRGB, UNORM_INT8):
289         return GL_SRGB8;
290     case FMT_CASE(RGB, UNSIGNED_INT_999_E5_REV):
291         return GL_RGB9_E5;
292     case FMT_CASE(RGB, UNORM_INT_1010102_REV):
293         return GL_RGB10;
294 
295     case FMT_CASE(RG, FLOAT):
296         return GL_RG32F;
297     case FMT_CASE(RG, SIGNED_INT32):
298         return GL_RG32I;
299     case FMT_CASE(RG, UNSIGNED_INT32):
300         return GL_RG32UI;
301     case FMT_CASE(RG, UNORM_INT16):
302         return GL_RG16;
303     case FMT_CASE(RG, SNORM_INT16):
304         return GL_RG16_SNORM;
305     case FMT_CASE(RG, HALF_FLOAT):
306         return GL_RG16F;
307     case FMT_CASE(RG, SIGNED_INT16):
308         return GL_RG16I;
309     case FMT_CASE(RG, UNSIGNED_INT16):
310         return GL_RG16UI;
311     case FMT_CASE(RG, UNORM_INT8):
312         return GL_RG8;
313     case FMT_CASE(RG, SIGNED_INT8):
314         return GL_RG8I;
315     case FMT_CASE(RG, UNSIGNED_INT8):
316         return GL_RG8UI;
317     case FMT_CASE(RG, SNORM_INT8):
318         return GL_RG8_SNORM;
319     case FMT_CASE(sRG, UNORM_INT8):
320         return GL_SRG8_EXT;
321 
322     case FMT_CASE(R, FLOAT):
323         return GL_R32F;
324     case FMT_CASE(R, SIGNED_INT32):
325         return GL_R32I;
326     case FMT_CASE(R, UNSIGNED_INT32):
327         return GL_R32UI;
328     case FMT_CASE(R, UNORM_INT16):
329         return GL_R16;
330     case FMT_CASE(R, SNORM_INT16):
331         return GL_R16_SNORM;
332     case FMT_CASE(R, HALF_FLOAT):
333         return GL_R16F;
334     case FMT_CASE(R, SIGNED_INT16):
335         return GL_R16I;
336     case FMT_CASE(R, UNSIGNED_INT16):
337         return GL_R16UI;
338     case FMT_CASE(R, UNORM_INT8):
339         return GL_R8;
340     case FMT_CASE(R, SIGNED_INT8):
341         return GL_R8I;
342     case FMT_CASE(R, UNSIGNED_INT8):
343         return GL_R8UI;
344     case FMT_CASE(R, SNORM_INT8):
345         return GL_R8_SNORM;
346     case FMT_CASE(sR, UNORM_INT8):
347         return GL_SR8_EXT;
348 
349     case FMT_CASE(D, FLOAT):
350         return GL_DEPTH_COMPONENT32F;
351     case FMT_CASE(D, UNSIGNED_INT_24_8):
352         return GL_DEPTH_COMPONENT24;
353     case FMT_CASE(D, UNSIGNED_INT32):
354         return GL_DEPTH_COMPONENT32;
355     case FMT_CASE(DS, FLOAT_UNSIGNED_INT_24_8_REV):
356         return GL_DEPTH32F_STENCIL8;
357     case FMT_CASE(DS, UNSIGNED_INT_24_8):
358         return GL_DEPTH24_STENCIL8;
359 
360     default:
361         throw tcu::InternalError("Can't map texture format to GL internal format");
362     }
363 }
364 
365 /*--------------------------------------------------------------------*//*!
366  * \brief Map generic compressed format to GL compressed format enum.
367  *
368  * Maps generic compressed format to GL compressed format enum value.
369  * If no mapping is found, throws tcu::InternalError.
370  *
371  * \param format Generic compressed format.
372  * \return GL compressed texture format.
373  *//*--------------------------------------------------------------------*/
getGLFormat(tcu::CompressedTexFormat format)374 uint32_t getGLFormat(tcu::CompressedTexFormat format)
375 {
376     switch (format)
377     {
378     case tcu::COMPRESSEDTEXFORMAT_ETC1_RGB8:
379         return GL_ETC1_RGB8_OES;
380     case tcu::COMPRESSEDTEXFORMAT_EAC_R11:
381         return GL_COMPRESSED_R11_EAC;
382     case tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_R11:
383         return GL_COMPRESSED_SIGNED_R11_EAC;
384     case tcu::COMPRESSEDTEXFORMAT_EAC_RG11:
385         return GL_COMPRESSED_RG11_EAC;
386     case tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11:
387         return GL_COMPRESSED_SIGNED_RG11_EAC;
388     case tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8:
389         return GL_COMPRESSED_RGB8_ETC2;
390     case tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8:
391         return GL_COMPRESSED_SRGB8_ETC2;
392     case tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:
393         return GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
394     case tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
395         return GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
396     case tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8:
397         return GL_COMPRESSED_RGBA8_ETC2_EAC;
398     case tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8:
399         return GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
400 
401     case tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA:
402         return GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
403     case tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA:
404         return GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
405     case tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA:
406         return GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
407     case tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA:
408         return GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
409     case tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA:
410         return GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
411     case tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA:
412         return GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
413     case tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA:
414         return GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
415     case tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA:
416         return GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
417     case tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA:
418         return GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
419     case tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA:
420         return GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
421     case tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA:
422         return GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
423     case tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA:
424         return GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
425     case tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA:
426         return GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
427     case tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA:
428         return GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
429     case tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8:
430         return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
431     case tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8:
432         return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
433     case tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8:
434         return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
435     case tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8:
436         return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
437     case tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8:
438         return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
439     case tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8:
440         return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
441     case tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8:
442         return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
443     case tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8:
444         return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
445     case tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8:
446         return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
447     case tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8:
448         return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
449     case tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8:
450         return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
451     case tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8:
452         return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
453     case tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8:
454         return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
455     case tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8:
456         return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
457 
458     default:
459         throw tcu::InternalError("Can't map compressed format to GL format");
460     }
461 }
462 
463 /*--------------------------------------------------------------------*//*!
464  * \brief Map compressed GL format to generic compressed format.
465  *
466  * Maps compressed GL format to generic compressed format.
467  * If no mapping is found, throws tcu::InternalError.
468  *
469  * \param GL compressed texture format.
470  * \return format Generic compressed format.
471  *//*--------------------------------------------------------------------*/
mapGLCompressedTexFormat(uint32_t format)472 tcu::CompressedTexFormat mapGLCompressedTexFormat(uint32_t format)
473 {
474     switch (format)
475     {
476     case GL_ETC1_RGB8_OES:
477         return tcu::COMPRESSEDTEXFORMAT_ETC1_RGB8;
478     case GL_COMPRESSED_R11_EAC:
479         return tcu::COMPRESSEDTEXFORMAT_EAC_R11;
480     case GL_COMPRESSED_SIGNED_R11_EAC:
481         return tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_R11;
482     case GL_COMPRESSED_RG11_EAC:
483         return tcu::COMPRESSEDTEXFORMAT_EAC_RG11;
484     case GL_COMPRESSED_SIGNED_RG11_EAC:
485         return tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11;
486     case GL_COMPRESSED_RGB8_ETC2:
487         return tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8;
488     case GL_COMPRESSED_SRGB8_ETC2:
489         return tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8;
490     case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
491         return tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1;
492     case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
493         return tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1;
494     case GL_COMPRESSED_RGBA8_ETC2_EAC:
495         return tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8;
496     case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
497         return tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8;
498 
499     case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
500         return tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA;
501     case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
502         return tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA;
503     case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
504         return tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA;
505     case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
506         return tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA;
507     case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
508         return tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA;
509     case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
510         return tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA;
511     case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
512         return tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA;
513     case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
514         return tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA;
515     case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
516         return tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA;
517     case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
518         return tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA;
519     case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
520         return tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA;
521     case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
522         return tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA;
523     case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
524         return tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA;
525     case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
526         return tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA;
527     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
528         return tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8;
529     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
530         return tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8;
531     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
532         return tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8;
533     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
534         return tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8;
535     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
536         return tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8;
537     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
538         return tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8;
539     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
540         return tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8;
541     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
542         return tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8;
543     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
544         return tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8;
545     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
546         return tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8;
547     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
548         return tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8;
549     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
550         return tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8;
551     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
552         return tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8;
553     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
554         return tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8;
555 
556     default:
557         throw tcu::InternalError("Can't map compressed GL format to compressed format");
558     }
559 }
560 
isCompressedFormat(uint32_t internalFormat)561 bool isCompressedFormat(uint32_t internalFormat)
562 {
563     switch (internalFormat)
564     {
565     case GL_ETC1_RGB8_OES:
566     case GL_COMPRESSED_R11_EAC:
567     case GL_COMPRESSED_SIGNED_R11_EAC:
568     case GL_COMPRESSED_RG11_EAC:
569     case GL_COMPRESSED_SIGNED_RG11_EAC:
570     case GL_COMPRESSED_RGB8_ETC2:
571     case GL_COMPRESSED_SRGB8_ETC2:
572     case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
573     case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
574     case GL_COMPRESSED_RGBA8_ETC2_EAC:
575     case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
576     case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
577     case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
578     case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
579     case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
580     case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
581     case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
582     case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
583     case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
584     case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
585     case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
586     case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
587     case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
588     case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
589     case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
590     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
591     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
592     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
593     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
594     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
595     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
596     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
597     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
598     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
599     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
600     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
601     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
602     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
603     case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
604         return true;
605 
606     default:
607         return false;
608     }
609 }
610 
mapGLChannelType(uint32_t dataType,bool normalized)611 static tcu::TextureFormat::ChannelType mapGLChannelType(uint32_t dataType, bool normalized)
612 {
613     // \note Normalized bit is ignored where it doesn't apply.
614     using tcu::TextureFormat;
615 
616     switch (dataType)
617     {
618     case GL_UNSIGNED_BYTE:
619         return normalized ? TextureFormat::UNORM_INT8 : TextureFormat::UNSIGNED_INT8;
620     case GL_BYTE:
621         return normalized ? TextureFormat::SNORM_INT8 : TextureFormat::SIGNED_INT8;
622     case GL_UNSIGNED_SHORT:
623         return normalized ? TextureFormat::UNORM_INT16 : TextureFormat::UNSIGNED_INT16;
624     case GL_SHORT:
625         return normalized ? TextureFormat::SNORM_INT16 : TextureFormat::SIGNED_INT16;
626     case GL_UNSIGNED_INT:
627         return normalized ? TextureFormat::UNORM_INT32 : TextureFormat::UNSIGNED_INT32;
628     case GL_INT:
629         return normalized ? TextureFormat::SNORM_INT32 : TextureFormat::SIGNED_INT32;
630     case GL_FLOAT:
631         return TextureFormat::FLOAT;
632     case GL_UNSIGNED_SHORT_4_4_4_4:
633         return TextureFormat::UNORM_SHORT_4444;
634     case GL_UNSIGNED_SHORT_5_5_5_1:
635         return TextureFormat::UNORM_SHORT_5551;
636     case GL_UNSIGNED_SHORT_5_6_5:
637         return TextureFormat::UNORM_SHORT_565;
638     case GL_HALF_FLOAT:
639         return TextureFormat::HALF_FLOAT;
640     case GL_UNSIGNED_INT_2_10_10_10_REV:
641         return normalized ? TextureFormat::UNORM_INT_1010102_REV : TextureFormat::UNSIGNED_INT_1010102_REV;
642     case GL_UNSIGNED_INT_10F_11F_11F_REV:
643         return TextureFormat::UNSIGNED_INT_11F_11F_10F_REV;
644     case GL_UNSIGNED_INT_24_8:
645         return TextureFormat::UNSIGNED_INT_24_8;
646     case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
647         return TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV;
648     case GL_UNSIGNED_INT_5_9_9_9_REV:
649         return TextureFormat::UNSIGNED_INT_999_E5_REV;
650 
651     // GL_OES_texture_half_float
652     case GL_HALF_FLOAT_OES:
653         return TextureFormat::HALF_FLOAT;
654 
655     default:
656         DE_ASSERT(false);
657         return TextureFormat::CHANNELTYPE_LAST;
658     }
659 }
660 
661 /*--------------------------------------------------------------------*//*!
662  * \brief Map GL pixel transfer format to tcu::TextureFormat.
663  *
664  * If no mapping is found, throws tcu::InternalError.
665  *
666  * \param format    GL pixel format.
667  * \param dataType    GL data type.
668  * \return Generic texture format.
669  *//*--------------------------------------------------------------------*/
mapGLTransferFormat(uint32_t format,uint32_t dataType)670 tcu::TextureFormat mapGLTransferFormat(uint32_t format, uint32_t dataType)
671 {
672     using tcu::TextureFormat;
673     switch (format)
674     {
675     case GL_ALPHA:
676         return TextureFormat(TextureFormat::A, mapGLChannelType(dataType, true));
677     case GL_LUMINANCE:
678         return TextureFormat(TextureFormat::L, mapGLChannelType(dataType, true));
679     case GL_LUMINANCE_ALPHA:
680         return TextureFormat(TextureFormat::LA, mapGLChannelType(dataType, true));
681     case GL_RGB:
682         return TextureFormat(TextureFormat::RGB, mapGLChannelType(dataType, true));
683     case GL_RGBA:
684         return TextureFormat(TextureFormat::RGBA, mapGLChannelType(dataType, true));
685     case GL_BGRA:
686         return TextureFormat(TextureFormat::BGRA, mapGLChannelType(dataType, true));
687     case GL_RG:
688         return TextureFormat(TextureFormat::RG, mapGLChannelType(dataType, true));
689     case GL_RED:
690         return TextureFormat(TextureFormat::R, mapGLChannelType(dataType, true));
691     case GL_RGBA_INTEGER:
692         return TextureFormat(TextureFormat::RGBA, mapGLChannelType(dataType, false));
693     case GL_RGB_INTEGER:
694         return TextureFormat(TextureFormat::RGB, mapGLChannelType(dataType, false));
695     case GL_RG_INTEGER:
696         return TextureFormat(TextureFormat::RG, mapGLChannelType(dataType, false));
697     case GL_RED_INTEGER:
698         return TextureFormat(TextureFormat::R, mapGLChannelType(dataType, false));
699     case GL_SRGB:
700         return TextureFormat(TextureFormat::sRGB, mapGLChannelType(dataType, false));
701     case GL_SRGB_ALPHA:
702         return TextureFormat(TextureFormat::sRGBA, mapGLChannelType(dataType, false));
703 
704     case GL_DEPTH_COMPONENT:
705         return TextureFormat(TextureFormat::D, mapGLChannelType(dataType, true));
706     case GL_DEPTH_STENCIL:
707         return TextureFormat(TextureFormat::DS, mapGLChannelType(dataType, true));
708 
709     default:
710         throw tcu::InternalError(string("Can't map GL pixel format (") + tcu::toHex(format).toString() + ", " +
711                                  tcu::toHex(dataType).toString() + ") to texture format");
712     }
713 }
714 
715 /*--------------------------------------------------------------------*//*!
716  * \brief Map GL internal texture format to tcu::TextureFormat.
717  *
718  * If no mapping is found, throws tcu::InternalError.
719  *
720  * \param internalFormat Sized internal format.
721  * \return Generic texture format.
722  *//*--------------------------------------------------------------------*/
mapGLInternalFormat(uint32_t internalFormat)723 tcu::TextureFormat mapGLInternalFormat(uint32_t internalFormat)
724 {
725     using tcu::TextureFormat;
726     switch (internalFormat)
727     {
728     case GL_RGB5_A1:
729         return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_SHORT_5551);
730     case GL_RGBA4:
731         return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_SHORT_4444);
732     case GL_RGB565:
733         return TextureFormat(TextureFormat::RGB, TextureFormat::UNORM_SHORT_565);
734     case GL_DEPTH_COMPONENT16:
735         return TextureFormat(TextureFormat::D, TextureFormat::UNORM_INT16);
736     case GL_STENCIL_INDEX8:
737         return TextureFormat(TextureFormat::S, TextureFormat::UNSIGNED_INT8);
738 
739     case GL_RGBA32F:
740         return TextureFormat(TextureFormat::RGBA, TextureFormat::FLOAT);
741     case GL_RGBA32I:
742         return TextureFormat(TextureFormat::RGBA, TextureFormat::SIGNED_INT32);
743     case GL_RGBA32UI:
744         return TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT32);
745     case GL_RGBA16:
746         return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT16);
747     case GL_RGBA16_SNORM:
748         return TextureFormat(TextureFormat::RGBA, TextureFormat::SNORM_INT16);
749     case GL_RGBA16F:
750         return TextureFormat(TextureFormat::RGBA, TextureFormat::HALF_FLOAT);
751     case GL_RGBA16I:
752         return TextureFormat(TextureFormat::RGBA, TextureFormat::SIGNED_INT16);
753     case GL_RGBA16UI:
754         return TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT16);
755     case GL_RGBA8:
756         return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8);
757     case GL_RGBA8I:
758         return TextureFormat(TextureFormat::RGBA, TextureFormat::SIGNED_INT8);
759     case GL_RGBA8UI:
760         return TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT8);
761     case GL_SRGB8_ALPHA8:
762         return TextureFormat(TextureFormat::sRGBA, TextureFormat::UNORM_INT8);
763     case GL_RGB10_A2:
764         return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT_1010102_REV);
765     case GL_RGB10_A2UI:
766         return TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT_1010102_REV);
767     case GL_RGBA8_SNORM:
768         return TextureFormat(TextureFormat::RGBA, TextureFormat::SNORM_INT8);
769 
770     case GL_RGB8:
771         return TextureFormat(TextureFormat::RGB, TextureFormat::UNORM_INT8);
772     case GL_R11F_G11F_B10F:
773         return TextureFormat(TextureFormat::RGB, TextureFormat::UNSIGNED_INT_11F_11F_10F_REV);
774     case GL_RGB32F:
775         return TextureFormat(TextureFormat::RGB, TextureFormat::FLOAT);
776     case GL_RGB32I:
777         return TextureFormat(TextureFormat::RGB, TextureFormat::SIGNED_INT32);
778     case GL_RGB32UI:
779         return TextureFormat(TextureFormat::RGB, TextureFormat::UNSIGNED_INT32);
780     case GL_RGB16:
781         return TextureFormat(TextureFormat::RGB, TextureFormat::UNORM_INT16);
782     case GL_RGB16_SNORM:
783         return TextureFormat(TextureFormat::RGB, TextureFormat::SNORM_INT16);
784     case GL_RGB16F:
785         return TextureFormat(TextureFormat::RGB, TextureFormat::HALF_FLOAT);
786     case GL_RGB16I:
787         return TextureFormat(TextureFormat::RGB, TextureFormat::SIGNED_INT16);
788     case GL_RGB16UI:
789         return TextureFormat(TextureFormat::RGB, TextureFormat::UNSIGNED_INT16);
790     case GL_RGB8_SNORM:
791         return TextureFormat(TextureFormat::RGB, TextureFormat::SNORM_INT8);
792     case GL_RGB8I:
793         return TextureFormat(TextureFormat::RGB, TextureFormat::SIGNED_INT8);
794     case GL_RGB8UI:
795         return TextureFormat(TextureFormat::RGB, TextureFormat::UNSIGNED_INT8);
796     case GL_SRGB8:
797         return TextureFormat(TextureFormat::sRGB, TextureFormat::UNORM_INT8);
798     case GL_RGB9_E5:
799         return TextureFormat(TextureFormat::RGB, TextureFormat::UNSIGNED_INT_999_E5_REV);
800     case GL_RGB10:
801         return TextureFormat(TextureFormat::RGB, TextureFormat::UNORM_INT_1010102_REV);
802 
803     case GL_RG32F:
804         return TextureFormat(TextureFormat::RG, TextureFormat::FLOAT);
805     case GL_RG32I:
806         return TextureFormat(TextureFormat::RG, TextureFormat::SIGNED_INT32);
807     case GL_RG32UI:
808         return TextureFormat(TextureFormat::RG, TextureFormat::UNSIGNED_INT32);
809     case GL_RG16:
810         return TextureFormat(TextureFormat::RG, TextureFormat::UNORM_INT16);
811     case GL_RG16_SNORM:
812         return TextureFormat(TextureFormat::RG, TextureFormat::SNORM_INT16);
813     case GL_RG16F:
814         return TextureFormat(TextureFormat::RG, TextureFormat::HALF_FLOAT);
815     case GL_RG16I:
816         return TextureFormat(TextureFormat::RG, TextureFormat::SIGNED_INT16);
817     case GL_RG16UI:
818         return TextureFormat(TextureFormat::RG, TextureFormat::UNSIGNED_INT16);
819     case GL_RG8:
820         return TextureFormat(TextureFormat::RG, TextureFormat::UNORM_INT8);
821     case GL_RG8I:
822         return TextureFormat(TextureFormat::RG, TextureFormat::SIGNED_INT8);
823     case GL_RG8UI:
824         return TextureFormat(TextureFormat::RG, TextureFormat::UNSIGNED_INT8);
825     case GL_RG8_SNORM:
826         return TextureFormat(TextureFormat::RG, TextureFormat::SNORM_INT8);
827     case GL_SRG8_EXT:
828         return TextureFormat(TextureFormat::sRG, TextureFormat::UNORM_INT8);
829 
830     case GL_R32F:
831         return TextureFormat(TextureFormat::R, TextureFormat::FLOAT);
832     case GL_R32I:
833         return TextureFormat(TextureFormat::R, TextureFormat::SIGNED_INT32);
834     case GL_R32UI:
835         return TextureFormat(TextureFormat::R, TextureFormat::UNSIGNED_INT32);
836     case GL_R16:
837         return TextureFormat(TextureFormat::R, TextureFormat::UNORM_INT16);
838     case GL_R16_SNORM:
839         return TextureFormat(TextureFormat::R, TextureFormat::SNORM_INT16);
840     case GL_R16F:
841         return TextureFormat(TextureFormat::R, TextureFormat::HALF_FLOAT);
842     case GL_R16I:
843         return TextureFormat(TextureFormat::R, TextureFormat::SIGNED_INT16);
844     case GL_R16UI:
845         return TextureFormat(TextureFormat::R, TextureFormat::UNSIGNED_INT16);
846     case GL_R8:
847         return TextureFormat(TextureFormat::R, TextureFormat::UNORM_INT8);
848     case GL_R8I:
849         return TextureFormat(TextureFormat::R, TextureFormat::SIGNED_INT8);
850     case GL_R8UI:
851         return TextureFormat(TextureFormat::R, TextureFormat::UNSIGNED_INT8);
852     case GL_R8_SNORM:
853         return TextureFormat(TextureFormat::R, TextureFormat::SNORM_INT8);
854     case GL_SR8_EXT:
855         return TextureFormat(TextureFormat::sR, TextureFormat::UNORM_INT8);
856 
857     case GL_BGRA:
858         return TextureFormat(TextureFormat::BGRA, TextureFormat::UNORM_INT8);
859     case GL_BGRA8_EXT:
860         return TextureFormat(TextureFormat::BGRA, TextureFormat::UNORM_INT8);
861 
862     case GL_DEPTH_COMPONENT32F:
863         return TextureFormat(TextureFormat::D, TextureFormat::FLOAT);
864     case GL_DEPTH_COMPONENT24:
865         return TextureFormat(TextureFormat::D, TextureFormat::UNSIGNED_INT_24_8);
866     case GL_DEPTH_COMPONENT32:
867         return TextureFormat(TextureFormat::D, TextureFormat::UNSIGNED_INT32);
868     case GL_DEPTH32F_STENCIL8:
869         return TextureFormat(TextureFormat::DS, TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV);
870     case GL_DEPTH24_STENCIL8:
871         return TextureFormat(TextureFormat::DS, TextureFormat::UNSIGNED_INT_24_8);
872 
873     default:
874         throw tcu::InternalError(string("Can't map GL sized internal format (") +
875                                  tcu::toHex(internalFormat).toString() + ") to texture format");
876     }
877 }
878 
isGLInternalColorFormatFilterable(uint32_t format)879 bool isGLInternalColorFormatFilterable(uint32_t format)
880 {
881     switch (format)
882     {
883     case GL_R8:
884     case GL_R8_SNORM:
885     case GL_RG8:
886     case GL_RG8_SNORM:
887     case GL_RGB8:
888     case GL_RGB8_SNORM:
889     case GL_RGB565:
890     case GL_RGBA4:
891     case GL_RGB5_A1:
892     case GL_RGBA8:
893     case GL_RGBA8_SNORM:
894     case GL_RGB10_A2:
895     case GL_SR8_EXT:
896     case GL_SRG8_EXT:
897     case GL_SRGB8:
898     case GL_SRGB8_ALPHA8:
899     case GL_R16F:
900     case GL_RG16F:
901     case GL_RGB16F:
902     case GL_RGBA16F:
903     case GL_R11F_G11F_B10F:
904     case GL_RGB9_E5:
905         return true;
906 
907     case GL_RGB10_A2UI:
908     case GL_R32F:
909     case GL_RG32F:
910     case GL_RGB32F:
911     case GL_RGBA32F:
912     case GL_R8I:
913     case GL_R8UI:
914     case GL_R16I:
915     case GL_R16UI:
916     case GL_R32I:
917     case GL_R32UI:
918     case GL_RG8I:
919     case GL_RG8UI:
920     case GL_RG16I:
921     case GL_RG16UI:
922     case GL_RG32I:
923     case GL_RG32UI:
924     case GL_RGB8I:
925     case GL_RGB8UI:
926     case GL_RGB16I:
927     case GL_RGB16UI:
928     case GL_RGB32I:
929     case GL_RGB32UI:
930     case GL_RGBA8I:
931     case GL_RGBA8UI:
932     case GL_RGBA16I:
933     case GL_RGBA16UI:
934     case GL_RGBA32I:
935     case GL_RGBA32UI:
936         return false;
937 
938     default:
939         DE_ASSERT(false);
940         return false;
941     }
942 }
943 
mapGLWrapMode(uint32_t wrapMode)944 static inline tcu::Sampler::WrapMode mapGLWrapMode(uint32_t wrapMode)
945 {
946     switch (wrapMode)
947     {
948     case GL_CLAMP_TO_EDGE:
949         return tcu::Sampler::CLAMP_TO_EDGE;
950     case GL_CLAMP_TO_BORDER:
951         return tcu::Sampler::CLAMP_TO_BORDER;
952     case GL_REPEAT:
953         return tcu::Sampler::REPEAT_GL;
954     case GL_MIRRORED_REPEAT:
955         return tcu::Sampler::MIRRORED_REPEAT_GL;
956     default:
957         throw tcu::InternalError("Can't map GL wrap mode " + tcu::toHex(wrapMode).toString());
958     }
959 }
960 
mapGLMinFilterMode(uint32_t filterMode)961 static inline tcu::Sampler::FilterMode mapGLMinFilterMode(uint32_t filterMode)
962 {
963     switch (filterMode)
964     {
965     case GL_NEAREST:
966         return tcu::Sampler::NEAREST;
967     case GL_LINEAR:
968         return tcu::Sampler::LINEAR;
969     case GL_NEAREST_MIPMAP_NEAREST:
970         return tcu::Sampler::NEAREST_MIPMAP_NEAREST;
971     case GL_NEAREST_MIPMAP_LINEAR:
972         return tcu::Sampler::NEAREST_MIPMAP_LINEAR;
973     case GL_LINEAR_MIPMAP_NEAREST:
974         return tcu::Sampler::LINEAR_MIPMAP_NEAREST;
975     case GL_LINEAR_MIPMAP_LINEAR:
976         return tcu::Sampler::LINEAR_MIPMAP_LINEAR;
977     default:
978         throw tcu::InternalError("Can't map GL min filter mode" + tcu::toHex(filterMode).toString());
979     }
980 }
981 
mapGLMagFilterMode(uint32_t filterMode)982 static inline tcu::Sampler::FilterMode mapGLMagFilterMode(uint32_t filterMode)
983 {
984     switch (filterMode)
985     {
986     case GL_NEAREST:
987         return tcu::Sampler::NEAREST;
988     case GL_LINEAR:
989         return tcu::Sampler::LINEAR;
990     default:
991         throw tcu::InternalError("Can't map GL mag filter mode" + tcu::toHex(filterMode).toString());
992     }
993 }
994 
995 /*--------------------------------------------------------------------*//*!
996  * \brief Map GL sampler parameters to tcu::Sampler.
997  *
998  * If no mapping is found, throws tcu::InternalError.
999  *
1000  * \param wrapS        S-component wrap mode
1001  * \param minFilter    Minification filter mode
1002  * \param magFilter    Magnification filter mode
1003  * \return Sampler description.
1004  *//*--------------------------------------------------------------------*/
mapGLSampler(uint32_t wrapS,uint32_t minFilter,uint32_t magFilter)1005 tcu::Sampler mapGLSampler(uint32_t wrapS, uint32_t minFilter, uint32_t magFilter)
1006 {
1007     return mapGLSampler(wrapS, wrapS, wrapS, minFilter, magFilter);
1008 }
1009 
1010 /*--------------------------------------------------------------------*//*!
1011  * \brief Map GL sampler parameters to tcu::Sampler.
1012  *
1013  * If no mapping is found, throws tcu::InternalError.
1014  *
1015  * \param wrapS        S-component wrap mode
1016  * \param wrapT        T-component wrap mode
1017  * \param minFilter    Minification filter mode
1018  * \param magFilter    Magnification filter mode
1019  * \return Sampler description.
1020  *//*--------------------------------------------------------------------*/
mapGLSampler(uint32_t wrapS,uint32_t wrapT,uint32_t minFilter,uint32_t magFilter)1021 tcu::Sampler mapGLSampler(uint32_t wrapS, uint32_t wrapT, uint32_t minFilter, uint32_t magFilter)
1022 {
1023     return mapGLSampler(wrapS, wrapT, wrapS, minFilter, magFilter);
1024 }
1025 
1026 /*--------------------------------------------------------------------*//*!
1027  * \brief Map GL sampler parameters to tcu::Sampler.
1028  *
1029  * If no mapping is found, throws tcu::InternalError.
1030  *
1031  * \param wrapS        S-component wrap mode
1032  * \param wrapT        T-component wrap mode
1033  * \param wrapR        R-component wrap mode
1034  * \param minFilter    Minification filter mode
1035  * \param magFilter    Magnification filter mode
1036  * \return Sampler description.
1037  *//*--------------------------------------------------------------------*/
mapGLSampler(uint32_t wrapS,uint32_t wrapT,uint32_t wrapR,uint32_t minFilter,uint32_t magFilter)1038 tcu::Sampler mapGLSampler(uint32_t wrapS, uint32_t wrapT, uint32_t wrapR, uint32_t minFilter, uint32_t magFilter)
1039 {
1040     return tcu::Sampler(mapGLWrapMode(wrapS), mapGLWrapMode(wrapT), mapGLWrapMode(wrapR), mapGLMinFilterMode(minFilter),
1041                         mapGLMagFilterMode(magFilter), 0.0f /* lod threshold */, true /* normalized coords */,
1042                         tcu::Sampler::COMPAREMODE_NONE /* no compare */, 0 /* compare channel */,
1043                         tcu::Vec4(0.0f) /* border color, not used */);
1044 }
1045 
1046 /*--------------------------------------------------------------------*//*!
1047  * \brief Map GL compare function to tcu::Sampler::CompareMode.
1048  *
1049  * If no mapping is found, throws tcu::InternalError.
1050  *
1051  * \param mode GL compare mode
1052  * \return Compare mode
1053  *//*--------------------------------------------------------------------*/
mapGLCompareFunc(uint32_t mode)1054 tcu::Sampler::CompareMode mapGLCompareFunc(uint32_t mode)
1055 {
1056     switch (mode)
1057     {
1058     case GL_LESS:
1059         return tcu::Sampler::COMPAREMODE_LESS;
1060     case GL_LEQUAL:
1061         return tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL;
1062     case GL_GREATER:
1063         return tcu::Sampler::COMPAREMODE_GREATER;
1064     case GL_GEQUAL:
1065         return tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL;
1066     case GL_EQUAL:
1067         return tcu::Sampler::COMPAREMODE_EQUAL;
1068     case GL_NOTEQUAL:
1069         return tcu::Sampler::COMPAREMODE_NOT_EQUAL;
1070     case GL_ALWAYS:
1071         return tcu::Sampler::COMPAREMODE_ALWAYS;
1072     case GL_NEVER:
1073         return tcu::Sampler::COMPAREMODE_NEVER;
1074     default:
1075         throw tcu::InternalError("Can't map GL compare mode " + tcu::toHex(mode).toString());
1076     }
1077 }
1078 
1079 /*--------------------------------------------------------------------*//*!
1080  * \brief Get GL wrap mode.
1081  *
1082  * If no mapping is found, throws tcu::InternalError.
1083  *
1084  * \param wrapMode Wrap mode
1085  * \return GL wrap mode
1086  *//*--------------------------------------------------------------------*/
getGLWrapMode(tcu::Sampler::WrapMode wrapMode)1087 uint32_t getGLWrapMode(tcu::Sampler::WrapMode wrapMode)
1088 {
1089     DE_ASSERT(wrapMode != tcu::Sampler::WRAPMODE_LAST);
1090     switch (wrapMode)
1091     {
1092     case tcu::Sampler::CLAMP_TO_EDGE:
1093         return GL_CLAMP_TO_EDGE;
1094     case tcu::Sampler::CLAMP_TO_BORDER:
1095         return GL_CLAMP_TO_BORDER;
1096     case tcu::Sampler::REPEAT_GL:
1097         return GL_REPEAT;
1098     case tcu::Sampler::MIRRORED_REPEAT_GL:
1099         return GL_MIRRORED_REPEAT;
1100     default:
1101         throw tcu::InternalError("Can't map wrap mode");
1102     }
1103 }
1104 
1105 /*--------------------------------------------------------------------*//*!
1106  * \brief Get GL filter mode.
1107  *
1108  * If no mapping is found, throws tcu::InternalError.
1109  *
1110  * \param filterMode Filter mode
1111  * \return GL filter mode
1112  *//*--------------------------------------------------------------------*/
getGLFilterMode(tcu::Sampler::FilterMode filterMode)1113 uint32_t getGLFilterMode(tcu::Sampler::FilterMode filterMode)
1114 {
1115     DE_ASSERT(filterMode != tcu::Sampler::FILTERMODE_LAST);
1116     switch (filterMode)
1117     {
1118     case tcu::Sampler::NEAREST:
1119         return GL_NEAREST;
1120     case tcu::Sampler::LINEAR:
1121         return GL_LINEAR;
1122     case tcu::Sampler::NEAREST_MIPMAP_NEAREST:
1123         return GL_NEAREST_MIPMAP_NEAREST;
1124     case tcu::Sampler::NEAREST_MIPMAP_LINEAR:
1125         return GL_NEAREST_MIPMAP_LINEAR;
1126     case tcu::Sampler::LINEAR_MIPMAP_NEAREST:
1127         return GL_LINEAR_MIPMAP_NEAREST;
1128     case tcu::Sampler::LINEAR_MIPMAP_LINEAR:
1129         return GL_LINEAR_MIPMAP_LINEAR;
1130     default:
1131         throw tcu::InternalError("Can't map filter mode");
1132     }
1133 }
1134 
1135 /*--------------------------------------------------------------------*//*!
1136  * \brief Get GL compare mode.
1137  *
1138  * If no mapping is found, throws tcu::InternalError.
1139  *
1140  * \param compareMode Compare mode
1141  * \return GL compare mode
1142  *//*--------------------------------------------------------------------*/
getGLCompareFunc(tcu::Sampler::CompareMode compareMode)1143 uint32_t getGLCompareFunc(tcu::Sampler::CompareMode compareMode)
1144 {
1145     DE_ASSERT(compareMode != tcu::Sampler::COMPAREMODE_NONE);
1146     switch (compareMode)
1147     {
1148     case tcu::Sampler::COMPAREMODE_NONE:
1149         return GL_NONE;
1150     case tcu::Sampler::COMPAREMODE_LESS:
1151         return GL_LESS;
1152     case tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL:
1153         return GL_LEQUAL;
1154     case tcu::Sampler::COMPAREMODE_GREATER:
1155         return GL_GREATER;
1156     case tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL:
1157         return GL_GEQUAL;
1158     case tcu::Sampler::COMPAREMODE_EQUAL:
1159         return GL_EQUAL;
1160     case tcu::Sampler::COMPAREMODE_NOT_EQUAL:
1161         return GL_NOTEQUAL;
1162     case tcu::Sampler::COMPAREMODE_ALWAYS:
1163         return GL_ALWAYS;
1164     case tcu::Sampler::COMPAREMODE_NEVER:
1165         return GL_NEVER;
1166     default:
1167         throw tcu::InternalError("Can't map compare mode");
1168     }
1169 }
1170 
1171 /*--------------------------------------------------------------------*//*!
1172  * \brief Get GL cube face.
1173  *
1174  * If no mapping is found, throws tcu::InternalError.
1175  *
1176  * \param face Cube face
1177  * \return GL cube face
1178  *//*--------------------------------------------------------------------*/
getGLCubeFace(tcu::CubeFace face)1179 uint32_t getGLCubeFace(tcu::CubeFace face)
1180 {
1181     DE_ASSERT(face != tcu::CUBEFACE_LAST);
1182     switch (face)
1183     {
1184     case tcu::CUBEFACE_NEGATIVE_X:
1185         return GL_TEXTURE_CUBE_MAP_NEGATIVE_X;
1186     case tcu::CUBEFACE_POSITIVE_X:
1187         return GL_TEXTURE_CUBE_MAP_POSITIVE_X;
1188     case tcu::CUBEFACE_NEGATIVE_Y:
1189         return GL_TEXTURE_CUBE_MAP_NEGATIVE_Y;
1190     case tcu::CUBEFACE_POSITIVE_Y:
1191         return GL_TEXTURE_CUBE_MAP_POSITIVE_Y;
1192     case tcu::CUBEFACE_NEGATIVE_Z:
1193         return GL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
1194     case tcu::CUBEFACE_POSITIVE_Z:
1195         return GL_TEXTURE_CUBE_MAP_POSITIVE_Z;
1196     default:
1197         throw tcu::InternalError("Can't map cube face");
1198     }
1199 }
1200 
getCubeFaceFromGL(uint32_t face)1201 tcu::CubeFace getCubeFaceFromGL(uint32_t face)
1202 {
1203     switch (face)
1204     {
1205     case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1206         return tcu::CUBEFACE_NEGATIVE_X;
1207     case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1208         return tcu::CUBEFACE_POSITIVE_X;
1209     case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1210         return tcu::CUBEFACE_NEGATIVE_Y;
1211     case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1212         return tcu::CUBEFACE_POSITIVE_Y;
1213     case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1214         return tcu::CUBEFACE_NEGATIVE_Z;
1215     case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1216         return tcu::CUBEFACE_POSITIVE_Z;
1217     default:
1218         throw tcu::InternalError("Can't map cube face");
1219     }
1220 }
1221 
1222 /*--------------------------------------------------------------------*//*!
1223  * \brief Get GLSL sampler type for texture format.
1224  *
1225  * If no mapping is found, glu::TYPE_LAST is returned.
1226  *
1227  * \param format Texture format
1228  * \return GLSL 1D sampler type for format
1229  *//*--------------------------------------------------------------------*/
getSampler1DType(tcu::TextureFormat format)1230 DataType getSampler1DType(tcu::TextureFormat format)
1231 {
1232     using tcu::TextureFormat;
1233 
1234     if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
1235         return TYPE_SAMPLER_1D;
1236 
1237     if (format.order == TextureFormat::S)
1238         return TYPE_LAST;
1239 
1240     switch (tcu::getTextureChannelClass(format.type))
1241     {
1242     case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1243     case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1244     case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1245         return glu::TYPE_SAMPLER_1D;
1246 
1247     case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1248         return glu::TYPE_INT_SAMPLER_1D;
1249 
1250     case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1251         return glu::TYPE_UINT_SAMPLER_1D;
1252 
1253     default:
1254         return glu::TYPE_LAST;
1255     }
1256 }
1257 
1258 /*--------------------------------------------------------------------*//*!
1259  * \brief Get GLSL sampler type for texture format.
1260  *
1261  * If no mapping is found, glu::TYPE_LAST is returned.
1262  *
1263  * \param format Texture format
1264  * \return GLSL 2D sampler type for format
1265  *//*--------------------------------------------------------------------*/
getSampler2DType(tcu::TextureFormat format)1266 DataType getSampler2DType(tcu::TextureFormat format)
1267 {
1268     using tcu::TextureFormat;
1269 
1270     if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
1271         return TYPE_SAMPLER_2D;
1272 
1273     if (format.order == TextureFormat::S)
1274         return TYPE_LAST;
1275 
1276     switch (tcu::getTextureChannelClass(format.type))
1277     {
1278     case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1279     case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1280     case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1281         return glu::TYPE_SAMPLER_2D;
1282 
1283     case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1284         return glu::TYPE_INT_SAMPLER_2D;
1285 
1286     case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1287         return glu::TYPE_UINT_SAMPLER_2D;
1288 
1289     default:
1290         return glu::TYPE_LAST;
1291     }
1292 }
1293 
1294 /*--------------------------------------------------------------------*//*!
1295  * \brief Get GLSL sampler type for texture format.
1296  *
1297  * If no mapping is found, glu::TYPE_LAST is returned.
1298  *
1299  * \param format Texture format
1300  * \return GLSL cube map sampler type for format
1301  *//*--------------------------------------------------------------------*/
getSamplerCubeType(tcu::TextureFormat format)1302 DataType getSamplerCubeType(tcu::TextureFormat format)
1303 {
1304     using tcu::TextureFormat;
1305 
1306     if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
1307         return TYPE_SAMPLER_CUBE;
1308 
1309     if (format.order == TextureFormat::S)
1310         return TYPE_LAST;
1311 
1312     switch (tcu::getTextureChannelClass(format.type))
1313     {
1314     case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1315     case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1316     case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1317         return glu::TYPE_SAMPLER_CUBE;
1318 
1319     case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1320         return glu::TYPE_INT_SAMPLER_CUBE;
1321 
1322     case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1323         return glu::TYPE_UINT_SAMPLER_CUBE;
1324 
1325     default:
1326         return glu::TYPE_LAST;
1327     }
1328 }
1329 
1330 /*--------------------------------------------------------------------*//*!
1331  * \brief Get GLSL sampler type for texture format.
1332  *
1333  * If no mapping is found, glu::TYPE_LAST is returned.
1334  *
1335  * \param format Texture format
1336  * \return GLSL 1D array sampler type for format
1337  *//*--------------------------------------------------------------------*/
getSampler1DArrayType(tcu::TextureFormat format)1338 DataType getSampler1DArrayType(tcu::TextureFormat format)
1339 {
1340     using tcu::TextureFormat;
1341 
1342     if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
1343         return TYPE_SAMPLER_1D_ARRAY;
1344 
1345     if (format.order == TextureFormat::S)
1346         return TYPE_LAST;
1347 
1348     switch (tcu::getTextureChannelClass(format.type))
1349     {
1350     case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1351     case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1352     case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1353         return glu::TYPE_SAMPLER_1D_ARRAY;
1354 
1355     case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1356         return glu::TYPE_INT_SAMPLER_1D_ARRAY;
1357 
1358     case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1359         return glu::TYPE_UINT_SAMPLER_1D_ARRAY;
1360 
1361     default:
1362         return glu::TYPE_LAST;
1363     }
1364 }
1365 
1366 /*--------------------------------------------------------------------*//*!
1367  * \brief Get GLSL sampler type for texture format.
1368  *
1369  * If no mapping is found, glu::TYPE_LAST is returned.
1370  *
1371  * \param format Texture format
1372  * \return GLSL 2D array sampler type for format
1373  *//*--------------------------------------------------------------------*/
getSampler2DArrayType(tcu::TextureFormat format)1374 DataType getSampler2DArrayType(tcu::TextureFormat format)
1375 {
1376     using tcu::TextureFormat;
1377 
1378     if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
1379         return TYPE_SAMPLER_2D_ARRAY;
1380 
1381     if (format.order == TextureFormat::S)
1382         return TYPE_LAST;
1383 
1384     switch (tcu::getTextureChannelClass(format.type))
1385     {
1386     case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1387     case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1388     case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1389         return glu::TYPE_SAMPLER_2D_ARRAY;
1390 
1391     case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1392         return glu::TYPE_INT_SAMPLER_2D_ARRAY;
1393 
1394     case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1395         return glu::TYPE_UINT_SAMPLER_2D_ARRAY;
1396 
1397     default:
1398         return glu::TYPE_LAST;
1399     }
1400 }
1401 
1402 /*--------------------------------------------------------------------*//*!
1403  * \brief Get GLSL sampler type for texture format.
1404  *
1405  * If no mapping is found, glu::TYPE_LAST is returned.
1406  *
1407  * \param format Texture format
1408  * \return GLSL 3D sampler type for format
1409  *//*--------------------------------------------------------------------*/
getSampler3DType(tcu::TextureFormat format)1410 DataType getSampler3DType(tcu::TextureFormat format)
1411 {
1412     using tcu::TextureFormat;
1413 
1414     if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
1415         return TYPE_SAMPLER_3D;
1416 
1417     if (format.order == TextureFormat::S)
1418         return TYPE_LAST;
1419 
1420     switch (tcu::getTextureChannelClass(format.type))
1421     {
1422     case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1423     case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1424     case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1425         return glu::TYPE_SAMPLER_3D;
1426 
1427     case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1428         return glu::TYPE_INT_SAMPLER_3D;
1429 
1430     case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1431         return glu::TYPE_UINT_SAMPLER_3D;
1432 
1433     default:
1434         return glu::TYPE_LAST;
1435     }
1436 }
1437 
1438 /*--------------------------------------------------------------------*//*!
1439  * \brief Get GLSL sampler type for texture format.
1440  *
1441  * If no mapping is found, glu::TYPE_LAST is returned.
1442  *
1443  * \param format Texture format
1444  * \return GLSL cube map array sampler type for format
1445  *//*--------------------------------------------------------------------*/
getSamplerCubeArrayType(tcu::TextureFormat format)1446 DataType getSamplerCubeArrayType(tcu::TextureFormat format)
1447 {
1448     using tcu::TextureFormat;
1449 
1450     if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
1451         return TYPE_SAMPLER_CUBE_ARRAY;
1452 
1453     if (format.order == TextureFormat::S)
1454         return TYPE_LAST;
1455 
1456     switch (tcu::getTextureChannelClass(format.type))
1457     {
1458     case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1459     case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1460     case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1461         return glu::TYPE_SAMPLER_CUBE_ARRAY;
1462 
1463     case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1464         return glu::TYPE_INT_SAMPLER_CUBE_ARRAY;
1465 
1466     case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1467         return glu::TYPE_UINT_SAMPLER_CUBE_ARRAY;
1468 
1469     default:
1470         return glu::TYPE_LAST;
1471     }
1472 }
1473 
1474 enum RenderableType
1475 {
1476     RENDERABLE_COLOR   = (1 << 0),
1477     RENDERABLE_DEPTH   = (1 << 1),
1478     RENDERABLE_STENCIL = (1 << 2)
1479 };
1480 
getRenderableBitsES3(const ContextInfo & contextInfo,uint32_t internalFormat)1481 static uint32_t getRenderableBitsES3(const ContextInfo &contextInfo, uint32_t internalFormat)
1482 {
1483     switch (internalFormat)
1484     {
1485     // Color-renderable formats
1486     case GL_RGBA32I:
1487     case GL_RGBA32UI:
1488     case GL_RGBA16I:
1489     case GL_RGBA16UI:
1490     case GL_RGBA8:
1491     case GL_RGBA8I:
1492     case GL_RGBA8UI:
1493     case GL_SRGB8_ALPHA8:
1494     case GL_RGB10_A2:
1495     case GL_RGB10_A2UI:
1496     case GL_RGBA4:
1497     case GL_RGB5_A1:
1498     case GL_RGB8:
1499     case GL_RGB565:
1500     case GL_RG32I:
1501     case GL_RG32UI:
1502     case GL_RG16I:
1503     case GL_RG16UI:
1504     case GL_RG8:
1505     case GL_RG8I:
1506     case GL_RG8UI:
1507     case GL_R32I:
1508     case GL_R32UI:
1509     case GL_R16I:
1510     case GL_R16UI:
1511     case GL_R8:
1512     case GL_R8I:
1513     case GL_R8UI:
1514         return RENDERABLE_COLOR;
1515 
1516     // GL_EXT_color_buffer_float
1517     case GL_RGBA32F:
1518     case GL_R11F_G11F_B10F:
1519     case GL_RG32F:
1520     case GL_R32F:
1521         if (contextInfo.isExtensionSupported("GL_EXT_color_buffer_float"))
1522             return RENDERABLE_COLOR;
1523         else
1524             return 0;
1525 
1526     // GL_EXT_color_buffer_float / GL_EXT_color_buffer_half_float
1527     case GL_RGBA16F:
1528     case GL_RG16F:
1529     case GL_R16F:
1530         if (contextInfo.isExtensionSupported("GL_EXT_color_buffer_float") ||
1531             contextInfo.isExtensionSupported("GL_EXT_color_buffer_half_float"))
1532             return RENDERABLE_COLOR;
1533         else
1534             return 0;
1535 
1536     // Depth formats
1537     case GL_DEPTH_COMPONENT32F:
1538     case GL_DEPTH_COMPONENT24:
1539     case GL_DEPTH_COMPONENT16:
1540         return RENDERABLE_DEPTH;
1541 
1542     // Depth+stencil formats
1543     case GL_DEPTH32F_STENCIL8:
1544     case GL_DEPTH24_STENCIL8:
1545         return RENDERABLE_DEPTH | RENDERABLE_STENCIL;
1546 
1547     // Stencil formats
1548     case GL_STENCIL_INDEX8:
1549         return RENDERABLE_STENCIL;
1550 
1551     default:
1552         return 0;
1553     }
1554 }
1555 
1556 /*--------------------------------------------------------------------*//*!
1557  * \brief Check if sized internal format is color-renderable.
1558  * \note Works currently only on ES3 context.
1559  *//*--------------------------------------------------------------------*/
isSizedFormatColorRenderable(const RenderContext & renderCtx,const ContextInfo & contextInfo,uint32_t sizedFormat)1560 bool isSizedFormatColorRenderable(const RenderContext &renderCtx, const ContextInfo &contextInfo, uint32_t sizedFormat)
1561 {
1562     uint32_t renderable = 0;
1563 
1564     if (renderCtx.getType().getAPI() == ApiType::es(3, 0))
1565         renderable = getRenderableBitsES3(contextInfo, sizedFormat);
1566     else
1567         throw tcu::InternalError("Context type not supported in query");
1568 
1569     return (renderable & RENDERABLE_COLOR) != 0;
1570 }
1571 
getDefaultGatherOffsets(void)1572 const tcu::IVec2 (&getDefaultGatherOffsets(void))[4]
1573 {
1574     static const tcu::IVec2 s_defaultOffsets[4] = {
1575         tcu::IVec2(0, 1),
1576         tcu::IVec2(1, 1),
1577         tcu::IVec2(1, 0),
1578         tcu::IVec2(0, 0),
1579     };
1580     return s_defaultOffsets;
1581 }
1582 
1583 tcu::PixelBufferAccess getTextureBufferEffectiveRefTexture(TextureBuffer &buffer, int maxTextureBufferSize)
1584 {
1585     DE_ASSERT(maxTextureBufferSize > 0);
1586 
1587     const tcu::PixelBufferAccess &fullAccess = buffer.getFullRefTexture();
1588 
1589     return tcu::PixelBufferAccess(fullAccess.getFormat(),
1590                                   tcu::IVec3(de::min(fullAccess.getWidth(), maxTextureBufferSize), 1, 1),
1591                                   fullAccess.getPitch(), fullAccess.getDataPtr());
1592 }
1593 
getTextureBufferEffectiveRefTexture(const TextureBuffer & buffer,int maxTextureBufferSize)1594 tcu::ConstPixelBufferAccess getTextureBufferEffectiveRefTexture(const TextureBuffer &buffer, int maxTextureBufferSize)
1595 {
1596     return getTextureBufferEffectiveRefTexture(const_cast<TextureBuffer &>(buffer), maxTextureBufferSize);
1597 }
1598 
1599 } // namespace glu
1600