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 	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 	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 	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 		"int",
196 		"ivec2",
197 		"ivec3",
198 		"ivec4",
199 		"uint",
200 		"uvec2",
201 		"uvec3",
202 		"uvec4",
203 		"bool",
204 		"bvec2",
205 		"bvec3",
206 		"bvec4",
207 		"sampler1D",
208 		"sampler2D",
209 		"samplerCube",
210 		"sampler2DArray",
211 		"sampler3D",
212 		"samplerCubeArray",
213 		"sampler1DShadow",
214 		"sampler2DShadow",
215 		"samplerCubeShadow",
216 		"sampler2DArrayShadow",
217 		"samplerCubeArrayShadow",
218 		"isampler1D",
219 		"isampler2D",
220 		"isamplerCube",
221 		"isampler2DArray",
222 		"isampler3D",
223 		"isamplerCubeArray",
224 		"usampler1D",
225 		"usampler2D",
226 		"usamplerCube",
227 		"usampler2DArray",
228 		"usampler3D",
229 		"usamplerCubeArray",
230 		"sampler2DMS",
231 		"isampler2DMS",
232 		"usampler2DMS",
233 		"image2D",
234 		"imageCube",
235 		"image2DArray",
236 		"image3D",
237 		"imageCubeArray",
238 		"iimage2D",
239 		"iimageCube",
240 		"iimage2DArray",
241 		"iimage3D",
242 		"iimageCubeArray",
243 		"uimage2D",
244 		"uimageCube",
245 		"uimage2DArray",
246 		"uimage3D",
247 		"uimageCubeArray",
248 		"atomic_uint",
249 		"samplerBuffer",
250 		"isamplerBuffer",
251 		"usamplerBuffer",
252 		"sampler2DMSArray",
253 		"isampler2DMSArray",
254 		"usampler2DMSArray",
255 		"imageBuffer",
256 		"iimageBuffer",
257 		"uimageBuffer",
258 	};
259 
260 	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_names) == TYPE_LAST);
261 	DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_names)));
262 	return s_names[(int)dataType];
263 }
264 
getDataTypeScalarSize(DataType dataType)265 int getDataTypeScalarSize (DataType dataType)
266 {
267 	const int s_sizes[] =
268 	{
269 		-1,		// invalid
270 		1,		// float
271 		2,		// vec2
272 		3,		// vec3
273 		4,		// vec4
274 		4,		// mat2
275 		6,		// mat2x3
276 		8,		// mat2x4
277 		6,		// mat3x2
278 		9,		// mat3
279 		12,		// mat3x4
280 		8,		// mat4x2
281 		12,		// mat4x3
282 		16,		// mat4
283 		1,		// int
284 		2,		// ivec2
285 		3,		// ivec3
286 		4,		// ivec4
287 		1,		// uint
288 		2,		// uvec2
289 		3,		// uvec3
290 		4,		// uvec4
291 		1,		// bool
292 		2,		// bvec2
293 		3,		// bvec3
294 		4,		// bvec4
295 		1,		// sampler1D
296 		1,		// sampler2D
297 		1,		// samplerCube
298 		1,		// sampler2DArray
299 		1,		// sampler3D
300 		1,		// samplerCubeArray
301 		1,		// sampler1DShadow
302 		1,		// sampler2DShadow
303 		1,		// samplerCubeShadow
304 		1,		// sampler2DArrayShadow
305 		1,		// samplerCubeArrayShadow
306 		1,		// isampler1D
307 		1,		// isampler2D
308 		1,		// isamplerCube
309 		1,		// isampler2DArray
310 		1,		// isampler3D
311 		1,		// isamplerCubeArray
312 		1,		// usampler1D
313 		1,		// usampler2D
314 		1,		// usamplerCube
315 		1,		// usampler2DArray
316 		1,		// usampler3D
317 		1,		// usamplerCubeArray
318 		1,		// sampler2DMS
319 		1,		// isampler2DMS
320 		1,		// usampler2DMS
321 		1,		// image2D
322 		1,		// imageCube
323 		1,		// image2DArray
324 		1,		// image3D
325 		1,		// imageCubeArray
326 		1,		// iimage2D
327 		1,		// iimageCube
328 		1,		// iimage2DArray
329 		1,		// iimage3D
330 		1,		// iimageCubeArray
331 		1,		// uimage2D
332 		1,		// uimageCube
333 		1,		// uimage2DArray
334 		1,		// uimage3D
335 		1,		// uimageCubeArray
336 		1,		// atomic_uint
337 		1,		// samplerBuffer
338 		1,		// isamplerBuffer
339 		1,		// usamplerBuffer
340 		1,		// sampler2DMSArray
341 		1,		// isampler2DMSArray
342 		1,		// usampler2DMSArray
343 		1,		// imageBuffer
344 		1,		// iimageBuffer
345 		1,		// uimageBuffer
346 	};
347 
348 	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_sizes) == TYPE_LAST);
349 	DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_sizes)));
350 	return s_sizes[(int)dataType];
351 }
352 
getDataTypeScalarType(DataType dataType)353 DataType getDataTypeScalarType (DataType dataType)
354 {
355 	const DataType s_scalarTypes[] =
356 	{
357 		TYPE_INVALID,							// invalid
358 		TYPE_FLOAT,								// float
359 		TYPE_FLOAT,								// vec2
360 		TYPE_FLOAT,								// vec3
361 		TYPE_FLOAT,								// vec4
362 		TYPE_FLOAT,								// mat2
363 		TYPE_FLOAT,								// mat2x3
364 		TYPE_FLOAT,								// mat2x4
365 		TYPE_FLOAT,								// mat3x2
366 		TYPE_FLOAT,								// mat3
367 		TYPE_FLOAT,								// mat3x4
368 		TYPE_FLOAT,								// mat4x2
369 		TYPE_FLOAT,								// mat4x3
370 		TYPE_FLOAT,								// mat4
371 		TYPE_INT,								// int
372 		TYPE_INT,								// ivec2
373 		TYPE_INT,								// ivec3
374 		TYPE_INT,								// ivec4
375 		TYPE_UINT,								// uint
376 		TYPE_UINT,								// uvec2
377 		TYPE_UINT,								// uvec3
378 		TYPE_UINT,								// uvec4
379 		TYPE_BOOL,								// bool
380 		TYPE_BOOL,								// bvec2
381 		TYPE_BOOL,								// bvec3
382 		TYPE_BOOL,								// bvec4
383 		TYPE_SAMPLER_1D,						// sampler1D
384 		TYPE_SAMPLER_2D,						// sampler2D
385 		TYPE_SAMPLER_CUBE,						// samplerCube
386 		TYPE_SAMPLER_2D_ARRAY,					// sampler2DArray
387 		TYPE_SAMPLER_3D,						// sampler3D
388 		TYPE_SAMPLER_CUBE_ARRAY,				// samplerCubeArray
389 		TYPE_SAMPLER_1D_SHADOW,					// sampler1DShadow
390 		TYPE_SAMPLER_2D_SHADOW,					// sampler2DShadow
391 		TYPE_SAMPLER_CUBE_SHADOW,				// samplerCubeShadow
392 		TYPE_SAMPLER_2D_ARRAY_SHADOW,			// sampler2DArrayShadow
393 		TYPE_SAMPLER_CUBE_ARRAY_SHADOW,			// samplerCubeArrayShadow
394 		TYPE_INT_SAMPLER_1D,					// isampler1D
395 		TYPE_INT_SAMPLER_2D,					// isampler2D
396 		TYPE_INT_SAMPLER_CUBE,					// isamplerCube
397 		TYPE_INT_SAMPLER_2D_ARRAY,				// isampler2DArray
398 		TYPE_INT_SAMPLER_3D,					// isampler3D
399 		TYPE_INT_SAMPLER_CUBE_ARRAY,			// isamplerCubeArray
400 		TYPE_UINT_SAMPLER_1D,					// usampler1D
401 		TYPE_UINT_SAMPLER_2D,					// usampler2D
402 		TYPE_UINT_SAMPLER_CUBE,					// usamplerCube
403 		TYPE_UINT_SAMPLER_2D_ARRAY,				// usampler2DArray
404 		TYPE_UINT_SAMPLER_3D,					// usampler3D
405 		TYPE_UINT_SAMPLER_CUBE_ARRAY,			// usamplerCubeArray
406 		TYPE_SAMPLER_2D_MULTISAMPLE,			// sampler2DMS
407 		TYPE_INT_SAMPLER_2D_MULTISAMPLE,		// isampler2DMS
408 		TYPE_UINT_SAMPLER_2D_MULTISAMPLE,		// usampler2DMS
409 		TYPE_IMAGE_2D,							// image2D
410 		TYPE_IMAGE_CUBE,						// imageCube
411 		TYPE_IMAGE_2D_ARRAY,					// image2DArray
412 		TYPE_IMAGE_3D,							// image3D
413 		TYPE_IMAGE_CUBE_ARRAY,					// imageCubeArray
414 		TYPE_INT_IMAGE_2D,						// iimage2D
415 		TYPE_INT_IMAGE_CUBE,					// iimageCube
416 		TYPE_INT_IMAGE_2D_ARRAY,				// iimage2DArray
417 		TYPE_INT_IMAGE_3D,						// iimage3D
418 		TYPE_INT_IMAGE_CUBE_ARRAY,				// iimageCubeArray
419 		TYPE_UINT_IMAGE_2D,						// uimage2D
420 		TYPE_UINT_IMAGE_CUBE,					// uimageCube
421 		TYPE_UINT_IMAGE_2D_ARRAY,				// uimage2DArray
422 		TYPE_UINT_IMAGE_3D,						// uimage3D
423 		TYPE_UINT_IMAGE_CUBE_ARRAY,				// uimageCubeArray
424 		TYPE_UINT_ATOMIC_COUNTER,				// atomic_uint
425 		TYPE_SAMPLER_BUFFER,					// samplerBuffer
426 		TYPE_INT_SAMPLER_BUFFER,				// isamplerBuffer
427 		TYPE_UINT_SAMPLER_BUFFER,				// usamplerBuffer
428 		TYPE_SAMPLER_2D_MULTISAMPLE_ARRAY,		// sampler2DMSArray
429 		TYPE_INT_SAMPLER_2D_MULTISAMPLE_ARRAY,	// isampler2DMSArray
430 		TYPE_UINT_SAMPLER_2D_MULTISAMPLE_ARRAY,	// usampler2DMSArray
431 		TYPE_IMAGE_BUFFER,						// imageBuffer
432 		TYPE_INT_IMAGE_BUFFER,					// iimageBuffer
433 		TYPE_UINT_IMAGE_BUFFER,					// uimageBuffer
434 	};
435 
436 	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_scalarTypes) == TYPE_LAST);
437 	DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_scalarTypes)));
438 	return s_scalarTypes[(int)dataType];
439 }
440 
getDataTypeFloatScalars(DataType dataType)441 DataType getDataTypeFloatScalars (DataType dataType)
442 {
443 	const DataType s_floatTypes[] =
444 	{
445 		TYPE_INVALID,		// invalid
446 		TYPE_FLOAT,			// float
447 		TYPE_FLOAT_VEC2,	// vec2
448 		TYPE_FLOAT_VEC3,	// vec3
449 		TYPE_FLOAT_VEC4,	// vec4
450 		TYPE_FLOAT_MAT2,	// mat2
451 		TYPE_FLOAT_MAT2X3,	// mat2x3
452 		TYPE_FLOAT_MAT2X4,	// mat2x4
453 		TYPE_FLOAT_MAT3X2,	// mat3x2
454 		TYPE_FLOAT_MAT3,	// mat3
455 		TYPE_FLOAT_MAT3X4,	// mat3x4
456 		TYPE_FLOAT_MAT4X2,	// mat4x2
457 		TYPE_FLOAT_MAT4X3,	// mat4x3
458 		TYPE_FLOAT_MAT4,	// mat4
459 		TYPE_FLOAT,			// int
460 		TYPE_FLOAT_VEC2,	// ivec2
461 		TYPE_FLOAT_VEC3,	// ivec3
462 		TYPE_FLOAT_VEC4,	// ivec4
463 		TYPE_FLOAT,			// uint
464 		TYPE_FLOAT_VEC2,	// uvec2
465 		TYPE_FLOAT_VEC3,	// uvec3
466 		TYPE_FLOAT_VEC4,	// uvec4
467 		TYPE_FLOAT,			// bool
468 		TYPE_FLOAT_VEC2,	// bvec2
469 		TYPE_FLOAT_VEC3,	// bvec3
470 		TYPE_FLOAT_VEC4,	// bvec4
471 		TYPE_INVALID,		// sampler1D
472 		TYPE_INVALID,		// sampler2D
473 		TYPE_INVALID,		// samplerCube
474 		TYPE_INVALID,		// sampler2DArray
475 		TYPE_INVALID,		// sampler3D
476 		TYPE_INVALID,		// samplerCubeArray
477 		TYPE_INVALID,		// sampler1DShadow
478 		TYPE_INVALID,		// sampler2DShadow
479 		TYPE_INVALID,		// samplerCubeShadow
480 		TYPE_INVALID,		// sampler2DArrayShadow
481 		TYPE_INVALID,		// samplerCubeArrayShadow
482 		TYPE_INVALID,		// isampler1D
483 		TYPE_INVALID,		// isampler2D
484 		TYPE_INVALID,		// isamplerCube
485 		TYPE_INVALID,		// isampler2DArray
486 		TYPE_INVALID,		// isampler3D
487 		TYPE_INVALID,		// isamplerCubeArray
488 		TYPE_INVALID,		// usampler1D
489 		TYPE_INVALID,		// usampler2D
490 		TYPE_INVALID,		// usamplerCube
491 		TYPE_INVALID,		// usampler2DArray
492 		TYPE_INVALID,		// usampler3D
493 		TYPE_INVALID,		// usamplerCubeArray
494 		TYPE_INVALID,		// sampler2DMS
495 		TYPE_INVALID,		// isampler2DMS
496 		TYPE_INVALID,		// usampler2DMS
497 		TYPE_INVALID,		// image2D
498 		TYPE_INVALID,		// imageCube
499 		TYPE_INVALID,		// image2DArray
500 		TYPE_INVALID,		// image3D
501 		TYPE_INVALID,		// imageCubeArray
502 		TYPE_INVALID,		// iimage2D
503 		TYPE_INVALID,		// iimageCube
504 		TYPE_INVALID,		// iimage2DArray
505 		TYPE_INVALID,		// iimage3D
506 		TYPE_INVALID,		// iimageCubeArray
507 		TYPE_INVALID,		// uimage2D
508 		TYPE_INVALID,		// uimageCube
509 		TYPE_INVALID,		// uimage2DArray
510 		TYPE_INVALID,		// uimage3D
511 		TYPE_INVALID,		// uimageCubeArray
512 		TYPE_INVALID,		// atomic_uint
513 		TYPE_INVALID,		// samplerBuffer
514 		TYPE_INVALID,		// isamplerBuffer
515 		TYPE_INVALID,		// usamplerBuffer
516 		TYPE_INVALID,		// sampler2DMSArray
517 		TYPE_INVALID,		// isampler2DMSArray
518 		TYPE_INVALID,		// usampler2DMSArray
519 		TYPE_INVALID,		// imageBuffer
520 		TYPE_INVALID,		// iimageBuffer
521 		TYPE_INVALID,		// uimageBuffer
522 	};
523 
524 	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_floatTypes) == TYPE_LAST);
525 	DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_floatTypes)));
526 	return s_floatTypes[(int)dataType];
527 }
528 
getDataTypeVector(DataType scalarType,int size)529 DataType getDataTypeVector (DataType scalarType, int size)
530 {
531 	DE_ASSERT(deInRange32(size, 1, 4));
532 	switch (scalarType)
533 	{
534 		case TYPE_FLOAT:
535 		case TYPE_INT:
536 		case TYPE_UINT:
537 		case TYPE_BOOL:
538 			return (DataType)((int)scalarType + size - 1);
539 		default:
540 			return TYPE_INVALID;
541 	}
542 }
543 
getDataTypeFloatVec(int vecSize)544 DataType getDataTypeFloatVec (int vecSize)
545 {
546 	return getDataTypeVector(TYPE_FLOAT, vecSize);
547 }
548 
getDataTypeIntVec(int vecSize)549 DataType getDataTypeIntVec (int vecSize)
550 {
551 	return getDataTypeVector(TYPE_INT, vecSize);
552 }
553 
getDataTypeUintVec(int vecSize)554 DataType getDataTypeUintVec (int vecSize)
555 {
556 	return getDataTypeVector(TYPE_UINT, vecSize);
557 }
558 
getDataTypeBoolVec(int vecSize)559 DataType getDataTypeBoolVec (int vecSize)
560 {
561 	return getDataTypeVector(TYPE_BOOL, vecSize);
562 }
563 
getDataTypeMatrix(int numCols,int numRows)564 DataType getDataTypeMatrix (int numCols, int numRows)
565 {
566 	DE_ASSERT(de::inRange(numCols, 2, 4) && de::inRange(numRows, 2, 4));
567 	return (DataType)((int)TYPE_FLOAT_MAT2 + (numCols-2)*3 + (numRows-2));
568 }
569 
getDataTypeMatrixNumRows(DataType dataType)570 int getDataTypeMatrixNumRows (DataType dataType)
571 {
572 	switch (dataType)
573 	{
574 		case TYPE_FLOAT_MAT2:	return 2;
575 		case TYPE_FLOAT_MAT2X3:	return 3;
576 		case TYPE_FLOAT_MAT2X4:	return 4;
577 		case TYPE_FLOAT_MAT3X2:	return 2;
578 		case TYPE_FLOAT_MAT3:	return 3;
579 		case TYPE_FLOAT_MAT3X4:	return 4;
580 		case TYPE_FLOAT_MAT4X2:	return 2;
581 		case TYPE_FLOAT_MAT4X3:	return 3;
582 		case TYPE_FLOAT_MAT4:	return 4;
583 		default:
584 			DE_ASSERT(false);
585 			return 0;
586 	}
587 }
588 
getDataTypeMatrixNumColumns(DataType dataType)589 int getDataTypeMatrixNumColumns (DataType dataType)
590 {
591 	switch (dataType)
592 	{
593 		case TYPE_FLOAT_MAT2:	return 2;
594 		case TYPE_FLOAT_MAT2X3:	return 2;
595 		case TYPE_FLOAT_MAT2X4:	return 2;
596 		case TYPE_FLOAT_MAT3X2:	return 3;
597 		case TYPE_FLOAT_MAT3:	return 3;
598 		case TYPE_FLOAT_MAT3X4:	return 3;
599 		case TYPE_FLOAT_MAT4X2:	return 4;
600 		case TYPE_FLOAT_MAT4X3:	return 4;
601 		case TYPE_FLOAT_MAT4:	return 4;
602 		default:
603 			DE_ASSERT(false);
604 			return 0;
605 	}
606 }
607 
getDataTypeNumLocations(DataType dataType)608 int	getDataTypeNumLocations	(DataType dataType)
609 {
610 	if (isDataTypeScalarOrVector(dataType))
611 		return 1;
612 	else if (isDataTypeMatrix(dataType))
613 		return getDataTypeMatrixNumColumns(dataType);
614 
615 	DE_FATAL("Illegal datatype.");
616 	return 0;
617 }
618 
getDataTypeNumComponents(DataType dataType)619 int	getDataTypeNumComponents (DataType dataType)
620 {
621 	if (isDataTypeScalarOrVector(dataType))
622 		return getDataTypeScalarSize(dataType);
623 	else if (isDataTypeMatrix(dataType))
624 		return getDataTypeMatrixNumRows(dataType);
625 
626 	DE_FATAL("Illegal datatype.");
627 	return 0;
628 }
629 
getDataTypeFromGLType(deUint32 glType)630 DataType getDataTypeFromGLType (deUint32 glType)
631 {
632 	switch (glType)
633 	{
634 		case GL_FLOAT:										return TYPE_FLOAT;
635 		case GL_FLOAT_VEC2:									return TYPE_FLOAT_VEC2;
636 		case GL_FLOAT_VEC3:									return TYPE_FLOAT_VEC3;
637 		case GL_FLOAT_VEC4:									return TYPE_FLOAT_VEC4;
638 
639 		case GL_FLOAT_MAT2:									return TYPE_FLOAT_MAT2;
640 		case GL_FLOAT_MAT2x3:								return TYPE_FLOAT_MAT2X3;
641 		case GL_FLOAT_MAT2x4:								return TYPE_FLOAT_MAT2X4;
642 
643 		case GL_FLOAT_MAT3x2:								return TYPE_FLOAT_MAT3X2;
644 		case GL_FLOAT_MAT3:									return TYPE_FLOAT_MAT3;
645 		case GL_FLOAT_MAT3x4:								return TYPE_FLOAT_MAT3X4;
646 
647 		case GL_FLOAT_MAT4x2:								return TYPE_FLOAT_MAT4X2;
648 		case GL_FLOAT_MAT4x3:								return TYPE_FLOAT_MAT4X3;
649 		case GL_FLOAT_MAT4:									return TYPE_FLOAT_MAT4;
650 
651 		case GL_INT:										return TYPE_INT;
652 		case GL_INT_VEC2:									return TYPE_INT_VEC2;
653 		case GL_INT_VEC3:									return TYPE_INT_VEC3;
654 		case GL_INT_VEC4:									return TYPE_INT_VEC4;
655 
656 		case GL_UNSIGNED_INT:								return TYPE_UINT;
657 		case GL_UNSIGNED_INT_VEC2:							return TYPE_UINT_VEC2;
658 		case GL_UNSIGNED_INT_VEC3:							return TYPE_UINT_VEC3;
659 		case GL_UNSIGNED_INT_VEC4:							return TYPE_UINT_VEC4;
660 
661 		case GL_BOOL:										return TYPE_BOOL;
662 		case GL_BOOL_VEC2:									return TYPE_BOOL_VEC2;
663 		case GL_BOOL_VEC3:									return TYPE_BOOL_VEC3;
664 		case GL_BOOL_VEC4:									return TYPE_BOOL_VEC4;
665 
666 		case GL_SAMPLER_1D:									return TYPE_SAMPLER_1D;
667 		case GL_SAMPLER_2D:									return TYPE_SAMPLER_2D;
668 		case GL_SAMPLER_CUBE:								return TYPE_SAMPLER_CUBE;
669 		case GL_SAMPLER_2D_ARRAY:							return TYPE_SAMPLER_2D_ARRAY;
670 		case GL_SAMPLER_3D:									return TYPE_SAMPLER_3D;
671 		case GL_SAMPLER_CUBE_MAP_ARRAY:						return TYPE_SAMPLER_CUBE_ARRAY;
672 
673 		case GL_SAMPLER_1D_SHADOW:							return TYPE_SAMPLER_1D_SHADOW;
674 		case GL_SAMPLER_2D_SHADOW:							return TYPE_SAMPLER_2D_SHADOW;
675 		case GL_SAMPLER_CUBE_SHADOW:						return TYPE_SAMPLER_CUBE_SHADOW;
676 		case GL_SAMPLER_2D_ARRAY_SHADOW:					return TYPE_SAMPLER_2D_ARRAY_SHADOW;
677 		case GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW:				return TYPE_SAMPLER_CUBE_ARRAY_SHADOW;
678 
679 		case GL_INT_SAMPLER_1D:								return TYPE_INT_SAMPLER_1D;
680 		case GL_INT_SAMPLER_2D:								return TYPE_INT_SAMPLER_2D;
681 		case GL_INT_SAMPLER_CUBE:							return TYPE_INT_SAMPLER_CUBE;
682 		case GL_INT_SAMPLER_2D_ARRAY:						return TYPE_INT_SAMPLER_2D_ARRAY;
683 		case GL_INT_SAMPLER_3D:								return TYPE_INT_SAMPLER_3D;
684 		case GL_INT_SAMPLER_CUBE_MAP_ARRAY:					return TYPE_INT_SAMPLER_CUBE_ARRAY;
685 
686 		case GL_UNSIGNED_INT_SAMPLER_1D:					return TYPE_UINT_SAMPLER_1D;
687 		case GL_UNSIGNED_INT_SAMPLER_2D:					return TYPE_UINT_SAMPLER_2D;
688 		case GL_UNSIGNED_INT_SAMPLER_CUBE:					return TYPE_UINT_SAMPLER_CUBE;
689 		case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:				return TYPE_UINT_SAMPLER_2D_ARRAY;
690 		case GL_UNSIGNED_INT_SAMPLER_3D:					return TYPE_UINT_SAMPLER_3D;
691 		case GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY:		return TYPE_UINT_SAMPLER_CUBE_ARRAY;
692 
693 		case GL_SAMPLER_2D_MULTISAMPLE:						return TYPE_SAMPLER_2D_MULTISAMPLE;
694 		case GL_INT_SAMPLER_2D_MULTISAMPLE:					return TYPE_INT_SAMPLER_2D_MULTISAMPLE;
695 		case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:		return TYPE_UINT_SAMPLER_2D_MULTISAMPLE;
696 
697 		case GL_IMAGE_2D:									return TYPE_IMAGE_2D;
698 		case GL_IMAGE_CUBE:									return TYPE_IMAGE_CUBE;
699 		case GL_IMAGE_2D_ARRAY:								return TYPE_IMAGE_2D_ARRAY;
700 		case GL_IMAGE_3D:									return TYPE_IMAGE_3D;
701 		case GL_INT_IMAGE_2D:								return TYPE_INT_IMAGE_2D;
702 		case GL_INT_IMAGE_CUBE:								return TYPE_INT_IMAGE_CUBE;
703 		case GL_INT_IMAGE_2D_ARRAY:							return TYPE_INT_IMAGE_2D_ARRAY;
704 		case GL_INT_IMAGE_3D:								return TYPE_INT_IMAGE_3D;
705 		case GL_UNSIGNED_INT_IMAGE_2D:						return TYPE_UINT_IMAGE_2D;
706 		case GL_UNSIGNED_INT_IMAGE_CUBE:					return TYPE_UINT_IMAGE_CUBE;
707 		case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:				return TYPE_UINT_IMAGE_2D_ARRAY;
708 		case GL_UNSIGNED_INT_IMAGE_3D:						return TYPE_UINT_IMAGE_3D;
709 
710 		case GL_UNSIGNED_INT_ATOMIC_COUNTER:				return TYPE_UINT_ATOMIC_COUNTER;
711 
712 		case GL_SAMPLER_BUFFER:								return TYPE_SAMPLER_BUFFER;
713 		case GL_INT_SAMPLER_BUFFER:							return TYPE_INT_SAMPLER_BUFFER;
714 		case GL_UNSIGNED_INT_SAMPLER_BUFFER:				return TYPE_UINT_SAMPLER_BUFFER;
715 
716 		case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:				return TYPE_SAMPLER_2D_MULTISAMPLE_ARRAY;
717 		case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:			return TYPE_INT_SAMPLER_2D_MULTISAMPLE_ARRAY;
718 		case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:	return TYPE_UINT_SAMPLER_2D_MULTISAMPLE_ARRAY;
719 
720 		case GL_IMAGE_BUFFER:								return TYPE_IMAGE_BUFFER;
721 		case GL_INT_IMAGE_BUFFER:							return TYPE_INT_IMAGE_BUFFER;
722 		case GL_UNSIGNED_INT_IMAGE_BUFFER:					return TYPE_UINT_IMAGE_BUFFER;
723 
724 		default:
725 			return TYPE_LAST;
726 	}
727 }
728 
729 } // glu
730