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 Shader utilities.
22 *//*--------------------------------------------------------------------*/
23
24 #include "gluShaderUtil.hpp"
25 #include "glwEnums.hpp"
26 #include "deArrayUtil.hpp"
27
28 namespace glu
29 {
30
31 // ShadingLanguageVersion
32
getGLSLVersionName(GLSLVersion version)33 const char* getGLSLVersionName (GLSLVersion version)
34 {
35 static const char* s_names[] =
36 {
37 "GLSL ES 1.0",
38 "GLSL ES 3.0",
39 "GLSL ES 3.1",
40 "GLSL ES 3.2",
41 "GLSL 1.3",
42 "GLSL 1.4",
43 "GLSL 1.5",
44 "GLSL 3.3",
45 "GLSL 4.0",
46 "GLSL 4.1",
47 "GLSL 4.2",
48 "GLSL 4.3",
49 "GLSL 4.4",
50 "GLSL 4.5",
51 "GLSL 4.6",
52 };
53
54 return de::getSizedArrayElement<GLSL_VERSION_LAST>(s_names, version);
55 }
56
getGLSLVersionDeclaration(GLSLVersion version)57 const char* getGLSLVersionDeclaration (GLSLVersion version)
58 {
59 static const char* s_decl[] =
60 {
61 "#version 100",
62 "#version 300 es",
63 "#version 310 es",
64 "#version 320 es",
65 "#version 130",
66 "#version 140",
67 "#version 150",
68 "#version 330",
69 "#version 400",
70 "#version 410",
71 "#version 420",
72 "#version 430",
73 "#version 440",
74 "#version 450",
75 "#version 460",
76 };
77
78 return de::getSizedArrayElement<GLSL_VERSION_LAST>(s_decl, version);
79 }
80
glslVersionUsesInOutQualifiers(GLSLVersion version)81 bool glslVersionUsesInOutQualifiers (GLSLVersion version)
82 {
83 return de::inRange<int>(version, GLSL_VERSION_300_ES, GLSL_VERSION_320_ES) || de::inRange<int>(version, GLSL_VERSION_330, GLSL_VERSION_460);
84 }
85
glslVersionIsES(GLSLVersion version)86 bool glslVersionIsES (GLSLVersion version)
87 {
88 DE_STATIC_ASSERT(GLSL_VERSION_LAST == 15);
89 DE_ASSERT(version != GLSL_VERSION_LAST);
90
91 if (version == GLSL_VERSION_100_ES ||
92 version == GLSL_VERSION_300_ES ||
93 version == GLSL_VERSION_310_ES ||
94 version == GLSL_VERSION_320_ES)
95 return true;
96 else
97 return false;
98 }
99
100 // \todo [2014-10-06 pyry] Export this.
getMinAPIForGLSLVersion(GLSLVersion version)101 static ApiType getMinAPIForGLSLVersion (GLSLVersion version)
102 {
103 static const ApiType s_minApi[] =
104 {
105 ApiType::es(2,0),
106 ApiType::es(3,0),
107 ApiType::es(3,1),
108 ApiType::es(3,2),
109 ApiType::core(3,0),
110 ApiType::core(3,1),
111 ApiType::core(3,2),
112 ApiType::core(3,3),
113 ApiType::core(4,0),
114 ApiType::core(4,1),
115 ApiType::core(4,2),
116 ApiType::core(4,3),
117 ApiType::core(4,4),
118 ApiType::core(4,5),
119 ApiType::core(4,6),
120 };
121
122 return de::getSizedArrayElement<GLSL_VERSION_LAST>(s_minApi, version);
123 }
124
isGLSLVersionSupported(ContextType type,GLSLVersion version)125 bool isGLSLVersionSupported (ContextType type, GLSLVersion version)
126 {
127 return contextSupports(type, getMinAPIForGLSLVersion(version));
128 }
129
getContextTypeGLSLVersion(ContextType type)130 GLSLVersion getContextTypeGLSLVersion (ContextType type)
131 {
132 // \note From newer to older
133 for (int version = GLSL_VERSION_LAST-1; version >= 0; version--)
134 {
135 if (isGLSLVersionSupported(type, GLSLVersion(version)))
136 return GLSLVersion(version);
137 }
138
139 DE_ASSERT(false);
140 return GLSL_VERSION_LAST;
141 }
142
143 // ShaderType
144
getShaderTypeName(ShaderType shaderType)145 const char* getShaderTypeName (ShaderType shaderType)
146 {
147 static const char* s_names[] =
148 {
149 "vertex",
150 "fragment",
151 "geometry",
152 "tess_control",
153 "tess_eval",
154 "compute",
155 };
156
157 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_names) == SHADERTYPE_LAST);
158 DE_ASSERT(deInBounds32((int)shaderType, 0, SHADERTYPE_LAST));
159 return s_names[(int)shaderType];
160 }
161
162 // Precision
163
getPrecisionName(Precision precision)164 const char* getPrecisionName (Precision precision)
165 {
166 static const char* s_names[] =
167 {
168 "lowp",
169 "mediump",
170 "highp"
171 };
172
173 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_names) == PRECISION_LAST);
174 DE_ASSERT(deInBounds32((int)precision, 0, PRECISION_LAST));
175 return s_names[(int)precision];
176 }
177
178 // DataType
179
getDataTypeName(DataType dataType)180 const char* getDataTypeName (DataType dataType)
181 {
182 static const char* s_names[] =
183 {
184 "invalid",
185 "float",
186 "vec2",
187 "vec3",
188 "vec4",
189 "mat2",
190 "mat2x3",
191 "mat2x4",
192 "mat3x2",
193 "mat3",
194 "mat3x4",
195 "mat4x2",
196 "mat4x3",
197 "mat4",
198 "double",
199 "dvec2",
200 "dvec3",
201 "dvec4",
202 "dmat2",
203 "dmat2x3",
204 "dmat2x4",
205 "dmat3x2",
206 "dmat3",
207 "dmat3x4",
208 "dmat4x2",
209 "dmat4x3",
210 "dmat4",
211 "int",
212 "ivec2",
213 "ivec3",
214 "ivec4",
215 "uint",
216 "uvec2",
217 "uvec3",
218 "uvec4",
219 "bool",
220 "bvec2",
221 "bvec3",
222 "bvec4",
223 "sampler1D",
224 "sampler2D",
225 "samplerCube",
226 "sampler1DArray",
227 "sampler2DArray",
228 "sampler3D",
229 "samplerCubeArray",
230 "sampler1DShadow",
231 "sampler2DShadow",
232 "samplerCubeShadow",
233 "sampler1DArrayShadow",
234 "sampler2DArrayShadow",
235 "samplerCubeArrayShadow",
236 "isampler1D",
237 "isampler2D",
238 "isamplerCube",
239 "isampler1DArray",
240 "isampler2DArray",
241 "isampler3D",
242 "isamplerCubeArray",
243 "usampler1D",
244 "usampler2D",
245 "usamplerCube",
246 "usampler1DArray",
247 "usampler2DArray",
248 "usampler3D",
249 "usamplerCubeArray",
250 "sampler2DMS",
251 "isampler2DMS",
252 "usampler2DMS",
253 "image2D",
254 "imageCube",
255 "image2DArray",
256 "image3D",
257 "imageCubeArray",
258 "iimage2D",
259 "iimageCube",
260 "iimage2DArray",
261 "iimage3D",
262 "iimageCubeArray",
263 "uimage2D",
264 "uimageCube",
265 "uimage2DArray",
266 "uimage3D",
267 "uimageCubeArray",
268 "atomic_uint",
269 "samplerBuffer",
270 "isamplerBuffer",
271 "usamplerBuffer",
272 "sampler2DMSArray",
273 "isampler2DMSArray",
274 "usampler2DMSArray",
275 "imageBuffer",
276 "iimageBuffer",
277 "uimageBuffer",
278 "uint8_t",
279 "u8vec2",
280 "u8vec3",
281 "u8vec4",
282 "int8_t",
283 "i8vec2",
284 "i8vec3",
285 "i8vec4",
286 "uint16_t",
287 "u16vec2",
288 "u16vec3",
289 "u16vec4",
290 "int16_t",
291 "i16vec2",
292 "i16vec3",
293 "i16vec4",
294 "float16_t",
295 "f16vec2",
296 "f16vec3",
297 "f16vec4",
298 "f16mat2",
299 "f16mat2x3",
300 "f16mat2x4",
301 "f16mat3x2",
302 "f16mat3",
303 "f16mat3x4",
304 "f16mat4x2",
305 "f16mat4x3",
306 "f16mat4",
307 };
308
309 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_names) == TYPE_LAST);
310 DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_names)));
311 return s_names[(int)dataType];
312 }
313
getDataTypeScalarSize(DataType dataType)314 int getDataTypeScalarSize (DataType dataType)
315 {
316 static const int s_sizes[] =
317 {
318 -1, // invalid
319 1, // float
320 2, // vec2
321 3, // vec3
322 4, // vec4
323 4, // mat2
324 6, // mat2x3
325 8, // mat2x4
326 6, // mat3x2
327 9, // mat3
328 12, // mat3x4
329 8, // mat4x2
330 12, // mat4x3
331 16, // mat4
332 1, // double
333 2, // dvec2
334 3, // dvec3
335 4, // dvec4
336 4, // dmat2
337 6, // dmat2x3
338 8, // dmat2x4
339 6, // dmat3x2
340 9, // dmat3
341 12, // dmat3x4
342 8, // dmat4x2
343 12, // dmat4x3
344 16, // dmat4
345 1, // int
346 2, // ivec2
347 3, // ivec3
348 4, // ivec4
349 1, // uint
350 2, // uvec2
351 3, // uvec3
352 4, // uvec4
353 1, // bool
354 2, // bvec2
355 3, // bvec3
356 4, // bvec4
357 1, // sampler1D
358 1, // sampler2D
359 1, // samplerCube
360 1, // sampler1DArray
361 1, // sampler2DArray
362 1, // sampler3D
363 1, // samplerCubeArray
364 1, // sampler1DShadow
365 1, // sampler2DShadow
366 1, // samplerCubeShadow
367 1, // sampler1DArrayShadow
368 1, // sampler2DArrayShadow
369 1, // samplerCubeArrayShadow
370 1, // isampler1D
371 1, // isampler2D
372 1, // isamplerCube
373 1, // isampler1DArray
374 1, // isampler2DArray
375 1, // isampler3D
376 1, // isamplerCubeArray
377 1, // usampler1D
378 1, // usampler2D
379 1, // usamplerCube
380 1, // usampler1DArray
381 1, // usampler2DArray
382 1, // usampler3D
383 1, // usamplerCubeArray
384 1, // sampler2DMS
385 1, // isampler2DMS
386 1, // usampler2DMS
387 1, // image2D
388 1, // imageCube
389 1, // image2DArray
390 1, // image3D
391 1, // imageCubeArray
392 1, // iimage2D
393 1, // iimageCube
394 1, // iimage2DArray
395 1, // iimage3D
396 1, // iimageCubeArray
397 1, // uimage2D
398 1, // uimageCube
399 1, // uimage2DArray
400 1, // uimage3D
401 1, // uimageCubeArray
402 1, // atomic_uint
403 1, // samplerBuffer
404 1, // isamplerBuffer
405 1, // usamplerBuffer
406 1, // sampler2DMSArray
407 1, // isampler2DMSArray
408 1, // usampler2DMSArray
409 1, // imageBuffer
410 1, // iimageBuffer
411 1, // uimageBuffer
412 1, // uint8_t
413 2, // u8vec2
414 3, // u8vec3
415 4, // u8vec4
416 1, // int8_t
417 2, // i8vec2
418 3, // i8vec3
419 4, // i8vec4
420 1, // uint16_t
421 2, // u16vec2
422 3, // u16vec3
423 4, // u16vec4
424 1, // int16_t
425 2, // i16vec2
426 3, // i16vec3
427 4, // i16vec4
428 1, // float16_t
429 2, // f16vec2
430 3, // f16vec3
431 4, // f16vec4
432 4, // f16mat2
433 6, // f16mat2x3
434 8, // f16mat2x4
435 6, // f16mat3x2
436 9, // f16mat3
437 12, // f16mat3x4
438 8, // f16mat4x2
439 12, // f16mat4x3
440 16, // f16mat4
441 };
442
443 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_sizes) == TYPE_LAST);
444 DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_sizes)));
445 return s_sizes[(int)dataType];
446 }
447
getDataTypeScalarType(DataType dataType)448 DataType getDataTypeScalarType (DataType dataType)
449 {
450 static const DataType s_scalarTypes[] =
451 {
452 TYPE_INVALID, // invalid
453 TYPE_FLOAT, // float
454 TYPE_FLOAT, // vec2
455 TYPE_FLOAT, // vec3
456 TYPE_FLOAT, // vec4
457 TYPE_FLOAT, // mat2
458 TYPE_FLOAT, // mat2x3
459 TYPE_FLOAT, // mat2x4
460 TYPE_FLOAT, // mat3x2
461 TYPE_FLOAT, // mat3
462 TYPE_FLOAT, // mat3x4
463 TYPE_FLOAT, // mat4x2
464 TYPE_FLOAT, // mat4x3
465 TYPE_FLOAT, // mat4
466 TYPE_DOUBLE, // double
467 TYPE_DOUBLE, // dvec2
468 TYPE_DOUBLE, // dvec3
469 TYPE_DOUBLE, // dvec4
470 TYPE_DOUBLE, // dmat2
471 TYPE_DOUBLE, // dmat2x3
472 TYPE_DOUBLE, // dmat2x4
473 TYPE_DOUBLE, // dmat3x2
474 TYPE_DOUBLE, // dmat3
475 TYPE_DOUBLE, // dmat3x4
476 TYPE_DOUBLE, // dmat4x2
477 TYPE_DOUBLE, // dmat4x3
478 TYPE_DOUBLE, // dmat4
479 TYPE_INT, // int
480 TYPE_INT, // ivec2
481 TYPE_INT, // ivec3
482 TYPE_INT, // ivec4
483 TYPE_UINT, // uint
484 TYPE_UINT, // uvec2
485 TYPE_UINT, // uvec3
486 TYPE_UINT, // uvec4
487 TYPE_BOOL, // bool
488 TYPE_BOOL, // bvec2
489 TYPE_BOOL, // bvec3
490 TYPE_BOOL, // bvec4
491 TYPE_SAMPLER_1D, // sampler1D
492 TYPE_SAMPLER_2D, // sampler2D
493 TYPE_SAMPLER_CUBE, // samplerCube
494 TYPE_SAMPLER_1D_ARRAY, // sampler1DArray
495 TYPE_SAMPLER_2D_ARRAY, // sampler2DArray
496 TYPE_SAMPLER_3D, // sampler3D
497 TYPE_SAMPLER_CUBE_ARRAY, // samplerCubeArray
498 TYPE_SAMPLER_1D_SHADOW, // sampler1DShadow
499 TYPE_SAMPLER_2D_SHADOW, // sampler2DShadow
500 TYPE_SAMPLER_CUBE_SHADOW, // samplerCubeShadow
501 TYPE_SAMPLER_1D_ARRAY_SHADOW, // sampler1DArrayShadow
502 TYPE_SAMPLER_2D_ARRAY_SHADOW, // sampler2DArrayShadow
503 TYPE_SAMPLER_CUBE_ARRAY_SHADOW, // samplerCubeArrayShadow
504 TYPE_INT_SAMPLER_1D, // isampler1D
505 TYPE_INT_SAMPLER_2D, // isampler2D
506 TYPE_INT_SAMPLER_CUBE, // isamplerCube
507 TYPE_INT_SAMPLER_1D_ARRAY, // isampler1DArray
508 TYPE_INT_SAMPLER_2D_ARRAY, // isampler2DArray
509 TYPE_INT_SAMPLER_3D, // isampler3D
510 TYPE_INT_SAMPLER_CUBE_ARRAY, // isamplerCubeArray
511 TYPE_UINT_SAMPLER_1D, // usampler1D
512 TYPE_UINT_SAMPLER_2D, // usampler2D
513 TYPE_UINT_SAMPLER_CUBE, // usamplerCube
514 TYPE_UINT_SAMPLER_1D_ARRAY, // usampler1DArray
515 TYPE_UINT_SAMPLER_2D_ARRAY, // usampler2DArray
516 TYPE_UINT_SAMPLER_3D, // usampler3D
517 TYPE_UINT_SAMPLER_CUBE_ARRAY, // usamplerCubeArray
518 TYPE_SAMPLER_2D_MULTISAMPLE, // sampler2DMS
519 TYPE_INT_SAMPLER_2D_MULTISAMPLE, // isampler2DMS
520 TYPE_UINT_SAMPLER_2D_MULTISAMPLE, // usampler2DMS
521 TYPE_IMAGE_2D, // image2D
522 TYPE_IMAGE_CUBE, // imageCube
523 TYPE_IMAGE_2D_ARRAY, // image2DArray
524 TYPE_IMAGE_3D, // image3D
525 TYPE_IMAGE_CUBE_ARRAY, // imageCubeArray
526 TYPE_INT_IMAGE_2D, // iimage2D
527 TYPE_INT_IMAGE_CUBE, // iimageCube
528 TYPE_INT_IMAGE_2D_ARRAY, // iimage2DArray
529 TYPE_INT_IMAGE_3D, // iimage3D
530 TYPE_INT_IMAGE_CUBE_ARRAY, // iimageCubeArray
531 TYPE_UINT_IMAGE_2D, // uimage2D
532 TYPE_UINT_IMAGE_CUBE, // uimageCube
533 TYPE_UINT_IMAGE_2D_ARRAY, // uimage2DArray
534 TYPE_UINT_IMAGE_3D, // uimage3D
535 TYPE_UINT_IMAGE_CUBE_ARRAY, // uimageCubeArray
536 TYPE_UINT_ATOMIC_COUNTER, // atomic_uint
537 TYPE_SAMPLER_BUFFER, // samplerBuffer
538 TYPE_INT_SAMPLER_BUFFER, // isamplerBuffer
539 TYPE_UINT_SAMPLER_BUFFER, // usamplerBuffer
540 TYPE_SAMPLER_2D_MULTISAMPLE_ARRAY, // sampler2DMSArray
541 TYPE_INT_SAMPLER_2D_MULTISAMPLE_ARRAY, // isampler2DMSArray
542 TYPE_UINT_SAMPLER_2D_MULTISAMPLE_ARRAY, // usampler2DMSArray
543 TYPE_IMAGE_BUFFER, // imageBuffer
544 TYPE_INT_IMAGE_BUFFER, // iimageBuffer
545 TYPE_UINT_IMAGE_BUFFER, // uimageBuffer
546 TYPE_UINT8, // uint8_t
547 TYPE_UINT8, // u8vec2
548 TYPE_UINT8, // u8vec3
549 TYPE_UINT8, // u8vec4
550 TYPE_INT8, // int8_t
551 TYPE_INT8, // i8vec2
552 TYPE_INT8, // i8vec3
553 TYPE_INT8, // i8vec4
554 TYPE_UINT16, // uint16_t
555 TYPE_UINT16, // u16vec2
556 TYPE_UINT16, // u16vec3
557 TYPE_UINT16, // u16vec4
558 TYPE_INT16, // int16_t
559 TYPE_INT16, // i16vec2
560 TYPE_INT16, // i16vec3
561 TYPE_INT16, // i16vec4
562 TYPE_FLOAT16, // float16_t
563 TYPE_FLOAT16, // f16vec2
564 TYPE_FLOAT16, // f16vec3
565 TYPE_FLOAT16, // f16vec4
566 TYPE_FLOAT16, // f16mat2
567 TYPE_FLOAT16, // f16mat2x3
568 TYPE_FLOAT16, // f16mat2x4
569 TYPE_FLOAT16, // f16mat3x2
570 TYPE_FLOAT16, // f16mat3
571 TYPE_FLOAT16, // f16mat3x4
572 TYPE_FLOAT16, // f16mat4x2
573 TYPE_FLOAT16, // f16mat4x3
574 TYPE_FLOAT16, // f16mat4
575 };
576
577 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_scalarTypes) == TYPE_LAST);
578 DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_scalarTypes)));
579 return s_scalarTypes[(int)dataType];
580 }
581
getDataTypeFloat16Scalars(DataType dataType)582 DataType getDataTypeFloat16Scalars (DataType dataType)
583 {
584 static const DataType s_floatTypes[] =
585 {
586 TYPE_INVALID, // invalid
587 TYPE_FLOAT16, // float
588 TYPE_FLOAT16_VEC2, // vec2
589 TYPE_FLOAT16_VEC3, // vec3
590 TYPE_FLOAT16_VEC4, // vec4
591 TYPE_FLOAT16_MAT2, // mat2
592 TYPE_FLOAT16_MAT2X3, // mat2x3
593 TYPE_FLOAT16_MAT2X4, // mat2x4
594 TYPE_FLOAT16_MAT3X2, // mat3x2
595 TYPE_FLOAT16_MAT3, // mat3
596 TYPE_FLOAT16_MAT3X4, // mat3x4
597 TYPE_FLOAT16_MAT4X2, // mat4x2
598 TYPE_FLOAT16_MAT4X3, // mat4x3
599 TYPE_FLOAT16_MAT4, // mat4
600 TYPE_FLOAT16, // double
601 TYPE_FLOAT16_VEC2, // dvec2
602 TYPE_FLOAT16_VEC3, // dvec3
603 TYPE_FLOAT16_VEC4, // dvec4
604 TYPE_FLOAT16_MAT2, // dmat2
605 TYPE_FLOAT16_MAT2X3, // dmat2x3
606 TYPE_FLOAT16_MAT2X4, // dmat2x4
607 TYPE_FLOAT16_MAT3X2, // dmat3x2
608 TYPE_FLOAT16_MAT3, // dmat3
609 TYPE_FLOAT16_MAT3X4, // dmat3x4
610 TYPE_FLOAT16_MAT4X2, // dmat4x2
611 TYPE_FLOAT16_MAT4X3, // dmat4x3
612 TYPE_FLOAT16_MAT4, // dmat4
613 TYPE_FLOAT16, // int
614 TYPE_FLOAT16_VEC2, // ivec2
615 TYPE_FLOAT16_VEC3, // ivec3
616 TYPE_FLOAT16_VEC4, // ivec4
617 TYPE_FLOAT16, // uint
618 TYPE_FLOAT16_VEC2, // uvec2
619 TYPE_FLOAT16_VEC3, // uvec3
620 TYPE_FLOAT16_VEC4, // uvec4
621 TYPE_FLOAT16, // bool
622 TYPE_FLOAT16_VEC2, // bvec2
623 TYPE_FLOAT16_VEC3, // bvec3
624 TYPE_FLOAT16_VEC4, // bvec4
625 TYPE_INVALID, // sampler1D
626 TYPE_INVALID, // sampler2D
627 TYPE_INVALID, // samplerCube
628 TYPE_INVALID, // sampler1DArray
629 TYPE_INVALID, // sampler2DArray
630 TYPE_INVALID, // sampler3D
631 TYPE_INVALID, // samplerCubeArray
632 TYPE_INVALID, // sampler1DShadow
633 TYPE_INVALID, // sampler2DShadow
634 TYPE_INVALID, // samplerCubeShadow
635 TYPE_INVALID, // sampler1DArrayShadow
636 TYPE_INVALID, // sampler2DArrayShadow
637 TYPE_INVALID, // samplerCubeArrayShadow
638 TYPE_INVALID, // isampler1D
639 TYPE_INVALID, // isampler2D
640 TYPE_INVALID, // isamplerCube
641 TYPE_INVALID, // isampler1DArray
642 TYPE_INVALID, // isampler2DArray
643 TYPE_INVALID, // isampler3D
644 TYPE_INVALID, // isamplerCubeArray
645 TYPE_INVALID, // usampler1D
646 TYPE_INVALID, // usampler2D
647 TYPE_INVALID, // usamplerCube
648 TYPE_INVALID, // usampler1DArray
649 TYPE_INVALID, // usampler2DArray
650 TYPE_INVALID, // usampler3D
651 TYPE_INVALID, // usamplerCubeArray
652 TYPE_INVALID, // sampler2DMS
653 TYPE_INVALID, // isampler2DMS
654 TYPE_INVALID, // usampler2DMS
655 TYPE_INVALID, // image2D
656 TYPE_INVALID, // imageCube
657 TYPE_INVALID, // image2DArray
658 TYPE_INVALID, // image3D
659 TYPE_INVALID, // imageCubeArray
660 TYPE_INVALID, // iimage2D
661 TYPE_INVALID, // iimageCube
662 TYPE_INVALID, // iimage2DArray
663 TYPE_INVALID, // iimage3D
664 TYPE_INVALID, // iimageCubeArray
665 TYPE_INVALID, // uimage2D
666 TYPE_INVALID, // uimageCube
667 TYPE_INVALID, // uimage2DArray
668 TYPE_INVALID, // uimage3D
669 TYPE_INVALID, // uimageCubeArray
670 TYPE_INVALID, // atomic_uint
671 TYPE_INVALID, // samplerBuffer
672 TYPE_INVALID, // isamplerBuffer
673 TYPE_INVALID, // usamplerBuffer
674 TYPE_INVALID, // sampler2DMSArray
675 TYPE_INVALID, // isampler2DMSArray
676 TYPE_INVALID, // usampler2DMSArray
677 TYPE_INVALID, // imageBuffer
678 TYPE_INVALID, // iimageBuffer
679 TYPE_INVALID, // uimageBuffer
680 TYPE_FLOAT16, // uint8_t
681 TYPE_FLOAT16_VEC2, // u8vec2
682 TYPE_FLOAT16_VEC3, // u8vec3
683 TYPE_FLOAT16_VEC4, // u8vec4
684 TYPE_FLOAT16, // int8_t
685 TYPE_FLOAT16_VEC2, // i8vec2
686 TYPE_FLOAT16_VEC3, // i8vec3
687 TYPE_FLOAT16_VEC4, // i8vec4
688 TYPE_FLOAT16, // uint16_t
689 TYPE_FLOAT16_VEC2, // u16vec2
690 TYPE_FLOAT16_VEC3, // u16vec3
691 TYPE_FLOAT16_VEC4, // u16vec4
692 TYPE_FLOAT16, // int16_t
693 TYPE_FLOAT16_VEC2, // i16vec2
694 TYPE_FLOAT16_VEC3, // i16vec3
695 TYPE_FLOAT16_VEC4, // i16vec4
696 TYPE_FLOAT16, // float16_t
697 TYPE_FLOAT16_VEC2, // f16vec2
698 TYPE_FLOAT16_VEC3, // f16vec3
699 TYPE_FLOAT16_VEC4, // f16vec4
700 TYPE_FLOAT16_MAT2, // f16mat2
701 TYPE_FLOAT16_MAT2X3, // f16mat2x3
702 TYPE_FLOAT16_MAT2X4, // f16mat2x4
703 TYPE_FLOAT16_MAT3X2, // f16mat3x2
704 TYPE_FLOAT16_MAT3, // f16mat3
705 TYPE_FLOAT16_MAT3X4, // f16mat3x4
706 TYPE_FLOAT16_MAT4X2, // f16mat4x2
707 TYPE_FLOAT16_MAT4X3, // f16mat4x3
708 TYPE_FLOAT16_MAT4, // f16mat4
709 };
710
711 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_floatTypes) == TYPE_LAST);
712 DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_floatTypes)));
713 return s_floatTypes[(int)dataType];
714 }
715
getDataTypeFloatScalars(DataType dataType)716 DataType getDataTypeFloatScalars (DataType dataType)
717 {
718 static const DataType s_floatTypes[] =
719 {
720 TYPE_INVALID, // invalid
721 TYPE_FLOAT, // float
722 TYPE_FLOAT_VEC2, // vec2
723 TYPE_FLOAT_VEC3, // vec3
724 TYPE_FLOAT_VEC4, // vec4
725 TYPE_FLOAT_MAT2, // mat2
726 TYPE_FLOAT_MAT2X3, // mat2x3
727 TYPE_FLOAT_MAT2X4, // mat2x4
728 TYPE_FLOAT_MAT3X2, // mat3x2
729 TYPE_FLOAT_MAT3, // mat3
730 TYPE_FLOAT_MAT3X4, // mat3x4
731 TYPE_FLOAT_MAT4X2, // mat4x2
732 TYPE_FLOAT_MAT4X3, // mat4x3
733 TYPE_FLOAT_MAT4, // mat4
734 TYPE_FLOAT, // double
735 TYPE_FLOAT_VEC2, // dvec2
736 TYPE_FLOAT_VEC3, // dvec3
737 TYPE_FLOAT_VEC4, // dvec4
738 TYPE_FLOAT_MAT2, // dmat2
739 TYPE_FLOAT_MAT2X3, // dmat2x3
740 TYPE_FLOAT_MAT2X4, // dmat2x4
741 TYPE_FLOAT_MAT3X2, // dmat3x2
742 TYPE_FLOAT_MAT3, // dmat3
743 TYPE_FLOAT_MAT3X4, // dmat3x4
744 TYPE_FLOAT_MAT4X2, // dmat4x2
745 TYPE_FLOAT_MAT4X3, // dmat4x3
746 TYPE_FLOAT_MAT4, // dmat4
747 TYPE_FLOAT, // int
748 TYPE_FLOAT_VEC2, // ivec2
749 TYPE_FLOAT_VEC3, // ivec3
750 TYPE_FLOAT_VEC4, // ivec4
751 TYPE_FLOAT, // uint
752 TYPE_FLOAT_VEC2, // uvec2
753 TYPE_FLOAT_VEC3, // uvec3
754 TYPE_FLOAT_VEC4, // uvec4
755 TYPE_FLOAT, // bool
756 TYPE_FLOAT_VEC2, // bvec2
757 TYPE_FLOAT_VEC3, // bvec3
758 TYPE_FLOAT_VEC4, // bvec4
759 TYPE_INVALID, // sampler1D
760 TYPE_INVALID, // sampler2D
761 TYPE_INVALID, // samplerCube
762 TYPE_INVALID, // sampler1DArray
763 TYPE_INVALID, // sampler2DArray
764 TYPE_INVALID, // sampler3D
765 TYPE_INVALID, // samplerCubeArray
766 TYPE_INVALID, // sampler1DShadow
767 TYPE_INVALID, // sampler2DShadow
768 TYPE_INVALID, // samplerCubeShadow
769 TYPE_INVALID, // sampler1DArrayShadow
770 TYPE_INVALID, // sampler2DArrayShadow
771 TYPE_INVALID, // samplerCubeArrayShadow
772 TYPE_INVALID, // isampler1D
773 TYPE_INVALID, // isampler2D
774 TYPE_INVALID, // isamplerCube
775 TYPE_INVALID, // isampler1DArray
776 TYPE_INVALID, // isampler2DArray
777 TYPE_INVALID, // isampler3D
778 TYPE_INVALID, // isamplerCubeArray
779 TYPE_INVALID, // usampler1D
780 TYPE_INVALID, // usampler2D
781 TYPE_INVALID, // usamplerCube
782 TYPE_INVALID, // usampler1DArray
783 TYPE_INVALID, // usampler2DArray
784 TYPE_INVALID, // usampler3D
785 TYPE_INVALID, // usamplerCubeArray
786 TYPE_INVALID, // sampler2DMS
787 TYPE_INVALID, // isampler2DMS
788 TYPE_INVALID, // usampler2DMS
789 TYPE_INVALID, // image2D
790 TYPE_INVALID, // imageCube
791 TYPE_INVALID, // image2DArray
792 TYPE_INVALID, // image3D
793 TYPE_INVALID, // imageCubeArray
794 TYPE_INVALID, // iimage2D
795 TYPE_INVALID, // iimageCube
796 TYPE_INVALID, // iimage2DArray
797 TYPE_INVALID, // iimage3D
798 TYPE_INVALID, // iimageCubeArray
799 TYPE_INVALID, // uimage2D
800 TYPE_INVALID, // uimageCube
801 TYPE_INVALID, // uimage2DArray
802 TYPE_INVALID, // uimage3D
803 TYPE_INVALID, // uimageCubeArray
804 TYPE_INVALID, // atomic_uint
805 TYPE_INVALID, // samplerBuffer
806 TYPE_INVALID, // isamplerBuffer
807 TYPE_INVALID, // usamplerBuffer
808 TYPE_INVALID, // sampler2DMSArray
809 TYPE_INVALID, // isampler2DMSArray
810 TYPE_INVALID, // usampler2DMSArray
811 TYPE_INVALID, // imageBuffer
812 TYPE_INVALID, // iimageBuffer
813 TYPE_INVALID, // uimageBuffer
814 TYPE_FLOAT, // uint8_t
815 TYPE_FLOAT_VEC2, // u8vec2
816 TYPE_FLOAT_VEC3, // u8vec3
817 TYPE_FLOAT_VEC4, // u8vec4
818 TYPE_FLOAT, // int8_t
819 TYPE_FLOAT_VEC2, // i8vec2
820 TYPE_FLOAT_VEC3, // i8vec3
821 TYPE_FLOAT_VEC4, // i8vec4
822 TYPE_FLOAT, // uint16_t
823 TYPE_FLOAT_VEC2, // u16vec2
824 TYPE_FLOAT_VEC3, // u16vec3
825 TYPE_FLOAT_VEC4, // u16vec4
826 TYPE_FLOAT, // int16_t
827 TYPE_FLOAT_VEC2, // i16vec2
828 TYPE_FLOAT_VEC3, // i16vec3
829 TYPE_FLOAT_VEC4, // i16vec4
830 TYPE_FLOAT, // float16_t
831 TYPE_FLOAT_VEC2, // f16vec2
832 TYPE_FLOAT_VEC3, // f16vec3
833 TYPE_FLOAT_VEC4, // f16vec4
834 TYPE_FLOAT_MAT2, // f16mat2
835 TYPE_FLOAT_MAT2X3, // f16mat2x3
836 TYPE_FLOAT_MAT2X4, // f16mat2x4
837 TYPE_FLOAT_MAT3X2, // f16mat3x2
838 TYPE_FLOAT_MAT3, // f16mat3
839 TYPE_FLOAT_MAT3X4, // f16mat3x4
840 TYPE_FLOAT_MAT4X2, // f16mat4x2
841 TYPE_FLOAT_MAT4X3, // f16mat4x3
842 TYPE_FLOAT_MAT4, // f16mat4
843 };
844
845 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_floatTypes) == TYPE_LAST);
846 DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_floatTypes)));
847 return s_floatTypes[(int)dataType];
848 }
849
getDataTypeDoubleScalars(DataType dataType)850 DataType getDataTypeDoubleScalars (DataType dataType)
851 {
852 static const DataType s_doubleTypes[] =
853 {
854 TYPE_INVALID, // invalid
855 TYPE_DOUBLE, // float
856 TYPE_DOUBLE_VEC2, // vec2
857 TYPE_DOUBLE_VEC3, // vec3
858 TYPE_DOUBLE_VEC4, // vec4
859 TYPE_DOUBLE_MAT2, // mat2
860 TYPE_DOUBLE_MAT2X3, // mat2x3
861 TYPE_DOUBLE_MAT2X4, // mat2x4
862 TYPE_DOUBLE_MAT3X2, // mat3x2
863 TYPE_DOUBLE_MAT3, // mat3
864 TYPE_DOUBLE_MAT3X4, // mat3x4
865 TYPE_DOUBLE_MAT4X2, // mat4x2
866 TYPE_DOUBLE_MAT4X3, // mat4x3
867 TYPE_DOUBLE_MAT4, // mat4
868 TYPE_DOUBLE, // double
869 TYPE_DOUBLE_VEC2, // dvec2
870 TYPE_DOUBLE_VEC3, // dvec3
871 TYPE_DOUBLE_VEC4, // dvec4
872 TYPE_DOUBLE_MAT2, // dmat2
873 TYPE_DOUBLE_MAT2X3, // dmat2x3
874 TYPE_DOUBLE_MAT2X4, // dmat2x4
875 TYPE_DOUBLE_MAT3X2, // dmat3x2
876 TYPE_DOUBLE_MAT3, // dmat3
877 TYPE_DOUBLE_MAT3X4, // dmat3x4
878 TYPE_DOUBLE_MAT4X2, // dmat4x2
879 TYPE_DOUBLE_MAT4X3, // dmat4x3
880 TYPE_DOUBLE_MAT4, // dmat4
881 TYPE_DOUBLE, // int
882 TYPE_DOUBLE_VEC2, // ivec2
883 TYPE_DOUBLE_VEC3, // ivec3
884 TYPE_DOUBLE_VEC4, // ivec4
885 TYPE_DOUBLE, // uint
886 TYPE_DOUBLE_VEC2, // uvec2
887 TYPE_DOUBLE_VEC3, // uvec3
888 TYPE_DOUBLE_VEC4, // uvec4
889 TYPE_DOUBLE, // bool
890 TYPE_DOUBLE_VEC2, // bvec2
891 TYPE_DOUBLE_VEC3, // bvec3
892 TYPE_DOUBLE_VEC4, // bvec4
893 TYPE_INVALID, // sampler1D
894 TYPE_INVALID, // sampler2D
895 TYPE_INVALID, // samplerCube
896 TYPE_INVALID, // sampler1DArray
897 TYPE_INVALID, // sampler2DArray
898 TYPE_INVALID, // sampler3D
899 TYPE_INVALID, // samplerCubeArray
900 TYPE_INVALID, // sampler1DShadow
901 TYPE_INVALID, // sampler2DShadow
902 TYPE_INVALID, // samplerCubeShadow
903 TYPE_INVALID, // sampler1DArrayShadow
904 TYPE_INVALID, // sampler2DArrayShadow
905 TYPE_INVALID, // samplerCubeArrayShadow
906 TYPE_INVALID, // isampler1D
907 TYPE_INVALID, // isampler2D
908 TYPE_INVALID, // isamplerCube
909 TYPE_INVALID, // isampler1DArray
910 TYPE_INVALID, // isampler2DArray
911 TYPE_INVALID, // isampler3D
912 TYPE_INVALID, // isamplerCubeArray
913 TYPE_INVALID, // usampler1D
914 TYPE_INVALID, // usampler2D
915 TYPE_INVALID, // usamplerCube
916 TYPE_INVALID, // usampler1DArray
917 TYPE_INVALID, // usampler2DArray
918 TYPE_INVALID, // usampler3D
919 TYPE_INVALID, // usamplerCubeArray
920 TYPE_INVALID, // sampler2DMS
921 TYPE_INVALID, // isampler2DMS
922 TYPE_INVALID, // usampler2DMS
923 TYPE_INVALID, // image2D
924 TYPE_INVALID, // imageCube
925 TYPE_INVALID, // image2DArray
926 TYPE_INVALID, // image3D
927 TYPE_INVALID, // imageCubeArray
928 TYPE_INVALID, // iimage2D
929 TYPE_INVALID, // iimageCube
930 TYPE_INVALID, // iimage2DArray
931 TYPE_INVALID, // iimage3D
932 TYPE_INVALID, // iimageCubeArray
933 TYPE_INVALID, // uimage2D
934 TYPE_INVALID, // uimageCube
935 TYPE_INVALID, // uimage2DArray
936 TYPE_INVALID, // uimage3D
937 TYPE_INVALID, // uimageCubeArray
938 TYPE_INVALID, // atomic_uint
939 TYPE_INVALID, // samplerBuffer
940 TYPE_INVALID, // isamplerBuffer
941 TYPE_INVALID, // usamplerBuffer
942 TYPE_INVALID, // sampler2DMSArray
943 TYPE_INVALID, // isampler2DMSArray
944 TYPE_INVALID, // usampler2DMSArray
945 TYPE_INVALID, // imageBuffer
946 TYPE_INVALID, // iimageBuffer
947 TYPE_INVALID, // uimageBuffer
948 TYPE_DOUBLE, // uint18_t
949 TYPE_DOUBLE_VEC2, // u8vec2
950 TYPE_DOUBLE_VEC3, // u8vec3
951 TYPE_DOUBLE_VEC4, // u8vec4
952 TYPE_DOUBLE, // int8_t
953 TYPE_DOUBLE_VEC2, // i8vec2
954 TYPE_DOUBLE_VEC3, // i8vec3
955 TYPE_DOUBLE_VEC4, // i8vec4
956 TYPE_DOUBLE, // uint16_t
957 TYPE_DOUBLE_VEC2, // u16vec2
958 TYPE_DOUBLE_VEC3, // u16vec3
959 TYPE_DOUBLE_VEC4, // u16vec4
960 TYPE_DOUBLE, // int16_t
961 TYPE_DOUBLE_VEC2, // i16vec2
962 TYPE_DOUBLE_VEC3, // i16vec3
963 TYPE_DOUBLE_VEC4, // i16vec4
964 TYPE_DOUBLE, // float16_t
965 TYPE_DOUBLE_VEC2, // f16vec2
966 TYPE_DOUBLE_VEC3, // f16vec3
967 TYPE_DOUBLE_VEC4, // f16vec4
968 TYPE_DOUBLE_MAT2, // f16mat2
969 TYPE_DOUBLE_MAT2X3, // f16mat2x3
970 TYPE_DOUBLE_MAT2X4, // f16mat2x4
971 TYPE_DOUBLE_MAT3X2, // f16mat3x2
972 TYPE_DOUBLE_MAT3, // f16mat3
973 TYPE_DOUBLE_MAT3X4, // f16mat3x4
974 TYPE_DOUBLE_MAT4X2, // f16mat4x2
975 TYPE_DOUBLE_MAT4X3, // f16mat4x3
976 TYPE_DOUBLE_MAT4, // f16mat4
977 };
978
979 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_doubleTypes) == TYPE_LAST);
980 DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_doubleTypes)));
981 return s_doubleTypes[(int)dataType];
982 }
983
getDataTypeVector(DataType scalarType,int size)984 DataType getDataTypeVector (DataType scalarType, int size)
985 {
986 DE_ASSERT(deInRange32(size, 1, 4));
987 switch (scalarType)
988 {
989 case TYPE_FLOAT:
990 case TYPE_DOUBLE:
991 case TYPE_INT:
992 case TYPE_UINT:
993 case TYPE_BOOL:
994 case TYPE_UINT8:
995 case TYPE_INT8:
996 case TYPE_UINT16:
997 case TYPE_INT16:
998 case TYPE_FLOAT16:
999 return (DataType)((int)scalarType + size - 1);
1000 default:
1001 return TYPE_INVALID;
1002 }
1003 }
1004
getDataTypeFloatVec(int vecSize)1005 DataType getDataTypeFloatVec (int vecSize)
1006 {
1007 return getDataTypeVector(TYPE_FLOAT, vecSize);
1008 }
1009
getDataTypeIntVec(int vecSize)1010 DataType getDataTypeIntVec (int vecSize)
1011 {
1012 return getDataTypeVector(TYPE_INT, vecSize);
1013 }
1014
getDataTypeUintVec(int vecSize)1015 DataType getDataTypeUintVec (int vecSize)
1016 {
1017 return getDataTypeVector(TYPE_UINT, vecSize);
1018 }
1019
getDataTypeBoolVec(int vecSize)1020 DataType getDataTypeBoolVec (int vecSize)
1021 {
1022 return getDataTypeVector(TYPE_BOOL, vecSize);
1023 }
1024
getDataTypeMatrix(int numCols,int numRows)1025 DataType getDataTypeMatrix (int numCols, int numRows)
1026 {
1027 DE_ASSERT(de::inRange(numCols, 2, 4) && de::inRange(numRows, 2, 4));
1028 return (DataType)((int)TYPE_FLOAT_MAT2 + (numCols-2)*3 + (numRows-2));
1029 }
1030
getDataTypeMatrixNumRows(DataType dataType)1031 int getDataTypeMatrixNumRows (DataType dataType)
1032 {
1033 switch (dataType)
1034 {
1035 case TYPE_FLOAT_MAT2: return 2;
1036 case TYPE_FLOAT_MAT2X3: return 3;
1037 case TYPE_FLOAT_MAT2X4: return 4;
1038 case TYPE_FLOAT_MAT3X2: return 2;
1039 case TYPE_FLOAT_MAT3: return 3;
1040 case TYPE_FLOAT_MAT3X4: return 4;
1041 case TYPE_FLOAT_MAT4X2: return 2;
1042 case TYPE_FLOAT_MAT4X3: return 3;
1043 case TYPE_FLOAT_MAT4: return 4;
1044 case TYPE_DOUBLE_MAT2: return 2;
1045 case TYPE_DOUBLE_MAT2X3: return 3;
1046 case TYPE_DOUBLE_MAT2X4: return 4;
1047 case TYPE_DOUBLE_MAT3X2: return 2;
1048 case TYPE_DOUBLE_MAT3: return 3;
1049 case TYPE_DOUBLE_MAT3X4: return 4;
1050 case TYPE_DOUBLE_MAT4X2: return 2;
1051 case TYPE_DOUBLE_MAT4X3: return 3;
1052 case TYPE_DOUBLE_MAT4: return 4;
1053 case TYPE_FLOAT16_MAT2: return 2;
1054 case TYPE_FLOAT16_MAT2X3: return 3;
1055 case TYPE_FLOAT16_MAT2X4: return 4;
1056 case TYPE_FLOAT16_MAT3X2: return 2;
1057 case TYPE_FLOAT16_MAT3: return 3;
1058 case TYPE_FLOAT16_MAT3X4: return 4;
1059 case TYPE_FLOAT16_MAT4X2: return 2;
1060 case TYPE_FLOAT16_MAT4X3: return 3;
1061 case TYPE_FLOAT16_MAT4: return 4;
1062 default:
1063 DE_ASSERT(false);
1064 return 0;
1065 }
1066 }
1067
getDataTypeMatrixNumColumns(DataType dataType)1068 int getDataTypeMatrixNumColumns (DataType dataType)
1069 {
1070 switch (dataType)
1071 {
1072 case TYPE_FLOAT_MAT2: return 2;
1073 case TYPE_FLOAT_MAT2X3: return 2;
1074 case TYPE_FLOAT_MAT2X4: return 2;
1075 case TYPE_FLOAT_MAT3X2: return 3;
1076 case TYPE_FLOAT_MAT3: return 3;
1077 case TYPE_FLOAT_MAT3X4: return 3;
1078 case TYPE_FLOAT_MAT4X2: return 4;
1079 case TYPE_FLOAT_MAT4X3: return 4;
1080 case TYPE_FLOAT_MAT4: return 4;
1081 case TYPE_DOUBLE_MAT2: return 2;
1082 case TYPE_DOUBLE_MAT2X3: return 2;
1083 case TYPE_DOUBLE_MAT2X4: return 2;
1084 case TYPE_DOUBLE_MAT3X2: return 3;
1085 case TYPE_DOUBLE_MAT3: return 3;
1086 case TYPE_DOUBLE_MAT3X4: return 3;
1087 case TYPE_DOUBLE_MAT4X2: return 4;
1088 case TYPE_DOUBLE_MAT4X3: return 4;
1089 case TYPE_DOUBLE_MAT4: return 4;
1090 case TYPE_FLOAT16_MAT2: return 2;
1091 case TYPE_FLOAT16_MAT2X3: return 2;
1092 case TYPE_FLOAT16_MAT2X4: return 2;
1093 case TYPE_FLOAT16_MAT3X2: return 3;
1094 case TYPE_FLOAT16_MAT3: return 3;
1095 case TYPE_FLOAT16_MAT3X4: return 3;
1096 case TYPE_FLOAT16_MAT4X2: return 4;
1097 case TYPE_FLOAT16_MAT4X3: return 4;
1098 case TYPE_FLOAT16_MAT4: return 4;
1099 default:
1100 DE_ASSERT(false);
1101 return 0;
1102 }
1103 }
1104
getDataTypeNumLocations(DataType dataType)1105 int getDataTypeNumLocations (DataType dataType)
1106 {
1107 if (isDataTypeScalarOrVector(dataType))
1108 return 1;
1109 else if (isDataTypeMatrix(dataType))
1110 return getDataTypeMatrixNumColumns(dataType);
1111
1112 DE_FATAL("Illegal datatype.");
1113 return 0;
1114 }
1115
getDataTypeNumComponents(DataType dataType)1116 int getDataTypeNumComponents (DataType dataType)
1117 {
1118 if (isDataTypeScalarOrVector(dataType))
1119 return getDataTypeScalarSize(dataType);
1120 else if (isDataTypeMatrix(dataType))
1121 return getDataTypeMatrixNumRows(dataType);
1122
1123 DE_FATAL("Illegal datatype.");
1124 return 0;
1125 }
1126
getDataTypeFromGLType(deUint32 glType)1127 DataType getDataTypeFromGLType (deUint32 glType)
1128 {
1129 switch (glType)
1130 {
1131 case GL_FLOAT: return TYPE_FLOAT;
1132 case GL_FLOAT_VEC2: return TYPE_FLOAT_VEC2;
1133 case GL_FLOAT_VEC3: return TYPE_FLOAT_VEC3;
1134 case GL_FLOAT_VEC4: return TYPE_FLOAT_VEC4;
1135
1136 case GL_FLOAT_MAT2: return TYPE_FLOAT_MAT2;
1137 case GL_FLOAT_MAT2x3: return TYPE_FLOAT_MAT2X3;
1138 case GL_FLOAT_MAT2x4: return TYPE_FLOAT_MAT2X4;
1139
1140 case GL_FLOAT_MAT3x2: return TYPE_FLOAT_MAT3X2;
1141 case GL_FLOAT_MAT3: return TYPE_FLOAT_MAT3;
1142 case GL_FLOAT_MAT3x4: return TYPE_FLOAT_MAT3X4;
1143
1144 case GL_FLOAT_MAT4x2: return TYPE_FLOAT_MAT4X2;
1145 case GL_FLOAT_MAT4x3: return TYPE_FLOAT_MAT4X3;
1146 case GL_FLOAT_MAT4: return TYPE_FLOAT_MAT4;
1147
1148 case GL_DOUBLE: return TYPE_DOUBLE;
1149 case GL_DOUBLE_VEC2: return TYPE_DOUBLE_VEC2;
1150 case GL_DOUBLE_VEC3: return TYPE_DOUBLE_VEC3;
1151 case GL_DOUBLE_VEC4: return TYPE_DOUBLE_VEC4;
1152
1153 case GL_DOUBLE_MAT2: return TYPE_DOUBLE_MAT2;
1154 case GL_DOUBLE_MAT2x3: return TYPE_DOUBLE_MAT2X3;
1155 case GL_DOUBLE_MAT2x4: return TYPE_DOUBLE_MAT2X4;
1156
1157 case GL_DOUBLE_MAT3x2: return TYPE_DOUBLE_MAT3X2;
1158 case GL_DOUBLE_MAT3: return TYPE_DOUBLE_MAT3;
1159 case GL_DOUBLE_MAT3x4: return TYPE_DOUBLE_MAT3X4;
1160
1161 case GL_DOUBLE_MAT4x2: return TYPE_DOUBLE_MAT4X2;
1162 case GL_DOUBLE_MAT4x3: return TYPE_DOUBLE_MAT4X3;
1163 case GL_DOUBLE_MAT4: return TYPE_DOUBLE_MAT4;
1164
1165 case GL_INT: return TYPE_INT;
1166 case GL_INT_VEC2: return TYPE_INT_VEC2;
1167 case GL_INT_VEC3: return TYPE_INT_VEC3;
1168 case GL_INT_VEC4: return TYPE_INT_VEC4;
1169
1170 case GL_UNSIGNED_INT: return TYPE_UINT;
1171 case GL_UNSIGNED_INT_VEC2: return TYPE_UINT_VEC2;
1172 case GL_UNSIGNED_INT_VEC3: return TYPE_UINT_VEC3;
1173 case GL_UNSIGNED_INT_VEC4: return TYPE_UINT_VEC4;
1174
1175 case GL_BOOL: return TYPE_BOOL;
1176 case GL_BOOL_VEC2: return TYPE_BOOL_VEC2;
1177 case GL_BOOL_VEC3: return TYPE_BOOL_VEC3;
1178 case GL_BOOL_VEC4: return TYPE_BOOL_VEC4;
1179
1180 case GL_SAMPLER_1D: return TYPE_SAMPLER_1D;
1181 case GL_SAMPLER_2D: return TYPE_SAMPLER_2D;
1182 case GL_SAMPLER_CUBE: return TYPE_SAMPLER_CUBE;
1183 case GL_SAMPLER_1D_ARRAY: return TYPE_SAMPLER_1D_ARRAY;
1184 case GL_SAMPLER_2D_ARRAY: return TYPE_SAMPLER_2D_ARRAY;
1185 case GL_SAMPLER_3D: return TYPE_SAMPLER_3D;
1186 case GL_SAMPLER_CUBE_MAP_ARRAY: return TYPE_SAMPLER_CUBE_ARRAY;
1187
1188 case GL_SAMPLER_1D_SHADOW: return TYPE_SAMPLER_1D_SHADOW;
1189 case GL_SAMPLER_2D_SHADOW: return TYPE_SAMPLER_2D_SHADOW;
1190 case GL_SAMPLER_CUBE_SHADOW: return TYPE_SAMPLER_CUBE_SHADOW;
1191 case GL_SAMPLER_1D_ARRAY_SHADOW: return TYPE_SAMPLER_1D_ARRAY_SHADOW;
1192 case GL_SAMPLER_2D_ARRAY_SHADOW: return TYPE_SAMPLER_2D_ARRAY_SHADOW;
1193 case GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW: return TYPE_SAMPLER_CUBE_ARRAY_SHADOW;
1194
1195 case GL_INT_SAMPLER_1D: return TYPE_INT_SAMPLER_1D;
1196 case GL_INT_SAMPLER_2D: return TYPE_INT_SAMPLER_2D;
1197 case GL_INT_SAMPLER_CUBE: return TYPE_INT_SAMPLER_CUBE;
1198 case GL_INT_SAMPLER_1D_ARRAY: return TYPE_INT_SAMPLER_1D_ARRAY;
1199 case GL_INT_SAMPLER_2D_ARRAY: return TYPE_INT_SAMPLER_2D_ARRAY;
1200 case GL_INT_SAMPLER_3D: return TYPE_INT_SAMPLER_3D;
1201 case GL_INT_SAMPLER_CUBE_MAP_ARRAY: return TYPE_INT_SAMPLER_CUBE_ARRAY;
1202
1203 case GL_UNSIGNED_INT_SAMPLER_1D: return TYPE_UINT_SAMPLER_1D;
1204 case GL_UNSIGNED_INT_SAMPLER_2D: return TYPE_UINT_SAMPLER_2D;
1205 case GL_UNSIGNED_INT_SAMPLER_CUBE: return TYPE_UINT_SAMPLER_CUBE;
1206 case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: return TYPE_UINT_SAMPLER_1D_ARRAY;
1207 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: return TYPE_UINT_SAMPLER_2D_ARRAY;
1208 case GL_UNSIGNED_INT_SAMPLER_3D: return TYPE_UINT_SAMPLER_3D;
1209 case GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY: return TYPE_UINT_SAMPLER_CUBE_ARRAY;
1210
1211 case GL_SAMPLER_2D_MULTISAMPLE: return TYPE_SAMPLER_2D_MULTISAMPLE;
1212 case GL_INT_SAMPLER_2D_MULTISAMPLE: return TYPE_INT_SAMPLER_2D_MULTISAMPLE;
1213 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: return TYPE_UINT_SAMPLER_2D_MULTISAMPLE;
1214
1215 case GL_IMAGE_2D: return TYPE_IMAGE_2D;
1216 case GL_IMAGE_CUBE: return TYPE_IMAGE_CUBE;
1217 case GL_IMAGE_2D_ARRAY: return TYPE_IMAGE_2D_ARRAY;
1218 case GL_IMAGE_3D: return TYPE_IMAGE_3D;
1219 case GL_INT_IMAGE_2D: return TYPE_INT_IMAGE_2D;
1220 case GL_INT_IMAGE_CUBE: return TYPE_INT_IMAGE_CUBE;
1221 case GL_INT_IMAGE_2D_ARRAY: return TYPE_INT_IMAGE_2D_ARRAY;
1222 case GL_INT_IMAGE_3D: return TYPE_INT_IMAGE_3D;
1223 case GL_UNSIGNED_INT_IMAGE_2D: return TYPE_UINT_IMAGE_2D;
1224 case GL_UNSIGNED_INT_IMAGE_CUBE: return TYPE_UINT_IMAGE_CUBE;
1225 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY: return TYPE_UINT_IMAGE_2D_ARRAY;
1226 case GL_UNSIGNED_INT_IMAGE_3D: return TYPE_UINT_IMAGE_3D;
1227
1228 case GL_UNSIGNED_INT_ATOMIC_COUNTER: return TYPE_UINT_ATOMIC_COUNTER;
1229
1230 case GL_SAMPLER_BUFFER: return TYPE_SAMPLER_BUFFER;
1231 case GL_INT_SAMPLER_BUFFER: return TYPE_INT_SAMPLER_BUFFER;
1232 case GL_UNSIGNED_INT_SAMPLER_BUFFER: return TYPE_UINT_SAMPLER_BUFFER;
1233
1234 case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: return TYPE_SAMPLER_2D_MULTISAMPLE_ARRAY;
1235 case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: return TYPE_INT_SAMPLER_2D_MULTISAMPLE_ARRAY;
1236 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: return TYPE_UINT_SAMPLER_2D_MULTISAMPLE_ARRAY;
1237
1238 case GL_IMAGE_BUFFER: return TYPE_IMAGE_BUFFER;
1239 case GL_INT_IMAGE_BUFFER: return TYPE_INT_IMAGE_BUFFER;
1240 case GL_UNSIGNED_INT_IMAGE_BUFFER: return TYPE_UINT_IMAGE_BUFFER;
1241
1242 default:
1243 return TYPE_LAST;
1244 }
1245 }
1246
1247 } // glu
1248