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
3 // found in the LICENSE file.
5 // This file is here so other GLES2 related files can have a common set of
6 // includes where appropriate.
10 #include <GLES2/gl2ext.h>
11 #include <GLES2/gl2extchromium.h>
12 #include <GLES3/gl3.h>
14 #include "base/numerics/safe_math.h"
15 #include "gpu/command_buffer/common/gles2_cmd_format.h"
16 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
21 namespace gl_error_bit
{
24 kInvalidEnum
= (1 << 0),
25 kInvalidValue
= (1 << 1),
26 kInvalidOperation
= (1 << 2),
27 kOutOfMemory
= (1 << 3),
28 kInvalidFrameBufferOperation
= (1 << 4),
29 kContextLost
= (1 << 5)
33 int GLES2Util::GLGetNumValuesReturned(int id
) const {
35 // -- glGetBooleanv, glGetFloatv, glGetIntergerv
36 case GL_ACTIVE_TEXTURE
:
38 case GL_ALIASED_LINE_WIDTH_RANGE
:
40 case GL_ALIASED_POINT_SIZE_RANGE
:
44 case GL_ARRAY_BUFFER_BINDING
:
50 case GL_BLEND_DST_ALPHA
:
52 case GL_BLEND_DST_RGB
:
54 case GL_BLEND_EQUATION_ALPHA
:
56 case GL_BLEND_EQUATION_RGB
:
58 case GL_BLEND_SRC_ALPHA
:
60 case GL_BLEND_SRC_RGB
:
64 case GL_COLOR_CLEAR_VALUE
:
66 case GL_COLOR_WRITEMASK
:
68 case GL_COMPRESSED_TEXTURE_FORMATS
:
69 return num_compressed_texture_formats_
;
72 case GL_CULL_FACE_MODE
:
74 case GL_CURRENT_PROGRAM
:
78 case GL_DEPTH_CLEAR_VALUE
:
86 case GL_DEPTH_WRITEMASK
:
90 case GL_ELEMENT_ARRAY_BUFFER_BINDING
:
92 case GL_FRAMEBUFFER_BINDING
:
96 case GL_GENERATE_MIPMAP_HINT
:
100 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
102 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
106 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS
:
108 case GL_MAX_CUBE_MAP_TEXTURE_SIZE
:
110 case GL_MAX_FRAGMENT_UNIFORM_VECTORS
:
112 case GL_MAX_RENDERBUFFER_SIZE
:
114 case GL_MAX_TEXTURE_IMAGE_UNITS
:
116 case GL_MAX_TEXTURE_SIZE
:
118 case GL_MAX_VARYING_VECTORS
:
120 case GL_MAX_VERTEX_ATTRIBS
:
122 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS
:
124 case GL_MAX_VERTEX_UNIFORM_VECTORS
:
126 case GL_MAX_VIEWPORT_DIMS
:
128 case GL_NUM_COMPRESSED_TEXTURE_FORMATS
:
130 case GL_NUM_SHADER_BINARY_FORMATS
:
132 case GL_PACK_ALIGNMENT
:
134 case GL_PACK_REVERSE_ROW_ORDER_ANGLE
:
136 case GL_POLYGON_OFFSET_FACTOR
:
138 case GL_POLYGON_OFFSET_FILL
:
140 case GL_POLYGON_OFFSET_UNITS
:
144 case GL_RENDERBUFFER_BINDING
:
146 case GL_SAMPLE_BUFFERS
:
148 case GL_SAMPLE_COVERAGE_INVERT
:
150 case GL_SAMPLE_COVERAGE_VALUE
:
156 case GL_SCISSOR_TEST
:
158 case GL_SHADER_BINARY_FORMATS
:
159 return num_shader_binary_formats_
;
160 case GL_SHADER_COMPILER
:
162 case GL_STENCIL_BACK_FAIL
:
164 case GL_STENCIL_BACK_FUNC
:
166 case GL_STENCIL_BACK_PASS_DEPTH_FAIL
:
168 case GL_STENCIL_BACK_PASS_DEPTH_PASS
:
170 case GL_STENCIL_BACK_REF
:
172 case GL_STENCIL_BACK_VALUE_MASK
:
174 case GL_STENCIL_BACK_WRITEMASK
:
176 case GL_STENCIL_BITS
:
178 case GL_STENCIL_CLEAR_VALUE
:
180 case GL_STENCIL_FAIL
:
182 case GL_STENCIL_FUNC
:
184 case GL_STENCIL_PASS_DEPTH_FAIL
:
186 case GL_STENCIL_PASS_DEPTH_PASS
:
190 case GL_STENCIL_TEST
:
192 case GL_STENCIL_VALUE_MASK
:
194 case GL_STENCIL_WRITEMASK
:
196 case GL_SUBPIXEL_BITS
:
198 case GL_TEXTURE_BINDING_2D
:
200 case GL_TEXTURE_BINDING_CUBE_MAP
:
202 case GL_TEXTURE_BINDING_EXTERNAL_OES
:
204 case GL_TEXTURE_BINDING_RECTANGLE_ARB
:
206 case GL_UNPACK_ALIGNMENT
:
212 case GL_COPY_READ_BUFFER_BINDING
:
214 case GL_COPY_WRITE_BUFFER_BINDING
:
216 case GL_PIXEL_PACK_BUFFER_BINDING
:
218 case GL_PIXEL_UNPACK_BUFFER_BINDING
:
220 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
222 case GL_UNIFORM_BUFFER_BINDING
:
225 // -- glGetBooleanv, glGetFloatv, glGetIntergerv with
226 // GL_CHROMIUM_framebuffer_multisample
227 case GL_MAX_SAMPLES_EXT
:
229 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
:
232 // -- glGetBufferParameteriv
235 case GL_BUFFER_USAGE
:
238 // -- glGetFramebufferAttachmentParameteriv
239 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
:
241 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
:
243 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL
:
245 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE
:
247 // -- glGetFramebufferAttachmentParameteriv with
248 // GL_EXT_multisampled_render_to_texture
249 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT
:
251 // -- glGetFramebufferAttachmentParameteriv with
253 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT
:
257 case GL_DELETE_STATUS
:
261 case GL_VALIDATE_STATUS
:
263 case GL_INFO_LOG_LENGTH
:
265 case GL_ATTACHED_SHADERS
:
267 case GL_ACTIVE_ATTRIBUTES
:
269 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
:
271 case GL_ACTIVE_UNIFORMS
:
273 case GL_ACTIVE_UNIFORM_MAX_LENGTH
:
276 // -- glGetRenderbufferAttachmentParameteriv
277 case GL_RENDERBUFFER_WIDTH
:
279 case GL_RENDERBUFFER_HEIGHT
:
281 case GL_RENDERBUFFER_INTERNAL_FORMAT
:
283 case GL_RENDERBUFFER_RED_SIZE
:
285 case GL_RENDERBUFFER_GREEN_SIZE
:
287 case GL_RENDERBUFFER_BLUE_SIZE
:
289 case GL_RENDERBUFFER_ALPHA_SIZE
:
291 case GL_RENDERBUFFER_DEPTH_SIZE
:
293 case GL_RENDERBUFFER_STENCIL_SIZE
:
295 // -- glGetRenderbufferAttachmentParameteriv with
296 // GL_EXT_multisampled_render_to_texture
297 case GL_RENDERBUFFER_SAMPLES_EXT
:
303 // Already defined under glGetFramebufferAttachemntParameteriv.
304 // case GL_DELETE_STATUS:
306 case GL_COMPILE_STATUS
:
308 // Already defined under glGetFramebufferAttachemntParameteriv.
309 // case GL_INFO_LOG_LENGTH:
311 case GL_SHADER_SOURCE_LENGTH
:
313 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE
:
316 // -- glGetTexParameterfv, glGetTexParameteriv
317 case GL_TEXTURE_MAG_FILTER
:
319 case GL_TEXTURE_MIN_FILTER
:
321 case GL_TEXTURE_WRAP_R
:
323 case GL_TEXTURE_WRAP_S
:
325 case GL_TEXTURE_WRAP_T
:
327 case GL_TEXTURE_COMPARE_FUNC
:
329 case GL_TEXTURE_COMPARE_MODE
:
331 case GL_TEXTURE_MAX_LOD
:
333 case GL_TEXTURE_MIN_LOD
:
335 case GL_TEXTURE_BASE_LEVEL
:
337 case GL_TEXTURE_MAX_LEVEL
:
339 case GL_TEXTURE_IMMUTABLE_FORMAT
:
341 case GL_TEXTURE_IMMUTABLE_LEVELS
:
343 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
346 // -- glGetVertexAttrib
347 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
:
349 case GL_VERTEX_ATTRIB_ARRAY_ENABLED
:
351 case GL_VERTEX_ATTRIB_ARRAY_SIZE
:
353 case GL_VERTEX_ATTRIB_ARRAY_STRIDE
:
355 case GL_VERTEX_ATTRIB_ARRAY_TYPE
:
357 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED
:
359 case GL_CURRENT_VERTEX_ATTRIB
:
361 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
363 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR
:
371 case GL_SYNC_CONDITION
:
376 // -- glHint with GL_OES_standard_derivatives
377 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES
:
380 // Chromium internal bind_generates_resource query
381 case GL_BIND_GENERATES_RESOURCE_CHROMIUM
:
392 // Return the number of elements per group of a specified format.
393 int ElementsPerGroup(int format
, int type
) {
395 case GL_UNSIGNED_SHORT_5_6_5
:
396 case GL_UNSIGNED_SHORT_4_4_4_4
:
397 case GL_UNSIGNED_SHORT_5_5_5_1
:
398 case GL_UNSIGNED_INT_24_8_OES
:
399 case GL_UNSIGNED_INT_2_10_10_10_REV
:
400 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
401 case GL_UNSIGNED_INT_5_9_9_9_REV
:
402 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
413 case GL_LUMINANCE_ALPHA
:
418 case GL_RGBA_INTEGER
:
420 case GL_SRGB_ALPHA_EXT
:
424 case GL_DEPTH_COMPONENT
:
425 case GL_DEPTH_COMPONENT24_OES
:
426 case GL_DEPTH_COMPONENT32_OES
:
427 case GL_DEPTH_COMPONENT16
:
428 case GL_DEPTH24_STENCIL8_OES
:
429 case GL_DEPTH_STENCIL_OES
:
438 // Return the number of bytes per element, based on the element type.
439 int BytesPerElement(int type
) {
441 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
444 case GL_UNSIGNED_INT_24_8_OES
:
445 case GL_UNSIGNED_INT
:
446 case GL_UNSIGNED_INT_2_10_10_10_REV
:
447 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
448 case GL_UNSIGNED_INT_5_9_9_9_REV
:
450 case GL_HALF_FLOAT_OES
:
451 case GL_UNSIGNED_SHORT
:
453 case GL_UNSIGNED_SHORT_5_6_5
:
454 case GL_UNSIGNED_SHORT_4_4_4_4
:
455 case GL_UNSIGNED_SHORT_5_5_5_1
:
457 case GL_UNSIGNED_BYTE
:
465 } // anonymous namespace
467 uint32
GLES2Util::ComputeImageGroupSize(int format
, int type
) {
468 int bytes_per_element
= BytesPerElement(type
);
469 DCHECK_GE(8, bytes_per_element
);
470 int elements_per_group
= ElementsPerGroup(format
, type
);
471 DCHECK_GE(4, elements_per_group
);
472 return bytes_per_element
* elements_per_group
;
475 bool GLES2Util::ComputeImagePaddedRowSize(
476 int width
, int format
, int type
, int unpack_alignment
,
477 uint32
* padded_row_size
) {
478 DCHECK(unpack_alignment
== 1 || unpack_alignment
== 2 ||
479 unpack_alignment
== 4 || unpack_alignment
== 8);
480 uint32 bytes_per_group
= ComputeImageGroupSize(format
, type
);
481 uint32 unpadded_row_size
;
482 if (!SafeMultiplyUint32(width
, bytes_per_group
, &unpadded_row_size
)) {
486 if (!SafeAddUint32(unpadded_row_size
, unpack_alignment
- 1, &temp
)) {
489 *padded_row_size
= (temp
/ unpack_alignment
) * unpack_alignment
;
493 // Returns the amount of data glTexImage*D or glTexSubImage*D will access.
494 bool GLES2Util::ComputeImageDataSizes(
495 int width
, int height
, int depth
, int format
, int type
,
496 int unpack_alignment
, uint32
* size
, uint32
* ret_unpadded_row_size
,
497 uint32
* ret_padded_row_size
) {
498 DCHECK(unpack_alignment
== 1 || unpack_alignment
== 2 ||
499 unpack_alignment
== 4 || unpack_alignment
== 8);
500 uint32 bytes_per_group
= ComputeImageGroupSize(format
, type
);
502 if (!SafeMultiplyUint32(width
, bytes_per_group
, &row_size
)) {
506 if (!SafeMultiplyUint32(height
, depth
, &num_of_rows
)) {
509 if (num_of_rows
> 1) {
511 if (!SafeAddUint32(row_size
, unpack_alignment
- 1, &temp
)) {
514 uint32 padded_row_size
= (temp
/ unpack_alignment
) * unpack_alignment
;
515 uint32 size_of_all_but_last_row
;
516 if (!SafeMultiplyUint32((num_of_rows
- 1), padded_row_size
,
517 &size_of_all_but_last_row
)) {
520 if (!SafeAddUint32(size_of_all_but_last_row
, row_size
, size
)) {
523 if (ret_padded_row_size
) {
524 *ret_padded_row_size
= padded_row_size
;
528 if (ret_padded_row_size
) {
529 *ret_padded_row_size
= row_size
;
532 if (ret_unpadded_row_size
) {
533 *ret_unpadded_row_size
= row_size
;
539 size_t GLES2Util::RenderbufferBytesPerPixel(int format
) {
541 case GL_STENCIL_INDEX8
:
546 case GL_DEPTH_COMPONENT16
:
550 case GL_DEPTH24_STENCIL8_OES
:
553 case GL_DEPTH_COMPONENT24_OES
:
560 uint32
GLES2Util::GetElementSizeForUniformType(int type
) {
569 return sizeof(GLfloat
);
579 case GL_SAMPLER_CUBE
:
580 case GL_SAMPLER_2D_RECT_ARB
: // extension.
581 case GL_SAMPLER_EXTERNAL_OES
: // extension.
582 return sizeof(GLint
);
585 case GL_UNSIGNED_INT
:
586 case GL_UNSIGNED_INT_VEC2
:
587 case GL_UNSIGNED_INT_VEC3
:
588 case GL_UNSIGNED_INT_VEC4
:
589 return sizeof(GLuint
);
591 case GL_SAMPLER_2D_SHADOW
:
592 case GL_SAMPLER_2D_ARRAY
:
593 case GL_SAMPLER_2D_ARRAY_SHADOW
:
594 case GL_SAMPLER_CUBE_SHADOW
:
595 case GL_INT_SAMPLER_2D
:
596 case GL_INT_SAMPLER_3D
:
597 case GL_INT_SAMPLER_CUBE
:
598 case GL_INT_SAMPLER_2D_ARRAY
:
599 case GL_UNSIGNED_INT_SAMPLER_2D
:
600 case GL_UNSIGNED_INT_SAMPLER_3D
:
601 case GL_UNSIGNED_INT_SAMPLER_CUBE
:
602 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY
:
603 return sizeof(GLint
);
604 case GL_FLOAT_MAT2x3
:
605 case GL_FLOAT_MAT3x2
:
606 case GL_FLOAT_MAT2x4
:
607 case GL_FLOAT_MAT4x2
:
608 case GL_FLOAT_MAT3x4
:
609 case GL_FLOAT_MAT4x3
:
610 return sizeof(GLfloat
);
617 uint32
GLES2Util::GetElementCountForUniformType(int type
) {
623 case GL_SAMPLER_CUBE
:
624 case GL_SAMPLER_2D_RECT_ARB
: // extension.
625 case GL_SAMPLER_EXTERNAL_OES
: // extension.
646 case GL_UNSIGNED_INT
:
648 case GL_SAMPLER_2D_SHADOW
:
649 case GL_SAMPLER_2D_ARRAY
:
650 case GL_SAMPLER_2D_ARRAY_SHADOW
:
651 case GL_SAMPLER_CUBE_SHADOW
:
652 case GL_INT_SAMPLER_2D
:
653 case GL_INT_SAMPLER_3D
:
654 case GL_INT_SAMPLER_CUBE
:
655 case GL_INT_SAMPLER_2D_ARRAY
:
656 case GL_UNSIGNED_INT_SAMPLER_2D
:
657 case GL_UNSIGNED_INT_SAMPLER_3D
:
658 case GL_UNSIGNED_INT_SAMPLER_CUBE
:
659 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY
:
661 case GL_UNSIGNED_INT_VEC2
:
663 case GL_UNSIGNED_INT_VEC3
:
665 case GL_UNSIGNED_INT_VEC4
:
667 case GL_FLOAT_MAT2x3
:
668 case GL_FLOAT_MAT3x2
:
670 case GL_FLOAT_MAT2x4
:
671 case GL_FLOAT_MAT4x2
:
673 case GL_FLOAT_MAT3x4
:
674 case GL_FLOAT_MAT4x3
:
682 size_t GLES2Util::GetGLTypeSizeForTexturesAndBuffers(uint32 type
) {
685 return sizeof(GLbyte
); // NOLINT
686 case GL_UNSIGNED_BYTE
:
687 return sizeof(GLubyte
); // NOLINT
689 return sizeof(GLshort
); // NOLINT
690 case GL_UNSIGNED_SHORT
:
691 return sizeof(GLushort
); // NOLINT
693 return sizeof(GLint
); // NOLINT
694 case GL_UNSIGNED_INT
:
695 return sizeof(GLuint
); // NOLINT
697 return sizeof(GLfloat
); // NOLINT
699 return sizeof(GLfixed
); // NOLINT
705 uint32
GLES2Util::GLErrorToErrorBit(uint32 error
) {
707 case GL_INVALID_ENUM
:
708 return gl_error_bit::kInvalidEnum
;
709 case GL_INVALID_VALUE
:
710 return gl_error_bit::kInvalidValue
;
711 case GL_INVALID_OPERATION
:
712 return gl_error_bit::kInvalidOperation
;
713 case GL_OUT_OF_MEMORY
:
714 return gl_error_bit::kOutOfMemory
;
715 case GL_INVALID_FRAMEBUFFER_OPERATION
:
716 return gl_error_bit::kInvalidFrameBufferOperation
;
717 case GL_CONTEXT_LOST_KHR
:
718 return gl_error_bit::kContextLost
;
721 return gl_error_bit::kNoError
;
725 uint32
GLES2Util::GLErrorBitToGLError(uint32 error_bit
) {
727 case gl_error_bit::kInvalidEnum
:
728 return GL_INVALID_ENUM
;
729 case gl_error_bit::kInvalidValue
:
730 return GL_INVALID_VALUE
;
731 case gl_error_bit::kInvalidOperation
:
732 return GL_INVALID_OPERATION
;
733 case gl_error_bit::kOutOfMemory
:
734 return GL_OUT_OF_MEMORY
;
735 case gl_error_bit::kInvalidFrameBufferOperation
:
736 return GL_INVALID_FRAMEBUFFER_OPERATION
;
737 case gl_error_bit::kContextLost
:
738 return GL_CONTEXT_LOST_KHR
;
745 uint32
GLES2Util::IndexToGLFaceTarget(int index
) {
746 static uint32 faces
[] = {
747 GL_TEXTURE_CUBE_MAP_POSITIVE_X
,
748 GL_TEXTURE_CUBE_MAP_NEGATIVE_X
,
749 GL_TEXTURE_CUBE_MAP_POSITIVE_Y
,
750 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
751 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
,
752 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
757 size_t GLES2Util::GLTargetToFaceIndex(uint32 target
) {
760 case GL_TEXTURE_EXTERNAL_OES
:
761 case GL_TEXTURE_RECTANGLE_ARB
:
763 case GL_TEXTURE_2D_ARRAY
:
765 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
767 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
769 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
771 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
773 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
775 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
783 uint32
GLES2Util::GetPreferredGLReadPixelsFormat(uint32 internal_format
) {
784 switch (internal_format
) {
796 uint32
GLES2Util::GetPreferredGLReadPixelsType(
797 uint32 internal_format
, uint32 texture_type
) {
798 switch (internal_format
) {
804 return GL_HALF_FLOAT_OES
;
807 // Unsized internal format, check the type
808 switch (texture_type
) {
810 case GL_HALF_FLOAT_OES
:
813 return GL_UNSIGNED_BYTE
;
816 return GL_UNSIGNED_BYTE
;
820 uint32
GLES2Util::GetChannelsForFormat(int format
) {
823 case GL_ALPHA16F_EXT
:
824 case GL_ALPHA32F_EXT
:
828 case GL_LUMINANCE_ALPHA
:
838 case GL_R11F_G11F_B10F
:
855 case GL_SRGB_ALPHA_EXT
:
856 case GL_SRGB8_ALPHA8_EXT
:
867 case GL_DEPTH_COMPONENT32_OES
:
868 case GL_DEPTH_COMPONENT24_OES
:
869 case GL_DEPTH_COMPONENT16
:
870 case GL_DEPTH_COMPONENT
:
871 case GL_DEPTH_COMPONENT32F
:
873 case GL_STENCIL_INDEX8
:
875 case GL_DEPTH_STENCIL_OES
:
876 case GL_DEPTH24_STENCIL8_OES
:
877 case GL_DEPTH32F_STENCIL8
:
878 return kDepth
| kStencil
;
902 return kRed
| kGreen
;
908 uint32
GLES2Util::GetChannelsNeededForAttachmentType(
909 int type
, uint32 max_color_attachments
) {
911 case GL_DEPTH_ATTACHMENT
:
913 case GL_STENCIL_ATTACHMENT
:
916 if (type
>= GL_COLOR_ATTACHMENT0
&&
917 type
< static_cast<int>(
918 GL_COLOR_ATTACHMENT0
+ max_color_attachments
)) {
925 std::string
GLES2Util::GetStringEnum(uint32 value
) {
926 const EnumToString
* entry
= enum_to_string_table_
;
927 const EnumToString
* end
= entry
+ enum_to_string_table_len_
;
928 for (;entry
< end
; ++entry
) {
929 if (value
== entry
->value
) {
933 std::stringstream ss
;
935 ss
.width(value
< 0x10000 ? 4 : 8);
936 ss
<< std::hex
<< value
;
937 return "0x" + ss
.str();
940 std::string
GLES2Util::GetStringError(uint32 value
) {
941 static EnumToString string_table
[] = {
942 { GL_NONE
, "GL_NONE" },
944 return GLES2Util::GetQualifiedEnumString(
945 string_table
, arraysize(string_table
), value
);
948 std::string
GLES2Util::GetStringBool(uint32 value
) {
949 return value
? "GL_TRUE" : "GL_FALSE";
952 std::string
GLES2Util::GetQualifiedEnumString(
953 const EnumToString
* table
, size_t count
, uint32 value
) {
954 for (const EnumToString
* end
= table
+ count
; table
< end
; ++table
) {
955 if (table
->value
== value
) {
959 return GetStringEnum(value
);
962 bool GLES2Util::ParseUniformName(
963 const std::string
& name
,
966 bool* getting_array
) {
969 bool getting_array_location
= false;
970 size_t open_pos
= std::string::npos
;
971 base::CheckedNumeric
<int> index
= 0;
972 if (name
[name
.size() - 1] == ']') {
973 if (name
.size() < 3) {
976 open_pos
= name
.find_last_of('[');
977 if (open_pos
== std::string::npos
||
978 open_pos
>= name
.size() - 2) {
981 size_t last
= name
.size() - 1;
982 for (size_t pos
= open_pos
+ 1; pos
< last
; ++pos
) {
983 int8 digit
= name
[pos
] - '0';
984 if (digit
< 0 || digit
> 9) {
987 index
= index
* 10 + digit
;
989 if (!index
.IsValid()) {
992 getting_array_location
= true;
994 *getting_array
= getting_array_location
;
995 *element_index
= index
.ValueOrDie();
996 *array_pos
= open_pos
;
1000 size_t GLES2Util::CalcClearBufferivDataCount(int buffer
) {
1011 size_t GLES2Util::CalcClearBufferfvDataCount(int buffer
) {
1023 void GLES2Util::MapUint64ToTwoUint32(
1024 uint64_t v64
, uint32_t* v32_0
, uint32_t* v32_1
) {
1025 DCHECK(v32_0
&& v32_1
);
1026 *v32_0
= static_cast<uint32_t>(v64
& 0xFFFFFFFF);
1027 *v32_1
= static_cast<uint32_t>((v64
& 0xFFFFFFFF00000000) >> 32);
1031 uint64_t GLES2Util::MapTwoUint32ToUint64(uint32_t v32_0
, uint32_t v32_1
) {
1032 uint64_t v64
= v32_1
;
1033 return (v64
<< 32) | v32_0
;
1037 uint32_t GLES2Util::MapBufferTargetToBindingEnum(uint32_t target
) {
1039 case GL_ARRAY_BUFFER
:
1040 return GL_ARRAY_BUFFER_BINDING
;
1041 case GL_COPY_READ_BUFFER
:
1042 return GL_COPY_READ_BUFFER_BINDING
;
1043 case GL_COPY_WRITE_BUFFER
:
1044 return GL_COPY_WRITE_BUFFER_BINDING
;
1045 case GL_ELEMENT_ARRAY_BUFFER
:
1046 return GL_ELEMENT_ARRAY_BUFFER_BINDING
;
1047 case GL_PIXEL_PACK_BUFFER
:
1048 return GL_PIXEL_PACK_BUFFER_BINDING
;
1049 case GL_PIXEL_UNPACK_BUFFER
:
1050 return GL_PIXEL_UNPACK_BUFFER_BINDING
;
1051 case GL_TRANSFORM_FEEDBACK_BUFFER
:
1052 return GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
;
1053 case GL_UNIFORM_BUFFER
:
1054 return GL_UNIFORM_BUFFER_BINDING
;
1063 // WebGraphicsContext3DCommandBufferImpl configuration attributes. Those in
1064 // the 16-bit range are the same as used by EGL. Those outside the 16-bit range
1065 // are unique to Chromium. Attributes are matched using a closest fit algorithm.
1067 // From <EGL/egl.h>.
1068 const int32 kAlphaSize
= 0x3021; // EGL_ALPHA_SIZE
1069 const int32 kBlueSize
= 0x3022; // EGL_BLUE_SIZE
1070 const int32 kGreenSize
= 0x3023; // EGL_GREEN_SIZE
1071 const int32 kRedSize
= 0x3024; // EGL_RED_SIZE
1072 const int32 kDepthSize
= 0x3025; // EGL_DEPTH_SIZE
1073 const int32 kStencilSize
= 0x3026; // EGL_STENCIL_SIZE
1074 const int32 kSamples
= 0x3031; // EGL_SAMPLES
1075 const int32 kSampleBuffers
= 0x3032; // EGL_SAMPLE_BUFFERS
1076 const int32 kNone
= 0x3038; // EGL_NONE
1077 const int32 kSwapBehavior
= 0x3093; // EGL_SWAP_BEHAVIOR
1078 const int32 kBufferPreserved
= 0x3094; // EGL_BUFFER_PRESERVED
1079 const int32 kBufferDestroyed
= 0x3095; // EGL_BUFFER_DESTROYED
1082 const int32 kBindGeneratesResource
= 0x10000;
1083 const int32 kFailIfMajorPerfCaveat
= 0x10001;
1084 const int32 kLoseContextWhenOutOfMemory
= 0x10002;
1085 const int32 kES3ContextRequired
= 0x10003;
1089 ContextCreationAttribHelper::ContextCreationAttribHelper()
1098 buffer_preserved(true),
1099 bind_generates_resource(true),
1100 fail_if_major_perf_caveat(false),
1101 lose_context_when_out_of_memory(false),
1102 es3_context_required(false) {}
1104 void ContextCreationAttribHelper::Serialize(std::vector
<int32
>* attribs
) const {
1105 if (alpha_size
!= -1) {
1106 attribs
->push_back(kAlphaSize
);
1107 attribs
->push_back(alpha_size
);
1109 if (blue_size
!= -1) {
1110 attribs
->push_back(kBlueSize
);
1111 attribs
->push_back(blue_size
);
1113 if (green_size
!= -1) {
1114 attribs
->push_back(kGreenSize
);
1115 attribs
->push_back(green_size
);
1117 if (red_size
!= -1) {
1118 attribs
->push_back(kRedSize
);
1119 attribs
->push_back(red_size
);
1121 if (depth_size
!= -1) {
1122 attribs
->push_back(kDepthSize
);
1123 attribs
->push_back(depth_size
);
1125 if (stencil_size
!= -1) {
1126 attribs
->push_back(kStencilSize
);
1127 attribs
->push_back(stencil_size
);
1129 if (samples
!= -1) {
1130 attribs
->push_back(kSamples
);
1131 attribs
->push_back(samples
);
1133 if (sample_buffers
!= -1) {
1134 attribs
->push_back(kSampleBuffers
);
1135 attribs
->push_back(sample_buffers
);
1137 attribs
->push_back(kSwapBehavior
);
1138 attribs
->push_back(buffer_preserved
? kBufferPreserved
: kBufferDestroyed
);
1139 attribs
->push_back(kBindGeneratesResource
);
1140 attribs
->push_back(bind_generates_resource
? 1 : 0);
1141 attribs
->push_back(kFailIfMajorPerfCaveat
);
1142 attribs
->push_back(fail_if_major_perf_caveat
? 1 : 0);
1143 attribs
->push_back(kLoseContextWhenOutOfMemory
);
1144 attribs
->push_back(lose_context_when_out_of_memory
? 1 : 0);
1145 attribs
->push_back(kES3ContextRequired
);
1146 attribs
->push_back(es3_context_required
? 1 : 0);
1147 attribs
->push_back(kNone
);
1150 bool ContextCreationAttribHelper::Parse(const std::vector
<int32
>& attribs
) {
1151 for (size_t i
= 0; i
< attribs
.size(); i
+= 2) {
1152 const int32 attrib
= attribs
[i
];
1153 if (i
+ 1 >= attribs
.size()) {
1154 if (attrib
== kNone
) {
1158 DLOG(ERROR
) << "Missing value after context creation attribute: "
1163 const int32 value
= attribs
[i
+1];
1181 stencil_size
= value
;
1186 case kSampleBuffers
:
1187 sample_buffers
= value
;
1190 buffer_preserved
= value
== kBufferPreserved
;
1192 case kBindGeneratesResource
:
1193 bind_generates_resource
= value
!= 0;
1195 case kFailIfMajorPerfCaveat
:
1196 fail_if_major_perf_caveat
= value
!= 0;
1198 case kLoseContextWhenOutOfMemory
:
1199 lose_context_when_out_of_memory
= value
!= 0;
1201 case kES3ContextRequired
:
1202 es3_context_required
= value
!= 0;
1205 // Terminate list, even if more attributes.
1208 DLOG(ERROR
) << "Invalid context creation attribute: " << attrib
;
1216 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h"
1218 } // namespace gles2