daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3 | // 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.org | a2ecfcc | 2013-05-30 00:11:59 +0000 | [diff] [blame] | 9 | #include "common/utilities.h" |
| 10 | #include "common/mathutil.h" |
Geoff Lang | 44fa759 | 2014-05-30 11:50:07 -0400 | [diff] [blame] | 11 | #include "common/platform.h" |
Geoff Lang | 8321779 | 2014-01-16 09:52:38 -0500 | [diff] [blame] | 12 | |
shannonwoods@chromium.org | a2ecfcc | 2013-05-30 00:11:59 +0000 | [diff] [blame] | 13 | #include <set> |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 14 | |
Cooper Partin | 88d3b8c | 2014-10-08 10:41:56 -0700 | [diff] [blame] | 15 | #if defined(ANGLE_ENABLE_WINDOWS_STORE) |
| 16 | # include <wrl.h> |
| 17 | # include <wrl/wrappers/corewrappers.h> |
| 18 | # include <windows.applicationmodel.core.h> |
| 19 | # include <windows.graphics.display.h> |
| 20 | #endif |
| 21 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 22 | namespace |
| 23 | { |
| 24 | |
| 25 | template <class IndexType> |
| 26 | gl::IndexRange ComputeTypedIndexRange(const IndexType *indices, |
| 27 | size_t count, |
| 28 | bool primitiveRestartEnabled, |
| 29 | GLuint primitiveRestartIndex) |
| 30 | { |
| 31 | ASSERT(count > 0); |
| 32 | |
| 33 | IndexType minIndex = 0; |
| 34 | IndexType maxIndex = 0; |
| 35 | size_t nonPrimitiveRestartIndices = 0; |
| 36 | |
| 37 | if (primitiveRestartEnabled) |
| 38 | { |
| 39 | // Find the first non-primitive restart index to initialize the min and max values |
| 40 | size_t i = 0; |
| 41 | for (; i < count; i++) |
| 42 | { |
| 43 | if (indices[i] != primitiveRestartIndex) |
| 44 | { |
| 45 | minIndex = indices[i]; |
| 46 | maxIndex = indices[i]; |
| 47 | nonPrimitiveRestartIndices++; |
| 48 | break; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | // Loop over the rest of the indices |
| 53 | for (; i < count; i++) |
| 54 | { |
| 55 | if (indices[i] != primitiveRestartIndex) |
| 56 | { |
| 57 | if (minIndex > indices[i]) |
| 58 | { |
| 59 | minIndex = indices[i]; |
| 60 | } |
| 61 | if (maxIndex < indices[i]) |
| 62 | { |
| 63 | maxIndex = indices[i]; |
| 64 | } |
| 65 | nonPrimitiveRestartIndices++; |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | else |
| 70 | { |
| 71 | minIndex = indices[0]; |
| 72 | maxIndex = indices[0]; |
| 73 | nonPrimitiveRestartIndices = count; |
| 74 | |
| 75 | for (size_t i = 1; i < count; i++) |
| 76 | { |
| 77 | if (minIndex > indices[i]) |
| 78 | { |
| 79 | minIndex = indices[i]; |
| 80 | } |
| 81 | if (maxIndex < indices[i]) |
| 82 | { |
| 83 | maxIndex = indices[i]; |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return gl::IndexRange(static_cast<size_t>(minIndex), static_cast<size_t>(maxIndex), |
| 89 | nonPrimitiveRestartIndices); |
| 90 | } |
| 91 | |
| 92 | } // anonymous namespace |
| 93 | |
daniel@transgaming.com | 1b3a815 | 2010-04-22 13:35:37 +0000 | [diff] [blame] | 94 | namespace gl |
| 95 | { |
| 96 | |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 97 | int VariableComponentCount(GLenum type) |
daniel@transgaming.com | 1b3a815 | 2010-04-22 13:35:37 +0000 | [diff] [blame] | 98 | { |
Jamie Madill | aa72d78 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 99 | return VariableRowCount(type) * VariableColumnCount(type); |
daniel@transgaming.com | 1b3a815 | 2010-04-22 13:35:37 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 102 | GLenum VariableComponentType(GLenum type) |
daniel@transgaming.com | 1b3a815 | 2010-04-22 13:35:37 +0000 | [diff] [blame] | 103 | { |
| 104 | switch(type) |
| 105 | { |
| 106 | case GL_BOOL: |
| 107 | case GL_BOOL_VEC2: |
| 108 | case GL_BOOL_VEC3: |
| 109 | case GL_BOOL_VEC4: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 110 | return GL_BOOL; |
daniel@transgaming.com | 1b3a815 | 2010-04-22 13:35:37 +0000 | [diff] [blame] | 111 | case GL_FLOAT: |
| 112 | case GL_FLOAT_VEC2: |
| 113 | case GL_FLOAT_VEC3: |
| 114 | case GL_FLOAT_VEC4: |
| 115 | case GL_FLOAT_MAT2: |
| 116 | case GL_FLOAT_MAT3: |
| 117 | case GL_FLOAT_MAT4: |
shannon.woods%transgaming.com@gtempaccount.com | e6ca670 | 2013-04-13 03:40:44 +0000 | [diff] [blame] | 118 | case GL_FLOAT_MAT2x3: |
| 119 | case GL_FLOAT_MAT3x2: |
| 120 | case GL_FLOAT_MAT2x4: |
| 121 | case GL_FLOAT_MAT4x2: |
| 122 | case GL_FLOAT_MAT3x4: |
| 123 | case GL_FLOAT_MAT4x3: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 124 | return GL_FLOAT; |
daniel@transgaming.com | 1b3a815 | 2010-04-22 13:35:37 +0000 | [diff] [blame] | 125 | case GL_INT: |
daniel@transgaming.com | a9cd70a | 2010-09-15 15:48:57 +0000 | [diff] [blame] | 126 | case GL_SAMPLER_2D: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 127 | case GL_SAMPLER_3D: |
daniel@transgaming.com | a9cd70a | 2010-09-15 15:48:57 +0000 | [diff] [blame] | 128 | case GL_SAMPLER_CUBE: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 129 | case GL_SAMPLER_2D_ARRAY: |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 130 | case GL_SAMPLER_EXTERNAL_OES: |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 131 | case GL_SAMPLER_2D_MULTISAMPLE: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 132 | case GL_INT_SAMPLER_2D: |
| 133 | case GL_INT_SAMPLER_3D: |
| 134 | case GL_INT_SAMPLER_CUBE: |
| 135 | case GL_INT_SAMPLER_2D_ARRAY: |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 136 | case GL_INT_SAMPLER_2D_MULTISAMPLE: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 137 | case GL_UNSIGNED_INT_SAMPLER_2D: |
| 138 | case GL_UNSIGNED_INT_SAMPLER_3D: |
| 139 | case GL_UNSIGNED_INT_SAMPLER_CUBE: |
| 140 | case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 141 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: |
Nicolas Capens | cb127d3 | 2013-07-15 17:26:18 -0400 | [diff] [blame] | 142 | case GL_SAMPLER_2D_SHADOW: |
| 143 | case GL_SAMPLER_CUBE_SHADOW: |
| 144 | case GL_SAMPLER_2D_ARRAY_SHADOW: |
daniel@transgaming.com | 1b3a815 | 2010-04-22 13:35:37 +0000 | [diff] [blame] | 145 | case GL_INT_VEC2: |
| 146 | case GL_INT_VEC3: |
| 147 | case GL_INT_VEC4: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 148 | return GL_INT; |
shannon.woods%transgaming.com@gtempaccount.com | 44ce5b1 | 2013-04-13 03:40:30 +0000 | [diff] [blame] | 149 | case GL_UNSIGNED_INT: |
| 150 | case GL_UNSIGNED_INT_VEC2: |
| 151 | case GL_UNSIGNED_INT_VEC3: |
| 152 | case GL_UNSIGNED_INT_VEC4: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 153 | return GL_UNSIGNED_INT; |
daniel@transgaming.com | 1b3a815 | 2010-04-22 13:35:37 +0000 | [diff] [blame] | 154 | default: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 155 | UNREACHABLE(); |
daniel@transgaming.com | 1b3a815 | 2010-04-22 13:35:37 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | return GL_NONE; |
| 159 | } |
| 160 | |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 161 | size_t VariableComponentSize(GLenum type) |
daniel@transgaming.com | 1b3a815 | 2010-04-22 13:35:37 +0000 | [diff] [blame] | 162 | { |
| 163 | switch(type) |
| 164 | { |
shannon.woods%transgaming.com@gtempaccount.com | 44ce5b1 | 2013-04-13 03:40:30 +0000 | [diff] [blame] | 165 | case GL_BOOL: return sizeof(GLint); |
| 166 | case GL_FLOAT: return sizeof(GLfloat); |
| 167 | case GL_INT: return sizeof(GLint); |
| 168 | case GL_UNSIGNED_INT: return sizeof(GLuint); |
jbauman@chromium.org | 72e8f44 | 2011-10-20 00:22:01 +0000 | [diff] [blame] | 169 | default: UNREACHABLE(); |
daniel@transgaming.com | 1b3a815 | 2010-04-22 13:35:37 +0000 | [diff] [blame] | 170 | } |
| 171 | |
jbauman@chromium.org | 72e8f44 | 2011-10-20 00:22:01 +0000 | [diff] [blame] | 172 | return 0; |
| 173 | } |
| 174 | |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 175 | size_t VariableInternalSize(GLenum type) |
jbauman@chromium.org | 72e8f44 | 2011-10-20 00:22:01 +0000 | [diff] [blame] | 176 | { |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 177 | // Expanded to 4-element vectors |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 178 | return VariableComponentSize(VariableComponentType(type)) * VariableRowCount(type) * 4; |
daniel@transgaming.com | 1b3a815 | 2010-04-22 13:35:37 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 181 | size_t VariableExternalSize(GLenum type) |
daniel@transgaming.com | 47c6005 | 2011-11-12 03:17:50 +0000 | [diff] [blame] | 182 | { |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 183 | return VariableComponentSize(VariableComponentType(type)) * VariableComponentCount(type); |
daniel@transgaming.com | 47c6005 | 2011-11-12 03:17:50 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 186 | GLenum VariableBoolVectorType(GLenum type) |
shannon.woods%transgaming.com@gtempaccount.com | 8a19eed | 2013-04-13 03:40:22 +0000 | [diff] [blame] | 187 | { |
| 188 | switch (type) |
| 189 | { |
| 190 | case GL_FLOAT: |
| 191 | case GL_INT: |
shannon.woods%transgaming.com@gtempaccount.com | 44ce5b1 | 2013-04-13 03:40:30 +0000 | [diff] [blame] | 192 | case GL_UNSIGNED_INT: |
shannon.woods%transgaming.com@gtempaccount.com | 8a19eed | 2013-04-13 03:40:22 +0000 | [diff] [blame] | 193 | return GL_BOOL; |
| 194 | case GL_FLOAT_VEC2: |
| 195 | case GL_INT_VEC2: |
shannon.woods%transgaming.com@gtempaccount.com | 44ce5b1 | 2013-04-13 03:40:30 +0000 | [diff] [blame] | 196 | case GL_UNSIGNED_INT_VEC2: |
shannon.woods%transgaming.com@gtempaccount.com | 8a19eed | 2013-04-13 03:40:22 +0000 | [diff] [blame] | 197 | return GL_BOOL_VEC2; |
| 198 | case GL_FLOAT_VEC3: |
| 199 | case GL_INT_VEC3: |
shannon.woods%transgaming.com@gtempaccount.com | 44ce5b1 | 2013-04-13 03:40:30 +0000 | [diff] [blame] | 200 | case GL_UNSIGNED_INT_VEC3: |
shannon.woods%transgaming.com@gtempaccount.com | 8a19eed | 2013-04-13 03:40:22 +0000 | [diff] [blame] | 201 | return GL_BOOL_VEC3; |
| 202 | case GL_FLOAT_VEC4: |
| 203 | case GL_INT_VEC4: |
shannon.woods%transgaming.com@gtempaccount.com | 44ce5b1 | 2013-04-13 03:40:30 +0000 | [diff] [blame] | 204 | case GL_UNSIGNED_INT_VEC4: |
shannon.woods%transgaming.com@gtempaccount.com | 8a19eed | 2013-04-13 03:40:22 +0000 | [diff] [blame] | 205 | return GL_BOOL_VEC4; |
| 206 | |
| 207 | default: |
| 208 | UNREACHABLE(); |
| 209 | return GL_NONE; |
| 210 | } |
| 211 | } |
| 212 | |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 213 | int VariableRowCount(GLenum type) |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 214 | { |
| 215 | switch (type) |
| 216 | { |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 217 | case GL_NONE: |
Jamie Madill | 66192b3 | 2013-09-09 15:41:37 -0400 | [diff] [blame] | 218 | case GL_STRUCT_ANGLEX: |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 219 | return 0; |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 220 | case GL_BOOL: |
| 221 | case GL_FLOAT: |
| 222 | case GL_INT: |
shannonwoods@chromium.org | 6b70991 | 2013-05-30 00:20:04 +0000 | [diff] [blame] | 223 | case GL_UNSIGNED_INT: |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 224 | case GL_BOOL_VEC2: |
| 225 | case GL_FLOAT_VEC2: |
| 226 | case GL_INT_VEC2: |
shannonwoods@chromium.org | 8c788e8 | 2013-05-30 00:20:21 +0000 | [diff] [blame] | 227 | case GL_UNSIGNED_INT_VEC2: |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 228 | case GL_BOOL_VEC3: |
shannonwoods@chromium.org | 8c788e8 | 2013-05-30 00:20:21 +0000 | [diff] [blame] | 229 | case GL_FLOAT_VEC3: |
| 230 | case GL_INT_VEC3: |
| 231 | case GL_UNSIGNED_INT_VEC3: |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 232 | case GL_BOOL_VEC4: |
| 233 | case GL_FLOAT_VEC4: |
| 234 | case GL_INT_VEC4: |
shannonwoods@chromium.org | 8c788e8 | 2013-05-30 00:20:21 +0000 | [diff] [blame] | 235 | case GL_UNSIGNED_INT_VEC4: |
daniel@transgaming.com | da8d380 | 2012-12-20 21:12:55 +0000 | [diff] [blame] | 236 | case GL_SAMPLER_2D: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 237 | case GL_SAMPLER_3D: |
daniel@transgaming.com | da8d380 | 2012-12-20 21:12:55 +0000 | [diff] [blame] | 238 | case GL_SAMPLER_CUBE: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 239 | case GL_SAMPLER_2D_ARRAY: |
Jamie Madill | aa72d78 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 240 | case GL_SAMPLER_EXTERNAL_OES: |
| 241 | case GL_SAMPLER_2D_RECT_ARB: |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 242 | case GL_SAMPLER_2D_MULTISAMPLE: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 243 | case GL_INT_SAMPLER_2D: |
| 244 | case GL_INT_SAMPLER_3D: |
| 245 | case GL_INT_SAMPLER_CUBE: |
| 246 | case GL_INT_SAMPLER_2D_ARRAY: |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 247 | case GL_INT_SAMPLER_2D_MULTISAMPLE: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 248 | case GL_UNSIGNED_INT_SAMPLER_2D: |
| 249 | case GL_UNSIGNED_INT_SAMPLER_3D: |
| 250 | case GL_UNSIGNED_INT_SAMPLER_CUBE: |
| 251 | case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 252 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: |
Nicolas Capens | cb127d3 | 2013-07-15 17:26:18 -0400 | [diff] [blame] | 253 | case GL_SAMPLER_2D_SHADOW: |
| 254 | case GL_SAMPLER_CUBE_SHADOW: |
| 255 | case GL_SAMPLER_2D_ARRAY_SHADOW: |
Martin Radev | 2cc85b3 | 2016-08-05 16:22:53 +0300 | [diff] [blame] | 256 | case GL_IMAGE_2D: |
| 257 | case GL_INT_IMAGE_2D: |
| 258 | case GL_UNSIGNED_INT_IMAGE_2D: |
| 259 | case GL_IMAGE_2D_ARRAY: |
| 260 | case GL_INT_IMAGE_2D_ARRAY: |
| 261 | case GL_UNSIGNED_INT_IMAGE_2D_ARRAY: |
| 262 | case GL_IMAGE_3D: |
| 263 | case GL_INT_IMAGE_3D: |
| 264 | case GL_UNSIGNED_INT_IMAGE_3D: |
| 265 | case GL_IMAGE_CUBE: |
| 266 | case GL_INT_IMAGE_CUBE: |
| 267 | case GL_UNSIGNED_INT_IMAGE_CUBE: |
| 268 | return 1; |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 269 | case GL_FLOAT_MAT2: |
shannon.woods%transgaming.com@gtempaccount.com | 02e11f3 | 2013-04-13 03:40:50 +0000 | [diff] [blame] | 270 | case GL_FLOAT_MAT3x2: |
| 271 | case GL_FLOAT_MAT4x2: |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 272 | return 2; |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 273 | case GL_FLOAT_MAT3: |
shannon.woods%transgaming.com@gtempaccount.com | 02e11f3 | 2013-04-13 03:40:50 +0000 | [diff] [blame] | 274 | case GL_FLOAT_MAT2x3: |
| 275 | case GL_FLOAT_MAT4x3: |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 276 | return 3; |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 277 | case GL_FLOAT_MAT4: |
shannon.woods%transgaming.com@gtempaccount.com | 02e11f3 | 2013-04-13 03:40:50 +0000 | [diff] [blame] | 278 | case GL_FLOAT_MAT2x4: |
| 279 | case GL_FLOAT_MAT3x4: |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 280 | return 4; |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 281 | default: |
| 282 | UNREACHABLE(); |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 283 | } |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | int VariableColumnCount(GLenum type) |
| 289 | { |
| 290 | switch (type) |
| 291 | { |
| 292 | case GL_NONE: |
Jamie Madill | 66192b3 | 2013-09-09 15:41:37 -0400 | [diff] [blame] | 293 | case GL_STRUCT_ANGLEX: |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 294 | return 0; |
| 295 | case GL_BOOL: |
| 296 | case GL_FLOAT: |
| 297 | case GL_INT: |
shannonwoods@chromium.org | 6b70991 | 2013-05-30 00:20:04 +0000 | [diff] [blame] | 298 | case GL_UNSIGNED_INT: |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 299 | case GL_SAMPLER_2D: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 300 | case GL_SAMPLER_3D: |
shannon.woods@transgaming.com | 2494c97 | 2013-02-28 23:10:03 +0000 | [diff] [blame] | 301 | case GL_SAMPLER_CUBE: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 302 | case GL_SAMPLER_2D_ARRAY: |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 303 | case GL_SAMPLER_2D_MULTISAMPLE: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 304 | case GL_INT_SAMPLER_2D: |
| 305 | case GL_INT_SAMPLER_3D: |
| 306 | case GL_INT_SAMPLER_CUBE: |
| 307 | case GL_INT_SAMPLER_2D_ARRAY: |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 308 | case GL_INT_SAMPLER_2D_MULTISAMPLE: |
Jamie Madill | aa72d78 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 309 | case GL_SAMPLER_EXTERNAL_OES: |
| 310 | case GL_SAMPLER_2D_RECT_ARB: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 311 | case GL_UNSIGNED_INT_SAMPLER_2D: |
| 312 | case GL_UNSIGNED_INT_SAMPLER_3D: |
| 313 | case GL_UNSIGNED_INT_SAMPLER_CUBE: |
| 314 | case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 315 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: |
Nicolas Capens | cb127d3 | 2013-07-15 17:26:18 -0400 | [diff] [blame] | 316 | case GL_SAMPLER_2D_SHADOW: |
| 317 | case GL_SAMPLER_CUBE_SHADOW: |
| 318 | case GL_SAMPLER_2D_ARRAY_SHADOW: |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 319 | return 1; |
| 320 | case GL_BOOL_VEC2: |
| 321 | case GL_FLOAT_VEC2: |
| 322 | case GL_INT_VEC2: |
shannonwoods@chromium.org | 8c788e8 | 2013-05-30 00:20:21 +0000 | [diff] [blame] | 323 | case GL_UNSIGNED_INT_VEC2: |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 324 | case GL_FLOAT_MAT2: |
shannon.woods%transgaming.com@gtempaccount.com | 02e11f3 | 2013-04-13 03:40:50 +0000 | [diff] [blame] | 325 | case GL_FLOAT_MAT2x3: |
| 326 | case GL_FLOAT_MAT2x4: |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 327 | return 2; |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 328 | case GL_BOOL_VEC3: |
shannonwoods@chromium.org | 8c788e8 | 2013-05-30 00:20:21 +0000 | [diff] [blame] | 329 | case GL_FLOAT_VEC3: |
| 330 | case GL_INT_VEC3: |
| 331 | case GL_UNSIGNED_INT_VEC3: |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 332 | case GL_FLOAT_MAT3: |
shannon.woods%transgaming.com@gtempaccount.com | 02e11f3 | 2013-04-13 03:40:50 +0000 | [diff] [blame] | 333 | case GL_FLOAT_MAT3x2: |
| 334 | case GL_FLOAT_MAT3x4: |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 335 | return 3; |
| 336 | case GL_BOOL_VEC4: |
| 337 | case GL_FLOAT_VEC4: |
| 338 | case GL_INT_VEC4: |
shannonwoods@chromium.org | 8c788e8 | 2013-05-30 00:20:21 +0000 | [diff] [blame] | 339 | case GL_UNSIGNED_INT_VEC4: |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 340 | case GL_FLOAT_MAT4: |
shannon.woods%transgaming.com@gtempaccount.com | 02e11f3 | 2013-04-13 03:40:50 +0000 | [diff] [blame] | 341 | case GL_FLOAT_MAT4x2: |
| 342 | case GL_FLOAT_MAT4x3: |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 343 | return 4; |
| 344 | default: |
| 345 | UNREACHABLE(); |
| 346 | } |
| 347 | |
| 348 | return 0; |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Geoff Lang | 2ec386b | 2014-12-03 14:44:38 -0500 | [diff] [blame] | 351 | bool IsSamplerType(GLenum type) |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 352 | { |
| 353 | switch (type) |
| 354 | { |
| 355 | case GL_SAMPLER_2D: |
| 356 | case GL_SAMPLER_3D: |
| 357 | case GL_SAMPLER_CUBE: |
| 358 | case GL_SAMPLER_2D_ARRAY: |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 359 | case GL_SAMPLER_EXTERNAL_OES: |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 360 | case GL_SAMPLER_2D_MULTISAMPLE: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 361 | case GL_INT_SAMPLER_2D: |
| 362 | case GL_INT_SAMPLER_3D: |
| 363 | case GL_INT_SAMPLER_CUBE: |
| 364 | case GL_INT_SAMPLER_2D_ARRAY: |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 365 | case GL_INT_SAMPLER_2D_MULTISAMPLE: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 366 | case GL_UNSIGNED_INT_SAMPLER_2D: |
| 367 | case GL_UNSIGNED_INT_SAMPLER_3D: |
| 368 | case GL_UNSIGNED_INT_SAMPLER_CUBE: |
| 369 | case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 370 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: |
Nicolas Capens | cb127d3 | 2013-07-15 17:26:18 -0400 | [diff] [blame] | 371 | case GL_SAMPLER_2D_SHADOW: |
| 372 | case GL_SAMPLER_CUBE_SHADOW: |
| 373 | case GL_SAMPLER_2D_ARRAY_SHADOW: |
Nicolas Capens | e605088 | 2013-07-08 10:43:10 -0400 | [diff] [blame] | 374 | return true; |
| 375 | } |
| 376 | |
| 377 | return false; |
| 378 | } |
| 379 | |
Geoff Lang | f51bc79 | 2015-05-04 14:57:03 -0400 | [diff] [blame] | 380 | GLenum SamplerTypeToTextureType(GLenum samplerType) |
| 381 | { |
| 382 | switch (samplerType) |
| 383 | { |
| 384 | case GL_SAMPLER_2D: |
| 385 | case GL_INT_SAMPLER_2D: |
| 386 | case GL_UNSIGNED_INT_SAMPLER_2D: |
| 387 | case GL_SAMPLER_2D_SHADOW: |
| 388 | return GL_TEXTURE_2D; |
| 389 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 390 | case GL_SAMPLER_EXTERNAL_OES: |
| 391 | return GL_TEXTURE_EXTERNAL_OES; |
| 392 | |
Geoff Lang | f51bc79 | 2015-05-04 14:57:03 -0400 | [diff] [blame] | 393 | case GL_SAMPLER_CUBE: |
| 394 | case GL_INT_SAMPLER_CUBE: |
| 395 | case GL_UNSIGNED_INT_SAMPLER_CUBE: |
| 396 | case GL_SAMPLER_CUBE_SHADOW: |
| 397 | return GL_TEXTURE_CUBE_MAP; |
| 398 | |
| 399 | case GL_SAMPLER_2D_ARRAY: |
| 400 | case GL_INT_SAMPLER_2D_ARRAY: |
| 401 | case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: |
| 402 | case GL_SAMPLER_2D_ARRAY_SHADOW: |
| 403 | return GL_TEXTURE_2D_ARRAY; |
| 404 | |
| 405 | case GL_SAMPLER_3D: |
| 406 | case GL_INT_SAMPLER_3D: |
| 407 | case GL_UNSIGNED_INT_SAMPLER_3D: |
| 408 | return GL_TEXTURE_3D; |
| 409 | |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 410 | case GL_SAMPLER_2D_MULTISAMPLE: |
| 411 | case GL_INT_SAMPLER_2D_MULTISAMPLE: |
| 412 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: |
| 413 | return GL_TEXTURE_2D_MULTISAMPLE; |
| 414 | |
Geoff Lang | f51bc79 | 2015-05-04 14:57:03 -0400 | [diff] [blame] | 415 | default: |
| 416 | UNREACHABLE(); |
| 417 | return 0; |
| 418 | } |
| 419 | } |
| 420 | |
shannon.woods%transgaming.com@gtempaccount.com | 02e11f3 | 2013-04-13 03:40:50 +0000 | [diff] [blame] | 421 | bool IsMatrixType(GLenum type) |
| 422 | { |
| 423 | return VariableRowCount(type) > 1; |
| 424 | } |
| 425 | |
shannonwoods@chromium.org | 9bd22fa | 2013-05-30 00:18:47 +0000 | [diff] [blame] | 426 | GLenum TransposeMatrixType(GLenum type) |
| 427 | { |
| 428 | if (!IsMatrixType(type)) |
| 429 | { |
| 430 | return type; |
| 431 | } |
| 432 | |
| 433 | switch (type) |
| 434 | { |
| 435 | case GL_FLOAT_MAT2: return GL_FLOAT_MAT2; |
| 436 | case GL_FLOAT_MAT3: return GL_FLOAT_MAT3; |
| 437 | case GL_FLOAT_MAT4: return GL_FLOAT_MAT4; |
| 438 | case GL_FLOAT_MAT2x3: return GL_FLOAT_MAT3x2; |
| 439 | case GL_FLOAT_MAT3x2: return GL_FLOAT_MAT2x3; |
| 440 | case GL_FLOAT_MAT2x4: return GL_FLOAT_MAT4x2; |
| 441 | case GL_FLOAT_MAT4x2: return GL_FLOAT_MAT2x4; |
| 442 | case GL_FLOAT_MAT3x4: return GL_FLOAT_MAT4x3; |
| 443 | case GL_FLOAT_MAT4x3: return GL_FLOAT_MAT3x4; |
| 444 | default: UNREACHABLE(); return GL_NONE; |
| 445 | } |
| 446 | } |
| 447 | |
Jamie Madill | 8c6befc | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 448 | int MatrixRegisterCount(GLenum type, bool isRowMajorMatrix) |
| 449 | { |
| 450 | ASSERT(IsMatrixType(type)); |
| 451 | return isRowMajorMatrix ? VariableRowCount(type) : VariableColumnCount(type); |
| 452 | } |
| 453 | |
| 454 | int MatrixComponentCount(GLenum type, bool isRowMajorMatrix) |
| 455 | { |
| 456 | ASSERT(IsMatrixType(type)); |
| 457 | return isRowMajorMatrix ? VariableColumnCount(type) : VariableRowCount(type); |
| 458 | } |
| 459 | |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 460 | int VariableRegisterCount(GLenum type) |
shannonwoods@chromium.org | 9bd22fa | 2013-05-30 00:18:47 +0000 | [diff] [blame] | 461 | { |
| 462 | return IsMatrixType(type) ? VariableColumnCount(type) : 1; |
| 463 | } |
| 464 | |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 465 | int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize) |
| 466 | { |
| 467 | ASSERT(allocationSize <= bitsSize); |
| 468 | |
| 469 | unsigned int mask = std::numeric_limits<unsigned int>::max() >> (std::numeric_limits<unsigned int>::digits - allocationSize); |
| 470 | |
| 471 | for (unsigned int i = 0; i < bitsSize - allocationSize + 1; i++) |
| 472 | { |
| 473 | if ((*bits & mask) == 0) |
| 474 | { |
| 475 | *bits |= mask; |
| 476 | return i; |
| 477 | } |
| 478 | |
| 479 | mask <<= 1; |
| 480 | } |
| 481 | |
| 482 | return -1; |
| 483 | } |
| 484 | |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 485 | static_assert(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1, "Unexpected GL cube map enum value."); |
| 486 | static_assert(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2, "Unexpected GL cube map enum value."); |
| 487 | static_assert(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3, "Unexpected GL cube map enum value."); |
| 488 | static_assert(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4, "Unexpected GL cube map enum value."); |
| 489 | static_assert(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5, "Unexpected GL cube map enum value."); |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 490 | |
| 491 | bool IsCubeMapTextureTarget(GLenum target) |
daniel@transgaming.com | 19ffc24 | 2010-05-04 03:35:21 +0000 | [diff] [blame] | 492 | { |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 493 | return (target >= FirstCubeMapTextureTarget && target <= LastCubeMapTextureTarget); |
| 494 | } |
| 495 | |
| 496 | size_t CubeMapTextureTargetToLayerIndex(GLenum target) |
| 497 | { |
| 498 | ASSERT(IsCubeMapTextureTarget(target)); |
| 499 | return target - static_cast<size_t>(FirstCubeMapTextureTarget); |
| 500 | } |
| 501 | |
| 502 | GLenum LayerIndexToCubeMapTextureTarget(size_t index) |
| 503 | { |
| 504 | ASSERT(index <= (LastCubeMapTextureTarget - FirstCubeMapTextureTarget)); |
| 505 | return FirstCubeMapTextureTarget + static_cast<GLenum>(index); |
daniel@transgaming.com | 19ffc24 | 2010-05-04 03:35:21 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 508 | IndexRange ComputeIndexRange(GLenum indexType, |
| 509 | const GLvoid *indices, |
| 510 | size_t count, |
| 511 | bool primitiveRestartEnabled) |
Geoff Lang | 831b195 | 2015-05-05 11:02:27 -0400 | [diff] [blame] | 512 | { |
| 513 | switch (indexType) |
| 514 | { |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 515 | case GL_UNSIGNED_BYTE: |
| 516 | return ComputeTypedIndexRange(static_cast<const GLubyte *>(indices), count, |
| 517 | primitiveRestartEnabled, |
| 518 | GetPrimitiveRestartIndex(indexType)); |
| 519 | case GL_UNSIGNED_SHORT: |
| 520 | return ComputeTypedIndexRange(static_cast<const GLushort *>(indices), count, |
| 521 | primitiveRestartEnabled, |
| 522 | GetPrimitiveRestartIndex(indexType)); |
| 523 | case GL_UNSIGNED_INT: |
| 524 | return ComputeTypedIndexRange(static_cast<const GLuint *>(indices), count, |
| 525 | primitiveRestartEnabled, |
| 526 | GetPrimitiveRestartIndex(indexType)); |
| 527 | default: |
| 528 | UNREACHABLE(); |
| 529 | return IndexRange(); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | GLuint GetPrimitiveRestartIndex(GLenum indexType) |
| 534 | { |
| 535 | switch (indexType) |
| 536 | { |
| 537 | case GL_UNSIGNED_BYTE: |
| 538 | return 0xFF; |
| 539 | case GL_UNSIGNED_SHORT: |
| 540 | return 0xFFFF; |
| 541 | case GL_UNSIGNED_INT: |
| 542 | return 0xFFFFFFFF; |
| 543 | default: |
| 544 | UNREACHABLE(); |
| 545 | return 0; |
Geoff Lang | 831b195 | 2015-05-05 11:02:27 -0400 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | |
daniel@transgaming.com | 97c852b | 2012-12-20 20:56:23 +0000 | [diff] [blame] | 549 | bool IsTriangleMode(GLenum drawMode) |
| 550 | { |
| 551 | switch (drawMode) |
| 552 | { |
| 553 | case GL_TRIANGLES: |
| 554 | case GL_TRIANGLE_FAN: |
| 555 | case GL_TRIANGLE_STRIP: |
| 556 | return true; |
| 557 | case GL_POINTS: |
| 558 | case GL_LINES: |
| 559 | case GL_LINE_LOOP: |
| 560 | case GL_LINE_STRIP: |
| 561 | return false; |
| 562 | default: UNREACHABLE(); |
| 563 | } |
| 564 | |
| 565 | return false; |
| 566 | } |
| 567 | |
Jamie Madill | 865d145 | 2014-07-02 15:31:20 -0400 | [diff] [blame] | 568 | // [OpenGL ES SL 3.00.4] Section 11 p. 120 |
| 569 | // Vertex Outs/Fragment Ins packing priorities |
| 570 | int VariableSortOrder(GLenum type) |
| 571 | { |
| 572 | switch (type) |
| 573 | { |
| 574 | // 1. Arrays of mat4 and mat4 |
| 575 | // Non-square matrices of type matCxR consume the same space as a square |
| 576 | // matrix of type matN where N is the greater of C and R |
| 577 | case GL_FLOAT_MAT4: |
| 578 | case GL_FLOAT_MAT2x4: |
| 579 | case GL_FLOAT_MAT3x4: |
| 580 | case GL_FLOAT_MAT4x2: |
| 581 | case GL_FLOAT_MAT4x3: |
| 582 | return 0; |
| 583 | |
| 584 | // 2. Arrays of mat2 and mat2 (since they occupy full rows) |
| 585 | case GL_FLOAT_MAT2: |
| 586 | return 1; |
| 587 | |
| 588 | // 3. Arrays of vec4 and vec4 |
| 589 | case GL_FLOAT_VEC4: |
| 590 | case GL_INT_VEC4: |
| 591 | case GL_BOOL_VEC4: |
| 592 | case GL_UNSIGNED_INT_VEC4: |
| 593 | return 2; |
| 594 | |
| 595 | // 4. Arrays of mat3 and mat3 |
| 596 | case GL_FLOAT_MAT3: |
| 597 | case GL_FLOAT_MAT2x3: |
| 598 | case GL_FLOAT_MAT3x2: |
| 599 | return 3; |
| 600 | |
| 601 | // 5. Arrays of vec3 and vec3 |
| 602 | case GL_FLOAT_VEC3: |
| 603 | case GL_INT_VEC3: |
| 604 | case GL_BOOL_VEC3: |
| 605 | case GL_UNSIGNED_INT_VEC3: |
| 606 | return 4; |
| 607 | |
| 608 | // 6. Arrays of vec2 and vec2 |
| 609 | case GL_FLOAT_VEC2: |
| 610 | case GL_INT_VEC2: |
| 611 | case GL_BOOL_VEC2: |
| 612 | case GL_UNSIGNED_INT_VEC2: |
| 613 | return 5; |
| 614 | |
| 615 | // 7. Single component types |
| 616 | case GL_FLOAT: |
| 617 | case GL_INT: |
| 618 | case GL_BOOL: |
| 619 | case GL_UNSIGNED_INT: |
| 620 | case GL_SAMPLER_2D: |
| 621 | case GL_SAMPLER_CUBE: |
| 622 | case GL_SAMPLER_EXTERNAL_OES: |
| 623 | case GL_SAMPLER_2D_RECT_ARB: |
| 624 | case GL_SAMPLER_2D_ARRAY: |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 625 | case GL_SAMPLER_2D_MULTISAMPLE: |
Jamie Madill | 865d145 | 2014-07-02 15:31:20 -0400 | [diff] [blame] | 626 | case GL_SAMPLER_3D: |
| 627 | case GL_INT_SAMPLER_2D: |
| 628 | case GL_INT_SAMPLER_3D: |
| 629 | case GL_INT_SAMPLER_CUBE: |
| 630 | case GL_INT_SAMPLER_2D_ARRAY: |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 631 | case GL_INT_SAMPLER_2D_MULTISAMPLE: |
Jamie Madill | 865d145 | 2014-07-02 15:31:20 -0400 | [diff] [blame] | 632 | case GL_UNSIGNED_INT_SAMPLER_2D: |
| 633 | case GL_UNSIGNED_INT_SAMPLER_3D: |
| 634 | case GL_UNSIGNED_INT_SAMPLER_CUBE: |
| 635 | case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 636 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: |
Jamie Madill | 865d145 | 2014-07-02 15:31:20 -0400 | [diff] [blame] | 637 | case GL_SAMPLER_2D_SHADOW: |
| 638 | case GL_SAMPLER_2D_ARRAY_SHADOW: |
| 639 | case GL_SAMPLER_CUBE_SHADOW: |
| 640 | return 6; |
| 641 | |
| 642 | default: |
| 643 | UNREACHABLE(); |
| 644 | return 0; |
| 645 | } |
| 646 | } |
| 647 | |
Geoff Lang | cfaeaa9 | 2015-04-14 13:41:02 -0400 | [diff] [blame] | 648 | std::string ParseUniformName(const std::string &name, size_t *outSubscript) |
| 649 | { |
| 650 | // Strip any trailing array operator and retrieve the subscript |
| 651 | size_t open = name.find_last_of('['); |
| 652 | size_t close = name.find_last_of(']'); |
| 653 | bool hasIndex = (open != std::string::npos) && (close == name.length() - 1); |
| 654 | if (!hasIndex) |
| 655 | { |
| 656 | if (outSubscript) |
| 657 | { |
| 658 | *outSubscript = GL_INVALID_INDEX; |
| 659 | } |
| 660 | return name; |
| 661 | } |
| 662 | |
| 663 | if (outSubscript) |
| 664 | { |
| 665 | int index = atoi(name.substr(open + 1).c_str()); |
| 666 | if (index >= 0) |
| 667 | { |
| 668 | *outSubscript = index; |
| 669 | } |
| 670 | else |
| 671 | { |
| 672 | *outSubscript = GL_INVALID_INDEX; |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | return name.substr(0, open); |
| 677 | } |
| 678 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 679 | template <> |
| 680 | GLuint ConvertToGLuint(GLfloat param) |
| 681 | { |
| 682 | return uiround<GLuint>(param); |
| 683 | } |
| 684 | |
| 685 | template <> |
| 686 | GLint ConvertToGLint(GLfloat param) |
| 687 | { |
| 688 | return iround<GLint>(param); |
| 689 | } |
| 690 | |
| 691 | template <> |
| 692 | GLint ConvertFromGLfloat(GLfloat param) |
| 693 | { |
| 694 | return iround<GLint>(param); |
| 695 | } |
| 696 | template <> |
| 697 | GLuint ConvertFromGLfloat(GLfloat param) |
| 698 | { |
| 699 | return uiround<GLuint>(param); |
| 700 | } |
| 701 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 702 | unsigned int ParseAndStripArrayIndex(std::string *name) |
| 703 | { |
| 704 | unsigned int subscript = GL_INVALID_INDEX; |
| 705 | |
| 706 | // Strip any trailing array operator and retrieve the subscript |
| 707 | size_t open = name->find_last_of('['); |
| 708 | size_t close = name->find_last_of(']'); |
| 709 | if (open != std::string::npos && close == name->length() - 1) |
| 710 | { |
| 711 | subscript = atoi(name->c_str() + open + 1); |
| 712 | name->erase(open); |
| 713 | } |
| 714 | |
| 715 | return subscript; |
daniel@transgaming.com | 1b3a815 | 2010-04-22 13:35:37 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 718 | } // namespace gl |
| 719 | |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 720 | namespace egl |
| 721 | { |
| 722 | static_assert(EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 1, |
| 723 | "Unexpected EGL cube map enum value."); |
| 724 | static_assert(EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 2, |
| 725 | "Unexpected EGL cube map enum value."); |
| 726 | static_assert(EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 3, |
| 727 | "Unexpected EGL cube map enum value."); |
| 728 | static_assert(EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 4, |
| 729 | "Unexpected EGL cube map enum value."); |
| 730 | static_assert(EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR - EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR == 5, |
| 731 | "Unexpected EGL cube map enum value."); |
| 732 | |
| 733 | bool IsCubeMapTextureTarget(EGLenum target) |
| 734 | { |
| 735 | return (target >= FirstCubeMapTextureTarget && target <= LastCubeMapTextureTarget); |
| 736 | } |
| 737 | |
| 738 | size_t CubeMapTextureTargetToLayerIndex(EGLenum target) |
| 739 | { |
| 740 | ASSERT(IsCubeMapTextureTarget(target)); |
| 741 | return target - static_cast<size_t>(FirstCubeMapTextureTarget); |
| 742 | } |
| 743 | |
| 744 | EGLenum LayerIndexToCubeMapTextureTarget(size_t index) |
| 745 | { |
| 746 | ASSERT(index <= (LastCubeMapTextureTarget - FirstCubeMapTextureTarget)); |
| 747 | return FirstCubeMapTextureTarget + static_cast<GLenum>(index); |
| 748 | } |
| 749 | |
| 750 | bool IsTextureTarget(EGLenum target) |
| 751 | { |
| 752 | switch (target) |
| 753 | { |
| 754 | case EGL_GL_TEXTURE_2D_KHR: |
| 755 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR: |
| 756 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR: |
| 757 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR: |
| 758 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR: |
| 759 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR: |
| 760 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR: |
| 761 | case EGL_GL_TEXTURE_3D_KHR: |
| 762 | return true; |
| 763 | |
| 764 | default: |
| 765 | return false; |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | bool IsRenderbufferTarget(EGLenum target) |
| 770 | { |
| 771 | return target == EGL_GL_RENDERBUFFER_KHR; |
| 772 | } |
Jamie Madill | 8b9b792 | 2016-05-19 13:13:37 -0400 | [diff] [blame] | 773 | } // namespace egl |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 774 | |
| 775 | namespace egl_gl |
| 776 | { |
| 777 | GLenum EGLCubeMapTargetToGLCubeMapTarget(EGLenum eglTarget) |
| 778 | { |
| 779 | ASSERT(egl::IsCubeMapTextureTarget(eglTarget)); |
| 780 | return gl::LayerIndexToCubeMapTextureTarget(egl::CubeMapTextureTargetToLayerIndex(eglTarget)); |
| 781 | } |
| 782 | |
| 783 | GLenum EGLImageTargetToGLTextureTarget(EGLenum eglTarget) |
| 784 | { |
| 785 | switch (eglTarget) |
| 786 | { |
| 787 | case EGL_GL_TEXTURE_2D_KHR: |
| 788 | return GL_TEXTURE_2D; |
| 789 | |
| 790 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR: |
| 791 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR: |
| 792 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR: |
| 793 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR: |
| 794 | case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR: |
| 795 | case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR: |
| 796 | return EGLCubeMapTargetToGLCubeMapTarget(eglTarget); |
| 797 | |
| 798 | case EGL_GL_TEXTURE_3D_KHR: |
| 799 | return GL_TEXTURE_3D; |
| 800 | |
| 801 | default: |
| 802 | UNREACHABLE(); |
| 803 | return GL_NONE; |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | GLuint EGLClientBufferToGLObjectHandle(EGLClientBuffer buffer) |
| 808 | { |
| 809 | return static_cast<GLuint>(reinterpret_cast<uintptr_t>(buffer)); |
| 810 | } |
Jamie Madill | 8b9b792 | 2016-05-19 13:13:37 -0400 | [diff] [blame] | 811 | } // namespace egl_gl |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 812 | |
Geoff Lang | c5a2a17 | 2017-01-13 15:55:07 -0500 | [diff] [blame] | 813 | namespace gl_egl |
| 814 | { |
| 815 | EGLenum GLComponentTypeToEGLColorComponentType(GLenum glComponentType) |
| 816 | { |
| 817 | switch (glComponentType) |
| 818 | { |
| 819 | case GL_FLOAT: |
| 820 | return EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT; |
| 821 | |
| 822 | case GL_UNSIGNED_NORMALIZED: |
| 823 | return EGL_COLOR_COMPONENT_TYPE_FIXED_EXT; |
| 824 | |
| 825 | default: |
| 826 | UNREACHABLE(); |
| 827 | return EGL_NONE; |
| 828 | } |
| 829 | } |
| 830 | } // namespace gl_egl |
| 831 | |
Austin Kinross | 922a9fb | 2014-10-21 14:26:33 -0700 | [diff] [blame] | 832 | #if !defined(ANGLE_ENABLE_WINDOWS_STORE) |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 833 | std::string getTempPath() |
| 834 | { |
Shannon Woods | fb83947 | 2014-06-16 13:21:41 -0400 | [diff] [blame] | 835 | #ifdef ANGLE_PLATFORM_WINDOWS |
Austin Kinross | 922a9fb | 2014-10-21 14:26:33 -0700 | [diff] [blame] | 836 | char path[MAX_PATH]; |
| 837 | DWORD pathLen = GetTempPathA(sizeof(path) / sizeof(path[0]), path); |
| 838 | if (pathLen == 0) |
| 839 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 840 | UNREACHABLE(); |
| 841 | return std::string(); |
Austin Kinross | 922a9fb | 2014-10-21 14:26:33 -0700 | [diff] [blame] | 842 | } |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 843 | |
Austin Kinross | 922a9fb | 2014-10-21 14:26:33 -0700 | [diff] [blame] | 844 | UINT unique = GetTempFileNameA(path, "sh", 0, path); |
| 845 | if (unique == 0) |
| 846 | { |
| 847 | UNREACHABLE(); |
| 848 | return std::string(); |
| 849 | } |
shannonwoods@chromium.org | a2ecfcc | 2013-05-30 00:11:59 +0000 | [diff] [blame] | 850 | |
Austin Kinross | 922a9fb | 2014-10-21 14:26:33 -0700 | [diff] [blame] | 851 | return path; |
Geoff Lang | 8321779 | 2014-01-16 09:52:38 -0500 | [diff] [blame] | 852 | #else |
| 853 | UNIMPLEMENTED(); |
| 854 | return ""; |
| 855 | #endif |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | void writeFile(const char* path, const void* content, size_t size) |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 859 | { |
| 860 | FILE* file = fopen(path, "w"); |
| 861 | if (!file) |
| 862 | { |
| 863 | UNREACHABLE(); |
| 864 | return; |
| 865 | } |
| 866 | |
| 867 | fwrite(content, sizeof(char), size, file); |
| 868 | fclose(file); |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 869 | } |
Austin Kinross | 922a9fb | 2014-10-21 14:26:33 -0700 | [diff] [blame] | 870 | #endif // !ANGLE_ENABLE_WINDOWS_STORE |
Cooper Partin | 88d3b8c | 2014-10-08 10:41:56 -0700 | [diff] [blame] | 871 | |
Cooper Partin | 1edac3b | 2014-11-20 13:49:27 -0800 | [diff] [blame] | 872 | #if defined (ANGLE_PLATFORM_WINDOWS) |
Cooper Partin | 88d3b8c | 2014-10-08 10:41:56 -0700 | [diff] [blame] | 873 | |
Cooper Partin | 1edac3b | 2014-11-20 13:49:27 -0800 | [diff] [blame] | 874 | // Causes the thread to relinquish the remainder of its time slice to any |
| 875 | // other thread that is ready to run.If there are no other threads ready |
| 876 | // to run, the function returns immediately, and the thread continues execution. |
| 877 | void ScheduleYield() |
Cooper Partin | 88d3b8c | 2014-10-08 10:41:56 -0700 | [diff] [blame] | 878 | { |
Geoff Lang | e5f735f | 2015-09-17 13:26:59 -0400 | [diff] [blame] | 879 | Sleep(0); |
Cooper Partin | 88d3b8c | 2014-10-08 10:41:56 -0700 | [diff] [blame] | 880 | } |
| 881 | |
Kenneth Russell | b23deb2 | 2014-11-21 14:53:56 -0800 | [diff] [blame] | 882 | #endif |