1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
9 #include "gl/GrGLAssembleInterface.h"
10 #include "GrGLUtil.h"
11
12 #define GET_PROC(F) functions->f##F = (GrGL##F##Fn*)get(ctx, "gl" #F)
13 #define GET_PROC_SUFFIX(F, S) functions->f##F = (GrGL##F##Fn*)get(ctx, "gl" #F #S)
14 #define GET_PROC_LOCAL(F) GrGL##F##Fn* F = (GrGL##F##Fn*)get(ctx, "gl" #F)
15
16 #define GET_EGL_PROC_SUFFIX(F, S) functions->fEGL##F = (GrEGL##F##Fn*)get(ctx, "egl" #F #S)
17
GrGLMakeAssembledInterface(void * ctx,GrGLGetProc get)18 sk_sp<const GrGLInterface> GrGLMakeAssembledInterface(void *ctx, GrGLGetProc get) {
19 GET_PROC_LOCAL(GetString);
20 if (nullptr == GetString) {
21 return nullptr;
22 }
23
24 const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION));
25 if (nullptr == verStr) {
26 return nullptr;
27 }
28
29 GrGLStandard standard = GrGLGetStandardInUseFromString(verStr);
30
31 if (kGLES_GrGLStandard == standard) {
32 return GrGLMakeAssembledGLESInterface(ctx, get);
33 } else if (kGL_GrGLStandard == standard) {
34 return GrGLMakeAssembledGLInterface(ctx, get);
35 }
36 return nullptr;
37 }
38
get_egl_query_and_display(GrEGLQueryStringFn ** queryString,GrEGLDisplay * display,void * ctx,GrGLGetProc get)39 static void get_egl_query_and_display(GrEGLQueryStringFn** queryString, GrEGLDisplay* display,
40 void* ctx, GrGLGetProc get) {
41 *queryString = (GrEGLQueryStringFn*)get(ctx, "eglQueryString");
42 *display = GR_EGL_NO_DISPLAY;
43 if (*queryString) {
44 GrEGLGetCurrentDisplayFn* getCurrentDisplay =
45 (GrEGLGetCurrentDisplayFn*)get(ctx, "eglGetCurrentDisplay");
46 if (getCurrentDisplay) {
47 *display = getCurrentDisplay();
48 } else {
49 *queryString = nullptr;
50 }
51 }
52 }
53
GrGLMakeAssembledGLInterface(void * ctx,GrGLGetProc get)54 sk_sp<const GrGLInterface> GrGLMakeAssembledGLInterface(void *ctx, GrGLGetProc get) {
55 GET_PROC_LOCAL(GetString);
56 GET_PROC_LOCAL(GetStringi);
57 GET_PROC_LOCAL(GetIntegerv);
58
59 // GetStringi may be nullptr depending on the GL version.
60 if (nullptr == GetString || nullptr == GetIntegerv) {
61 return nullptr;
62 }
63
64 const char* versionString = (const char*) GetString(GR_GL_VERSION);
65 GrGLVersion glVer = GrGLGetVersionFromString(versionString);
66
67 if (glVer < GR_GL_VER(2,0) || GR_GL_INVALID_VER == glVer) {
68 // This is our minimum for non-ES GL.
69 return nullptr;
70 }
71
72 GrEGLQueryStringFn* queryString;
73 GrEGLDisplay display;
74 get_egl_query_and_display(&queryString, &display, ctx, get);
75 GrGLExtensions extensions;
76 if (!extensions.init(kGL_GrGLStandard, GetString, GetStringi, GetIntegerv, queryString,
77 display)) {
78 return nullptr;
79 }
80
81 sk_sp<GrGLInterface> interface(new GrGLInterface());
82 GrGLInterface::Functions* functions = &interface->fFunctions;
83
84 GET_PROC(ActiveTexture);
85 GET_PROC(AttachShader);
86 GET_PROC(BindAttribLocation);
87 GET_PROC(BindBuffer);
88 if (glVer >= GR_GL_VER(3,0)) {
89 GET_PROC(BindFragDataLocation);
90 }
91 GET_PROC(BeginQuery);
92 GET_PROC(BindTexture);
93
94 if (extensions.has("GL_KHR_blend_equation_advanced")) {
95 GET_PROC_SUFFIX(BlendBarrier, KHR);
96 } else if (extensions.has("GL_NV_blend_equation_advanced")) {
97 GET_PROC_SUFFIX(BlendBarrier, NV);
98 }
99
100 GET_PROC(BlendColor);
101 GET_PROC(BlendEquation);
102 GET_PROC(BlendFunc);
103 GET_PROC(BufferData);
104 GET_PROC(BufferSubData);
105 GET_PROC(Clear);
106 GET_PROC(ClearColor);
107 GET_PROC(ClearStencil);
108 if (glVer >= GR_GL_VER(4,4) || extensions.has("GL_ARB_clear_texture")) {
109 GET_PROC(ClearTexImage);
110 GET_PROC(ClearTexSubImage);
111 }
112 GET_PROC(ColorMask);
113 GET_PROC(CompileShader);
114 GET_PROC(CompressedTexImage2D);
115 GET_PROC(CompressedTexSubImage2D);
116 GET_PROC(CopyTexSubImage2D);
117 GET_PROC(CreateProgram);
118 GET_PROC(CreateShader);
119 GET_PROC(CullFace);
120 GET_PROC(DeleteBuffers);
121 GET_PROC(DeleteProgram);
122 GET_PROC(DeleteQueries);
123 GET_PROC(DeleteShader);
124 GET_PROC(DeleteTextures);
125 GET_PROC(DepthMask);
126 GET_PROC(Disable);
127 GET_PROC(DisableVertexAttribArray);
128 GET_PROC(DrawArrays);
129 GET_PROC(DrawBuffer);
130 GET_PROC(DrawBuffers);
131 GET_PROC(DrawElements);
132
133 if (glVer >= GR_GL_VER(3,1) || extensions.has("GL_ARB_draw_instanced") ||
134 extensions.has("GL_EXT_draw_instanced")) {
135 GET_PROC(DrawArraysInstanced);
136 GET_PROC(DrawElementsInstanced);
137 }
138
139 if (glVer >= GR_GL_VER(4,0) || extensions.has("GL_ARB_draw_indirect")) {
140 GET_PROC(DrawArraysIndirect);
141 GET_PROC(DrawElementsIndirect);
142 }
143 GET_PROC(DrawRangeElements);
144 GET_PROC(Enable);
145 GET_PROC(EnableVertexAttribArray);
146 GET_PROC(EndQuery);
147 GET_PROC(Finish);
148 GET_PROC(Flush);
149 GET_PROC(FrontFace);
150 GET_PROC(GenBuffers);
151 GET_PROC(GetBufferParameteriv);
152 GET_PROC(GetError);
153 GET_PROC(GetIntegerv);
154 if (glVer >= GR_GL_VER(3,2) || extensions.has("GL_ARB_texture_multisample")) {
155 GET_PROC(GetMultisamplefv);
156 }
157 GET_PROC(GetQueryObjectiv);
158 GET_PROC(GetQueryObjectuiv);
159 if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) {
160 GET_PROC(GetQueryObjecti64v);
161 GET_PROC(GetQueryObjectui64v);
162 GET_PROC(QueryCounter);
163 } else if (extensions.has("GL_EXT_timer_query")) {
164 GET_PROC_SUFFIX(GetQueryObjecti64v, EXT);
165 GET_PROC_SUFFIX(GetQueryObjectui64v, EXT);
166 }
167 GET_PROC(GetQueryiv);
168 GET_PROC(GetProgramInfoLog);
169 GET_PROC(GetProgramiv);
170 GET_PROC(GetShaderInfoLog);
171 GET_PROC(GetShaderiv);
172 GET_PROC(GetString);
173 GET_PROC(GetStringi);
174 GET_PROC(GetShaderPrecisionFormat);
175 GET_PROC(GetTexLevelParameteriv);
176 GET_PROC(GenQueries);
177 GET_PROC(GenTextures);
178 GET_PROC(GetUniformLocation);
179 GET_PROC(IsTexture);
180 GET_PROC(LineWidth);
181 GET_PROC(LinkProgram);
182 GET_PROC(MapBuffer);
183
184 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_multi_draw_indirect")) {
185 GET_PROC(MultiDrawArraysIndirect);
186 GET_PROC(MultiDrawElementsIndirect);
187 }
188
189 GET_PROC(PixelStorei);
190 GET_PROC(PolygonMode);
191 GET_PROC(ReadBuffer);
192 GET_PROC(ReadPixels);
193 GET_PROC(Scissor);
194 GET_PROC(ShaderSource);
195 GET_PROC(StencilFunc);
196 GET_PROC(StencilFuncSeparate);
197 GET_PROC(StencilMask);
198 GET_PROC(StencilMaskSeparate);
199 GET_PROC(StencilOp);
200 GET_PROC(StencilOpSeparate);
201 if (glVer >= GR_GL_VER(3,1)) {
202 GET_PROC(TexBuffer);
203 }
204 if (glVer >= GR_GL_VER(4,3)) {
205 GET_PROC(TexBufferRange);
206 }
207 GET_PROC(TexImage2D);
208 GET_PROC(TexParameterf);
209 GET_PROC(TexParameterfv);
210 GET_PROC(TexParameteri);
211 GET_PROC(TexParameteriv);
212 if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) {
213 GET_PROC(TexStorage2D);
214 } else if (extensions.has("GL_EXT_texture_storage")) {
215 GET_PROC_SUFFIX(TexStorage2D, EXT);
216 }
217 GET_PROC(TexSubImage2D);
218 if (glVer >= GR_GL_VER(4,5) || extensions.has("GL_ARB_texture_barrier")) {
219 GET_PROC(TextureBarrier);
220 } else if (extensions.has("GL_NV_texture_barrier")) {
221 GET_PROC_SUFFIX(TextureBarrier, NV);
222 }
223 GET_PROC(Uniform1f);
224 GET_PROC(Uniform1i);
225 GET_PROC(Uniform1fv);
226 GET_PROC(Uniform1iv);
227 GET_PROC(Uniform2f);
228 GET_PROC(Uniform2i);
229 GET_PROC(Uniform2fv);
230 GET_PROC(Uniform2iv);
231 GET_PROC(Uniform3f);
232 GET_PROC(Uniform3i);
233 GET_PROC(Uniform3fv);
234 GET_PROC(Uniform3iv);
235 GET_PROC(Uniform4f);
236 GET_PROC(Uniform4i);
237 GET_PROC(Uniform4fv);
238 GET_PROC(Uniform4iv);
239 GET_PROC(UniformMatrix2fv);
240 GET_PROC(UniformMatrix3fv);
241 GET_PROC(UniformMatrix4fv);
242 GET_PROC(UnmapBuffer);
243 GET_PROC(UseProgram);
244 GET_PROC(VertexAttrib1f);
245 GET_PROC(VertexAttrib2fv);
246 GET_PROC(VertexAttrib3fv);
247 GET_PROC(VertexAttrib4fv);
248
249 if (glVer >= GR_GL_VER(3,2) || extensions.has("GL_ARB_instanced_arrays")) {
250 GET_PROC(VertexAttribDivisor);
251 }
252
253 if (glVer >= GR_GL_VER(3,0)) {
254 GET_PROC(VertexAttribIPointer);
255 }
256
257 GET_PROC(VertexAttribPointer);
258 GET_PROC(Viewport);
259 GET_PROC(BindFragDataLocationIndexed);
260
261 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object")) {
262 // no ARB suffix for GL_ARB_vertex_array_object
263 GET_PROC(BindVertexArray);
264 GET_PROC(GenVertexArrays);
265 GET_PROC(DeleteVertexArrays);
266 } else if (extensions.has("GL_APPLE_vertex_array_object")) {
267 GET_PROC_SUFFIX(BindVertexArray, APPLE);
268 GET_PROC_SUFFIX(GenVertexArrays, APPLE);
269 GET_PROC_SUFFIX(DeleteVertexArrays, APPLE);
270 }
271
272 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_map_buffer_range")) {
273 GET_PROC(MapBufferRange);
274 GET_PROC(FlushMappedBufferRange);
275 }
276
277 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
278 // GL_ARB_framebuffer_object doesn't use ARB suffix.)
279 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) {
280 GET_PROC(GenerateMipmap);
281 GET_PROC(GenFramebuffers);
282 GET_PROC(GetFramebufferAttachmentParameteriv);
283 GET_PROC(GetRenderbufferParameteriv);
284 GET_PROC(BindFramebuffer);
285 GET_PROC(FramebufferTexture2D);
286 GET_PROC(CheckFramebufferStatus);
287 GET_PROC(DeleteFramebuffers);
288 GET_PROC(RenderbufferStorage);
289 GET_PROC(GenRenderbuffers);
290 GET_PROC(DeleteRenderbuffers);
291 GET_PROC(FramebufferRenderbuffer);
292 GET_PROC(BindRenderbuffer);
293 GET_PROC(RenderbufferStorageMultisample);
294 GET_PROC(BlitFramebuffer);
295 } else if (extensions.has("GL_EXT_framebuffer_object")) {
296 GET_PROC_SUFFIX(GenerateMipmap, EXT);
297 GET_PROC_SUFFIX(GenFramebuffers, EXT);
298 GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
299 GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
300 GET_PROC_SUFFIX(BindFramebuffer, EXT);
301 GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
302 GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
303 GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
304 GET_PROC_SUFFIX(RenderbufferStorage, EXT);
305 GET_PROC_SUFFIX(GenRenderbuffers, EXT);
306 GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
307 GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
308 GET_PROC_SUFFIX(BindRenderbuffer, EXT);
309 if (extensions.has("GL_EXT_framebuffer_multisample")) {
310 GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
311 }
312 if (extensions.has("GL_EXT_framebuffer_blit")) {
313 GET_PROC_SUFFIX(BlitFramebuffer, EXT);
314 }
315 } else {
316 // we must have FBOs
317 return nullptr;
318 }
319
320 if (extensions.has("GL_NV_path_rendering")) {
321 GET_PROC_SUFFIX(MatrixLoadf, EXT);
322 GET_PROC_SUFFIX(MatrixLoadIdentity, EXT);
323 GET_PROC_SUFFIX(PathCommands, NV);
324 GET_PROC_SUFFIX(PathParameteri, NV);
325 GET_PROC_SUFFIX(PathParameterf, NV);
326 GET_PROC_SUFFIX(GenPaths, NV);
327 GET_PROC_SUFFIX(DeletePaths, NV);
328 GET_PROC_SUFFIX(IsPath, NV);
329 GET_PROC_SUFFIX(PathStencilFunc, NV);
330 GET_PROC_SUFFIX(StencilFillPath, NV);
331 GET_PROC_SUFFIX(StencilStrokePath, NV);
332 GET_PROC_SUFFIX(StencilFillPathInstanced, NV);
333 GET_PROC_SUFFIX(StencilStrokePathInstanced, NV);
334 GET_PROC_SUFFIX(CoverFillPath, NV);
335 GET_PROC_SUFFIX(CoverStrokePath, NV);
336 GET_PROC_SUFFIX(CoverFillPathInstanced, NV);
337 GET_PROC_SUFFIX(CoverStrokePathInstanced, NV);
338 GET_PROC_SUFFIX(StencilThenCoverFillPath, NV);
339 GET_PROC_SUFFIX(StencilThenCoverStrokePath, NV);
340 GET_PROC_SUFFIX(StencilThenCoverFillPathInstanced, NV);
341 GET_PROC_SUFFIX(StencilThenCoverStrokePathInstanced, NV);
342 GET_PROC_SUFFIX(ProgramPathFragmentInputGen, NV);
343 }
344
345 if (extensions.has("GL_NV_framebuffer_mixed_samples")) {
346 GET_PROC_SUFFIX(CoverageModulation, NV);
347 }
348
349 if (extensions.has("GL_EXT_debug_marker")) {
350 GET_PROC_SUFFIX(InsertEventMarker, EXT);
351 GET_PROC_SUFFIX(PushGroupMarker, EXT);
352 GET_PROC_SUFFIX(PopGroupMarker, EXT);
353 }
354
355 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_invalidate_subdata")) {
356 GET_PROC(InvalidateBufferData);
357 GET_PROC(InvalidateBufferSubData);
358 GET_PROC(InvalidateFramebuffer);
359 GET_PROC(InvalidateSubFramebuffer);
360 GET_PROC(InvalidateTexImage);
361 GET_PROC(InvalidateTexSubImage);
362 }
363
364 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_program_interface_query")) {
365 GET_PROC(GetProgramResourceLocation);
366 }
367
368 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_KHR_debug")) {
369 // KHR_debug defines these methods to have no suffix in an OpenGL (not ES) context.
370 GET_PROC(DebugMessageControl);
371 GET_PROC(DebugMessageInsert);
372 GET_PROC(DebugMessageCallback);
373 GET_PROC(GetDebugMessageLog);
374 GET_PROC(PushDebugGroup);
375 GET_PROC(PopDebugGroup);
376 GET_PROC(ObjectLabel);
377 }
378
379 if (extensions.has("GL_EXT_window_rectangles")) {
380 GET_PROC_SUFFIX(WindowRectangles, EXT);
381 }
382
383 if (extensions.has("EGL_KHR_image") || extensions.has("EGL_KHR_image_base")) {
384 GET_EGL_PROC_SUFFIX(CreateImage, KHR);
385 GET_EGL_PROC_SUFFIX(DestroyImage, KHR);
386 }
387
388 if (glVer >= GR_GL_VER(3, 2) || extensions.has("GL_ARB_sync")) {
389 GET_PROC(FenceSync);
390 GET_PROC(IsSync);
391 GET_PROC(ClientWaitSync);
392 GET_PROC(WaitSync);
393 GET_PROC(DeleteSync);
394 }
395
396 if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_internalformat_query")) {
397 GET_PROC(GetInternalformativ);
398 }
399
400 if (glVer >= GR_GL_VER(4, 1)) {
401 GET_PROC(GetProgramBinary);
402 GET_PROC(ProgramBinary);
403 GET_PROC(ProgramParameteri);
404 }
405
406 if (glVer >= GR_GL_VER(3,2) || extensions.has("GL_ARB_sampler_objects")) {
407 GET_PROC(BindSampler);
408 GET_PROC(DeleteSamplers);
409 GET_PROC(GenSamplers);
410 GET_PROC(SamplerParameteri);
411 GET_PROC(SamplerParameteriv);
412 }
413
414 interface->fStandard = kGL_GrGLStandard;
415 interface->fExtensions.swap(&extensions);
416
417 return std::move(interface);
418 }
419
GrGLMakeAssembledGLESInterface(void * ctx,GrGLGetProc get)420 sk_sp<const GrGLInterface> GrGLMakeAssembledGLESInterface(void *ctx, GrGLGetProc get) {
421 GET_PROC_LOCAL(GetString);
422 if (nullptr == GetString) {
423 return nullptr;
424 }
425
426 const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION));
427 GrGLVersion version = GrGLGetVersionFromString(verStr);
428
429 if (version < GR_GL_VER(2,0)) {
430 return nullptr;
431 }
432
433 GET_PROC_LOCAL(GetIntegerv);
434 GET_PROC_LOCAL(GetStringi);
435 GrEGLQueryStringFn* queryString;
436 GrEGLDisplay display;
437 get_egl_query_and_display(&queryString, &display, ctx, get);
438 GrGLExtensions extensions;
439 if (!extensions.init(kGLES_GrGLStandard, GetString, GetStringi, GetIntegerv, queryString,
440 display)) {
441 return nullptr;
442 }
443
444 sk_sp<GrGLInterface> interface(new GrGLInterface);
445 GrGLInterface::Functions* functions = &interface->fFunctions;
446
447 GET_PROC(ActiveTexture);
448 GET_PROC(AttachShader);
449 GET_PROC(BindAttribLocation);
450 GET_PROC(BindBuffer);
451 GET_PROC(BindTexture);
452
453 if (version >= GR_GL_VER(3,0)) {
454 GET_PROC(BindVertexArray);
455 GET_PROC(DeleteVertexArrays);
456 GET_PROC(GenVertexArrays);
457 } else if (extensions.has("GL_OES_vertex_array_object")) {
458 GET_PROC_SUFFIX(BindVertexArray, OES);
459 GET_PROC_SUFFIX(DeleteVertexArrays, OES);
460 GET_PROC_SUFFIX(GenVertexArrays, OES);
461 }
462
463 if (version >= GR_GL_VER(3,0) && extensions.has("GL_EXT_blend_func_extended")) {
464 GET_PROC_SUFFIX(BindFragDataLocation, EXT);
465 GET_PROC_SUFFIX(BindFragDataLocationIndexed, EXT);
466 }
467
468 if (extensions.has("GL_KHR_blend_equation_advanced")) {
469 GET_PROC_SUFFIX(BlendBarrier, KHR);
470 } else if (extensions.has("GL_NV_blend_equation_advanced")) {
471 GET_PROC_SUFFIX(BlendBarrier, NV);
472 }
473
474 GET_PROC(BlendColor);
475 GET_PROC(BlendEquation);
476 GET_PROC(BlendFunc);
477 GET_PROC(BufferData);
478 GET_PROC(BufferSubData);
479 GET_PROC(Clear);
480 GET_PROC(ClearColor);
481 GET_PROC(ClearStencil);
482 if (extensions.has("GL_EXT_clear_texture")) {
483 GET_PROC_SUFFIX(ClearTexImage, EXT);
484 GET_PROC_SUFFIX(ClearTexSubImage, EXT);
485 }
486 GET_PROC(ColorMask);
487 GET_PROC(CompileShader);
488 GET_PROC(CompressedTexImage2D);
489 GET_PROC(CompressedTexSubImage2D);
490 GET_PROC(CopyTexSubImage2D);
491 GET_PROC(CreateProgram);
492 GET_PROC(CreateShader);
493 GET_PROC(CullFace);
494 GET_PROC(DeleteBuffers);
495 GET_PROC(DeleteProgram);
496 GET_PROC(DeleteShader);
497 GET_PROC(DeleteTextures);
498 GET_PROC(DepthMask);
499 GET_PROC(Disable);
500 GET_PROC(DisableVertexAttribArray);
501 GET_PROC(DrawArrays);
502
503 if (version >= GR_GL_VER(3,0)) {
504 GET_PROC(DrawArraysInstanced);
505 GET_PROC(DrawBuffers);
506 GET_PROC(DrawElementsInstanced);
507 } else if (extensions.has("GL_EXT_draw_instanced")) {
508 GET_PROC_SUFFIX(DrawArraysInstanced, EXT);
509 GET_PROC_SUFFIX(DrawElementsInstanced, EXT);
510 }
511
512 if (version >= GR_GL_VER(3,1)) {
513 GET_PROC(DrawArraysIndirect);
514 GET_PROC(DrawElementsIndirect);
515 }
516
517 GET_PROC(DrawElements);
518 if (version >= GR_GL_VER(3,0)) {
519 GET_PROC(DrawRangeElements);
520 }
521 GET_PROC(Enable);
522 GET_PROC(EnableVertexAttribArray);
523 GET_PROC(Finish);
524 GET_PROC(Flush);
525 GET_PROC(FrontFace);
526 GET_PROC(GenBuffers);
527 GET_PROC(GenerateMipmap);
528 GET_PROC(GenTextures);
529 GET_PROC(GetBufferParameteriv);
530 GET_PROC(GetError);
531 GET_PROC(GetIntegerv);
532
533 if (version >= GR_GL_VER(3,1)) {
534 GET_PROC(GetMultisamplefv);
535 }
536
537 GET_PROC(GetProgramInfoLog);
538 GET_PROC(GetProgramiv);
539 GET_PROC(GetShaderInfoLog);
540 GET_PROC(GetShaderPrecisionFormat);
541 GET_PROC(GetShaderiv);
542 GET_PROC(GetString);
543 GET_PROC(GetStringi);
544 if (version >= GR_GL_VER(3,1)) {
545 GET_PROC(GetTexLevelParameteriv);
546 }
547 GET_PROC(GetUniformLocation);
548 GET_PROC(IsTexture);
549 GET_PROC(LineWidth);
550 GET_PROC(LinkProgram);
551
552 if (extensions.has("GL_EXT_multi_draw_indirect")) {
553 GET_PROC_SUFFIX(MultiDrawArraysIndirect, EXT);
554 GET_PROC_SUFFIX(MultiDrawElementsIndirect, EXT);
555 }
556
557 GET_PROC(PixelStorei);
558
559 if (version >= GR_GL_VER(3,0)) {
560 GET_PROC(ReadBuffer);
561 }
562 GET_PROC(ReadPixels);
563 GET_PROC(Scissor);
564 GET_PROC(ShaderSource);
565 GET_PROC(StencilFunc);
566 GET_PROC(StencilFuncSeparate);
567 GET_PROC(StencilMask);
568 GET_PROC(StencilMaskSeparate);
569 GET_PROC(StencilOp);
570 GET_PROC(StencilOpSeparate);
571
572 if (version >= GR_GL_VER(3,2)) {
573 GET_PROC(TexBuffer);
574 GET_PROC(TexBufferRange);
575 } else if (extensions.has("GL_OES_texture_buffer")) {
576 GET_PROC_SUFFIX(TexBuffer, OES);
577 GET_PROC_SUFFIX(TexBufferRange, OES);
578 } else if (extensions.has("GL_EXT_texture_buffer")) {
579 GET_PROC_SUFFIX(TexBuffer, EXT);
580 GET_PROC_SUFFIX(TexBufferRange, EXT);
581 }
582
583 GET_PROC(TexImage2D);
584 GET_PROC(TexParameterf);
585 GET_PROC(TexParameterfv);
586 GET_PROC(TexParameteri);
587 GET_PROC(TexParameteriv);
588 GET_PROC(TexSubImage2D);
589
590 if (version >= GR_GL_VER(3,0)) {
591 GET_PROC(TexStorage2D);
592 } else {
593 GET_PROC_SUFFIX(TexStorage2D, EXT);
594 }
595
596 if (extensions.has("GL_NV_texture_barrier")) {
597 GET_PROC_SUFFIX(TextureBarrier, NV);
598 }
599
600 GET_PROC_SUFFIX(DiscardFramebuffer, EXT);
601 GET_PROC(Uniform1f);
602 GET_PROC(Uniform1i);
603 GET_PROC(Uniform1fv);
604 GET_PROC(Uniform1iv);
605 GET_PROC(Uniform2f);
606 GET_PROC(Uniform2i);
607 GET_PROC(Uniform2fv);
608 GET_PROC(Uniform2iv);
609 GET_PROC(Uniform3f);
610 GET_PROC(Uniform3i);
611 GET_PROC(Uniform3fv);
612 GET_PROC(Uniform3iv);
613 GET_PROC(Uniform4f);
614 GET_PROC(Uniform4i);
615 GET_PROC(Uniform4fv);
616 GET_PROC(Uniform4iv);
617 GET_PROC(UniformMatrix2fv);
618 GET_PROC(UniformMatrix3fv);
619 GET_PROC(UniformMatrix4fv);
620 GET_PROC(UseProgram);
621 GET_PROC(VertexAttrib1f);
622 GET_PROC(VertexAttrib2fv);
623 GET_PROC(VertexAttrib3fv);
624 GET_PROC(VertexAttrib4fv);
625
626 if (version >= GR_GL_VER(3,0)) {
627 GET_PROC(VertexAttribDivisor);
628 } else if (extensions.has("GL_EXT_instanced_arrays")) {
629 GET_PROC_SUFFIX(VertexAttribDivisor, EXT);
630 }
631
632 if (version >= GR_GL_VER(3,0)) {
633 GET_PROC(VertexAttribIPointer);
634 }
635
636 GET_PROC(VertexAttribPointer);
637 GET_PROC(Viewport);
638 GET_PROC(BindFramebuffer);
639 GET_PROC(BindRenderbuffer);
640 GET_PROC(CheckFramebufferStatus);
641 GET_PROC(DeleteFramebuffers);
642 GET_PROC(DeleteRenderbuffers);
643 GET_PROC(FramebufferRenderbuffer);
644 GET_PROC(FramebufferTexture2D);
645
646 if (version >= GR_GL_VER(3,0)) {
647 GET_PROC(RenderbufferStorageMultisample);
648 GET_PROC(BlitFramebuffer);
649 } else if (extensions.has("GL_CHROMIUM_framebuffer_multisample")) {
650 GET_PROC_SUFFIX(RenderbufferStorageMultisample, CHROMIUM);
651 GET_PROC_SUFFIX(BlitFramebuffer, CHROMIUM);
652 } else {
653 if (extensions.has("GL_ANGLE_framebuffer_multisample")) {
654 GET_PROC_SUFFIX(RenderbufferStorageMultisample, ANGLE);
655 }
656 if (extensions.has("GL_ANGLE_framebuffer_blit")) {
657 GET_PROC_SUFFIX(BlitFramebuffer, ANGLE);
658 }
659 }
660
661 if (extensions.has("GL_CHROMIUM_map_sub")) {
662 GET_PROC_SUFFIX(MapBufferSubData, CHROMIUM);
663 GET_PROC_SUFFIX(MapTexSubImage2D, CHROMIUM);
664 GET_PROC_SUFFIX(UnmapBufferSubData, CHROMIUM);
665 GET_PROC_SUFFIX(UnmapTexSubImage2D, CHROMIUM);
666 }
667
668 if (extensions.has("GL_EXT_multisampled_render_to_texture")) {
669 GET_PROC_SUFFIX(FramebufferTexture2DMultisample, EXT);
670 functions->fRenderbufferStorageMultisampleES2EXT =
671 (GrGLRenderbufferStorageMultisampleFn*)get(ctx,
672 "glRenderbufferStorageMultisampleEXT");
673 } else if (extensions.has("GL_IMG_multisampled_render_to_texture")) {
674 GET_PROC_SUFFIX(FramebufferTexture2DMultisample, IMG);
675 functions->fRenderbufferStorageMultisampleES2EXT =
676 (GrGLRenderbufferStorageMultisampleFn*)get(ctx,
677 "glRenderbufferStorageMultisampleIMG");
678 } else if (extensions.has("GL_APPLE_framebuffer_multisample")) {
679 functions->fRenderbufferStorageMultisampleES2APPLE =
680 (GrGLRenderbufferStorageMultisampleFn*)get(ctx,
681 "glRenderbufferStorageMultisampleAPPLE");
682 GET_PROC_SUFFIX(ResolveMultisampleFramebuffer, APPLE);
683 }
684
685 GET_PROC(GenFramebuffers);
686 GET_PROC(GenRenderbuffers);
687 GET_PROC(GetFramebufferAttachmentParameteriv);
688 GET_PROC(GetRenderbufferParameteriv);
689 GET_PROC(RenderbufferStorage);
690
691 // There are several APIs for buffer mapping:
692 // ES2 + GL_OES_mapbuffer: MapBufferOES and UnmapBufferOES
693 // ES2 + GL_EXT_map_buffer_range: Adds MapBufferRangeEXT and FlushMappedBufferRangeEXT
694 // ES3: MapBufferRange, FlushMappedBufferRange, and UnmapBuffer are core (so no suffix).
695 //
696 // MapBuffer is not part of ES3, but implementations may still report the OES versions of
697 // MapBuffer and UnmapBuffer, per the older GL_OES_mapbuffer extension. Some implementations
698 // let us mix the newer MapBufferRange with the older UnmapBufferOES, but we've hit others that
699 // don't permit it. Note that in GrGLBuffer, we choose which API to use based on version and
700 // extensions. This code is written so that we never mix OES and non-OES functions.
701 GET_PROC_SUFFIX(MapBuffer, OES);
702 if (version >= GR_GL_VER(3, 0)) {
703 GET_PROC(UnmapBuffer);
704 } else {
705 GET_PROC_SUFFIX(UnmapBuffer, OES);
706 }
707
708 if (version >= GR_GL_VER(3,0)) {
709 GET_PROC(MapBufferRange);
710 GET_PROC(FlushMappedBufferRange);
711 } else if (extensions.has("GL_EXT_map_buffer_range")) {
712 GET_PROC_SUFFIX(MapBufferRange, EXT);
713 GET_PROC_SUFFIX(FlushMappedBufferRange, EXT);
714 }
715
716 if (extensions.has("GL_EXT_debug_marker")) {
717 GET_PROC_SUFFIX(InsertEventMarker, EXT);
718 GET_PROC_SUFFIX(PushGroupMarker, EXT);
719 GET_PROC_SUFFIX(PopGroupMarker, EXT);
720 }
721
722 GET_PROC(InvalidateFramebuffer);
723 GET_PROC(InvalidateSubFramebuffer);
724 GET_PROC(InvalidateBufferData);
725 GET_PROC(InvalidateBufferSubData);
726 GET_PROC(InvalidateTexImage);
727 GET_PROC(InvalidateTexSubImage);
728
729 if (version >= GR_GL_VER(3,1)) {
730 GET_PROC(GetProgramResourceLocation);
731 }
732
733 if (extensions.has("GL_NV_path_rendering")) {
734 GET_PROC_SUFFIX(MatrixLoadf, EXT);
735 GET_PROC_SUFFIX(MatrixLoadIdentity, EXT);
736 GET_PROC_SUFFIX(PathCommands, NV);
737 GET_PROC_SUFFIX(PathParameteri, NV);
738 GET_PROC_SUFFIX(PathParameterf, NV);
739 GET_PROC_SUFFIX(GenPaths, NV);
740 GET_PROC_SUFFIX(DeletePaths, NV);
741 GET_PROC_SUFFIX(IsPath, NV);
742 GET_PROC_SUFFIX(PathStencilFunc, NV);
743 GET_PROC_SUFFIX(StencilFillPath, NV);
744 GET_PROC_SUFFIX(StencilStrokePath, NV);
745 GET_PROC_SUFFIX(StencilFillPathInstanced, NV);
746 GET_PROC_SUFFIX(StencilStrokePathInstanced, NV);
747 GET_PROC_SUFFIX(CoverFillPath, NV);
748 GET_PROC_SUFFIX(CoverStrokePath, NV);
749 GET_PROC_SUFFIX(CoverFillPathInstanced, NV);
750 GET_PROC_SUFFIX(CoverStrokePathInstanced, NV);
751 GET_PROC_SUFFIX(StencilThenCoverFillPath, NV);
752 GET_PROC_SUFFIX(StencilThenCoverStrokePath, NV);
753 GET_PROC_SUFFIX(StencilThenCoverFillPathInstanced, NV);
754 GET_PROC_SUFFIX(StencilThenCoverStrokePathInstanced, NV);
755 GET_PROC_SUFFIX(ProgramPathFragmentInputGen, NV);
756 }
757
758 if (extensions.has("GL_CHROMIUM_path_rendering")) {
759 GET_PROC_SUFFIX(MatrixLoadf, CHROMIUM);
760 GET_PROC_SUFFIX(MatrixLoadIdentity, CHROMIUM);
761 GET_PROC_SUFFIX(PathCommands, CHROMIUM);
762 GET_PROC_SUFFIX(PathParameteri, CHROMIUM);
763 GET_PROC_SUFFIX(PathParameterf, CHROMIUM);
764 GET_PROC_SUFFIX(GenPaths, CHROMIUM);
765 GET_PROC_SUFFIX(DeletePaths, CHROMIUM);
766 GET_PROC_SUFFIX(IsPath, CHROMIUM);
767 GET_PROC_SUFFIX(PathStencilFunc, CHROMIUM);
768 GET_PROC_SUFFIX(StencilFillPath, CHROMIUM);
769 GET_PROC_SUFFIX(StencilStrokePath, CHROMIUM);
770 GET_PROC_SUFFIX(StencilFillPathInstanced, CHROMIUM);
771 GET_PROC_SUFFIX(StencilStrokePathInstanced, CHROMIUM);
772 GET_PROC_SUFFIX(CoverFillPath, CHROMIUM);
773 GET_PROC_SUFFIX(CoverStrokePath, CHROMIUM);
774 GET_PROC_SUFFIX(CoverFillPathInstanced, CHROMIUM);
775 GET_PROC_SUFFIX(CoverStrokePathInstanced, CHROMIUM);
776 GET_PROC_SUFFIX(StencilThenCoverFillPath, CHROMIUM);
777 GET_PROC_SUFFIX(StencilThenCoverStrokePath, CHROMIUM);
778 GET_PROC_SUFFIX(StencilThenCoverFillPathInstanced, CHROMIUM);
779 GET_PROC_SUFFIX(StencilThenCoverStrokePathInstanced, CHROMIUM);
780 GET_PROC_SUFFIX(ProgramPathFragmentInputGen, CHROMIUM);
781 // GL_CHROMIUM_path_rendering additions:
782 GET_PROC_SUFFIX(BindFragmentInputLocation, CHROMIUM);
783 }
784
785 if (extensions.has("GL_NV_framebuffer_mixed_samples")) {
786 GET_PROC_SUFFIX(CoverageModulation, NV);
787 }
788 if (extensions.has("GL_CHROMIUM_framebuffer_mixed_samples")) {
789 GET_PROC_SUFFIX(CoverageModulation, CHROMIUM);
790 }
791
792 if (extensions.has("GL_KHR_debug")) {
793 GET_PROC_SUFFIX(DebugMessageControl, KHR);
794 GET_PROC_SUFFIX(DebugMessageInsert, KHR);
795 GET_PROC_SUFFIX(DebugMessageCallback, KHR);
796 GET_PROC_SUFFIX(GetDebugMessageLog, KHR);
797 GET_PROC_SUFFIX(PushDebugGroup, KHR);
798 GET_PROC_SUFFIX(PopDebugGroup, KHR);
799 GET_PROC_SUFFIX(ObjectLabel, KHR);
800 // In general we have a policy against removing extension strings when the driver does
801 // not provide function pointers for an advertised extension. However, because there is a
802 // known device that advertises GL_KHR_debug but fails to provide the functions and this is
803 // a debugging- only extension we've made an exception. This also can happen when using
804 // APITRACE.
805 if (!interface->fFunctions.fDebugMessageControl) {
806 extensions.remove("GL_KHR_debug");
807 }
808 }
809
810 if (extensions.has("GL_CHROMIUM_bind_uniform_location")) {
811 GET_PROC_SUFFIX(BindUniformLocation, CHROMIUM);
812 }
813
814 if (extensions.has("GL_EXT_window_rectangles")) {
815 GET_PROC_SUFFIX(WindowRectangles, EXT);
816 }
817
818 if (extensions.has("EGL_KHR_image") || extensions.has("EGL_KHR_image_base")) {
819 GET_EGL_PROC_SUFFIX(CreateImage, KHR);
820 GET_EGL_PROC_SUFFIX(DestroyImage, KHR);
821 }
822
823 if (version >= GR_GL_VER(3, 0)) {
824 GET_PROC(FenceSync);
825 GET_PROC(IsSync);
826 GET_PROC(ClientWaitSync);
827 GET_PROC(WaitSync);
828 GET_PROC(DeleteSync);
829 } else if (extensions.has("GL_APPLE_sync")) {
830 GET_PROC_SUFFIX(FenceSync, APPLE);
831 GET_PROC_SUFFIX(IsSync, APPLE);
832 GET_PROC_SUFFIX(ClientWaitSync, APPLE);
833 GET_PROC_SUFFIX(WaitSync, APPLE);
834 GET_PROC_SUFFIX(DeleteSync, APPLE);
835 }
836
837 if (version >= GR_GL_VER(3,0)) {
838 GET_PROC(GetInternalformativ);
839 }
840
841 if (version >= GR_GL_VER(3, 0)) {
842 GET_PROC(GetProgramBinary);
843 GET_PROC(ProgramBinary);
844 GET_PROC(ProgramParameteri);
845 }
846
847 if (version >= GR_GL_VER(3,0)) {
848 GET_PROC(BindSampler);
849 GET_PROC(DeleteSamplers);
850 GET_PROC(GenSamplers);
851 GET_PROC(SamplerParameteri);
852 GET_PROC(SamplerParameteriv);
853 }
854
855 interface->fStandard = kGLES_GrGLStandard;
856 interface->fExtensions.swap(&extensions);
857
858 return std::move(interface);
859 }
860
GrGLAssembleInterface(void * ctx,GrGLGetProc get)861 SK_API const GrGLInterface* GrGLAssembleInterface(void *ctx, GrGLGetProc get) {
862 return GrGLMakeAssembledInterface(ctx, get).release();
863 }
864