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_TEXTURE_IMMUTABLE_FORMAT_EXT
:
208 case GL_UNPACK_ALIGNMENT
:
212 // -- glGetBooleanv, glGetFloatv, glGetIntergerv with
213 // GL_CHROMIUM_framebuffer_multisample
214 case GL_MAX_SAMPLES_EXT
:
216 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
:
219 // -- glGetBufferParameteriv
222 case GL_BUFFER_USAGE
:
225 // -- glGetFramebufferAttachmentParameteriv
226 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
:
228 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
:
230 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL
:
232 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE
:
234 // -- glGetFramebufferAttachmentParameteriv with
235 // GL_EXT_multisampled_render_to_texture
236 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT
:
238 // -- glGetFramebufferAttachmentParameteriv with
240 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT
:
244 case GL_DELETE_STATUS
:
248 case GL_VALIDATE_STATUS
:
250 case GL_INFO_LOG_LENGTH
:
252 case GL_ATTACHED_SHADERS
:
254 case GL_ACTIVE_ATTRIBUTES
:
256 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
:
258 case GL_ACTIVE_UNIFORMS
:
260 case GL_ACTIVE_UNIFORM_MAX_LENGTH
:
264 // -- glGetRenderbufferAttachmentParameteriv
265 case GL_RENDERBUFFER_WIDTH
:
267 case GL_RENDERBUFFER_HEIGHT
:
269 case GL_RENDERBUFFER_INTERNAL_FORMAT
:
271 case GL_RENDERBUFFER_RED_SIZE
:
273 case GL_RENDERBUFFER_GREEN_SIZE
:
275 case GL_RENDERBUFFER_BLUE_SIZE
:
277 case GL_RENDERBUFFER_ALPHA_SIZE
:
279 case GL_RENDERBUFFER_DEPTH_SIZE
:
281 case GL_RENDERBUFFER_STENCIL_SIZE
:
283 // -- glGetRenderbufferAttachmentParameteriv with
284 // GL_EXT_multisampled_render_to_texture
285 case GL_RENDERBUFFER_SAMPLES_EXT
:
291 // Already defined under glGetFramebufferAttachemntParameteriv.
292 // case GL_DELETE_STATUS:
294 case GL_COMPILE_STATUS
:
296 // Already defined under glGetFramebufferAttachemntParameteriv.
297 // case GL_INFO_LOG_LENGTH:
299 case GL_SHADER_SOURCE_LENGTH
:
301 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE
:
304 // -- glGetTexParameterfv, glGetTexParameteriv
305 case GL_TEXTURE_MAG_FILTER
:
307 case GL_TEXTURE_MIN_FILTER
:
309 case GL_TEXTURE_WRAP_S
:
311 case GL_TEXTURE_WRAP_T
:
313 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
316 // -- glGetVertexAttribfv, glGetVertexAttribiv
317 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
:
319 case GL_VERTEX_ATTRIB_ARRAY_ENABLED
:
321 case GL_VERTEX_ATTRIB_ARRAY_SIZE
:
323 case GL_VERTEX_ATTRIB_ARRAY_STRIDE
:
325 case GL_VERTEX_ATTRIB_ARRAY_TYPE
:
327 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED
:
329 case GL_CURRENT_VERTEX_ATTRIB
:
337 case GL_SYNC_CONDITION
:
342 // -- glHint with GL_OES_standard_derivatives
343 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES
:
346 // Chromium internal bind_generates_resource query
347 case GL_BIND_GENERATES_RESOURCE_CHROMIUM
:
358 // Return the number of elements per group of a specified format.
359 int ElementsPerGroup(int format
, int type
) {
361 case GL_UNSIGNED_SHORT_5_6_5
:
362 case GL_UNSIGNED_SHORT_4_4_4_4
:
363 case GL_UNSIGNED_SHORT_5_5_5_1
:
364 case GL_UNSIGNED_INT_24_8_OES
:
365 case GL_UNSIGNED_INT_2_10_10_10_REV
:
366 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
367 case GL_UNSIGNED_INT_5_9_9_9_REV
:
368 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
379 case GL_LUMINANCE_ALPHA
:
384 case GL_RGBA_INTEGER
:
386 case GL_SRGB_ALPHA_EXT
:
390 case GL_DEPTH_COMPONENT
:
391 case GL_DEPTH_COMPONENT24_OES
:
392 case GL_DEPTH_COMPONENT32_OES
:
393 case GL_DEPTH_COMPONENT16
:
394 case GL_DEPTH24_STENCIL8_OES
:
395 case GL_DEPTH_STENCIL_OES
:
404 // Return the number of bytes per element, based on the element type.
405 int BytesPerElement(int type
) {
407 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
410 case GL_UNSIGNED_INT_24_8_OES
:
411 case GL_UNSIGNED_INT
:
412 case GL_UNSIGNED_INT_2_10_10_10_REV
:
413 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
414 case GL_UNSIGNED_INT_5_9_9_9_REV
:
416 case GL_HALF_FLOAT_OES
:
417 case GL_UNSIGNED_SHORT
:
419 case GL_UNSIGNED_SHORT_5_6_5
:
420 case GL_UNSIGNED_SHORT_4_4_4_4
:
421 case GL_UNSIGNED_SHORT_5_5_5_1
:
423 case GL_UNSIGNED_BYTE
:
431 } // anonymous namespace
433 uint32
GLES2Util::ComputeImageGroupSize(int format
, int type
) {
434 int bytes_per_element
= BytesPerElement(type
);
435 DCHECK_GE(8, bytes_per_element
);
436 int elements_per_group
= ElementsPerGroup(format
, type
);
437 DCHECK_GE(4, elements_per_group
);
438 return bytes_per_element
* elements_per_group
;
441 bool GLES2Util::ComputeImagePaddedRowSize(
442 int width
, int format
, int type
, int unpack_alignment
,
443 uint32
* padded_row_size
) {
444 DCHECK(unpack_alignment
== 1 || unpack_alignment
== 2 ||
445 unpack_alignment
== 4 || unpack_alignment
== 8);
446 uint32 bytes_per_group
= ComputeImageGroupSize(format
, type
);
447 uint32 unpadded_row_size
;
448 if (!SafeMultiplyUint32(width
, bytes_per_group
, &unpadded_row_size
)) {
452 if (!SafeAddUint32(unpadded_row_size
, unpack_alignment
- 1, &temp
)) {
455 *padded_row_size
= (temp
/ unpack_alignment
) * unpack_alignment
;
459 // Returns the amount of data glTexImage*D or glTexSubImage*D will access.
460 bool GLES2Util::ComputeImageDataSizes(
461 int width
, int height
, int depth
, int format
, int type
,
462 int unpack_alignment
, uint32
* size
, uint32
* ret_unpadded_row_size
,
463 uint32
* ret_padded_row_size
) {
464 DCHECK(unpack_alignment
== 1 || unpack_alignment
== 2 ||
465 unpack_alignment
== 4 || unpack_alignment
== 8);
466 uint32 bytes_per_group
= ComputeImageGroupSize(format
, type
);
468 if (!SafeMultiplyUint32(width
, bytes_per_group
, &row_size
)) {
472 if (!SafeMultiplyUint32(height
, depth
, &num_of_rows
)) {
475 if (num_of_rows
> 1) {
477 if (!SafeAddUint32(row_size
, unpack_alignment
- 1, &temp
)) {
480 uint32 padded_row_size
= (temp
/ unpack_alignment
) * unpack_alignment
;
481 uint32 size_of_all_but_last_row
;
482 if (!SafeMultiplyUint32((num_of_rows
- 1), padded_row_size
,
483 &size_of_all_but_last_row
)) {
486 if (!SafeAddUint32(size_of_all_but_last_row
, row_size
, size
)) {
489 if (ret_padded_row_size
) {
490 *ret_padded_row_size
= padded_row_size
;
494 if (ret_padded_row_size
) {
495 *ret_padded_row_size
= row_size
;
498 if (ret_unpadded_row_size
) {
499 *ret_unpadded_row_size
= row_size
;
505 size_t GLES2Util::RenderbufferBytesPerPixel(int format
) {
507 case GL_STENCIL_INDEX8
:
512 case GL_DEPTH_COMPONENT16
:
516 case GL_DEPTH24_STENCIL8_OES
:
519 case GL_DEPTH_COMPONENT24_OES
:
526 uint32
GLES2Util::GetGLDataTypeSizeForUniforms(int type
) {
529 return sizeof(GLfloat
); // NOLINT
531 return sizeof(GLfloat
) * 2; // NOLINT
533 return sizeof(GLfloat
) * 3; // NOLINT
535 return sizeof(GLfloat
) * 4; // NOLINT
537 return sizeof(GLint
); // NOLINT
539 return sizeof(GLint
) * 2; // NOLINT
541 return sizeof(GLint
) * 3; // NOLINT
543 return sizeof(GLint
) * 4; // NOLINT
545 return sizeof(GLint
); // NOLINT
547 return sizeof(GLint
) * 2; // NOLINT
549 return sizeof(GLint
) * 3; // NOLINT
551 return sizeof(GLint
) * 4; // NOLINT
553 return sizeof(GLfloat
) * 2 * 2; // NOLINT
555 return sizeof(GLfloat
) * 3 * 3; // NOLINT
557 return sizeof(GLfloat
) * 4 * 4; // NOLINT
559 return sizeof(GLint
); // NOLINT
560 case GL_SAMPLER_2D_RECT_ARB
:
561 return sizeof(GLint
); // NOLINT
562 case GL_SAMPLER_CUBE
:
563 return sizeof(GLint
); // NOLINT
564 case GL_SAMPLER_EXTERNAL_OES
:
565 return sizeof(GLint
); // NOLINT
571 size_t GLES2Util::GetGLTypeSizeForTexturesAndBuffers(uint32 type
) {
574 return sizeof(GLbyte
); // NOLINT
575 case GL_UNSIGNED_BYTE
:
576 return sizeof(GLubyte
); // NOLINT
578 return sizeof(GLshort
); // NOLINT
579 case GL_UNSIGNED_SHORT
:
580 return sizeof(GLushort
); // NOLINT
582 return sizeof(GLint
); // NOLINT
583 case GL_UNSIGNED_INT
:
584 return sizeof(GLuint
); // NOLINT
586 return sizeof(GLfloat
); // NOLINT
588 return sizeof(GLfixed
); // NOLINT
594 uint32
GLES2Util::GLErrorToErrorBit(uint32 error
) {
596 case GL_INVALID_ENUM
:
597 return gl_error_bit::kInvalidEnum
;
598 case GL_INVALID_VALUE
:
599 return gl_error_bit::kInvalidValue
;
600 case GL_INVALID_OPERATION
:
601 return gl_error_bit::kInvalidOperation
;
602 case GL_OUT_OF_MEMORY
:
603 return gl_error_bit::kOutOfMemory
;
604 case GL_INVALID_FRAMEBUFFER_OPERATION
:
605 return gl_error_bit::kInvalidFrameBufferOperation
;
606 case GL_CONTEXT_LOST_KHR
:
607 return gl_error_bit::kContextLost
;
610 return gl_error_bit::kNoError
;
614 uint32
GLES2Util::GLErrorBitToGLError(uint32 error_bit
) {
616 case gl_error_bit::kInvalidEnum
:
617 return GL_INVALID_ENUM
;
618 case gl_error_bit::kInvalidValue
:
619 return GL_INVALID_VALUE
;
620 case gl_error_bit::kInvalidOperation
:
621 return GL_INVALID_OPERATION
;
622 case gl_error_bit::kOutOfMemory
:
623 return GL_OUT_OF_MEMORY
;
624 case gl_error_bit::kInvalidFrameBufferOperation
:
625 return GL_INVALID_FRAMEBUFFER_OPERATION
;
626 case gl_error_bit::kContextLost
:
627 return GL_CONTEXT_LOST_KHR
;
634 uint32
GLES2Util::IndexToGLFaceTarget(int index
) {
635 static uint32 faces
[] = {
636 GL_TEXTURE_CUBE_MAP_POSITIVE_X
,
637 GL_TEXTURE_CUBE_MAP_NEGATIVE_X
,
638 GL_TEXTURE_CUBE_MAP_POSITIVE_Y
,
639 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
640 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
,
641 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
646 size_t GLES2Util::GLTargetToFaceIndex(uint32 target
) {
649 case GL_TEXTURE_EXTERNAL_OES
:
650 case GL_TEXTURE_RECTANGLE_ARB
:
652 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
654 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
656 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
658 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
660 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
662 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
670 uint32
GLES2Util::GetPreferredGLReadPixelsFormat(uint32 internal_format
) {
671 switch (internal_format
) {
683 uint32
GLES2Util::GetPreferredGLReadPixelsType(
684 uint32 internal_format
, uint32 texture_type
) {
685 switch (internal_format
) {
691 return GL_HALF_FLOAT_OES
;
694 // Unsized internal format, check the type
695 switch (texture_type
) {
697 case GL_HALF_FLOAT_OES
:
700 return GL_UNSIGNED_BYTE
;
703 return GL_UNSIGNED_BYTE
;
707 uint32
GLES2Util::GetChannelsForFormat(int format
) {
710 case GL_ALPHA16F_EXT
:
711 case GL_ALPHA32F_EXT
:
715 case GL_LUMINANCE_ALPHA
:
725 case GL_R11F_G11F_B10F
:
742 case GL_SRGB_ALPHA_EXT
:
743 case GL_SRGB8_ALPHA8_EXT
:
754 case GL_DEPTH_COMPONENT32_OES
:
755 case GL_DEPTH_COMPONENT24_OES
:
756 case GL_DEPTH_COMPONENT16
:
757 case GL_DEPTH_COMPONENT
:
758 case GL_DEPTH_COMPONENT32F
:
760 case GL_STENCIL_INDEX8
:
762 case GL_DEPTH_STENCIL_OES
:
763 case GL_DEPTH24_STENCIL8_OES
:
764 case GL_DEPTH32F_STENCIL8
:
765 return kDepth
| kStencil
;
789 return kRed
| kGreen
;
795 uint32
GLES2Util::GetChannelsNeededForAttachmentType(
796 int type
, uint32 max_color_attachments
) {
798 case GL_DEPTH_ATTACHMENT
:
800 case GL_STENCIL_ATTACHMENT
:
803 if (type
>= GL_COLOR_ATTACHMENT0
&&
804 type
< static_cast<int>(
805 GL_COLOR_ATTACHMENT0
+ max_color_attachments
)) {
812 std::string
GLES2Util::GetStringEnum(uint32 value
) {
813 const EnumToString
* entry
= enum_to_string_table_
;
814 const EnumToString
* end
= entry
+ enum_to_string_table_len_
;
815 for (;entry
< end
; ++entry
) {
816 if (value
== entry
->value
) {
820 std::stringstream ss
;
822 ss
.width(value
< 0x10000 ? 4 : 8);
823 ss
<< std::hex
<< value
;
824 return "0x" + ss
.str();
827 std::string
GLES2Util::GetStringError(uint32 value
) {
828 static EnumToString string_table
[] = {
829 { GL_NONE
, "GL_NONE" },
831 return GLES2Util::GetQualifiedEnumString(
832 string_table
, arraysize(string_table
), value
);
835 std::string
GLES2Util::GetStringBool(uint32 value
) {
836 return value
? "GL_TRUE" : "GL_FALSE";
839 std::string
GLES2Util::GetQualifiedEnumString(
840 const EnumToString
* table
, size_t count
, uint32 value
) {
841 for (const EnumToString
* end
= table
+ count
; table
< end
; ++table
) {
842 if (table
->value
== value
) {
846 return GetStringEnum(value
);
849 bool GLES2Util::ParseUniformName(
850 const std::string
& name
,
853 bool* getting_array
) {
856 bool getting_array_location
= false;
857 size_t open_pos
= std::string::npos
;
858 base::CheckedNumeric
<int> index
= 0;
859 if (name
[name
.size() - 1] == ']') {
860 if (name
.size() < 3) {
863 open_pos
= name
.find_last_of('[');
864 if (open_pos
== std::string::npos
||
865 open_pos
>= name
.size() - 2) {
868 size_t last
= name
.size() - 1;
869 for (size_t pos
= open_pos
+ 1; pos
< last
; ++pos
) {
870 int8 digit
= name
[pos
] - '0';
871 if (digit
< 0 || digit
> 9) {
874 index
= index
* 10 + digit
;
876 if (!index
.IsValid()) {
879 getting_array_location
= true;
881 *getting_array
= getting_array_location
;
882 *element_index
= index
.ValueOrDie();
883 *array_pos
= open_pos
;
887 size_t GLES2Util::CalcClearBufferivDataCount(int buffer
) {
898 size_t GLES2Util::CalcClearBufferfvDataCount(int buffer
) {
910 void GLES2Util::MapUint64ToTwoUint32(
911 uint64_t v64
, uint32_t* v32_0
, uint32_t* v32_1
) {
912 DCHECK(v32_0
&& v32_1
);
913 *v32_0
= static_cast<uint32_t>(v64
& 0xFFFFFFFF);
914 *v32_1
= static_cast<uint32_t>((v64
& 0xFFFFFFFF00000000) >> 32);
918 uint64_t GLES2Util::MapTwoUint32ToUint64(uint32_t v32_0
, uint32_t v32_1
) {
919 uint64_t v64
= v32_1
;
920 return (v64
<< 32) | v32_0
;
924 uint32_t GLES2Util::MapBufferTargetToBindingEnum(uint32_t target
) {
926 case GL_ARRAY_BUFFER
:
927 return GL_ARRAY_BUFFER_BINDING
;
928 case GL_COPY_READ_BUFFER
:
929 return GL_COPY_READ_BUFFER_BINDING
;
930 case GL_COPY_WRITE_BUFFER
:
931 return GL_COPY_WRITE_BUFFER_BINDING
;
932 case GL_ELEMENT_ARRAY_BUFFER
:
933 return GL_ELEMENT_ARRAY_BUFFER_BINDING
;
934 case GL_PIXEL_PACK_BUFFER
:
935 return GL_PIXEL_PACK_BUFFER_BINDING
;
936 case GL_PIXEL_UNPACK_BUFFER
:
937 return GL_PIXEL_UNPACK_BUFFER_BINDING
;
938 case GL_TRANSFORM_FEEDBACK_BUFFER
:
939 return GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
;
940 case GL_UNIFORM_BUFFER
:
941 return GL_UNIFORM_BUFFER_BINDING
;
950 // WebGraphicsContext3DCommandBufferImpl configuration attributes. Those in
951 // the 16-bit range are the same as used by EGL. Those outside the 16-bit range
952 // are unique to Chromium. Attributes are matched using a closest fit algorithm.
955 const int32 kAlphaSize
= 0x3021; // EGL_ALPHA_SIZE
956 const int32 kBlueSize
= 0x3022; // EGL_BLUE_SIZE
957 const int32 kGreenSize
= 0x3023; // EGL_GREEN_SIZE
958 const int32 kRedSize
= 0x3024; // EGL_RED_SIZE
959 const int32 kDepthSize
= 0x3025; // EGL_DEPTH_SIZE
960 const int32 kStencilSize
= 0x3026; // EGL_STENCIL_SIZE
961 const int32 kSamples
= 0x3031; // EGL_SAMPLES
962 const int32 kSampleBuffers
= 0x3032; // EGL_SAMPLE_BUFFERS
963 const int32 kNone
= 0x3038; // EGL_NONE
964 const int32 kSwapBehavior
= 0x3093; // EGL_SWAP_BEHAVIOR
965 const int32 kBufferPreserved
= 0x3094; // EGL_BUFFER_PRESERVED
966 const int32 kBufferDestroyed
= 0x3095; // EGL_BUFFER_DESTROYED
969 const int32 kBindGeneratesResource
= 0x10000;
970 const int32 kFailIfMajorPerfCaveat
= 0x10001;
971 const int32 kLoseContextWhenOutOfMemory
= 0x10002;
972 const int32 kES3ContextRequired
= 0x10003;
976 ContextCreationAttribHelper::ContextCreationAttribHelper()
985 buffer_preserved(true),
986 bind_generates_resource(true),
987 fail_if_major_perf_caveat(false),
988 lose_context_when_out_of_memory(false),
989 es3_context_required(false) {}
991 void ContextCreationAttribHelper::Serialize(std::vector
<int32
>* attribs
) const {
992 if (alpha_size
!= -1) {
993 attribs
->push_back(kAlphaSize
);
994 attribs
->push_back(alpha_size
);
996 if (blue_size
!= -1) {
997 attribs
->push_back(kBlueSize
);
998 attribs
->push_back(blue_size
);
1000 if (green_size
!= -1) {
1001 attribs
->push_back(kGreenSize
);
1002 attribs
->push_back(green_size
);
1004 if (red_size
!= -1) {
1005 attribs
->push_back(kRedSize
);
1006 attribs
->push_back(red_size
);
1008 if (depth_size
!= -1) {
1009 attribs
->push_back(kDepthSize
);
1010 attribs
->push_back(depth_size
);
1012 if (stencil_size
!= -1) {
1013 attribs
->push_back(kStencilSize
);
1014 attribs
->push_back(stencil_size
);
1016 if (samples
!= -1) {
1017 attribs
->push_back(kSamples
);
1018 attribs
->push_back(samples
);
1020 if (sample_buffers
!= -1) {
1021 attribs
->push_back(kSampleBuffers
);
1022 attribs
->push_back(sample_buffers
);
1024 attribs
->push_back(kSwapBehavior
);
1025 attribs
->push_back(buffer_preserved
? kBufferPreserved
: kBufferDestroyed
);
1026 attribs
->push_back(kBindGeneratesResource
);
1027 attribs
->push_back(bind_generates_resource
? 1 : 0);
1028 attribs
->push_back(kFailIfMajorPerfCaveat
);
1029 attribs
->push_back(fail_if_major_perf_caveat
? 1 : 0);
1030 attribs
->push_back(kLoseContextWhenOutOfMemory
);
1031 attribs
->push_back(lose_context_when_out_of_memory
? 1 : 0);
1032 attribs
->push_back(kES3ContextRequired
);
1033 attribs
->push_back(es3_context_required
? 1 : 0);
1034 attribs
->push_back(kNone
);
1037 bool ContextCreationAttribHelper::Parse(const std::vector
<int32
>& attribs
) {
1038 for (size_t i
= 0; i
< attribs
.size(); i
+= 2) {
1039 const int32 attrib
= attribs
[i
];
1040 if (i
+ 1 >= attribs
.size()) {
1041 if (attrib
== kNone
) {
1045 DLOG(ERROR
) << "Missing value after context creation attribute: "
1050 const int32 value
= attribs
[i
+1];
1068 stencil_size
= value
;
1073 case kSampleBuffers
:
1074 sample_buffers
= value
;
1077 buffer_preserved
= value
== kBufferPreserved
;
1079 case kBindGeneratesResource
:
1080 bind_generates_resource
= value
!= 0;
1082 case kFailIfMajorPerfCaveat
:
1083 fail_if_major_perf_caveat
= value
!= 0;
1085 case kLoseContextWhenOutOfMemory
:
1086 lose_context_when_out_of_memory
= value
!= 0;
1088 case kES3ContextRequired
:
1089 es3_context_required
= value
!= 0;
1092 // Terminate list, even if more attributes.
1095 DLOG(ERROR
) << "Invalid context creation attribute: " << attrib
;
1103 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h"
1105 } // namespace gles2