gfx/angle/src/libGLESv2/utilities.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 #include "precompiled.h"
michael@0 2 //
michael@0 3 // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
michael@0 4 // Use of this source code is governed by a BSD-style license that can be
michael@0 5 // found in the LICENSE file.
michael@0 6 //
michael@0 7
michael@0 8 // utilities.cpp: Conversion functions and other utility routines.
michael@0 9
michael@0 10 #include "libGLESv2/utilities.h"
michael@0 11 #include "libGLESv2/mathutil.h"
michael@0 12
michael@0 13 namespace gl
michael@0 14 {
michael@0 15
michael@0 16 int UniformComponentCount(GLenum type)
michael@0 17 {
michael@0 18 switch (type)
michael@0 19 {
michael@0 20 case GL_BOOL:
michael@0 21 case GL_FLOAT:
michael@0 22 case GL_INT:
michael@0 23 case GL_SAMPLER_2D:
michael@0 24 case GL_SAMPLER_CUBE:
michael@0 25 return 1;
michael@0 26 case GL_BOOL_VEC2:
michael@0 27 case GL_FLOAT_VEC2:
michael@0 28 case GL_INT_VEC2:
michael@0 29 return 2;
michael@0 30 case GL_INT_VEC3:
michael@0 31 case GL_FLOAT_VEC3:
michael@0 32 case GL_BOOL_VEC3:
michael@0 33 return 3;
michael@0 34 case GL_BOOL_VEC4:
michael@0 35 case GL_FLOAT_VEC4:
michael@0 36 case GL_INT_VEC4:
michael@0 37 case GL_FLOAT_MAT2:
michael@0 38 return 4;
michael@0 39 case GL_FLOAT_MAT3:
michael@0 40 return 9;
michael@0 41 case GL_FLOAT_MAT4:
michael@0 42 return 16;
michael@0 43 default:
michael@0 44 UNREACHABLE();
michael@0 45 }
michael@0 46
michael@0 47 return 0;
michael@0 48 }
michael@0 49
michael@0 50 GLenum UniformComponentType(GLenum type)
michael@0 51 {
michael@0 52 switch(type)
michael@0 53 {
michael@0 54 case GL_BOOL:
michael@0 55 case GL_BOOL_VEC2:
michael@0 56 case GL_BOOL_VEC3:
michael@0 57 case GL_BOOL_VEC4:
michael@0 58 return GL_BOOL;
michael@0 59 case GL_FLOAT:
michael@0 60 case GL_FLOAT_VEC2:
michael@0 61 case GL_FLOAT_VEC3:
michael@0 62 case GL_FLOAT_VEC4:
michael@0 63 case GL_FLOAT_MAT2:
michael@0 64 case GL_FLOAT_MAT3:
michael@0 65 case GL_FLOAT_MAT4:
michael@0 66 return GL_FLOAT;
michael@0 67 case GL_INT:
michael@0 68 case GL_SAMPLER_2D:
michael@0 69 case GL_SAMPLER_CUBE:
michael@0 70 case GL_INT_VEC2:
michael@0 71 case GL_INT_VEC3:
michael@0 72 case GL_INT_VEC4:
michael@0 73 return GL_INT;
michael@0 74 default:
michael@0 75 UNREACHABLE();
michael@0 76 }
michael@0 77
michael@0 78 return GL_NONE;
michael@0 79 }
michael@0 80
michael@0 81 size_t UniformComponentSize(GLenum type)
michael@0 82 {
michael@0 83 switch(type)
michael@0 84 {
michael@0 85 case GL_BOOL: return sizeof(GLint);
michael@0 86 case GL_FLOAT: return sizeof(GLfloat);
michael@0 87 case GL_INT: return sizeof(GLint);
michael@0 88 default: UNREACHABLE();
michael@0 89 }
michael@0 90
michael@0 91 return 0;
michael@0 92 }
michael@0 93
michael@0 94 size_t UniformInternalSize(GLenum type)
michael@0 95 {
michael@0 96 // Expanded to 4-element vectors
michael@0 97 return UniformComponentSize(UniformComponentType(type)) * VariableRowCount(type) * 4;
michael@0 98 }
michael@0 99
michael@0 100 size_t UniformExternalSize(GLenum type)
michael@0 101 {
michael@0 102 return UniformComponentSize(UniformComponentType(type)) * UniformComponentCount(type);
michael@0 103 }
michael@0 104
michael@0 105 int VariableRowCount(GLenum type)
michael@0 106 {
michael@0 107 switch (type)
michael@0 108 {
michael@0 109 case GL_NONE:
michael@0 110 return 0;
michael@0 111 case GL_BOOL:
michael@0 112 case GL_FLOAT:
michael@0 113 case GL_INT:
michael@0 114 case GL_BOOL_VEC2:
michael@0 115 case GL_FLOAT_VEC2:
michael@0 116 case GL_INT_VEC2:
michael@0 117 case GL_INT_VEC3:
michael@0 118 case GL_FLOAT_VEC3:
michael@0 119 case GL_BOOL_VEC3:
michael@0 120 case GL_BOOL_VEC4:
michael@0 121 case GL_FLOAT_VEC4:
michael@0 122 case GL_INT_VEC4:
michael@0 123 case GL_SAMPLER_2D:
michael@0 124 case GL_SAMPLER_CUBE:
michael@0 125 return 1;
michael@0 126 case GL_FLOAT_MAT2:
michael@0 127 return 2;
michael@0 128 case GL_FLOAT_MAT3:
michael@0 129 return 3;
michael@0 130 case GL_FLOAT_MAT4:
michael@0 131 return 4;
michael@0 132 default:
michael@0 133 UNREACHABLE();
michael@0 134 }
michael@0 135
michael@0 136 return 0;
michael@0 137 }
michael@0 138
michael@0 139 int VariableColumnCount(GLenum type)
michael@0 140 {
michael@0 141 switch (type)
michael@0 142 {
michael@0 143 case GL_NONE:
michael@0 144 return 0;
michael@0 145 case GL_BOOL:
michael@0 146 case GL_FLOAT:
michael@0 147 case GL_INT:
michael@0 148 case GL_SAMPLER_2D:
michael@0 149 case GL_SAMPLER_CUBE:
michael@0 150 return 1;
michael@0 151 case GL_BOOL_VEC2:
michael@0 152 case GL_FLOAT_VEC2:
michael@0 153 case GL_INT_VEC2:
michael@0 154 case GL_FLOAT_MAT2:
michael@0 155 return 2;
michael@0 156 case GL_INT_VEC3:
michael@0 157 case GL_FLOAT_VEC3:
michael@0 158 case GL_BOOL_VEC3:
michael@0 159 case GL_FLOAT_MAT3:
michael@0 160 return 3;
michael@0 161 case GL_BOOL_VEC4:
michael@0 162 case GL_FLOAT_VEC4:
michael@0 163 case GL_INT_VEC4:
michael@0 164 case GL_FLOAT_MAT4:
michael@0 165 return 4;
michael@0 166 default:
michael@0 167 UNREACHABLE();
michael@0 168 }
michael@0 169
michael@0 170 return 0;
michael@0 171 }
michael@0 172
michael@0 173 int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize)
michael@0 174 {
michael@0 175 ASSERT(allocationSize <= bitsSize);
michael@0 176
michael@0 177 unsigned int mask = std::numeric_limits<unsigned int>::max() >> (std::numeric_limits<unsigned int>::digits - allocationSize);
michael@0 178
michael@0 179 for (unsigned int i = 0; i < bitsSize - allocationSize + 1; i++)
michael@0 180 {
michael@0 181 if ((*bits & mask) == 0)
michael@0 182 {
michael@0 183 *bits |= mask;
michael@0 184 return i;
michael@0 185 }
michael@0 186
michael@0 187 mask <<= 1;
michael@0 188 }
michael@0 189
michael@0 190 return -1;
michael@0 191 }
michael@0 192
michael@0 193 GLsizei ComputePitch(GLsizei width, GLint internalformat, GLint alignment)
michael@0 194 {
michael@0 195 ASSERT(alignment > 0 && isPow2(alignment));
michael@0 196
michael@0 197 GLsizei rawPitch = ComputePixelSize(internalformat) * width;
michael@0 198 return (rawPitch + alignment - 1) & ~(alignment - 1);
michael@0 199 }
michael@0 200
michael@0 201 GLsizei ComputeCompressedPitch(GLsizei width, GLenum internalformat)
michael@0 202 {
michael@0 203 return ComputeCompressedSize(width, 1, internalformat);
michael@0 204 }
michael@0 205
michael@0 206 GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum internalformat)
michael@0 207 {
michael@0 208 switch (internalformat)
michael@0 209 {
michael@0 210 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
michael@0 211 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
michael@0 212 return 8 * ((width + 3) / 4) * ((height + 3) / 4);
michael@0 213 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
michael@0 214 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
michael@0 215 return 16 * ((width + 3) / 4) * ((height + 3) / 4);
michael@0 216 default:
michael@0 217 return 0;
michael@0 218 }
michael@0 219 }
michael@0 220
michael@0 221 GLsizei ComputeTypeSize(GLenum type)
michael@0 222 {
michael@0 223 switch (type)
michael@0 224 {
michael@0 225 case GL_BYTE: return 1;
michael@0 226 case GL_UNSIGNED_BYTE: return 1;
michael@0 227 case GL_SHORT: return 2;
michael@0 228 case GL_UNSIGNED_SHORT: return 2;
michael@0 229 case GL_INT: return 4;
michael@0 230 case GL_UNSIGNED_INT: return 4;
michael@0 231 case GL_FLOAT: return 4;
michael@0 232 case GL_HALF_FLOAT_OES: return 2;
michael@0 233 case GL_UNSIGNED_SHORT_5_6_5: return 2;
michael@0 234 case GL_UNSIGNED_SHORT_4_4_4_4: return 2;
michael@0 235 case GL_UNSIGNED_SHORT_5_5_5_1: return 2;
michael@0 236 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: return 2;
michael@0 237 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: return 2;
michael@0 238 case GL_UNSIGNED_INT_2_10_10_10_REV_EXT: return 4;
michael@0 239 case GL_UNSIGNED_INT_24_8_OES: return 4;
michael@0 240 default: UNREACHABLE(); return 0;
michael@0 241 }
michael@0 242 }
michael@0 243
michael@0 244 bool IsCompressed(GLenum format)
michael@0 245 {
michael@0 246 if(format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||
michael@0 247 format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ||
michael@0 248 format == GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE ||
michael@0 249 format == GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE)
michael@0 250 {
michael@0 251 return true;
michael@0 252 }
michael@0 253 else
michael@0 254 {
michael@0 255 return false;
michael@0 256 }
michael@0 257 }
michael@0 258
michael@0 259 bool IsDepthTexture(GLenum format)
michael@0 260 {
michael@0 261 if (format == GL_DEPTH_COMPONENT ||
michael@0 262 format == GL_DEPTH_STENCIL_OES ||
michael@0 263 format == GL_DEPTH_COMPONENT16 ||
michael@0 264 format == GL_DEPTH_COMPONENT32_OES ||
michael@0 265 format == GL_DEPTH24_STENCIL8_OES)
michael@0 266 {
michael@0 267 return true;
michael@0 268 }
michael@0 269
michael@0 270 return false;
michael@0 271 }
michael@0 272
michael@0 273 bool IsStencilTexture(GLenum format)
michael@0 274 {
michael@0 275 if (format == GL_DEPTH_STENCIL_OES ||
michael@0 276 format == GL_DEPTH24_STENCIL8_OES)
michael@0 277 {
michael@0 278 return true;
michael@0 279 }
michael@0 280
michael@0 281 return false;
michael@0 282 }
michael@0 283
michael@0 284 void MakeValidSize(bool isImage, bool isCompressed, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset)
michael@0 285 {
michael@0 286 int upsampleCount = 0;
michael@0 287
michael@0 288 if (isCompressed)
michael@0 289 {
michael@0 290 // Don't expand the size of full textures that are at least 4x4
michael@0 291 // already.
michael@0 292 if (isImage || *requestWidth < 4 || *requestHeight < 4)
michael@0 293 {
michael@0 294 while (*requestWidth % 4 != 0 || *requestHeight % 4 != 0)
michael@0 295 {
michael@0 296 *requestWidth <<= 1;
michael@0 297 *requestHeight <<= 1;
michael@0 298 upsampleCount++;
michael@0 299 }
michael@0 300 }
michael@0 301 }
michael@0 302 *levelOffset = upsampleCount;
michael@0 303 }
michael@0 304
michael@0 305 // Returns the size, in bytes, of a single texel in an Image
michael@0 306 int ComputePixelSize(GLint internalformat)
michael@0 307 {
michael@0 308 switch (internalformat)
michael@0 309 {
michael@0 310 case GL_ALPHA8_EXT: return sizeof(unsigned char);
michael@0 311 case GL_LUMINANCE8_EXT: return sizeof(unsigned char);
michael@0 312 case GL_ALPHA32F_EXT: return sizeof(float);
michael@0 313 case GL_LUMINANCE32F_EXT: return sizeof(float);
michael@0 314 case GL_ALPHA16F_EXT: return sizeof(unsigned short);
michael@0 315 case GL_LUMINANCE16F_EXT: return sizeof(unsigned short);
michael@0 316 case GL_LUMINANCE8_ALPHA8_EXT: return sizeof(unsigned char) * 2;
michael@0 317 case GL_LUMINANCE_ALPHA32F_EXT: return sizeof(float) * 2;
michael@0 318 case GL_LUMINANCE_ALPHA16F_EXT: return sizeof(unsigned short) * 2;
michael@0 319 case GL_RGB8_OES: return sizeof(unsigned char) * 3;
michael@0 320 case GL_RGB565: return sizeof(unsigned short);
michael@0 321 case GL_RGB32F_EXT: return sizeof(float) * 3;
michael@0 322 case GL_RGB16F_EXT: return sizeof(unsigned short) * 3;
michael@0 323 case GL_RGBA8_OES: return sizeof(unsigned char) * 4;
michael@0 324 case GL_RGBA4: return sizeof(unsigned short);
michael@0 325 case GL_RGB5_A1: return sizeof(unsigned short);
michael@0 326 case GL_RGBA32F_EXT: return sizeof(float) * 4;
michael@0 327 case GL_RGBA16F_EXT: return sizeof(unsigned short) * 4;
michael@0 328 case GL_BGRA8_EXT: return sizeof(unsigned char) * 4;
michael@0 329 case GL_BGRA4_ANGLEX: return sizeof(unsigned short);
michael@0 330 case GL_BGR5_A1_ANGLEX: return sizeof(unsigned short);
michael@0 331 default: UNREACHABLE();
michael@0 332 }
michael@0 333
michael@0 334 return 0;
michael@0 335 }
michael@0 336
michael@0 337 bool IsCubemapTextureTarget(GLenum target)
michael@0 338 {
michael@0 339 return (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);
michael@0 340 }
michael@0 341
michael@0 342 bool IsInternalTextureTarget(GLenum target)
michael@0 343 {
michael@0 344 return target == GL_TEXTURE_2D || IsCubemapTextureTarget(target);
michael@0 345 }
michael@0 346
michael@0 347 GLint ConvertSizedInternalFormat(GLenum format, GLenum type)
michael@0 348 {
michael@0 349 switch (format)
michael@0 350 {
michael@0 351 case GL_ALPHA:
michael@0 352 switch (type)
michael@0 353 {
michael@0 354 case GL_UNSIGNED_BYTE: return GL_ALPHA8_EXT;
michael@0 355 case GL_FLOAT: return GL_ALPHA32F_EXT;
michael@0 356 case GL_HALF_FLOAT_OES: return GL_ALPHA16F_EXT;
michael@0 357 default: UNIMPLEMENTED();
michael@0 358 }
michael@0 359 break;
michael@0 360 case GL_LUMINANCE:
michael@0 361 switch (type)
michael@0 362 {
michael@0 363 case GL_UNSIGNED_BYTE: return GL_LUMINANCE8_EXT;
michael@0 364 case GL_FLOAT: return GL_LUMINANCE32F_EXT;
michael@0 365 case GL_HALF_FLOAT_OES: return GL_LUMINANCE16F_EXT;
michael@0 366 default: UNIMPLEMENTED();
michael@0 367 }
michael@0 368 break;
michael@0 369 case GL_LUMINANCE_ALPHA:
michael@0 370 switch (type)
michael@0 371 {
michael@0 372 case GL_UNSIGNED_BYTE: return GL_LUMINANCE8_ALPHA8_EXT;
michael@0 373 case GL_FLOAT: return GL_LUMINANCE_ALPHA32F_EXT;
michael@0 374 case GL_HALF_FLOAT_OES: return GL_LUMINANCE_ALPHA16F_EXT;
michael@0 375 default: UNIMPLEMENTED();
michael@0 376 }
michael@0 377 break;
michael@0 378 case GL_RGB:
michael@0 379 switch (type)
michael@0 380 {
michael@0 381 case GL_UNSIGNED_BYTE: return GL_RGB8_OES;
michael@0 382 case GL_UNSIGNED_SHORT_5_6_5: return GL_RGB565;
michael@0 383 case GL_FLOAT: return GL_RGB32F_EXT;
michael@0 384 case GL_HALF_FLOAT_OES: return GL_RGB16F_EXT;
michael@0 385 default: UNIMPLEMENTED();
michael@0 386 }
michael@0 387 break;
michael@0 388 case GL_RGBA:
michael@0 389 switch (type)
michael@0 390 {
michael@0 391 case GL_UNSIGNED_BYTE: return GL_RGBA8_OES;
michael@0 392 case GL_UNSIGNED_SHORT_4_4_4_4: return GL_RGBA4;
michael@0 393 case GL_UNSIGNED_SHORT_5_5_5_1: return GL_RGB5_A1;
michael@0 394 case GL_FLOAT: return GL_RGBA32F_EXT;
michael@0 395 case GL_HALF_FLOAT_OES: return GL_RGBA16F_EXT;
michael@0 396 break;
michael@0 397 default: UNIMPLEMENTED();
michael@0 398 }
michael@0 399 break;
michael@0 400 case GL_BGRA_EXT:
michael@0 401 switch (type)
michael@0 402 {
michael@0 403 case GL_UNSIGNED_BYTE: return GL_BGRA8_EXT;
michael@0 404 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: return GL_BGRA4_ANGLEX;
michael@0 405 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: return GL_BGR5_A1_ANGLEX;
michael@0 406 default: UNIMPLEMENTED();
michael@0 407 }
michael@0 408 break;
michael@0 409 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
michael@0 410 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
michael@0 411 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
michael@0 412 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
michael@0 413 return format;
michael@0 414 case GL_DEPTH_COMPONENT:
michael@0 415 switch (type)
michael@0 416 {
michael@0 417 case GL_UNSIGNED_SHORT: return GL_DEPTH_COMPONENT16;
michael@0 418 case GL_UNSIGNED_INT: return GL_DEPTH_COMPONENT32_OES;
michael@0 419 default: UNIMPLEMENTED();
michael@0 420 }
michael@0 421 break;
michael@0 422 case GL_DEPTH_STENCIL_OES:
michael@0 423 switch (type)
michael@0 424 {
michael@0 425 case GL_UNSIGNED_INT_24_8_OES: return GL_DEPTH24_STENCIL8_OES;
michael@0 426 default: UNIMPLEMENTED();
michael@0 427 }
michael@0 428 break;
michael@0 429 default:
michael@0 430 UNIMPLEMENTED();
michael@0 431 }
michael@0 432
michael@0 433 return GL_NONE;
michael@0 434 }
michael@0 435
michael@0 436 GLenum ExtractFormat(GLenum internalformat)
michael@0 437 {
michael@0 438 switch (internalformat)
michael@0 439 {
michael@0 440 case GL_RGB565: return GL_RGB;
michael@0 441 case GL_RGBA4: return GL_RGBA;
michael@0 442 case GL_RGB5_A1: return GL_RGBA;
michael@0 443 case GL_RGB8_OES: return GL_RGB;
michael@0 444 case GL_RGBA8_OES: return GL_RGBA;
michael@0 445 case GL_LUMINANCE8_ALPHA8_EXT: return GL_LUMINANCE_ALPHA;
michael@0 446 case GL_LUMINANCE8_EXT: return GL_LUMINANCE;
michael@0 447 case GL_ALPHA8_EXT: return GL_ALPHA;
michael@0 448 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
michael@0 449 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
michael@0 450 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: return GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE;
michael@0 451 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: return GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE;
michael@0 452 case GL_RGBA32F_EXT: return GL_RGBA;
michael@0 453 case GL_RGB32F_EXT: return GL_RGB;
michael@0 454 case GL_ALPHA32F_EXT: return GL_ALPHA;
michael@0 455 case GL_LUMINANCE32F_EXT: return GL_LUMINANCE;
michael@0 456 case GL_LUMINANCE_ALPHA32F_EXT: return GL_LUMINANCE_ALPHA;
michael@0 457 case GL_RGBA16F_EXT: return GL_RGBA;
michael@0 458 case GL_RGB16F_EXT: return GL_RGB;
michael@0 459 case GL_ALPHA16F_EXT: return GL_ALPHA;
michael@0 460 case GL_LUMINANCE16F_EXT: return GL_LUMINANCE;
michael@0 461 case GL_LUMINANCE_ALPHA16F_EXT: return GL_LUMINANCE_ALPHA;
michael@0 462 case GL_BGRA8_EXT: return GL_BGRA_EXT;
michael@0 463 case GL_DEPTH_COMPONENT16: return GL_DEPTH_COMPONENT;
michael@0 464 case GL_DEPTH_COMPONENT32_OES: return GL_DEPTH_COMPONENT;
michael@0 465 case GL_DEPTH24_STENCIL8_OES: return GL_DEPTH_STENCIL_OES;
michael@0 466 default: return GL_NONE; // Unsupported
michael@0 467 }
michael@0 468 }
michael@0 469
michael@0 470 GLenum ExtractType(GLenum internalformat)
michael@0 471 {
michael@0 472 switch (internalformat)
michael@0 473 {
michael@0 474 case GL_RGB565: return GL_UNSIGNED_SHORT_5_6_5;
michael@0 475 case GL_RGBA4: return GL_UNSIGNED_SHORT_4_4_4_4;
michael@0 476 case GL_RGB5_A1: return GL_UNSIGNED_SHORT_5_5_5_1;
michael@0 477 case GL_RGB8_OES: return GL_UNSIGNED_BYTE;
michael@0 478 case GL_RGBA8_OES: return GL_UNSIGNED_BYTE;
michael@0 479 case GL_LUMINANCE8_ALPHA8_EXT: return GL_UNSIGNED_BYTE;
michael@0 480 case GL_LUMINANCE8_EXT: return GL_UNSIGNED_BYTE;
michael@0 481 case GL_ALPHA8_EXT: return GL_UNSIGNED_BYTE;
michael@0 482 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: return GL_UNSIGNED_BYTE;
michael@0 483 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return GL_UNSIGNED_BYTE;
michael@0 484 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: return GL_UNSIGNED_BYTE;
michael@0 485 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: return GL_UNSIGNED_BYTE;
michael@0 486 case GL_RGBA32F_EXT: return GL_FLOAT;
michael@0 487 case GL_RGB32F_EXT: return GL_FLOAT;
michael@0 488 case GL_ALPHA32F_EXT: return GL_FLOAT;
michael@0 489 case GL_LUMINANCE32F_EXT: return GL_FLOAT;
michael@0 490 case GL_LUMINANCE_ALPHA32F_EXT: return GL_FLOAT;
michael@0 491 case GL_RGBA16F_EXT: return GL_HALF_FLOAT_OES;
michael@0 492 case GL_RGB16F_EXT: return GL_HALF_FLOAT_OES;
michael@0 493 case GL_ALPHA16F_EXT: return GL_HALF_FLOAT_OES;
michael@0 494 case GL_LUMINANCE16F_EXT: return GL_HALF_FLOAT_OES;
michael@0 495 case GL_LUMINANCE_ALPHA16F_EXT: return GL_HALF_FLOAT_OES;
michael@0 496 case GL_BGRA8_EXT: return GL_UNSIGNED_BYTE;
michael@0 497 case GL_DEPTH_COMPONENT16: return GL_UNSIGNED_SHORT;
michael@0 498 case GL_DEPTH_COMPONENT32_OES: return GL_UNSIGNED_INT;
michael@0 499 case GL_DEPTH24_STENCIL8_OES: return GL_UNSIGNED_INT_24_8_OES;
michael@0 500 default: return GL_NONE; // Unsupported
michael@0 501 }
michael@0 502 }
michael@0 503
michael@0 504 bool IsColorRenderable(GLenum internalformat)
michael@0 505 {
michael@0 506 switch (internalformat)
michael@0 507 {
michael@0 508 case GL_RGBA4:
michael@0 509 case GL_RGB5_A1:
michael@0 510 case GL_RGB565:
michael@0 511 case GL_RGB8_OES:
michael@0 512 case GL_RGBA8_OES:
michael@0 513 return true;
michael@0 514 case GL_DEPTH_COMPONENT16:
michael@0 515 case GL_STENCIL_INDEX8:
michael@0 516 case GL_DEPTH24_STENCIL8_OES:
michael@0 517 return false;
michael@0 518 case GL_BGRA8_EXT:
michael@0 519 return true;
michael@0 520 default:
michael@0 521 UNIMPLEMENTED();
michael@0 522 }
michael@0 523
michael@0 524 return false;
michael@0 525 }
michael@0 526
michael@0 527 bool IsDepthRenderable(GLenum internalformat)
michael@0 528 {
michael@0 529 switch (internalformat)
michael@0 530 {
michael@0 531 case GL_DEPTH_COMPONENT16:
michael@0 532 case GL_DEPTH24_STENCIL8_OES:
michael@0 533 return true;
michael@0 534 case GL_STENCIL_INDEX8:
michael@0 535 case GL_RGBA4:
michael@0 536 case GL_RGB5_A1:
michael@0 537 case GL_RGB565:
michael@0 538 case GL_RGB8_OES:
michael@0 539 case GL_RGBA8_OES:
michael@0 540 return false;
michael@0 541 default:
michael@0 542 UNIMPLEMENTED();
michael@0 543 }
michael@0 544
michael@0 545 return false;
michael@0 546 }
michael@0 547
michael@0 548 bool IsStencilRenderable(GLenum internalformat)
michael@0 549 {
michael@0 550 switch (internalformat)
michael@0 551 {
michael@0 552 case GL_STENCIL_INDEX8:
michael@0 553 case GL_DEPTH24_STENCIL8_OES:
michael@0 554 return true;
michael@0 555 case GL_RGBA4:
michael@0 556 case GL_RGB5_A1:
michael@0 557 case GL_RGB565:
michael@0 558 case GL_RGB8_OES:
michael@0 559 case GL_RGBA8_OES:
michael@0 560 case GL_DEPTH_COMPONENT16:
michael@0 561 return false;
michael@0 562 default:
michael@0 563 UNIMPLEMENTED();
michael@0 564 }
michael@0 565
michael@0 566 return false;
michael@0 567 }
michael@0 568
michael@0 569 bool IsFloat32Format(GLint internalformat)
michael@0 570 {
michael@0 571 switch (internalformat)
michael@0 572 {
michael@0 573 case GL_RGBA32F_EXT:
michael@0 574 case GL_RGB32F_EXT:
michael@0 575 case GL_ALPHA32F_EXT:
michael@0 576 case GL_LUMINANCE32F_EXT:
michael@0 577 case GL_LUMINANCE_ALPHA32F_EXT:
michael@0 578 return true;
michael@0 579 default:
michael@0 580 return false;
michael@0 581 }
michael@0 582 }
michael@0 583
michael@0 584 bool IsFloat16Format(GLint internalformat)
michael@0 585 {
michael@0 586 switch (internalformat)
michael@0 587 {
michael@0 588 case GL_RGBA16F_EXT:
michael@0 589 case GL_RGB16F_EXT:
michael@0 590 case GL_ALPHA16F_EXT:
michael@0 591 case GL_LUMINANCE16F_EXT:
michael@0 592 case GL_LUMINANCE_ALPHA16F_EXT:
michael@0 593 return true;
michael@0 594 default:
michael@0 595 return false;
michael@0 596 }
michael@0 597 }
michael@0 598
michael@0 599 unsigned int GetAlphaSize(GLenum colorFormat)
michael@0 600 {
michael@0 601 switch (colorFormat)
michael@0 602 {
michael@0 603 case GL_RGBA16F_EXT:
michael@0 604 return 16;
michael@0 605 case GL_RGBA32F_EXT:
michael@0 606 return 32;
michael@0 607 case GL_RGBA4:
michael@0 608 return 4;
michael@0 609 case GL_RGBA8_OES:
michael@0 610 case GL_BGRA8_EXT:
michael@0 611 return 8;
michael@0 612 case GL_RGB5_A1:
michael@0 613 return 1;
michael@0 614 case GL_RGB8_OES:
michael@0 615 case GL_RGB565:
michael@0 616 case GL_RGB32F_EXT:
michael@0 617 case GL_RGB16F_EXT:
michael@0 618 return 0;
michael@0 619 default:
michael@0 620 return 0;
michael@0 621 }
michael@0 622 }
michael@0 623
michael@0 624 unsigned int GetRedSize(GLenum colorFormat)
michael@0 625 {
michael@0 626 switch (colorFormat)
michael@0 627 {
michael@0 628 case GL_RGBA16F_EXT:
michael@0 629 case GL_RGB16F_EXT:
michael@0 630 return 16;
michael@0 631 case GL_RGBA32F_EXT:
michael@0 632 case GL_RGB32F_EXT:
michael@0 633 return 32;
michael@0 634 case GL_RGBA4:
michael@0 635 return 4;
michael@0 636 case GL_RGBA8_OES:
michael@0 637 case GL_BGRA8_EXT:
michael@0 638 case GL_RGB8_OES:
michael@0 639 return 8;
michael@0 640 case GL_RGB5_A1:
michael@0 641 case GL_RGB565:
michael@0 642 return 5;
michael@0 643 default:
michael@0 644 return 0;
michael@0 645 }
michael@0 646 }
michael@0 647
michael@0 648 unsigned int GetGreenSize(GLenum colorFormat)
michael@0 649 {
michael@0 650 switch (colorFormat)
michael@0 651 {
michael@0 652 case GL_RGBA16F_EXT:
michael@0 653 case GL_RGB16F_EXT:
michael@0 654 return 16;
michael@0 655 case GL_RGBA32F_EXT:
michael@0 656 case GL_RGB32F_EXT:
michael@0 657 return 32;
michael@0 658 case GL_RGBA4:
michael@0 659 return 4;
michael@0 660 case GL_RGBA8_OES:
michael@0 661 case GL_BGRA8_EXT:
michael@0 662 case GL_RGB8_OES:
michael@0 663 return 8;
michael@0 664 case GL_RGB5_A1:
michael@0 665 return 5;
michael@0 666 case GL_RGB565:
michael@0 667 return 6;
michael@0 668 default:
michael@0 669 return 0;
michael@0 670 }
michael@0 671 }
michael@0 672
michael@0 673 unsigned int GetBlueSize(GLenum colorFormat)
michael@0 674 {
michael@0 675 switch (colorFormat)
michael@0 676 {
michael@0 677 case GL_RGBA16F_EXT:
michael@0 678 case GL_RGB16F_EXT:
michael@0 679 return 16;
michael@0 680 case GL_RGBA32F_EXT:
michael@0 681 case GL_RGB32F_EXT:
michael@0 682 return 32;
michael@0 683 case GL_RGBA4:
michael@0 684 return 4;
michael@0 685 case GL_RGBA8_OES:
michael@0 686 case GL_BGRA8_EXT:
michael@0 687 case GL_RGB8_OES:
michael@0 688 return 8;
michael@0 689 case GL_RGB5_A1:
michael@0 690 case GL_RGB565:
michael@0 691 return 5;
michael@0 692 default:
michael@0 693 return 0;
michael@0 694 }
michael@0 695 }
michael@0 696
michael@0 697 unsigned int GetDepthSize(GLenum depthFormat)
michael@0 698 {
michael@0 699 switch (depthFormat)
michael@0 700 {
michael@0 701 case GL_DEPTH_COMPONENT16: return 16;
michael@0 702 case GL_DEPTH_COMPONENT32_OES: return 32;
michael@0 703 case GL_DEPTH24_STENCIL8_OES: return 24;
michael@0 704 default: return 0;
michael@0 705 }
michael@0 706 }
michael@0 707
michael@0 708 unsigned int GetStencilSize(GLenum stencilFormat)
michael@0 709 {
michael@0 710 switch (stencilFormat)
michael@0 711 {
michael@0 712 case GL_DEPTH24_STENCIL8_OES: return 8;
michael@0 713 default: return 0;
michael@0 714 }
michael@0 715 }
michael@0 716
michael@0 717 bool IsTriangleMode(GLenum drawMode)
michael@0 718 {
michael@0 719 switch (drawMode)
michael@0 720 {
michael@0 721 case GL_TRIANGLES:
michael@0 722 case GL_TRIANGLE_FAN:
michael@0 723 case GL_TRIANGLE_STRIP:
michael@0 724 return true;
michael@0 725 case GL_POINTS:
michael@0 726 case GL_LINES:
michael@0 727 case GL_LINE_LOOP:
michael@0 728 case GL_LINE_STRIP:
michael@0 729 return false;
michael@0 730 default: UNREACHABLE();
michael@0 731 }
michael@0 732
michael@0 733 return false;
michael@0 734 }
michael@0 735
michael@0 736 }
michael@0 737
michael@0 738 std::string getTempPath()
michael@0 739 {
michael@0 740 char path[MAX_PATH];
michael@0 741 DWORD pathLen = GetTempPathA(sizeof(path) / sizeof(path[0]), path);
michael@0 742 if (pathLen == 0)
michael@0 743 {
michael@0 744 UNREACHABLE();
michael@0 745 return std::string();
michael@0 746 }
michael@0 747
michael@0 748 UINT unique = GetTempFileNameA(path, "sh", 0, path);
michael@0 749 if (unique == 0)
michael@0 750 {
michael@0 751 UNREACHABLE();
michael@0 752 return std::string();
michael@0 753 }
michael@0 754
michael@0 755 return path;
michael@0 756 }
michael@0 757
michael@0 758 void writeFile(const char* path, const void* content, size_t size)
michael@0 759 {
michael@0 760 FILE* file = fopen(path, "w");
michael@0 761 if (!file)
michael@0 762 {
michael@0 763 UNREACHABLE();
michael@0 764 return;
michael@0 765 }
michael@0 766
michael@0 767 fwrite(content, sizeof(char), size, file);
michael@0 768 fclose(file);
michael@0 769 }

mercurial