• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES Utilities
3  * ------------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief 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 	};
52 
53 	return de::getSizedArrayElement<GLSL_VERSION_LAST>(s_names, version);
54 }
55 
getGLSLVersionDeclaration(GLSLVersion version)56 const char* getGLSLVersionDeclaration (GLSLVersion version)
57 {
58 	static const char* s_decl[] =
59 	{
60 		"#version 100",
61 		"#version 300 es",
62 		"#version 310 es",
63 		"#version 320 es",
64 		"#version 130",
65 		"#version 140",
66 		"#version 150",
67 		"#version 330",
68 		"#version 400",
69 		"#version 410",
70 		"#version 420",
71 		"#version 430",
72 		"#version 440",
73 		"#version 450",
74 	};
75 
76 	return de::getSizedArrayElement<GLSL_VERSION_LAST>(s_decl, version);
77 }
78 
glslVersionUsesInOutQualifiers(GLSLVersion version)79 bool glslVersionUsesInOutQualifiers (GLSLVersion version)
80 {
81 	return de::inRange<int>(version, GLSL_VERSION_300_ES, GLSL_VERSION_320_ES) || de::inRange<int>(version, GLSL_VERSION_330, GLSL_VERSION_430);
82 }
83 
glslVersionIsES(GLSLVersion version)84 bool glslVersionIsES (GLSLVersion version)
85 {
86 	DE_STATIC_ASSERT(GLSL_VERSION_LAST == 14);
87 	DE_ASSERT(version != GLSL_VERSION_LAST);
88 
89 	if (version == GLSL_VERSION_100_ES	||
90 		version == GLSL_VERSION_300_ES	||
91 		version == GLSL_VERSION_310_ES	||
92 		version == GLSL_VERSION_320_ES)
93 		return true;
94 	else
95 		return false;
96 }
97 
98 // \todo [2014-10-06 pyry] Export this.
getMinAPIForGLSLVersion(GLSLVersion version)99 static ApiType getMinAPIForGLSLVersion (GLSLVersion version)
100 {
101 	static const ApiType s_minApi[] =
102 	{
103 		ApiType::es(2,0),
104 		ApiType::es(3,0),
105 		ApiType::es(3,1),
106 		ApiType::es(3,2),
107 		ApiType::core(3,0),
108 		ApiType::core(3,1),
109 		ApiType::core(3,2),
110 		ApiType::core(3,3),
111 		ApiType::core(4,0),
112 		ApiType::core(4,1),
113 		ApiType::core(4,2),
114 		ApiType::core(4,3),
115 		ApiType::core(4,4),
116 		ApiType::core(4,5),
117 	};
118 
119 	return de::getSizedArrayElement<GLSL_VERSION_LAST>(s_minApi, version);
120 }
121 
isGLSLVersionSupported(ContextType type,GLSLVersion version)122 bool isGLSLVersionSupported (ContextType type, GLSLVersion version)
123 {
124 	return contextSupports(type, getMinAPIForGLSLVersion(version));
125 }
126 
getContextTypeGLSLVersion(ContextType type)127 GLSLVersion getContextTypeGLSLVersion (ContextType type)
128 {
129 	// \note From newer to older
130 	for (int version = GLSL_VERSION_LAST-1; version >= 0; version--)
131 	{
132 		if (isGLSLVersionSupported(type, GLSLVersion(version)))
133 			return GLSLVersion(version);
134 	}
135 
136 	DE_ASSERT(false);
137 	return GLSL_VERSION_LAST;
138 }
139 
140 // ShaderType
141 
getShaderTypeName(ShaderType shaderType)142 const char* getShaderTypeName (ShaderType shaderType)
143 {
144 	static const char* s_names[] =
145 	{
146 		"vertex",
147 		"fragment",
148 		"geometry",
149 		"tess_control",
150 		"tess_eval",
151 		"compute",
152 	};
153 
154 	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_names) == SHADERTYPE_LAST);
155 	DE_ASSERT(deInBounds32((int)shaderType, 0, SHADERTYPE_LAST));
156 	return s_names[(int)shaderType];
157 }
158 
159 // Precision
160 
getPrecisionName(Precision precision)161 const char* getPrecisionName (Precision precision)
162 {
163 	static const char* s_names[] =
164 	{
165 		"lowp",
166 		"mediump",
167 		"highp"
168 	};
169 
170 	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_names) == PRECISION_LAST);
171 	DE_ASSERT(deInBounds32((int)precision, 0, PRECISION_LAST));
172 	return s_names[(int)precision];
173 }
174 
175 // DataType
176 
getDataTypeName(DataType dataType)177 const char* getDataTypeName (DataType dataType)
178 {
179 	static const char* s_names[] =
180 	{
181 		"invalid",
182 		"float",
183 		"vec2",
184 		"vec3",
185 		"vec4",
186 		"mat2",
187 		"mat2x3",
188 		"mat2x4",
189 		"mat3x2",
190 		"mat3",
191 		"mat3x4",
192 		"mat4x2",
193 		"mat4x3",
194 		"mat4",
195 		"double",
196 		"dvec2",
197 		"dvec3",
198 		"dvec4",
199 		"dmat2",
200 		"dmat2x3",
201 		"dmat2x4",
202 		"dmat3x2",
203 		"dmat3",
204 		"dmat3x4",
205 		"dmat4x2",
206 		"dmat4x3",
207 		"dmat4",
208 		"int",
209 		"ivec2",
210 		"ivec3",
211 		"ivec4",
212 		"uint",
213 		"uvec2",
214 		"uvec3",
215 		"uvec4",
216 		"bool",
217 		"bvec2",
218 		"bvec3",
219 		"bvec4",
220 		"sampler1D",
221 		"sampler2D",
222 		"samplerCube",
223 		"sampler1DArray",
224 		"sampler2DArray",
225 		"sampler3D",
226 		"samplerCubeArray",
227 		"sampler1DShadow",
228 		"sampler2DShadow",
229 		"samplerCubeShadow",
230 		"sampler1DArrayShadow",
231 		"sampler2DArrayShadow",
232 		"samplerCubeArrayShadow",
233 		"isampler1D",
234 		"isampler2D",
235 		"isamplerCube",
236 		"isampler1DArray",
237 		"isampler2DArray",
238 		"isampler3D",
239 		"isamplerCubeArray",
240 		"usampler1D",
241 		"usampler2D",
242 		"usamplerCube",
243 		"usampler1DArray",
244 		"usampler2DArray",
245 		"usampler3D",
246 		"usamplerCubeArray",
247 		"sampler2DMS",
248 		"isampler2DMS",
249 		"usampler2DMS",
250 		"image2D",
251 		"imageCube",
252 		"image2DArray",
253 		"image3D",
254 		"imageCubeArray",
255 		"iimage2D",
256 		"iimageCube",
257 		"iimage2DArray",
258 		"iimage3D",
259 		"iimageCubeArray",
260 		"uimage2D",
261 		"uimageCube",
262 		"uimage2DArray",
263 		"uimage3D",
264 		"uimageCubeArray",
265 		"atomic_uint",
266 		"samplerBuffer",
267 		"isamplerBuffer",
268 		"usamplerBuffer",
269 		"sampler2DMSArray",
270 		"isampler2DMSArray",
271 		"usampler2DMSArray",
272 		"imageBuffer",
273 		"iimageBuffer",
274 		"uimageBuffer",
275 	};
276 
277 	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_names) == TYPE_LAST);
278 	DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_names)));
279 	return s_names[(int)dataType];
280 }
281 
getDataTypeScalarSize(DataType dataType)282 int getDataTypeScalarSize (DataType dataType)
283 {
284 	static const int s_sizes[] =
285 	{
286 		-1,		// invalid
287 		1,		// float
288 		2,		// vec2
289 		3,		// vec3
290 		4,		// vec4
291 		4,		// mat2
292 		6,		// mat2x3
293 		8,		// mat2x4
294 		6,		// mat3x2
295 		9,		// mat3
296 		12,		// mat3x4
297 		8,		// mat4x2
298 		12,		// mat4x3
299 		16,		// mat4
300 		1,		// double
301 		2,		// dvec2
302 		3,		// dvec3
303 		4,		// dvec4
304 		4,		// dmat2
305 		6,		// dmat2x3
306 		8,		// dmat2x4
307 		6,		// dmat3x2
308 		9,		// dmat3
309 		12,		// dmat3x4
310 		8,		// dmat4x2
311 		12,		// dmat4x3
312 		16,		// dmat4
313 		1,		// int
314 		2,		// ivec2
315 		3,		// ivec3
316 		4,		// ivec4
317 		1,		// uint
318 		2,		// uvec2
319 		3,		// uvec3
320 		4,		// uvec4
321 		1,		// bool
322 		2,		// bvec2
323 		3,		// bvec3
324 		4,		// bvec4
325 		1,		// sampler1D
326 		1,		// sampler2D
327 		1,		// samplerCube
328 		1,		// sampler1DArray
329 		1,		// sampler2DArray
330 		1,		// sampler3D
331 		1,		// samplerCubeArray
332 		1,		// sampler1DShadow
333 		1,		// sampler2DShadow
334 		1,		// samplerCubeShadow
335 		1,		// sampler1DArrayShadow
336 		1,		// sampler2DArrayShadow
337 		1,		// samplerCubeArrayShadow
338 		1,		// isampler1D
339 		1,		// isampler2D
340 		1,		// isamplerCube
341 		1,		// isampler1DArray
342 		1,		// isampler2DArray
343 		1,		// isampler3D
344 		1,		// isamplerCubeArray
345 		1,		// usampler1D
346 		1,		// usampler2D
347 		1,		// usamplerCube
348 		1,		// usampler1DArray
349 		1,		// usampler2DArray
350 		1,		// usampler3D
351 		1,		// usamplerCubeArray
352 		1,		// sampler2DMS
353 		1,		// isampler2DMS
354 		1,		// usampler2DMS
355 		1,		// image2D
356 		1,		// imageCube
357 		1,		// image2DArray
358 		1,		// image3D
359 		1,		// imageCubeArray
360 		1,		// iimage2D
361 		1,		// iimageCube
362 		1,		// iimage2DArray
363 		1,		// iimage3D
364 		1,		// iimageCubeArray
365 		1,		// uimage2D
366 		1,		// uimageCube
367 		1,		// uimage2DArray
368 		1,		// uimage3D
369 		1,		// uimageCubeArray
370 		1,		// atomic_uint
371 		1,		// samplerBuffer
372 		1,		// isamplerBuffer
373 		1,		// usamplerBuffer
374 		1,		// sampler2DMSArray
375 		1,		// isampler2DMSArray
376 		1,		// usampler2DMSArray
377 		1,		// imageBuffer
378 		1,		// iimageBuffer
379 		1,		// uimageBuffer
380 	};
381 
382 	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_sizes) == TYPE_LAST);
383 	DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_sizes)));
384 	return s_sizes[(int)dataType];
385 }
386 
getDataTypeScalarType(DataType dataType)387 DataType getDataTypeScalarType (DataType dataType)
388 {
389 	static const DataType s_scalarTypes[] =
390 	{
391 		TYPE_INVALID,							// invalid
392 		TYPE_FLOAT,								// float
393 		TYPE_FLOAT,								// vec2
394 		TYPE_FLOAT,								// vec3
395 		TYPE_FLOAT,								// vec4
396 		TYPE_FLOAT,								// mat2
397 		TYPE_FLOAT,								// mat2x3
398 		TYPE_FLOAT,								// mat2x4
399 		TYPE_FLOAT,								// mat3x2
400 		TYPE_FLOAT,								// mat3
401 		TYPE_FLOAT,								// mat3x4
402 		TYPE_FLOAT,								// mat4x2
403 		TYPE_FLOAT,								// mat4x3
404 		TYPE_FLOAT,								// mat4
405 		TYPE_DOUBLE,							// double
406 		TYPE_DOUBLE,							// dvec2
407 		TYPE_DOUBLE,							// dvec3
408 		TYPE_DOUBLE,							// dvec4
409 		TYPE_DOUBLE,							// dmat2
410 		TYPE_DOUBLE,							// dmat2x3
411 		TYPE_DOUBLE,							// dmat2x4
412 		TYPE_DOUBLE,							// dmat3x2
413 		TYPE_DOUBLE,							// dmat3
414 		TYPE_DOUBLE,							// dmat3x4
415 		TYPE_DOUBLE,							// dmat4x2
416 		TYPE_DOUBLE,							// dmat4x3
417 		TYPE_DOUBLE,							// dmat4
418 		TYPE_INT,								// int
419 		TYPE_INT,								// ivec2
420 		TYPE_INT,								// ivec3
421 		TYPE_INT,								// ivec4
422 		TYPE_UINT,								// uint
423 		TYPE_UINT,								// uvec2
424 		TYPE_UINT,								// uvec3
425 		TYPE_UINT,								// uvec4
426 		TYPE_BOOL,								// bool
427 		TYPE_BOOL,								// bvec2
428 		TYPE_BOOL,								// bvec3
429 		TYPE_BOOL,								// bvec4
430 		TYPE_SAMPLER_1D,						// sampler1D
431 		TYPE_SAMPLER_2D,						// sampler2D
432 		TYPE_SAMPLER_CUBE,						// samplerCube
433 		TYPE_SAMPLER_1D_ARRAY,					// sampler1DArray
434 		TYPE_SAMPLER_2D_ARRAY,					// sampler2DArray
435 		TYPE_SAMPLER_3D,						// sampler3D
436 		TYPE_SAMPLER_CUBE_ARRAY,				// samplerCubeArray
437 		TYPE_SAMPLER_1D_SHADOW,					// sampler1DShadow
438 		TYPE_SAMPLER_2D_SHADOW,					// sampler2DShadow
439 		TYPE_SAMPLER_CUBE_SHADOW,				// samplerCubeShadow
440 		TYPE_SAMPLER_1D_ARRAY_SHADOW,			// sampler1DArrayShadow
441 		TYPE_SAMPLER_2D_ARRAY_SHADOW,			// sampler2DArrayShadow
442 		TYPE_SAMPLER_CUBE_ARRAY_SHADOW,			// samplerCubeArrayShadow
443 		TYPE_INT_SAMPLER_1D,					// isampler1D
444 		TYPE_INT_SAMPLER_2D,					// isampler2D
445 		TYPE_INT_SAMPLER_CUBE,					// isamplerCube
446 		TYPE_INT_SAMPLER_1D_ARRAY,				// isampler1DArray
447 		TYPE_INT_SAMPLER_2D_ARRAY,				// isampler2DArray
448 		TYPE_INT_SAMPLER_3D,					// isampler3D
449 		TYPE_INT_SAMPLER_CUBE_ARRAY,			// isamplerCubeArray
450 		TYPE_UINT_SAMPLER_1D,					// usampler1D
451 		TYPE_UINT_SAMPLER_2D,					// usampler2D
452 		TYPE_UINT_SAMPLER_CUBE,					// usamplerCube
453 		TYPE_UINT_SAMPLER_1D_ARRAY,				// usampler1DArray
454 		TYPE_UINT_SAMPLER_2D_ARRAY,				// usampler2DArray
455 		TYPE_UINT_SAMPLER_3D,					// usampler3D
456 		TYPE_UINT_SAMPLER_CUBE_ARRAY,			// usamplerCubeArray
457 		TYPE_SAMPLER_2D_MULTISAMPLE,			// sampler2DMS
458 		TYPE_INT_SAMPLER_2D_MULTISAMPLE,		// isampler2DMS
459 		TYPE_UINT_SAMPLER_2D_MULTISAMPLE,		// usampler2DMS
460 		TYPE_IMAGE_2D,							// image2D
461 		TYPE_IMAGE_CUBE,						// imageCube
462 		TYPE_IMAGE_2D_ARRAY,					// image2DArray
463 		TYPE_IMAGE_3D,							// image3D
464 		TYPE_IMAGE_CUBE_ARRAY,					// imageCubeArray
465 		TYPE_INT_IMAGE_2D,						// iimage2D
466 		TYPE_INT_IMAGE_CUBE,					// iimageCube
467 		TYPE_INT_IMAGE_2D_ARRAY,				// iimage2DArray
468 		TYPE_INT_IMAGE_3D,						// iimage3D
469 		TYPE_INT_IMAGE_CUBE_ARRAY,				// iimageCubeArray
470 		TYPE_UINT_IMAGE_2D,						// uimage2D
471 		TYPE_UINT_IMAGE_CUBE,					// uimageCube
472 		TYPE_UINT_IMAGE_2D_ARRAY,				// uimage2DArray
473 		TYPE_UINT_IMAGE_3D,						// uimage3D
474 		TYPE_UINT_IMAGE_CUBE_ARRAY,				// uimageCubeArray
475 		TYPE_UINT_ATOMIC_COUNTER,				// atomic_uint
476 		TYPE_SAMPLER_BUFFER,					// samplerBuffer
477 		TYPE_INT_SAMPLER_BUFFER,				// isamplerBuffer
478 		TYPE_UINT_SAMPLER_BUFFER,				// usamplerBuffer
479 		TYPE_SAMPLER_2D_MULTISAMPLE_ARRAY,		// sampler2DMSArray
480 		TYPE_INT_SAMPLER_2D_MULTISAMPLE_ARRAY,	// isampler2DMSArray
481 		TYPE_UINT_SAMPLER_2D_MULTISAMPLE_ARRAY,	// usampler2DMSArray
482 		TYPE_IMAGE_BUFFER,						// imageBuffer
483 		TYPE_INT_IMAGE_BUFFER,					// iimageBuffer
484 		TYPE_UINT_IMAGE_BUFFER,					// uimageBuffer
485 	};
486 
487 	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_scalarTypes) == TYPE_LAST);
488 	DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_scalarTypes)));
489 	return s_scalarTypes[(int)dataType];
490 }
491 
getDataTypeFloatScalars(DataType dataType)492 DataType getDataTypeFloatScalars (DataType dataType)
493 {
494 	static const DataType s_floatTypes[] =
495 	{
496 		TYPE_INVALID,		// invalid
497 		TYPE_FLOAT,			// float
498 		TYPE_FLOAT_VEC2,	// vec2
499 		TYPE_FLOAT_VEC3,	// vec3
500 		TYPE_FLOAT_VEC4,	// vec4
501 		TYPE_FLOAT_MAT2,	// mat2
502 		TYPE_FLOAT_MAT2X3,	// mat2x3
503 		TYPE_FLOAT_MAT2X4,	// mat2x4
504 		TYPE_FLOAT_MAT3X2,	// mat3x2
505 		TYPE_FLOAT_MAT3,	// mat3
506 		TYPE_FLOAT_MAT3X4,	// mat3x4
507 		TYPE_FLOAT_MAT4X2,	// mat4x2
508 		TYPE_FLOAT_MAT4X3,	// mat4x3
509 		TYPE_FLOAT_MAT4,	// mat4
510 		TYPE_FLOAT,			// double
511 		TYPE_FLOAT_VEC2,	// dvec2
512 		TYPE_FLOAT_VEC3,	// dvec3
513 		TYPE_FLOAT_VEC4,	// dvec4
514 		TYPE_FLOAT_MAT2,	// dmat2
515 		TYPE_FLOAT_MAT2X3,	// dmat2x3
516 		TYPE_FLOAT_MAT2X4,	// dmat2x4
517 		TYPE_FLOAT_MAT3X2,	// dmat3x2
518 		TYPE_FLOAT_MAT3,	// dmat3
519 		TYPE_FLOAT_MAT3X4,	// dmat3x4
520 		TYPE_FLOAT_MAT4X2,	// dmat4x2
521 		TYPE_FLOAT_MAT4X3,	// dmat4x3
522 		TYPE_FLOAT_MAT4,	// dmat4
523 		TYPE_FLOAT,			// int
524 		TYPE_FLOAT_VEC2,	// ivec2
525 		TYPE_FLOAT_VEC3,	// ivec3
526 		TYPE_FLOAT_VEC4,	// ivec4
527 		TYPE_FLOAT,			// uint
528 		TYPE_FLOAT_VEC2,	// uvec2
529 		TYPE_FLOAT_VEC3,	// uvec3
530 		TYPE_FLOAT_VEC4,	// uvec4
531 		TYPE_FLOAT,			// bool
532 		TYPE_FLOAT_VEC2,	// bvec2
533 		TYPE_FLOAT_VEC3,	// bvec3
534 		TYPE_FLOAT_VEC4,	// bvec4
535 		TYPE_INVALID,		// sampler1D
536 		TYPE_INVALID,		// sampler2D
537 		TYPE_INVALID,		// samplerCube
538 		TYPE_INVALID,		// sampler1DArray
539 		TYPE_INVALID,		// sampler2DArray
540 		TYPE_INVALID,		// sampler3D
541 		TYPE_INVALID,		// samplerCubeArray
542 		TYPE_INVALID,		// sampler1DShadow
543 		TYPE_INVALID,		// sampler2DShadow
544 		TYPE_INVALID,		// samplerCubeShadow
545 		TYPE_INVALID,		// sampler1DArrayShadow
546 		TYPE_INVALID,		// sampler2DArrayShadow
547 		TYPE_INVALID,		// samplerCubeArrayShadow
548 		TYPE_INVALID,		// isampler1D
549 		TYPE_INVALID,		// isampler2D
550 		TYPE_INVALID,		// isamplerCube
551 		TYPE_INVALID,		// isampler1DArray
552 		TYPE_INVALID,		// isampler2DArray
553 		TYPE_INVALID,		// isampler3D
554 		TYPE_INVALID,		// isamplerCubeArray
555 		TYPE_INVALID,		// usampler1D
556 		TYPE_INVALID,		// usampler2D
557 		TYPE_INVALID,		// usamplerCube
558 		TYPE_INVALID,		// usampler1DArray
559 		TYPE_INVALID,		// usampler2DArray
560 		TYPE_INVALID,		// usampler3D
561 		TYPE_INVALID,		// usamplerCubeArray
562 		TYPE_INVALID,		// sampler2DMS
563 		TYPE_INVALID,		// isampler2DMS
564 		TYPE_INVALID,		// usampler2DMS
565 		TYPE_INVALID,		// image2D
566 		TYPE_INVALID,		// imageCube
567 		TYPE_INVALID,		// image2DArray
568 		TYPE_INVALID,		// image3D
569 		TYPE_INVALID,		// imageCubeArray
570 		TYPE_INVALID,		// iimage2D
571 		TYPE_INVALID,		// iimageCube
572 		TYPE_INVALID,		// iimage2DArray
573 		TYPE_INVALID,		// iimage3D
574 		TYPE_INVALID,		// iimageCubeArray
575 		TYPE_INVALID,		// uimage2D
576 		TYPE_INVALID,		// uimageCube
577 		TYPE_INVALID,		// uimage2DArray
578 		TYPE_INVALID,		// uimage3D
579 		TYPE_INVALID,		// uimageCubeArray
580 		TYPE_INVALID,		// atomic_uint
581 		TYPE_INVALID,		// samplerBuffer
582 		TYPE_INVALID,		// isamplerBuffer
583 		TYPE_INVALID,		// usamplerBuffer
584 		TYPE_INVALID,		// sampler2DMSArray
585 		TYPE_INVALID,		// isampler2DMSArray
586 		TYPE_INVALID,		// usampler2DMSArray
587 		TYPE_INVALID,		// imageBuffer
588 		TYPE_INVALID,		// iimageBuffer
589 		TYPE_INVALID,		// uimageBuffer
590 	};
591 
592 	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_floatTypes) == TYPE_LAST);
593 	DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_floatTypes)));
594 	return s_floatTypes[(int)dataType];
595 }
596 
getDataTypeDoubleScalars(DataType dataType)597 DataType getDataTypeDoubleScalars (DataType dataType)
598 {
599 	static const DataType s_doubleTypes[] =
600 	{
601 		TYPE_INVALID,		// invalid
602 		TYPE_DOUBLE,		// float
603 		TYPE_DOUBLE_VEC2,	// vec2
604 		TYPE_DOUBLE_VEC3,	// vec3
605 		TYPE_DOUBLE_VEC4,	// vec4
606 		TYPE_DOUBLE_MAT2,	// mat2
607 		TYPE_DOUBLE_MAT2X3,	// mat2x3
608 		TYPE_DOUBLE_MAT2X4,	// mat2x4
609 		TYPE_DOUBLE_MAT3X2,	// mat3x2
610 		TYPE_DOUBLE_MAT3,	// mat3
611 		TYPE_DOUBLE_MAT3X4,	// mat3x4
612 		TYPE_DOUBLE_MAT4X2,	// mat4x2
613 		TYPE_DOUBLE_MAT4X3,	// mat4x3
614 		TYPE_DOUBLE_MAT4,	// mat4
615 		TYPE_DOUBLE,		// double
616 		TYPE_DOUBLE_VEC2,	// dvec2
617 		TYPE_DOUBLE_VEC3,	// dvec3
618 		TYPE_DOUBLE_VEC4,	// dvec4
619 		TYPE_DOUBLE_MAT2,	// dmat2
620 		TYPE_DOUBLE_MAT2X3,	// dmat2x3
621 		TYPE_DOUBLE_MAT2X4,	// dmat2x4
622 		TYPE_DOUBLE_MAT3X2,	// dmat3x2
623 		TYPE_DOUBLE_MAT3,	// dmat3
624 		TYPE_DOUBLE_MAT3X4,	// dmat3x4
625 		TYPE_DOUBLE_MAT4X2,	// dmat4x2
626 		TYPE_DOUBLE_MAT4X3,	// dmat4x3
627 		TYPE_DOUBLE_MAT4,	// dmat4
628 		TYPE_DOUBLE,		// int
629 		TYPE_DOUBLE_VEC2,	// ivec2
630 		TYPE_DOUBLE_VEC3,	// ivec3
631 		TYPE_DOUBLE_VEC4,	// ivec4
632 		TYPE_DOUBLE,		// uint
633 		TYPE_DOUBLE_VEC2,	// uvec2
634 		TYPE_DOUBLE_VEC3,	// uvec3
635 		TYPE_DOUBLE_VEC4,	// uvec4
636 		TYPE_DOUBLE,		// bool
637 		TYPE_DOUBLE_VEC2,	// bvec2
638 		TYPE_DOUBLE_VEC3,	// bvec3
639 		TYPE_DOUBLE_VEC4,	// bvec4
640 		TYPE_INVALID,		// sampler1D
641 		TYPE_INVALID,		// sampler2D
642 		TYPE_INVALID,		// samplerCube
643 		TYPE_INVALID,		// sampler1DArray
644 		TYPE_INVALID,		// sampler2DArray
645 		TYPE_INVALID,		// sampler3D
646 		TYPE_INVALID,		// samplerCubeArray
647 		TYPE_INVALID,		// sampler1DShadow
648 		TYPE_INVALID,		// sampler2DShadow
649 		TYPE_INVALID,		// samplerCubeShadow
650 		TYPE_INVALID,		// sampler1DArrayShadow
651 		TYPE_INVALID,		// sampler2DArrayShadow
652 		TYPE_INVALID,		// samplerCubeArrayShadow
653 		TYPE_INVALID,		// isampler1D
654 		TYPE_INVALID,		// isampler2D
655 		TYPE_INVALID,		// isamplerCube
656 		TYPE_INVALID,		// isampler1DArray
657 		TYPE_INVALID,		// isampler2DArray
658 		TYPE_INVALID,		// isampler3D
659 		TYPE_INVALID,		// isamplerCubeArray
660 		TYPE_INVALID,		// usampler1D
661 		TYPE_INVALID,		// usampler2D
662 		TYPE_INVALID,		// usamplerCube
663 		TYPE_INVALID,		// usampler1DArray
664 		TYPE_INVALID,		// usampler2DArray
665 		TYPE_INVALID,		// usampler3D
666 		TYPE_INVALID,		// usamplerCubeArray
667 		TYPE_INVALID,		// sampler2DMS
668 		TYPE_INVALID,		// isampler2DMS
669 		TYPE_INVALID,		// usampler2DMS
670 		TYPE_INVALID,		// image2D
671 		TYPE_INVALID,		// imageCube
672 		TYPE_INVALID,		// image2DArray
673 		TYPE_INVALID,		// image3D
674 		TYPE_INVALID,		// imageCubeArray
675 		TYPE_INVALID,		// iimage2D
676 		TYPE_INVALID,		// iimageCube
677 		TYPE_INVALID,		// iimage2DArray
678 		TYPE_INVALID,		// iimage3D
679 		TYPE_INVALID,		// iimageCubeArray
680 		TYPE_INVALID,		// uimage2D
681 		TYPE_INVALID,		// uimageCube
682 		TYPE_INVALID,		// uimage2DArray
683 		TYPE_INVALID,		// uimage3D
684 		TYPE_INVALID,		// uimageCubeArray
685 		TYPE_INVALID,		// atomic_uint
686 		TYPE_INVALID,		// samplerBuffer
687 		TYPE_INVALID,		// isamplerBuffer
688 		TYPE_INVALID,		// usamplerBuffer
689 		TYPE_INVALID,		// sampler2DMSArray
690 		TYPE_INVALID,		// isampler2DMSArray
691 		TYPE_INVALID,		// usampler2DMSArray
692 		TYPE_INVALID,		// imageBuffer
693 		TYPE_INVALID,		// iimageBuffer
694 		TYPE_INVALID,		// uimageBuffer
695 	};
696 
697 	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_doubleTypes) == TYPE_LAST);
698 	DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_doubleTypes)));
699 	return s_doubleTypes[(int)dataType];
700 }
701 
getDataTypeVector(DataType scalarType,int size)702 DataType getDataTypeVector (DataType scalarType, int size)
703 {
704 	DE_ASSERT(deInRange32(size, 1, 4));
705 	switch (scalarType)
706 	{
707 		case TYPE_FLOAT:
708 		case TYPE_DOUBLE:
709 		case TYPE_INT:
710 		case TYPE_UINT:
711 		case TYPE_BOOL:
712 			return (DataType)((int)scalarType + size - 1);
713 		default:
714 			return TYPE_INVALID;
715 	}
716 }
717 
getDataTypeFloatVec(int vecSize)718 DataType getDataTypeFloatVec (int vecSize)
719 {
720 	return getDataTypeVector(TYPE_FLOAT, vecSize);
721 }
722 
getDataTypeIntVec(int vecSize)723 DataType getDataTypeIntVec (int vecSize)
724 {
725 	return getDataTypeVector(TYPE_INT, vecSize);
726 }
727 
getDataTypeUintVec(int vecSize)728 DataType getDataTypeUintVec (int vecSize)
729 {
730 	return getDataTypeVector(TYPE_UINT, vecSize);
731 }
732 
getDataTypeBoolVec(int vecSize)733 DataType getDataTypeBoolVec (int vecSize)
734 {
735 	return getDataTypeVector(TYPE_BOOL, vecSize);
736 }
737 
getDataTypeMatrix(int numCols,int numRows)738 DataType getDataTypeMatrix (int numCols, int numRows)
739 {
740 	DE_ASSERT(de::inRange(numCols, 2, 4) && de::inRange(numRows, 2, 4));
741 	return (DataType)((int)TYPE_FLOAT_MAT2 + (numCols-2)*3 + (numRows-2));
742 }
743 
getDataTypeMatrixNumRows(DataType dataType)744 int getDataTypeMatrixNumRows (DataType dataType)
745 {
746 	switch (dataType)
747 	{
748 		case TYPE_FLOAT_MAT2:		return 2;
749 		case TYPE_FLOAT_MAT2X3:		return 3;
750 		case TYPE_FLOAT_MAT2X4:		return 4;
751 		case TYPE_FLOAT_MAT3X2:		return 2;
752 		case TYPE_FLOAT_MAT3:		return 3;
753 		case TYPE_FLOAT_MAT3X4:		return 4;
754 		case TYPE_FLOAT_MAT4X2:		return 2;
755 		case TYPE_FLOAT_MAT4X3:		return 3;
756 		case TYPE_FLOAT_MAT4:		return 4;
757 		case TYPE_DOUBLE_MAT2:		return 2;
758 		case TYPE_DOUBLE_MAT2X3:	return 3;
759 		case TYPE_DOUBLE_MAT2X4:	return 4;
760 		case TYPE_DOUBLE_MAT3X2:	return 2;
761 		case TYPE_DOUBLE_MAT3:		return 3;
762 		case TYPE_DOUBLE_MAT3X4:	return 4;
763 		case TYPE_DOUBLE_MAT4X2:	return 2;
764 		case TYPE_DOUBLE_MAT4X3:	return 3;
765 		case TYPE_DOUBLE_MAT4:		return 4;
766 		default:
767 			DE_ASSERT(false);
768 			return 0;
769 	}
770 }
771 
getDataTypeMatrixNumColumns(DataType dataType)772 int getDataTypeMatrixNumColumns (DataType dataType)
773 {
774 	switch (dataType)
775 	{
776 		case TYPE_FLOAT_MAT2:		return 2;
777 		case TYPE_FLOAT_MAT2X3:		return 2;
778 		case TYPE_FLOAT_MAT2X4:		return 2;
779 		case TYPE_FLOAT_MAT3X2:		return 3;
780 		case TYPE_FLOAT_MAT3:		return 3;
781 		case TYPE_FLOAT_MAT3X4:		return 3;
782 		case TYPE_FLOAT_MAT4X2:		return 4;
783 		case TYPE_FLOAT_MAT4X3:		return 4;
784 		case TYPE_FLOAT_MAT4:		return 4;
785 		case TYPE_DOUBLE_MAT2:		return 2;
786 		case TYPE_DOUBLE_MAT2X3:	return 2;
787 		case TYPE_DOUBLE_MAT2X4:	return 2;
788 		case TYPE_DOUBLE_MAT3X2:	return 3;
789 		case TYPE_DOUBLE_MAT3:		return 3;
790 		case TYPE_DOUBLE_MAT3X4:	return 3;
791 		case TYPE_DOUBLE_MAT4X2:	return 4;
792 		case TYPE_DOUBLE_MAT4X3:	return 4;
793 		case TYPE_DOUBLE_MAT4:		return 4;
794 		default:
795 			DE_ASSERT(false);
796 			return 0;
797 	}
798 }
799 
getDataTypeNumLocations(DataType dataType)800 int	getDataTypeNumLocations	(DataType dataType)
801 {
802 	if (isDataTypeScalarOrVector(dataType))
803 		return 1;
804 	else if (isDataTypeMatrix(dataType))
805 		return getDataTypeMatrixNumColumns(dataType);
806 
807 	DE_FATAL("Illegal datatype.");
808 	return 0;
809 }
810 
getDataTypeNumComponents(DataType dataType)811 int	getDataTypeNumComponents (DataType dataType)
812 {
813 	if (isDataTypeScalarOrVector(dataType))
814 		return getDataTypeScalarSize(dataType);
815 	else if (isDataTypeMatrix(dataType))
816 		return getDataTypeMatrixNumRows(dataType);
817 
818 	DE_FATAL("Illegal datatype.");
819 	return 0;
820 }
821 
getDataTypeFromGLType(deUint32 glType)822 DataType getDataTypeFromGLType (deUint32 glType)
823 {
824 	switch (glType)
825 	{
826 		case GL_FLOAT:										return TYPE_FLOAT;
827 		case GL_FLOAT_VEC2:									return TYPE_FLOAT_VEC2;
828 		case GL_FLOAT_VEC3:									return TYPE_FLOAT_VEC3;
829 		case GL_FLOAT_VEC4:									return TYPE_FLOAT_VEC4;
830 
831 		case GL_FLOAT_MAT2:									return TYPE_FLOAT_MAT2;
832 		case GL_FLOAT_MAT2x3:								return TYPE_FLOAT_MAT2X3;
833 		case GL_FLOAT_MAT2x4:								return TYPE_FLOAT_MAT2X4;
834 
835 		case GL_FLOAT_MAT3x2:								return TYPE_FLOAT_MAT3X2;
836 		case GL_FLOAT_MAT3:									return TYPE_FLOAT_MAT3;
837 		case GL_FLOAT_MAT3x4:								return TYPE_FLOAT_MAT3X4;
838 
839 		case GL_FLOAT_MAT4x2:								return TYPE_FLOAT_MAT4X2;
840 		case GL_FLOAT_MAT4x3:								return TYPE_FLOAT_MAT4X3;
841 		case GL_FLOAT_MAT4:									return TYPE_FLOAT_MAT4;
842 
843 		case GL_DOUBLE:										return TYPE_DOUBLE;
844 		case GL_DOUBLE_VEC2:								return TYPE_DOUBLE_VEC2;
845 		case GL_DOUBLE_VEC3:								return TYPE_DOUBLE_VEC3;
846 		case GL_DOUBLE_VEC4:								return TYPE_DOUBLE_VEC4;
847 
848 		case GL_DOUBLE_MAT2:								return TYPE_DOUBLE_MAT2;
849 		case GL_DOUBLE_MAT2x3:								return TYPE_DOUBLE_MAT2X3;
850 		case GL_DOUBLE_MAT2x4:								return TYPE_DOUBLE_MAT2X4;
851 
852 		case GL_DOUBLE_MAT3x2:								return TYPE_DOUBLE_MAT3X2;
853 		case GL_DOUBLE_MAT3:								return TYPE_DOUBLE_MAT3;
854 		case GL_DOUBLE_MAT3x4:								return TYPE_DOUBLE_MAT3X4;
855 
856 		case GL_DOUBLE_MAT4x2:								return TYPE_DOUBLE_MAT4X2;
857 		case GL_DOUBLE_MAT4x3:								return TYPE_DOUBLE_MAT4X3;
858 		case GL_DOUBLE_MAT4:								return TYPE_DOUBLE_MAT4;
859 
860 		case GL_INT:										return TYPE_INT;
861 		case GL_INT_VEC2:									return TYPE_INT_VEC2;
862 		case GL_INT_VEC3:									return TYPE_INT_VEC3;
863 		case GL_INT_VEC4:									return TYPE_INT_VEC4;
864 
865 		case GL_UNSIGNED_INT:								return TYPE_UINT;
866 		case GL_UNSIGNED_INT_VEC2:							return TYPE_UINT_VEC2;
867 		case GL_UNSIGNED_INT_VEC3:							return TYPE_UINT_VEC3;
868 		case GL_UNSIGNED_INT_VEC4:							return TYPE_UINT_VEC4;
869 
870 		case GL_BOOL:										return TYPE_BOOL;
871 		case GL_BOOL_VEC2:									return TYPE_BOOL_VEC2;
872 		case GL_BOOL_VEC3:									return TYPE_BOOL_VEC3;
873 		case GL_BOOL_VEC4:									return TYPE_BOOL_VEC4;
874 
875 		case GL_SAMPLER_1D:									return TYPE_SAMPLER_1D;
876 		case GL_SAMPLER_2D:									return TYPE_SAMPLER_2D;
877 		case GL_SAMPLER_CUBE:								return TYPE_SAMPLER_CUBE;
878 		case GL_SAMPLER_1D_ARRAY:							return TYPE_SAMPLER_1D_ARRAY;
879 		case GL_SAMPLER_2D_ARRAY:							return TYPE_SAMPLER_2D_ARRAY;
880 		case GL_SAMPLER_3D:									return TYPE_SAMPLER_3D;
881 		case GL_SAMPLER_CUBE_MAP_ARRAY:						return TYPE_SAMPLER_CUBE_ARRAY;
882 
883 		case GL_SAMPLER_1D_SHADOW:							return TYPE_SAMPLER_1D_SHADOW;
884 		case GL_SAMPLER_2D_SHADOW:							return TYPE_SAMPLER_2D_SHADOW;
885 		case GL_SAMPLER_CUBE_SHADOW:						return TYPE_SAMPLER_CUBE_SHADOW;
886 		case GL_SAMPLER_1D_ARRAY_SHADOW:					return TYPE_SAMPLER_1D_ARRAY_SHADOW;
887 		case GL_SAMPLER_2D_ARRAY_SHADOW:					return TYPE_SAMPLER_2D_ARRAY_SHADOW;
888 		case GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW:				return TYPE_SAMPLER_CUBE_ARRAY_SHADOW;
889 
890 		case GL_INT_SAMPLER_1D:								return TYPE_INT_SAMPLER_1D;
891 		case GL_INT_SAMPLER_2D:								return TYPE_INT_SAMPLER_2D;
892 		case GL_INT_SAMPLER_CUBE:							return TYPE_INT_SAMPLER_CUBE;
893 		case GL_INT_SAMPLER_1D_ARRAY:						return TYPE_INT_SAMPLER_1D_ARRAY;
894 		case GL_INT_SAMPLER_2D_ARRAY:						return TYPE_INT_SAMPLER_2D_ARRAY;
895 		case GL_INT_SAMPLER_3D:								return TYPE_INT_SAMPLER_3D;
896 		case GL_INT_SAMPLER_CUBE_MAP_ARRAY:					return TYPE_INT_SAMPLER_CUBE_ARRAY;
897 
898 		case GL_UNSIGNED_INT_SAMPLER_1D:					return TYPE_UINT_SAMPLER_1D;
899 		case GL_UNSIGNED_INT_SAMPLER_2D:					return TYPE_UINT_SAMPLER_2D;
900 		case GL_UNSIGNED_INT_SAMPLER_CUBE:					return TYPE_UINT_SAMPLER_CUBE;
901 		case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY:				return TYPE_UINT_SAMPLER_1D_ARRAY;
902 		case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:				return TYPE_UINT_SAMPLER_2D_ARRAY;
903 		case GL_UNSIGNED_INT_SAMPLER_3D:					return TYPE_UINT_SAMPLER_3D;
904 		case GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY:		return TYPE_UINT_SAMPLER_CUBE_ARRAY;
905 
906 		case GL_SAMPLER_2D_MULTISAMPLE:						return TYPE_SAMPLER_2D_MULTISAMPLE;
907 		case GL_INT_SAMPLER_2D_MULTISAMPLE:					return TYPE_INT_SAMPLER_2D_MULTISAMPLE;
908 		case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:		return TYPE_UINT_SAMPLER_2D_MULTISAMPLE;
909 
910 		case GL_IMAGE_2D:									return TYPE_IMAGE_2D;
911 		case GL_IMAGE_CUBE:									return TYPE_IMAGE_CUBE;
912 		case GL_IMAGE_2D_ARRAY:								return TYPE_IMAGE_2D_ARRAY;
913 		case GL_IMAGE_3D:									return TYPE_IMAGE_3D;
914 		case GL_INT_IMAGE_2D:								return TYPE_INT_IMAGE_2D;
915 		case GL_INT_IMAGE_CUBE:								return TYPE_INT_IMAGE_CUBE;
916 		case GL_INT_IMAGE_2D_ARRAY:							return TYPE_INT_IMAGE_2D_ARRAY;
917 		case GL_INT_IMAGE_3D:								return TYPE_INT_IMAGE_3D;
918 		case GL_UNSIGNED_INT_IMAGE_2D:						return TYPE_UINT_IMAGE_2D;
919 		case GL_UNSIGNED_INT_IMAGE_CUBE:					return TYPE_UINT_IMAGE_CUBE;
920 		case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:				return TYPE_UINT_IMAGE_2D_ARRAY;
921 		case GL_UNSIGNED_INT_IMAGE_3D:						return TYPE_UINT_IMAGE_3D;
922 
923 		case GL_UNSIGNED_INT_ATOMIC_COUNTER:				return TYPE_UINT_ATOMIC_COUNTER;
924 
925 		case GL_SAMPLER_BUFFER:								return TYPE_SAMPLER_BUFFER;
926 		case GL_INT_SAMPLER_BUFFER:							return TYPE_INT_SAMPLER_BUFFER;
927 		case GL_UNSIGNED_INT_SAMPLER_BUFFER:				return TYPE_UINT_SAMPLER_BUFFER;
928 
929 		case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:				return TYPE_SAMPLER_2D_MULTISAMPLE_ARRAY;
930 		case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:			return TYPE_INT_SAMPLER_2D_MULTISAMPLE_ARRAY;
931 		case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:	return TYPE_UINT_SAMPLER_2D_MULTISAMPLE_ARRAY;
932 
933 		case GL_IMAGE_BUFFER:								return TYPE_IMAGE_BUFFER;
934 		case GL_INT_IMAGE_BUFFER:							return TYPE_INT_IMAGE_BUFFER;
935 		case GL_UNSIGNED_INT_IMAGE_BUFFER:					return TYPE_UINT_IMAGE_BUFFER;
936 
937 		default:
938 			return TYPE_LAST;
939 	}
940 }
941 
942 } // glu
943