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