blob: 8ef211d03cc1fcc955528c12f9c99891d7040159 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
shannon.woods@transgaming.com2494c972013-02-28 23:10:03 +00002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// utilities.cpp: Conversion functions and other utility routines.
8
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +00009#include "common/utilities.h"
jchen108225e732017-11-14 16:29:03 +080010#include <GLSLANG/ShaderVars.h>
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000011#include "common/mathutil.h"
Geoff Lang44fa7592014-05-30 11:50:07 -040012#include "common/platform.h"
Geoff Lang83217792014-01-16 09:52:38 -050013
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000014#include <set>
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000015
Cooper Partin88d3b8c2014-10-08 10:41:56 -070016#if defined(ANGLE_ENABLE_WINDOWS_STORE)
Jamie Madillb980c562018-11-27 11:34:27 -050017# include <windows.applicationmodel.core.h>
18# include <windows.graphics.display.h>
19# include <wrl.h>
20# include <wrl/wrappers/corewrappers.h>
Cooper Partin88d3b8c2014-10-08 10:41:56 -070021#endif
22
Geoff Lang3edfe032015-09-04 16:38:24 -040023namespace
24{
25
26template <class IndexType>
27gl::IndexRange ComputeTypedIndexRange(const IndexType *indices,
28 size_t count,
29 bool primitiveRestartEnabled,
30 GLuint primitiveRestartIndex)
31{
32 ASSERT(count > 0);
33
34 IndexType minIndex = 0;
35 IndexType maxIndex = 0;
36 size_t nonPrimitiveRestartIndices = 0;
37
38 if (primitiveRestartEnabled)
39 {
40 // Find the first non-primitive restart index to initialize the min and max values
41 size_t i = 0;
42 for (; i < count; i++)
43 {
44 if (indices[i] != primitiveRestartIndex)
45 {
46 minIndex = indices[i];
47 maxIndex = indices[i];
48 nonPrimitiveRestartIndices++;
49 break;
50 }
51 }
52
53 // Loop over the rest of the indices
54 for (; i < count; i++)
55 {
56 if (indices[i] != primitiveRestartIndex)
57 {
58 if (minIndex > indices[i])
59 {
60 minIndex = indices[i];
61 }
62 if (maxIndex < indices[i])
63 {
64 maxIndex = indices[i];
65 }
66 nonPrimitiveRestartIndices++;
67 }
68 }
69 }
70 else
71 {
72 minIndex = indices[0];
73 maxIndex = indices[0];
74 nonPrimitiveRestartIndices = count;
75
76 for (size_t i = 1; i < count; i++)
77 {
78 if (minIndex > indices[i])
79 {
80 minIndex = indices[i];
81 }
82 if (maxIndex < indices[i])
83 {
84 maxIndex = indices[i];
85 }
86 }
87 }
88
89 return gl::IndexRange(static_cast<size_t>(minIndex), static_cast<size_t>(maxIndex),
90 nonPrimitiveRestartIndices);
91}
92
93} // anonymous namespace
94
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +000095namespace gl
96{
97
Jamie Madillf2575982014-06-25 16:04:54 -040098int VariableComponentCount(GLenum type)
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +000099{
Jamie Madillaa72d782014-07-02 15:31:19 -0400100 return VariableRowCount(type) * VariableColumnCount(type);
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000101}
102
Jamie Madillf2575982014-06-25 16:04:54 -0400103GLenum VariableComponentType(GLenum type)
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000104{
Jamie Madill493f9572018-05-24 19:52:15 -0400105 switch (type)
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000106 {
Jamie Madill493f9572018-05-24 19:52:15 -0400107 case GL_BOOL:
108 case GL_BOOL_VEC2:
109 case GL_BOOL_VEC3:
110 case GL_BOOL_VEC4:
111 return GL_BOOL;
112 case GL_FLOAT:
113 case GL_FLOAT_VEC2:
114 case GL_FLOAT_VEC3:
115 case GL_FLOAT_VEC4:
116 case GL_FLOAT_MAT2:
117 case GL_FLOAT_MAT3:
118 case GL_FLOAT_MAT4:
119 case GL_FLOAT_MAT2x3:
120 case GL_FLOAT_MAT3x2:
121 case GL_FLOAT_MAT2x4:
122 case GL_FLOAT_MAT4x2:
123 case GL_FLOAT_MAT3x4:
124 case GL_FLOAT_MAT4x3:
125 return GL_FLOAT;
126 case GL_INT:
127 case GL_SAMPLER_2D:
128 case GL_SAMPLER_2D_RECT_ANGLE:
129 case GL_SAMPLER_3D:
130 case GL_SAMPLER_CUBE:
131 case GL_SAMPLER_2D_ARRAY:
132 case GL_SAMPLER_EXTERNAL_OES:
133 case GL_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300134 case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400135 case GL_INT_SAMPLER_2D:
136 case GL_INT_SAMPLER_3D:
137 case GL_INT_SAMPLER_CUBE:
138 case GL_INT_SAMPLER_2D_ARRAY:
139 case GL_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300140 case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400141 case GL_UNSIGNED_INT_SAMPLER_2D:
142 case GL_UNSIGNED_INT_SAMPLER_3D:
143 case GL_UNSIGNED_INT_SAMPLER_CUBE:
144 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
145 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300146 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400147 case GL_SAMPLER_2D_SHADOW:
148 case GL_SAMPLER_CUBE_SHADOW:
149 case GL_SAMPLER_2D_ARRAY_SHADOW:
150 case GL_INT_VEC2:
151 case GL_INT_VEC3:
152 case GL_INT_VEC4:
153 case GL_IMAGE_2D:
154 case GL_INT_IMAGE_2D:
155 case GL_UNSIGNED_INT_IMAGE_2D:
156 case GL_IMAGE_3D:
157 case GL_INT_IMAGE_3D:
158 case GL_UNSIGNED_INT_IMAGE_3D:
159 case GL_IMAGE_2D_ARRAY:
160 case GL_INT_IMAGE_2D_ARRAY:
161 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
162 case GL_IMAGE_CUBE:
163 case GL_INT_IMAGE_CUBE:
164 case GL_UNSIGNED_INT_IMAGE_CUBE:
165 case GL_UNSIGNED_INT_ATOMIC_COUNTER:
166 return GL_INT;
167 case GL_UNSIGNED_INT:
168 case GL_UNSIGNED_INT_VEC2:
169 case GL_UNSIGNED_INT_VEC3:
170 case GL_UNSIGNED_INT_VEC4:
171 return GL_UNSIGNED_INT;
172 default:
173 UNREACHABLE();
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000174 }
175
176 return GL_NONE;
177}
178
Jamie Madillf2575982014-06-25 16:04:54 -0400179size_t VariableComponentSize(GLenum type)
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000180{
Jamie Madill493f9572018-05-24 19:52:15 -0400181 switch (type)
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000182 {
Jamie Madill493f9572018-05-24 19:52:15 -0400183 case GL_BOOL:
184 return sizeof(GLint);
185 case GL_FLOAT:
186 return sizeof(GLfloat);
187 case GL_INT:
188 return sizeof(GLint);
189 case GL_UNSIGNED_INT:
190 return sizeof(GLuint);
191 default:
192 UNREACHABLE();
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000193 }
194
jbauman@chromium.org72e8f442011-10-20 00:22:01 +0000195 return 0;
196}
197
Jamie Madillf2575982014-06-25 16:04:54 -0400198size_t VariableInternalSize(GLenum type)
jbauman@chromium.org72e8f442011-10-20 00:22:01 +0000199{
shannon.woods@transgaming.com2494c972013-02-28 23:10:03 +0000200 // Expanded to 4-element vectors
Jamie Madillf2575982014-06-25 16:04:54 -0400201 return VariableComponentSize(VariableComponentType(type)) * VariableRowCount(type) * 4;
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000202}
203
Jamie Madillf2575982014-06-25 16:04:54 -0400204size_t VariableExternalSize(GLenum type)
daniel@transgaming.com47c60052011-11-12 03:17:50 +0000205{
Jamie Madillf2575982014-06-25 16:04:54 -0400206 return VariableComponentSize(VariableComponentType(type)) * VariableComponentCount(type);
daniel@transgaming.com47c60052011-11-12 03:17:50 +0000207}
208
Jamie Madillf2575982014-06-25 16:04:54 -0400209GLenum VariableBoolVectorType(GLenum type)
shannon.woods%transgaming.com@gtempaccount.com8a19eed2013-04-13 03:40:22 +0000210{
211 switch (type)
212 {
Jamie Madill493f9572018-05-24 19:52:15 -0400213 case GL_FLOAT:
214 case GL_INT:
215 case GL_UNSIGNED_INT:
216 return GL_BOOL;
217 case GL_FLOAT_VEC2:
218 case GL_INT_VEC2:
219 case GL_UNSIGNED_INT_VEC2:
220 return GL_BOOL_VEC2;
221 case GL_FLOAT_VEC3:
222 case GL_INT_VEC3:
223 case GL_UNSIGNED_INT_VEC3:
224 return GL_BOOL_VEC3;
225 case GL_FLOAT_VEC4:
226 case GL_INT_VEC4:
227 case GL_UNSIGNED_INT_VEC4:
228 return GL_BOOL_VEC4;
shannon.woods%transgaming.com@gtempaccount.com8a19eed2013-04-13 03:40:22 +0000229
Jamie Madill493f9572018-05-24 19:52:15 -0400230 default:
231 UNREACHABLE();
232 return GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com8a19eed2013-04-13 03:40:22 +0000233 }
234}
235
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000236int VariableRowCount(GLenum type)
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000237{
238 switch (type)
239 {
Jamie Madill493f9572018-05-24 19:52:15 -0400240 case GL_NONE:
241 return 0;
242 case GL_BOOL:
243 case GL_FLOAT:
244 case GL_INT:
245 case GL_UNSIGNED_INT:
246 case GL_BOOL_VEC2:
247 case GL_FLOAT_VEC2:
248 case GL_INT_VEC2:
249 case GL_UNSIGNED_INT_VEC2:
250 case GL_BOOL_VEC3:
251 case GL_FLOAT_VEC3:
252 case GL_INT_VEC3:
253 case GL_UNSIGNED_INT_VEC3:
254 case GL_BOOL_VEC4:
255 case GL_FLOAT_VEC4:
256 case GL_INT_VEC4:
257 case GL_UNSIGNED_INT_VEC4:
258 case GL_SAMPLER_2D:
259 case GL_SAMPLER_3D:
260 case GL_SAMPLER_CUBE:
261 case GL_SAMPLER_2D_ARRAY:
262 case GL_SAMPLER_EXTERNAL_OES:
263 case GL_SAMPLER_2D_RECT_ANGLE:
264 case GL_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300265 case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400266 case GL_INT_SAMPLER_2D:
267 case GL_INT_SAMPLER_3D:
268 case GL_INT_SAMPLER_CUBE:
269 case GL_INT_SAMPLER_2D_ARRAY:
270 case GL_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300271 case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400272 case GL_UNSIGNED_INT_SAMPLER_2D:
273 case GL_UNSIGNED_INT_SAMPLER_3D:
274 case GL_UNSIGNED_INT_SAMPLER_CUBE:
275 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
276 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300277 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400278 case GL_SAMPLER_2D_SHADOW:
279 case GL_SAMPLER_CUBE_SHADOW:
280 case GL_SAMPLER_2D_ARRAY_SHADOW:
281 case GL_IMAGE_2D:
282 case GL_INT_IMAGE_2D:
283 case GL_UNSIGNED_INT_IMAGE_2D:
284 case GL_IMAGE_2D_ARRAY:
285 case GL_INT_IMAGE_2D_ARRAY:
286 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
287 case GL_IMAGE_3D:
288 case GL_INT_IMAGE_3D:
289 case GL_UNSIGNED_INT_IMAGE_3D:
290 case GL_IMAGE_CUBE:
291 case GL_INT_IMAGE_CUBE:
292 case GL_UNSIGNED_INT_IMAGE_CUBE:
293 case GL_UNSIGNED_INT_ATOMIC_COUNTER:
294 return 1;
295 case GL_FLOAT_MAT2:
296 case GL_FLOAT_MAT3x2:
297 case GL_FLOAT_MAT4x2:
298 return 2;
299 case GL_FLOAT_MAT3:
300 case GL_FLOAT_MAT2x3:
301 case GL_FLOAT_MAT4x3:
302 return 3;
303 case GL_FLOAT_MAT4:
304 case GL_FLOAT_MAT2x4:
305 case GL_FLOAT_MAT3x4:
306 return 4;
307 default:
308 UNREACHABLE();
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000309 }
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000310
311 return 0;
312}
313
314int VariableColumnCount(GLenum type)
315{
316 switch (type)
317 {
Jamie Madill493f9572018-05-24 19:52:15 -0400318 case GL_NONE:
319 return 0;
320 case GL_BOOL:
321 case GL_FLOAT:
322 case GL_INT:
323 case GL_UNSIGNED_INT:
324 case GL_SAMPLER_2D:
325 case GL_SAMPLER_3D:
326 case GL_SAMPLER_CUBE:
327 case GL_SAMPLER_2D_ARRAY:
328 case GL_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300329 case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400330 case GL_INT_SAMPLER_2D:
331 case GL_INT_SAMPLER_3D:
332 case GL_INT_SAMPLER_CUBE:
333 case GL_INT_SAMPLER_2D_ARRAY:
334 case GL_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300335 case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400336 case GL_SAMPLER_EXTERNAL_OES:
337 case GL_SAMPLER_2D_RECT_ANGLE:
338 case GL_UNSIGNED_INT_SAMPLER_2D:
339 case GL_UNSIGNED_INT_SAMPLER_3D:
340 case GL_UNSIGNED_INT_SAMPLER_CUBE:
341 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
342 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300343 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400344 case GL_SAMPLER_2D_SHADOW:
345 case GL_SAMPLER_CUBE_SHADOW:
346 case GL_SAMPLER_2D_ARRAY_SHADOW:
347 case GL_IMAGE_2D:
348 case GL_INT_IMAGE_2D:
349 case GL_UNSIGNED_INT_IMAGE_2D:
350 case GL_IMAGE_3D:
351 case GL_INT_IMAGE_3D:
352 case GL_UNSIGNED_INT_IMAGE_3D:
353 case GL_IMAGE_2D_ARRAY:
354 case GL_INT_IMAGE_2D_ARRAY:
355 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
356 case GL_IMAGE_CUBE:
357 case GL_INT_IMAGE_CUBE:
358 case GL_UNSIGNED_INT_IMAGE_CUBE:
359 case GL_UNSIGNED_INT_ATOMIC_COUNTER:
360 return 1;
361 case GL_BOOL_VEC2:
362 case GL_FLOAT_VEC2:
363 case GL_INT_VEC2:
364 case GL_UNSIGNED_INT_VEC2:
365 case GL_FLOAT_MAT2:
366 case GL_FLOAT_MAT2x3:
367 case GL_FLOAT_MAT2x4:
368 return 2;
369 case GL_BOOL_VEC3:
370 case GL_FLOAT_VEC3:
371 case GL_INT_VEC3:
372 case GL_UNSIGNED_INT_VEC3:
373 case GL_FLOAT_MAT3:
374 case GL_FLOAT_MAT3x2:
375 case GL_FLOAT_MAT3x4:
376 return 3;
377 case GL_BOOL_VEC4:
378 case GL_FLOAT_VEC4:
379 case GL_INT_VEC4:
380 case GL_UNSIGNED_INT_VEC4:
381 case GL_FLOAT_MAT4:
382 case GL_FLOAT_MAT4x2:
383 case GL_FLOAT_MAT4x3:
384 return 4;
385 default:
386 UNREACHABLE();
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000387 }
388
389 return 0;
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000390}
391
Geoff Lang2ec386b2014-12-03 14:44:38 -0500392bool IsSamplerType(GLenum type)
Nicolas Capense6050882013-07-08 10:43:10 -0400393{
394 switch (type)
395 {
Jamie Madill493f9572018-05-24 19:52:15 -0400396 case GL_SAMPLER_2D:
397 case GL_SAMPLER_3D:
398 case GL_SAMPLER_CUBE:
399 case GL_SAMPLER_2D_ARRAY:
400 case GL_SAMPLER_EXTERNAL_OES:
401 case GL_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300402 case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400403 case GL_SAMPLER_2D_RECT_ANGLE:
404 case GL_INT_SAMPLER_2D:
405 case GL_INT_SAMPLER_3D:
406 case GL_INT_SAMPLER_CUBE:
407 case GL_INT_SAMPLER_2D_ARRAY:
408 case GL_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300409 case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400410 case GL_UNSIGNED_INT_SAMPLER_2D:
411 case GL_UNSIGNED_INT_SAMPLER_3D:
412 case GL_UNSIGNED_INT_SAMPLER_CUBE:
413 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
414 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300415 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400416 case GL_SAMPLER_2D_SHADOW:
417 case GL_SAMPLER_CUBE_SHADOW:
418 case GL_SAMPLER_2D_ARRAY_SHADOW:
419 return true;
Nicolas Capense6050882013-07-08 10:43:10 -0400420 }
421
422 return false;
423}
424
Olli Etuahoceb10482017-02-13 12:31:03 +0000425bool IsImageType(GLenum type)
426{
427 switch (type)
428 {
429 case GL_IMAGE_2D:
430 case GL_INT_IMAGE_2D:
431 case GL_UNSIGNED_INT_IMAGE_2D:
432 case GL_IMAGE_3D:
433 case GL_INT_IMAGE_3D:
434 case GL_UNSIGNED_INT_IMAGE_3D:
435 case GL_IMAGE_2D_ARRAY:
436 case GL_INT_IMAGE_2D_ARRAY:
437 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
438 case GL_IMAGE_CUBE:
439 case GL_INT_IMAGE_CUBE:
440 case GL_UNSIGNED_INT_IMAGE_CUBE:
441 return true;
442 }
443 return false;
444}
445
jchen104cdac9e2017-05-08 11:01:20 +0800446bool IsAtomicCounterType(GLenum type)
447{
448 return type == GL_UNSIGNED_INT_ATOMIC_COUNTER;
449}
450
Olli Etuahoceb10482017-02-13 12:31:03 +0000451bool IsOpaqueType(GLenum type)
452{
453 // ESSL 3.10 section 4.1.7 defines opaque types as: samplers, images and atomic counters.
jchen104cdac9e2017-05-08 11:01:20 +0800454 return IsImageType(type) || IsSamplerType(type) || IsAtomicCounterType(type);
Olli Etuahoceb10482017-02-13 12:31:03 +0000455}
456
shannon.woods%transgaming.com@gtempaccount.com02e11f32013-04-13 03:40:50 +0000457bool IsMatrixType(GLenum type)
458{
459 return VariableRowCount(type) > 1;
460}
461
shannonwoods@chromium.org9bd22fa2013-05-30 00:18:47 +0000462GLenum TransposeMatrixType(GLenum type)
463{
464 if (!IsMatrixType(type))
465 {
466 return type;
467 }
468
469 switch (type)
470 {
Jamie Madill493f9572018-05-24 19:52:15 -0400471 case GL_FLOAT_MAT2:
472 return GL_FLOAT_MAT2;
473 case GL_FLOAT_MAT3:
474 return GL_FLOAT_MAT3;
475 case GL_FLOAT_MAT4:
476 return GL_FLOAT_MAT4;
477 case GL_FLOAT_MAT2x3:
478 return GL_FLOAT_MAT3x2;
479 case GL_FLOAT_MAT3x2:
480 return GL_FLOAT_MAT2x3;
481 case GL_FLOAT_MAT2x4:
482 return GL_FLOAT_MAT4x2;
483 case GL_FLOAT_MAT4x2:
484 return GL_FLOAT_MAT2x4;
485 case GL_FLOAT_MAT3x4:
486 return GL_FLOAT_MAT4x3;
487 case GL_FLOAT_MAT4x3:
488 return GL_FLOAT_MAT3x4;
489 default:
490 UNREACHABLE();
491 return GL_NONE;
shannonwoods@chromium.org9bd22fa2013-05-30 00:18:47 +0000492 }
493}
494
Jamie Madill8c6befc2013-06-20 11:55:55 -0400495int MatrixRegisterCount(GLenum type, bool isRowMajorMatrix)
496{
497 ASSERT(IsMatrixType(type));
498 return isRowMajorMatrix ? VariableRowCount(type) : VariableColumnCount(type);
499}
500
501int MatrixComponentCount(GLenum type, bool isRowMajorMatrix)
502{
503 ASSERT(IsMatrixType(type));
504 return isRowMajorMatrix ? VariableColumnCount(type) : VariableRowCount(type);
505}
506
Jamie Madillf2575982014-06-25 16:04:54 -0400507int VariableRegisterCount(GLenum type)
shannonwoods@chromium.org9bd22fa2013-05-30 00:18:47 +0000508{
509 return IsMatrixType(type) ? VariableColumnCount(type) : 1;
510}
511
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000512int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize)
513{
514 ASSERT(allocationSize <= bitsSize);
515
Jamie Madill493f9572018-05-24 19:52:15 -0400516 unsigned int mask = std::numeric_limits<unsigned int>::max() >>
517 (std::numeric_limits<unsigned int>::digits - allocationSize);
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000518
519 for (unsigned int i = 0; i < bitsSize - allocationSize + 1; i++)
520 {
521 if ((*bits & mask) == 0)
522 {
523 *bits |= mask;
524 return i;
525 }
526
527 mask <<= 1;
528 }
529
530 return -1;
531}
532
Jamie Madill8dc27f92018-11-29 11:45:44 -0500533IndexRange ComputeIndexRange(DrawElementsType indexType,
Geoff Lang3edfe032015-09-04 16:38:24 -0400534 const GLvoid *indices,
535 size_t count,
536 bool primitiveRestartEnabled)
Geoff Lang831b1952015-05-05 11:02:27 -0400537{
538 switch (indexType)
539 {
Jamie Madill8dc27f92018-11-29 11:45:44 -0500540 case DrawElementsType::UnsignedByte:
Geoff Lang3edfe032015-09-04 16:38:24 -0400541 return ComputeTypedIndexRange(static_cast<const GLubyte *>(indices), count,
542 primitiveRestartEnabled,
543 GetPrimitiveRestartIndex(indexType));
Jamie Madill8dc27f92018-11-29 11:45:44 -0500544 case DrawElementsType::UnsignedShort:
Geoff Lang3edfe032015-09-04 16:38:24 -0400545 return ComputeTypedIndexRange(static_cast<const GLushort *>(indices), count,
546 primitiveRestartEnabled,
547 GetPrimitiveRestartIndex(indexType));
Jamie Madill8dc27f92018-11-29 11:45:44 -0500548 case DrawElementsType::UnsignedInt:
Geoff Lang3edfe032015-09-04 16:38:24 -0400549 return ComputeTypedIndexRange(static_cast<const GLuint *>(indices), count,
550 primitiveRestartEnabled,
551 GetPrimitiveRestartIndex(indexType));
552 default:
553 UNREACHABLE();
554 return IndexRange();
555 }
556}
557
Jamie Madill8dc27f92018-11-29 11:45:44 -0500558GLuint GetPrimitiveRestartIndex(DrawElementsType indexType)
Geoff Lang3edfe032015-09-04 16:38:24 -0400559{
560 switch (indexType)
561 {
Jamie Madill8dc27f92018-11-29 11:45:44 -0500562 case DrawElementsType::UnsignedByte:
Geoff Lang3edfe032015-09-04 16:38:24 -0400563 return 0xFF;
Jamie Madill8dc27f92018-11-29 11:45:44 -0500564 case DrawElementsType::UnsignedShort:
Geoff Lang3edfe032015-09-04 16:38:24 -0400565 return 0xFFFF;
Jamie Madill8dc27f92018-11-29 11:45:44 -0500566 case DrawElementsType::UnsignedInt:
Geoff Lang3edfe032015-09-04 16:38:24 -0400567 return 0xFFFFFFFF;
568 default:
569 UNREACHABLE();
570 return 0;
Geoff Lang831b1952015-05-05 11:02:27 -0400571 }
572}
573
Jamie Madill493f9572018-05-24 19:52:15 -0400574bool IsTriangleMode(PrimitiveMode drawMode)
daniel@transgaming.com97c852b2012-12-20 20:56:23 +0000575{
576 switch (drawMode)
577 {
Jamie Madill493f9572018-05-24 19:52:15 -0400578 case PrimitiveMode::Triangles:
579 case PrimitiveMode::TriangleFan:
580 case PrimitiveMode::TriangleStrip:
581 return true;
582 case PrimitiveMode::Points:
583 case PrimitiveMode::Lines:
584 case PrimitiveMode::LineLoop:
585 case PrimitiveMode::LineStrip:
586 return false;
587 default:
588 UNREACHABLE();
daniel@transgaming.com97c852b2012-12-20 20:56:23 +0000589 }
590
591 return false;
592}
593
Jamie Madillb36a4812018-09-25 10:15:11 -0400594bool IsLineMode(PrimitiveMode primitiveMode)
595{
596 switch (primitiveMode)
597 {
598 case PrimitiveMode::LineLoop:
599 case PrimitiveMode::LineStrip:
600 case PrimitiveMode::LineStripAdjacency:
601 case PrimitiveMode::Lines:
602 return true;
603
604 default:
605 return false;
606 }
607}
608
Geoff Lang4f0e0032017-05-01 16:04:35 -0400609bool IsIntegerFormat(GLenum unsizedFormat)
610{
611 switch (unsizedFormat)
612 {
613 case GL_RGBA_INTEGER:
614 case GL_RGB_INTEGER:
615 case GL_RG_INTEGER:
616 case GL_RED_INTEGER:
617 return true;
618
619 default:
620 return false;
621 }
622}
623
Jamie Madill865d1452014-07-02 15:31:20 -0400624// [OpenGL ES SL 3.00.4] Section 11 p. 120
625// Vertex Outs/Fragment Ins packing priorities
626int VariableSortOrder(GLenum type)
627{
628 switch (type)
629 {
Jamie Madill493f9572018-05-24 19:52:15 -0400630 // 1. Arrays of mat4 and mat4
631 // Non-square matrices of type matCxR consume the same space as a square
632 // matrix of type matN where N is the greater of C and R
633 case GL_FLOAT_MAT4:
634 case GL_FLOAT_MAT2x4:
635 case GL_FLOAT_MAT3x4:
636 case GL_FLOAT_MAT4x2:
637 case GL_FLOAT_MAT4x3:
638 return 0;
Jamie Madill865d1452014-07-02 15:31:20 -0400639
Jamie Madill493f9572018-05-24 19:52:15 -0400640 // 2. Arrays of mat2 and mat2 (since they occupy full rows)
641 case GL_FLOAT_MAT2:
642 return 1;
Jamie Madill865d1452014-07-02 15:31:20 -0400643
Jamie Madill493f9572018-05-24 19:52:15 -0400644 // 3. Arrays of vec4 and vec4
645 case GL_FLOAT_VEC4:
646 case GL_INT_VEC4:
647 case GL_BOOL_VEC4:
648 case GL_UNSIGNED_INT_VEC4:
649 return 2;
Jamie Madill865d1452014-07-02 15:31:20 -0400650
Jamie Madill493f9572018-05-24 19:52:15 -0400651 // 4. Arrays of mat3 and mat3
652 case GL_FLOAT_MAT3:
653 case GL_FLOAT_MAT2x3:
654 case GL_FLOAT_MAT3x2:
655 return 3;
Jamie Madill865d1452014-07-02 15:31:20 -0400656
Jamie Madill493f9572018-05-24 19:52:15 -0400657 // 5. Arrays of vec3 and vec3
658 case GL_FLOAT_VEC3:
659 case GL_INT_VEC3:
660 case GL_BOOL_VEC3:
661 case GL_UNSIGNED_INT_VEC3:
662 return 4;
Jamie Madill865d1452014-07-02 15:31:20 -0400663
Jamie Madill493f9572018-05-24 19:52:15 -0400664 // 6. Arrays of vec2 and vec2
665 case GL_FLOAT_VEC2:
666 case GL_INT_VEC2:
667 case GL_BOOL_VEC2:
668 case GL_UNSIGNED_INT_VEC2:
669 return 5;
Jamie Madill865d1452014-07-02 15:31:20 -0400670
Jamie Madill493f9572018-05-24 19:52:15 -0400671 // 7. Single component types
672 case GL_FLOAT:
673 case GL_INT:
674 case GL_BOOL:
675 case GL_UNSIGNED_INT:
676 case GL_SAMPLER_2D:
677 case GL_SAMPLER_CUBE:
678 case GL_SAMPLER_EXTERNAL_OES:
679 case GL_SAMPLER_2D_RECT_ANGLE:
680 case GL_SAMPLER_2D_ARRAY:
681 case GL_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300682 case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400683 case GL_SAMPLER_3D:
684 case GL_INT_SAMPLER_2D:
685 case GL_INT_SAMPLER_3D:
686 case GL_INT_SAMPLER_CUBE:
687 case GL_INT_SAMPLER_2D_ARRAY:
688 case GL_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300689 case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400690 case GL_UNSIGNED_INT_SAMPLER_2D:
691 case GL_UNSIGNED_INT_SAMPLER_3D:
692 case GL_UNSIGNED_INT_SAMPLER_CUBE:
693 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
694 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +0300695 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
Jamie Madill493f9572018-05-24 19:52:15 -0400696 case GL_SAMPLER_2D_SHADOW:
697 case GL_SAMPLER_2D_ARRAY_SHADOW:
698 case GL_SAMPLER_CUBE_SHADOW:
699 case GL_IMAGE_2D:
700 case GL_INT_IMAGE_2D:
701 case GL_UNSIGNED_INT_IMAGE_2D:
702 case GL_IMAGE_3D:
703 case GL_INT_IMAGE_3D:
704 case GL_UNSIGNED_INT_IMAGE_3D:
705 case GL_IMAGE_2D_ARRAY:
706 case GL_INT_IMAGE_2D_ARRAY:
707 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
708 case GL_IMAGE_CUBE:
709 case GL_INT_IMAGE_CUBE:
710 case GL_UNSIGNED_INT_IMAGE_CUBE:
711 case GL_UNSIGNED_INT_ATOMIC_COUNTER:
712 return 6;
Jamie Madill865d1452014-07-02 15:31:20 -0400713
Jamie Madill493f9572018-05-24 19:52:15 -0400714 default:
715 UNREACHABLE();
716 return 0;
Jamie Madill865d1452014-07-02 15:31:20 -0400717 }
718}
719
Olli Etuahoc8538042017-09-27 11:20:15 +0300720std::string ParseResourceName(const std::string &name, std::vector<unsigned int> *outSubscripts)
Geoff Langcfaeaa92015-04-14 13:41:02 -0400721{
Olli Etuahoc8538042017-09-27 11:20:15 +0300722 if (outSubscripts)
Geoff Langcfaeaa92015-04-14 13:41:02 -0400723 {
Olli Etuahoc8538042017-09-27 11:20:15 +0300724 outSubscripts->clear();
Geoff Langcfaeaa92015-04-14 13:41:02 -0400725 }
Olli Etuahoc8538042017-09-27 11:20:15 +0300726 // Strip any trailing array indexing operators and retrieve the subscripts.
727 size_t baseNameLength = name.length();
728 bool hasIndex = true;
729 while (hasIndex)
Geoff Langcfaeaa92015-04-14 13:41:02 -0400730 {
Olli Etuahoc8538042017-09-27 11:20:15 +0300731 size_t open = name.find_last_of('[', baseNameLength - 1);
732 size_t close = name.find_last_of(']', baseNameLength - 1);
733 hasIndex = (open != std::string::npos) && (close == baseNameLength - 1);
734 if (hasIndex)
Geoff Langcfaeaa92015-04-14 13:41:02 -0400735 {
Olli Etuahoc8538042017-09-27 11:20:15 +0300736 baseNameLength = open;
737 if (outSubscripts)
738 {
739 int index = atoi(name.substr(open + 1).c_str());
740 if (index >= 0)
741 {
742 outSubscripts->push_back(index);
743 }
744 else
745 {
746 outSubscripts->push_back(GL_INVALID_INDEX);
747 }
748 }
Geoff Langcfaeaa92015-04-14 13:41:02 -0400749 }
750 }
751
Olli Etuahoc8538042017-09-27 11:20:15 +0300752 return name.substr(0, baseNameLength);
Geoff Langcfaeaa92015-04-14 13:41:02 -0400753}
754
jchen108225e732017-11-14 16:29:03 +0800755const sh::ShaderVariable *FindShaderVarField(const sh::ShaderVariable &var,
756 const std::string &fullName)
757{
758 if (var.fields.empty())
759 {
760 return nullptr;
761 }
762 size_t pos = fullName.find_first_of(".");
763 if (pos == std::string::npos)
764 {
765 return nullptr;
766 }
767 std::string topName = fullName.substr(0, pos);
768 if (topName != var.name)
769 {
770 return nullptr;
771 }
772 std::string fieldName = fullName.substr(pos + 1);
773 if (fieldName.empty())
774 {
775 return nullptr;
776 }
777 for (const auto &field : var.fields)
778 {
779 if (field.name == fieldName)
780 {
781 return &field;
782 }
783 }
784 return nullptr;
785}
786
Olli Etuaho465835d2017-09-26 13:34:10 +0300787unsigned int ArraySizeProduct(const std::vector<unsigned int> &arraySizes)
788{
789 unsigned int arraySizeProduct = 1u;
790 for (unsigned int arraySize : arraySizes)
791 {
792 arraySizeProduct *= arraySize;
793 }
794 return arraySizeProduct;
795}
796
Olli Etuahod2551232017-10-26 20:03:33 +0300797unsigned int ParseArrayIndex(const std::string &name, size_t *nameLengthWithoutArrayIndexOut)
Jamie Madill4a3c2342015-10-08 12:58:45 -0400798{
Olli Etuahod2551232017-10-26 20:03:33 +0300799 ASSERT(nameLengthWithoutArrayIndexOut != nullptr);
Jamie Madill4a3c2342015-10-08 12:58:45 -0400800
801 // Strip any trailing array operator and retrieve the subscript
Olli Etuahod2551232017-10-26 20:03:33 +0300802 size_t open = name.find_last_of('[');
803 if (open != std::string::npos && name.back() == ']')
Jamie Madill4a3c2342015-10-08 12:58:45 -0400804 {
Olli Etuahod2551232017-10-26 20:03:33 +0300805 bool indexIsValidDecimalNumber = true;
806 for (size_t i = open + 1; i < name.length() - 1u; ++i)
807 {
808 if (!isdigit(name[i]))
809 {
810 indexIsValidDecimalNumber = false;
811 break;
812 }
813 }
814 if (indexIsValidDecimalNumber)
815 {
Bryan Bernhart (Intel Americas Inc)f4f293e2017-11-06 15:56:29 -0800816 errno = 0; // reset global error flag.
817 unsigned long subscript =
818 strtoul(name.c_str() + open + 1, /*endptr*/ nullptr, /*radix*/ 10);
819
820 // Check if resulting integer is out-of-range or conversion error.
821 if ((subscript <= static_cast<unsigned long>(UINT_MAX)) &&
822 !(subscript == ULONG_MAX && errno == ERANGE) && !(errno != 0 && subscript == 0))
823 {
824 *nameLengthWithoutArrayIndexOut = open;
825 return static_cast<unsigned int>(subscript);
826 }
Olli Etuahod2551232017-10-26 20:03:33 +0300827 }
Jamie Madill4a3c2342015-10-08 12:58:45 -0400828 }
829
Olli Etuahod2551232017-10-26 20:03:33 +0300830 *nameLengthWithoutArrayIndexOut = name.length();
Bryan Bernhart (Intel Americas Inc)f4f293e2017-11-06 15:56:29 -0800831 return GL_INVALID_INDEX;
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000832}
833
Geoff Langee6884e2017-11-09 16:51:11 -0500834const char *GetGenericErrorMessage(GLenum error)
835{
836 switch (error)
837 {
838 case GL_NO_ERROR:
839 return "";
840 case GL_INVALID_ENUM:
841 return "Invalid enum.";
842 case GL_INVALID_VALUE:
843 return "Invalid value.";
844 case GL_INVALID_OPERATION:
845 return "Invalid operation.";
846 case GL_STACK_OVERFLOW:
847 return "Stack overflow.";
848 case GL_STACK_UNDERFLOW:
849 return "Stack underflow.";
850 case GL_OUT_OF_MEMORY:
851 return "Out of memory.";
852 case GL_INVALID_FRAMEBUFFER_OPERATION:
853 return "Invalid framebuffer operation.";
854 default:
855 UNREACHABLE();
856 return "Unknown error.";
857 }
858}
859
Jamie Madill8957b6c2017-11-14 12:40:38 -0500860unsigned int ElementTypeSize(GLenum elementType)
861{
862 switch (elementType)
863 {
864 case GL_UNSIGNED_BYTE:
865 return sizeof(GLubyte);
866 case GL_UNSIGNED_SHORT:
867 return sizeof(GLushort);
868 case GL_UNSIGNED_INT:
869 return sizeof(GLuint);
870 default:
871 UNREACHABLE();
872 return 0;
873 }
874}
875
Jamie Madill4a3c2342015-10-08 12:58:45 -0400876} // namespace gl
877
Geoff Langa8406172015-07-21 16:53:39 -0400878namespace egl
879{
880static_assert(EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 1,
881 "Unexpected EGL cube map enum value.");
882static_assert(EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 2,
883 "Unexpected EGL cube map enum value.");
884static_assert(EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 3,
885 "Unexpected EGL cube map enum value.");
886static_assert(EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 4,
887 "Unexpected EGL cube map enum value.");
888static_assert(EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 5,
889 "Unexpected EGL cube map enum value.");
890
891bool IsCubeMapTextureTarget(EGLenum target)
892{
893 return (target >= FirstCubeMapTextureTarget && target <= LastCubeMapTextureTarget);
894}
895
896size_t CubeMapTextureTargetToLayerIndex(EGLenum target)
897{
898 ASSERT(IsCubeMapTextureTarget(target));
899 return target - static_cast<size_t>(FirstCubeMapTextureTarget);
900}
901
902EGLenum LayerIndexToCubeMapTextureTarget(size_t index)
903{
904 ASSERT(index <= (LastCubeMapTextureTarget - FirstCubeMapTextureTarget));
905 return FirstCubeMapTextureTarget + static_cast<GLenum>(index);
906}
907
908bool IsTextureTarget(EGLenum target)
909{
910 switch (target)
911 {
912 case EGL_GL_TEXTURE_2D_KHR:
913 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR:
914 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR:
915 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR:
916 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR:
917 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR:
918 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR:
919 case EGL_GL_TEXTURE_3D_KHR:
920 return true;
921
922 default:
923 return false;
924 }
925}
926
927bool IsRenderbufferTarget(EGLenum target)
928{
929 return target == EGL_GL_RENDERBUFFER_KHR;
930}
Geoff Langee6884e2017-11-09 16:51:11 -0500931
Geoff Langc3ee7ec2018-09-21 16:15:03 -0400932bool IsExternalImageTarget(EGLenum target)
933{
934 switch (target)
935 {
936 case EGL_NATIVE_BUFFER_ANDROID:
937 return true;
938
939 default:
940 return false;
941 }
942}
943
Geoff Langee6884e2017-11-09 16:51:11 -0500944const char *GetGenericErrorMessage(EGLint error)
945{
946 switch (error)
947 {
948 case EGL_SUCCESS:
949 return "";
950 case EGL_NOT_INITIALIZED:
951 return "Not initialized.";
952 case EGL_BAD_ACCESS:
953 return "Bad access.";
954 case EGL_BAD_ALLOC:
955 return "Bad allocation.";
956 case EGL_BAD_ATTRIBUTE:
957 return "Bad attribute.";
958 case EGL_BAD_CONFIG:
959 return "Bad config.";
960 case EGL_BAD_CONTEXT:
961 return "Bad context.";
962 case EGL_BAD_CURRENT_SURFACE:
963 return "Bad current surface.";
964 case EGL_BAD_DISPLAY:
965 return "Bad display.";
966 case EGL_BAD_MATCH:
967 return "Bad match.";
968 case EGL_BAD_NATIVE_WINDOW:
969 return "Bad native window.";
970 case EGL_BAD_PARAMETER:
971 return "Bad parameter.";
972 case EGL_BAD_SURFACE:
973 return "Bad surface.";
974 case EGL_CONTEXT_LOST:
975 return "Context lost.";
976 case EGL_BAD_STREAM_KHR:
977 return "Bad stream.";
978 case EGL_BAD_STATE_KHR:
979 return "Bad state.";
980 case EGL_BAD_DEVICE_EXT:
981 return "Bad device.";
982 default:
983 UNREACHABLE();
984 return "Unknown error.";
985 }
986}
987
Jamie Madill8b9b7922016-05-19 13:13:37 -0400988} // namespace egl
Geoff Langa8406172015-07-21 16:53:39 -0400989
990namespace egl_gl
991{
Geoff Langa8406172015-07-21 16:53:39 -0400992GLuint EGLClientBufferToGLObjectHandle(EGLClientBuffer buffer)
993{
994 return static_cast<GLuint>(reinterpret_cast<uintptr_t>(buffer));
995}
Jamie Madill8b9b7922016-05-19 13:13:37 -0400996} // namespace egl_gl
Geoff Langa8406172015-07-21 16:53:39 -0400997
Geoff Langc5a2a172017-01-13 15:55:07 -0500998namespace gl_egl
999{
1000EGLenum GLComponentTypeToEGLColorComponentType(GLenum glComponentType)
1001{
1002 switch (glComponentType)
1003 {
1004 case GL_FLOAT:
1005 return EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT;
1006
1007 case GL_UNSIGNED_NORMALIZED:
1008 return EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
1009
1010 default:
1011 UNREACHABLE();
1012 return EGL_NONE;
1013 }
1014}
Geoff Langdbd16122018-07-19 11:30:21 -04001015
1016EGLClientBuffer GLObjectHandleToEGLClientBuffer(GLuint handle)
1017{
1018 return reinterpret_cast<EGLClientBuffer>(static_cast<uintptr_t>(handle));
1019}
1020
Geoff Langc5a2a172017-01-13 15:55:07 -05001021} // namespace gl_egl
1022
Austin Kinross922a9fb2014-10-21 14:26:33 -07001023#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001024std::string getTempPath()
1025{
Jamie Madillb980c562018-11-27 11:34:27 -05001026# ifdef ANGLE_PLATFORM_WINDOWS
Austin Kinross922a9fb2014-10-21 14:26:33 -07001027 char path[MAX_PATH];
1028 DWORD pathLen = GetTempPathA(sizeof(path) / sizeof(path[0]), path);
1029 if (pathLen == 0)
1030 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00001031 UNREACHABLE();
1032 return std::string();
Austin Kinross922a9fb2014-10-21 14:26:33 -07001033 }
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00001034
Austin Kinross922a9fb2014-10-21 14:26:33 -07001035 UINT unique = GetTempFileNameA(path, "sh", 0, path);
1036 if (unique == 0)
1037 {
1038 UNREACHABLE();
1039 return std::string();
1040 }
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +00001041
Austin Kinross922a9fb2014-10-21 14:26:33 -07001042 return path;
Jamie Madillb980c562018-11-27 11:34:27 -05001043# else
Geoff Lang83217792014-01-16 09:52:38 -05001044 UNIMPLEMENTED();
1045 return "";
Jamie Madillb980c562018-11-27 11:34:27 -05001046# endif
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001047}
1048
Jamie Madill493f9572018-05-24 19:52:15 -04001049void writeFile(const char *path, const void *content, size_t size)
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00001050{
Jamie Madill493f9572018-05-24 19:52:15 -04001051 FILE *file = fopen(path, "w");
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00001052 if (!file)
1053 {
1054 UNREACHABLE();
1055 return;
1056 }
1057
1058 fwrite(content, sizeof(char), size, file);
1059 fclose(file);
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001060}
Jamie Madill493f9572018-05-24 19:52:15 -04001061#endif // !ANGLE_ENABLE_WINDOWS_STORE
Cooper Partin88d3b8c2014-10-08 10:41:56 -07001062
Jamie Madill493f9572018-05-24 19:52:15 -04001063#if defined(ANGLE_PLATFORM_WINDOWS)
Cooper Partin88d3b8c2014-10-08 10:41:56 -07001064
Cooper Partin1edac3b2014-11-20 13:49:27 -08001065// Causes the thread to relinquish the remainder of its time slice to any
1066// other thread that is ready to run.If there are no other threads ready
1067// to run, the function returns immediately, and the thread continues execution.
1068void ScheduleYield()
Cooper Partin88d3b8c2014-10-08 10:41:56 -07001069{
Geoff Lange5f735f2015-09-17 13:26:59 -04001070 Sleep(0);
Cooper Partin88d3b8c2014-10-08 10:41:56 -07001071}
1072
Kenneth Russellb23deb22014-11-21 14:53:56 -08001073#endif