blob: 644e46b3f0c9e8628b8f9ab5f9b5a63e7f4f7348 [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)
17# include <wrl.h>
18# include <wrl/wrappers/corewrappers.h>
19# include <windows.applicationmodel.core.h>
20# include <windows.graphics.display.h>
21#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{
105 switch(type)
106 {
107 case GL_BOOL:
108 case GL_BOOL_VEC2:
109 case GL_BOOL_VEC3:
110 case GL_BOOL_VEC4:
Nicolas Capense6050882013-07-08 10:43:10 -0400111 return GL_BOOL;
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000112 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:
shannon.woods%transgaming.com@gtempaccount.come6ca6702013-04-13 03:40:44 +0000119 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:
Nicolas Capense6050882013-07-08 10:43:10 -0400125 return GL_FLOAT;
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000126 case GL_INT:
daniel@transgaming.coma9cd70a2010-09-15 15:48:57 +0000127 case GL_SAMPLER_2D:
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400128 case GL_SAMPLER_2D_RECT_ANGLE:
Nicolas Capense6050882013-07-08 10:43:10 -0400129 case GL_SAMPLER_3D:
daniel@transgaming.coma9cd70a2010-09-15 15:48:57 +0000130 case GL_SAMPLER_CUBE:
Nicolas Capense6050882013-07-08 10:43:10 -0400131 case GL_SAMPLER_2D_ARRAY:
Ian Ewellbda75592016-04-18 17:25:54 -0400132 case GL_SAMPLER_EXTERNAL_OES:
JiangYizhou40219322016-12-09 09:50:51 +0800133 case GL_SAMPLER_2D_MULTISAMPLE:
Nicolas Capense6050882013-07-08 10:43:10 -0400134 case GL_INT_SAMPLER_2D:
135 case GL_INT_SAMPLER_3D:
136 case GL_INT_SAMPLER_CUBE:
137 case GL_INT_SAMPLER_2D_ARRAY:
JiangYizhou40219322016-12-09 09:50:51 +0800138 case GL_INT_SAMPLER_2D_MULTISAMPLE:
Nicolas Capense6050882013-07-08 10:43:10 -0400139 case GL_UNSIGNED_INT_SAMPLER_2D:
140 case GL_UNSIGNED_INT_SAMPLER_3D:
141 case GL_UNSIGNED_INT_SAMPLER_CUBE:
142 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
JiangYizhou40219322016-12-09 09:50:51 +0800143 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
Nicolas Capenscb127d32013-07-15 17:26:18 -0400144 case GL_SAMPLER_2D_SHADOW:
145 case GL_SAMPLER_CUBE_SHADOW:
146 case GL_SAMPLER_2D_ARRAY_SHADOW:
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000147 case GL_INT_VEC2:
148 case GL_INT_VEC3:
149 case GL_INT_VEC4:
Olli Etuahoceb10482017-02-13 12:31:03 +0000150 case GL_IMAGE_2D:
151 case GL_INT_IMAGE_2D:
152 case GL_UNSIGNED_INT_IMAGE_2D:
153 case GL_IMAGE_3D:
154 case GL_INT_IMAGE_3D:
155 case GL_UNSIGNED_INT_IMAGE_3D:
156 case GL_IMAGE_2D_ARRAY:
157 case GL_INT_IMAGE_2D_ARRAY:
158 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
159 case GL_IMAGE_CUBE:
160 case GL_INT_IMAGE_CUBE:
161 case GL_UNSIGNED_INT_IMAGE_CUBE:
jchen104cdac9e2017-05-08 11:01:20 +0800162 case GL_UNSIGNED_INT_ATOMIC_COUNTER:
Olli Etuahoceb10482017-02-13 12:31:03 +0000163 return GL_INT;
shannon.woods%transgaming.com@gtempaccount.com44ce5b12013-04-13 03:40:30 +0000164 case GL_UNSIGNED_INT:
165 case GL_UNSIGNED_INT_VEC2:
166 case GL_UNSIGNED_INT_VEC3:
167 case GL_UNSIGNED_INT_VEC4:
Nicolas Capense6050882013-07-08 10:43:10 -0400168 return GL_UNSIGNED_INT;
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000169 default:
Nicolas Capense6050882013-07-08 10:43:10 -0400170 UNREACHABLE();
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000171 }
172
173 return GL_NONE;
174}
175
Jamie Madillf2575982014-06-25 16:04:54 -0400176size_t VariableComponentSize(GLenum type)
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000177{
178 switch(type)
179 {
shannon.woods%transgaming.com@gtempaccount.com44ce5b12013-04-13 03:40:30 +0000180 case GL_BOOL: return sizeof(GLint);
181 case GL_FLOAT: return sizeof(GLfloat);
182 case GL_INT: return sizeof(GLint);
183 case GL_UNSIGNED_INT: return sizeof(GLuint);
jbauman@chromium.org72e8f442011-10-20 00:22:01 +0000184 default: UNREACHABLE();
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000185 }
186
jbauman@chromium.org72e8f442011-10-20 00:22:01 +0000187 return 0;
188}
189
Jamie Madillf2575982014-06-25 16:04:54 -0400190size_t VariableInternalSize(GLenum type)
jbauman@chromium.org72e8f442011-10-20 00:22:01 +0000191{
shannon.woods@transgaming.com2494c972013-02-28 23:10:03 +0000192 // Expanded to 4-element vectors
Jamie Madillf2575982014-06-25 16:04:54 -0400193 return VariableComponentSize(VariableComponentType(type)) * VariableRowCount(type) * 4;
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000194}
195
Jamie Madillf2575982014-06-25 16:04:54 -0400196size_t VariableExternalSize(GLenum type)
daniel@transgaming.com47c60052011-11-12 03:17:50 +0000197{
Jamie Madillf2575982014-06-25 16:04:54 -0400198 return VariableComponentSize(VariableComponentType(type)) * VariableComponentCount(type);
daniel@transgaming.com47c60052011-11-12 03:17:50 +0000199}
200
Jamie Madillf2575982014-06-25 16:04:54 -0400201GLenum VariableBoolVectorType(GLenum type)
shannon.woods%transgaming.com@gtempaccount.com8a19eed2013-04-13 03:40:22 +0000202{
203 switch (type)
204 {
205 case GL_FLOAT:
206 case GL_INT:
shannon.woods%transgaming.com@gtempaccount.com44ce5b12013-04-13 03:40:30 +0000207 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com8a19eed2013-04-13 03:40:22 +0000208 return GL_BOOL;
209 case GL_FLOAT_VEC2:
210 case GL_INT_VEC2:
shannon.woods%transgaming.com@gtempaccount.com44ce5b12013-04-13 03:40:30 +0000211 case GL_UNSIGNED_INT_VEC2:
shannon.woods%transgaming.com@gtempaccount.com8a19eed2013-04-13 03:40:22 +0000212 return GL_BOOL_VEC2;
213 case GL_FLOAT_VEC3:
214 case GL_INT_VEC3:
shannon.woods%transgaming.com@gtempaccount.com44ce5b12013-04-13 03:40:30 +0000215 case GL_UNSIGNED_INT_VEC3:
shannon.woods%transgaming.com@gtempaccount.com8a19eed2013-04-13 03:40:22 +0000216 return GL_BOOL_VEC3;
217 case GL_FLOAT_VEC4:
218 case GL_INT_VEC4:
shannon.woods%transgaming.com@gtempaccount.com44ce5b12013-04-13 03:40:30 +0000219 case GL_UNSIGNED_INT_VEC4:
shannon.woods%transgaming.com@gtempaccount.com8a19eed2013-04-13 03:40:22 +0000220 return GL_BOOL_VEC4;
221
222 default:
223 UNREACHABLE();
224 return GL_NONE;
225 }
226}
227
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000228int VariableRowCount(GLenum type)
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000229{
230 switch (type)
231 {
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000232 case GL_NONE:
233 return 0;
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000234 case GL_BOOL:
235 case GL_FLOAT:
236 case GL_INT:
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000237 case GL_UNSIGNED_INT:
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000238 case GL_BOOL_VEC2:
239 case GL_FLOAT_VEC2:
240 case GL_INT_VEC2:
shannonwoods@chromium.org8c788e82013-05-30 00:20:21 +0000241 case GL_UNSIGNED_INT_VEC2:
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000242 case GL_BOOL_VEC3:
shannonwoods@chromium.org8c788e82013-05-30 00:20:21 +0000243 case GL_FLOAT_VEC3:
244 case GL_INT_VEC3:
245 case GL_UNSIGNED_INT_VEC3:
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000246 case GL_BOOL_VEC4:
247 case GL_FLOAT_VEC4:
248 case GL_INT_VEC4:
shannonwoods@chromium.org8c788e82013-05-30 00:20:21 +0000249 case GL_UNSIGNED_INT_VEC4:
daniel@transgaming.comda8d3802012-12-20 21:12:55 +0000250 case GL_SAMPLER_2D:
Nicolas Capense6050882013-07-08 10:43:10 -0400251 case GL_SAMPLER_3D:
daniel@transgaming.comda8d3802012-12-20 21:12:55 +0000252 case GL_SAMPLER_CUBE:
Nicolas Capense6050882013-07-08 10:43:10 -0400253 case GL_SAMPLER_2D_ARRAY:
Jamie Madillaa72d782014-07-02 15:31:19 -0400254 case GL_SAMPLER_EXTERNAL_OES:
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400255 case GL_SAMPLER_2D_RECT_ANGLE:
JiangYizhou40219322016-12-09 09:50:51 +0800256 case GL_SAMPLER_2D_MULTISAMPLE:
Nicolas Capense6050882013-07-08 10:43:10 -0400257 case GL_INT_SAMPLER_2D:
258 case GL_INT_SAMPLER_3D:
259 case GL_INT_SAMPLER_CUBE:
260 case GL_INT_SAMPLER_2D_ARRAY:
JiangYizhou40219322016-12-09 09:50:51 +0800261 case GL_INT_SAMPLER_2D_MULTISAMPLE:
Nicolas Capense6050882013-07-08 10:43:10 -0400262 case GL_UNSIGNED_INT_SAMPLER_2D:
263 case GL_UNSIGNED_INT_SAMPLER_3D:
264 case GL_UNSIGNED_INT_SAMPLER_CUBE:
265 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
JiangYizhou40219322016-12-09 09:50:51 +0800266 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
Nicolas Capenscb127d32013-07-15 17:26:18 -0400267 case GL_SAMPLER_2D_SHADOW:
268 case GL_SAMPLER_CUBE_SHADOW:
269 case GL_SAMPLER_2D_ARRAY_SHADOW:
Martin Radev2cc85b32016-08-05 16:22:53 +0300270 case GL_IMAGE_2D:
271 case GL_INT_IMAGE_2D:
272 case GL_UNSIGNED_INT_IMAGE_2D:
273 case GL_IMAGE_2D_ARRAY:
274 case GL_INT_IMAGE_2D_ARRAY:
275 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
276 case GL_IMAGE_3D:
277 case GL_INT_IMAGE_3D:
278 case GL_UNSIGNED_INT_IMAGE_3D:
279 case GL_IMAGE_CUBE:
280 case GL_INT_IMAGE_CUBE:
281 case GL_UNSIGNED_INT_IMAGE_CUBE:
jchen104cdac9e2017-05-08 11:01:20 +0800282 case GL_UNSIGNED_INT_ATOMIC_COUNTER:
Martin Radev2cc85b32016-08-05 16:22:53 +0300283 return 1;
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000284 case GL_FLOAT_MAT2:
shannon.woods%transgaming.com@gtempaccount.com02e11f32013-04-13 03:40:50 +0000285 case GL_FLOAT_MAT3x2:
286 case GL_FLOAT_MAT4x2:
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000287 return 2;
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000288 case GL_FLOAT_MAT3:
shannon.woods%transgaming.com@gtempaccount.com02e11f32013-04-13 03:40:50 +0000289 case GL_FLOAT_MAT2x3:
290 case GL_FLOAT_MAT4x3:
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000291 return 3;
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000292 case GL_FLOAT_MAT4:
shannon.woods%transgaming.com@gtempaccount.com02e11f32013-04-13 03:40:50 +0000293 case GL_FLOAT_MAT2x4:
294 case GL_FLOAT_MAT3x4:
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000295 return 4;
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000296 default:
297 UNREACHABLE();
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000298 }
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000299
300 return 0;
301}
302
303int VariableColumnCount(GLenum type)
304{
305 switch (type)
306 {
307 case GL_NONE:
308 return 0;
309 case GL_BOOL:
310 case GL_FLOAT:
311 case GL_INT:
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000312 case GL_UNSIGNED_INT:
shannon.woods@transgaming.com2494c972013-02-28 23:10:03 +0000313 case GL_SAMPLER_2D:
Nicolas Capense6050882013-07-08 10:43:10 -0400314 case GL_SAMPLER_3D:
shannon.woods@transgaming.com2494c972013-02-28 23:10:03 +0000315 case GL_SAMPLER_CUBE:
Nicolas Capense6050882013-07-08 10:43:10 -0400316 case GL_SAMPLER_2D_ARRAY:
JiangYizhou40219322016-12-09 09:50:51 +0800317 case GL_SAMPLER_2D_MULTISAMPLE:
Nicolas Capense6050882013-07-08 10:43:10 -0400318 case GL_INT_SAMPLER_2D:
319 case GL_INT_SAMPLER_3D:
320 case GL_INT_SAMPLER_CUBE:
321 case GL_INT_SAMPLER_2D_ARRAY:
JiangYizhou40219322016-12-09 09:50:51 +0800322 case GL_INT_SAMPLER_2D_MULTISAMPLE:
Jamie Madillaa72d782014-07-02 15:31:19 -0400323 case GL_SAMPLER_EXTERNAL_OES:
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400324 case GL_SAMPLER_2D_RECT_ANGLE:
Nicolas Capense6050882013-07-08 10:43:10 -0400325 case GL_UNSIGNED_INT_SAMPLER_2D:
326 case GL_UNSIGNED_INT_SAMPLER_3D:
327 case GL_UNSIGNED_INT_SAMPLER_CUBE:
328 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
JiangYizhou40219322016-12-09 09:50:51 +0800329 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
Nicolas Capenscb127d32013-07-15 17:26:18 -0400330 case GL_SAMPLER_2D_SHADOW:
331 case GL_SAMPLER_CUBE_SHADOW:
332 case GL_SAMPLER_2D_ARRAY_SHADOW:
Olli Etuahoceb10482017-02-13 12:31:03 +0000333 case GL_IMAGE_2D:
334 case GL_INT_IMAGE_2D:
335 case GL_UNSIGNED_INT_IMAGE_2D:
336 case GL_IMAGE_3D:
337 case GL_INT_IMAGE_3D:
338 case GL_UNSIGNED_INT_IMAGE_3D:
339 case GL_IMAGE_2D_ARRAY:
340 case GL_INT_IMAGE_2D_ARRAY:
341 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
342 case GL_IMAGE_CUBE:
343 case GL_INT_IMAGE_CUBE:
344 case GL_UNSIGNED_INT_IMAGE_CUBE:
jchen104cdac9e2017-05-08 11:01:20 +0800345 case GL_UNSIGNED_INT_ATOMIC_COUNTER:
Olli Etuahoceb10482017-02-13 12:31:03 +0000346 return 1;
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000347 case GL_BOOL_VEC2:
348 case GL_FLOAT_VEC2:
349 case GL_INT_VEC2:
shannonwoods@chromium.org8c788e82013-05-30 00:20:21 +0000350 case GL_UNSIGNED_INT_VEC2:
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000351 case GL_FLOAT_MAT2:
shannon.woods%transgaming.com@gtempaccount.com02e11f32013-04-13 03:40:50 +0000352 case GL_FLOAT_MAT2x3:
353 case GL_FLOAT_MAT2x4:
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000354 return 2;
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000355 case GL_BOOL_VEC3:
shannonwoods@chromium.org8c788e82013-05-30 00:20:21 +0000356 case GL_FLOAT_VEC3:
357 case GL_INT_VEC3:
358 case GL_UNSIGNED_INT_VEC3:
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000359 case GL_FLOAT_MAT3:
shannon.woods%transgaming.com@gtempaccount.com02e11f32013-04-13 03:40:50 +0000360 case GL_FLOAT_MAT3x2:
361 case GL_FLOAT_MAT3x4:
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000362 return 3;
363 case GL_BOOL_VEC4:
364 case GL_FLOAT_VEC4:
365 case GL_INT_VEC4:
shannonwoods@chromium.org8c788e82013-05-30 00:20:21 +0000366 case GL_UNSIGNED_INT_VEC4:
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000367 case GL_FLOAT_MAT4:
shannon.woods%transgaming.com@gtempaccount.com02e11f32013-04-13 03:40:50 +0000368 case GL_FLOAT_MAT4x2:
369 case GL_FLOAT_MAT4x3:
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000370 return 4;
371 default:
372 UNREACHABLE();
373 }
374
375 return 0;
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000376}
377
Geoff Lang2ec386b2014-12-03 14:44:38 -0500378bool IsSamplerType(GLenum type)
Nicolas Capense6050882013-07-08 10:43:10 -0400379{
380 switch (type)
381 {
382 case GL_SAMPLER_2D:
383 case GL_SAMPLER_3D:
384 case GL_SAMPLER_CUBE:
385 case GL_SAMPLER_2D_ARRAY:
Ian Ewellbda75592016-04-18 17:25:54 -0400386 case GL_SAMPLER_EXTERNAL_OES:
JiangYizhou40219322016-12-09 09:50:51 +0800387 case GL_SAMPLER_2D_MULTISAMPLE:
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400388 case GL_SAMPLER_2D_RECT_ANGLE:
Nicolas Capense6050882013-07-08 10:43:10 -0400389 case GL_INT_SAMPLER_2D:
390 case GL_INT_SAMPLER_3D:
391 case GL_INT_SAMPLER_CUBE:
392 case GL_INT_SAMPLER_2D_ARRAY:
JiangYizhou40219322016-12-09 09:50:51 +0800393 case GL_INT_SAMPLER_2D_MULTISAMPLE:
Nicolas Capense6050882013-07-08 10:43:10 -0400394 case GL_UNSIGNED_INT_SAMPLER_2D:
395 case GL_UNSIGNED_INT_SAMPLER_3D:
396 case GL_UNSIGNED_INT_SAMPLER_CUBE:
397 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
JiangYizhou40219322016-12-09 09:50:51 +0800398 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
Nicolas Capenscb127d32013-07-15 17:26:18 -0400399 case GL_SAMPLER_2D_SHADOW:
400 case GL_SAMPLER_CUBE_SHADOW:
401 case GL_SAMPLER_2D_ARRAY_SHADOW:
Nicolas Capense6050882013-07-08 10:43:10 -0400402 return true;
403 }
404
405 return false;
406}
407
Olli Etuahoceb10482017-02-13 12:31:03 +0000408bool IsImageType(GLenum type)
409{
410 switch (type)
411 {
412 case GL_IMAGE_2D:
413 case GL_INT_IMAGE_2D:
414 case GL_UNSIGNED_INT_IMAGE_2D:
415 case GL_IMAGE_3D:
416 case GL_INT_IMAGE_3D:
417 case GL_UNSIGNED_INT_IMAGE_3D:
418 case GL_IMAGE_2D_ARRAY:
419 case GL_INT_IMAGE_2D_ARRAY:
420 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
421 case GL_IMAGE_CUBE:
422 case GL_INT_IMAGE_CUBE:
423 case GL_UNSIGNED_INT_IMAGE_CUBE:
424 return true;
425 }
426 return false;
427}
428
jchen104cdac9e2017-05-08 11:01:20 +0800429bool IsAtomicCounterType(GLenum type)
430{
431 return type == GL_UNSIGNED_INT_ATOMIC_COUNTER;
432}
433
Olli Etuahoceb10482017-02-13 12:31:03 +0000434bool IsOpaqueType(GLenum type)
435{
436 // ESSL 3.10 section 4.1.7 defines opaque types as: samplers, images and atomic counters.
jchen104cdac9e2017-05-08 11:01:20 +0800437 return IsImageType(type) || IsSamplerType(type) || IsAtomicCounterType(type);
Olli Etuahoceb10482017-02-13 12:31:03 +0000438}
439
shannon.woods%transgaming.com@gtempaccount.com02e11f32013-04-13 03:40:50 +0000440bool IsMatrixType(GLenum type)
441{
442 return VariableRowCount(type) > 1;
443}
444
shannonwoods@chromium.org9bd22fa2013-05-30 00:18:47 +0000445GLenum TransposeMatrixType(GLenum type)
446{
447 if (!IsMatrixType(type))
448 {
449 return type;
450 }
451
452 switch (type)
453 {
454 case GL_FLOAT_MAT2: return GL_FLOAT_MAT2;
455 case GL_FLOAT_MAT3: return GL_FLOAT_MAT3;
456 case GL_FLOAT_MAT4: return GL_FLOAT_MAT4;
457 case GL_FLOAT_MAT2x3: return GL_FLOAT_MAT3x2;
458 case GL_FLOAT_MAT3x2: return GL_FLOAT_MAT2x3;
459 case GL_FLOAT_MAT2x4: return GL_FLOAT_MAT4x2;
460 case GL_FLOAT_MAT4x2: return GL_FLOAT_MAT2x4;
461 case GL_FLOAT_MAT3x4: return GL_FLOAT_MAT4x3;
462 case GL_FLOAT_MAT4x3: return GL_FLOAT_MAT3x4;
463 default: UNREACHABLE(); return GL_NONE;
464 }
465}
466
Jamie Madill8c6befc2013-06-20 11:55:55 -0400467int MatrixRegisterCount(GLenum type, bool isRowMajorMatrix)
468{
469 ASSERT(IsMatrixType(type));
470 return isRowMajorMatrix ? VariableRowCount(type) : VariableColumnCount(type);
471}
472
473int MatrixComponentCount(GLenum type, bool isRowMajorMatrix)
474{
475 ASSERT(IsMatrixType(type));
476 return isRowMajorMatrix ? VariableColumnCount(type) : VariableRowCount(type);
477}
478
Jamie Madillf2575982014-06-25 16:04:54 -0400479int VariableRegisterCount(GLenum type)
shannonwoods@chromium.org9bd22fa2013-05-30 00:18:47 +0000480{
481 return IsMatrixType(type) ? VariableColumnCount(type) : 1;
482}
483
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +0000484int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize)
485{
486 ASSERT(allocationSize <= bitsSize);
487
488 unsigned int mask = std::numeric_limits<unsigned int>::max() >> (std::numeric_limits<unsigned int>::digits - allocationSize);
489
490 for (unsigned int i = 0; i < bitsSize - allocationSize + 1; i++)
491 {
492 if ((*bits & mask) == 0)
493 {
494 *bits |= mask;
495 return i;
496 }
497
498 mask <<= 1;
499 }
500
501 return -1;
502}
503
Geoff Lang3edfe032015-09-04 16:38:24 -0400504IndexRange ComputeIndexRange(GLenum indexType,
505 const GLvoid *indices,
506 size_t count,
507 bool primitiveRestartEnabled)
Geoff Lang831b1952015-05-05 11:02:27 -0400508{
509 switch (indexType)
510 {
Geoff Lang3edfe032015-09-04 16:38:24 -0400511 case GL_UNSIGNED_BYTE:
512 return ComputeTypedIndexRange(static_cast<const GLubyte *>(indices), count,
513 primitiveRestartEnabled,
514 GetPrimitiveRestartIndex(indexType));
515 case GL_UNSIGNED_SHORT:
516 return ComputeTypedIndexRange(static_cast<const GLushort *>(indices), count,
517 primitiveRestartEnabled,
518 GetPrimitiveRestartIndex(indexType));
519 case GL_UNSIGNED_INT:
520 return ComputeTypedIndexRange(static_cast<const GLuint *>(indices), count,
521 primitiveRestartEnabled,
522 GetPrimitiveRestartIndex(indexType));
523 default:
524 UNREACHABLE();
525 return IndexRange();
526 }
527}
528
529GLuint GetPrimitiveRestartIndex(GLenum indexType)
530{
531 switch (indexType)
532 {
533 case GL_UNSIGNED_BYTE:
534 return 0xFF;
535 case GL_UNSIGNED_SHORT:
536 return 0xFFFF;
537 case GL_UNSIGNED_INT:
538 return 0xFFFFFFFF;
539 default:
540 UNREACHABLE();
541 return 0;
Geoff Lang831b1952015-05-05 11:02:27 -0400542 }
543}
544
daniel@transgaming.com97c852b2012-12-20 20:56:23 +0000545bool IsTriangleMode(GLenum drawMode)
546{
547 switch (drawMode)
548 {
549 case GL_TRIANGLES:
550 case GL_TRIANGLE_FAN:
551 case GL_TRIANGLE_STRIP:
552 return true;
553 case GL_POINTS:
554 case GL_LINES:
555 case GL_LINE_LOOP:
556 case GL_LINE_STRIP:
557 return false;
558 default: UNREACHABLE();
559 }
560
561 return false;
562}
563
Geoff Lang4f0e0032017-05-01 16:04:35 -0400564bool IsIntegerFormat(GLenum unsizedFormat)
565{
566 switch (unsizedFormat)
567 {
568 case GL_RGBA_INTEGER:
569 case GL_RGB_INTEGER:
570 case GL_RG_INTEGER:
571 case GL_RED_INTEGER:
572 return true;
573
574 default:
575 return false;
576 }
577}
578
Jamie Madill865d1452014-07-02 15:31:20 -0400579// [OpenGL ES SL 3.00.4] Section 11 p. 120
580// Vertex Outs/Fragment Ins packing priorities
581int VariableSortOrder(GLenum type)
582{
583 switch (type)
584 {
585 // 1. Arrays of mat4 and mat4
586 // Non-square matrices of type matCxR consume the same space as a square
587 // matrix of type matN where N is the greater of C and R
588 case GL_FLOAT_MAT4:
589 case GL_FLOAT_MAT2x4:
590 case GL_FLOAT_MAT3x4:
591 case GL_FLOAT_MAT4x2:
592 case GL_FLOAT_MAT4x3:
593 return 0;
594
595 // 2. Arrays of mat2 and mat2 (since they occupy full rows)
596 case GL_FLOAT_MAT2:
597 return 1;
598
599 // 3. Arrays of vec4 and vec4
600 case GL_FLOAT_VEC4:
601 case GL_INT_VEC4:
602 case GL_BOOL_VEC4:
603 case GL_UNSIGNED_INT_VEC4:
604 return 2;
605
606 // 4. Arrays of mat3 and mat3
607 case GL_FLOAT_MAT3:
608 case GL_FLOAT_MAT2x3:
609 case GL_FLOAT_MAT3x2:
610 return 3;
611
612 // 5. Arrays of vec3 and vec3
613 case GL_FLOAT_VEC3:
614 case GL_INT_VEC3:
615 case GL_BOOL_VEC3:
616 case GL_UNSIGNED_INT_VEC3:
617 return 4;
618
619 // 6. Arrays of vec2 and vec2
620 case GL_FLOAT_VEC2:
621 case GL_INT_VEC2:
622 case GL_BOOL_VEC2:
623 case GL_UNSIGNED_INT_VEC2:
624 return 5;
625
626 // 7. Single component types
627 case GL_FLOAT:
628 case GL_INT:
629 case GL_BOOL:
630 case GL_UNSIGNED_INT:
631 case GL_SAMPLER_2D:
632 case GL_SAMPLER_CUBE:
633 case GL_SAMPLER_EXTERNAL_OES:
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400634 case GL_SAMPLER_2D_RECT_ANGLE:
Jamie Madill865d1452014-07-02 15:31:20 -0400635 case GL_SAMPLER_2D_ARRAY:
JiangYizhou40219322016-12-09 09:50:51 +0800636 case GL_SAMPLER_2D_MULTISAMPLE:
Jamie Madill865d1452014-07-02 15:31:20 -0400637 case GL_SAMPLER_3D:
638 case GL_INT_SAMPLER_2D:
639 case GL_INT_SAMPLER_3D:
640 case GL_INT_SAMPLER_CUBE:
641 case GL_INT_SAMPLER_2D_ARRAY:
JiangYizhou40219322016-12-09 09:50:51 +0800642 case GL_INT_SAMPLER_2D_MULTISAMPLE:
Jamie Madill865d1452014-07-02 15:31:20 -0400643 case GL_UNSIGNED_INT_SAMPLER_2D:
644 case GL_UNSIGNED_INT_SAMPLER_3D:
645 case GL_UNSIGNED_INT_SAMPLER_CUBE:
646 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
JiangYizhou40219322016-12-09 09:50:51 +0800647 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
Jamie Madill865d1452014-07-02 15:31:20 -0400648 case GL_SAMPLER_2D_SHADOW:
649 case GL_SAMPLER_2D_ARRAY_SHADOW:
650 case GL_SAMPLER_CUBE_SHADOW:
jchen1005c31da2017-07-18 16:11:39 +0800651 case GL_IMAGE_2D:
652 case GL_INT_IMAGE_2D:
653 case GL_UNSIGNED_INT_IMAGE_2D:
654 case GL_IMAGE_3D:
655 case GL_INT_IMAGE_3D:
656 case GL_UNSIGNED_INT_IMAGE_3D:
657 case GL_IMAGE_2D_ARRAY:
658 case GL_INT_IMAGE_2D_ARRAY:
659 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
660 case GL_IMAGE_CUBE:
661 case GL_INT_IMAGE_CUBE:
662 case GL_UNSIGNED_INT_IMAGE_CUBE:
663 case GL_UNSIGNED_INT_ATOMIC_COUNTER:
664 return 6;
Jamie Madill865d1452014-07-02 15:31:20 -0400665
666 default:
667 UNREACHABLE();
668 return 0;
669 }
670}
671
Olli Etuahoc8538042017-09-27 11:20:15 +0300672std::string ParseResourceName(const std::string &name, std::vector<unsigned int> *outSubscripts)
Geoff Langcfaeaa92015-04-14 13:41:02 -0400673{
Olli Etuahoc8538042017-09-27 11:20:15 +0300674 if (outSubscripts)
Geoff Langcfaeaa92015-04-14 13:41:02 -0400675 {
Olli Etuahoc8538042017-09-27 11:20:15 +0300676 outSubscripts->clear();
Geoff Langcfaeaa92015-04-14 13:41:02 -0400677 }
Olli Etuahoc8538042017-09-27 11:20:15 +0300678 // Strip any trailing array indexing operators and retrieve the subscripts.
679 size_t baseNameLength = name.length();
680 bool hasIndex = true;
681 while (hasIndex)
Geoff Langcfaeaa92015-04-14 13:41:02 -0400682 {
Olli Etuahoc8538042017-09-27 11:20:15 +0300683 size_t open = name.find_last_of('[', baseNameLength - 1);
684 size_t close = name.find_last_of(']', baseNameLength - 1);
685 hasIndex = (open != std::string::npos) && (close == baseNameLength - 1);
686 if (hasIndex)
Geoff Langcfaeaa92015-04-14 13:41:02 -0400687 {
Olli Etuahoc8538042017-09-27 11:20:15 +0300688 baseNameLength = open;
689 if (outSubscripts)
690 {
691 int index = atoi(name.substr(open + 1).c_str());
692 if (index >= 0)
693 {
694 outSubscripts->push_back(index);
695 }
696 else
697 {
698 outSubscripts->push_back(GL_INVALID_INDEX);
699 }
700 }
Geoff Langcfaeaa92015-04-14 13:41:02 -0400701 }
702 }
703
Olli Etuahoc8538042017-09-27 11:20:15 +0300704 return name.substr(0, baseNameLength);
Geoff Langcfaeaa92015-04-14 13:41:02 -0400705}
706
jchen108225e732017-11-14 16:29:03 +0800707const sh::ShaderVariable *FindShaderVarField(const sh::ShaderVariable &var,
708 const std::string &fullName)
709{
710 if (var.fields.empty())
711 {
712 return nullptr;
713 }
714 size_t pos = fullName.find_first_of(".");
715 if (pos == std::string::npos)
716 {
717 return nullptr;
718 }
719 std::string topName = fullName.substr(0, pos);
720 if (topName != var.name)
721 {
722 return nullptr;
723 }
724 std::string fieldName = fullName.substr(pos + 1);
725 if (fieldName.empty())
726 {
727 return nullptr;
728 }
729 for (const auto &field : var.fields)
730 {
731 if (field.name == fieldName)
732 {
733 return &field;
734 }
735 }
736 return nullptr;
737}
738
Olli Etuaho465835d2017-09-26 13:34:10 +0300739unsigned int ArraySizeProduct(const std::vector<unsigned int> &arraySizes)
740{
741 unsigned int arraySizeProduct = 1u;
742 for (unsigned int arraySize : arraySizes)
743 {
744 arraySizeProduct *= arraySize;
745 }
746 return arraySizeProduct;
747}
748
Olli Etuahod2551232017-10-26 20:03:33 +0300749unsigned int ParseArrayIndex(const std::string &name, size_t *nameLengthWithoutArrayIndexOut)
Jamie Madill4a3c2342015-10-08 12:58:45 -0400750{
Olli Etuahod2551232017-10-26 20:03:33 +0300751 ASSERT(nameLengthWithoutArrayIndexOut != nullptr);
Jamie Madill4a3c2342015-10-08 12:58:45 -0400752
753 // Strip any trailing array operator and retrieve the subscript
Olli Etuahod2551232017-10-26 20:03:33 +0300754 size_t open = name.find_last_of('[');
755 if (open != std::string::npos && name.back() == ']')
Jamie Madill4a3c2342015-10-08 12:58:45 -0400756 {
Olli Etuahod2551232017-10-26 20:03:33 +0300757 bool indexIsValidDecimalNumber = true;
758 for (size_t i = open + 1; i < name.length() - 1u; ++i)
759 {
760 if (!isdigit(name[i]))
761 {
762 indexIsValidDecimalNumber = false;
763 break;
764 }
765 }
766 if (indexIsValidDecimalNumber)
767 {
Bryan Bernhart (Intel Americas Inc)f4f293e2017-11-06 15:56:29 -0800768 errno = 0; // reset global error flag.
769 unsigned long subscript =
770 strtoul(name.c_str() + open + 1, /*endptr*/ nullptr, /*radix*/ 10);
771
772 // Check if resulting integer is out-of-range or conversion error.
773 if ((subscript <= static_cast<unsigned long>(UINT_MAX)) &&
774 !(subscript == ULONG_MAX && errno == ERANGE) && !(errno != 0 && subscript == 0))
775 {
776 *nameLengthWithoutArrayIndexOut = open;
777 return static_cast<unsigned int>(subscript);
778 }
Olli Etuahod2551232017-10-26 20:03:33 +0300779 }
Jamie Madill4a3c2342015-10-08 12:58:45 -0400780 }
781
Olli Etuahod2551232017-10-26 20:03:33 +0300782 *nameLengthWithoutArrayIndexOut = name.length();
Bryan Bernhart (Intel Americas Inc)f4f293e2017-11-06 15:56:29 -0800783 return GL_INVALID_INDEX;
daniel@transgaming.com1b3a8152010-04-22 13:35:37 +0000784}
785
Geoff Langee6884e2017-11-09 16:51:11 -0500786const char *GetGenericErrorMessage(GLenum error)
787{
788 switch (error)
789 {
790 case GL_NO_ERROR:
791 return "";
792 case GL_INVALID_ENUM:
793 return "Invalid enum.";
794 case GL_INVALID_VALUE:
795 return "Invalid value.";
796 case GL_INVALID_OPERATION:
797 return "Invalid operation.";
798 case GL_STACK_OVERFLOW:
799 return "Stack overflow.";
800 case GL_STACK_UNDERFLOW:
801 return "Stack underflow.";
802 case GL_OUT_OF_MEMORY:
803 return "Out of memory.";
804 case GL_INVALID_FRAMEBUFFER_OPERATION:
805 return "Invalid framebuffer operation.";
806 default:
807 UNREACHABLE();
808 return "Unknown error.";
809 }
810}
811
Jamie Madill8957b6c2017-11-14 12:40:38 -0500812unsigned int ElementTypeSize(GLenum elementType)
813{
814 switch (elementType)
815 {
816 case GL_UNSIGNED_BYTE:
817 return sizeof(GLubyte);
818 case GL_UNSIGNED_SHORT:
819 return sizeof(GLushort);
820 case GL_UNSIGNED_INT:
821 return sizeof(GLuint);
822 default:
823 UNREACHABLE();
824 return 0;
825 }
826}
827
Jamie Madill4a3c2342015-10-08 12:58:45 -0400828} // namespace gl
829
Geoff Langa8406172015-07-21 16:53:39 -0400830namespace egl
831{
832static_assert(EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 1,
833 "Unexpected EGL cube map enum value.");
834static_assert(EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 2,
835 "Unexpected EGL cube map enum value.");
836static_assert(EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 3,
837 "Unexpected EGL cube map enum value.");
838static_assert(EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 4,
839 "Unexpected EGL cube map enum value.");
840static_assert(EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 5,
841 "Unexpected EGL cube map enum value.");
842
843bool IsCubeMapTextureTarget(EGLenum target)
844{
845 return (target >= FirstCubeMapTextureTarget && target <= LastCubeMapTextureTarget);
846}
847
848size_t CubeMapTextureTargetToLayerIndex(EGLenum target)
849{
850 ASSERT(IsCubeMapTextureTarget(target));
851 return target - static_cast<size_t>(FirstCubeMapTextureTarget);
852}
853
854EGLenum LayerIndexToCubeMapTextureTarget(size_t index)
855{
856 ASSERT(index <= (LastCubeMapTextureTarget - FirstCubeMapTextureTarget));
857 return FirstCubeMapTextureTarget + static_cast<GLenum>(index);
858}
859
860bool IsTextureTarget(EGLenum target)
861{
862 switch (target)
863 {
864 case EGL_GL_TEXTURE_2D_KHR:
865 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR:
866 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR:
867 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR:
868 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR:
869 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR:
870 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR:
871 case EGL_GL_TEXTURE_3D_KHR:
872 return true;
873
874 default:
875 return false;
876 }
877}
878
879bool IsRenderbufferTarget(EGLenum target)
880{
881 return target == EGL_GL_RENDERBUFFER_KHR;
882}
Geoff Langee6884e2017-11-09 16:51:11 -0500883
884const char *GetGenericErrorMessage(EGLint error)
885{
886 switch (error)
887 {
888 case EGL_SUCCESS:
889 return "";
890 case EGL_NOT_INITIALIZED:
891 return "Not initialized.";
892 case EGL_BAD_ACCESS:
893 return "Bad access.";
894 case EGL_BAD_ALLOC:
895 return "Bad allocation.";
896 case EGL_BAD_ATTRIBUTE:
897 return "Bad attribute.";
898 case EGL_BAD_CONFIG:
899 return "Bad config.";
900 case EGL_BAD_CONTEXT:
901 return "Bad context.";
902 case EGL_BAD_CURRENT_SURFACE:
903 return "Bad current surface.";
904 case EGL_BAD_DISPLAY:
905 return "Bad display.";
906 case EGL_BAD_MATCH:
907 return "Bad match.";
908 case EGL_BAD_NATIVE_WINDOW:
909 return "Bad native window.";
910 case EGL_BAD_PARAMETER:
911 return "Bad parameter.";
912 case EGL_BAD_SURFACE:
913 return "Bad surface.";
914 case EGL_CONTEXT_LOST:
915 return "Context lost.";
916 case EGL_BAD_STREAM_KHR:
917 return "Bad stream.";
918 case EGL_BAD_STATE_KHR:
919 return "Bad state.";
920 case EGL_BAD_DEVICE_EXT:
921 return "Bad device.";
922 default:
923 UNREACHABLE();
924 return "Unknown error.";
925 }
926}
927
Jamie Madill8b9b7922016-05-19 13:13:37 -0400928} // namespace egl
Geoff Langa8406172015-07-21 16:53:39 -0400929
930namespace egl_gl
931{
Geoff Langa8406172015-07-21 16:53:39 -0400932GLuint EGLClientBufferToGLObjectHandle(EGLClientBuffer buffer)
933{
934 return static_cast<GLuint>(reinterpret_cast<uintptr_t>(buffer));
935}
Jamie Madill8b9b7922016-05-19 13:13:37 -0400936} // namespace egl_gl
Geoff Langa8406172015-07-21 16:53:39 -0400937
Geoff Langc5a2a172017-01-13 15:55:07 -0500938namespace gl_egl
939{
940EGLenum GLComponentTypeToEGLColorComponentType(GLenum glComponentType)
941{
942 switch (glComponentType)
943 {
944 case GL_FLOAT:
945 return EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT;
946
947 case GL_UNSIGNED_NORMALIZED:
948 return EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
949
950 default:
951 UNREACHABLE();
952 return EGL_NONE;
953 }
954}
955} // namespace gl_egl
956
Austin Kinross922a9fb2014-10-21 14:26:33 -0700957#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000958std::string getTempPath()
959{
Shannon Woodsfb839472014-06-16 13:21:41 -0400960#ifdef ANGLE_PLATFORM_WINDOWS
Austin Kinross922a9fb2014-10-21 14:26:33 -0700961 char path[MAX_PATH];
962 DWORD pathLen = GetTempPathA(sizeof(path) / sizeof(path[0]), path);
963 if (pathLen == 0)
964 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000965 UNREACHABLE();
966 return std::string();
Austin Kinross922a9fb2014-10-21 14:26:33 -0700967 }
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000968
Austin Kinross922a9fb2014-10-21 14:26:33 -0700969 UINT unique = GetTempFileNameA(path, "sh", 0, path);
970 if (unique == 0)
971 {
972 UNREACHABLE();
973 return std::string();
974 }
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +0000975
Austin Kinross922a9fb2014-10-21 14:26:33 -0700976 return path;
Geoff Lang83217792014-01-16 09:52:38 -0500977#else
978 UNIMPLEMENTED();
979 return "";
980#endif
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000981}
982
983void writeFile(const char* path, const void* content, size_t size)
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000984{
985 FILE* file = fopen(path, "w");
986 if (!file)
987 {
988 UNREACHABLE();
989 return;
990 }
991
992 fwrite(content, sizeof(char), size, file);
993 fclose(file);
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000994}
Austin Kinross922a9fb2014-10-21 14:26:33 -0700995#endif // !ANGLE_ENABLE_WINDOWS_STORE
Cooper Partin88d3b8c2014-10-08 10:41:56 -0700996
Cooper Partin1edac3b2014-11-20 13:49:27 -0800997#if defined (ANGLE_PLATFORM_WINDOWS)
Cooper Partin88d3b8c2014-10-08 10:41:56 -0700998
Cooper Partin1edac3b2014-11-20 13:49:27 -0800999// Causes the thread to relinquish the remainder of its time slice to any
1000// other thread that is ready to run.If there are no other threads ready
1001// to run, the function returns immediately, and the thread continues execution.
1002void ScheduleYield()
Cooper Partin88d3b8c2014-10-08 10:41:56 -07001003{
Geoff Lange5f735f2015-09-17 13:26:59 -04001004 Sleep(0);
Cooper Partin88d3b8c2014-10-08 10:41:56 -07001005}
1006
Kenneth Russellb23deb22014-11-21 14:53:56 -08001007#endif