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>
13 #include "gpu/command_buffer/common/gles2_cmd_format.h"
14 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
19 namespace gl_error_bit
{
22 kInvalidEnum
= (1 << 0),
23 kInvalidValue
= (1 << 1),
24 kInvalidOperation
= (1 << 2),
25 kOutOfMemory
= (1 << 3),
26 kInvalidFrameBufferOperation
= (1 << 4),
27 kContextLost
= (1 << 5)
31 int GLES2Util::GLGetNumValuesReturned(int id
) const {
33 // -- glGetBooleanv, glGetFloatv, glGetIntergerv
34 case GL_ACTIVE_TEXTURE
:
36 case GL_ALIASED_LINE_WIDTH_RANGE
:
38 case GL_ALIASED_POINT_SIZE_RANGE
:
42 case GL_ARRAY_BUFFER_BINDING
:
48 case GL_BLEND_DST_ALPHA
:
50 case GL_BLEND_DST_RGB
:
52 case GL_BLEND_EQUATION_ALPHA
:
54 case GL_BLEND_EQUATION_RGB
:
56 case GL_BLEND_SRC_ALPHA
:
58 case GL_BLEND_SRC_RGB
:
62 case GL_COLOR_CLEAR_VALUE
:
64 case GL_COLOR_WRITEMASK
:
66 case GL_COMPRESSED_TEXTURE_FORMATS
:
67 return num_compressed_texture_formats_
;
70 case GL_CULL_FACE_MODE
:
72 case GL_CURRENT_PROGRAM
:
76 case GL_DEPTH_CLEAR_VALUE
:
84 case GL_DEPTH_WRITEMASK
:
88 case GL_ELEMENT_ARRAY_BUFFER_BINDING
:
90 case GL_FRAMEBUFFER_BINDING
:
94 case GL_GENERATE_MIPMAP_HINT
:
98 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
100 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
104 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS
:
106 case GL_MAX_CUBE_MAP_TEXTURE_SIZE
:
108 case GL_MAX_FRAGMENT_UNIFORM_VECTORS
:
110 case GL_MAX_RENDERBUFFER_SIZE
:
112 case GL_MAX_TEXTURE_IMAGE_UNITS
:
114 case GL_MAX_TEXTURE_SIZE
:
116 case GL_MAX_VARYING_VECTORS
:
118 case GL_MAX_VERTEX_ATTRIBS
:
120 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS
:
122 case GL_MAX_VERTEX_UNIFORM_VECTORS
:
124 case GL_MAX_VIEWPORT_DIMS
:
126 case GL_NUM_COMPRESSED_TEXTURE_FORMATS
:
128 case GL_NUM_SHADER_BINARY_FORMATS
:
130 case GL_PACK_ALIGNMENT
:
132 case GL_PACK_REVERSE_ROW_ORDER_ANGLE
:
134 case GL_POLYGON_OFFSET_FACTOR
:
136 case GL_POLYGON_OFFSET_FILL
:
138 case GL_POLYGON_OFFSET_UNITS
:
142 case GL_RENDERBUFFER_BINDING
:
144 case GL_SAMPLE_BUFFERS
:
146 case GL_SAMPLE_COVERAGE_INVERT
:
148 case GL_SAMPLE_COVERAGE_VALUE
:
154 case GL_SCISSOR_TEST
:
156 case GL_SHADER_BINARY_FORMATS
:
157 return num_shader_binary_formats_
;
158 case GL_SHADER_COMPILER
:
160 case GL_STENCIL_BACK_FAIL
:
162 case GL_STENCIL_BACK_FUNC
:
164 case GL_STENCIL_BACK_PASS_DEPTH_FAIL
:
166 case GL_STENCIL_BACK_PASS_DEPTH_PASS
:
168 case GL_STENCIL_BACK_REF
:
170 case GL_STENCIL_BACK_VALUE_MASK
:
172 case GL_STENCIL_BACK_WRITEMASK
:
174 case GL_STENCIL_BITS
:
176 case GL_STENCIL_CLEAR_VALUE
:
178 case GL_STENCIL_FAIL
:
180 case GL_STENCIL_FUNC
:
182 case GL_STENCIL_PASS_DEPTH_FAIL
:
184 case GL_STENCIL_PASS_DEPTH_PASS
:
188 case GL_STENCIL_TEST
:
190 case GL_STENCIL_VALUE_MASK
:
192 case GL_STENCIL_WRITEMASK
:
194 case GL_SUBPIXEL_BITS
:
196 case GL_TEXTURE_BINDING_2D
:
198 case GL_TEXTURE_BINDING_CUBE_MAP
:
200 case GL_TEXTURE_BINDING_EXTERNAL_OES
:
202 case GL_TEXTURE_BINDING_RECTANGLE_ARB
:
204 case GL_TEXTURE_IMMUTABLE_FORMAT_EXT
:
206 case GL_UNPACK_ALIGNMENT
:
210 // -- glGetBooleanv, glGetFloatv, glGetIntergerv with
211 // GL_CHROMIUM_framebuffer_multisample
212 case GL_MAX_SAMPLES_EXT
:
214 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
:
217 // -- glGetBufferParameteriv
220 case GL_BUFFER_USAGE
:
223 // -- glGetFramebufferAttachmentParameteriv
224 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
:
226 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
:
228 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL
:
230 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE
:
232 // -- glGetFramebufferAttachmentParameteriv with
233 // GL_EXT_multisampled_render_to_texture
234 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT
:
236 // -- glGetFramebufferAttachmentParameteriv with
238 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT
:
242 case GL_DELETE_STATUS
:
246 case GL_VALIDATE_STATUS
:
248 case GL_INFO_LOG_LENGTH
:
250 case GL_ATTACHED_SHADERS
:
252 case GL_ACTIVE_ATTRIBUTES
:
254 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
:
256 case GL_ACTIVE_UNIFORMS
:
258 case GL_ACTIVE_UNIFORM_MAX_LENGTH
:
262 // -- glGetRenderbufferAttachmentParameteriv
263 case GL_RENDERBUFFER_WIDTH
:
265 case GL_RENDERBUFFER_HEIGHT
:
267 case GL_RENDERBUFFER_INTERNAL_FORMAT
:
269 case GL_RENDERBUFFER_RED_SIZE
:
271 case GL_RENDERBUFFER_GREEN_SIZE
:
273 case GL_RENDERBUFFER_BLUE_SIZE
:
275 case GL_RENDERBUFFER_ALPHA_SIZE
:
277 case GL_RENDERBUFFER_DEPTH_SIZE
:
279 case GL_RENDERBUFFER_STENCIL_SIZE
:
281 // -- glGetRenderbufferAttachmentParameteriv with
282 // GL_EXT_multisampled_render_to_texture
283 case GL_RENDERBUFFER_SAMPLES_EXT
:
289 // Already defined under glGetFramebufferAttachemntParameteriv.
290 // case GL_DELETE_STATUS:
292 case GL_COMPILE_STATUS
:
294 // Already defined under glGetFramebufferAttachemntParameteriv.
295 // case GL_INFO_LOG_LENGTH:
297 case GL_SHADER_SOURCE_LENGTH
:
299 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE
:
302 // -- glGetTexParameterfv, glGetTexParameteriv
303 case GL_TEXTURE_MAG_FILTER
:
305 case GL_TEXTURE_MIN_FILTER
:
307 case GL_TEXTURE_WRAP_S
:
309 case GL_TEXTURE_WRAP_T
:
311 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
314 // -- glGetVertexAttribfv, glGetVertexAttribiv
315 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
:
317 case GL_VERTEX_ATTRIB_ARRAY_ENABLED
:
319 case GL_VERTEX_ATTRIB_ARRAY_SIZE
:
321 case GL_VERTEX_ATTRIB_ARRAY_STRIDE
:
323 case GL_VERTEX_ATTRIB_ARRAY_TYPE
:
325 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED
:
327 case GL_CURRENT_VERTEX_ATTRIB
:
330 // -- glHint with GL_OES_standard_derivatives
331 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES
:
334 // Chromium internal bind_generates_resource query
335 case GL_BIND_GENERATES_RESOURCE_CHROMIUM
:
346 // Return the number of elements per group of a specified format.
347 int ElementsPerGroup(int format
, int type
) {
349 case GL_UNSIGNED_SHORT_5_6_5
:
350 case GL_UNSIGNED_SHORT_4_4_4_4
:
351 case GL_UNSIGNED_SHORT_5_5_5_1
:
352 case GL_UNSIGNED_INT_24_8_OES
:
362 case GL_LUMINANCE_ALPHA
:
366 case GL_SRGB_ALPHA_EXT
:
370 case GL_DEPTH_COMPONENT
:
371 case GL_DEPTH_COMPONENT24_OES
:
372 case GL_DEPTH_COMPONENT32_OES
:
373 case GL_DEPTH_COMPONENT16
:
374 case GL_DEPTH24_STENCIL8_OES
:
375 case GL_DEPTH_STENCIL_OES
:
382 // Return the number of bytes per element, based on the element type.
383 int BytesPerElement(int type
) {
386 case GL_UNSIGNED_INT_24_8_OES
:
387 case GL_UNSIGNED_INT
:
389 case GL_HALF_FLOAT_OES
:
390 case GL_UNSIGNED_SHORT
:
392 case GL_UNSIGNED_SHORT_5_6_5
:
393 case GL_UNSIGNED_SHORT_4_4_4_4
:
394 case GL_UNSIGNED_SHORT_5_5_5_1
:
396 case GL_UNSIGNED_BYTE
:
404 } // anonymous namespace
406 uint32
GLES2Util::ComputeImageGroupSize(int format
, int type
) {
407 return BytesPerElement(type
) * ElementsPerGroup(format
, type
);
410 bool GLES2Util::ComputeImagePaddedRowSize(
411 int width
, int format
, int type
, int unpack_alignment
,
412 uint32
* padded_row_size
) {
413 uint32 bytes_per_group
= ComputeImageGroupSize(format
, type
);
414 uint32 unpadded_row_size
;
415 if (!SafeMultiplyUint32(width
, bytes_per_group
, &unpadded_row_size
)) {
419 if (!SafeAddUint32(unpadded_row_size
, unpack_alignment
- 1, &temp
)) {
422 *padded_row_size
= (temp
/ unpack_alignment
) * unpack_alignment
;
426 // Returns the amount of data glTexImage2D or glTexSubImage2D will access.
427 bool GLES2Util::ComputeImageDataSizes(
428 int width
, int height
, int format
, int type
, int unpack_alignment
,
429 uint32
* size
, uint32
* ret_unpadded_row_size
, uint32
* ret_padded_row_size
) {
430 uint32 bytes_per_group
= ComputeImageGroupSize(format
, type
);
432 if (!SafeMultiplyUint32(width
, bytes_per_group
, &row_size
)) {
437 if (!SafeAddUint32(row_size
, unpack_alignment
- 1, &temp
)) {
440 uint32 padded_row_size
= (temp
/ unpack_alignment
) * unpack_alignment
;
441 uint32 size_of_all_but_last_row
;
442 if (!SafeMultiplyUint32((height
- 1), padded_row_size
,
443 &size_of_all_but_last_row
)) {
446 if (!SafeAddUint32(size_of_all_but_last_row
, row_size
, size
)) {
449 if (ret_padded_row_size
) {
450 *ret_padded_row_size
= padded_row_size
;
453 if (!SafeMultiplyUint32(height
, row_size
, size
)) {
456 if (ret_padded_row_size
) {
457 *ret_padded_row_size
= row_size
;
460 if (ret_unpadded_row_size
) {
461 *ret_unpadded_row_size
= row_size
;
467 size_t GLES2Util::RenderbufferBytesPerPixel(int format
) {
469 case GL_STENCIL_INDEX8
:
474 case GL_DEPTH_COMPONENT16
:
478 case GL_DEPTH24_STENCIL8_OES
:
481 case GL_DEPTH_COMPONENT24_OES
:
488 uint32
GLES2Util::GetGLDataTypeSizeForUniforms(int type
) {
491 return sizeof(GLfloat
); // NOLINT
493 return sizeof(GLfloat
) * 2; // NOLINT
495 return sizeof(GLfloat
) * 3; // NOLINT
497 return sizeof(GLfloat
) * 4; // NOLINT
499 return sizeof(GLint
); // NOLINT
501 return sizeof(GLint
) * 2; // NOLINT
503 return sizeof(GLint
) * 3; // NOLINT
505 return sizeof(GLint
) * 4; // NOLINT
507 return sizeof(GLint
); // NOLINT
509 return sizeof(GLint
) * 2; // NOLINT
511 return sizeof(GLint
) * 3; // NOLINT
513 return sizeof(GLint
) * 4; // NOLINT
515 return sizeof(GLfloat
) * 2 * 2; // NOLINT
517 return sizeof(GLfloat
) * 3 * 3; // NOLINT
519 return sizeof(GLfloat
) * 4 * 4; // NOLINT
521 return sizeof(GLint
); // NOLINT
522 case GL_SAMPLER_2D_RECT_ARB
:
523 return sizeof(GLint
); // NOLINT
524 case GL_SAMPLER_CUBE
:
525 return sizeof(GLint
); // NOLINT
526 case GL_SAMPLER_EXTERNAL_OES
:
527 return sizeof(GLint
); // NOLINT
533 size_t GLES2Util::GetGLTypeSizeForTexturesAndBuffers(uint32 type
) {
536 return sizeof(GLbyte
); // NOLINT
537 case GL_UNSIGNED_BYTE
:
538 return sizeof(GLubyte
); // NOLINT
540 return sizeof(GLshort
); // NOLINT
541 case GL_UNSIGNED_SHORT
:
542 return sizeof(GLushort
); // NOLINT
544 return sizeof(GLint
); // NOLINT
545 case GL_UNSIGNED_INT
:
546 return sizeof(GLuint
); // NOLINT
548 return sizeof(GLfloat
); // NOLINT
550 return sizeof(GLfixed
); // NOLINT
556 uint32
GLES2Util::GLErrorToErrorBit(uint32 error
) {
558 case GL_INVALID_ENUM
:
559 return gl_error_bit::kInvalidEnum
;
560 case GL_INVALID_VALUE
:
561 return gl_error_bit::kInvalidValue
;
562 case GL_INVALID_OPERATION
:
563 return gl_error_bit::kInvalidOperation
;
564 case GL_OUT_OF_MEMORY
:
565 return gl_error_bit::kOutOfMemory
;
566 case GL_INVALID_FRAMEBUFFER_OPERATION
:
567 return gl_error_bit::kInvalidFrameBufferOperation
;
568 case GL_CONTEXT_LOST_KHR
:
569 return gl_error_bit::kContextLost
;
572 return gl_error_bit::kNoError
;
576 uint32
GLES2Util::GLErrorBitToGLError(uint32 error_bit
) {
578 case gl_error_bit::kInvalidEnum
:
579 return GL_INVALID_ENUM
;
580 case gl_error_bit::kInvalidValue
:
581 return GL_INVALID_VALUE
;
582 case gl_error_bit::kInvalidOperation
:
583 return GL_INVALID_OPERATION
;
584 case gl_error_bit::kOutOfMemory
:
585 return GL_OUT_OF_MEMORY
;
586 case gl_error_bit::kInvalidFrameBufferOperation
:
587 return GL_INVALID_FRAMEBUFFER_OPERATION
;
588 case gl_error_bit::kContextLost
:
589 return GL_CONTEXT_LOST_KHR
;
596 uint32
GLES2Util::IndexToGLFaceTarget(int index
) {
597 static uint32 faces
[] = {
598 GL_TEXTURE_CUBE_MAP_POSITIVE_X
,
599 GL_TEXTURE_CUBE_MAP_NEGATIVE_X
,
600 GL_TEXTURE_CUBE_MAP_POSITIVE_Y
,
601 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
602 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
,
603 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
608 size_t GLES2Util::GLTargetToFaceIndex(uint32 target
) {
611 case GL_TEXTURE_EXTERNAL_OES
:
612 case GL_TEXTURE_RECTANGLE_ARB
:
614 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
616 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
618 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
620 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
622 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
624 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
632 uint32
GLES2Util::GetPreferredGLReadPixelsFormat(uint32 internal_format
) {
633 switch (internal_format
) {
645 uint32
GLES2Util::GetPreferredGLReadPixelsType(
646 uint32 internal_format
, uint32 texture_type
) {
647 switch (internal_format
) {
653 return GL_HALF_FLOAT_OES
;
656 // Unsized internal format, check the type
657 switch (texture_type
) {
659 case GL_HALF_FLOAT_OES
:
662 return GL_UNSIGNED_BYTE
;
665 return GL_UNSIGNED_BYTE
;
669 uint32
GLES2Util::GetChannelsForFormat(int format
) {
672 case GL_ALPHA16F_EXT
:
673 case GL_ALPHA32F_EXT
:
677 case GL_LUMINANCE_ALPHA
:
694 case GL_SRGB_ALPHA_EXT
:
695 case GL_SRGB8_ALPHA8_EXT
:
697 case GL_DEPTH_COMPONENT32_OES
:
698 case GL_DEPTH_COMPONENT24_OES
:
699 case GL_DEPTH_COMPONENT16
:
700 case GL_DEPTH_COMPONENT
:
702 case GL_STENCIL_INDEX8
:
704 case GL_DEPTH_STENCIL_OES
:
705 case GL_DEPTH24_STENCIL8_OES
:
706 return kDepth
| kStencil
;
712 uint32
GLES2Util::GetChannelsNeededForAttachmentType(
713 int type
, uint32 max_color_attachments
) {
715 case GL_DEPTH_ATTACHMENT
:
717 case GL_STENCIL_ATTACHMENT
:
720 if (type
>= GL_COLOR_ATTACHMENT0
&&
721 type
< static_cast<int>(
722 GL_COLOR_ATTACHMENT0
+ max_color_attachments
)) {
729 std::string
GLES2Util::GetStringEnum(uint32 value
) {
730 const EnumToString
* entry
= enum_to_string_table_
;
731 const EnumToString
* end
= entry
+ enum_to_string_table_len_
;
732 for (;entry
< end
; ++entry
) {
733 if (value
== entry
->value
) {
737 std::stringstream ss
;
739 ss
.width(value
< 0x10000 ? 4 : 8);
740 ss
<< std::hex
<< value
;
741 return "0x" + ss
.str();
744 std::string
GLES2Util::GetStringError(uint32 value
) {
745 static EnumToString string_table
[] = {
746 { GL_NONE
, "GL_NONE" },
748 return GLES2Util::GetQualifiedEnumString(
749 string_table
, arraysize(string_table
), value
);
752 std::string
GLES2Util::GetStringBool(uint32 value
) {
753 return value
? "GL_TRUE" : "GL_FALSE";
756 std::string
GLES2Util::GetQualifiedEnumString(
757 const EnumToString
* table
, size_t count
, uint32 value
) {
758 for (const EnumToString
* end
= table
+ count
; table
< end
; ++table
) {
759 if (table
->value
== value
) {
763 return GetStringEnum(value
);
766 bool GLES2Util::ParseUniformName(
767 const std::string
& name
,
770 bool* getting_array
) {
771 bool getting_array_location
= false;
772 size_t open_pos
= std::string::npos
;
774 if (name
[name
.size() - 1] == ']') {
775 if (name
.size() < 3) {
778 open_pos
= name
.find_last_of('[');
779 if (open_pos
== std::string::npos
||
780 open_pos
>= name
.size() - 2) {
783 size_t last
= name
.size() - 1;
784 for (size_t pos
= open_pos
+ 1; pos
< last
; ++pos
) {
785 int8 digit
= name
[pos
] - '0';
786 if (digit
< 0 || digit
> 9) {
789 index
= index
* 10 + digit
;
791 getting_array_location
= true;
793 *getting_array
= getting_array_location
;
794 *element_index
= index
;
795 *array_pos
= open_pos
;
801 // WebGraphicsContext3DCommandBufferImpl configuration attributes. Those in
802 // the 16-bit range are the same as used by EGL. Those outside the 16-bit range
803 // are unique to Chromium. Attributes are matched using a closest fit algorithm.
806 const int32 kAlphaSize
= 0x3021; // EGL_ALPHA_SIZE
807 const int32 kBlueSize
= 0x3022; // EGL_BLUE_SIZE
808 const int32 kGreenSize
= 0x3023; // EGL_GREEN_SIZE
809 const int32 kRedSize
= 0x3024; // EGL_RED_SIZE
810 const int32 kDepthSize
= 0x3025; // EGL_DEPTH_SIZE
811 const int32 kStencilSize
= 0x3026; // EGL_STENCIL_SIZE
812 const int32 kSamples
= 0x3031; // EGL_SAMPLES
813 const int32 kSampleBuffers
= 0x3032; // EGL_SAMPLE_BUFFERS
814 const int32 kNone
= 0x3038; // EGL_NONE
815 const int32 kSwapBehavior
= 0x3093; // EGL_SWAP_BEHAVIOR
816 const int32 kBufferPreserved
= 0x3094; // EGL_BUFFER_PRESERVED
817 const int32 kBufferDestroyed
= 0x3095; // EGL_BUFFER_DESTROYED
820 const int32 kBindGeneratesResource
= 0x10000;
821 const int32 kFailIfMajorPerfCaveat
= 0x10001;
822 const int32 kLoseContextWhenOutOfMemory
= 0x10002;
826 ContextCreationAttribHelper::ContextCreationAttribHelper()
835 buffer_preserved(true),
836 bind_generates_resource(true),
837 fail_if_major_perf_caveat(false),
838 lose_context_when_out_of_memory(false) {}
840 void ContextCreationAttribHelper::Serialize(std::vector
<int32
>* attribs
) const {
841 if (alpha_size
!= -1) {
842 attribs
->push_back(kAlphaSize
);
843 attribs
->push_back(alpha_size
);
845 if (blue_size
!= -1) {
846 attribs
->push_back(kBlueSize
);
847 attribs
->push_back(blue_size
);
849 if (green_size
!= -1) {
850 attribs
->push_back(kGreenSize
);
851 attribs
->push_back(green_size
);
853 if (red_size
!= -1) {
854 attribs
->push_back(kRedSize
);
855 attribs
->push_back(red_size
);
857 if (depth_size
!= -1) {
858 attribs
->push_back(kDepthSize
);
859 attribs
->push_back(depth_size
);
861 if (stencil_size
!= -1) {
862 attribs
->push_back(kStencilSize
);
863 attribs
->push_back(stencil_size
);
866 attribs
->push_back(kSamples
);
867 attribs
->push_back(samples
);
869 if (sample_buffers
!= -1) {
870 attribs
->push_back(kSampleBuffers
);
871 attribs
->push_back(sample_buffers
);
873 attribs
->push_back(kSwapBehavior
);
874 attribs
->push_back(buffer_preserved
? kBufferPreserved
: kBufferDestroyed
);
875 attribs
->push_back(kBindGeneratesResource
);
876 attribs
->push_back(bind_generates_resource
? 1 : 0);
877 attribs
->push_back(kFailIfMajorPerfCaveat
);
878 attribs
->push_back(fail_if_major_perf_caveat
? 1 : 0);
879 attribs
->push_back(kLoseContextWhenOutOfMemory
);
880 attribs
->push_back(lose_context_when_out_of_memory
? 1 : 0);
881 attribs
->push_back(kNone
);
884 bool ContextCreationAttribHelper::Parse(const std::vector
<int32
>& attribs
) {
885 for (size_t i
= 0; i
< attribs
.size(); i
+= 2) {
886 const int32 attrib
= attribs
[i
];
887 if (i
+ 1 >= attribs
.size()) {
888 if (attrib
== kNone
) {
892 DLOG(ERROR
) << "Missing value after context creation attribute: "
897 const int32 value
= attribs
[i
+1];
915 stencil_size
= value
;
921 sample_buffers
= value
;
924 buffer_preserved
= value
== kBufferPreserved
;
926 case kBindGeneratesResource
:
927 bind_generates_resource
= value
!= 0;
929 case kFailIfMajorPerfCaveat
:
930 fail_if_major_perf_caveat
= value
!= 0;
932 case kLoseContextWhenOutOfMemory
:
933 lose_context_when_out_of_memory
= value
!= 0;
936 // Terminate list, even if more attributes.
939 DLOG(ERROR
) << "Invalid context creation attribute: " << attrib
;
947 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h"