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
|
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrTypes.h"
#include "GrGLInterface.h"
#include "GrGLDefines.h"
#include <stdio.h>
#if GR_GL_PER_GL_FUNC_CALLBACK
namespace {
void GrGLDefaultInterfaceCallback(const GrGLInterface*) {}
}
#endif
GrGLVersion GrGLGetVersionFromString(const char* versionString) {
if (NULL == versionString) {
GrAssert(!"NULL GL version string.");
return 0;
}
int major, minor;
int n = sscanf(versionString, "%d.%d", &major, &minor);
if (2 == n) {
return GR_GL_VER(major, minor);
}
char profile[2];
n = sscanf(versionString, "OpenGL ES-%c%c %d.%d", profile, profile+1,
&major, &minor);
if (4 == n) {
return GR_GL_VER(major, minor);
}
n = sscanf(versionString, "OpenGL ES %d.%d", &major, &minor);
if (2 == n) {
return GR_GL_VER(major, minor);
}
return 0;
}
GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString) {
if (NULL == versionString) {
GrAssert(!"NULL GLSL version string.");
return 0;
}
int major, minor;
int n = sscanf(versionString, "%d.%d", &major, &minor);
if (2 == n) {
return GR_GLSL_VER(major, minor);
}
n = sscanf(versionString, "OpenGL ES GLSL ES %d.%d", &major, &minor);
if (2 == n) {
return GR_GLSL_VER(major, minor);
}
return 0;
}
bool GrGLHasExtensionFromString(const char* ext, const char* extensionString) {
int extLength = strlen(ext);
while (true) {
int n = strcspn(extensionString, " ");
if (n == extLength && 0 == strncmp(ext, extensionString, n)) {
return true;
}
if (0 == extensionString[n]) {
return false;
}
extensionString += n+1;
}
return false;
}
bool GrGLHasExtension(const GrGLInterface* gl, const char* ext) {
const GrGLubyte* glstr;
GR_GL_CALL_RET(gl, glstr, GetString(GR_GL_EXTENSIONS));
return GrGLHasExtensionFromString(ext, (const char*) glstr);
}
GrGLVersion GrGLGetVersion(const GrGLInterface* gl) {
const GrGLubyte* v;
GR_GL_CALL_RET(gl, v, GetString(GR_GL_VERSION));
return GrGLGetVersionFromString((const char*) v);
}
GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface* gl) {
const GrGLubyte* v;
GR_GL_CALL_RET(gl, v, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
return GrGLGetGLSLVersionFromString((const char*) v);
}
GrGLInterface::GrGLInterface() {
fBindingsExported = (GrGLBinding)0;
fActiveTexture = NULL;
fAttachShader = NULL;
fBeginQuery = NULL;
fBindAttribLocation = NULL;
fBindBuffer = NULL;
fBindFragDataLocation = NULL;
fBindTexture = NULL;
fBlendColor = NULL;
fBlendFunc = NULL;
fBufferData = NULL;
fBufferSubData = NULL;
fClear = NULL;
fClearColor = NULL;
fClearStencil = NULL;
fColorMask = NULL;
fColorPointer = NULL;
fCompileShader = NULL;
fCompressedTexImage2D = NULL;
fCreateProgram = NULL;
fCreateShader = NULL;
fCullFace = NULL;
fDeleteBuffers = NULL;
fDeleteProgram = NULL;
fDeleteQueries = NULL;
fDeleteShader = NULL;
fDeleteTextures = NULL;
fDepthMask = NULL;
fDisable = NULL;
fDisableVertexAttribArray = NULL;
fDrawArrays = NULL;
fDrawBuffer = NULL;
fDrawBuffers = NULL;
fDrawElements = NULL;
fEndQuery = NULL;
fFinish = NULL;
fFlush = NULL;
fEnable = NULL;
fEnableVertexAttribArray = NULL;
fFrontFace = NULL;
fGenBuffers = NULL;
fGenQueries = NULL;
fGenTextures = NULL;
fGetBufferParameteriv = NULL;
fGetError = NULL;
fGetIntegerv = NULL;
fGetQueryiv = NULL;
fGetQueryObjecti64v = NULL;
fGetQueryObjectiv = NULL;
fGetQueryObjectui64v = NULL;
fGetQueryObjectuiv = NULL;
fGetProgramInfoLog = NULL;
fGetProgramiv = NULL;
fGetShaderInfoLog = NULL;
fGetShaderiv = NULL;
fGetString = NULL;
fGetTexLevelParameteriv = NULL;
fGetUniformLocation = NULL;
fLineWidth = NULL;
fLinkProgram = NULL;
fPixelStorei = NULL;
fQueryCounter = NULL;
fReadBuffer = NULL;
fReadPixels = NULL;
fScissor = NULL;
fShaderSource = NULL;
fStencilFunc = NULL;
fStencilFuncSeparate = NULL;
fStencilMask = NULL;
fStencilMaskSeparate = NULL;
fStencilOp = NULL;
fStencilOpSeparate = NULL;
fTexImage2D = NULL;
fTexParameteri = NULL;
fTexSubImage2D = NULL;
fUniform1f = NULL;
fUniform1i = NULL;
fUniform1fv = NULL;
fUniform1iv = NULL;
fUniform2f = NULL;
fUniform2i = NULL;
fUniform2fv = NULL;
fUniform2iv = NULL;
fUniform3f = NULL;
fUniform3i = NULL;
fUniform3fv = NULL;
fUniform3iv = NULL;
fUniform4f = NULL;
fUniform4i = NULL;
fUniform4fv = NULL;
fUniform4iv = NULL;
fUniformMatrix2fv = NULL;
fUniformMatrix3fv = NULL;
fUniformMatrix4fv = NULL;
fUseProgram = NULL;
fVertexAttrib4fv = NULL;
fVertexAttribPointer = NULL;
fViewport = NULL;
fBindFramebuffer = NULL;
fBindRenderbuffer = NULL;
fCheckFramebufferStatus = NULL;
fDeleteFramebuffers = NULL;
fDeleteRenderbuffers = NULL;
fFramebufferRenderbuffer = NULL;
fFramebufferTexture2D = NULL;
fGenFramebuffers = NULL;
fGenRenderbuffers = NULL;
fGetFramebufferAttachmentParameteriv = NULL;
fGetRenderbufferParameteriv = NULL;
fRenderbufferStorage = NULL;
fRenderbufferStorageMultisample = NULL;
fBlitFramebuffer = NULL;
fResolveMultisampleFramebuffer = NULL;
fMapBuffer = NULL;
fUnmapBuffer = NULL;
fBindFragDataLocationIndexed = NULL;
#if GR_GL_PER_GL_FUNC_CALLBACK
fCallback = GrGLDefaultInterfaceCallback;
fCallbackData = 0;
#endif
}
bool GrGLInterface::validate() const {
bool isDesktop = this->supportsDesktop();
bool isES2 = this->supportsES2();
if (isDesktop == isES2) {
// must have one, don't support both in same interface
return false;
}
// functions that are always required
if (NULL == fActiveTexture ||
NULL == fAttachShader ||
NULL == fBindAttribLocation ||
NULL == fBindBuffer ||
NULL == fBindTexture ||
NULL == fBlendFunc ||
NULL == fBufferData ||
NULL == fBufferSubData ||
NULL == fClear ||
NULL == fClearColor ||
NULL == fClearStencil ||
NULL == fColorMask ||
NULL == fCompileShader ||
NULL == fCreateProgram ||
NULL == fCreateShader ||
NULL == fCullFace ||
NULL == fDeleteBuffers ||
NULL == fDeleteProgram ||
NULL == fDeleteShader ||
NULL == fDeleteTextures ||
NULL == fDepthMask ||
NULL == fDisable ||
NULL == fDisableVertexAttribArray ||
NULL == fDrawArrays ||
NULL == fDrawElements ||
NULL == fEnable ||
NULL == fEnableVertexAttribArray ||
NULL == fFrontFace ||
NULL == fGenBuffers ||
NULL == fGenTextures ||
NULL == fGetBufferParameteriv ||
NULL == fGetError ||
NULL == fGetIntegerv ||
NULL == fGetProgramInfoLog ||
NULL == fGetProgramiv ||
NULL == fGetShaderInfoLog ||
NULL == fGetShaderiv ||
NULL == fGetString ||
NULL == fGetUniformLocation ||
NULL == fLinkProgram ||
NULL == fPixelStorei ||
NULL == fReadPixels ||
NULL == fScissor ||
NULL == fShaderSource ||
NULL == fStencilFunc ||
NULL == fStencilMask ||
NULL == fStencilOp ||
NULL == fTexImage2D ||
NULL == fTexParameteri ||
NULL == fTexSubImage2D ||
NULL == fUniform1f ||
NULL == fUniform1i ||
NULL == fUniform1fv ||
NULL == fUniform1iv ||
NULL == fUniform2f ||
NULL == fUniform2i ||
NULL == fUniform2fv ||
NULL == fUniform2iv ||
NULL == fUniform3f ||
NULL == fUniform3i ||
NULL == fUniform3fv ||
NULL == fUniform3iv ||
NULL == fUniform4f ||
NULL == fUniform4i ||
NULL == fUniform4fv ||
NULL == fUniform4iv ||
NULL == fUniformMatrix2fv ||
NULL == fUniformMatrix3fv ||
NULL == fUniformMatrix4fv ||
NULL == fUseProgram ||
NULL == fVertexAttrib4fv ||
NULL == fVertexAttribPointer ||
NULL == fViewport ||
NULL == fBindFramebuffer ||
NULL == fBindRenderbuffer ||
NULL == fCheckFramebufferStatus ||
NULL == fDeleteFramebuffers ||
NULL == fDeleteRenderbuffers ||
NULL == fFinish ||
NULL == fFlush ||
NULL == fFramebufferRenderbuffer ||
NULL == fFramebufferTexture2D ||
NULL == fGetFramebufferAttachmentParameteriv ||
NULL == fGetRenderbufferParameteriv ||
NULL == fGenFramebuffers ||
NULL == fGenRenderbuffers ||
NULL == fRenderbufferStorage) {
return false;
}
const char* ext;
GrGLVersion glVer = GrGLGetVersion(this);
ext = (const char*)fGetString(GR_GL_EXTENSIONS);
// Now check that baseline ES/Desktop fns not covered above are present
// and that we have fn pointers for any advertised extensions that we will
// try to use.
// these functions are part of ES2, we assume they are available
// On the desktop we assume they are available if the extension
// is present or GL version is high enough.
if ((kES2_GrGLBinding & fBindingsExported)) {
if (NULL == fBlendColor ||
NULL == fStencilFuncSeparate ||
NULL == fStencilMaskSeparate ||
NULL == fStencilOpSeparate) {
return false;
}
} else if (kDesktop_GrGLBinding == fBindingsExported) {
if (glVer >= GR_GL_VER(2,0)) {
if (NULL == fStencilFuncSeparate ||
NULL == fStencilMaskSeparate ||
NULL == fStencilOpSeparate) {
return false;
}
}
if (glVer >= GR_GL_VER(3,0) && NULL == fBindFragDataLocation) {
return false;
}
if (glVer >= GR_GL_VER(2,0) ||
GrGLHasExtensionFromString("GL_ARB_draw_buffers", ext)) {
if (NULL == fDrawBuffers) {
return false;
}
}
if (glVer >= GR_GL_VER(1,4) ||
GrGLHasExtensionFromString("GL_EXT_blend_color", ext)) {
if (NULL == fBlendColor) {
return false;
}
}
if (glVer >= GR_GL_VER(1,5) ||
GrGLHasExtensionFromString("GL_ARB_occlusion_query", ext)) {
if (NULL == fGenQueries ||
NULL == fDeleteQueries ||
NULL == fBeginQuery ||
NULL == fEndQuery ||
NULL == fGetQueryiv ||
NULL == fGetQueryObjectiv ||
NULL == fGetQueryObjectuiv) {
return false;
}
}
if (glVer >= GR_GL_VER(3,3) ||
GrGLHasExtensionFromString("GL_ARB_timer_query", ext) ||
GrGLHasExtensionFromString("GL_EXT_timer_query", ext)) {
if (NULL == fGetQueryObjecti64v ||
NULL == fGetQueryObjectui64v) {
return false;
}
}
if (glVer >= GR_GL_VER(3,3) ||
GrGLHasExtensionFromString("GL_ARB_timer_query", ext)) {
if (NULL == fQueryCounter) {
return false;
}
}
}
// optional function on desktop before 1.3
if (kDesktop_GrGLBinding != fBindingsExported ||
(glVer >= GR_GL_VER(1,3) ||
GrGLHasExtensionFromString("GL_ARB_texture_compression", ext))) {
if (NULL == fCompressedTexImage2D) {
return false;
}
}
// part of desktop GL, but not ES
if (kDesktop_GrGLBinding == fBindingsExported &&
(NULL == fLineWidth ||
NULL == fGetTexLevelParameteriv ||
NULL == fDrawBuffer ||
NULL == fReadBuffer)) {
return false;
}
// FBO MSAA
if (kDesktop_GrGLBinding == fBindingsExported) {
// GL 3.0 and the ARB extension have multisample + blit
if (glVer >= GR_GL_VER(3,0) || GrGLHasExtensionFromString("GL_ARB_framebuffer_object", ext)) {
if (NULL == fRenderbufferStorageMultisample ||
NULL == fBlitFramebuffer) {
return false;
}
} else {
if (GrGLHasExtensionFromString("GL_EXT_framebuffer_blit", ext) &&
NULL == fBlitFramebuffer) {
return false;
}
if (GrGLHasExtensionFromString("GL_EXT_framebuffer_multisample", ext) &&
NULL == fRenderbufferStorageMultisample) {
return false;
}
}
} else {
if (GrGLHasExtensionFromString("GL_CHROMIUM_framebuffer_multisample", ext)) {
if (NULL == fRenderbufferStorageMultisample ||
NULL == fBlitFramebuffer) {
return false;
}
}
if (GrGLHasExtensionFromString("GL_APPLE_framebuffer_multisample", ext)) {
if (NULL == fRenderbufferStorageMultisample ||
NULL == fResolveMultisampleFramebuffer) {
return false;
}
}
}
// On ES buffer mapping is an extension. On Desktop
// buffer mapping was part of original VBO extension
// which we require.
if (kDesktop_GrGLBinding == fBindingsExported ||
GrGLHasExtensionFromString("GL_OES_mapbuffer", ext)) {
if (NULL == fMapBuffer ||
NULL == fUnmapBuffer) {
return false;
}
}
// Dual source blending
if (kDesktop_GrGLBinding == fBindingsExported &&
(glVer >= GR_GL_VER(3,3) ||
GrGLHasExtensionFromString("GL_ARB_blend_func_extended", ext))) {
if (NULL == fBindFragDataLocationIndexed) {
return false;
}
}
return true;
}
|