xref: /aosp_15_r20/external/deqp/framework/opengl/gluTextureUtil.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
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_DEPTH_COMPONENT32F:
858         return TextureFormat(TextureFormat::D, TextureFormat::FLOAT);
859     case GL_DEPTH_COMPONENT24:
860         return TextureFormat(TextureFormat::D, TextureFormat::UNSIGNED_INT_24_8);
861     case GL_DEPTH_COMPONENT32:
862         return TextureFormat(TextureFormat::D, TextureFormat::UNSIGNED_INT32);
863     case GL_DEPTH32F_STENCIL8:
864         return TextureFormat(TextureFormat::DS, TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV);
865     case GL_DEPTH24_STENCIL8:
866         return TextureFormat(TextureFormat::DS, TextureFormat::UNSIGNED_INT_24_8);
867 
868     default:
869         throw tcu::InternalError(string("Can't map GL sized internal format (") +
870                                  tcu::toHex(internalFormat).toString() + ") to texture format");
871     }
872 }
873 
isGLInternalColorFormatFilterable(uint32_t format)874 bool isGLInternalColorFormatFilterable(uint32_t format)
875 {
876     switch (format)
877     {
878     case GL_R8:
879     case GL_R8_SNORM:
880     case GL_RG8:
881     case GL_RG8_SNORM:
882     case GL_RGB8:
883     case GL_RGB8_SNORM:
884     case GL_RGB565:
885     case GL_RGBA4:
886     case GL_RGB5_A1:
887     case GL_RGBA8:
888     case GL_RGBA8_SNORM:
889     case GL_RGB10_A2:
890     case GL_SR8_EXT:
891     case GL_SRG8_EXT:
892     case GL_SRGB8:
893     case GL_SRGB8_ALPHA8:
894     case GL_R16F:
895     case GL_RG16F:
896     case GL_RGB16F:
897     case GL_RGBA16F:
898     case GL_R11F_G11F_B10F:
899     case GL_RGB9_E5:
900         return true;
901 
902     case GL_RGB10_A2UI:
903     case GL_R32F:
904     case GL_RG32F:
905     case GL_RGB32F:
906     case GL_RGBA32F:
907     case GL_R8I:
908     case GL_R8UI:
909     case GL_R16I:
910     case GL_R16UI:
911     case GL_R32I:
912     case GL_R32UI:
913     case GL_RG8I:
914     case GL_RG8UI:
915     case GL_RG16I:
916     case GL_RG16UI:
917     case GL_RG32I:
918     case GL_RG32UI:
919     case GL_RGB8I:
920     case GL_RGB8UI:
921     case GL_RGB16I:
922     case GL_RGB16UI:
923     case GL_RGB32I:
924     case GL_RGB32UI:
925     case GL_RGBA8I:
926     case GL_RGBA8UI:
927     case GL_RGBA16I:
928     case GL_RGBA16UI:
929     case GL_RGBA32I:
930     case GL_RGBA32UI:
931         return false;
932 
933     default:
934         DE_ASSERT(false);
935         return false;
936     }
937 }
938 
mapGLWrapMode(uint32_t wrapMode)939 static inline tcu::Sampler::WrapMode mapGLWrapMode(uint32_t wrapMode)
940 {
941     switch (wrapMode)
942     {
943     case GL_CLAMP_TO_EDGE:
944         return tcu::Sampler::CLAMP_TO_EDGE;
945     case GL_CLAMP_TO_BORDER:
946         return tcu::Sampler::CLAMP_TO_BORDER;
947     case GL_REPEAT:
948         return tcu::Sampler::REPEAT_GL;
949     case GL_MIRRORED_REPEAT:
950         return tcu::Sampler::MIRRORED_REPEAT_GL;
951     default:
952         throw tcu::InternalError("Can't map GL wrap mode " + tcu::toHex(wrapMode).toString());
953     }
954 }
955 
mapGLMinFilterMode(uint32_t filterMode)956 static inline tcu::Sampler::FilterMode mapGLMinFilterMode(uint32_t filterMode)
957 {
958     switch (filterMode)
959     {
960     case GL_NEAREST:
961         return tcu::Sampler::NEAREST;
962     case GL_LINEAR:
963         return tcu::Sampler::LINEAR;
964     case GL_NEAREST_MIPMAP_NEAREST:
965         return tcu::Sampler::NEAREST_MIPMAP_NEAREST;
966     case GL_NEAREST_MIPMAP_LINEAR:
967         return tcu::Sampler::NEAREST_MIPMAP_LINEAR;
968     case GL_LINEAR_MIPMAP_NEAREST:
969         return tcu::Sampler::LINEAR_MIPMAP_NEAREST;
970     case GL_LINEAR_MIPMAP_LINEAR:
971         return tcu::Sampler::LINEAR_MIPMAP_LINEAR;
972     default:
973         throw tcu::InternalError("Can't map GL min filter mode" + tcu::toHex(filterMode).toString());
974     }
975 }
976 
mapGLMagFilterMode(uint32_t filterMode)977 static inline tcu::Sampler::FilterMode mapGLMagFilterMode(uint32_t filterMode)
978 {
979     switch (filterMode)
980     {
981     case GL_NEAREST:
982         return tcu::Sampler::NEAREST;
983     case GL_LINEAR:
984         return tcu::Sampler::LINEAR;
985     default:
986         throw tcu::InternalError("Can't map GL mag filter mode" + tcu::toHex(filterMode).toString());
987     }
988 }
989 
990 /*--------------------------------------------------------------------*//*!
991  * \brief Map GL sampler parameters to tcu::Sampler.
992  *
993  * If no mapping is found, throws tcu::InternalError.
994  *
995  * \param wrapS        S-component wrap mode
996  * \param minFilter    Minification filter mode
997  * \param magFilter    Magnification filter mode
998  * \return Sampler description.
999  *//*--------------------------------------------------------------------*/
mapGLSampler(uint32_t wrapS,uint32_t minFilter,uint32_t magFilter)1000 tcu::Sampler mapGLSampler(uint32_t wrapS, uint32_t minFilter, uint32_t magFilter)
1001 {
1002     return mapGLSampler(wrapS, wrapS, wrapS, minFilter, magFilter);
1003 }
1004 
1005 /*--------------------------------------------------------------------*//*!
1006  * \brief Map GL sampler parameters to tcu::Sampler.
1007  *
1008  * If no mapping is found, throws tcu::InternalError.
1009  *
1010  * \param wrapS        S-component wrap mode
1011  * \param wrapT        T-component wrap mode
1012  * \param minFilter    Minification filter mode
1013  * \param magFilter    Magnification filter mode
1014  * \return Sampler description.
1015  *//*--------------------------------------------------------------------*/
mapGLSampler(uint32_t wrapS,uint32_t wrapT,uint32_t minFilter,uint32_t magFilter)1016 tcu::Sampler mapGLSampler(uint32_t wrapS, uint32_t wrapT, uint32_t minFilter, uint32_t magFilter)
1017 {
1018     return mapGLSampler(wrapS, wrapT, wrapS, minFilter, magFilter);
1019 }
1020 
1021 /*--------------------------------------------------------------------*//*!
1022  * \brief Map GL sampler parameters to tcu::Sampler.
1023  *
1024  * If no mapping is found, throws tcu::InternalError.
1025  *
1026  * \param wrapS        S-component wrap mode
1027  * \param wrapT        T-component wrap mode
1028  * \param wrapR        R-component wrap mode
1029  * \param minFilter    Minification filter mode
1030  * \param magFilter    Magnification filter mode
1031  * \return Sampler description.
1032  *//*--------------------------------------------------------------------*/
mapGLSampler(uint32_t wrapS,uint32_t wrapT,uint32_t wrapR,uint32_t minFilter,uint32_t magFilter)1033 tcu::Sampler mapGLSampler(uint32_t wrapS, uint32_t wrapT, uint32_t wrapR, uint32_t minFilter, uint32_t magFilter)
1034 {
1035     return tcu::Sampler(mapGLWrapMode(wrapS), mapGLWrapMode(wrapT), mapGLWrapMode(wrapR), mapGLMinFilterMode(minFilter),
1036                         mapGLMagFilterMode(magFilter), 0.0f /* lod threshold */, true /* normalized coords */,
1037                         tcu::Sampler::COMPAREMODE_NONE /* no compare */, 0 /* compare channel */,
1038                         tcu::Vec4(0.0f) /* border color, not used */);
1039 }
1040 
1041 /*--------------------------------------------------------------------*//*!
1042  * \brief Map GL compare function to tcu::Sampler::CompareMode.
1043  *
1044  * If no mapping is found, throws tcu::InternalError.
1045  *
1046  * \param mode GL compare mode
1047  * \return Compare mode
1048  *//*--------------------------------------------------------------------*/
mapGLCompareFunc(uint32_t mode)1049 tcu::Sampler::CompareMode mapGLCompareFunc(uint32_t mode)
1050 {
1051     switch (mode)
1052     {
1053     case GL_LESS:
1054         return tcu::Sampler::COMPAREMODE_LESS;
1055     case GL_LEQUAL:
1056         return tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL;
1057     case GL_GREATER:
1058         return tcu::Sampler::COMPAREMODE_GREATER;
1059     case GL_GEQUAL:
1060         return tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL;
1061     case GL_EQUAL:
1062         return tcu::Sampler::COMPAREMODE_EQUAL;
1063     case GL_NOTEQUAL:
1064         return tcu::Sampler::COMPAREMODE_NOT_EQUAL;
1065     case GL_ALWAYS:
1066         return tcu::Sampler::COMPAREMODE_ALWAYS;
1067     case GL_NEVER:
1068         return tcu::Sampler::COMPAREMODE_NEVER;
1069     default:
1070         throw tcu::InternalError("Can't map GL compare mode " + tcu::toHex(mode).toString());
1071     }
1072 }
1073 
1074 /*--------------------------------------------------------------------*//*!
1075  * \brief Get GL wrap mode.
1076  *
1077  * If no mapping is found, throws tcu::InternalError.
1078  *
1079  * \param wrapMode Wrap mode
1080  * \return GL wrap mode
1081  *//*--------------------------------------------------------------------*/
getGLWrapMode(tcu::Sampler::WrapMode wrapMode)1082 uint32_t getGLWrapMode(tcu::Sampler::WrapMode wrapMode)
1083 {
1084     DE_ASSERT(wrapMode != tcu::Sampler::WRAPMODE_LAST);
1085     switch (wrapMode)
1086     {
1087     case tcu::Sampler::CLAMP_TO_EDGE:
1088         return GL_CLAMP_TO_EDGE;
1089     case tcu::Sampler::CLAMP_TO_BORDER:
1090         return GL_CLAMP_TO_BORDER;
1091     case tcu::Sampler::REPEAT_GL:
1092         return GL_REPEAT;
1093     case tcu::Sampler::MIRRORED_REPEAT_GL:
1094         return GL_MIRRORED_REPEAT;
1095     default:
1096         throw tcu::InternalError("Can't map wrap mode");
1097     }
1098 }
1099 
1100 /*--------------------------------------------------------------------*//*!
1101  * \brief Get GL filter mode.
1102  *
1103  * If no mapping is found, throws tcu::InternalError.
1104  *
1105  * \param filterMode Filter mode
1106  * \return GL filter mode
1107  *//*--------------------------------------------------------------------*/
getGLFilterMode(tcu::Sampler::FilterMode filterMode)1108 uint32_t getGLFilterMode(tcu::Sampler::FilterMode filterMode)
1109 {
1110     DE_ASSERT(filterMode != tcu::Sampler::FILTERMODE_LAST);
1111     switch (filterMode)
1112     {
1113     case tcu::Sampler::NEAREST:
1114         return GL_NEAREST;
1115     case tcu::Sampler::LINEAR:
1116         return GL_LINEAR;
1117     case tcu::Sampler::NEAREST_MIPMAP_NEAREST:
1118         return GL_NEAREST_MIPMAP_NEAREST;
1119     case tcu::Sampler::NEAREST_MIPMAP_LINEAR:
1120         return GL_NEAREST_MIPMAP_LINEAR;
1121     case tcu::Sampler::LINEAR_MIPMAP_NEAREST:
1122         return GL_LINEAR_MIPMAP_NEAREST;
1123     case tcu::Sampler::LINEAR_MIPMAP_LINEAR:
1124         return GL_LINEAR_MIPMAP_LINEAR;
1125     default:
1126         throw tcu::InternalError("Can't map filter mode");
1127     }
1128 }
1129 
1130 /*--------------------------------------------------------------------*//*!
1131  * \brief Get GL compare mode.
1132  *
1133  * If no mapping is found, throws tcu::InternalError.
1134  *
1135  * \param compareMode Compare mode
1136  * \return GL compare mode
1137  *//*--------------------------------------------------------------------*/
getGLCompareFunc(tcu::Sampler::CompareMode compareMode)1138 uint32_t getGLCompareFunc(tcu::Sampler::CompareMode compareMode)
1139 {
1140     DE_ASSERT(compareMode != tcu::Sampler::COMPAREMODE_NONE);
1141     switch (compareMode)
1142     {
1143     case tcu::Sampler::COMPAREMODE_NONE:
1144         return GL_NONE;
1145     case tcu::Sampler::COMPAREMODE_LESS:
1146         return GL_LESS;
1147     case tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL:
1148         return GL_LEQUAL;
1149     case tcu::Sampler::COMPAREMODE_GREATER:
1150         return GL_GREATER;
1151     case tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL:
1152         return GL_GEQUAL;
1153     case tcu::Sampler::COMPAREMODE_EQUAL:
1154         return GL_EQUAL;
1155     case tcu::Sampler::COMPAREMODE_NOT_EQUAL:
1156         return GL_NOTEQUAL;
1157     case tcu::Sampler::COMPAREMODE_ALWAYS:
1158         return GL_ALWAYS;
1159     case tcu::Sampler::COMPAREMODE_NEVER:
1160         return GL_NEVER;
1161     default:
1162         throw tcu::InternalError("Can't map compare mode");
1163     }
1164 }
1165 
1166 /*--------------------------------------------------------------------*//*!
1167  * \brief Get GL cube face.
1168  *
1169  * If no mapping is found, throws tcu::InternalError.
1170  *
1171  * \param face Cube face
1172  * \return GL cube face
1173  *//*--------------------------------------------------------------------*/
getGLCubeFace(tcu::CubeFace face)1174 uint32_t getGLCubeFace(tcu::CubeFace face)
1175 {
1176     DE_ASSERT(face != tcu::CUBEFACE_LAST);
1177     switch (face)
1178     {
1179     case tcu::CUBEFACE_NEGATIVE_X:
1180         return GL_TEXTURE_CUBE_MAP_NEGATIVE_X;
1181     case tcu::CUBEFACE_POSITIVE_X:
1182         return GL_TEXTURE_CUBE_MAP_POSITIVE_X;
1183     case tcu::CUBEFACE_NEGATIVE_Y:
1184         return GL_TEXTURE_CUBE_MAP_NEGATIVE_Y;
1185     case tcu::CUBEFACE_POSITIVE_Y:
1186         return GL_TEXTURE_CUBE_MAP_POSITIVE_Y;
1187     case tcu::CUBEFACE_NEGATIVE_Z:
1188         return GL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
1189     case tcu::CUBEFACE_POSITIVE_Z:
1190         return GL_TEXTURE_CUBE_MAP_POSITIVE_Z;
1191     default:
1192         throw tcu::InternalError("Can't map cube face");
1193     }
1194 }
1195 
getCubeFaceFromGL(uint32_t face)1196 tcu::CubeFace getCubeFaceFromGL(uint32_t face)
1197 {
1198     switch (face)
1199     {
1200     case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1201         return tcu::CUBEFACE_NEGATIVE_X;
1202     case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1203         return tcu::CUBEFACE_POSITIVE_X;
1204     case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1205         return tcu::CUBEFACE_NEGATIVE_Y;
1206     case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1207         return tcu::CUBEFACE_POSITIVE_Y;
1208     case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1209         return tcu::CUBEFACE_NEGATIVE_Z;
1210     case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1211         return tcu::CUBEFACE_POSITIVE_Z;
1212     default:
1213         throw tcu::InternalError("Can't map cube face");
1214     }
1215 }
1216 
1217 /*--------------------------------------------------------------------*//*!
1218  * \brief Get GLSL sampler type for texture format.
1219  *
1220  * If no mapping is found, glu::TYPE_LAST is returned.
1221  *
1222  * \param format Texture format
1223  * \return GLSL 1D sampler type for format
1224  *//*--------------------------------------------------------------------*/
getSampler1DType(tcu::TextureFormat format)1225 DataType getSampler1DType(tcu::TextureFormat format)
1226 {
1227     using tcu::TextureFormat;
1228 
1229     if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
1230         return TYPE_SAMPLER_1D;
1231 
1232     if (format.order == TextureFormat::S)
1233         return TYPE_LAST;
1234 
1235     switch (tcu::getTextureChannelClass(format.type))
1236     {
1237     case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1238     case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1239     case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1240         return glu::TYPE_SAMPLER_1D;
1241 
1242     case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1243         return glu::TYPE_INT_SAMPLER_1D;
1244 
1245     case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1246         return glu::TYPE_UINT_SAMPLER_1D;
1247 
1248     default:
1249         return glu::TYPE_LAST;
1250     }
1251 }
1252 
1253 /*--------------------------------------------------------------------*//*!
1254  * \brief Get GLSL sampler type for texture format.
1255  *
1256  * If no mapping is found, glu::TYPE_LAST is returned.
1257  *
1258  * \param format Texture format
1259  * \return GLSL 2D sampler type for format
1260  *//*--------------------------------------------------------------------*/
getSampler2DType(tcu::TextureFormat format)1261 DataType getSampler2DType(tcu::TextureFormat format)
1262 {
1263     using tcu::TextureFormat;
1264 
1265     if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
1266         return TYPE_SAMPLER_2D;
1267 
1268     if (format.order == TextureFormat::S)
1269         return TYPE_LAST;
1270 
1271     switch (tcu::getTextureChannelClass(format.type))
1272     {
1273     case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1274     case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1275     case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1276         return glu::TYPE_SAMPLER_2D;
1277 
1278     case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1279         return glu::TYPE_INT_SAMPLER_2D;
1280 
1281     case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1282         return glu::TYPE_UINT_SAMPLER_2D;
1283 
1284     default:
1285         return glu::TYPE_LAST;
1286     }
1287 }
1288 
1289 /*--------------------------------------------------------------------*//*!
1290  * \brief Get GLSL sampler type for texture format.
1291  *
1292  * If no mapping is found, glu::TYPE_LAST is returned.
1293  *
1294  * \param format Texture format
1295  * \return GLSL cube map sampler type for format
1296  *//*--------------------------------------------------------------------*/
getSamplerCubeType(tcu::TextureFormat format)1297 DataType getSamplerCubeType(tcu::TextureFormat format)
1298 {
1299     using tcu::TextureFormat;
1300 
1301     if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
1302         return TYPE_SAMPLER_CUBE;
1303 
1304     if (format.order == TextureFormat::S)
1305         return TYPE_LAST;
1306 
1307     switch (tcu::getTextureChannelClass(format.type))
1308     {
1309     case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1310     case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1311     case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1312         return glu::TYPE_SAMPLER_CUBE;
1313 
1314     case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1315         return glu::TYPE_INT_SAMPLER_CUBE;
1316 
1317     case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1318         return glu::TYPE_UINT_SAMPLER_CUBE;
1319 
1320     default:
1321         return glu::TYPE_LAST;
1322     }
1323 }
1324 
1325 /*--------------------------------------------------------------------*//*!
1326  * \brief Get GLSL sampler type for texture format.
1327  *
1328  * If no mapping is found, glu::TYPE_LAST is returned.
1329  *
1330  * \param format Texture format
1331  * \return GLSL 1D array sampler type for format
1332  *//*--------------------------------------------------------------------*/
getSampler1DArrayType(tcu::TextureFormat format)1333 DataType getSampler1DArrayType(tcu::TextureFormat format)
1334 {
1335     using tcu::TextureFormat;
1336 
1337     if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
1338         return TYPE_SAMPLER_1D_ARRAY;
1339 
1340     if (format.order == TextureFormat::S)
1341         return TYPE_LAST;
1342 
1343     switch (tcu::getTextureChannelClass(format.type))
1344     {
1345     case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1346     case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1347     case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1348         return glu::TYPE_SAMPLER_1D_ARRAY;
1349 
1350     case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1351         return glu::TYPE_INT_SAMPLER_1D_ARRAY;
1352 
1353     case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1354         return glu::TYPE_UINT_SAMPLER_1D_ARRAY;
1355 
1356     default:
1357         return glu::TYPE_LAST;
1358     }
1359 }
1360 
1361 /*--------------------------------------------------------------------*//*!
1362  * \brief Get GLSL sampler type for texture format.
1363  *
1364  * If no mapping is found, glu::TYPE_LAST is returned.
1365  *
1366  * \param format Texture format
1367  * \return GLSL 2D array sampler type for format
1368  *//*--------------------------------------------------------------------*/
getSampler2DArrayType(tcu::TextureFormat format)1369 DataType getSampler2DArrayType(tcu::TextureFormat format)
1370 {
1371     using tcu::TextureFormat;
1372 
1373     if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
1374         return TYPE_SAMPLER_2D_ARRAY;
1375 
1376     if (format.order == TextureFormat::S)
1377         return TYPE_LAST;
1378 
1379     switch (tcu::getTextureChannelClass(format.type))
1380     {
1381     case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1382     case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1383     case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1384         return glu::TYPE_SAMPLER_2D_ARRAY;
1385 
1386     case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1387         return glu::TYPE_INT_SAMPLER_2D_ARRAY;
1388 
1389     case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1390         return glu::TYPE_UINT_SAMPLER_2D_ARRAY;
1391 
1392     default:
1393         return glu::TYPE_LAST;
1394     }
1395 }
1396 
1397 /*--------------------------------------------------------------------*//*!
1398  * \brief Get GLSL sampler type for texture format.
1399  *
1400  * If no mapping is found, glu::TYPE_LAST is returned.
1401  *
1402  * \param format Texture format
1403  * \return GLSL 3D sampler type for format
1404  *//*--------------------------------------------------------------------*/
getSampler3DType(tcu::TextureFormat format)1405 DataType getSampler3DType(tcu::TextureFormat format)
1406 {
1407     using tcu::TextureFormat;
1408 
1409     if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
1410         return TYPE_SAMPLER_3D;
1411 
1412     if (format.order == TextureFormat::S)
1413         return TYPE_LAST;
1414 
1415     switch (tcu::getTextureChannelClass(format.type))
1416     {
1417     case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1418     case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1419     case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1420         return glu::TYPE_SAMPLER_3D;
1421 
1422     case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1423         return glu::TYPE_INT_SAMPLER_3D;
1424 
1425     case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1426         return glu::TYPE_UINT_SAMPLER_3D;
1427 
1428     default:
1429         return glu::TYPE_LAST;
1430     }
1431 }
1432 
1433 /*--------------------------------------------------------------------*//*!
1434  * \brief Get GLSL sampler type for texture format.
1435  *
1436  * If no mapping is found, glu::TYPE_LAST is returned.
1437  *
1438  * \param format Texture format
1439  * \return GLSL cube map array sampler type for format
1440  *//*--------------------------------------------------------------------*/
getSamplerCubeArrayType(tcu::TextureFormat format)1441 DataType getSamplerCubeArrayType(tcu::TextureFormat format)
1442 {
1443     using tcu::TextureFormat;
1444 
1445     if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
1446         return TYPE_SAMPLER_CUBE_ARRAY;
1447 
1448     if (format.order == TextureFormat::S)
1449         return TYPE_LAST;
1450 
1451     switch (tcu::getTextureChannelClass(format.type))
1452     {
1453     case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1454     case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1455     case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1456         return glu::TYPE_SAMPLER_CUBE_ARRAY;
1457 
1458     case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1459         return glu::TYPE_INT_SAMPLER_CUBE_ARRAY;
1460 
1461     case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1462         return glu::TYPE_UINT_SAMPLER_CUBE_ARRAY;
1463 
1464     default:
1465         return glu::TYPE_LAST;
1466     }
1467 }
1468 
1469 enum RenderableType
1470 {
1471     RENDERABLE_COLOR   = (1 << 0),
1472     RENDERABLE_DEPTH   = (1 << 1),
1473     RENDERABLE_STENCIL = (1 << 2)
1474 };
1475 
getRenderableBitsES3(const ContextInfo & contextInfo,uint32_t internalFormat)1476 static uint32_t getRenderableBitsES3(const ContextInfo &contextInfo, uint32_t internalFormat)
1477 {
1478     switch (internalFormat)
1479     {
1480     // Color-renderable formats
1481     case GL_RGBA32I:
1482     case GL_RGBA32UI:
1483     case GL_RGBA16I:
1484     case GL_RGBA16UI:
1485     case GL_RGBA8:
1486     case GL_RGBA8I:
1487     case GL_RGBA8UI:
1488     case GL_SRGB8_ALPHA8:
1489     case GL_RGB10_A2:
1490     case GL_RGB10_A2UI:
1491     case GL_RGBA4:
1492     case GL_RGB5_A1:
1493     case GL_RGB8:
1494     case GL_RGB565:
1495     case GL_RG32I:
1496     case GL_RG32UI:
1497     case GL_RG16I:
1498     case GL_RG16UI:
1499     case GL_RG8:
1500     case GL_RG8I:
1501     case GL_RG8UI:
1502     case GL_R32I:
1503     case GL_R32UI:
1504     case GL_R16I:
1505     case GL_R16UI:
1506     case GL_R8:
1507     case GL_R8I:
1508     case GL_R8UI:
1509         return RENDERABLE_COLOR;
1510 
1511     // GL_EXT_color_buffer_float
1512     case GL_RGBA32F:
1513     case GL_R11F_G11F_B10F:
1514     case GL_RG32F:
1515     case GL_R32F:
1516         if (contextInfo.isExtensionSupported("GL_EXT_color_buffer_float"))
1517             return RENDERABLE_COLOR;
1518         else
1519             return 0;
1520 
1521     // GL_EXT_color_buffer_float / GL_EXT_color_buffer_half_float
1522     case GL_RGBA16F:
1523     case GL_RG16F:
1524     case GL_R16F:
1525         if (contextInfo.isExtensionSupported("GL_EXT_color_buffer_float") ||
1526             contextInfo.isExtensionSupported("GL_EXT_color_buffer_half_float"))
1527             return RENDERABLE_COLOR;
1528         else
1529             return 0;
1530 
1531     // Depth formats
1532     case GL_DEPTH_COMPONENT32F:
1533     case GL_DEPTH_COMPONENT24:
1534     case GL_DEPTH_COMPONENT16:
1535         return RENDERABLE_DEPTH;
1536 
1537     // Depth+stencil formats
1538     case GL_DEPTH32F_STENCIL8:
1539     case GL_DEPTH24_STENCIL8:
1540         return RENDERABLE_DEPTH | RENDERABLE_STENCIL;
1541 
1542     // Stencil formats
1543     case GL_STENCIL_INDEX8:
1544         return RENDERABLE_STENCIL;
1545 
1546     default:
1547         return 0;
1548     }
1549 }
1550 
1551 /*--------------------------------------------------------------------*//*!
1552  * \brief Check if sized internal format is color-renderable.
1553  * \note Works currently only on ES3 context.
1554  *//*--------------------------------------------------------------------*/
isSizedFormatColorRenderable(const RenderContext & renderCtx,const ContextInfo & contextInfo,uint32_t sizedFormat)1555 bool isSizedFormatColorRenderable(const RenderContext &renderCtx, const ContextInfo &contextInfo, uint32_t sizedFormat)
1556 {
1557     uint32_t renderable = 0;
1558 
1559     if (renderCtx.getType().getAPI() == ApiType::es(3, 0))
1560         renderable = getRenderableBitsES3(contextInfo, sizedFormat);
1561     else
1562         throw tcu::InternalError("Context type not supported in query");
1563 
1564     return (renderable & RENDERABLE_COLOR) != 0;
1565 }
1566 
getDefaultGatherOffsets(void)1567 const tcu::IVec2 (&getDefaultGatherOffsets(void))[4]
1568 {
1569     static const tcu::IVec2 s_defaultOffsets[4] = {
1570         tcu::IVec2(0, 1),
1571         tcu::IVec2(1, 1),
1572         tcu::IVec2(1, 0),
1573         tcu::IVec2(0, 0),
1574     };
1575     return s_defaultOffsets;
1576 }
1577 
1578 tcu::PixelBufferAccess getTextureBufferEffectiveRefTexture(TextureBuffer &buffer, int maxTextureBufferSize)
1579 {
1580     DE_ASSERT(maxTextureBufferSize > 0);
1581 
1582     const tcu::PixelBufferAccess &fullAccess = buffer.getFullRefTexture();
1583 
1584     return tcu::PixelBufferAccess(fullAccess.getFormat(),
1585                                   tcu::IVec3(de::min(fullAccess.getWidth(), maxTextureBufferSize), 1, 1),
1586                                   fullAccess.getPitch(), fullAccess.getDataPtr());
1587 }
1588 
getTextureBufferEffectiveRefTexture(const TextureBuffer & buffer,int maxTextureBufferSize)1589 tcu::ConstPixelBufferAccess getTextureBufferEffectiveRefTexture(const TextureBuffer &buffer, int maxTextureBufferSize)
1590 {
1591     return getTextureBufferEffectiveRefTexture(const_cast<TextureBuffer &>(buffer), maxTextureBufferSize);
1592 }
1593 
1594 } // namespace glu
1595