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
:
239 case GL_BUFFER_MAPPED
:
241 case GL_BUFFER_ACCESS_FLAGS
:
243 case GL_BUFFER_MAP_LENGTH
:
245 case GL_BUFFER_MAP_OFFSET
:
248 // -- glGetFramebufferAttachmentParameteriv
249 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
:
251 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
:
253 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL
:
255 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE
:
257 // -- glGetFramebufferAttachmentParameteriv with
258 // GL_EXT_multisampled_render_to_texture
259 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT
:
261 // -- glGetFramebufferAttachmentParameteriv with
263 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT
:
267 case GL_DELETE_STATUS
:
271 case GL_VALIDATE_STATUS
:
273 case GL_INFO_LOG_LENGTH
:
275 case GL_ATTACHED_SHADERS
:
277 case GL_ACTIVE_ATTRIBUTES
:
279 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
:
281 case GL_ACTIVE_UNIFORMS
:
283 case GL_ACTIVE_UNIFORM_MAX_LENGTH
:
286 // -- glGetRenderbufferAttachmentParameteriv
287 case GL_RENDERBUFFER_WIDTH
:
289 case GL_RENDERBUFFER_HEIGHT
:
291 case GL_RENDERBUFFER_INTERNAL_FORMAT
:
293 case GL_RENDERBUFFER_RED_SIZE
:
295 case GL_RENDERBUFFER_GREEN_SIZE
:
297 case GL_RENDERBUFFER_BLUE_SIZE
:
299 case GL_RENDERBUFFER_ALPHA_SIZE
:
301 case GL_RENDERBUFFER_DEPTH_SIZE
:
303 case GL_RENDERBUFFER_STENCIL_SIZE
:
305 // -- glGetRenderbufferAttachmentParameteriv with
306 // GL_EXT_multisampled_render_to_texture
307 case GL_RENDERBUFFER_SAMPLES_EXT
:
313 // Already defined under glGetFramebufferAttachemntParameteriv.
314 // case GL_DELETE_STATUS:
316 case GL_COMPILE_STATUS
:
318 // Already defined under glGetFramebufferAttachemntParameteriv.
319 // case GL_INFO_LOG_LENGTH:
321 case GL_SHADER_SOURCE_LENGTH
:
323 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE
:
326 // -- glGetTexParameterfv, glGetTexParameteriv
327 case GL_TEXTURE_MAG_FILTER
:
329 case GL_TEXTURE_MIN_FILTER
:
331 case GL_TEXTURE_WRAP_R
:
333 case GL_TEXTURE_WRAP_S
:
335 case GL_TEXTURE_WRAP_T
:
337 case GL_TEXTURE_COMPARE_FUNC
:
339 case GL_TEXTURE_COMPARE_MODE
:
341 case GL_TEXTURE_MAX_LOD
:
343 case GL_TEXTURE_MIN_LOD
:
345 case GL_TEXTURE_BASE_LEVEL
:
347 case GL_TEXTURE_MAX_LEVEL
:
349 case GL_TEXTURE_IMMUTABLE_FORMAT
:
351 case GL_TEXTURE_IMMUTABLE_LEVELS
:
353 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
356 // -- glGetVertexAttrib
357 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
:
359 case GL_VERTEX_ATTRIB_ARRAY_ENABLED
:
361 case GL_VERTEX_ATTRIB_ARRAY_SIZE
:
363 case GL_VERTEX_ATTRIB_ARRAY_STRIDE
:
365 case GL_VERTEX_ATTRIB_ARRAY_TYPE
:
367 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED
:
369 case GL_CURRENT_VERTEX_ATTRIB
:
371 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
373 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR
:
381 case GL_SYNC_CONDITION
:
386 // -- glHint with GL_OES_standard_derivatives
387 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES
:
390 // Chromium internal bind_generates_resource query
391 case GL_BIND_GENERATES_RESOURCE_CHROMIUM
:
402 // Return the number of elements per group of a specified format.
403 int ElementsPerGroup(int format
, int type
) {
405 case GL_UNSIGNED_SHORT_5_6_5
:
406 case GL_UNSIGNED_SHORT_4_4_4_4
:
407 case GL_UNSIGNED_SHORT_5_5_5_1
:
408 case GL_UNSIGNED_INT_24_8_OES
:
409 case GL_UNSIGNED_INT_2_10_10_10_REV
:
410 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
411 case GL_UNSIGNED_INT_5_9_9_9_REV
:
412 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
423 case GL_LUMINANCE_ALPHA
:
428 case GL_RGBA_INTEGER
:
430 case GL_SRGB_ALPHA_EXT
:
434 case GL_DEPTH_COMPONENT
:
435 case GL_DEPTH_COMPONENT24_OES
:
436 case GL_DEPTH_COMPONENT32_OES
:
437 case GL_DEPTH_COMPONENT16
:
438 case GL_DEPTH24_STENCIL8_OES
:
439 case GL_DEPTH_STENCIL_OES
:
448 // Return the number of bytes per element, based on the element type.
449 int BytesPerElement(int type
) {
451 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
454 case GL_UNSIGNED_INT_24_8_OES
:
455 case GL_UNSIGNED_INT
:
457 case GL_UNSIGNED_INT_2_10_10_10_REV
:
458 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
459 case GL_UNSIGNED_INT_5_9_9_9_REV
:
462 case GL_HALF_FLOAT_OES
:
463 case GL_UNSIGNED_SHORT
:
465 case GL_UNSIGNED_SHORT_5_6_5
:
466 case GL_UNSIGNED_SHORT_4_4_4_4
:
467 case GL_UNSIGNED_SHORT_5_5_5_1
:
469 case GL_UNSIGNED_BYTE
:
477 } // anonymous namespace
479 uint32
GLES2Util::ComputeImageGroupSize(int format
, int type
) {
480 int bytes_per_element
= BytesPerElement(type
);
481 DCHECK_GE(8, bytes_per_element
);
482 int elements_per_group
= ElementsPerGroup(format
, type
);
483 DCHECK_GE(4, elements_per_group
);
484 return bytes_per_element
* elements_per_group
;
487 bool GLES2Util::ComputeImagePaddedRowSize(
488 int width
, int format
, int type
, int unpack_alignment
,
489 uint32
* padded_row_size
) {
490 DCHECK(unpack_alignment
== 1 || unpack_alignment
== 2 ||
491 unpack_alignment
== 4 || unpack_alignment
== 8);
492 uint32 bytes_per_group
= ComputeImageGroupSize(format
, type
);
493 uint32 unpadded_row_size
;
494 if (!SafeMultiplyUint32(width
, bytes_per_group
, &unpadded_row_size
)) {
498 if (!SafeAddUint32(unpadded_row_size
, unpack_alignment
- 1, &temp
)) {
501 *padded_row_size
= (temp
/ unpack_alignment
) * unpack_alignment
;
505 // Returns the amount of data glTexImage*D or glTexSubImage*D will access.
506 bool GLES2Util::ComputeImageDataSizes(
507 int width
, int height
, int depth
, int format
, int type
,
508 int unpack_alignment
, uint32
* size
, uint32
* ret_unpadded_row_size
,
509 uint32
* ret_padded_row_size
) {
510 DCHECK(unpack_alignment
== 1 || unpack_alignment
== 2 ||
511 unpack_alignment
== 4 || unpack_alignment
== 8);
512 uint32 bytes_per_group
= ComputeImageGroupSize(format
, type
);
514 if (!SafeMultiplyUint32(width
, bytes_per_group
, &row_size
)) {
518 if (!SafeMultiplyUint32(height
, depth
, &num_of_rows
)) {
521 if (num_of_rows
> 1) {
523 if (!SafeAddUint32(row_size
, unpack_alignment
- 1, &temp
)) {
526 uint32 padded_row_size
= (temp
/ unpack_alignment
) * unpack_alignment
;
527 uint32 size_of_all_but_last_row
;
528 if (!SafeMultiplyUint32((num_of_rows
- 1), padded_row_size
,
529 &size_of_all_but_last_row
)) {
532 if (!SafeAddUint32(size_of_all_but_last_row
, row_size
, size
)) {
535 if (ret_padded_row_size
) {
536 *ret_padded_row_size
= padded_row_size
;
540 if (ret_padded_row_size
) {
541 *ret_padded_row_size
= row_size
;
544 if (ret_unpadded_row_size
) {
545 *ret_unpadded_row_size
= row_size
;
551 size_t GLES2Util::RenderbufferBytesPerPixel(int format
) {
553 case GL_STENCIL_INDEX8
:
558 case GL_DEPTH_COMPONENT16
:
562 case GL_DEPTH24_STENCIL8_OES
:
565 case GL_DEPTH_COMPONENT24_OES
:
572 uint32
GLES2Util::GetElementSizeForUniformType(int type
) {
581 return sizeof(GLfloat
);
591 case GL_SAMPLER_CUBE
:
592 case GL_SAMPLER_2D_RECT_ARB
: // extension.
593 case GL_SAMPLER_EXTERNAL_OES
: // extension.
594 return sizeof(GLint
);
597 case GL_UNSIGNED_INT
:
598 case GL_UNSIGNED_INT_VEC2
:
599 case GL_UNSIGNED_INT_VEC3
:
600 case GL_UNSIGNED_INT_VEC4
:
601 return sizeof(GLuint
);
603 case GL_SAMPLER_2D_SHADOW
:
604 case GL_SAMPLER_2D_ARRAY
:
605 case GL_SAMPLER_2D_ARRAY_SHADOW
:
606 case GL_SAMPLER_CUBE_SHADOW
:
607 case GL_INT_SAMPLER_2D
:
608 case GL_INT_SAMPLER_3D
:
609 case GL_INT_SAMPLER_CUBE
:
610 case GL_INT_SAMPLER_2D_ARRAY
:
611 case GL_UNSIGNED_INT_SAMPLER_2D
:
612 case GL_UNSIGNED_INT_SAMPLER_3D
:
613 case GL_UNSIGNED_INT_SAMPLER_CUBE
:
614 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY
:
615 return sizeof(GLint
);
616 case GL_FLOAT_MAT2x3
:
617 case GL_FLOAT_MAT3x2
:
618 case GL_FLOAT_MAT2x4
:
619 case GL_FLOAT_MAT4x2
:
620 case GL_FLOAT_MAT3x4
:
621 case GL_FLOAT_MAT4x3
:
622 return sizeof(GLfloat
);
629 uint32
GLES2Util::GetElementCountForUniformType(int type
) {
635 case GL_SAMPLER_CUBE
:
636 case GL_SAMPLER_2D_RECT_ARB
: // extension.
637 case GL_SAMPLER_EXTERNAL_OES
: // extension.
658 case GL_UNSIGNED_INT
:
660 case GL_SAMPLER_2D_SHADOW
:
661 case GL_SAMPLER_2D_ARRAY
:
662 case GL_SAMPLER_2D_ARRAY_SHADOW
:
663 case GL_SAMPLER_CUBE_SHADOW
:
664 case GL_INT_SAMPLER_2D
:
665 case GL_INT_SAMPLER_3D
:
666 case GL_INT_SAMPLER_CUBE
:
667 case GL_INT_SAMPLER_2D_ARRAY
:
668 case GL_UNSIGNED_INT_SAMPLER_2D
:
669 case GL_UNSIGNED_INT_SAMPLER_3D
:
670 case GL_UNSIGNED_INT_SAMPLER_CUBE
:
671 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY
:
673 case GL_UNSIGNED_INT_VEC2
:
675 case GL_UNSIGNED_INT_VEC3
:
677 case GL_UNSIGNED_INT_VEC4
:
679 case GL_FLOAT_MAT2x3
:
680 case GL_FLOAT_MAT3x2
:
682 case GL_FLOAT_MAT2x4
:
683 case GL_FLOAT_MAT4x2
:
685 case GL_FLOAT_MAT3x4
:
686 case GL_FLOAT_MAT4x3
:
694 size_t GLES2Util::GetGLTypeSizeForTexturesAndBuffers(uint32 type
) {
697 return sizeof(GLbyte
); // NOLINT
698 case GL_UNSIGNED_BYTE
:
699 return sizeof(GLubyte
); // NOLINT
701 return sizeof(GLshort
); // NOLINT
702 case GL_UNSIGNED_SHORT
:
703 return sizeof(GLushort
); // NOLINT
705 return sizeof(GLint
); // NOLINT
706 case GL_UNSIGNED_INT
:
707 return sizeof(GLuint
); // NOLINT
709 return sizeof(GLfloat
); // NOLINT
711 return sizeof(GLfixed
); // NOLINT
717 size_t GLES2Util::GetGLTypeSizeForPathCoordType(uint32 type
) {
720 return sizeof(GLbyte
); // NOLINT
721 case GL_UNSIGNED_BYTE
:
722 return sizeof(GLubyte
); // NOLINT
724 return sizeof(GLshort
); // NOLINT
725 case GL_UNSIGNED_SHORT
:
726 return sizeof(GLushort
); // NOLINT
728 return sizeof(GLfloat
); // NOLINT
734 uint32
GLES2Util::GLErrorToErrorBit(uint32 error
) {
736 case GL_INVALID_ENUM
:
737 return gl_error_bit::kInvalidEnum
;
738 case GL_INVALID_VALUE
:
739 return gl_error_bit::kInvalidValue
;
740 case GL_INVALID_OPERATION
:
741 return gl_error_bit::kInvalidOperation
;
742 case GL_OUT_OF_MEMORY
:
743 return gl_error_bit::kOutOfMemory
;
744 case GL_INVALID_FRAMEBUFFER_OPERATION
:
745 return gl_error_bit::kInvalidFrameBufferOperation
;
746 case GL_CONTEXT_LOST_KHR
:
747 return gl_error_bit::kContextLost
;
750 return gl_error_bit::kNoError
;
754 uint32
GLES2Util::GLErrorBitToGLError(uint32 error_bit
) {
756 case gl_error_bit::kInvalidEnum
:
757 return GL_INVALID_ENUM
;
758 case gl_error_bit::kInvalidValue
:
759 return GL_INVALID_VALUE
;
760 case gl_error_bit::kInvalidOperation
:
761 return GL_INVALID_OPERATION
;
762 case gl_error_bit::kOutOfMemory
:
763 return GL_OUT_OF_MEMORY
;
764 case gl_error_bit::kInvalidFrameBufferOperation
:
765 return GL_INVALID_FRAMEBUFFER_OPERATION
;
766 case gl_error_bit::kContextLost
:
767 return GL_CONTEXT_LOST_KHR
;
774 uint32
GLES2Util::IndexToGLFaceTarget(int index
) {
775 static uint32 faces
[] = {
776 GL_TEXTURE_CUBE_MAP_POSITIVE_X
,
777 GL_TEXTURE_CUBE_MAP_NEGATIVE_X
,
778 GL_TEXTURE_CUBE_MAP_POSITIVE_Y
,
779 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
780 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
,
781 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
786 size_t GLES2Util::GLTargetToFaceIndex(uint32 target
) {
789 case GL_TEXTURE_EXTERNAL_OES
:
790 case GL_TEXTURE_RECTANGLE_ARB
:
792 case GL_TEXTURE_2D_ARRAY
:
794 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
796 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
798 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
800 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
802 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
804 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
812 uint32
GLES2Util::GetGLReadPixelsImplementationFormat(
813 uint32 internal_format
) {
814 switch (internal_format
) {
825 return GL_RED_INTEGER
;
836 return GL_RG_INTEGER
;
840 case GL_R11F_G11F_B10F
:
851 return GL_RGBA_INTEGER
;
857 uint32
GLES2Util::GetGLReadPixelsImplementationType(
858 uint32 internal_format
, uint32 texture_type
) {
859 switch (internal_format
) {
865 return GL_UNSIGNED_SHORT
;
869 return GL_UNSIGNED_INT
;
889 case GL_R11F_G11F_B10F
:
892 // TODO(zmo): Consider return GL_UNSIGNED_INT_10F_11F_11F_REV and
897 // Unsized internal format, check the type
898 switch (texture_type
) {
900 case GL_HALF_FLOAT_OES
:
902 // TODO(zmo): Consider return GL_UNSIGNED_SHORT_5_6_5,
903 // GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_5_5_5_1, and
904 // GL_UNSIGNED_INT_2_10_10_10_REV.
906 return GL_UNSIGNED_BYTE
;
909 return GL_UNSIGNED_BYTE
;
913 uint32
GLES2Util::GetChannelsForFormat(int format
) {
916 case GL_ALPHA16F_EXT
:
917 case GL_ALPHA32F_EXT
:
921 case GL_LUMINANCE_ALPHA
:
931 case GL_R11F_G11F_B10F
:
948 case GL_SRGB_ALPHA_EXT
:
949 case GL_SRGB8_ALPHA8_EXT
:
960 case GL_DEPTH_COMPONENT32_OES
:
961 case GL_DEPTH_COMPONENT24_OES
:
962 case GL_DEPTH_COMPONENT16
:
963 case GL_DEPTH_COMPONENT
:
964 case GL_DEPTH_COMPONENT32F
:
966 case GL_STENCIL_INDEX8
:
968 case GL_DEPTH_STENCIL_OES
:
969 case GL_DEPTH24_STENCIL8_OES
:
970 case GL_DEPTH32F_STENCIL8
:
971 return kDepth
| kStencil
;
995 return kRed
| kGreen
;
1001 uint32
GLES2Util::GetChannelsNeededForAttachmentType(
1002 int type
, uint32 max_color_attachments
) {
1004 case GL_DEPTH_ATTACHMENT
:
1006 case GL_STENCIL_ATTACHMENT
:
1009 if (type
>= GL_COLOR_ATTACHMENT0
&&
1010 type
< static_cast<int>(
1011 GL_COLOR_ATTACHMENT0
+ max_color_attachments
)) {
1018 std::string
GLES2Util::GetStringEnum(uint32 value
) {
1019 const EnumToString
* entry
= enum_to_string_table_
;
1020 const EnumToString
* end
= entry
+ enum_to_string_table_len_
;
1021 for (;entry
< end
; ++entry
) {
1022 if (value
== entry
->value
) {
1026 std::stringstream ss
;
1028 ss
.width(value
< 0x10000 ? 4 : 8);
1029 ss
<< std::hex
<< value
;
1030 return "0x" + ss
.str();
1033 std::string
GLES2Util::GetStringError(uint32 value
) {
1034 static EnumToString string_table
[] = {
1035 { GL_NONE
, "GL_NONE" },
1037 return GLES2Util::GetQualifiedEnumString(
1038 string_table
, arraysize(string_table
), value
);
1041 std::string
GLES2Util::GetStringBool(uint32 value
) {
1042 return value
? "GL_TRUE" : "GL_FALSE";
1045 std::string
GLES2Util::GetQualifiedEnumString(
1046 const EnumToString
* table
, size_t count
, uint32 value
) {
1047 for (const EnumToString
* end
= table
+ count
; table
< end
; ++table
) {
1048 if (table
->value
== value
) {
1052 return GetStringEnum(value
);
1055 bool GLES2Util::ParseUniformName(
1056 const std::string
& name
,
1059 bool* getting_array
) {
1062 bool getting_array_location
= false;
1063 size_t open_pos
= std::string::npos
;
1064 base::CheckedNumeric
<int> index
= 0;
1065 if (name
[name
.size() - 1] == ']') {
1066 if (name
.size() < 3) {
1069 open_pos
= name
.find_last_of('[');
1070 if (open_pos
== std::string::npos
||
1071 open_pos
>= name
.size() - 2) {
1074 size_t last
= name
.size() - 1;
1075 for (size_t pos
= open_pos
+ 1; pos
< last
; ++pos
) {
1076 int8 digit
= name
[pos
] - '0';
1077 if (digit
< 0 || digit
> 9) {
1080 index
= index
* 10 + digit
;
1082 if (!index
.IsValid()) {
1085 getting_array_location
= true;
1087 *getting_array
= getting_array_location
;
1088 *element_index
= index
.ValueOrDie();
1089 *array_pos
= open_pos
;
1093 size_t GLES2Util::CalcClearBufferivDataCount(int buffer
) {
1104 size_t GLES2Util::CalcClearBufferfvDataCount(int buffer
) {
1116 void GLES2Util::MapUint64ToTwoUint32(
1117 uint64_t v64
, uint32_t* v32_0
, uint32_t* v32_1
) {
1118 DCHECK(v32_0
&& v32_1
);
1119 *v32_0
= static_cast<uint32_t>(v64
& 0xFFFFFFFF);
1120 *v32_1
= static_cast<uint32_t>((v64
& 0xFFFFFFFF00000000) >> 32);
1124 uint64_t GLES2Util::MapTwoUint32ToUint64(uint32_t v32_0
, uint32_t v32_1
) {
1125 uint64_t v64
= v32_1
;
1126 return (v64
<< 32) | v32_0
;
1130 uint32_t GLES2Util::MapBufferTargetToBindingEnum(uint32_t target
) {
1132 case GL_ARRAY_BUFFER
:
1133 return GL_ARRAY_BUFFER_BINDING
;
1134 case GL_COPY_READ_BUFFER
:
1135 return GL_COPY_READ_BUFFER_BINDING
;
1136 case GL_COPY_WRITE_BUFFER
:
1137 return GL_COPY_WRITE_BUFFER_BINDING
;
1138 case GL_ELEMENT_ARRAY_BUFFER
:
1139 return GL_ELEMENT_ARRAY_BUFFER_BINDING
;
1140 case GL_PIXEL_PACK_BUFFER
:
1141 return GL_PIXEL_PACK_BUFFER_BINDING
;
1142 case GL_PIXEL_UNPACK_BUFFER
:
1143 return GL_PIXEL_UNPACK_BUFFER_BINDING
;
1144 case GL_TRANSFORM_FEEDBACK_BUFFER
:
1145 return GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
;
1146 case GL_UNIFORM_BUFFER
:
1147 return GL_UNIFORM_BUFFER_BINDING
;
1154 bool GLES2Util::IsUnsignedIntegerFormat(uint32_t internal_format
) {
1155 switch (internal_format
) {
1173 bool GLES2Util::IsSignedIntegerFormat(uint32_t internal_format
) {
1174 switch (internal_format
) {
1191 bool GLES2Util::IsIntegerFormat(uint32_t internal_format
) {
1192 return (IsUnsignedIntegerFormat(internal_format
) ||
1193 IsSignedIntegerFormat(internal_format
));
1199 // WebGraphicsContext3DCommandBufferImpl configuration attributes. Those in
1200 // the 16-bit range are the same as used by EGL. Those outside the 16-bit range
1201 // are unique to Chromium. Attributes are matched using a closest fit algorithm.
1203 // From <EGL/egl.h>.
1204 const int32 kAlphaSize
= 0x3021; // EGL_ALPHA_SIZE
1205 const int32 kBlueSize
= 0x3022; // EGL_BLUE_SIZE
1206 const int32 kGreenSize
= 0x3023; // EGL_GREEN_SIZE
1207 const int32 kRedSize
= 0x3024; // EGL_RED_SIZE
1208 const int32 kDepthSize
= 0x3025; // EGL_DEPTH_SIZE
1209 const int32 kStencilSize
= 0x3026; // EGL_STENCIL_SIZE
1210 const int32 kSamples
= 0x3031; // EGL_SAMPLES
1211 const int32 kSampleBuffers
= 0x3032; // EGL_SAMPLE_BUFFERS
1212 const int32 kNone
= 0x3038; // EGL_NONE
1213 const int32 kSwapBehavior
= 0x3093; // EGL_SWAP_BEHAVIOR
1214 const int32 kBufferPreserved
= 0x3094; // EGL_BUFFER_PRESERVED
1215 const int32 kBufferDestroyed
= 0x3095; // EGL_BUFFER_DESTROYED
1218 const int32 kBindGeneratesResource
= 0x10000;
1219 const int32 kFailIfMajorPerfCaveat
= 0x10001;
1220 const int32 kLoseContextWhenOutOfMemory
= 0x10002;
1221 const int32 kWebGLVersion
= 0x10003;
1225 ContextCreationAttribHelper::ContextCreationAttribHelper()
1234 buffer_preserved(true),
1235 bind_generates_resource(true),
1236 fail_if_major_perf_caveat(false),
1237 lose_context_when_out_of_memory(false),
1241 void ContextCreationAttribHelper::Serialize(std::vector
<int32
>* attribs
) const {
1242 if (alpha_size
!= -1) {
1243 attribs
->push_back(kAlphaSize
);
1244 attribs
->push_back(alpha_size
);
1246 if (blue_size
!= -1) {
1247 attribs
->push_back(kBlueSize
);
1248 attribs
->push_back(blue_size
);
1250 if (green_size
!= -1) {
1251 attribs
->push_back(kGreenSize
);
1252 attribs
->push_back(green_size
);
1254 if (red_size
!= -1) {
1255 attribs
->push_back(kRedSize
);
1256 attribs
->push_back(red_size
);
1258 if (depth_size
!= -1) {
1259 attribs
->push_back(kDepthSize
);
1260 attribs
->push_back(depth_size
);
1262 if (stencil_size
!= -1) {
1263 attribs
->push_back(kStencilSize
);
1264 attribs
->push_back(stencil_size
);
1266 if (samples
!= -1) {
1267 attribs
->push_back(kSamples
);
1268 attribs
->push_back(samples
);
1270 if (sample_buffers
!= -1) {
1271 attribs
->push_back(kSampleBuffers
);
1272 attribs
->push_back(sample_buffers
);
1274 attribs
->push_back(kSwapBehavior
);
1275 attribs
->push_back(buffer_preserved
? kBufferPreserved
: kBufferDestroyed
);
1276 attribs
->push_back(kBindGeneratesResource
);
1277 attribs
->push_back(bind_generates_resource
? 1 : 0);
1278 attribs
->push_back(kFailIfMajorPerfCaveat
);
1279 attribs
->push_back(fail_if_major_perf_caveat
? 1 : 0);
1280 attribs
->push_back(kLoseContextWhenOutOfMemory
);
1281 attribs
->push_back(lose_context_when_out_of_memory
? 1 : 0);
1282 attribs
->push_back(kWebGLVersion
);
1283 attribs
->push_back(webgl_version
);
1284 attribs
->push_back(kNone
);
1287 bool ContextCreationAttribHelper::Parse(const std::vector
<int32
>& attribs
) {
1288 for (size_t i
= 0; i
< attribs
.size(); i
+= 2) {
1289 const int32 attrib
= attribs
[i
];
1290 if (i
+ 1 >= attribs
.size()) {
1291 if (attrib
== kNone
) {
1295 DLOG(ERROR
) << "Missing value after context creation attribute: "
1300 const int32 value
= attribs
[i
+1];
1318 stencil_size
= value
;
1323 case kSampleBuffers
:
1324 sample_buffers
= value
;
1327 buffer_preserved
= value
== kBufferPreserved
;
1329 case kBindGeneratesResource
:
1330 bind_generates_resource
= value
!= 0;
1332 case kFailIfMajorPerfCaveat
:
1333 fail_if_major_perf_caveat
= value
!= 0;
1335 case kLoseContextWhenOutOfMemory
:
1336 lose_context_when_out_of_memory
= value
!= 0;
1339 webgl_version
= value
;
1342 // Terminate list, even if more attributes.
1345 DLOG(ERROR
) << "Invalid context creation attribute: " << attrib
;
1353 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h"
1355 } // namespace gles2