OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file is here so other GLES2 related files can have a common set of | 5 // This file is here so other GLES2 related files can have a common set of |
6 // includes where appropriate. | 6 // includes where appropriate. |
7 | 7 |
8 #include <sstream> | 8 #include <sstream> |
9 #include <GLES2/gl2.h> | 9 #include <GLES2/gl2.h> |
10 #include <GLES2/gl2ext.h> | 10 #include <GLES2/gl2ext.h> |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 | 345 |
346 namespace { | 346 namespace { |
347 | 347 |
348 // Return the number of elements per group of a specified format. | 348 // Return the number of elements per group of a specified format. |
349 int ElementsPerGroup(int format, int type) { | 349 int ElementsPerGroup(int format, int type) { |
350 switch (type) { | 350 switch (type) { |
351 case GL_UNSIGNED_SHORT_5_6_5: | 351 case GL_UNSIGNED_SHORT_5_6_5: |
352 case GL_UNSIGNED_SHORT_4_4_4_4: | 352 case GL_UNSIGNED_SHORT_4_4_4_4: |
353 case GL_UNSIGNED_SHORT_5_5_5_1: | 353 case GL_UNSIGNED_SHORT_5_5_5_1: |
354 case GL_UNSIGNED_INT_24_8_OES: | 354 case GL_UNSIGNED_INT_24_8_OES: |
| 355 case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 356 case GL_UNSIGNED_INT_10F_11F_11F_REV: |
| 357 case GL_UNSIGNED_INT_5_9_9_9_REV: |
| 358 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: |
355 return 1; | 359 return 1; |
356 default: | 360 default: |
357 break; | 361 break; |
358 } | 362 } |
359 | 363 |
360 switch (format) { | 364 switch (format) { |
361 case GL_RGB: | 365 case GL_RGB: |
| 366 case GL_RGB_INTEGER: |
362 case GL_SRGB_EXT: | 367 case GL_SRGB_EXT: |
363 return 3; | 368 return 3; |
364 case GL_LUMINANCE_ALPHA: | 369 case GL_LUMINANCE_ALPHA: |
365 case GL_RG_EXT: | 370 case GL_RG_EXT: |
| 371 case GL_RG_INTEGER: |
366 return 2; | 372 return 2; |
367 case GL_RGBA: | 373 case GL_RGBA: |
| 374 case GL_RGBA_INTEGER: |
368 case GL_BGRA_EXT: | 375 case GL_BGRA_EXT: |
369 case GL_SRGB_ALPHA_EXT: | 376 case GL_SRGB_ALPHA_EXT: |
370 return 4; | 377 return 4; |
371 case GL_ALPHA: | 378 case GL_ALPHA: |
372 case GL_LUMINANCE: | 379 case GL_LUMINANCE: |
373 case GL_DEPTH_COMPONENT: | 380 case GL_DEPTH_COMPONENT: |
374 case GL_DEPTH_COMPONENT24_OES: | 381 case GL_DEPTH_COMPONENT24_OES: |
375 case GL_DEPTH_COMPONENT32_OES: | 382 case GL_DEPTH_COMPONENT32_OES: |
376 case GL_DEPTH_COMPONENT16: | 383 case GL_DEPTH_COMPONENT16: |
377 case GL_DEPTH24_STENCIL8_OES: | 384 case GL_DEPTH24_STENCIL8_OES: |
378 case GL_DEPTH_STENCIL_OES: | 385 case GL_DEPTH_STENCIL_OES: |
379 case GL_RED_EXT: | 386 case GL_RED_EXT: |
| 387 case GL_RED_INTEGER: |
380 return 1; | 388 return 1; |
381 default: | 389 default: |
382 return 0; | 390 return 0; |
383 } | 391 } |
384 } | 392 } |
385 | 393 |
386 // Return the number of bytes per element, based on the element type. | 394 // Return the number of bytes per element, based on the element type. |
387 int BytesPerElement(int type) { | 395 int BytesPerElement(int type) { |
388 switch (type) { | 396 switch (type) { |
389 case GL_FLOAT: | 397 case GL_FLOAT: |
390 case GL_UNSIGNED_INT_24_8_OES: | 398 case GL_UNSIGNED_INT_24_8_OES: |
391 case GL_UNSIGNED_INT: | 399 case GL_UNSIGNED_INT: |
| 400 case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 401 case GL_UNSIGNED_INT_10F_11F_11F_REV: |
| 402 case GL_UNSIGNED_INT_5_9_9_9_REV: |
| 403 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: |
392 return 4; | 404 return 4; |
393 case GL_HALF_FLOAT_OES: | 405 case GL_HALF_FLOAT_OES: |
394 case GL_UNSIGNED_SHORT: | 406 case GL_UNSIGNED_SHORT: |
395 case GL_SHORT: | 407 case GL_SHORT: |
396 case GL_UNSIGNED_SHORT_5_6_5: | 408 case GL_UNSIGNED_SHORT_5_6_5: |
397 case GL_UNSIGNED_SHORT_4_4_4_4: | 409 case GL_UNSIGNED_SHORT_4_4_4_4: |
398 case GL_UNSIGNED_SHORT_5_5_5_1: | 410 case GL_UNSIGNED_SHORT_5_5_5_1: |
399 return 2; | 411 return 2; |
400 case GL_UNSIGNED_BYTE: | 412 case GL_UNSIGNED_BYTE: |
401 case GL_BYTE: | 413 case GL_BYTE: |
(...skipping 18 matching lines...) Expand all Loading... |
420 return false; | 432 return false; |
421 } | 433 } |
422 uint32 temp; | 434 uint32 temp; |
423 if (!SafeAddUint32(unpadded_row_size, unpack_alignment - 1, &temp)) { | 435 if (!SafeAddUint32(unpadded_row_size, unpack_alignment - 1, &temp)) { |
424 return false; | 436 return false; |
425 } | 437 } |
426 *padded_row_size = (temp / unpack_alignment) * unpack_alignment; | 438 *padded_row_size = (temp / unpack_alignment) * unpack_alignment; |
427 return true; | 439 return true; |
428 } | 440 } |
429 | 441 |
430 // Returns the amount of data glTexImage2D or glTexSubImage2D will access. | 442 // Returns the amount of data glTexImage*D or glTexSubImage*D will access. |
431 bool GLES2Util::ComputeImageDataSizes( | 443 bool GLES2Util::ComputeImageDataSizes( |
432 int width, int height, int format, int type, int unpack_alignment, | 444 int width, int height, int depth, int format, int type, |
433 uint32* size, uint32* ret_unpadded_row_size, uint32* ret_padded_row_size) { | 445 int unpack_alignment, uint32* size, uint32* ret_unpadded_row_size, |
| 446 uint32* ret_padded_row_size) { |
434 uint32 bytes_per_group = ComputeImageGroupSize(format, type); | 447 uint32 bytes_per_group = ComputeImageGroupSize(format, type); |
435 uint32 row_size; | 448 uint32 row_size; |
436 if (!SafeMultiplyUint32(width, bytes_per_group, &row_size)) { | 449 if (!SafeMultiplyUint32(width, bytes_per_group, &row_size)) { |
437 return false; | 450 return false; |
438 } | 451 } |
439 if (height > 1) { | 452 uint32 num_of_rows; |
| 453 if (!SafeMultiplyUint32(height, depth, &num_of_rows)) { |
| 454 return false; |
| 455 } |
| 456 if (num_of_rows > 1) { |
440 uint32 temp; | 457 uint32 temp; |
441 if (!SafeAddUint32(row_size, unpack_alignment - 1, &temp)) { | 458 if (!SafeAddUint32(row_size, unpack_alignment - 1, &temp)) { |
442 return false; | 459 return false; |
443 } | 460 } |
444 uint32 padded_row_size = (temp / unpack_alignment) * unpack_alignment; | 461 uint32 padded_row_size = (temp / unpack_alignment) * unpack_alignment; |
445 uint32 size_of_all_but_last_row; | 462 uint32 size_of_all_but_last_row; |
446 if (!SafeMultiplyUint32((height - 1), padded_row_size, | 463 if (!SafeMultiplyUint32((num_of_rows - 1), padded_row_size, |
447 &size_of_all_but_last_row)) { | 464 &size_of_all_but_last_row)) { |
448 return false; | 465 return false; |
449 } | 466 } |
450 if (!SafeAddUint32(size_of_all_but_last_row, row_size, size)) { | 467 if (!SafeAddUint32(size_of_all_but_last_row, row_size, size)) { |
451 return false; | 468 return false; |
452 } | 469 } |
453 if (ret_padded_row_size) { | 470 if (ret_padded_row_size) { |
454 *ret_padded_row_size = padded_row_size; | 471 *ret_padded_row_size = padded_row_size; |
455 } | 472 } |
456 } else { | 473 } else { |
457 if (!SafeMultiplyUint32(height, row_size, size)) { | 474 *size = row_size; |
458 return false; | |
459 } | |
460 if (ret_padded_row_size) { | 475 if (ret_padded_row_size) { |
461 *ret_padded_row_size = row_size; | 476 *ret_padded_row_size = row_size; |
462 } | 477 } |
463 } | 478 } |
464 if (ret_unpadded_row_size) { | 479 if (ret_unpadded_row_size) { |
465 *ret_unpadded_row_size = row_size; | 480 *ret_unpadded_row_size = row_size; |
466 } | 481 } |
467 | 482 |
468 return true; | 483 return true; |
469 } | 484 } |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 } | 968 } |
954 | 969 |
955 return true; | 970 return true; |
956 } | 971 } |
957 | 972 |
958 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h" | 973 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h" |
959 | 974 |
960 } // namespace gles2 | 975 } // namespace gles2 |
961 } // namespace gpu | 976 } // namespace gpu |
962 | 977 |
OLD | NEW |