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
:
332 // -- glHint with GL_OES_standard_derivatives
333 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES
:
336 // Chromium internal bind_generates_resource query
337 case GL_BIND_GENERATES_RESOURCE_CHROMIUM
:
348 // Return the number of elements per group of a specified format.
349 int ElementsPerGroup(int format
, int type
) {
351 case GL_UNSIGNED_SHORT_5_6_5
:
352 case GL_UNSIGNED_SHORT_4_4_4_4
:
353 case GL_UNSIGNED_SHORT_5_5_5_1
:
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
:
369 case GL_LUMINANCE_ALPHA
:
374 case GL_RGBA_INTEGER
:
376 case GL_SRGB_ALPHA_EXT
:
380 case GL_DEPTH_COMPONENT
:
381 case GL_DEPTH_COMPONENT24_OES
:
382 case GL_DEPTH_COMPONENT32_OES
:
383 case GL_DEPTH_COMPONENT16
:
384 case GL_DEPTH24_STENCIL8_OES
:
385 case GL_DEPTH_STENCIL_OES
:
394 // Return the number of bytes per element, based on the element type.
395 int BytesPerElement(int type
) {
398 case GL_UNSIGNED_INT_24_8_OES
:
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
:
405 case GL_HALF_FLOAT_OES
:
406 case GL_UNSIGNED_SHORT
:
408 case GL_UNSIGNED_SHORT_5_6_5
:
409 case GL_UNSIGNED_SHORT_4_4_4_4
:
410 case GL_UNSIGNED_SHORT_5_5_5_1
:
412 case GL_UNSIGNED_BYTE
:
420 } // anonymous namespace
422 uint32
GLES2Util::ComputeImageGroupSize(int format
, int type
) {
423 return BytesPerElement(type
) * ElementsPerGroup(format
, type
);
426 bool GLES2Util::ComputeImagePaddedRowSize(
427 int width
, int format
, int type
, int unpack_alignment
,
428 uint32
* padded_row_size
) {
429 uint32 bytes_per_group
= ComputeImageGroupSize(format
, type
);
430 uint32 unpadded_row_size
;
431 if (!SafeMultiplyUint32(width
, bytes_per_group
, &unpadded_row_size
)) {
435 if (!SafeAddUint32(unpadded_row_size
, unpack_alignment
- 1, &temp
)) {
438 *padded_row_size
= (temp
/ unpack_alignment
) * unpack_alignment
;
442 // Returns the amount of data glTexImage*D or glTexSubImage*D will access.
443 bool GLES2Util::ComputeImageDataSizes(
444 int width
, int height
, int depth
, int format
, int type
,
445 int unpack_alignment
, uint32
* size
, uint32
* ret_unpadded_row_size
,
446 uint32
* ret_padded_row_size
) {
447 uint32 bytes_per_group
= ComputeImageGroupSize(format
, type
);
449 if (!SafeMultiplyUint32(width
, bytes_per_group
, &row_size
)) {
453 if (!SafeMultiplyUint32(height
, depth
, &num_of_rows
)) {
456 if (num_of_rows
> 1) {
458 if (!SafeAddUint32(row_size
, unpack_alignment
- 1, &temp
)) {
461 uint32 padded_row_size
= (temp
/ unpack_alignment
) * unpack_alignment
;
462 uint32 size_of_all_but_last_row
;
463 if (!SafeMultiplyUint32((num_of_rows
- 1), padded_row_size
,
464 &size_of_all_but_last_row
)) {
467 if (!SafeAddUint32(size_of_all_but_last_row
, row_size
, size
)) {
470 if (ret_padded_row_size
) {
471 *ret_padded_row_size
= padded_row_size
;
475 if (ret_padded_row_size
) {
476 *ret_padded_row_size
= row_size
;
479 if (ret_unpadded_row_size
) {
480 *ret_unpadded_row_size
= row_size
;
486 size_t GLES2Util::RenderbufferBytesPerPixel(int format
) {
488 case GL_STENCIL_INDEX8
:
493 case GL_DEPTH_COMPONENT16
:
497 case GL_DEPTH24_STENCIL8_OES
:
500 case GL_DEPTH_COMPONENT24_OES
:
507 uint32
GLES2Util::GetGLDataTypeSizeForUniforms(int type
) {
510 return sizeof(GLfloat
); // NOLINT
512 return sizeof(GLfloat
) * 2; // NOLINT
514 return sizeof(GLfloat
) * 3; // NOLINT
516 return sizeof(GLfloat
) * 4; // NOLINT
518 return sizeof(GLint
); // NOLINT
520 return sizeof(GLint
) * 2; // NOLINT
522 return sizeof(GLint
) * 3; // NOLINT
524 return sizeof(GLint
) * 4; // NOLINT
526 return sizeof(GLint
); // NOLINT
528 return sizeof(GLint
) * 2; // NOLINT
530 return sizeof(GLint
) * 3; // NOLINT
532 return sizeof(GLint
) * 4; // NOLINT
534 return sizeof(GLfloat
) * 2 * 2; // NOLINT
536 return sizeof(GLfloat
) * 3 * 3; // NOLINT
538 return sizeof(GLfloat
) * 4 * 4; // NOLINT
540 return sizeof(GLint
); // NOLINT
541 case GL_SAMPLER_2D_RECT_ARB
:
542 return sizeof(GLint
); // NOLINT
543 case GL_SAMPLER_CUBE
:
544 return sizeof(GLint
); // NOLINT
545 case GL_SAMPLER_EXTERNAL_OES
:
546 return sizeof(GLint
); // NOLINT
552 size_t GLES2Util::GetGLTypeSizeForTexturesAndBuffers(uint32 type
) {
555 return sizeof(GLbyte
); // NOLINT
556 case GL_UNSIGNED_BYTE
:
557 return sizeof(GLubyte
); // NOLINT
559 return sizeof(GLshort
); // NOLINT
560 case GL_UNSIGNED_SHORT
:
561 return sizeof(GLushort
); // NOLINT
563 return sizeof(GLint
); // NOLINT
564 case GL_UNSIGNED_INT
:
565 return sizeof(GLuint
); // NOLINT
567 return sizeof(GLfloat
); // NOLINT
569 return sizeof(GLfixed
); // NOLINT
575 uint32
GLES2Util::GLErrorToErrorBit(uint32 error
) {
577 case GL_INVALID_ENUM
:
578 return gl_error_bit::kInvalidEnum
;
579 case GL_INVALID_VALUE
:
580 return gl_error_bit::kInvalidValue
;
581 case GL_INVALID_OPERATION
:
582 return gl_error_bit::kInvalidOperation
;
583 case GL_OUT_OF_MEMORY
:
584 return gl_error_bit::kOutOfMemory
;
585 case GL_INVALID_FRAMEBUFFER_OPERATION
:
586 return gl_error_bit::kInvalidFrameBufferOperation
;
587 case GL_CONTEXT_LOST_KHR
:
588 return gl_error_bit::kContextLost
;
591 return gl_error_bit::kNoError
;
595 uint32
GLES2Util::GLErrorBitToGLError(uint32 error_bit
) {
597 case gl_error_bit::kInvalidEnum
:
598 return GL_INVALID_ENUM
;
599 case gl_error_bit::kInvalidValue
:
600 return GL_INVALID_VALUE
;
601 case gl_error_bit::kInvalidOperation
:
602 return GL_INVALID_OPERATION
;
603 case gl_error_bit::kOutOfMemory
:
604 return GL_OUT_OF_MEMORY
;
605 case gl_error_bit::kInvalidFrameBufferOperation
:
606 return GL_INVALID_FRAMEBUFFER_OPERATION
;
607 case gl_error_bit::kContextLost
:
608 return GL_CONTEXT_LOST_KHR
;
615 uint32
GLES2Util::IndexToGLFaceTarget(int index
) {
616 static uint32 faces
[] = {
617 GL_TEXTURE_CUBE_MAP_POSITIVE_X
,
618 GL_TEXTURE_CUBE_MAP_NEGATIVE_X
,
619 GL_TEXTURE_CUBE_MAP_POSITIVE_Y
,
620 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
621 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
,
622 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
627 size_t GLES2Util::GLTargetToFaceIndex(uint32 target
) {
630 case GL_TEXTURE_EXTERNAL_OES
:
631 case GL_TEXTURE_RECTANGLE_ARB
:
633 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
635 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
637 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
639 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
641 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
643 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
651 uint32
GLES2Util::GetPreferredGLReadPixelsFormat(uint32 internal_format
) {
652 switch (internal_format
) {
664 uint32
GLES2Util::GetPreferredGLReadPixelsType(
665 uint32 internal_format
, uint32 texture_type
) {
666 switch (internal_format
) {
672 return GL_HALF_FLOAT_OES
;
675 // Unsized internal format, check the type
676 switch (texture_type
) {
678 case GL_HALF_FLOAT_OES
:
681 return GL_UNSIGNED_BYTE
;
684 return GL_UNSIGNED_BYTE
;
688 uint32
GLES2Util::GetChannelsForFormat(int format
) {
691 case GL_ALPHA16F_EXT
:
692 case GL_ALPHA32F_EXT
:
696 case GL_LUMINANCE_ALPHA
:
713 case GL_SRGB_ALPHA_EXT
:
714 case GL_SRGB8_ALPHA8_EXT
:
716 case GL_DEPTH_COMPONENT32_OES
:
717 case GL_DEPTH_COMPONENT24_OES
:
718 case GL_DEPTH_COMPONENT16
:
719 case GL_DEPTH_COMPONENT
:
721 case GL_STENCIL_INDEX8
:
723 case GL_DEPTH_STENCIL_OES
:
724 case GL_DEPTH24_STENCIL8_OES
:
725 return kDepth
| kStencil
;
729 return kRed
| kGreen
;
735 uint32
GLES2Util::GetChannelsNeededForAttachmentType(
736 int type
, uint32 max_color_attachments
) {
738 case GL_DEPTH_ATTACHMENT
:
740 case GL_STENCIL_ATTACHMENT
:
743 if (type
>= GL_COLOR_ATTACHMENT0
&&
744 type
< static_cast<int>(
745 GL_COLOR_ATTACHMENT0
+ max_color_attachments
)) {
752 std::string
GLES2Util::GetStringEnum(uint32 value
) {
753 const EnumToString
* entry
= enum_to_string_table_
;
754 const EnumToString
* end
= entry
+ enum_to_string_table_len_
;
755 for (;entry
< end
; ++entry
) {
756 if (value
== entry
->value
) {
760 std::stringstream ss
;
762 ss
.width(value
< 0x10000 ? 4 : 8);
763 ss
<< std::hex
<< value
;
764 return "0x" + ss
.str();
767 std::string
GLES2Util::GetStringError(uint32 value
) {
768 static EnumToString string_table
[] = {
769 { GL_NONE
, "GL_NONE" },
771 return GLES2Util::GetQualifiedEnumString(
772 string_table
, arraysize(string_table
), value
);
775 std::string
GLES2Util::GetStringBool(uint32 value
) {
776 return value
? "GL_TRUE" : "GL_FALSE";
779 std::string
GLES2Util::GetQualifiedEnumString(
780 const EnumToString
* table
, size_t count
, uint32 value
) {
781 for (const EnumToString
* end
= table
+ count
; table
< end
; ++table
) {
782 if (table
->value
== value
) {
786 return GetStringEnum(value
);
789 bool GLES2Util::ParseUniformName(
790 const std::string
& name
,
793 bool* getting_array
) {
796 bool getting_array_location
= false;
797 size_t open_pos
= std::string::npos
;
798 base::CheckedNumeric
<int> index
= 0;
799 if (name
[name
.size() - 1] == ']') {
800 if (name
.size() < 3) {
803 open_pos
= name
.find_last_of('[');
804 if (open_pos
== std::string::npos
||
805 open_pos
>= name
.size() - 2) {
808 size_t last
= name
.size() - 1;
809 for (size_t pos
= open_pos
+ 1; pos
< last
; ++pos
) {
810 int8 digit
= name
[pos
] - '0';
811 if (digit
< 0 || digit
> 9) {
814 index
= index
* 10 + digit
;
816 if (!index
.IsValid()) {
819 getting_array_location
= true;
821 *getting_array
= getting_array_location
;
822 *element_index
= index
.ValueOrDie();
823 *array_pos
= open_pos
;
827 size_t GLES2Util::CalcClearBufferivDataCount(int buffer
) {
838 size_t GLES2Util::CalcClearBufferfvDataCount(int buffer
) {
850 void GLES2Util::MapUint64ToTwoUint32(
851 uint64_t v64
, uint32_t* v32_0
, uint32_t* v32_1
) {
852 DCHECK(v32_0
&& v32_1
);
853 *v32_0
= static_cast<uint32_t>(v64
& 0xFFFFFFFF);
854 *v32_1
= static_cast<uint32_t>((v64
& 0xFFFFFFFF00000000) >> 32);
858 uint64_t GLES2Util::MapTwoUint32ToUint64(uint32_t v32_0
, uint32_t v32_1
) {
859 uint64_t v64
= v32_1
;
860 return (v64
<< 32) | v32_0
;
865 // WebGraphicsContext3DCommandBufferImpl configuration attributes. Those in
866 // the 16-bit range are the same as used by EGL. Those outside the 16-bit range
867 // are unique to Chromium. Attributes are matched using a closest fit algorithm.
870 const int32 kAlphaSize
= 0x3021; // EGL_ALPHA_SIZE
871 const int32 kBlueSize
= 0x3022; // EGL_BLUE_SIZE
872 const int32 kGreenSize
= 0x3023; // EGL_GREEN_SIZE
873 const int32 kRedSize
= 0x3024; // EGL_RED_SIZE
874 const int32 kDepthSize
= 0x3025; // EGL_DEPTH_SIZE
875 const int32 kStencilSize
= 0x3026; // EGL_STENCIL_SIZE
876 const int32 kSamples
= 0x3031; // EGL_SAMPLES
877 const int32 kSampleBuffers
= 0x3032; // EGL_SAMPLE_BUFFERS
878 const int32 kNone
= 0x3038; // EGL_NONE
879 const int32 kSwapBehavior
= 0x3093; // EGL_SWAP_BEHAVIOR
880 const int32 kBufferPreserved
= 0x3094; // EGL_BUFFER_PRESERVED
881 const int32 kBufferDestroyed
= 0x3095; // EGL_BUFFER_DESTROYED
884 const int32 kBindGeneratesResource
= 0x10000;
885 const int32 kFailIfMajorPerfCaveat
= 0x10001;
886 const int32 kLoseContextWhenOutOfMemory
= 0x10002;
890 ContextCreationAttribHelper::ContextCreationAttribHelper()
899 buffer_preserved(true),
900 bind_generates_resource(true),
901 fail_if_major_perf_caveat(false),
902 lose_context_when_out_of_memory(false) {}
904 void ContextCreationAttribHelper::Serialize(std::vector
<int32
>* attribs
) const {
905 if (alpha_size
!= -1) {
906 attribs
->push_back(kAlphaSize
);
907 attribs
->push_back(alpha_size
);
909 if (blue_size
!= -1) {
910 attribs
->push_back(kBlueSize
);
911 attribs
->push_back(blue_size
);
913 if (green_size
!= -1) {
914 attribs
->push_back(kGreenSize
);
915 attribs
->push_back(green_size
);
917 if (red_size
!= -1) {
918 attribs
->push_back(kRedSize
);
919 attribs
->push_back(red_size
);
921 if (depth_size
!= -1) {
922 attribs
->push_back(kDepthSize
);
923 attribs
->push_back(depth_size
);
925 if (stencil_size
!= -1) {
926 attribs
->push_back(kStencilSize
);
927 attribs
->push_back(stencil_size
);
930 attribs
->push_back(kSamples
);
931 attribs
->push_back(samples
);
933 if (sample_buffers
!= -1) {
934 attribs
->push_back(kSampleBuffers
);
935 attribs
->push_back(sample_buffers
);
937 attribs
->push_back(kSwapBehavior
);
938 attribs
->push_back(buffer_preserved
? kBufferPreserved
: kBufferDestroyed
);
939 attribs
->push_back(kBindGeneratesResource
);
940 attribs
->push_back(bind_generates_resource
? 1 : 0);
941 attribs
->push_back(kFailIfMajorPerfCaveat
);
942 attribs
->push_back(fail_if_major_perf_caveat
? 1 : 0);
943 attribs
->push_back(kLoseContextWhenOutOfMemory
);
944 attribs
->push_back(lose_context_when_out_of_memory
? 1 : 0);
945 attribs
->push_back(kNone
);
948 bool ContextCreationAttribHelper::Parse(const std::vector
<int32
>& attribs
) {
949 for (size_t i
= 0; i
< attribs
.size(); i
+= 2) {
950 const int32 attrib
= attribs
[i
];
951 if (i
+ 1 >= attribs
.size()) {
952 if (attrib
== kNone
) {
956 DLOG(ERROR
) << "Missing value after context creation attribute: "
961 const int32 value
= attribs
[i
+1];
979 stencil_size
= value
;
985 sample_buffers
= value
;
988 buffer_preserved
= value
== kBufferPreserved
;
990 case kBindGeneratesResource
:
991 bind_generates_resource
= value
!= 0;
993 case kFailIfMajorPerfCaveat
:
994 fail_if_major_perf_caveat
= value
!= 0;
996 case kLoseContextWhenOutOfMemory
:
997 lose_context_when_out_of_memory
= value
!= 0;
1000 // Terminate list, even if more attributes.
1003 DLOG(ERROR
) << "Invalid context creation attribute: " << attrib
;
1011 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h"
1013 } // namespace gles2