blob: 1fe53ebc3edcee04b6ba2bd69c74037cbd431ac6 [file] [log] [blame]
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +00001
2/*
3 * Copyright 2014 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#include "GrGLAssembleInterface.h"
11#include "GrGLUtil.h"
12
13#define GET_PROC(F) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F)
14#define GET_PROC_SUFFIX(F, S) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F #S)
15#define GET_PROC_LOCAL(F) GrGL ## F ## Proc F = (GrGL ## F ## Proc) get(ctx, "gl" #F)
16
bsalomona721c812014-08-26 11:35:23 -070017const GrGLInterface* GrGLAssembleInterface(void* ctx, GrGLGetProc get) {
18 GET_PROC_LOCAL(GetString);
19 if (NULL == GetString) {
20 return NULL;
21 }
22
23 const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION));
24 if (NULL == verStr) {
25 return NULL;
26 }
27
28 GrGLStandard standard = GrGLGetStandardInUseFromString(verStr);
29
30 if (kGLES_GrGLStandard == standard) {
31 return GrGLAssembleGLESInterface(ctx, get);
32 } else if (kGL_GrGLStandard == standard) {
33 return GrGLAssembleGLInterface(ctx, get);
34 }
35 return NULL;
36}
37
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +000038const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) {
39 GET_PROC_LOCAL(GetString);
40 GET_PROC_LOCAL(GetStringi);
41 GET_PROC_LOCAL(GetIntegerv);
42
43 // GetStringi may be NULL depending on the GL version.
44 if (NULL == GetString || NULL == GetIntegerv) {
45 return NULL;
46 }
47
48 const char* versionString = (const char*) GetString(GR_GL_VERSION);
49 GrGLVersion glVer = GrGLGetVersionFromString(versionString);
50
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +000051 if (glVer < GR_GL_VER(1,5) || GR_GL_INVALID_VER == glVer) {
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +000052 // We must have array and element_array buffer objects.
53 return NULL;
54 }
55
56 GrGLExtensions extensions;
57 if (!extensions.init(kGL_GrGLStandard, GetString, GetStringi, GetIntegerv)) {
58 return NULL;
59 }
60
61 GrGLInterface* interface = SkNEW(GrGLInterface());
62 GrGLInterface::Functions* functions = &interface->fFunctions;
63
64 GET_PROC(ActiveTexture);
65 GET_PROC(AttachShader);
66 GET_PROC(BindAttribLocation);
67 GET_PROC(BindBuffer);
68 if (glVer >= GR_GL_VER(3,0)) {
69 GET_PROC(BindFragDataLocation);
70 }
71 GET_PROC(BeginQuery);
72 GET_PROC(BindTexture);
tomhudson2575f312015-04-21 14:16:53 -070073
cdaltonbae6f6c2015-04-22 10:39:03 -070074 if (extensions.has("GL_KHR_blend_equation_advanced")) {
75 GET_PROC_SUFFIX(BlendBarrier, KHR);
76 } else if (extensions.has("GL_NV_blend_equation_advanced")) {
77 GET_PROC_SUFFIX(BlendBarrier, NV);
tomhudson2575f312015-04-21 14:16:53 -070078 }
79
cdaltonbae6f6c2015-04-22 10:39:03 -070080 if (glVer >= GR_GL_VER(1,4) ||
81 extensions.has("GL_ARB_imaging")) {
82 GET_PROC(BlendColor);
83 } else if (extensions.has("GL_EXT_blend_color")) {
84 GET_PROC_SUFFIX(BlendColor, EXT);
85 }
86
87 if (glVer >= GR_GL_VER(1,4) ||
88 extensions.has("GL_ARB_imaging")) {
89 GET_PROC(BlendEquation);
90 } else if (extensions.has("GL_EXT_blend_subtract")) {
91 GET_PROC_SUFFIX(BlendEquation, EXT);
92 }
93
94 GET_PROC(BlendFunc);
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +000095 GET_PROC(BufferData);
96 GET_PROC(BufferSubData);
97 GET_PROC(Clear);
98 GET_PROC(ClearColor);
99 GET_PROC(ClearStencil);
100 GET_PROC(ColorMask);
101 GET_PROC(CompileShader);
102 GET_PROC(CompressedTexImage2D);
krajcevski37d20f72014-06-11 10:38:47 -0700103 GET_PROC(CompressedTexSubImage2D);
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000104 GET_PROC(CopyTexSubImage2D);
105 GET_PROC(CreateProgram);
106 GET_PROC(CreateShader);
107 GET_PROC(CullFace);
108 GET_PROC(DeleteBuffers);
109 GET_PROC(DeleteProgram);
110 GET_PROC(DeleteQueries);
111 GET_PROC(DeleteShader);
112 GET_PROC(DeleteTextures);
113 GET_PROC(DepthMask);
114 GET_PROC(Disable);
115 GET_PROC(DisableVertexAttribArray);
116 GET_PROC(DrawArrays);
117 GET_PROC(DrawBuffer);
118 GET_PROC(DrawBuffers);
119 GET_PROC(DrawElements);
120 GET_PROC(Enable);
121 GET_PROC(EnableVertexAttribArray);
122 GET_PROC(EndQuery);
123 GET_PROC(Finish);
124 GET_PROC(Flush);
125 GET_PROC(FrontFace);
126 GET_PROC(GenBuffers);
127 GET_PROC(GenerateMipmap);
128 GET_PROC(GetBufferParameteriv);
129 GET_PROC(GetError);
130 GET_PROC(GetIntegerv);
131 GET_PROC(GetQueryObjectiv);
132 GET_PROC(GetQueryObjectuiv);
133 if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) {
134 GET_PROC(GetQueryObjecti64v);
135 GET_PROC(GetQueryObjectui64v);
136 GET_PROC(QueryCounter);
137 } else if (extensions.has("GL_EXT_timer_query")) {
138 GET_PROC_SUFFIX(GetQueryObjecti64v, EXT);
139 GET_PROC_SUFFIX(GetQueryObjectui64v, EXT);
140 }
141 GET_PROC(GetQueryiv);
142 GET_PROC(GetProgramInfoLog);
143 GET_PROC(GetProgramiv);
144 GET_PROC(GetShaderInfoLog);
145 GET_PROC(GetShaderiv);
146 GET_PROC(GetString);
147 GET_PROC(GetStringi);
bsalomonee64d6e2014-12-03 10:46:08 -0800148 GET_PROC(GetShaderPrecisionFormat);
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000149 GET_PROC(GetTexLevelParameteriv);
150 GET_PROC(GenQueries);
151 GET_PROC(GenTextures);
152 GET_PROC(GetUniformLocation);
bsalomon6dc6f5f2015-06-18 09:12:16 -0700153 GET_PROC(IsTexture);
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000154 GET_PROC(LineWidth);
155 GET_PROC(LinkProgram);
156 GET_PROC(MapBuffer);
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000157 GET_PROC(PixelStorei);
cdalton0edea2c2015-05-21 08:27:44 -0700158 if (extensions.has("GL_EXT_raster_multisample")) {
159 GET_PROC_SUFFIX(RasterSamples, EXT);
160 }
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000161 GET_PROC(ReadBuffer);
162 GET_PROC(ReadPixels);
163 GET_PROC(Scissor);
164 GET_PROC(ShaderSource);
165 GET_PROC(StencilFunc);
166 GET_PROC(StencilFuncSeparate);
167 GET_PROC(StencilMask);
168 GET_PROC(StencilMaskSeparate);
169 GET_PROC(StencilOp);
170 GET_PROC(StencilOpSeparate);
171 GET_PROC(TexImage2D);
172 GET_PROC(TexParameteri);
173 GET_PROC(TexParameteriv);
174 if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) {
175 GET_PROC(TexStorage2D);
176 } else if (extensions.has("GL_EXT_texture_storage")) {
177 GET_PROC_SUFFIX(TexStorage2D, EXT);
178 }
179 GET_PROC(TexSubImage2D);
cdaltonfd4167d2015-04-21 11:45:56 -0700180 if (glVer >= GR_GL_VER(4,5) || extensions.has("GL_ARB_texture_barrier")) {
181 GET_PROC(TextureBarrier);
182 } else if (extensions.has("GL_NV_texture_barrier")) {
183 GET_PROC_SUFFIX(TextureBarrier, NV);
184 }
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000185 GET_PROC(Uniform1f);
186 GET_PROC(Uniform1i);
187 GET_PROC(Uniform1fv);
188 GET_PROC(Uniform1iv);
189 GET_PROC(Uniform2f);
190 GET_PROC(Uniform2i);
191 GET_PROC(Uniform2fv);
192 GET_PROC(Uniform2iv);
193 GET_PROC(Uniform3f);
194 GET_PROC(Uniform3i);
195 GET_PROC(Uniform3fv);
196 GET_PROC(Uniform3iv);
197 GET_PROC(Uniform4f);
198 GET_PROC(Uniform4i);
199 GET_PROC(Uniform4fv);
200 GET_PROC(Uniform4iv);
201 GET_PROC(UniformMatrix2fv);
202 GET_PROC(UniformMatrix3fv);
203 GET_PROC(UniformMatrix4fv);
204 GET_PROC(UnmapBuffer);
205 GET_PROC(UseProgram);
egdaniel27c15212014-10-24 15:00:50 -0700206 GET_PROC(VertexAttrib1f);
207 GET_PROC(VertexAttrib2fv);
208 GET_PROC(VertexAttrib3fv);
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000209 GET_PROC(VertexAttrib4fv);
210 GET_PROC(VertexAttribPointer);
211 GET_PROC(Viewport);
212 GET_PROC(BindFragDataLocationIndexed);
213
214 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object")) {
215 // no ARB suffix for GL_ARB_vertex_array_object
216 GET_PROC(BindVertexArray);
217 GET_PROC(GenVertexArrays);
218 GET_PROC(DeleteVertexArrays);
tomhudson612e9262014-11-24 11:22:36 -0800219 } else if (extensions.has("GL_APPLE_vertex_array_object")) {
220 GET_PROC_SUFFIX(BindVertexArray, APPLE);
221 GET_PROC_SUFFIX(GenVertexArrays, APPLE);
222 GET_PROC_SUFFIX(DeleteVertexArrays, APPLE);
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000223 }
224
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000225 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_map_buffer_range")) {
226 GET_PROC(MapBufferRange);
227 GET_PROC(FlushMappedBufferRange);
228 }
229
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000230 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
231 // GL_ARB_framebuffer_object doesn't use ARB suffix.)
232 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) {
233 GET_PROC(GenFramebuffers);
234 GET_PROC(GetFramebufferAttachmentParameteriv);
235 GET_PROC(GetRenderbufferParameteriv);
236 GET_PROC(BindFramebuffer);
237 GET_PROC(FramebufferTexture2D);
238 GET_PROC(CheckFramebufferStatus);
239 GET_PROC(DeleteFramebuffers);
240 GET_PROC(RenderbufferStorage);
241 GET_PROC(GenRenderbuffers);
242 GET_PROC(DeleteRenderbuffers);
243 GET_PROC(FramebufferRenderbuffer);
244 GET_PROC(BindRenderbuffer);
245 GET_PROC(RenderbufferStorageMultisample);
246 GET_PROC(BlitFramebuffer);
247 } else if (extensions.has("GL_EXT_framebuffer_object")) {
248 GET_PROC_SUFFIX(GenFramebuffers, EXT);
249 GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
250 GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
251 GET_PROC_SUFFIX(BindFramebuffer, EXT);
252 GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
253 GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
254 GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
255 GET_PROC_SUFFIX(RenderbufferStorage, EXT);
256 GET_PROC_SUFFIX(GenRenderbuffers, EXT);
257 GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
258 GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
259 GET_PROC_SUFFIX(BindRenderbuffer, EXT);
260 if (extensions.has("GL_EXT_framebuffer_multisample")) {
261 GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
262 }
263 if (extensions.has("GL_EXT_framebuffer_blit")) {
264 GET_PROC_SUFFIX(BlitFramebuffer, EXT);
265 }
266 } else {
267 // we must have FBOs
268 delete interface;
269 return NULL;
270 }
271
272 if (extensions.has("GL_NV_path_rendering")) {
cdalton626e1ff2015-06-12 13:56:46 -0700273 GET_PROC_SUFFIX(MatrixLoadf, EXT);
274 GET_PROC_SUFFIX(MatrixLoadIdentity, EXT);
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000275 GET_PROC_SUFFIX(PathCommands, NV);
jvanverth439f23e2015-06-30 09:40:38 -0700276 GET_PROC_SUFFIX(PathCoords, NV);
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000277 GET_PROC_SUFFIX(PathParameteri, NV);
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000278 GET_PROC_SUFFIX(PathParameterf, NV);
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000279 GET_PROC_SUFFIX(GenPaths, NV);
280 GET_PROC_SUFFIX(DeletePaths, NV);
cdalton8dd90cb2014-07-17 09:28:36 -0700281 GET_PROC_SUFFIX(IsPath, NV);
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000282 GET_PROC_SUFFIX(PathStencilFunc, NV);
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000283 GET_PROC_SUFFIX(StencilFillPath, NV);
284 GET_PROC_SUFFIX(StencilStrokePath, NV);
285 GET_PROC_SUFFIX(StencilFillPathInstanced, NV);
286 GET_PROC_SUFFIX(StencilStrokePathInstanced, NV);
jvanverth439f23e2015-06-30 09:40:38 -0700287 GET_PROC_SUFFIX(PathTexGen, NV);
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000288 GET_PROC_SUFFIX(CoverFillPath, NV);
289 GET_PROC_SUFFIX(CoverStrokePath, NV);
290 GET_PROC_SUFFIX(CoverFillPathInstanced, NV);
291 GET_PROC_SUFFIX(CoverStrokePathInstanced, NV);
jvanverth439f23e2015-06-30 09:40:38 -0700292 // NV_path_rendering v1.2 (These methods may not be present)
cdaltonc8f52042014-07-29 15:25:51 -0700293 GET_PROC_SUFFIX(StencilThenCoverFillPath, NV);
294 GET_PROC_SUFFIX(StencilThenCoverStrokePath, NV);
295 GET_PROC_SUFFIX(StencilThenCoverFillPathInstanced, NV);
296 GET_PROC_SUFFIX(StencilThenCoverStrokePathInstanced, NV);
jvanverth439f23e2015-06-30 09:40:38 -0700297 // NV_path_rendering v1.3 (These methods may not be present)
kkinnunen32b9a3b2014-07-02 22:56:35 -0700298 GET_PROC_SUFFIX(ProgramPathFragmentInputGen, NV);
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000299 }
300
vbuzinov08b4d292015-04-01 06:29:49 -0700301 if (extensions.has("GL_NV_framebuffer_mixed_samples")) {
302 GET_PROC_SUFFIX(CoverageModulation, NV);
303 }
304
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000305 if (extensions.has("GL_EXT_debug_marker")) {
306 GET_PROC_SUFFIX(InsertEventMarker, EXT);
307 GET_PROC_SUFFIX(PushGroupMarker, EXT);
308 GET_PROC_SUFFIX(PopGroupMarker, EXT);
309 }
310
311 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_invalidate_subdata")) {
312 GET_PROC(InvalidateBufferData);
313 GET_PROC(InvalidateBufferSubData);
314 GET_PROC(InvalidateFramebuffer);
315 GET_PROC(InvalidateSubFramebuffer);
316 GET_PROC(InvalidateTexImage);
317 GET_PROC(InvalidateTexSubImage);
318 }
319
kkinnunen32b9a3b2014-07-02 22:56:35 -0700320 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_program_interface_query")) {
321 GET_PROC(GetProgramResourceLocation);
322 }
323
cdalton626e1ff2015-06-12 13:56:46 -0700324 if (glVer >= GR_GL_VER(3,1) || extensions.has("GL_ARB_draw_instanced")) {
325 GET_PROC(DrawArraysInstanced);
326 GET_PROC(DrawElementsInstanced);
327 }
328
329 if (glVer >= GR_GL_VER(3,2) || extensions.has("GL_ARB_instanced_arrays")) {
330 GET_PROC(VertexAttribDivisor);
331 }
332
333 if (extensions.has("GL_NV_bindless_texture")) {
334 GET_PROC_SUFFIX(GetTextureHandle, NV);
335 GET_PROC_SUFFIX(GetTextureSamplerHandle, NV);
336 GET_PROC_SUFFIX(MakeTextureHandleResident, NV);
337 GET_PROC_SUFFIX(MakeTextureHandleNonResident, NV);
338 GET_PROC_SUFFIX(GetImageHandle, NV);
339 GET_PROC_SUFFIX(MakeImageHandleResident, NV);
340 GET_PROC_SUFFIX(MakeImageHandleNonResident, NV);
341 GET_PROC_SUFFIX(IsTextureHandleResident, NV);
342 GET_PROC_SUFFIX(IsImageHandleResident, NV);
343 GET_PROC_SUFFIX(UniformHandleui64, NV);
344 GET_PROC_SUFFIX(UniformHandleui64v, NV);
345 GET_PROC_SUFFIX(ProgramUniformHandleui64, NV);
346 GET_PROC_SUFFIX(ProgramUniformHandleui64v, NV);
347 }
348
349 if (extensions.has("GL_EXT_direct_state_access")) {
350 GET_PROC_SUFFIX(TextureParameteri, EXT);
351 GET_PROC_SUFFIX(TextureParameteriv, EXT);
352 GET_PROC_SUFFIX(TextureParameterf, EXT);
353 GET_PROC_SUFFIX(TextureParameterfv, EXT);
354 GET_PROC_SUFFIX(TextureImage1D, EXT);
355 GET_PROC_SUFFIX(TextureImage2D, EXT);
356 GET_PROC_SUFFIX(TextureSubImage1D, EXT);
357 GET_PROC_SUFFIX(TextureSubImage2D, EXT);
358 GET_PROC_SUFFIX(CopyTextureImage1D, EXT);
359 GET_PROC_SUFFIX(CopyTextureImage2D, EXT);
360 GET_PROC_SUFFIX(CopyTextureSubImage1D, EXT);
361 GET_PROC_SUFFIX(CopyTextureSubImage2D, EXT);
362 GET_PROC_SUFFIX(GetTextureImage, EXT);
363 GET_PROC_SUFFIX(GetTextureParameterfv, EXT);
364 GET_PROC_SUFFIX(GetTextureParameteriv, EXT);
365 GET_PROC_SUFFIX(GetTextureLevelParameterfv, EXT);
366 GET_PROC_SUFFIX(GetTextureLevelParameteriv, EXT);
367 if (glVer >= GR_GL_VER(1,2)) {
368 GET_PROC_SUFFIX(TextureImage3D, EXT);
369 GET_PROC_SUFFIX(TextureSubImage3D, EXT);
370 GET_PROC_SUFFIX(CopyTextureSubImage3D, EXT);
371 GET_PROC_SUFFIX(CompressedTextureImage3D, EXT);
372 GET_PROC_SUFFIX(CompressedTextureImage2D, EXT);
373 GET_PROC_SUFFIX(CompressedTextureImage1D, EXT);
374 GET_PROC_SUFFIX(CompressedTextureSubImage3D, EXT);
375 GET_PROC_SUFFIX(CompressedTextureSubImage2D, EXT);
376 GET_PROC_SUFFIX(CompressedTextureSubImage1D, EXT);
377 GET_PROC_SUFFIX(GetCompressedTextureImage, EXT);
378 }
379 if (glVer >= GR_GL_VER(1,5)) {
380 GET_PROC_SUFFIX(NamedBufferData, EXT);
381 GET_PROC_SUFFIX(NamedBufferSubData, EXT);
382 GET_PROC_SUFFIX(MapNamedBuffer, EXT);
383 GET_PROC_SUFFIX(UnmapNamedBuffer, EXT);
384 GET_PROC_SUFFIX(GetNamedBufferParameteriv, EXT);
385 GET_PROC_SUFFIX(GetNamedBufferPointerv, EXT);
386 GET_PROC_SUFFIX(GetNamedBufferSubData, EXT);
387 }
388 if (glVer >= GR_GL_VER(2,0)) {
389 GET_PROC_SUFFIX(ProgramUniform1f, EXT);
390 GET_PROC_SUFFIX(ProgramUniform2f, EXT);
391 GET_PROC_SUFFIX(ProgramUniform3f, EXT);
392 GET_PROC_SUFFIX(ProgramUniform4f, EXT);
393 GET_PROC_SUFFIX(ProgramUniform1i, EXT);
394 GET_PROC_SUFFIX(ProgramUniform2i, EXT);
395 GET_PROC_SUFFIX(ProgramUniform3i, EXT);
396 GET_PROC_SUFFIX(ProgramUniform4i, EXT);
397 GET_PROC_SUFFIX(ProgramUniform1fv, EXT);
398 GET_PROC_SUFFIX(ProgramUniform2fv, EXT);
399 GET_PROC_SUFFIX(ProgramUniform3fv, EXT);
400 GET_PROC_SUFFIX(ProgramUniform4fv, EXT);
401 GET_PROC_SUFFIX(ProgramUniform1iv, EXT);
402 GET_PROC_SUFFIX(ProgramUniform2iv, EXT);
403 GET_PROC_SUFFIX(ProgramUniform3iv, EXT);
404 GET_PROC_SUFFIX(ProgramUniform4iv, EXT);
405 GET_PROC_SUFFIX(ProgramUniformMatrix2fv, EXT);
406 GET_PROC_SUFFIX(ProgramUniformMatrix3fv, EXT);
407 GET_PROC_SUFFIX(ProgramUniformMatrix4fv, EXT);
408 }
409 if (glVer >= GR_GL_VER(2,1)) {
410 GET_PROC_SUFFIX(ProgramUniformMatrix2x3fv, EXT);
411 GET_PROC_SUFFIX(ProgramUniformMatrix3x2fv, EXT);
412 GET_PROC_SUFFIX(ProgramUniformMatrix2x4fv, EXT);
413 GET_PROC_SUFFIX(ProgramUniformMatrix4x2fv, EXT);
414 GET_PROC_SUFFIX(ProgramUniformMatrix3x4fv, EXT);
415 GET_PROC_SUFFIX(ProgramUniformMatrix4x3fv, EXT);
416 }
417 if (glVer >= GR_GL_VER(3,0)) {
418 GET_PROC_SUFFIX(NamedRenderbufferStorage, EXT);
419 GET_PROC_SUFFIX(GetNamedRenderbufferParameteriv, EXT);
420 GET_PROC_SUFFIX(NamedRenderbufferStorageMultisample, EXT);
421 GET_PROC_SUFFIX(CheckNamedFramebufferStatus, EXT);
422 GET_PROC_SUFFIX(NamedFramebufferTexture1D, EXT);
423 GET_PROC_SUFFIX(NamedFramebufferTexture2D, EXT);
424 GET_PROC_SUFFIX(NamedFramebufferTexture3D, EXT);
425 GET_PROC_SUFFIX(NamedFramebufferRenderbuffer, EXT);
426 GET_PROC_SUFFIX(GetNamedFramebufferAttachmentParameteriv, EXT);
427 GET_PROC_SUFFIX(GenerateTextureMipmap, EXT);
428 GET_PROC_SUFFIX(FramebufferDrawBuffer, EXT);
429 GET_PROC_SUFFIX(FramebufferDrawBuffers, EXT);
430 GET_PROC_SUFFIX(FramebufferReadBuffer, EXT);
431 GET_PROC_SUFFIX(GetFramebufferParameteriv, EXT);
432 GET_PROC_SUFFIX(NamedCopyBufferSubData, EXT);
433 GET_PROC_SUFFIX(VertexArrayVertexOffset, EXT);
434 GET_PROC_SUFFIX(VertexArrayColorOffset, EXT);
435 GET_PROC_SUFFIX(VertexArrayEdgeFlagOffset, EXT);
436 GET_PROC_SUFFIX(VertexArrayIndexOffset, EXT);
437 GET_PROC_SUFFIX(VertexArrayNormalOffset, EXT);
438 GET_PROC_SUFFIX(VertexArrayTexCoordOffset, EXT);
439 GET_PROC_SUFFIX(VertexArrayMultiTexCoordOffset, EXT);
440 GET_PROC_SUFFIX(VertexArrayFogCoordOffset, EXT);
441 GET_PROC_SUFFIX(VertexArraySecondaryColorOffset, EXT);
442 GET_PROC_SUFFIX(VertexArrayVertexAttribOffset, EXT);
443 GET_PROC_SUFFIX(VertexArrayVertexAttribIOffset, EXT);
444 GET_PROC_SUFFIX(EnableVertexArray, EXT);
445 GET_PROC_SUFFIX(DisableVertexArray, EXT);
446 GET_PROC_SUFFIX(EnableVertexArrayAttrib, EXT);
447 GET_PROC_SUFFIX(DisableVertexArrayAttrib, EXT);
448 GET_PROC_SUFFIX(GetVertexArrayIntegerv, EXT);
449 GET_PROC_SUFFIX(GetVertexArrayPointerv, EXT);
450 GET_PROC_SUFFIX(GetVertexArrayIntegeri_v, EXT);
451 GET_PROC_SUFFIX(GetVertexArrayPointeri_v, EXT);
452 GET_PROC_SUFFIX(MapNamedBufferRange, EXT);
453 GET_PROC_SUFFIX(FlushMappedNamedBufferRange, EXT);
454 }
455 }
456
457 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_KHR_debug")) {
458 // KHR_debug defines these methods to have no suffix in an OpenGL (not ES) context.
459 GET_PROC(DebugMessageControl);
460 GET_PROC(DebugMessageInsert);
461 GET_PROC(DebugMessageCallback);
462 GET_PROC(GetDebugMessageLog);
463 GET_PROC(PushDebugGroup);
464 GET_PROC(PopDebugGroup);
465 GET_PROC(ObjectLabel);
466 }
467
commit-bot@chromium.org9add5dc2014-04-29 20:06:22 +0000468 interface->fStandard = kGL_GrGLStandard;
469 interface->fExtensions.swap(&extensions);
470
471 return interface;
472}
bsalomona721c812014-08-26 11:35:23 -0700473
474const GrGLInterface* GrGLAssembleGLESInterface(void* ctx, GrGLGetProc get) {
475 GET_PROC_LOCAL(GetString);
476 if (NULL == GetString) {
477 return NULL;
478 }
479
480 const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION));
481 GrGLVersion version = GrGLGetVersionFromString(verStr);
482
483 if (version < GR_GL_VER(2,0)) {
484 return NULL;
485 }
486
487 GET_PROC_LOCAL(GetIntegerv);
488 GET_PROC_LOCAL(GetStringi);
489 GrGLExtensions extensions;
490 if (!extensions.init(kGLES_GrGLStandard, GetString, GetStringi, GetIntegerv)) {
491 return NULL;
492 }
493
494 GrGLInterface* interface = SkNEW(GrGLInterface);
495 GrGLInterface::Functions* functions = &interface->fFunctions;
496
497 GET_PROC(ActiveTexture);
498 GET_PROC(AttachShader);
499 GET_PROC(BindAttribLocation);
500 GET_PROC(BindBuffer);
501 GET_PROC(BindTexture);
502 GET_PROC_SUFFIX(BindVertexArray, OES);
cdaltonbae6f6c2015-04-22 10:39:03 -0700503
504 if (extensions.has("GL_KHR_blend_equation_advanced")) {
505 GET_PROC_SUFFIX(BlendBarrier, KHR);
506 } else if (extensions.has("GL_NV_blend_equation_advanced")) {
507 GET_PROC_SUFFIX(BlendBarrier, NV);
508 }
509
bsalomona721c812014-08-26 11:35:23 -0700510 GET_PROC(BlendColor);
cdaltonbae6f6c2015-04-22 10:39:03 -0700511 GET_PROC(BlendEquation);
bsalomona721c812014-08-26 11:35:23 -0700512 GET_PROC(BlendFunc);
513 GET_PROC(BufferData);
514 GET_PROC(BufferSubData);
515 GET_PROC(Clear);
516 GET_PROC(ClearColor);
517 GET_PROC(ClearStencil);
518 GET_PROC(ColorMask);
519 GET_PROC(CompileShader);
520 GET_PROC(CompressedTexImage2D);
521 GET_PROC(CompressedTexSubImage2D);
522 GET_PROC(CopyTexSubImage2D);
523 GET_PROC(CreateProgram);
524 GET_PROC(CreateShader);
525 GET_PROC(CullFace);
526 GET_PROC(DeleteBuffers);
527 GET_PROC(DeleteProgram);
528 GET_PROC(DeleteShader);
529 GET_PROC(DeleteTextures);
530 GET_PROC_SUFFIX(DeleteVertexArrays, OES);
531 GET_PROC(DepthMask);
532 GET_PROC(Disable);
533 GET_PROC(DisableVertexAttribArray);
534 GET_PROC(DrawArrays);
535 GET_PROC(DrawElements);
536 GET_PROC(Enable);
537 GET_PROC(EnableVertexAttribArray);
538 GET_PROC(Finish);
539 GET_PROC(Flush);
540 GET_PROC(FrontFace);
541 GET_PROC(GenBuffers);
542 GET_PROC(GenerateMipmap);
543 GET_PROC(GenTextures);
544 GET_PROC_SUFFIX(GenVertexArrays, OES);
545 GET_PROC(GetBufferParameteriv);
546 GET_PROC(GetError);
547 GET_PROC(GetIntegerv);
548 GET_PROC(GetProgramInfoLog);
549 GET_PROC(GetProgramiv);
550 GET_PROC(GetShaderInfoLog);
bsalomonee64d6e2014-12-03 10:46:08 -0800551 GET_PROC(GetShaderPrecisionFormat);
bsalomona721c812014-08-26 11:35:23 -0700552 GET_PROC(GetShaderiv);
553 GET_PROC(GetString);
554 GET_PROC(GetStringi);
555 GET_PROC(GetUniformLocation);
bsalomon6dc6f5f2015-06-18 09:12:16 -0700556 GET_PROC(IsTexture);
bsalomona721c812014-08-26 11:35:23 -0700557 GET_PROC(LineWidth);
558 GET_PROC(LinkProgram);
559 GET_PROC(PixelStorei);
cdalton0edea2c2015-05-21 08:27:44 -0700560
561 if (extensions.has("GL_EXT_raster_multisample")) {
562 GET_PROC_SUFFIX(RasterSamples, EXT);
563 }
564
bsalomona721c812014-08-26 11:35:23 -0700565 GET_PROC(ReadPixels);
566 GET_PROC(Scissor);
567 GET_PROC(ShaderSource);
568 GET_PROC(StencilFunc);
569 GET_PROC(StencilFuncSeparate);
570 GET_PROC(StencilMask);
571 GET_PROC(StencilMaskSeparate);
572 GET_PROC(StencilOp);
573 GET_PROC(StencilOpSeparate);
574 GET_PROC(TexImage2D);
575 GET_PROC(TexParameteri);
576 GET_PROC(TexParameteriv);
577 GET_PROC(TexSubImage2D);
578
579 if (version >= GR_GL_VER(3,0)) {
580 GET_PROC(TexStorage2D);
581 } else {
582 GET_PROC_SUFFIX(TexStorage2D, EXT);
583 }
584
cdaltonfd4167d2015-04-21 11:45:56 -0700585 if (extensions.has("GL_NV_texture_barrier")) {
586 GET_PROC_SUFFIX(TextureBarrier, NV);
587 }
588
bsalomona721c812014-08-26 11:35:23 -0700589 GET_PROC_SUFFIX(DiscardFramebuffer, EXT);
590 GET_PROC(Uniform1f);
591 GET_PROC(Uniform1i);
592 GET_PROC(Uniform1fv);
593 GET_PROC(Uniform1iv);
594 GET_PROC(Uniform2f);
595 GET_PROC(Uniform2i);
596 GET_PROC(Uniform2fv);
597 GET_PROC(Uniform2iv);
598 GET_PROC(Uniform3f);
599 GET_PROC(Uniform3i);
600 GET_PROC(Uniform3fv);
601 GET_PROC(Uniform3iv);
602 GET_PROC(Uniform4f);
603 GET_PROC(Uniform4i);
604 GET_PROC(Uniform4fv);
605 GET_PROC(Uniform4iv);
606 GET_PROC(UniformMatrix2fv);
607 GET_PROC(UniformMatrix3fv);
608 GET_PROC(UniformMatrix4fv);
609 GET_PROC(UseProgram);
egdaniel27c15212014-10-24 15:00:50 -0700610 GET_PROC(VertexAttrib1f);
611 GET_PROC(VertexAttrib2fv);
612 GET_PROC(VertexAttrib3fv);
bsalomona721c812014-08-26 11:35:23 -0700613 GET_PROC(VertexAttrib4fv);
614 GET_PROC(VertexAttribPointer);
615 GET_PROC(Viewport);
616 GET_PROC(BindFramebuffer);
617 GET_PROC(BindRenderbuffer);
618 GET_PROC(CheckFramebufferStatus);
619 GET_PROC(DeleteFramebuffers);
620 GET_PROC(DeleteRenderbuffers);
621 GET_PROC(FramebufferRenderbuffer);
622 GET_PROC(FramebufferTexture2D);
623
624 if (version >= GR_GL_VER(3,0)) {
625 GET_PROC(RenderbufferStorageMultisample);
626 GET_PROC(BlitFramebuffer);
627 }
628
629 if (extensions.has("GL_EXT_multisampled_render_to_texture")) {
630 GET_PROC_SUFFIX(FramebufferTexture2DMultisample, EXT);
631 functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStorageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleEXT");
632 } else if (extensions.has("GL_IMG_multisampled_render_to_texture")) {
633 GET_PROC_SUFFIX(FramebufferTexture2DMultisample, IMG);
634 functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStorageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleIMG");
635 } else if (extensions.has("GL_APPLE_framebuffer_multisample")) {
636 functions->fRenderbufferStorageMultisampleES2APPLE = (GrGLRenderbufferStorageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleAPPLE");
637 GET_PROC_SUFFIX(ResolveMultisampleFramebuffer, APPLE);
638 }
639
640 GET_PROC(GenFramebuffers);
641 GET_PROC(GenRenderbuffers);
642 GET_PROC(GetFramebufferAttachmentParameteriv);
643 GET_PROC(GetRenderbufferParameteriv);
644 GET_PROC(RenderbufferStorage);
645
646 GET_PROC_SUFFIX(MapBuffer, OES);
647 GET_PROC_SUFFIX(UnmapBuffer, OES);
648
649 if (version >= GR_GL_VER(3,0)) {
650 GET_PROC(MapBufferRange);
651 GET_PROC(FlushMappedBufferRange);
652 } else if (extensions.has("GL_EXT_map_buffer_range")) {
653 GET_PROC_SUFFIX(MapBufferRange, EXT);
654 GET_PROC_SUFFIX(FlushMappedBufferRange, EXT);
655 }
656
657 if (extensions.has("GL_EXT_debug_marker")) {
658 GET_PROC(InsertEventMarker);
659 GET_PROC(PushGroupMarker);
660 GET_PROC(PopGroupMarker);
661 // The below check is here because a device has been found that has the extension string but
662 // returns NULL from the eglGetProcAddress for the functions
663 if (NULL == functions->fInsertEventMarker ||
664 NULL == functions->fPushGroupMarker ||
665 NULL == functions->fPopGroupMarker) {
666 extensions.remove("GL_EXT_debug_marker");
667 }
668 }
669
670 GET_PROC(InvalidateFramebuffer);
671 GET_PROC(InvalidateSubFramebuffer);
672 GET_PROC(InvalidateBufferData);
673 GET_PROC(InvalidateBufferSubData);
674 GET_PROC(InvalidateTexImage);
675 GET_PROC(InvalidateTexSubImage);
676
677 if (version >= GR_GL_VER(3,1)) {
678 GET_PROC(GetProgramResourceLocation);
679 }
680
681 if (extensions.has("GL_NV_path_rendering")) {
682 GET_PROC_SUFFIX(MatrixLoadf, EXT);
683 GET_PROC_SUFFIX(MatrixLoadIdentity, EXT);
684 GET_PROC_SUFFIX(PathCommands, NV);
jvanverth439f23e2015-06-30 09:40:38 -0700685 GET_PROC_SUFFIX(PathCoords, NV);
bsalomona721c812014-08-26 11:35:23 -0700686 GET_PROC_SUFFIX(PathParameteri, NV);
687 GET_PROC_SUFFIX(PathParameterf, NV);
688 GET_PROC_SUFFIX(GenPaths, NV);
689 GET_PROC_SUFFIX(DeletePaths, NV);
690 GET_PROC_SUFFIX(IsPath, NV);
691 GET_PROC_SUFFIX(PathStencilFunc, NV);
692 GET_PROC_SUFFIX(StencilFillPath, NV);
693 GET_PROC_SUFFIX(StencilStrokePath, NV);
694 GET_PROC_SUFFIX(StencilFillPathInstanced, NV);
695 GET_PROC_SUFFIX(StencilStrokePathInstanced, NV);
696 GET_PROC_SUFFIX(CoverFillPath, NV);
697 GET_PROC_SUFFIX(CoverStrokePath, NV);
698 GET_PROC_SUFFIX(CoverFillPathInstanced, NV);
699 GET_PROC_SUFFIX(CoverStrokePathInstanced, NV);
700 GET_PROC_SUFFIX(StencilThenCoverFillPath, NV);
701 GET_PROC_SUFFIX(StencilThenCoverStrokePath, NV);
702 GET_PROC_SUFFIX(StencilThenCoverFillPathInstanced, NV);
703 GET_PROC_SUFFIX(StencilThenCoverStrokePathInstanced, NV);
704 GET_PROC_SUFFIX(ProgramPathFragmentInputGen, NV);
705 }
706
vbuzinov08b4d292015-04-01 06:29:49 -0700707 if (extensions.has("GL_NV_framebuffer_mixed_samples")) {
708 GET_PROC_SUFFIX(CoverageModulation, NV);
709 }
710
cdalton626e1ff2015-06-12 13:56:46 -0700711 if (version >= GR_GL_VER(3,0) || extensions.has("GL_EXT_draw_instanced")) {
712 GET_PROC(DrawArraysInstanced);
713 GET_PROC(DrawElementsInstanced);
714 }
715
716 if (version >= GR_GL_VER(3,0) || extensions.has("GL_EXT_instanced_arrays")) {
717 GET_PROC(VertexAttribDivisor);
718 }
719
720 if (extensions.has("GL_NV_bindless_texture")) {
721 GET_PROC_SUFFIX(GetTextureHandle, NV);
722 GET_PROC_SUFFIX(GetTextureSamplerHandle, NV);
723 GET_PROC_SUFFIX(MakeTextureHandleResident, NV);
724 GET_PROC_SUFFIX(MakeTextureHandleNonResident, NV);
725 GET_PROC_SUFFIX(GetImageHandle, NV);
726 GET_PROC_SUFFIX(MakeImageHandleResident, NV);
727 GET_PROC_SUFFIX(MakeImageHandleNonResident, NV);
728 GET_PROC_SUFFIX(IsTextureHandleResident, NV);
729 GET_PROC_SUFFIX(IsImageHandleResident, NV);
730 GET_PROC_SUFFIX(UniformHandleui64, NV);
731 GET_PROC_SUFFIX(UniformHandleui64v, NV);
732 GET_PROC_SUFFIX(ProgramUniformHandleui64, NV);
733 GET_PROC_SUFFIX(ProgramUniformHandleui64v, NV);
734 }
735
736 if (extensions.has("GL_KHR_debug")) {
737 GET_PROC_SUFFIX(DebugMessageControl, KHR);
738 GET_PROC_SUFFIX(DebugMessageInsert, KHR);
739 GET_PROC_SUFFIX(DebugMessageCallback, KHR);
740 GET_PROC_SUFFIX(GetDebugMessageLog, KHR);
741 GET_PROC_SUFFIX(PushDebugGroup, KHR);
742 GET_PROC_SUFFIX(PopDebugGroup, KHR);
743 GET_PROC_SUFFIX(ObjectLabel, KHR);
744 }
745
bsalomona721c812014-08-26 11:35:23 -0700746 interface->fStandard = kGLES_GrGLStandard;
747 interface->fExtensions.swap(&extensions);
748
749 return interface;
750}