• 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 Reference context utils
22  *//*--------------------------------------------------------------------*/
23 
24 #include "sglrReferenceUtils.hpp"
25 #include "glwEnums.hpp"
26 
27 namespace sglr
28 {
29 namespace rr_util
30 {
31 
mapGLPureIntegerVertexAttributeType(deUint32 type)32 rr::VertexAttribType mapGLPureIntegerVertexAttributeType (deUint32 type)
33 {
34 	switch (type)
35 	{
36 		case GL_UNSIGNED_BYTE:					return rr::VERTEXATTRIBTYPE_PURE_UINT8;
37 		case GL_UNSIGNED_SHORT:					return rr::VERTEXATTRIBTYPE_PURE_UINT16;
38 		case GL_UNSIGNED_INT:					return rr::VERTEXATTRIBTYPE_PURE_UINT32;
39 		case GL_BYTE:							return rr::VERTEXATTRIBTYPE_PURE_INT8;
40 		case GL_SHORT:							return rr::VERTEXATTRIBTYPE_PURE_INT16;
41 		case GL_INT:							return rr::VERTEXATTRIBTYPE_PURE_INT32;
42 		default:
43 			DE_ASSERT(false);
44 			return rr::VERTEXATTRIBTYPE_LAST;
45 	}
46 }
47 
mapGLFloatVertexAttributeType(deUint32 type,bool normalizedInteger,int size,glu::ContextType ctxType)48 rr::VertexAttribType mapGLFloatVertexAttributeType (deUint32 type, bool normalizedInteger, int size, glu::ContextType ctxType)
49 {
50 	const bool useClampingNormalization	= (ctxType.getProfile() == glu::PROFILE_ES && ctxType.getMajorVersion() >= 3) ||
51 										  (ctxType.getMajorVersion() == 4 && ctxType.getMinorVersion() >= 2);
52 	const bool bgraComponentOrder		= (size == GL_BGRA);
53 
54 	switch (type)
55 	{
56 		case GL_FLOAT:
57 			return rr::VERTEXATTRIBTYPE_FLOAT;
58 
59 		case GL_HALF_FLOAT:
60 			return rr::VERTEXATTRIBTYPE_HALF;
61 
62 		case GL_FIXED:
63 			return rr::VERTEXATTRIBTYPE_FIXED;
64 
65 		case GL_DOUBLE:
66 			return rr::VERTEXATTRIBTYPE_DOUBLE;
67 
68 		case GL_UNSIGNED_BYTE:
69 			if (!normalizedInteger)
70 				return rr::VERTEXATTRIBTYPE_NONPURE_UINT8;
71 			else
72 				return (!bgraComponentOrder) ? (rr::VERTEXATTRIBTYPE_NONPURE_UNORM8) : (rr::VERTEXATTRIBTYPE_NONPURE_UNORM8_BGRA);
73 
74 		case GL_UNSIGNED_SHORT:
75 			if (!normalizedInteger)
76 				return rr::VERTEXATTRIBTYPE_NONPURE_UINT16;
77 			else
78 				return rr::VERTEXATTRIBTYPE_NONPURE_UNORM16;
79 
80 		case GL_UNSIGNED_INT:
81 			if (!normalizedInteger)
82 				return rr::VERTEXATTRIBTYPE_NONPURE_UINT32;
83 			else
84 				return rr::VERTEXATTRIBTYPE_NONPURE_UNORM32;
85 
86 		case GL_UNSIGNED_INT_2_10_10_10_REV:
87 			if (!normalizedInteger)
88 				return rr::VERTEXATTRIBTYPE_NONPURE_UINT_2_10_10_10_REV;
89 			else
90 				return (!bgraComponentOrder) ? (rr::VERTEXATTRIBTYPE_NONPURE_UNORM_2_10_10_10_REV) : (rr::VERTEXATTRIBTYPE_NONPURE_UNORM_2_10_10_10_REV_BGRA);
91 
92 		case GL_BYTE:
93 			if (!normalizedInteger)
94 				return rr::VERTEXATTRIBTYPE_NONPURE_INT8;
95 			else if (useClampingNormalization)
96 				return rr::VERTEXATTRIBTYPE_NONPURE_SNORM8_CLAMP;
97 			else
98 				return rr::VERTEXATTRIBTYPE_NONPURE_SNORM8_SCALE;
99 
100 		case GL_SHORT:
101 			if (!normalizedInteger)
102 				return rr::VERTEXATTRIBTYPE_NONPURE_INT16;
103 			else if (useClampingNormalization)
104 				return rr::VERTEXATTRIBTYPE_NONPURE_SNORM16_CLAMP;
105 			else
106 				return rr::VERTEXATTRIBTYPE_NONPURE_SNORM16_SCALE;
107 
108 		case GL_INT:
109 			if (!normalizedInteger)
110 				return rr::VERTEXATTRIBTYPE_NONPURE_INT32;
111 			else if (useClampingNormalization)
112 				return rr::VERTEXATTRIBTYPE_NONPURE_SNORM32_CLAMP;
113 			else
114 				return rr::VERTEXATTRIBTYPE_NONPURE_SNORM32_SCALE;
115 
116 		case GL_INT_2_10_10_10_REV:
117 			if (!normalizedInteger)
118 				return rr::VERTEXATTRIBTYPE_NONPURE_INT_2_10_10_10_REV;
119 			else if (useClampingNormalization)
120 				return (!bgraComponentOrder) ? (rr::VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_CLAMP) : (rr::VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_CLAMP_BGRA);
121 			else
122 				return (!bgraComponentOrder) ? (rr::VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_SCALE) : (rr::VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_SCALE_BGRA);
123 
124 		default:
125 			DE_ASSERT(false);
126 			return rr::VERTEXATTRIBTYPE_LAST;
127 	}
128 }
129 
mapGLSize(int size)130 int mapGLSize (int size)
131 {
132 	switch (size)
133 	{
134 		case 1:			return 1;
135 		case 2:			return 2;
136 		case 3:			return 3;
137 		case 4:			return 4;
138 		case GL_BGRA:	return 4;
139 
140 		default:
141 			DE_ASSERT(false);
142 			return 0;
143 	}
144 }
145 
mapGLPrimitiveType(deUint32 type)146 rr::PrimitiveType mapGLPrimitiveType (deUint32 type)
147 {
148 	switch (type)
149 	{
150 		case GL_TRIANGLES:					return rr::PRIMITIVETYPE_TRIANGLES;
151 		case GL_TRIANGLE_STRIP:				return rr::PRIMITIVETYPE_TRIANGLE_STRIP;
152 		case GL_TRIANGLE_FAN:				return rr::PRIMITIVETYPE_TRIANGLE_FAN;
153 		case GL_LINES:						return rr::PRIMITIVETYPE_LINES;
154 		case GL_LINE_STRIP:					return rr::PRIMITIVETYPE_LINE_STRIP;
155 		case GL_LINE_LOOP:					return rr::PRIMITIVETYPE_LINE_LOOP;
156 		case GL_POINTS:						return rr::PRIMITIVETYPE_POINTS;
157 		case GL_LINES_ADJACENCY:			return rr::PRIMITIVETYPE_LINES_ADJACENCY;
158 		case GL_LINE_STRIP_ADJACENCY:		return rr::PRIMITIVETYPE_LINE_STRIP_ADJACENCY;
159 		case GL_TRIANGLES_ADJACENCY:		return rr::PRIMITIVETYPE_TRIANGLES_ADJACENCY;
160 		case GL_TRIANGLE_STRIP_ADJACENCY:	return rr::PRIMITIVETYPE_TRIANGLE_STRIP_ADJACENCY;
161 		default:
162 			DE_ASSERT(false);
163 			return rr::PRIMITIVETYPE_LAST;
164 	}
165 }
166 
mapGLIndexType(deUint32 type)167 rr::IndexType mapGLIndexType (deUint32 type)
168 {
169 	switch (type)
170 	{
171 		case GL_UNSIGNED_BYTE:	return rr::INDEXTYPE_UINT8;
172 		case GL_UNSIGNED_SHORT:	return rr::INDEXTYPE_UINT16;
173 		case GL_UNSIGNED_INT:	return rr::INDEXTYPE_UINT32;
174 		default:
175 			DE_ASSERT(false);
176 			return rr::INDEXTYPE_LAST;
177 	}
178 }
179 
180 
mapGLGeometryShaderOutputType(deUint32 primitive)181 rr::GeometryShaderOutputType mapGLGeometryShaderOutputType (deUint32 primitive)
182 {
183 	switch (primitive)
184 	{
185 		case GL_POINTS:				return rr::GEOMETRYSHADEROUTPUTTYPE_POINTS;
186 		case GL_LINE_STRIP:			return rr::GEOMETRYSHADEROUTPUTTYPE_LINE_STRIP;
187 		case GL_TRIANGLE_STRIP:		return rr::GEOMETRYSHADEROUTPUTTYPE_TRIANGLE_STRIP;
188 		default:
189 			DE_ASSERT(DE_FALSE);
190 			return rr::GEOMETRYSHADEROUTPUTTYPE_LAST;
191 	}
192 }
193 
mapGLGeometryShaderInputType(deUint32 primitive)194 rr::GeometryShaderInputType mapGLGeometryShaderInputType (deUint32 primitive)
195 {
196 	switch (primitive)
197 	{
198 		case GL_POINTS:						return rr::GEOMETRYSHADERINPUTTYPE_POINTS;
199 		case GL_LINES:						return rr::GEOMETRYSHADERINPUTTYPE_LINES;
200 		case GL_LINE_STRIP:					return rr::GEOMETRYSHADERINPUTTYPE_LINES;
201 		case GL_LINE_LOOP:					return rr::GEOMETRYSHADERINPUTTYPE_LINES;
202 		case GL_TRIANGLES:					return rr::GEOMETRYSHADERINPUTTYPE_TRIANGLES;
203 		case GL_TRIANGLE_STRIP:				return rr::GEOMETRYSHADERINPUTTYPE_TRIANGLES;
204 		case GL_TRIANGLE_FAN:				return rr::GEOMETRYSHADERINPUTTYPE_TRIANGLES;
205 		case GL_LINES_ADJACENCY:			return rr::GEOMETRYSHADERINPUTTYPE_LINES_ADJACENCY;
206 		case GL_LINE_STRIP_ADJACENCY:		return rr::GEOMETRYSHADERINPUTTYPE_LINES_ADJACENCY;
207 		case GL_TRIANGLES_ADJACENCY:		return rr::GEOMETRYSHADERINPUTTYPE_TRIANGLES_ADJACENCY;
208 		case GL_TRIANGLE_STRIP_ADJACENCY:	return rr::GEOMETRYSHADERINPUTTYPE_TRIANGLES_ADJACENCY;
209 		default:
210 			DE_ASSERT(DE_FALSE);
211 			return rr::GEOMETRYSHADERINPUTTYPE_LAST;
212 	}
213 }
214 
mapGLTestFunc(deUint32 func)215 rr::TestFunc mapGLTestFunc (deUint32 func)
216 {
217 	switch (func)
218 	{
219 		case GL_ALWAYS:		return rr::TESTFUNC_ALWAYS;
220 		case GL_EQUAL:		return rr::TESTFUNC_EQUAL;
221 		case GL_GEQUAL:		return rr::TESTFUNC_GEQUAL;
222 		case GL_GREATER:	return rr::TESTFUNC_GREATER;
223 		case GL_LEQUAL:		return rr::TESTFUNC_LEQUAL;
224 		case GL_LESS:		return rr::TESTFUNC_LESS;
225 		case GL_NEVER:		return rr::TESTFUNC_NEVER;
226 		case GL_NOTEQUAL:	return rr::TESTFUNC_NOTEQUAL;
227 		default:
228 			DE_ASSERT(false);
229 			return rr::TESTFUNC_LAST;
230 	}
231 }
232 
mapGLStencilOp(deUint32 op)233 rr::StencilOp mapGLStencilOp (deUint32 op)
234 {
235 	switch (op)
236 	{
237 		case GL_KEEP:		return rr::STENCILOP_KEEP;
238 		case GL_ZERO:		return rr::STENCILOP_ZERO;
239 		case GL_REPLACE:	return rr::STENCILOP_REPLACE;
240 		case GL_INCR:		return rr::STENCILOP_INCR;
241 		case GL_DECR:		return rr::STENCILOP_DECR;
242 		case GL_INCR_WRAP:	return rr::STENCILOP_INCR_WRAP;
243 		case GL_DECR_WRAP:	return rr::STENCILOP_DECR_WRAP;
244 		case GL_INVERT:		return rr::STENCILOP_INVERT;
245 		default:
246 			DE_ASSERT(false);
247 			return rr::STENCILOP_LAST;
248 	}
249 }
250 
mapGLBlendEquation(deUint32 equation)251 rr::BlendEquation mapGLBlendEquation (deUint32 equation)
252 {
253 	switch (equation)
254 	{
255 		case GL_FUNC_ADD:				return rr::BLENDEQUATION_ADD;
256 		case GL_FUNC_SUBTRACT:			return rr::BLENDEQUATION_SUBTRACT;
257 		case GL_FUNC_REVERSE_SUBTRACT:	return rr::BLENDEQUATION_REVERSE_SUBTRACT;
258 		case GL_MIN:					return rr::BLENDEQUATION_MIN;
259 		case GL_MAX:					return rr::BLENDEQUATION_MAX;
260 		default:
261 			DE_ASSERT(false);
262 			return rr::BLENDEQUATION_LAST;
263 	}
264 }
265 
mapGLBlendEquationAdvanced(deUint32 equation)266 rr::BlendEquationAdvanced mapGLBlendEquationAdvanced (deUint32 equation)
267 {
268 	switch (equation)
269 	{
270 		case GL_MULTIPLY_KHR:		return rr::BLENDEQUATION_ADVANCED_MULTIPLY;
271 		case GL_SCREEN_KHR:			return rr::BLENDEQUATION_ADVANCED_SCREEN;
272 		case GL_OVERLAY_KHR:		return rr::BLENDEQUATION_ADVANCED_OVERLAY;
273 		case GL_DARKEN_KHR:			return rr::BLENDEQUATION_ADVANCED_DARKEN;
274 		case GL_LIGHTEN_KHR:		return rr::BLENDEQUATION_ADVANCED_LIGHTEN;
275 		case GL_COLORDODGE_KHR:		return rr::BLENDEQUATION_ADVANCED_COLORDODGE;
276 		case GL_COLORBURN_KHR:		return rr::BLENDEQUATION_ADVANCED_COLORBURN;
277 		case GL_HARDLIGHT_KHR:		return rr::BLENDEQUATION_ADVANCED_HARDLIGHT;
278 		case GL_SOFTLIGHT_KHR:		return rr::BLENDEQUATION_ADVANCED_SOFTLIGHT;
279 		case GL_DIFFERENCE_KHR:		return rr::BLENDEQUATION_ADVANCED_DIFFERENCE;
280 		case GL_EXCLUSION_KHR:		return rr::BLENDEQUATION_ADVANCED_EXCLUSION;
281 		case GL_HSL_HUE_KHR:		return rr::BLENDEQUATION_ADVANCED_HSL_HUE;
282 		case GL_HSL_SATURATION_KHR:	return rr::BLENDEQUATION_ADVANCED_HSL_SATURATION;
283 		case GL_HSL_COLOR_KHR:		return rr::BLENDEQUATION_ADVANCED_HSL_COLOR;
284 		case GL_HSL_LUMINOSITY_KHR:	return rr::BLENDEQUATION_ADVANCED_HSL_LUMINOSITY;
285 		default:
286 			DE_ASSERT(false);
287 			return rr::BLENDEQUATION_ADVANCED_LAST;
288 	}
289 }
290 
mapGLBlendFunc(deUint32 func)291 rr::BlendFunc mapGLBlendFunc (deUint32 func)
292 {
293 	switch (func)
294 	{
295 		case GL_ZERO:						return rr::BLENDFUNC_ZERO;
296 		case GL_ONE:						return rr::BLENDFUNC_ONE;
297 		case GL_SRC_COLOR:					return rr::BLENDFUNC_SRC_COLOR;
298 		case GL_ONE_MINUS_SRC_COLOR:		return rr::BLENDFUNC_ONE_MINUS_SRC_COLOR;
299 		case GL_DST_COLOR:					return rr::BLENDFUNC_DST_COLOR;
300 		case GL_ONE_MINUS_DST_COLOR:		return rr::BLENDFUNC_ONE_MINUS_DST_COLOR;
301 		case GL_SRC_ALPHA:					return rr::BLENDFUNC_SRC_ALPHA;
302 		case GL_ONE_MINUS_SRC_ALPHA:		return rr::BLENDFUNC_ONE_MINUS_SRC_ALPHA;
303 		case GL_DST_ALPHA:					return rr::BLENDFUNC_DST_ALPHA;
304 		case GL_ONE_MINUS_DST_ALPHA:		return rr::BLENDFUNC_ONE_MINUS_DST_ALPHA;
305 		case GL_CONSTANT_COLOR:				return rr::BLENDFUNC_CONSTANT_COLOR;
306 		case GL_ONE_MINUS_CONSTANT_COLOR:	return rr::BLENDFUNC_ONE_MINUS_CONSTANT_COLOR;
307 		case GL_CONSTANT_ALPHA:				return rr::BLENDFUNC_CONSTANT_ALPHA;
308 		case GL_ONE_MINUS_CONSTANT_ALPHA:	return rr::BLENDFUNC_ONE_MINUS_CONSTANT_ALPHA;
309 		case GL_SRC_ALPHA_SATURATE:			return rr::BLENDFUNC_SRC_ALPHA_SATURATE;
310 		case GL_SRC1_COLOR:					return rr::BLENDFUNC_SRC1_COLOR;
311 		case GL_ONE_MINUS_SRC1_COLOR:		return rr::BLENDFUNC_ONE_MINUS_SRC1_COLOR;
312 		case GL_SRC1_ALPHA:					return rr::BLENDFUNC_SRC1_ALPHA;
313 		case GL_ONE_MINUS_SRC1_ALPHA:		return rr::BLENDFUNC_ONE_MINUS_SRC1_ALPHA;
314 		default:
315 			DE_ASSERT(false);
316 			return rr::BLENDFUNC_LAST;
317 	}
318 }
319 
320 } // rr_util
321 } // sglr
322