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
:
456 case GL_UNSIGNED_INT_2_10_10_10_REV
:
457 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
458 case GL_UNSIGNED_INT_5_9_9_9_REV
:
461 case GL_HALF_FLOAT_OES
:
462 case GL_UNSIGNED_SHORT
:
464 case GL_UNSIGNED_SHORT_5_6_5
:
465 case GL_UNSIGNED_SHORT_4_4_4_4
:
466 case GL_UNSIGNED_SHORT_5_5_5_1
:
468 case GL_UNSIGNED_BYTE
:
476 } // anonymous namespace
478 uint32
GLES2Util::ComputeImageGroupSize(int format
, int type
) {
479 int bytes_per_element
= BytesPerElement(type
);
480 DCHECK_GE(8, bytes_per_element
);
481 int elements_per_group
= ElementsPerGroup(format
, type
);
482 DCHECK_GE(4, elements_per_group
);
483 return bytes_per_element
* elements_per_group
;
486 bool GLES2Util::ComputeImagePaddedRowSize(
487 int width
, int format
, int type
, int unpack_alignment
,
488 uint32
* padded_row_size
) {
489 DCHECK(unpack_alignment
== 1 || unpack_alignment
== 2 ||
490 unpack_alignment
== 4 || unpack_alignment
== 8);
491 uint32 bytes_per_group
= ComputeImageGroupSize(format
, type
);
492 uint32 unpadded_row_size
;
493 if (!SafeMultiplyUint32(width
, bytes_per_group
, &unpadded_row_size
)) {
497 if (!SafeAddUint32(unpadded_row_size
, unpack_alignment
- 1, &temp
)) {
500 *padded_row_size
= (temp
/ unpack_alignment
) * unpack_alignment
;
504 // Returns the amount of data glTexImage*D or glTexSubImage*D will access.
505 bool GLES2Util::ComputeImageDataSizes(
506 int width
, int height
, int depth
, int format
, int type
,
507 int unpack_alignment
, uint32
* size
, uint32
* ret_unpadded_row_size
,
508 uint32
* ret_padded_row_size
) {
509 DCHECK(unpack_alignment
== 1 || unpack_alignment
== 2 ||
510 unpack_alignment
== 4 || unpack_alignment
== 8);
511 uint32 bytes_per_group
= ComputeImageGroupSize(format
, type
);
513 if (!SafeMultiplyUint32(width
, bytes_per_group
, &row_size
)) {
517 if (!SafeMultiplyUint32(height
, depth
, &num_of_rows
)) {
520 if (num_of_rows
> 1) {
522 if (!SafeAddUint32(row_size
, unpack_alignment
- 1, &temp
)) {
525 uint32 padded_row_size
= (temp
/ unpack_alignment
) * unpack_alignment
;
526 uint32 size_of_all_but_last_row
;
527 if (!SafeMultiplyUint32((num_of_rows
- 1), padded_row_size
,
528 &size_of_all_but_last_row
)) {
531 if (!SafeAddUint32(size_of_all_but_last_row
, row_size
, size
)) {
534 if (ret_padded_row_size
) {
535 *ret_padded_row_size
= padded_row_size
;
539 if (ret_padded_row_size
) {
540 *ret_padded_row_size
= row_size
;
543 if (ret_unpadded_row_size
) {
544 *ret_unpadded_row_size
= row_size
;
550 size_t GLES2Util::RenderbufferBytesPerPixel(int format
) {
552 case GL_STENCIL_INDEX8
:
557 case GL_DEPTH_COMPONENT16
:
561 case GL_DEPTH24_STENCIL8_OES
:
564 case GL_DEPTH_COMPONENT24_OES
:
571 uint32
GLES2Util::GetElementSizeForUniformType(int type
) {
580 return sizeof(GLfloat
);
590 case GL_SAMPLER_CUBE
:
591 case GL_SAMPLER_2D_RECT_ARB
: // extension.
592 case GL_SAMPLER_EXTERNAL_OES
: // extension.
593 return sizeof(GLint
);
596 case GL_UNSIGNED_INT
:
597 case GL_UNSIGNED_INT_VEC2
:
598 case GL_UNSIGNED_INT_VEC3
:
599 case GL_UNSIGNED_INT_VEC4
:
600 return sizeof(GLuint
);
602 case GL_SAMPLER_2D_SHADOW
:
603 case GL_SAMPLER_2D_ARRAY
:
604 case GL_SAMPLER_2D_ARRAY_SHADOW
:
605 case GL_SAMPLER_CUBE_SHADOW
:
606 case GL_INT_SAMPLER_2D
:
607 case GL_INT_SAMPLER_3D
:
608 case GL_INT_SAMPLER_CUBE
:
609 case GL_INT_SAMPLER_2D_ARRAY
:
610 case GL_UNSIGNED_INT_SAMPLER_2D
:
611 case GL_UNSIGNED_INT_SAMPLER_3D
:
612 case GL_UNSIGNED_INT_SAMPLER_CUBE
:
613 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY
:
614 return sizeof(GLint
);
615 case GL_FLOAT_MAT2x3
:
616 case GL_FLOAT_MAT3x2
:
617 case GL_FLOAT_MAT2x4
:
618 case GL_FLOAT_MAT4x2
:
619 case GL_FLOAT_MAT3x4
:
620 case GL_FLOAT_MAT4x3
:
621 return sizeof(GLfloat
);
628 uint32
GLES2Util::GetElementCountForUniformType(int type
) {
634 case GL_SAMPLER_CUBE
:
635 case GL_SAMPLER_2D_RECT_ARB
: // extension.
636 case GL_SAMPLER_EXTERNAL_OES
: // extension.
657 case GL_UNSIGNED_INT
:
659 case GL_SAMPLER_2D_SHADOW
:
660 case GL_SAMPLER_2D_ARRAY
:
661 case GL_SAMPLER_2D_ARRAY_SHADOW
:
662 case GL_SAMPLER_CUBE_SHADOW
:
663 case GL_INT_SAMPLER_2D
:
664 case GL_INT_SAMPLER_3D
:
665 case GL_INT_SAMPLER_CUBE
:
666 case GL_INT_SAMPLER_2D_ARRAY
:
667 case GL_UNSIGNED_INT_SAMPLER_2D
:
668 case GL_UNSIGNED_INT_SAMPLER_3D
:
669 case GL_UNSIGNED_INT_SAMPLER_CUBE
:
670 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY
:
672 case GL_UNSIGNED_INT_VEC2
:
674 case GL_UNSIGNED_INT_VEC3
:
676 case GL_UNSIGNED_INT_VEC4
:
678 case GL_FLOAT_MAT2x3
:
679 case GL_FLOAT_MAT3x2
:
681 case GL_FLOAT_MAT2x4
:
682 case GL_FLOAT_MAT4x2
:
684 case GL_FLOAT_MAT3x4
:
685 case GL_FLOAT_MAT4x3
:
693 size_t GLES2Util::GetGLTypeSizeForTexturesAndBuffers(uint32 type
) {
696 return sizeof(GLbyte
); // NOLINT
697 case GL_UNSIGNED_BYTE
:
698 return sizeof(GLubyte
); // NOLINT
700 return sizeof(GLshort
); // NOLINT
701 case GL_UNSIGNED_SHORT
:
702 return sizeof(GLushort
); // NOLINT
704 return sizeof(GLint
); // NOLINT
705 case GL_UNSIGNED_INT
:
706 return sizeof(GLuint
); // NOLINT
708 return sizeof(GLfloat
); // NOLINT
710 return sizeof(GLfixed
); // NOLINT
716 size_t GLES2Util::GetGLTypeSizeForPathCoordType(uint32 type
) {
719 return sizeof(GLbyte
); // NOLINT
720 case GL_UNSIGNED_BYTE
:
721 return sizeof(GLubyte
); // NOLINT
723 return sizeof(GLshort
); // NOLINT
724 case GL_UNSIGNED_SHORT
:
725 return sizeof(GLushort
); // NOLINT
727 return sizeof(GLfloat
); // NOLINT
733 uint32
GLES2Util::GLErrorToErrorBit(uint32 error
) {
735 case GL_INVALID_ENUM
:
736 return gl_error_bit::kInvalidEnum
;
737 case GL_INVALID_VALUE
:
738 return gl_error_bit::kInvalidValue
;
739 case GL_INVALID_OPERATION
:
740 return gl_error_bit::kInvalidOperation
;
741 case GL_OUT_OF_MEMORY
:
742 return gl_error_bit::kOutOfMemory
;
743 case GL_INVALID_FRAMEBUFFER_OPERATION
:
744 return gl_error_bit::kInvalidFrameBufferOperation
;
745 case GL_CONTEXT_LOST_KHR
:
746 return gl_error_bit::kContextLost
;
749 return gl_error_bit::kNoError
;
753 uint32
GLES2Util::GLErrorBitToGLError(uint32 error_bit
) {
755 case gl_error_bit::kInvalidEnum
:
756 return GL_INVALID_ENUM
;
757 case gl_error_bit::kInvalidValue
:
758 return GL_INVALID_VALUE
;
759 case gl_error_bit::kInvalidOperation
:
760 return GL_INVALID_OPERATION
;
761 case gl_error_bit::kOutOfMemory
:
762 return GL_OUT_OF_MEMORY
;
763 case gl_error_bit::kInvalidFrameBufferOperation
:
764 return GL_INVALID_FRAMEBUFFER_OPERATION
;
765 case gl_error_bit::kContextLost
:
766 return GL_CONTEXT_LOST_KHR
;
773 uint32
GLES2Util::IndexToGLFaceTarget(int index
) {
774 static uint32 faces
[] = {
775 GL_TEXTURE_CUBE_MAP_POSITIVE_X
,
776 GL_TEXTURE_CUBE_MAP_NEGATIVE_X
,
777 GL_TEXTURE_CUBE_MAP_POSITIVE_Y
,
778 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
779 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
,
780 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
785 size_t GLES2Util::GLTargetToFaceIndex(uint32 target
) {
788 case GL_TEXTURE_EXTERNAL_OES
:
789 case GL_TEXTURE_RECTANGLE_ARB
:
791 case GL_TEXTURE_2D_ARRAY
:
793 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
795 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
797 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
799 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
801 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
803 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
811 uint32
GLES2Util::GetPreferredGLReadPixelsFormat(uint32 internal_format
) {
812 switch (internal_format
) {
824 uint32
GLES2Util::GetPreferredGLReadPixelsType(
825 uint32 internal_format
, uint32 texture_type
) {
826 switch (internal_format
) {
832 return GL_HALF_FLOAT_OES
;
835 // Unsized internal format, check the type
836 switch (texture_type
) {
838 case GL_HALF_FLOAT_OES
:
841 return GL_UNSIGNED_BYTE
;
844 return GL_UNSIGNED_BYTE
;
848 uint32
GLES2Util::GetChannelsForFormat(int format
) {
851 case GL_ALPHA16F_EXT
:
852 case GL_ALPHA32F_EXT
:
856 case GL_LUMINANCE_ALPHA
:
866 case GL_R11F_G11F_B10F
:
883 case GL_SRGB_ALPHA_EXT
:
884 case GL_SRGB8_ALPHA8_EXT
:
895 case GL_DEPTH_COMPONENT32_OES
:
896 case GL_DEPTH_COMPONENT24_OES
:
897 case GL_DEPTH_COMPONENT16
:
898 case GL_DEPTH_COMPONENT
:
899 case GL_DEPTH_COMPONENT32F
:
901 case GL_STENCIL_INDEX8
:
903 case GL_DEPTH_STENCIL_OES
:
904 case GL_DEPTH24_STENCIL8_OES
:
905 case GL_DEPTH32F_STENCIL8
:
906 return kDepth
| kStencil
;
930 return kRed
| kGreen
;
936 uint32
GLES2Util::GetChannelsNeededForAttachmentType(
937 int type
, uint32 max_color_attachments
) {
939 case GL_DEPTH_ATTACHMENT
:
941 case GL_STENCIL_ATTACHMENT
:
944 if (type
>= GL_COLOR_ATTACHMENT0
&&
945 type
< static_cast<int>(
946 GL_COLOR_ATTACHMENT0
+ max_color_attachments
)) {
953 std::string
GLES2Util::GetStringEnum(uint32 value
) {
954 const EnumToString
* entry
= enum_to_string_table_
;
955 const EnumToString
* end
= entry
+ enum_to_string_table_len_
;
956 for (;entry
< end
; ++entry
) {
957 if (value
== entry
->value
) {
961 std::stringstream ss
;
963 ss
.width(value
< 0x10000 ? 4 : 8);
964 ss
<< std::hex
<< value
;
965 return "0x" + ss
.str();
968 std::string
GLES2Util::GetStringError(uint32 value
) {
969 static EnumToString string_table
[] = {
970 { GL_NONE
, "GL_NONE" },
972 return GLES2Util::GetQualifiedEnumString(
973 string_table
, arraysize(string_table
), value
);
976 std::string
GLES2Util::GetStringBool(uint32 value
) {
977 return value
? "GL_TRUE" : "GL_FALSE";
980 std::string
GLES2Util::GetQualifiedEnumString(
981 const EnumToString
* table
, size_t count
, uint32 value
) {
982 for (const EnumToString
* end
= table
+ count
; table
< end
; ++table
) {
983 if (table
->value
== value
) {
987 return GetStringEnum(value
);
990 bool GLES2Util::ParseUniformName(
991 const std::string
& name
,
994 bool* getting_array
) {
997 bool getting_array_location
= false;
998 size_t open_pos
= std::string::npos
;
999 base::CheckedNumeric
<int> index
= 0;
1000 if (name
[name
.size() - 1] == ']') {
1001 if (name
.size() < 3) {
1004 open_pos
= name
.find_last_of('[');
1005 if (open_pos
== std::string::npos
||
1006 open_pos
>= name
.size() - 2) {
1009 size_t last
= name
.size() - 1;
1010 for (size_t pos
= open_pos
+ 1; pos
< last
; ++pos
) {
1011 int8 digit
= name
[pos
] - '0';
1012 if (digit
< 0 || digit
> 9) {
1015 index
= index
* 10 + digit
;
1017 if (!index
.IsValid()) {
1020 getting_array_location
= true;
1022 *getting_array
= getting_array_location
;
1023 *element_index
= index
.ValueOrDie();
1024 *array_pos
= open_pos
;
1028 size_t GLES2Util::CalcClearBufferivDataCount(int buffer
) {
1039 size_t GLES2Util::CalcClearBufferfvDataCount(int buffer
) {
1051 void GLES2Util::MapUint64ToTwoUint32(
1052 uint64_t v64
, uint32_t* v32_0
, uint32_t* v32_1
) {
1053 DCHECK(v32_0
&& v32_1
);
1054 *v32_0
= static_cast<uint32_t>(v64
& 0xFFFFFFFF);
1055 *v32_1
= static_cast<uint32_t>((v64
& 0xFFFFFFFF00000000) >> 32);
1059 uint64_t GLES2Util::MapTwoUint32ToUint64(uint32_t v32_0
, uint32_t v32_1
) {
1060 uint64_t v64
= v32_1
;
1061 return (v64
<< 32) | v32_0
;
1065 uint32_t GLES2Util::MapBufferTargetToBindingEnum(uint32_t target
) {
1067 case GL_ARRAY_BUFFER
:
1068 return GL_ARRAY_BUFFER_BINDING
;
1069 case GL_COPY_READ_BUFFER
:
1070 return GL_COPY_READ_BUFFER_BINDING
;
1071 case GL_COPY_WRITE_BUFFER
:
1072 return GL_COPY_WRITE_BUFFER_BINDING
;
1073 case GL_ELEMENT_ARRAY_BUFFER
:
1074 return GL_ELEMENT_ARRAY_BUFFER_BINDING
;
1075 case GL_PIXEL_PACK_BUFFER
:
1076 return GL_PIXEL_PACK_BUFFER_BINDING
;
1077 case GL_PIXEL_UNPACK_BUFFER
:
1078 return GL_PIXEL_UNPACK_BUFFER_BINDING
;
1079 case GL_TRANSFORM_FEEDBACK_BUFFER
:
1080 return GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
;
1081 case GL_UNIFORM_BUFFER
:
1082 return GL_UNIFORM_BUFFER_BINDING
;
1091 // WebGraphicsContext3DCommandBufferImpl configuration attributes. Those in
1092 // the 16-bit range are the same as used by EGL. Those outside the 16-bit range
1093 // are unique to Chromium. Attributes are matched using a closest fit algorithm.
1095 // From <EGL/egl.h>.
1096 const int32 kAlphaSize
= 0x3021; // EGL_ALPHA_SIZE
1097 const int32 kBlueSize
= 0x3022; // EGL_BLUE_SIZE
1098 const int32 kGreenSize
= 0x3023; // EGL_GREEN_SIZE
1099 const int32 kRedSize
= 0x3024; // EGL_RED_SIZE
1100 const int32 kDepthSize
= 0x3025; // EGL_DEPTH_SIZE
1101 const int32 kStencilSize
= 0x3026; // EGL_STENCIL_SIZE
1102 const int32 kSamples
= 0x3031; // EGL_SAMPLES
1103 const int32 kSampleBuffers
= 0x3032; // EGL_SAMPLE_BUFFERS
1104 const int32 kNone
= 0x3038; // EGL_NONE
1105 const int32 kSwapBehavior
= 0x3093; // EGL_SWAP_BEHAVIOR
1106 const int32 kBufferPreserved
= 0x3094; // EGL_BUFFER_PRESERVED
1107 const int32 kBufferDestroyed
= 0x3095; // EGL_BUFFER_DESTROYED
1110 const int32 kBindGeneratesResource
= 0x10000;
1111 const int32 kFailIfMajorPerfCaveat
= 0x10001;
1112 const int32 kLoseContextWhenOutOfMemory
= 0x10002;
1113 const int32 kWebGLVersion
= 0x10003;
1117 ContextCreationAttribHelper::ContextCreationAttribHelper()
1126 buffer_preserved(true),
1127 bind_generates_resource(true),
1128 fail_if_major_perf_caveat(false),
1129 lose_context_when_out_of_memory(false),
1133 void ContextCreationAttribHelper::Serialize(std::vector
<int32
>* attribs
) const {
1134 if (alpha_size
!= -1) {
1135 attribs
->push_back(kAlphaSize
);
1136 attribs
->push_back(alpha_size
);
1138 if (blue_size
!= -1) {
1139 attribs
->push_back(kBlueSize
);
1140 attribs
->push_back(blue_size
);
1142 if (green_size
!= -1) {
1143 attribs
->push_back(kGreenSize
);
1144 attribs
->push_back(green_size
);
1146 if (red_size
!= -1) {
1147 attribs
->push_back(kRedSize
);
1148 attribs
->push_back(red_size
);
1150 if (depth_size
!= -1) {
1151 attribs
->push_back(kDepthSize
);
1152 attribs
->push_back(depth_size
);
1154 if (stencil_size
!= -1) {
1155 attribs
->push_back(kStencilSize
);
1156 attribs
->push_back(stencil_size
);
1158 if (samples
!= -1) {
1159 attribs
->push_back(kSamples
);
1160 attribs
->push_back(samples
);
1162 if (sample_buffers
!= -1) {
1163 attribs
->push_back(kSampleBuffers
);
1164 attribs
->push_back(sample_buffers
);
1166 attribs
->push_back(kSwapBehavior
);
1167 attribs
->push_back(buffer_preserved
? kBufferPreserved
: kBufferDestroyed
);
1168 attribs
->push_back(kBindGeneratesResource
);
1169 attribs
->push_back(bind_generates_resource
? 1 : 0);
1170 attribs
->push_back(kFailIfMajorPerfCaveat
);
1171 attribs
->push_back(fail_if_major_perf_caveat
? 1 : 0);
1172 attribs
->push_back(kLoseContextWhenOutOfMemory
);
1173 attribs
->push_back(lose_context_when_out_of_memory
? 1 : 0);
1174 attribs
->push_back(kWebGLVersion
);
1175 attribs
->push_back(webgl_version
);
1176 attribs
->push_back(kNone
);
1179 bool ContextCreationAttribHelper::Parse(const std::vector
<int32
>& attribs
) {
1180 for (size_t i
= 0; i
< attribs
.size(); i
+= 2) {
1181 const int32 attrib
= attribs
[i
];
1182 if (i
+ 1 >= attribs
.size()) {
1183 if (attrib
== kNone
) {
1187 DLOG(ERROR
) << "Missing value after context creation attribute: "
1192 const int32 value
= attribs
[i
+1];
1210 stencil_size
= value
;
1215 case kSampleBuffers
:
1216 sample_buffers
= value
;
1219 buffer_preserved
= value
== kBufferPreserved
;
1221 case kBindGeneratesResource
:
1222 bind_generates_resource
= value
!= 0;
1224 case kFailIfMajorPerfCaveat
:
1225 fail_if_major_perf_caveat
= value
!= 0;
1227 case kLoseContextWhenOutOfMemory
:
1228 lose_context_when_out_of_memory
= value
!= 0;
1231 webgl_version
= value
;
1234 // Terminate list, even if more attributes.
1237 DLOG(ERROR
) << "Invalid context creation attribute: " << attrib
;
1245 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h"
1247 } // namespace gles2