1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is here so other GLES2 related files can have a common set of
// includes where appropriate.
#include <stdio.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include "../common/gles2_cmd_utils.h"
#include "../common/gles2_cmd_format.h"
namespace gpu {
namespace gles2 {
namespace gl_error_bit {
enum GLErrorBit {
kNoError = 0,
kInvalidEnum = (1 << 0),
kInvalidValue = (1 << 1),
kInvalidOperation = (1 << 2),
kOutOfMemory = (1 << 3),
kInvalidFrameBufferOperation = (1 << 4)
};
}
int GLES2Util::GLGetNumValuesReturned(int id) const {
switch (id) {
// -- glGetBooleanv, glGetFloatv, glGetIntergerv
case GL_ACTIVE_TEXTURE:
return 1;
case GL_ALIASED_LINE_WIDTH_RANGE:
return 2;
case GL_ALIASED_POINT_SIZE_RANGE:
return 2;
case GL_ALPHA_BITS:
return 1;
case GL_ARRAY_BUFFER_BINDING:
return 1;
case GL_BLEND:
return 1;
case GL_BLEND_COLOR:
return 4;
case GL_BLEND_DST_ALPHA:
return 1;
case GL_BLEND_DST_RGB:
return 1;
case GL_BLEND_EQUATION_ALPHA:
return 1;
case GL_BLEND_EQUATION_RGB:
return 1;
case GL_BLEND_SRC_ALPHA:
return 1;
case GL_BLEND_SRC_RGB:
return 1;
case GL_BLUE_BITS:
return 1;
case GL_COLOR_CLEAR_VALUE:
return 4;
case GL_COLOR_WRITEMASK:
return 4;
case GL_COMPRESSED_TEXTURE_FORMATS:
return num_compressed_texture_formats_;
case GL_CULL_FACE:
return 1;
case GL_CULL_FACE_MODE:
return 1;
case GL_CURRENT_PROGRAM:
return 1;
case GL_DEPTH_BITS:
return 1;
case GL_DEPTH_CLEAR_VALUE:
return 1;
case GL_DEPTH_FUNC:
return 1;
case GL_DEPTH_RANGE:
return 2;
case GL_DEPTH_TEST:
return 1;
case GL_DEPTH_WRITEMASK:
return 1;
case GL_DITHER:
return 1;
case GL_ELEMENT_ARRAY_BUFFER_BINDING:
return 1;
case GL_FRAMEBUFFER_BINDING:
return 1;
case GL_FRONT_FACE:
return 1;
case GL_GENERATE_MIPMAP_HINT:
return 1;
case GL_GREEN_BITS:
return 1;
case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
return 1;
case GL_IMPLEMENTATION_COLOR_READ_TYPE:
return 1;
case GL_LINE_WIDTH:
return 1;
case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
return 1;
case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
return 1;
case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
return 1;
case GL_MAX_RENDERBUFFER_SIZE:
return 1;
case GL_MAX_TEXTURE_IMAGE_UNITS:
return 1;
case GL_MAX_TEXTURE_SIZE:
return 1;
case GL_MAX_VARYING_VECTORS:
return 1;
case GL_MAX_VERTEX_ATTRIBS:
return 1;
case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
return 1;
case GL_MAX_VERTEX_UNIFORM_VECTORS:
return 1;
case GL_MAX_VIEWPORT_DIMS:
return 2;
case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
return 1;
case GL_NUM_SHADER_BINARY_FORMATS:
return 1;
case GL_PACK_ALIGNMENT:
return 1;
case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
return 1;
case GL_POLYGON_OFFSET_FACTOR:
return 1;
case GL_POLYGON_OFFSET_FILL:
return 1;
case GL_POLYGON_OFFSET_UNITS:
return 1;
case GL_RED_BITS:
return 1;
case GL_RENDERBUFFER_BINDING:
return 1;
case GL_SAMPLE_BUFFERS:
return 1;
case GL_SAMPLE_COVERAGE_INVERT:
return 1;
case GL_SAMPLE_COVERAGE_VALUE:
return 1;
case GL_SAMPLES:
return 1;
case GL_SCISSOR_BOX:
return 4;
case GL_SCISSOR_TEST:
return 1;
case GL_SHADER_BINARY_FORMATS:
return num_shader_binary_formats_;
case GL_SHADER_COMPILER:
return 1;
case GL_STENCIL_BACK_FAIL:
return 1;
case GL_STENCIL_BACK_FUNC:
return 1;
case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
return 1;
case GL_STENCIL_BACK_PASS_DEPTH_PASS:
return 1;
case GL_STENCIL_BACK_REF:
return 1;
case GL_STENCIL_BACK_VALUE_MASK:
return 1;
case GL_STENCIL_BACK_WRITEMASK:
return 1;
case GL_STENCIL_BITS:
return 1;
case GL_STENCIL_CLEAR_VALUE:
return 1;
case GL_STENCIL_FAIL:
return 1;
case GL_STENCIL_FUNC:
return 1;
case GL_STENCIL_PASS_DEPTH_FAIL:
return 1;
case GL_STENCIL_PASS_DEPTH_PASS:
return 1;
case GL_STENCIL_REF:
return 1;
case GL_STENCIL_TEST:
return 1;
case GL_STENCIL_VALUE_MASK:
return 1;
case GL_STENCIL_WRITEMASK:
return 1;
case GL_SUBPIXEL_BITS:
return 1;
case GL_TEXTURE_BINDING_2D:
return 1;
case GL_TEXTURE_BINDING_CUBE_MAP:
return 1;
case GL_TEXTURE_BINDING_EXTERNAL_OES:
return 1;
case GL_TEXTURE_BINDING_RECTANGLE_ARB:
return 1;
case GL_UNPACK_ALIGNMENT:
return 1;
case GL_VIEWPORT:
return 4;
// -- glGetBooleanv, glGetFloatv, glGetIntergerv with
// GL_CHROMIUM_framebuffer_multisample
case GL_MAX_SAMPLES_EXT:
return 1;
case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
return 1;
// -- glGetBufferParameteriv
case GL_BUFFER_SIZE:
return 1;
case GL_BUFFER_USAGE:
return 1;
// -- glGetFramebufferAttachmentParameteriv
case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
return 1;
case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
return 1;
case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
return 1;
case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
return 1;
// -- glGetFramebufferAttachmentParameteriv
case GL_DELETE_STATUS:
return 1;
case GL_LINK_STATUS:
return 1;
case GL_VALIDATE_STATUS:
return 1;
case GL_INFO_LOG_LENGTH:
return 1;
case GL_ATTACHED_SHADERS:
return 1;
case GL_ACTIVE_ATTRIBUTES:
return 1;
case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
return 1;
case GL_ACTIVE_UNIFORMS:
return 1;
case GL_ACTIVE_UNIFORM_MAX_LENGTH:
return 1;
// -- glGetRenderbufferAttachmentParameteriv
case GL_RENDERBUFFER_WIDTH:
return 1;
case GL_RENDERBUFFER_HEIGHT:
return 1;
case GL_RENDERBUFFER_INTERNAL_FORMAT:
return 1;
case GL_RENDERBUFFER_RED_SIZE:
return 1;
case GL_RENDERBUFFER_GREEN_SIZE:
return 1;
case GL_RENDERBUFFER_BLUE_SIZE:
return 1;
case GL_RENDERBUFFER_ALPHA_SIZE:
return 1;
case GL_RENDERBUFFER_DEPTH_SIZE:
return 1;
case GL_RENDERBUFFER_STENCIL_SIZE:
return 1;
// -- glGetShaderiv
case GL_SHADER_TYPE:
return 1;
// Already defined under glGetFramebufferAttachemntParameteriv.
// case GL_DELETE_STATUS:
// return 1;
case GL_COMPILE_STATUS:
return 1;
// Already defined under glGetFramebufferAttachemntParameteriv.
// case GL_INFO_LOG_LENGTH:
// return 1;
case GL_SHADER_SOURCE_LENGTH:
return 1;
case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
return 1;
// -- glGetTexParameterfv, glGetTexParameteriv
case GL_TEXTURE_MAG_FILTER:
return 1;
case GL_TEXTURE_MIN_FILTER:
return 1;
case GL_TEXTURE_WRAP_S:
return 1;
case GL_TEXTURE_WRAP_T:
return 1;
case GL_TEXTURE_MAX_ANISOTROPY_EXT:
return 1;
// -- glGetVertexAttribfv, glGetVertexAttribiv
case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
return 1;
case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
return 1;
case GL_VERTEX_ATTRIB_ARRAY_SIZE:
return 1;
case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
return 1;
case GL_VERTEX_ATTRIB_ARRAY_TYPE:
return 1;
case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
return 1;
case GL_CURRENT_VERTEX_ATTRIB:
return 4;
// -- glHint with GL_OES_standard_derivatives
case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
return 1;
// bad enum
default:
return 0;
}
}
namespace {
// Return the number of elements per group of a specified format.
int ElementsPerGroup(int format, int type) {
switch (type) {
case GL_UNSIGNED_SHORT_5_6_5:
case GL_UNSIGNED_SHORT_4_4_4_4:
case GL_UNSIGNED_SHORT_5_5_5_1:
case GL_UNSIGNED_INT_24_8_OES:
return 1;
default:
break;
}
switch (format) {
case GL_RGB:
return 3;
case GL_LUMINANCE_ALPHA:
return 2;
case GL_RGBA:
case GL_BGRA_EXT:
return 4;
case GL_ALPHA:
case GL_LUMINANCE:
case GL_DEPTH_COMPONENT:
case GL_DEPTH_STENCIL_OES:
return 1;
default:
return 0;
}
}
// Return the number of bytes per element, based on the element type.
int BytesPerElement(int type) {
switch (type) {
case GL_FLOAT:
case GL_UNSIGNED_INT_24_8_OES:
case GL_UNSIGNED_INT:
return 4;
case GL_HALF_FLOAT_OES:
case GL_UNSIGNED_SHORT:
case GL_SHORT:
case GL_UNSIGNED_SHORT_5_6_5:
case GL_UNSIGNED_SHORT_4_4_4_4:
case GL_UNSIGNED_SHORT_5_5_5_1:
return 2;
case GL_UNSIGNED_BYTE:
case GL_BYTE:
return 1;
default:
return 0;
}
}
} // anonymous namespace
uint32 GLES2Util::ComputeImageGroupSize(int format, int type) {
return BytesPerElement(type) * ElementsPerGroup(format, type);
}
bool GLES2Util::ComputeImagePaddedRowSize(
int width, int format, int type, int unpack_alignment,
uint32* padded_row_size) {
uint32 bytes_per_group = ComputeImageGroupSize(format, type);
uint32 unpadded_row_size;
if (!SafeMultiplyUint32(width, bytes_per_group, &unpadded_row_size)) {
return false;
}
uint32 temp;
if (!SafeAddUint32(unpadded_row_size, unpack_alignment - 1, &temp)) {
return false;
}
*padded_row_size = (temp / unpack_alignment) * unpack_alignment;
return true;
}
// Returns the amount of data glTexImage2D or glTexSubImage2D will access.
bool GLES2Util::ComputeImageDataSizes(
int width, int height, int format, int type, int unpack_alignment,
uint32* size, uint32* ret_unpadded_row_size, uint32* ret_padded_row_size) {
uint32 bytes_per_group = ComputeImageGroupSize(format, type);
uint32 row_size;
if (!SafeMultiplyUint32(width, bytes_per_group, &row_size)) {
return false;
}
if (height > 1) {
uint32 temp;
if (!SafeAddUint32(row_size, unpack_alignment - 1, &temp)) {
return false;
}
uint32 padded_row_size = (temp / unpack_alignment) * unpack_alignment;
uint32 size_of_all_but_last_row;
if (!SafeMultiplyUint32((height - 1), padded_row_size,
&size_of_all_but_last_row)) {
return false;
}
if (!SafeAddUint32(size_of_all_but_last_row, row_size, size)) {
return false;
}
if (ret_padded_row_size) {
*ret_padded_row_size = padded_row_size;
}
} else {
if (!SafeMultiplyUint32(height, row_size, size)) {
return false;
}
if (ret_padded_row_size) {
*ret_padded_row_size = row_size;
}
}
if (ret_unpadded_row_size) {
*ret_unpadded_row_size = row_size;
}
return true;
}
size_t GLES2Util::RenderbufferBytesPerPixel(int format) {
switch (format) {
case GL_STENCIL_INDEX8:
return 1;
case GL_RGBA4:
case GL_RGB565:
case GL_RGB5_A1:
case GL_DEPTH_COMPONENT16:
return 2;
case GL_RGB:
case GL_RGBA:
case GL_DEPTH24_STENCIL8_OES:
case GL_RGB8_OES:
case GL_RGBA8_OES:
case GL_DEPTH_COMPONENT24_OES:
return 4;
default:
return 0;
}
}
uint32 GLES2Util::GetGLDataTypeSizeForUniforms(int type) {
switch (type) {
case GL_FLOAT:
return sizeof(GLfloat); // NOLINT
case GL_FLOAT_VEC2:
return sizeof(GLfloat) * 2; // NOLINT
case GL_FLOAT_VEC3:
return sizeof(GLfloat) * 3; // NOLINT
case GL_FLOAT_VEC4:
return sizeof(GLfloat) * 4; // NOLINT
case GL_INT:
return sizeof(GLint); // NOLINT
case GL_INT_VEC2:
return sizeof(GLint) * 2; // NOLINT
case GL_INT_VEC3:
return sizeof(GLint) * 3; // NOLINT
case GL_INT_VEC4:
return sizeof(GLint) * 4; // NOLINT
case GL_BOOL:
return sizeof(GLint); // NOLINT
case GL_BOOL_VEC2:
return sizeof(GLint) * 2; // NOLINT
case GL_BOOL_VEC3:
return sizeof(GLint) * 3; // NOLINT
case GL_BOOL_VEC4:
return sizeof(GLint) * 4; // NOLINT
case GL_FLOAT_MAT2:
return sizeof(GLfloat) * 2 * 2; // NOLINT
case GL_FLOAT_MAT3:
return sizeof(GLfloat) * 3 * 3; // NOLINT
case GL_FLOAT_MAT4:
return sizeof(GLfloat) * 4 * 4; // NOLINT
case GL_SAMPLER_2D:
return sizeof(GLint); // NOLINT
case GL_SAMPLER_CUBE:
return sizeof(GLint); // NOLINT
case GL_SAMPLER_EXTERNAL_OES:
return sizeof(GLint); // NOLINT
default:
return 0;
}
}
size_t GLES2Util::GetGLTypeSizeForTexturesAndBuffers(uint32 type) {
switch (type) {
case GL_BYTE:
return sizeof(GLbyte); // NOLINT
case GL_UNSIGNED_BYTE:
return sizeof(GLubyte); // NOLINT
case GL_SHORT:
return sizeof(GLshort); // NOLINT
case GL_UNSIGNED_SHORT:
return sizeof(GLushort); // NOLINT
case GL_INT:
return sizeof(GLint); // NOLINT
case GL_UNSIGNED_INT:
return sizeof(GLuint); // NOLINT
case GL_FLOAT:
return sizeof(GLfloat); // NOLINT
case GL_FIXED:
return sizeof(GLfixed); // NOLINT
default:
return 0;
}
}
uint32 GLES2Util::GLErrorToErrorBit(uint32 error) {
switch (error) {
case GL_INVALID_ENUM:
return gl_error_bit::kInvalidEnum;
case GL_INVALID_VALUE:
return gl_error_bit::kInvalidValue;
case GL_INVALID_OPERATION:
return gl_error_bit::kInvalidOperation;
case GL_OUT_OF_MEMORY:
return gl_error_bit::kOutOfMemory;
case GL_INVALID_FRAMEBUFFER_OPERATION:
return gl_error_bit::kInvalidFrameBufferOperation;
default:
GPU_NOTREACHED();
return gl_error_bit::kNoError;
}
}
uint32 GLES2Util::GLErrorBitToGLError(uint32 error_bit) {
switch (error_bit) {
case gl_error_bit::kInvalidEnum:
return GL_INVALID_ENUM;
case gl_error_bit::kInvalidValue:
return GL_INVALID_VALUE;
case gl_error_bit::kInvalidOperation:
return GL_INVALID_OPERATION;
case gl_error_bit::kOutOfMemory:
return GL_OUT_OF_MEMORY;
case gl_error_bit::kInvalidFrameBufferOperation:
return GL_INVALID_FRAMEBUFFER_OPERATION;
default:
GPU_NOTREACHED();
return GL_NO_ERROR;
}
}
uint32 GLES2Util::IndexToGLFaceTarget(int index) {
static uint32 faces[] = {
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
};
return faces[index];
}
uint32 GLES2Util::GetChannelsForFormat(int format) {
switch (format) {
case GL_ALPHA:
case GL_ALPHA16F_EXT:
case GL_ALPHA32F_EXT:
return kAlpha;
case GL_LUMINANCE:
return kRGB;
case GL_LUMINANCE_ALPHA:
return kRGBA;
case GL_RGB:
case GL_RGB8_OES:
case GL_RGB565:
case GL_RGB16F_EXT:
case GL_RGB32F_EXT:
return kRGB;
case GL_BGRA_EXT:
case GL_BGRA8_EXT:
case GL_RGBA16F_EXT:
case GL_RGBA32F_EXT:
case GL_RGBA:
case GL_RGBA8_OES:
case GL_RGBA4:
case GL_RGB5_A1:
return kRGBA;
case GL_DEPTH_COMPONENT16:
case GL_DEPTH_COMPONENT:
return kDepth;
case GL_STENCIL_INDEX8:
return kStencil;
case GL_DEPTH_STENCIL_OES:
case GL_DEPTH24_STENCIL8_OES:
return kDepth | kStencil;
default:
return 0x0000;
}
}
uint32 GLES2Util::GetChannelsNeededForAttachmentType(int type) {
switch (type) {
case GL_COLOR_ATTACHMENT0:
return kRGBA;
case GL_DEPTH_ATTACHMENT:
return kDepth;
case GL_STENCIL_ATTACHMENT:
return kStencil;
default:
return 0x0000;
}
}
std::string GLES2Util::GetStringEnum(uint32 value) {
const EnumToString* entry = enum_to_string_table_;
const EnumToString* end = entry + enum_to_string_table_len_;
for (;entry < end; ++entry) {
if (value == entry->value) {
return entry->name;
}
}
char buffer[20];
sprintf(buffer, (value < 0x10000) ? "0x%04x" : "0x%08x", value);
return buffer;
}
std::string GLES2Util::GetStringError(uint32 value) {
static EnumToString string_table[] = {
{ GL_NONE, "GL_NONE" },
};
return GLES2Util::GetQualifiedEnumString(
string_table, arraysize(string_table), value);
}
std::string GLES2Util::GetStringBool(uint32 value) {
return value ? "GL_TRUE" : "GL_FALSE";
}
std::string GLES2Util::GetQualifiedEnumString(
const EnumToString* table, size_t count, uint32 value) {
for (const EnumToString* end = table + count; table < end; ++table) {
if (table->value == value) {
return table->name;
}
}
return GetStringEnum(value);
}
ContextCreationAttribParser::ContextCreationAttribParser()
: alpha_size_(-1),
blue_size_(-1),
green_size_(-1),
red_size_(-1),
depth_size_(-1),
stencil_size_(-1),
samples_(-1),
sample_buffers_(-1),
buffer_preserved_(true),
share_resources_(false),
bind_generates_resource_(true) {
}
bool ContextCreationAttribParser::Parse(const std::vector<int32>& attribs) {
// From <EGL/egl.h>.
const int32 EGL_ALPHA_SIZE = 0x3021;
const int32 EGL_BLUE_SIZE = 0x3022;
const int32 EGL_GREEN_SIZE = 0x3023;
const int32 EGL_RED_SIZE = 0x3024;
const int32 EGL_DEPTH_SIZE = 0x3025;
const int32 EGL_STENCIL_SIZE = 0x3026;
const int32 EGL_SAMPLES = 0x3031;
const int32 EGL_SAMPLE_BUFFERS = 0x3032;
const int32 EGL_NONE = 0x3038;
const int32 EGL_SWAP_BEHAVIOR = 0x3093;
const int32 EGL_BUFFER_PRESERVED = 0x3094;
// Chromium only.
const int32 SHARE_RESOURCES = 0x10000;
const int32 BIND_GENERATES_RESOURCES = 0x10001;
for (size_t i = 0; i < attribs.size(); i += 2) {
const int32 attrib = attribs[i];
if (i + 1 >= attribs.size()) {
if (attrib == EGL_NONE) {
return true;
}
GPU_DLOG(ERROR) << "Missing value after context creation attribute: "
<< attrib;
return false;
}
const int32 value = attribs[i+1];
switch (attrib) {
case EGL_ALPHA_SIZE:
alpha_size_ = value;
break;
case EGL_BLUE_SIZE:
blue_size_ = value;
break;
case EGL_GREEN_SIZE:
green_size_ = value;
break;
case EGL_RED_SIZE:
red_size_ = value;
break;
case EGL_DEPTH_SIZE:
depth_size_ = value;
break;
case EGL_STENCIL_SIZE:
stencil_size_ = value;
break;
case EGL_SAMPLES:
samples_ = value;
break;
case EGL_SAMPLE_BUFFERS:
sample_buffers_ = value;
break;
case EGL_SWAP_BEHAVIOR:
buffer_preserved_ = value == EGL_BUFFER_PRESERVED;
break;
case SHARE_RESOURCES:
share_resources_ = value != 0;
break;
case BIND_GENERATES_RESOURCES:
bind_generates_resource_ = value != 0;
break;
case EGL_NONE:
// Terminate list, even if more attributes.
return true;
default:
GPU_DLOG(ERROR) << "Invalid context creation attribute: " << attrib;
return false;
}
}
return true;
}
#include "../common/gles2_cmd_utils_implementation_autogen.h"
} // namespace gles2
} // namespace gpu
|