1
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
GrGLAssembleGLInterface(void * ctx,GrGLGetProc get)17 const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) {
18 GET_PROC_LOCAL(GetString);
19 GET_PROC_LOCAL(GetStringi);
20 GET_PROC_LOCAL(GetIntegerv);
21
22 // GetStringi may be NULL depending on the GL version.
23 if (NULL == GetString || NULL == GetIntegerv) {
24 return NULL;
25 }
26
27 const char* versionString = (const char*) GetString(GR_GL_VERSION);
28 GrGLVersion glVer = GrGLGetVersionFromString(versionString);
29
30 if (glVer < GR_GL_VER(1,5) || GR_GL_INVALID_VER == glVer) {
31 // We must have array and element_array buffer objects.
32 return NULL;
33 }
34
35 GrGLExtensions extensions;
36 if (!extensions.init(kGL_GrGLStandard, GetString, GetStringi, GetIntegerv)) {
37 return NULL;
38 }
39
40 GrGLInterface* interface = SkNEW(GrGLInterface());
41 GrGLInterface::Functions* functions = &interface->fFunctions;
42
43 GET_PROC(ActiveTexture);
44 GET_PROC(AttachShader);
45 GET_PROC(BindAttribLocation);
46 GET_PROC(BindBuffer);
47 if (glVer >= GR_GL_VER(3,0)) {
48 GET_PROC(BindFragDataLocation);
49 }
50 GET_PROC(BeginQuery);
51 GET_PROC(BindTexture);
52 GET_PROC(BlendFunc);
53
54 if (glVer >= GR_GL_VER(1,4) ||
55 extensions.has("GL_ARB_imaging") ||
56 extensions.has("GL_EXT_blend_color")) {
57 GET_PROC(BlendColor);
58 }
59
60 GET_PROC(BufferData);
61 GET_PROC(BufferSubData);
62 GET_PROC(Clear);
63 GET_PROC(ClearColor);
64 GET_PROC(ClearStencil);
65 GET_PROC(ColorMask);
66 GET_PROC(CompileShader);
67 GET_PROC(CompressedTexImage2D);
68 GET_PROC(CompressedTexSubImage2D);
69 GET_PROC(CopyTexSubImage2D);
70 GET_PROC(CreateProgram);
71 GET_PROC(CreateShader);
72 GET_PROC(CullFace);
73 GET_PROC(DeleteBuffers);
74 GET_PROC(DeleteProgram);
75 GET_PROC(DeleteQueries);
76 GET_PROC(DeleteShader);
77 GET_PROC(DeleteTextures);
78 GET_PROC(DepthMask);
79 GET_PROC(Disable);
80 GET_PROC(DisableVertexAttribArray);
81 GET_PROC(DrawArrays);
82 GET_PROC(DrawBuffer);
83 GET_PROC(DrawBuffers);
84 GET_PROC(DrawElements);
85 GET_PROC(Enable);
86 GET_PROC(EnableVertexAttribArray);
87 GET_PROC(EndQuery);
88 GET_PROC(Finish);
89 GET_PROC(Flush);
90 GET_PROC(FrontFace);
91 GET_PROC(GenBuffers);
92 GET_PROC(GenerateMipmap);
93 GET_PROC(GetBufferParameteriv);
94 GET_PROC(GetError);
95 GET_PROC(GetIntegerv);
96 GET_PROC(GetQueryObjectiv);
97 GET_PROC(GetQueryObjectuiv);
98 if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) {
99 GET_PROC(GetQueryObjecti64v);
100 GET_PROC(GetQueryObjectui64v);
101 GET_PROC(QueryCounter);
102 } else if (extensions.has("GL_EXT_timer_query")) {
103 GET_PROC_SUFFIX(GetQueryObjecti64v, EXT);
104 GET_PROC_SUFFIX(GetQueryObjectui64v, EXT);
105 }
106 GET_PROC(GetQueryiv);
107 GET_PROC(GetProgramInfoLog);
108 GET_PROC(GetProgramiv);
109 GET_PROC(GetShaderInfoLog);
110 GET_PROC(GetShaderiv);
111 GET_PROC(GetString);
112 GET_PROC(GetStringi);
113 GET_PROC(GetTexLevelParameteriv);
114 GET_PROC(GenQueries);
115 GET_PROC(GenTextures);
116 GET_PROC(GetUniformLocation);
117 GET_PROC(LineWidth);
118 GET_PROC(LinkProgram);
119 GET_PROC(MapBuffer);
120 if (extensions.has("GL_EXT_direct_state_access")) {
121 GET_PROC_SUFFIX(MatrixLoadf, EXT);
122 GET_PROC_SUFFIX(MatrixLoadIdentity, EXT);
123 }
124 GET_PROC(PixelStorei);
125 GET_PROC(ReadBuffer);
126 GET_PROC(ReadPixels);
127 GET_PROC(Scissor);
128 GET_PROC(ShaderSource);
129 GET_PROC(StencilFunc);
130 GET_PROC(StencilFuncSeparate);
131 GET_PROC(StencilMask);
132 GET_PROC(StencilMaskSeparate);
133 GET_PROC(StencilOp);
134 GET_PROC(StencilOpSeparate);
135 GET_PROC(TexImage2D);
136 GET_PROC(TexParameteri);
137 GET_PROC(TexParameteriv);
138 if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) {
139 GET_PROC(TexStorage2D);
140 } else if (extensions.has("GL_EXT_texture_storage")) {
141 GET_PROC_SUFFIX(TexStorage2D, EXT);
142 }
143 GET_PROC(TexSubImage2D);
144 GET_PROC(Uniform1f);
145 GET_PROC(Uniform1i);
146 GET_PROC(Uniform1fv);
147 GET_PROC(Uniform1iv);
148 GET_PROC(Uniform2f);
149 GET_PROC(Uniform2i);
150 GET_PROC(Uniform2fv);
151 GET_PROC(Uniform2iv);
152 GET_PROC(Uniform3f);
153 GET_PROC(Uniform3i);
154 GET_PROC(Uniform3fv);
155 GET_PROC(Uniform3iv);
156 GET_PROC(Uniform4f);
157 GET_PROC(Uniform4i);
158 GET_PROC(Uniform4fv);
159 GET_PROC(Uniform4iv);
160 GET_PROC(UniformMatrix2fv);
161 GET_PROC(UniformMatrix3fv);
162 GET_PROC(UniformMatrix4fv);
163 GET_PROC(UnmapBuffer);
164 GET_PROC(UseProgram);
165 GET_PROC(VertexAttrib4fv);
166 GET_PROC(VertexAttribPointer);
167 GET_PROC(Viewport);
168 GET_PROC(BindFragDataLocationIndexed);
169
170 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object")) {
171 // no ARB suffix for GL_ARB_vertex_array_object
172 GET_PROC(BindVertexArray);
173 GET_PROC(GenVertexArrays);
174 GET_PROC(DeleteVertexArrays);
175 }
176
177 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_map_buffer_range")) {
178 GET_PROC(MapBufferRange);
179 GET_PROC(FlushMappedBufferRange);
180 }
181
182 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
183 // GL_ARB_framebuffer_object doesn't use ARB suffix.)
184 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) {
185 GET_PROC(GenFramebuffers);
186 GET_PROC(GetFramebufferAttachmentParameteriv);
187 GET_PROC(GetRenderbufferParameteriv);
188 GET_PROC(BindFramebuffer);
189 GET_PROC(FramebufferTexture2D);
190 GET_PROC(CheckFramebufferStatus);
191 GET_PROC(DeleteFramebuffers);
192 GET_PROC(RenderbufferStorage);
193 GET_PROC(GenRenderbuffers);
194 GET_PROC(DeleteRenderbuffers);
195 GET_PROC(FramebufferRenderbuffer);
196 GET_PROC(BindRenderbuffer);
197 GET_PROC(RenderbufferStorageMultisample);
198 GET_PROC(BlitFramebuffer);
199 } else if (extensions.has("GL_EXT_framebuffer_object")) {
200 GET_PROC_SUFFIX(GenFramebuffers, EXT);
201 GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
202 GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
203 GET_PROC_SUFFIX(BindFramebuffer, EXT);
204 GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
205 GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
206 GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
207 GET_PROC_SUFFIX(RenderbufferStorage, EXT);
208 GET_PROC_SUFFIX(GenRenderbuffers, EXT);
209 GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
210 GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
211 GET_PROC_SUFFIX(BindRenderbuffer, EXT);
212 if (extensions.has("GL_EXT_framebuffer_multisample")) {
213 GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
214 }
215 if (extensions.has("GL_EXT_framebuffer_blit")) {
216 GET_PROC_SUFFIX(BlitFramebuffer, EXT);
217 }
218 } else {
219 // we must have FBOs
220 delete interface;
221 return NULL;
222 }
223
224 if (extensions.has("GL_NV_path_rendering")) {
225 GET_PROC_SUFFIX(PathCommands, NV);
226 GET_PROC_SUFFIX(PathCoords, NV);
227 GET_PROC_SUFFIX(PathSubCommands, NV);
228 GET_PROC_SUFFIX(PathSubCoords, NV);
229 GET_PROC_SUFFIX(PathString, NV);
230 GET_PROC_SUFFIX(PathGlyphs, NV);
231 GET_PROC_SUFFIX(PathGlyphRange, NV);
232 GET_PROC_SUFFIX(WeightPaths, NV);
233 GET_PROC_SUFFIX(CopyPath, NV);
234 GET_PROC_SUFFIX(InterpolatePaths, NV);
235 GET_PROC_SUFFIX(TransformPath, NV);
236 GET_PROC_SUFFIX(PathParameteriv, NV);
237 GET_PROC_SUFFIX(PathParameteri, NV);
238 GET_PROC_SUFFIX(PathParameterfv, NV);
239 GET_PROC_SUFFIX(PathParameterf, NV);
240 GET_PROC_SUFFIX(PathDashArray, NV);
241 GET_PROC_SUFFIX(GenPaths, NV);
242 GET_PROC_SUFFIX(DeletePaths, NV);
243 GET_PROC_SUFFIX(IsPath, NV);
244 GET_PROC_SUFFIX(PathStencilFunc, NV);
245 GET_PROC_SUFFIX(PathStencilDepthOffset, NV);
246 GET_PROC_SUFFIX(StencilFillPath, NV);
247 GET_PROC_SUFFIX(StencilStrokePath, NV);
248 GET_PROC_SUFFIX(StencilFillPathInstanced, NV);
249 GET_PROC_SUFFIX(StencilStrokePathInstanced, NV);
250 GET_PROC_SUFFIX(PathCoverDepthFunc, NV);
251 GET_PROC_SUFFIX(PathColorGen, NV);
252 GET_PROC_SUFFIX(PathTexGen, NV);
253 GET_PROC_SUFFIX(PathFogGen, NV);
254 GET_PROC_SUFFIX(CoverFillPath, NV);
255 GET_PROC_SUFFIX(CoverStrokePath, NV);
256 GET_PROC_SUFFIX(CoverFillPathInstanced, NV);
257 GET_PROC_SUFFIX(CoverStrokePathInstanced, NV);
258 GET_PROC_SUFFIX(GetPathParameteriv, NV);
259 GET_PROC_SUFFIX(GetPathParameterfv, NV);
260 GET_PROC_SUFFIX(GetPathCommands, NV);
261 GET_PROC_SUFFIX(GetPathCoords, NV);
262 GET_PROC_SUFFIX(GetPathDashArray, NV);
263 GET_PROC_SUFFIX(GetPathMetrics, NV);
264 GET_PROC_SUFFIX(GetPathMetricRange, NV);
265 GET_PROC_SUFFIX(GetPathSpacing, NV);
266 GET_PROC_SUFFIX(GetPathColorGeniv, NV);
267 GET_PROC_SUFFIX(GetPathColorGenfv, NV);
268 GET_PROC_SUFFIX(GetPathTexGeniv, NV);
269 GET_PROC_SUFFIX(GetPathTexGenfv, NV);
270 GET_PROC_SUFFIX(IsPointInFillPath, NV);
271 GET_PROC_SUFFIX(IsPointInStrokePath, NV);
272 GET_PROC_SUFFIX(GetPathLength, NV);
273 GET_PROC_SUFFIX(PointAlongPath, NV);
274 }
275
276 if (extensions.has("GL_EXT_debug_marker")) {
277 GET_PROC_SUFFIX(InsertEventMarker, EXT);
278 GET_PROC_SUFFIX(PushGroupMarker, EXT);
279 GET_PROC_SUFFIX(PopGroupMarker, EXT);
280 }
281
282 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_invalidate_subdata")) {
283 GET_PROC(InvalidateBufferData);
284 GET_PROC(InvalidateBufferSubData);
285 GET_PROC(InvalidateFramebuffer);
286 GET_PROC(InvalidateSubFramebuffer);
287 GET_PROC(InvalidateTexImage);
288 GET_PROC(InvalidateTexSubImage);
289 }
290
291 interface->fStandard = kGL_GrGLStandard;
292 interface->fExtensions.swap(&extensions);
293
294 return interface;
295 }
296