blob: 11355b8991d65dd5a159599619ce83274ff8123b [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
17const 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)) {
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(CopyTexSubImage2D);
69 GET_PROC(CreateProgram);
70 GET_PROC(CreateShader);
71 GET_PROC(CullFace);
72 GET_PROC(DeleteBuffers);
73 GET_PROC(DeleteProgram);
74 GET_PROC(DeleteQueries);
75 GET_PROC(DeleteShader);
76 GET_PROC(DeleteTextures);
77 GET_PROC(DepthMask);
78 GET_PROC(Disable);
79 GET_PROC(DisableVertexAttribArray);
80 GET_PROC(DrawArrays);
81 GET_PROC(DrawBuffer);
82 GET_PROC(DrawBuffers);
83 GET_PROC(DrawElements);
84 GET_PROC(Enable);
85 GET_PROC(EnableVertexAttribArray);
86 GET_PROC(EndQuery);
87 GET_PROC(Finish);
88 GET_PROC(Flush);
89 GET_PROC(FrontFace);
90 GET_PROC(GenBuffers);
91 GET_PROC(GenerateMipmap);
92 GET_PROC(GetBufferParameteriv);
93 GET_PROC(GetError);
94 GET_PROC(GetIntegerv);
95 GET_PROC(GetQueryObjectiv);
96 GET_PROC(GetQueryObjectuiv);
97 if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) {
98 GET_PROC(GetQueryObjecti64v);
99 GET_PROC(GetQueryObjectui64v);
100 GET_PROC(QueryCounter);
101 } else if (extensions.has("GL_EXT_timer_query")) {
102 GET_PROC_SUFFIX(GetQueryObjecti64v, EXT);
103 GET_PROC_SUFFIX(GetQueryObjectui64v, EXT);
104 }
105 GET_PROC(GetQueryiv);
106 GET_PROC(GetProgramInfoLog);
107 GET_PROC(GetProgramiv);
108 GET_PROC(GetShaderInfoLog);
109 GET_PROC(GetShaderiv);
110 GET_PROC(GetString);
111 GET_PROC(GetStringi);
112 GET_PROC(GetTexLevelParameteriv);
113 GET_PROC(GenQueries);
114 GET_PROC(GenTextures);
115 GET_PROC(GetUniformLocation);
116 GET_PROC(LineWidth);
117 GET_PROC(LinkProgram);
118 GET_PROC(MapBuffer);
119 if (extensions.has("GL_EXT_direct_state_access")) {
120 GET_PROC_SUFFIX(MatrixLoadf, EXT);
121 GET_PROC_SUFFIX(MatrixLoadIdentity, EXT);
122 }
123 GET_PROC(PixelStorei);
124 GET_PROC(ReadBuffer);
125 GET_PROC(ReadPixels);
126 GET_PROC(Scissor);
127 GET_PROC(ShaderSource);
128 GET_PROC(StencilFunc);
129 GET_PROC(StencilFuncSeparate);
130 GET_PROC(StencilMask);
131 GET_PROC(StencilMaskSeparate);
132 GET_PROC(StencilOp);
133 GET_PROC(StencilOpSeparate);
134 GET_PROC(TexImage2D);
135 GET_PROC(TexParameteri);
136 GET_PROC(TexParameteriv);
137 if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) {
138 GET_PROC(TexStorage2D);
139 } else if (extensions.has("GL_EXT_texture_storage")) {
140 GET_PROC_SUFFIX(TexStorage2D, EXT);
141 }
142 GET_PROC(TexSubImage2D);
143 GET_PROC(Uniform1f);
144 GET_PROC(Uniform1i);
145 GET_PROC(Uniform1fv);
146 GET_PROC(Uniform1iv);
147 GET_PROC(Uniform2f);
148 GET_PROC(Uniform2i);
149 GET_PROC(Uniform2fv);
150 GET_PROC(Uniform2iv);
151 GET_PROC(Uniform3f);
152 GET_PROC(Uniform3i);
153 GET_PROC(Uniform3fv);
154 GET_PROC(Uniform3iv);
155 GET_PROC(Uniform4f);
156 GET_PROC(Uniform4i);
157 GET_PROC(Uniform4fv);
158 GET_PROC(Uniform4iv);
159 GET_PROC(UniformMatrix2fv);
160 GET_PROC(UniformMatrix3fv);
161 GET_PROC(UniformMatrix4fv);
162 GET_PROC(UnmapBuffer);
163 GET_PROC(UseProgram);
164 GET_PROC(VertexAttrib4fv);
165 GET_PROC(VertexAttribPointer);
166 GET_PROC(Viewport);
167 GET_PROC(BindFragDataLocationIndexed);
168
169 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object")) {
170 // no ARB suffix for GL_ARB_vertex_array_object
171 GET_PROC(BindVertexArray);
172 GET_PROC(GenVertexArrays);
173 GET_PROC(DeleteVertexArrays);
174 }
175
176 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
177 // GL_ARB_framebuffer_object doesn't use ARB suffix.)
178 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) {
179 GET_PROC(GenFramebuffers);
180 GET_PROC(GetFramebufferAttachmentParameteriv);
181 GET_PROC(GetRenderbufferParameteriv);
182 GET_PROC(BindFramebuffer);
183 GET_PROC(FramebufferTexture2D);
184 GET_PROC(CheckFramebufferStatus);
185 GET_PROC(DeleteFramebuffers);
186 GET_PROC(RenderbufferStorage);
187 GET_PROC(GenRenderbuffers);
188 GET_PROC(DeleteRenderbuffers);
189 GET_PROC(FramebufferRenderbuffer);
190 GET_PROC(BindRenderbuffer);
191 GET_PROC(RenderbufferStorageMultisample);
192 GET_PROC(BlitFramebuffer);
193 } else if (extensions.has("GL_EXT_framebuffer_object")) {
194 GET_PROC_SUFFIX(GenFramebuffers, EXT);
195 GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
196 GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
197 GET_PROC_SUFFIX(BindFramebuffer, EXT);
198 GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
199 GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
200 GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
201 GET_PROC_SUFFIX(RenderbufferStorage, EXT);
202 GET_PROC_SUFFIX(GenRenderbuffers, EXT);
203 GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
204 GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
205 GET_PROC_SUFFIX(BindRenderbuffer, EXT);
206 if (extensions.has("GL_EXT_framebuffer_multisample")) {
207 GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
208 }
209 if (extensions.has("GL_EXT_framebuffer_blit")) {
210 GET_PROC_SUFFIX(BlitFramebuffer, EXT);
211 }
212 } else {
213 // we must have FBOs
214 delete interface;
215 return NULL;
216 }
217
218 if (extensions.has("GL_NV_path_rendering")) {
219 GET_PROC_SUFFIX(PathCommands, NV);
220 GET_PROC_SUFFIX(PathCoords, NV);
221 GET_PROC_SUFFIX(PathSubCommands, NV);
222 GET_PROC_SUFFIX(PathSubCoords, NV);
223 GET_PROC_SUFFIX(PathString, NV);
224 GET_PROC_SUFFIX(PathGlyphs, NV);
225 GET_PROC_SUFFIX(PathGlyphRange, NV);
226 GET_PROC_SUFFIX(WeightPaths, NV);
227 GET_PROC_SUFFIX(CopyPath, NV);
228 GET_PROC_SUFFIX(InterpolatePaths, NV);
229 GET_PROC_SUFFIX(TransformPath, NV);
230 GET_PROC_SUFFIX(PathParameteriv, NV);
231 GET_PROC_SUFFIX(PathParameteri, NV);
232 GET_PROC_SUFFIX(PathParameterfv, NV);
233 GET_PROC_SUFFIX(PathParameterf, NV);
234 GET_PROC_SUFFIX(PathDashArray, NV);
235 GET_PROC_SUFFIX(GenPaths, NV);
236 GET_PROC_SUFFIX(DeletePaths, NV);
237 GET_PROC_SUFFIX(IsPath, NV);
238 GET_PROC_SUFFIX(PathStencilFunc, NV);
239 GET_PROC_SUFFIX(PathStencilDepthOffset, NV);
240 GET_PROC_SUFFIX(StencilFillPath, NV);
241 GET_PROC_SUFFIX(StencilStrokePath, NV);
242 GET_PROC_SUFFIX(StencilFillPathInstanced, NV);
243 GET_PROC_SUFFIX(StencilStrokePathInstanced, NV);
244 GET_PROC_SUFFIX(PathCoverDepthFunc, NV);
245 GET_PROC_SUFFIX(PathColorGen, NV);
246 GET_PROC_SUFFIX(PathTexGen, NV);
247 GET_PROC_SUFFIX(PathFogGen, NV);
248 GET_PROC_SUFFIX(CoverFillPath, NV);
249 GET_PROC_SUFFIX(CoverStrokePath, NV);
250 GET_PROC_SUFFIX(CoverFillPathInstanced, NV);
251 GET_PROC_SUFFIX(CoverStrokePathInstanced, NV);
252 GET_PROC_SUFFIX(GetPathParameteriv, NV);
253 GET_PROC_SUFFIX(GetPathParameterfv, NV);
254 GET_PROC_SUFFIX(GetPathCommands, NV);
255 GET_PROC_SUFFIX(GetPathCoords, NV);
256 GET_PROC_SUFFIX(GetPathDashArray, NV);
257 GET_PROC_SUFFIX(GetPathMetrics, NV);
258 GET_PROC_SUFFIX(GetPathMetricRange, NV);
259 GET_PROC_SUFFIX(GetPathSpacing, NV);
260 GET_PROC_SUFFIX(GetPathColorGeniv, NV);
261 GET_PROC_SUFFIX(GetPathColorGenfv, NV);
262 GET_PROC_SUFFIX(GetPathTexGeniv, NV);
263 GET_PROC_SUFFIX(GetPathTexGenfv, NV);
264 GET_PROC_SUFFIX(IsPointInFillPath, NV);
265 GET_PROC_SUFFIX(IsPointInStrokePath, NV);
266 GET_PROC_SUFFIX(GetPathLength, NV);
267 GET_PROC_SUFFIX(PointAlongPath, NV);
268 }
269
270 if (extensions.has("GL_EXT_debug_marker")) {
271 GET_PROC_SUFFIX(InsertEventMarker, EXT);
272 GET_PROC_SUFFIX(PushGroupMarker, EXT);
273 GET_PROC_SUFFIX(PopGroupMarker, EXT);
274 }
275
276 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_invalidate_subdata")) {
277 GET_PROC(InvalidateBufferData);
278 GET_PROC(InvalidateBufferSubData);
279 GET_PROC(InvalidateFramebuffer);
280 GET_PROC(InvalidateSubFramebuffer);
281 GET_PROC(InvalidateTexImage);
282 GET_PROC(InvalidateTexSubImage);
283 }
284
285 interface->fStandard = kGL_GrGLStandard;
286 interface->fExtensions.swap(&extensions);
287
288 return interface;
289}