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 };
279
280 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_names) == TYPE_LAST);
281 DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_names)));
282 return s_names[(int)dataType];
283 }
284
getDataTypeScalarSize(DataType dataType)285 int getDataTypeScalarSize (DataType dataType)
286 {
287 static const int s_sizes[] =
288 {
289 -1, // invalid
290 1, // float
291 2, // vec2
292 3, // vec3
293 4, // vec4
294 4, // mat2
295 6, // mat2x3
296 8, // mat2x4
297 6, // mat3x2
298 9, // mat3
299 12, // mat3x4
300 8, // mat4x2
301 12, // mat4x3
302 16, // mat4
303 1, // double
304 2, // dvec2
305 3, // dvec3
306 4, // dvec4
307 4, // dmat2
308 6, // dmat2x3
309 8, // dmat2x4
310 6, // dmat3x2
311 9, // dmat3
312 12, // dmat3x4
313 8, // dmat4x2
314 12, // dmat4x3
315 16, // dmat4
316 1, // int
317 2, // ivec2
318 3, // ivec3
319 4, // ivec4
320 1, // uint
321 2, // uvec2
322 3, // uvec3
323 4, // uvec4
324 1, // bool
325 2, // bvec2
326 3, // bvec3
327 4, // bvec4
328 1, // sampler1D
329 1, // sampler2D
330 1, // samplerCube
331 1, // sampler1DArray
332 1, // sampler2DArray
333 1, // sampler3D
334 1, // samplerCubeArray
335 1, // sampler1DShadow
336 1, // sampler2DShadow
337 1, // samplerCubeShadow
338 1, // sampler1DArrayShadow
339 1, // sampler2DArrayShadow
340 1, // samplerCubeArrayShadow
341 1, // isampler1D
342 1, // isampler2D
343 1, // isamplerCube
344 1, // isampler1DArray
345 1, // isampler2DArray
346 1, // isampler3D
347 1, // isamplerCubeArray
348 1, // usampler1D
349 1, // usampler2D
350 1, // usamplerCube
351 1, // usampler1DArray
352 1, // usampler2DArray
353 1, // usampler3D
354 1, // usamplerCubeArray
355 1, // sampler2DMS
356 1, // isampler2DMS
357 1, // usampler2DMS
358 1, // image2D
359 1, // imageCube
360 1, // image2DArray
361 1, // image3D
362 1, // imageCubeArray
363 1, // iimage2D
364 1, // iimageCube
365 1, // iimage2DArray
366 1, // iimage3D
367 1, // iimageCubeArray
368 1, // uimage2D
369 1, // uimageCube
370 1, // uimage2DArray
371 1, // uimage3D
372 1, // uimageCubeArray
373 1, // atomic_uint
374 1, // samplerBuffer
375 1, // isamplerBuffer
376 1, // usamplerBuffer
377 1, // sampler2DMSArray
378 1, // isampler2DMSArray
379 1, // usampler2DMSArray
380 1, // imageBuffer
381 1, // iimageBuffer
382 1, // uimageBuffer
383 };
384
385 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_sizes) == TYPE_LAST);
386 DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_sizes)));
387 return s_sizes[(int)dataType];
388 }
389
getDataTypeScalarType(DataType dataType)390 DataType getDataTypeScalarType (DataType dataType)
391 {
392 static const DataType s_scalarTypes[] =
393 {
394 TYPE_INVALID, // invalid
395 TYPE_FLOAT, // float
396 TYPE_FLOAT, // vec2
397 TYPE_FLOAT, // vec3
398 TYPE_FLOAT, // vec4
399 TYPE_FLOAT, // mat2
400 TYPE_FLOAT, // mat2x3
401 TYPE_FLOAT, // mat2x4
402 TYPE_FLOAT, // mat3x2
403 TYPE_FLOAT, // mat3
404 TYPE_FLOAT, // mat3x4
405 TYPE_FLOAT, // mat4x2
406 TYPE_FLOAT, // mat4x3
407 TYPE_FLOAT, // mat4
408 TYPE_DOUBLE, // double
409 TYPE_DOUBLE, // dvec2
410 TYPE_DOUBLE, // dvec3
411 TYPE_DOUBLE, // dvec4
412 TYPE_DOUBLE, // dmat2
413 TYPE_DOUBLE, // dmat2x3
414 TYPE_DOUBLE, // dmat2x4
415 TYPE_DOUBLE, // dmat3x2
416 TYPE_DOUBLE, // dmat3
417 TYPE_DOUBLE, // dmat3x4
418 TYPE_DOUBLE, // dmat4x2
419 TYPE_DOUBLE, // dmat4x3
420 TYPE_DOUBLE, // dmat4
421 TYPE_INT, // int
422 TYPE_INT, // ivec2
423 TYPE_INT, // ivec3
424 TYPE_INT, // ivec4
425 TYPE_UINT, // uint
426 TYPE_UINT, // uvec2
427 TYPE_UINT, // uvec3
428 TYPE_UINT, // uvec4
429 TYPE_BOOL, // bool
430 TYPE_BOOL, // bvec2
431 TYPE_BOOL, // bvec3
432 TYPE_BOOL, // bvec4
433 TYPE_SAMPLER_1D, // sampler1D
434 TYPE_SAMPLER_2D, // sampler2D
435 TYPE_SAMPLER_CUBE, // samplerCube
436 TYPE_SAMPLER_1D_ARRAY, // sampler1DArray
437 TYPE_SAMPLER_2D_ARRAY, // sampler2DArray
438 TYPE_SAMPLER_3D, // sampler3D
439 TYPE_SAMPLER_CUBE_ARRAY, // samplerCubeArray
440 TYPE_SAMPLER_1D_SHADOW, // sampler1DShadow
441 TYPE_SAMPLER_2D_SHADOW, // sampler2DShadow
442 TYPE_SAMPLER_CUBE_SHADOW, // samplerCubeShadow
443 TYPE_SAMPLER_1D_ARRAY_SHADOW, // sampler1DArrayShadow
444 TYPE_SAMPLER_2D_ARRAY_SHADOW, // sampler2DArrayShadow
445 TYPE_SAMPLER_CUBE_ARRAY_SHADOW, // samplerCubeArrayShadow
446 TYPE_INT_SAMPLER_1D, // isampler1D
447 TYPE_INT_SAMPLER_2D, // isampler2D
448 TYPE_INT_SAMPLER_CUBE, // isamplerCube
449 TYPE_INT_SAMPLER_1D_ARRAY, // isampler1DArray
450 TYPE_INT_SAMPLER_2D_ARRAY, // isampler2DArray
451 TYPE_INT_SAMPLER_3D, // isampler3D
452 TYPE_INT_SAMPLER_CUBE_ARRAY, // isamplerCubeArray
453 TYPE_UINT_SAMPLER_1D, // usampler1D
454 TYPE_UINT_SAMPLER_2D, // usampler2D
455 TYPE_UINT_SAMPLER_CUBE, // usamplerCube
456 TYPE_UINT_SAMPLER_1D_ARRAY, // usampler1DArray
457 TYPE_UINT_SAMPLER_2D_ARRAY, // usampler2DArray
458 TYPE_UINT_SAMPLER_3D, // usampler3D
459 TYPE_UINT_SAMPLER_CUBE_ARRAY, // usamplerCubeArray
460 TYPE_SAMPLER_2D_MULTISAMPLE, // sampler2DMS
461 TYPE_INT_SAMPLER_2D_MULTISAMPLE, // isampler2DMS
462 TYPE_UINT_SAMPLER_2D_MULTISAMPLE, // usampler2DMS
463 TYPE_IMAGE_2D, // image2D
464 TYPE_IMAGE_CUBE, // imageCube
465 TYPE_IMAGE_2D_ARRAY, // image2DArray
466 TYPE_IMAGE_3D, // image3D
467 TYPE_IMAGE_CUBE_ARRAY, // imageCubeArray
468 TYPE_INT_IMAGE_2D, // iimage2D
469 TYPE_INT_IMAGE_CUBE, // iimageCube
470 TYPE_INT_IMAGE_2D_ARRAY, // iimage2DArray
471 TYPE_INT_IMAGE_3D, // iimage3D
472 TYPE_INT_IMAGE_CUBE_ARRAY, // iimageCubeArray
473 TYPE_UINT_IMAGE_2D, // uimage2D
474 TYPE_UINT_IMAGE_CUBE, // uimageCube
475 TYPE_UINT_IMAGE_2D_ARRAY, // uimage2DArray
476 TYPE_UINT_IMAGE_3D, // uimage3D
477 TYPE_UINT_IMAGE_CUBE_ARRAY, // uimageCubeArray
478 TYPE_UINT_ATOMIC_COUNTER, // atomic_uint
479 TYPE_SAMPLER_BUFFER, // samplerBuffer
480 TYPE_INT_SAMPLER_BUFFER, // isamplerBuffer
481 TYPE_UINT_SAMPLER_BUFFER, // usamplerBuffer
482 TYPE_SAMPLER_2D_MULTISAMPLE_ARRAY, // sampler2DMSArray
483 TYPE_INT_SAMPLER_2D_MULTISAMPLE_ARRAY, // isampler2DMSArray
484 TYPE_UINT_SAMPLER_2D_MULTISAMPLE_ARRAY, // usampler2DMSArray
485 TYPE_IMAGE_BUFFER, // imageBuffer
486 TYPE_INT_IMAGE_BUFFER, // iimageBuffer
487 TYPE_UINT_IMAGE_BUFFER, // uimageBuffer
488 };
489
490 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_scalarTypes) == TYPE_LAST);
491 DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_scalarTypes)));
492 return s_scalarTypes[(int)dataType];
493 }
494
getDataTypeFloatScalars(DataType dataType)495 DataType getDataTypeFloatScalars (DataType dataType)
496 {
497 static const DataType s_floatTypes[] =
498 {
499 TYPE_INVALID, // invalid
500 TYPE_FLOAT, // float
501 TYPE_FLOAT_VEC2, // vec2
502 TYPE_FLOAT_VEC3, // vec3
503 TYPE_FLOAT_VEC4, // vec4
504 TYPE_FLOAT_MAT2, // mat2
505 TYPE_FLOAT_MAT2X3, // mat2x3
506 TYPE_FLOAT_MAT2X4, // mat2x4
507 TYPE_FLOAT_MAT3X2, // mat3x2
508 TYPE_FLOAT_MAT3, // mat3
509 TYPE_FLOAT_MAT3X4, // mat3x4
510 TYPE_FLOAT_MAT4X2, // mat4x2
511 TYPE_FLOAT_MAT4X3, // mat4x3
512 TYPE_FLOAT_MAT4, // mat4
513 TYPE_FLOAT, // double
514 TYPE_FLOAT_VEC2, // dvec2
515 TYPE_FLOAT_VEC3, // dvec3
516 TYPE_FLOAT_VEC4, // dvec4
517 TYPE_FLOAT_MAT2, // dmat2
518 TYPE_FLOAT_MAT2X3, // dmat2x3
519 TYPE_FLOAT_MAT2X4, // dmat2x4
520 TYPE_FLOAT_MAT3X2, // dmat3x2
521 TYPE_FLOAT_MAT3, // dmat3
522 TYPE_FLOAT_MAT3X4, // dmat3x4
523 TYPE_FLOAT_MAT4X2, // dmat4x2
524 TYPE_FLOAT_MAT4X3, // dmat4x3
525 TYPE_FLOAT_MAT4, // dmat4
526 TYPE_FLOAT, // int
527 TYPE_FLOAT_VEC2, // ivec2
528 TYPE_FLOAT_VEC3, // ivec3
529 TYPE_FLOAT_VEC4, // ivec4
530 TYPE_FLOAT, // uint
531 TYPE_FLOAT_VEC2, // uvec2
532 TYPE_FLOAT_VEC3, // uvec3
533 TYPE_FLOAT_VEC4, // uvec4
534 TYPE_FLOAT, // bool
535 TYPE_FLOAT_VEC2, // bvec2
536 TYPE_FLOAT_VEC3, // bvec3
537 TYPE_FLOAT_VEC4, // bvec4
538 TYPE_INVALID, // sampler1D
539 TYPE_INVALID, // sampler2D
540 TYPE_INVALID, // samplerCube
541 TYPE_INVALID, // sampler1DArray
542 TYPE_INVALID, // sampler2DArray
543 TYPE_INVALID, // sampler3D
544 TYPE_INVALID, // samplerCubeArray
545 TYPE_INVALID, // sampler1DShadow
546 TYPE_INVALID, // sampler2DShadow
547 TYPE_INVALID, // samplerCubeShadow
548 TYPE_INVALID, // sampler1DArrayShadow
549 TYPE_INVALID, // sampler2DArrayShadow
550 TYPE_INVALID, // samplerCubeArrayShadow
551 TYPE_INVALID, // isampler1D
552 TYPE_INVALID, // isampler2D
553 TYPE_INVALID, // isamplerCube
554 TYPE_INVALID, // isampler1DArray
555 TYPE_INVALID, // isampler2DArray
556 TYPE_INVALID, // isampler3D
557 TYPE_INVALID, // isamplerCubeArray
558 TYPE_INVALID, // usampler1D
559 TYPE_INVALID, // usampler2D
560 TYPE_INVALID, // usamplerCube
561 TYPE_INVALID, // usampler1DArray
562 TYPE_INVALID, // usampler2DArray
563 TYPE_INVALID, // usampler3D
564 TYPE_INVALID, // usamplerCubeArray
565 TYPE_INVALID, // sampler2DMS
566 TYPE_INVALID, // isampler2DMS
567 TYPE_INVALID, // usampler2DMS
568 TYPE_INVALID, // image2D
569 TYPE_INVALID, // imageCube
570 TYPE_INVALID, // image2DArray
571 TYPE_INVALID, // image3D
572 TYPE_INVALID, // imageCubeArray
573 TYPE_INVALID, // iimage2D
574 TYPE_INVALID, // iimageCube
575 TYPE_INVALID, // iimage2DArray
576 TYPE_INVALID, // iimage3D
577 TYPE_INVALID, // iimageCubeArray
578 TYPE_INVALID, // uimage2D
579 TYPE_INVALID, // uimageCube
580 TYPE_INVALID, // uimage2DArray
581 TYPE_INVALID, // uimage3D
582 TYPE_INVALID, // uimageCubeArray
583 TYPE_INVALID, // atomic_uint
584 TYPE_INVALID, // samplerBuffer
585 TYPE_INVALID, // isamplerBuffer
586 TYPE_INVALID, // usamplerBuffer
587 TYPE_INVALID, // sampler2DMSArray
588 TYPE_INVALID, // isampler2DMSArray
589 TYPE_INVALID, // usampler2DMSArray
590 TYPE_INVALID, // imageBuffer
591 TYPE_INVALID, // iimageBuffer
592 TYPE_INVALID, // uimageBuffer
593 };
594
595 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_floatTypes) == TYPE_LAST);
596 DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_floatTypes)));
597 return s_floatTypes[(int)dataType];
598 }
599
getDataTypeDoubleScalars(DataType dataType)600 DataType getDataTypeDoubleScalars (DataType dataType)
601 {
602 static const DataType s_doubleTypes[] =
603 {
604 TYPE_INVALID, // invalid
605 TYPE_DOUBLE, // float
606 TYPE_DOUBLE_VEC2, // vec2
607 TYPE_DOUBLE_VEC3, // vec3
608 TYPE_DOUBLE_VEC4, // vec4
609 TYPE_DOUBLE_MAT2, // mat2
610 TYPE_DOUBLE_MAT2X3, // mat2x3
611 TYPE_DOUBLE_MAT2X4, // mat2x4
612 TYPE_DOUBLE_MAT3X2, // mat3x2
613 TYPE_DOUBLE_MAT3, // mat3
614 TYPE_DOUBLE_MAT3X4, // mat3x4
615 TYPE_DOUBLE_MAT4X2, // mat4x2
616 TYPE_DOUBLE_MAT4X3, // mat4x3
617 TYPE_DOUBLE_MAT4, // mat4
618 TYPE_DOUBLE, // double
619 TYPE_DOUBLE_VEC2, // dvec2
620 TYPE_DOUBLE_VEC3, // dvec3
621 TYPE_DOUBLE_VEC4, // dvec4
622 TYPE_DOUBLE_MAT2, // dmat2
623 TYPE_DOUBLE_MAT2X3, // dmat2x3
624 TYPE_DOUBLE_MAT2X4, // dmat2x4
625 TYPE_DOUBLE_MAT3X2, // dmat3x2
626 TYPE_DOUBLE_MAT3, // dmat3
627 TYPE_DOUBLE_MAT3X4, // dmat3x4
628 TYPE_DOUBLE_MAT4X2, // dmat4x2
629 TYPE_DOUBLE_MAT4X3, // dmat4x3
630 TYPE_DOUBLE_MAT4, // dmat4
631 TYPE_DOUBLE, // int
632 TYPE_DOUBLE_VEC2, // ivec2
633 TYPE_DOUBLE_VEC3, // ivec3
634 TYPE_DOUBLE_VEC4, // ivec4
635 TYPE_DOUBLE, // uint
636 TYPE_DOUBLE_VEC2, // uvec2
637 TYPE_DOUBLE_VEC3, // uvec3
638 TYPE_DOUBLE_VEC4, // uvec4
639 TYPE_DOUBLE, // bool
640 TYPE_DOUBLE_VEC2, // bvec2
641 TYPE_DOUBLE_VEC3, // bvec3
642 TYPE_DOUBLE_VEC4, // bvec4
643 TYPE_INVALID, // sampler1D
644 TYPE_INVALID, // sampler2D
645 TYPE_INVALID, // samplerCube
646 TYPE_INVALID, // sampler1DArray
647 TYPE_INVALID, // sampler2DArray
648 TYPE_INVALID, // sampler3D
649 TYPE_INVALID, // samplerCubeArray
650 TYPE_INVALID, // sampler1DShadow
651 TYPE_INVALID, // sampler2DShadow
652 TYPE_INVALID, // samplerCubeShadow
653 TYPE_INVALID, // sampler1DArrayShadow
654 TYPE_INVALID, // sampler2DArrayShadow
655 TYPE_INVALID, // samplerCubeArrayShadow
656 TYPE_INVALID, // isampler1D
657 TYPE_INVALID, // isampler2D
658 TYPE_INVALID, // isamplerCube
659 TYPE_INVALID, // isampler1DArray
660 TYPE_INVALID, // isampler2DArray
661 TYPE_INVALID, // isampler3D
662 TYPE_INVALID, // isamplerCubeArray
663 TYPE_INVALID, // usampler1D
664 TYPE_INVALID, // usampler2D
665 TYPE_INVALID, // usamplerCube
666 TYPE_INVALID, // usampler1DArray
667 TYPE_INVALID, // usampler2DArray
668 TYPE_INVALID, // usampler3D
669 TYPE_INVALID, // usamplerCubeArray
670 TYPE_INVALID, // sampler2DMS
671 TYPE_INVALID, // isampler2DMS
672 TYPE_INVALID, // usampler2DMS
673 TYPE_INVALID, // image2D
674 TYPE_INVALID, // imageCube
675 TYPE_INVALID, // image2DArray
676 TYPE_INVALID, // image3D
677 TYPE_INVALID, // imageCubeArray
678 TYPE_INVALID, // iimage2D
679 TYPE_INVALID, // iimageCube
680 TYPE_INVALID, // iimage2DArray
681 TYPE_INVALID, // iimage3D
682 TYPE_INVALID, // iimageCubeArray
683 TYPE_INVALID, // uimage2D
684 TYPE_INVALID, // uimageCube
685 TYPE_INVALID, // uimage2DArray
686 TYPE_INVALID, // uimage3D
687 TYPE_INVALID, // uimageCubeArray
688 TYPE_INVALID, // atomic_uint
689 TYPE_INVALID, // samplerBuffer
690 TYPE_INVALID, // isamplerBuffer
691 TYPE_INVALID, // usamplerBuffer
692 TYPE_INVALID, // sampler2DMSArray
693 TYPE_INVALID, // isampler2DMSArray
694 TYPE_INVALID, // usampler2DMSArray
695 TYPE_INVALID, // imageBuffer
696 TYPE_INVALID, // iimageBuffer
697 TYPE_INVALID, // uimageBuffer
698 };
699
700 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_doubleTypes) == TYPE_LAST);
701 DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_doubleTypes)));
702 return s_doubleTypes[(int)dataType];
703 }
704
getDataTypeVector(DataType scalarType,int size)705 DataType getDataTypeVector (DataType scalarType, int size)
706 {
707 DE_ASSERT(deInRange32(size, 1, 4));
708 switch (scalarType)
709 {
710 case TYPE_FLOAT:
711 case TYPE_DOUBLE:
712 case TYPE_INT:
713 case TYPE_UINT:
714 case TYPE_BOOL:
715 return (DataType)((int)scalarType + size - 1);
716 default:
717 return TYPE_INVALID;
718 }
719 }
720
getDataTypeFloatVec(int vecSize)721 DataType getDataTypeFloatVec (int vecSize)
722 {
723 return getDataTypeVector(TYPE_FLOAT, vecSize);
724 }
725
getDataTypeIntVec(int vecSize)726 DataType getDataTypeIntVec (int vecSize)
727 {
728 return getDataTypeVector(TYPE_INT, vecSize);
729 }
730
getDataTypeUintVec(int vecSize)731 DataType getDataTypeUintVec (int vecSize)
732 {
733 return getDataTypeVector(TYPE_UINT, vecSize);
734 }
735
getDataTypeBoolVec(int vecSize)736 DataType getDataTypeBoolVec (int vecSize)
737 {
738 return getDataTypeVector(TYPE_BOOL, vecSize);
739 }
740
getDataTypeMatrix(int numCols,int numRows)741 DataType getDataTypeMatrix (int numCols, int numRows)
742 {
743 DE_ASSERT(de::inRange(numCols, 2, 4) && de::inRange(numRows, 2, 4));
744 return (DataType)((int)TYPE_FLOAT_MAT2 + (numCols-2)*3 + (numRows-2));
745 }
746
getDataTypeMatrixNumRows(DataType dataType)747 int getDataTypeMatrixNumRows (DataType dataType)
748 {
749 switch (dataType)
750 {
751 case TYPE_FLOAT_MAT2: return 2;
752 case TYPE_FLOAT_MAT2X3: return 3;
753 case TYPE_FLOAT_MAT2X4: return 4;
754 case TYPE_FLOAT_MAT3X2: return 2;
755 case TYPE_FLOAT_MAT3: return 3;
756 case TYPE_FLOAT_MAT3X4: return 4;
757 case TYPE_FLOAT_MAT4X2: return 2;
758 case TYPE_FLOAT_MAT4X3: return 3;
759 case TYPE_FLOAT_MAT4: return 4;
760 case TYPE_DOUBLE_MAT2: return 2;
761 case TYPE_DOUBLE_MAT2X3: return 3;
762 case TYPE_DOUBLE_MAT2X4: return 4;
763 case TYPE_DOUBLE_MAT3X2: return 2;
764 case TYPE_DOUBLE_MAT3: return 3;
765 case TYPE_DOUBLE_MAT3X4: return 4;
766 case TYPE_DOUBLE_MAT4X2: return 2;
767 case TYPE_DOUBLE_MAT4X3: return 3;
768 case TYPE_DOUBLE_MAT4: return 4;
769 default:
770 DE_ASSERT(false);
771 return 0;
772 }
773 }
774
getDataTypeMatrixNumColumns(DataType dataType)775 int getDataTypeMatrixNumColumns (DataType dataType)
776 {
777 switch (dataType)
778 {
779 case TYPE_FLOAT_MAT2: return 2;
780 case TYPE_FLOAT_MAT2X3: return 2;
781 case TYPE_FLOAT_MAT2X4: return 2;
782 case TYPE_FLOAT_MAT3X2: return 3;
783 case TYPE_FLOAT_MAT3: return 3;
784 case TYPE_FLOAT_MAT3X4: return 3;
785 case TYPE_FLOAT_MAT4X2: return 4;
786 case TYPE_FLOAT_MAT4X3: return 4;
787 case TYPE_FLOAT_MAT4: return 4;
788 case TYPE_DOUBLE_MAT2: return 2;
789 case TYPE_DOUBLE_MAT2X3: return 2;
790 case TYPE_DOUBLE_MAT2X4: return 2;
791 case TYPE_DOUBLE_MAT3X2: return 3;
792 case TYPE_DOUBLE_MAT3: return 3;
793 case TYPE_DOUBLE_MAT3X4: return 3;
794 case TYPE_DOUBLE_MAT4X2: return 4;
795 case TYPE_DOUBLE_MAT4X3: return 4;
796 case TYPE_DOUBLE_MAT4: return 4;
797 default:
798 DE_ASSERT(false);
799 return 0;
800 }
801 }
802
getDataTypeNumLocations(DataType dataType)803 int getDataTypeNumLocations (DataType dataType)
804 {
805 if (isDataTypeScalarOrVector(dataType))
806 return 1;
807 else if (isDataTypeMatrix(dataType))
808 return getDataTypeMatrixNumColumns(dataType);
809
810 DE_FATAL("Illegal datatype.");
811 return 0;
812 }
813
getDataTypeNumComponents(DataType dataType)814 int getDataTypeNumComponents (DataType dataType)
815 {
816 if (isDataTypeScalarOrVector(dataType))
817 return getDataTypeScalarSize(dataType);
818 else if (isDataTypeMatrix(dataType))
819 return getDataTypeMatrixNumRows(dataType);
820
821 DE_FATAL("Illegal datatype.");
822 return 0;
823 }
824
getDataTypeFromGLType(deUint32 glType)825 DataType getDataTypeFromGLType (deUint32 glType)
826 {
827 switch (glType)
828 {
829 case GL_FLOAT: return TYPE_FLOAT;
830 case GL_FLOAT_VEC2: return TYPE_FLOAT_VEC2;
831 case GL_FLOAT_VEC3: return TYPE_FLOAT_VEC3;
832 case GL_FLOAT_VEC4: return TYPE_FLOAT_VEC4;
833
834 case GL_FLOAT_MAT2: return TYPE_FLOAT_MAT2;
835 case GL_FLOAT_MAT2x3: return TYPE_FLOAT_MAT2X3;
836 case GL_FLOAT_MAT2x4: return TYPE_FLOAT_MAT2X4;
837
838 case GL_FLOAT_MAT3x2: return TYPE_FLOAT_MAT3X2;
839 case GL_FLOAT_MAT3: return TYPE_FLOAT_MAT3;
840 case GL_FLOAT_MAT3x4: return TYPE_FLOAT_MAT3X4;
841
842 case GL_FLOAT_MAT4x2: return TYPE_FLOAT_MAT4X2;
843 case GL_FLOAT_MAT4x3: return TYPE_FLOAT_MAT4X3;
844 case GL_FLOAT_MAT4: return TYPE_FLOAT_MAT4;
845
846 case GL_DOUBLE: return TYPE_DOUBLE;
847 case GL_DOUBLE_VEC2: return TYPE_DOUBLE_VEC2;
848 case GL_DOUBLE_VEC3: return TYPE_DOUBLE_VEC3;
849 case GL_DOUBLE_VEC4: return TYPE_DOUBLE_VEC4;
850
851 case GL_DOUBLE_MAT2: return TYPE_DOUBLE_MAT2;
852 case GL_DOUBLE_MAT2x3: return TYPE_DOUBLE_MAT2X3;
853 case GL_DOUBLE_MAT2x4: return TYPE_DOUBLE_MAT2X4;
854
855 case GL_DOUBLE_MAT3x2: return TYPE_DOUBLE_MAT3X2;
856 case GL_DOUBLE_MAT3: return TYPE_DOUBLE_MAT3;
857 case GL_DOUBLE_MAT3x4: return TYPE_DOUBLE_MAT3X4;
858
859 case GL_DOUBLE_MAT4x2: return TYPE_DOUBLE_MAT4X2;
860 case GL_DOUBLE_MAT4x3: return TYPE_DOUBLE_MAT4X3;
861 case GL_DOUBLE_MAT4: return TYPE_DOUBLE_MAT4;
862
863 case GL_INT: return TYPE_INT;
864 case GL_INT_VEC2: return TYPE_INT_VEC2;
865 case GL_INT_VEC3: return TYPE_INT_VEC3;
866 case GL_INT_VEC4: return TYPE_INT_VEC4;
867
868 case GL_UNSIGNED_INT: return TYPE_UINT;
869 case GL_UNSIGNED_INT_VEC2: return TYPE_UINT_VEC2;
870 case GL_UNSIGNED_INT_VEC3: return TYPE_UINT_VEC3;
871 case GL_UNSIGNED_INT_VEC4: return TYPE_UINT_VEC4;
872
873 case GL_BOOL: return TYPE_BOOL;
874 case GL_BOOL_VEC2: return TYPE_BOOL_VEC2;
875 case GL_BOOL_VEC3: return TYPE_BOOL_VEC3;
876 case GL_BOOL_VEC4: return TYPE_BOOL_VEC4;
877
878 case GL_SAMPLER_1D: return TYPE_SAMPLER_1D;
879 case GL_SAMPLER_2D: return TYPE_SAMPLER_2D;
880 case GL_SAMPLER_CUBE: return TYPE_SAMPLER_CUBE;
881 case GL_SAMPLER_1D_ARRAY: return TYPE_SAMPLER_1D_ARRAY;
882 case GL_SAMPLER_2D_ARRAY: return TYPE_SAMPLER_2D_ARRAY;
883 case GL_SAMPLER_3D: return TYPE_SAMPLER_3D;
884 case GL_SAMPLER_CUBE_MAP_ARRAY: return TYPE_SAMPLER_CUBE_ARRAY;
885
886 case GL_SAMPLER_1D_SHADOW: return TYPE_SAMPLER_1D_SHADOW;
887 case GL_SAMPLER_2D_SHADOW: return TYPE_SAMPLER_2D_SHADOW;
888 case GL_SAMPLER_CUBE_SHADOW: return TYPE_SAMPLER_CUBE_SHADOW;
889 case GL_SAMPLER_1D_ARRAY_SHADOW: return TYPE_SAMPLER_1D_ARRAY_SHADOW;
890 case GL_SAMPLER_2D_ARRAY_SHADOW: return TYPE_SAMPLER_2D_ARRAY_SHADOW;
891 case GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW: return TYPE_SAMPLER_CUBE_ARRAY_SHADOW;
892
893 case GL_INT_SAMPLER_1D: return TYPE_INT_SAMPLER_1D;
894 case GL_INT_SAMPLER_2D: return TYPE_INT_SAMPLER_2D;
895 case GL_INT_SAMPLER_CUBE: return TYPE_INT_SAMPLER_CUBE;
896 case GL_INT_SAMPLER_1D_ARRAY: return TYPE_INT_SAMPLER_1D_ARRAY;
897 case GL_INT_SAMPLER_2D_ARRAY: return TYPE_INT_SAMPLER_2D_ARRAY;
898 case GL_INT_SAMPLER_3D: return TYPE_INT_SAMPLER_3D;
899 case GL_INT_SAMPLER_CUBE_MAP_ARRAY: return TYPE_INT_SAMPLER_CUBE_ARRAY;
900
901 case GL_UNSIGNED_INT_SAMPLER_1D: return TYPE_UINT_SAMPLER_1D;
902 case GL_UNSIGNED_INT_SAMPLER_2D: return TYPE_UINT_SAMPLER_2D;
903 case GL_UNSIGNED_INT_SAMPLER_CUBE: return TYPE_UINT_SAMPLER_CUBE;
904 case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: return TYPE_UINT_SAMPLER_1D_ARRAY;
905 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: return TYPE_UINT_SAMPLER_2D_ARRAY;
906 case GL_UNSIGNED_INT_SAMPLER_3D: return TYPE_UINT_SAMPLER_3D;
907 case GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY: return TYPE_UINT_SAMPLER_CUBE_ARRAY;
908
909 case GL_SAMPLER_2D_MULTISAMPLE: return TYPE_SAMPLER_2D_MULTISAMPLE;
910 case GL_INT_SAMPLER_2D_MULTISAMPLE: return TYPE_INT_SAMPLER_2D_MULTISAMPLE;
911 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: return TYPE_UINT_SAMPLER_2D_MULTISAMPLE;
912
913 case GL_IMAGE_2D: return TYPE_IMAGE_2D;
914 case GL_IMAGE_CUBE: return TYPE_IMAGE_CUBE;
915 case GL_IMAGE_2D_ARRAY: return TYPE_IMAGE_2D_ARRAY;
916 case GL_IMAGE_3D: return TYPE_IMAGE_3D;
917 case GL_INT_IMAGE_2D: return TYPE_INT_IMAGE_2D;
918 case GL_INT_IMAGE_CUBE: return TYPE_INT_IMAGE_CUBE;
919 case GL_INT_IMAGE_2D_ARRAY: return TYPE_INT_IMAGE_2D_ARRAY;
920 case GL_INT_IMAGE_3D: return TYPE_INT_IMAGE_3D;
921 case GL_UNSIGNED_INT_IMAGE_2D: return TYPE_UINT_IMAGE_2D;
922 case GL_UNSIGNED_INT_IMAGE_CUBE: return TYPE_UINT_IMAGE_CUBE;
923 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY: return TYPE_UINT_IMAGE_2D_ARRAY;
924 case GL_UNSIGNED_INT_IMAGE_3D: return TYPE_UINT_IMAGE_3D;
925
926 case GL_UNSIGNED_INT_ATOMIC_COUNTER: return TYPE_UINT_ATOMIC_COUNTER;
927
928 case GL_SAMPLER_BUFFER: return TYPE_SAMPLER_BUFFER;
929 case GL_INT_SAMPLER_BUFFER: return TYPE_INT_SAMPLER_BUFFER;
930 case GL_UNSIGNED_INT_SAMPLER_BUFFER: return TYPE_UINT_SAMPLER_BUFFER;
931
932 case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: return TYPE_SAMPLER_2D_MULTISAMPLE_ARRAY;
933 case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: return TYPE_INT_SAMPLER_2D_MULTISAMPLE_ARRAY;
934 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: return TYPE_UINT_SAMPLER_2D_MULTISAMPLE_ARRAY;
935
936 case GL_IMAGE_BUFFER: return TYPE_IMAGE_BUFFER;
937 case GL_INT_IMAGE_BUFFER: return TYPE_INT_IMAGE_BUFFER;
938 case GL_UNSIGNED_INT_IMAGE_BUFFER: return TYPE_UINT_IMAGE_BUFFER;
939
940 default:
941 return TYPE_LAST;
942 }
943 }
944
945 } // glu
946