|
1 |
|
2 /* |
|
3 * Copyright 2011 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 "gl/GrGLInterface.h" |
|
11 #include "../GrGLUtil.h" |
|
12 |
|
13 #include <GL/glx.h> |
|
14 #include <GL/gl.h> |
|
15 #include <GL/glext.h> |
|
16 #include <GL/glu.h> |
|
17 |
|
18 #define GR_GL_GET_PROC(F) interface->fFunctions.f ## F = (GrGL ## F ## Proc) \ |
|
19 glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F)); |
|
20 #define GR_GL_GET_PROC_SUFFIX(F, S) interface->fFunctions.f ## F = (GrGL ## F ## Proc) \ |
|
21 glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F #S)); |
|
22 |
|
23 const GrGLInterface* GrGLCreateNativeInterface() { |
|
24 if (NULL != glXGetCurrentContext()) { |
|
25 |
|
26 const char* versionString = (const char*) glGetString(GL_VERSION); |
|
27 GrGLVersion glVer = GrGLGetVersionFromString(versionString); |
|
28 |
|
29 // This may or may not succeed depending on the gl version. |
|
30 GrGLGetStringiProc glGetStringi = |
|
31 (GrGLGetStringiProc) glXGetProcAddress(reinterpret_cast<const GLubyte*>("glGetStringi")); |
|
32 |
|
33 GrGLExtensions extensions; |
|
34 if (!extensions.init(kGL_GrGLStandard, glGetString, glGetStringi, glGetIntegerv)) { |
|
35 return NULL; |
|
36 } |
|
37 |
|
38 if (glVer < GR_GL_VER(1,5)) { |
|
39 // We must have array and element_array buffer objects. |
|
40 return NULL; |
|
41 } |
|
42 |
|
43 GrGLInterface* interface = SkNEW(GrGLInterface()); |
|
44 GrGLInterface::Functions* functions = &interface->fFunctions; |
|
45 |
|
46 functions->fActiveTexture = glActiveTexture; |
|
47 GR_GL_GET_PROC(AttachShader); |
|
48 GR_GL_GET_PROC(BindAttribLocation); |
|
49 GR_GL_GET_PROC(BindBuffer); |
|
50 GR_GL_GET_PROC(BindFragDataLocation); |
|
51 GR_GL_GET_PROC(BeginQuery); |
|
52 functions->fBindTexture = glBindTexture; |
|
53 functions->fBlendFunc = glBlendFunc; |
|
54 |
|
55 if (glVer >= GR_GL_VER(1,4) || |
|
56 extensions.has("GL_ARB_imaging") || |
|
57 extensions.has("GL_EXT_blend_color")) { |
|
58 GR_GL_GET_PROC(BlendColor); |
|
59 } |
|
60 |
|
61 GR_GL_GET_PROC(BufferData); |
|
62 GR_GL_GET_PROC(BufferSubData); |
|
63 functions->fClear = glClear; |
|
64 functions->fClearColor = glClearColor; |
|
65 functions->fClearStencil = glClearStencil; |
|
66 functions->fColorMask = glColorMask; |
|
67 GR_GL_GET_PROC(CompileShader); |
|
68 functions->fCompressedTexImage2D = glCompressedTexImage2D; |
|
69 functions->fCopyTexSubImage2D = glCopyTexSubImage2D; |
|
70 GR_GL_GET_PROC(CreateProgram); |
|
71 GR_GL_GET_PROC(CreateShader); |
|
72 functions->fCullFace = glCullFace; |
|
73 GR_GL_GET_PROC(DeleteBuffers); |
|
74 GR_GL_GET_PROC(DeleteProgram); |
|
75 GR_GL_GET_PROC(DeleteQueries); |
|
76 GR_GL_GET_PROC(DeleteShader); |
|
77 functions->fDeleteTextures = glDeleteTextures; |
|
78 functions->fDepthMask = glDepthMask; |
|
79 functions->fDisable = glDisable; |
|
80 GR_GL_GET_PROC(DisableVertexAttribArray); |
|
81 functions->fDrawArrays = glDrawArrays; |
|
82 functions->fDrawBuffer = glDrawBuffer; |
|
83 GR_GL_GET_PROC(DrawBuffers); |
|
84 functions->fDrawElements = glDrawElements; |
|
85 functions->fEnable = glEnable; |
|
86 GR_GL_GET_PROC(EnableVertexAttribArray); |
|
87 GR_GL_GET_PROC(EndQuery); |
|
88 functions->fFinish = glFinish; |
|
89 functions->fFlush = glFlush; |
|
90 functions->fFrontFace = glFrontFace; |
|
91 GR_GL_GET_PROC(GenBuffers); |
|
92 GR_GL_GET_PROC(GenerateMipmap); |
|
93 GR_GL_GET_PROC(GetBufferParameteriv); |
|
94 functions->fGetError = glGetError; |
|
95 functions->fGetIntegerv = glGetIntegerv; |
|
96 GR_GL_GET_PROC(GetQueryObjectiv); |
|
97 GR_GL_GET_PROC(GetQueryObjectuiv); |
|
98 if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) { |
|
99 GR_GL_GET_PROC(GetQueryObjecti64v); |
|
100 GR_GL_GET_PROC(GetQueryObjectui64v); |
|
101 GR_GL_GET_PROC(QueryCounter); |
|
102 } else if (extensions.has("GL_EXT_timer_query")) { |
|
103 GR_GL_GET_PROC_SUFFIX(GetQueryObjecti64v, EXT); |
|
104 GR_GL_GET_PROC_SUFFIX(GetQueryObjectui64v, EXT); |
|
105 } |
|
106 GR_GL_GET_PROC(GetQueryiv); |
|
107 GR_GL_GET_PROC(GetProgramInfoLog); |
|
108 GR_GL_GET_PROC(GetProgramiv); |
|
109 GR_GL_GET_PROC(GetShaderInfoLog); |
|
110 GR_GL_GET_PROC(GetShaderiv); |
|
111 functions->fGetString = glGetString; |
|
112 GR_GL_GET_PROC(GetStringi); |
|
113 functions->fGetTexLevelParameteriv = glGetTexLevelParameteriv; |
|
114 GR_GL_GET_PROC(GenQueries); |
|
115 functions->fGenTextures = glGenTextures; |
|
116 GR_GL_GET_PROC(GetUniformLocation); |
|
117 functions->fLineWidth = glLineWidth; |
|
118 GR_GL_GET_PROC(LinkProgram); |
|
119 GR_GL_GET_PROC(MapBuffer); |
|
120 functions->fPixelStorei = glPixelStorei; |
|
121 functions->fReadBuffer = glReadBuffer; |
|
122 functions->fReadPixels = glReadPixels; |
|
123 functions->fScissor = glScissor; |
|
124 GR_GL_GET_PROC(ShaderSource); |
|
125 functions->fStencilFunc = glStencilFunc; |
|
126 GR_GL_GET_PROC(StencilFuncSeparate); |
|
127 functions->fStencilMask = glStencilMask; |
|
128 GR_GL_GET_PROC(StencilMaskSeparate); |
|
129 functions->fStencilOp = glStencilOp; |
|
130 GR_GL_GET_PROC(StencilOpSeparate); |
|
131 functions->fTexImage2D = glTexImage2D; |
|
132 functions->fTexGenfv = glTexGenfv; |
|
133 functions->fTexGeni = glTexGeni; |
|
134 functions->fTexParameteri = glTexParameteri; |
|
135 functions->fTexParameteriv = glTexParameteriv; |
|
136 if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) { |
|
137 GR_GL_GET_PROC(TexStorage2D); |
|
138 } else if (extensions.has("GL_EXT_texture_storage")) { |
|
139 GR_GL_GET_PROC_SUFFIX(TexStorage2D, EXT); |
|
140 } |
|
141 functions->fTexSubImage2D = glTexSubImage2D; |
|
142 GR_GL_GET_PROC(Uniform1f); |
|
143 GR_GL_GET_PROC(Uniform1i); |
|
144 GR_GL_GET_PROC(Uniform1fv); |
|
145 GR_GL_GET_PROC(Uniform1iv); |
|
146 GR_GL_GET_PROC(Uniform2f); |
|
147 GR_GL_GET_PROC(Uniform2i); |
|
148 GR_GL_GET_PROC(Uniform2fv); |
|
149 GR_GL_GET_PROC(Uniform2iv); |
|
150 GR_GL_GET_PROC(Uniform3f); |
|
151 GR_GL_GET_PROC(Uniform3i); |
|
152 GR_GL_GET_PROC(Uniform3fv); |
|
153 GR_GL_GET_PROC(Uniform3iv); |
|
154 GR_GL_GET_PROC(Uniform4f); |
|
155 GR_GL_GET_PROC(Uniform4i); |
|
156 GR_GL_GET_PROC(Uniform4fv); |
|
157 GR_GL_GET_PROC(Uniform4iv); |
|
158 GR_GL_GET_PROC(UniformMatrix2fv); |
|
159 GR_GL_GET_PROC(UniformMatrix3fv); |
|
160 GR_GL_GET_PROC(UniformMatrix4fv); |
|
161 GR_GL_GET_PROC(UnmapBuffer); |
|
162 GR_GL_GET_PROC(UseProgram); |
|
163 GR_GL_GET_PROC(VertexAttrib4fv); |
|
164 GR_GL_GET_PROC(VertexAttribPointer); |
|
165 functions->fViewport = glViewport; |
|
166 GR_GL_GET_PROC(BindFragDataLocationIndexed); |
|
167 |
|
168 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object")) { |
|
169 // no ARB suffix for GL_ARB_vertex_array_object |
|
170 GR_GL_GET_PROC(BindVertexArray); |
|
171 GR_GL_GET_PROC(GenVertexArrays); |
|
172 GR_GL_GET_PROC(DeleteVertexArrays); |
|
173 } |
|
174 |
|
175 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since |
|
176 // GL_ARB_framebuffer_object doesn't use ARB suffix.) |
|
177 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) { |
|
178 GR_GL_GET_PROC(GenFramebuffers); |
|
179 GR_GL_GET_PROC(GetFramebufferAttachmentParameteriv); |
|
180 GR_GL_GET_PROC(GetRenderbufferParameteriv); |
|
181 GR_GL_GET_PROC(BindFramebuffer); |
|
182 GR_GL_GET_PROC(FramebufferTexture2D); |
|
183 GR_GL_GET_PROC(CheckFramebufferStatus); |
|
184 GR_GL_GET_PROC(DeleteFramebuffers); |
|
185 GR_GL_GET_PROC(RenderbufferStorage); |
|
186 GR_GL_GET_PROC(GenRenderbuffers); |
|
187 GR_GL_GET_PROC(DeleteRenderbuffers); |
|
188 GR_GL_GET_PROC(FramebufferRenderbuffer); |
|
189 GR_GL_GET_PROC(BindRenderbuffer); |
|
190 GR_GL_GET_PROC(RenderbufferStorageMultisample); |
|
191 GR_GL_GET_PROC(BlitFramebuffer); |
|
192 } else if (extensions.has("GL_EXT_framebuffer_object")) { |
|
193 GR_GL_GET_PROC_SUFFIX(GenFramebuffers, EXT); |
|
194 GR_GL_GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT); |
|
195 GR_GL_GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT); |
|
196 GR_GL_GET_PROC_SUFFIX(BindFramebuffer, EXT); |
|
197 GR_GL_GET_PROC_SUFFIX(FramebufferTexture2D, EXT); |
|
198 GR_GL_GET_PROC_SUFFIX(CheckFramebufferStatus, EXT); |
|
199 GR_GL_GET_PROC_SUFFIX(DeleteFramebuffers, EXT); |
|
200 GR_GL_GET_PROC_SUFFIX(RenderbufferStorage, EXT); |
|
201 GR_GL_GET_PROC_SUFFIX(GenRenderbuffers, EXT); |
|
202 GR_GL_GET_PROC_SUFFIX(DeleteRenderbuffers, EXT); |
|
203 GR_GL_GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT); |
|
204 GR_GL_GET_PROC_SUFFIX(BindRenderbuffer, EXT); |
|
205 if (extensions.has("GL_EXT_framebuffer_multisample")) { |
|
206 GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT); |
|
207 } |
|
208 if (extensions.has("GL_EXT_framebuffer_blit")) { |
|
209 GR_GL_GET_PROC_SUFFIX(BlitFramebuffer, EXT); |
|
210 } |
|
211 } else { |
|
212 // we must have FBOs |
|
213 delete interface; |
|
214 return NULL; |
|
215 } |
|
216 |
|
217 GR_GL_GET_PROC(LoadIdentity); |
|
218 GR_GL_GET_PROC(LoadMatrixf); |
|
219 GR_GL_GET_PROC(MatrixMode); |
|
220 |
|
221 if (extensions.has("GL_NV_path_rendering")) { |
|
222 GR_GL_GET_PROC_SUFFIX(PathCommands, NV); |
|
223 GR_GL_GET_PROC_SUFFIX(PathCoords, NV); |
|
224 GR_GL_GET_PROC_SUFFIX(PathSubCommands, NV); |
|
225 GR_GL_GET_PROC_SUFFIX(PathSubCoords, NV); |
|
226 GR_GL_GET_PROC_SUFFIX(PathString, NV); |
|
227 GR_GL_GET_PROC_SUFFIX(PathGlyphs, NV); |
|
228 GR_GL_GET_PROC_SUFFIX(PathGlyphRange, NV); |
|
229 GR_GL_GET_PROC_SUFFIX(WeightPaths, NV); |
|
230 GR_GL_GET_PROC_SUFFIX(CopyPath, NV); |
|
231 GR_GL_GET_PROC_SUFFIX(InterpolatePaths, NV); |
|
232 GR_GL_GET_PROC_SUFFIX(TransformPath, NV); |
|
233 GR_GL_GET_PROC_SUFFIX(PathParameteriv, NV); |
|
234 GR_GL_GET_PROC_SUFFIX(PathParameteri, NV); |
|
235 GR_GL_GET_PROC_SUFFIX(PathParameterfv, NV); |
|
236 GR_GL_GET_PROC_SUFFIX(PathParameterf, NV); |
|
237 GR_GL_GET_PROC_SUFFIX(PathDashArray, NV); |
|
238 GR_GL_GET_PROC_SUFFIX(GenPaths, NV); |
|
239 GR_GL_GET_PROC_SUFFIX(DeletePaths, NV); |
|
240 GR_GL_GET_PROC_SUFFIX(IsPath, NV); |
|
241 GR_GL_GET_PROC_SUFFIX(PathStencilFunc, NV); |
|
242 GR_GL_GET_PROC_SUFFIX(PathStencilDepthOffset, NV); |
|
243 GR_GL_GET_PROC_SUFFIX(StencilFillPath, NV); |
|
244 GR_GL_GET_PROC_SUFFIX(StencilStrokePath, NV); |
|
245 GR_GL_GET_PROC_SUFFIX(StencilFillPathInstanced, NV); |
|
246 GR_GL_GET_PROC_SUFFIX(StencilStrokePathInstanced, NV); |
|
247 GR_GL_GET_PROC_SUFFIX(PathCoverDepthFunc, NV); |
|
248 GR_GL_GET_PROC_SUFFIX(PathColorGen, NV); |
|
249 GR_GL_GET_PROC_SUFFIX(PathTexGen, NV); |
|
250 GR_GL_GET_PROC_SUFFIX(PathFogGen, NV); |
|
251 GR_GL_GET_PROC_SUFFIX(CoverFillPath, NV); |
|
252 GR_GL_GET_PROC_SUFFIX(CoverStrokePath, NV); |
|
253 GR_GL_GET_PROC_SUFFIX(CoverFillPathInstanced, NV); |
|
254 GR_GL_GET_PROC_SUFFIX(CoverStrokePathInstanced, NV); |
|
255 GR_GL_GET_PROC_SUFFIX(GetPathParameteriv, NV); |
|
256 GR_GL_GET_PROC_SUFFIX(GetPathParameterfv, NV); |
|
257 GR_GL_GET_PROC_SUFFIX(GetPathCommands, NV); |
|
258 GR_GL_GET_PROC_SUFFIX(GetPathCoords, NV); |
|
259 GR_GL_GET_PROC_SUFFIX(GetPathDashArray, NV); |
|
260 GR_GL_GET_PROC_SUFFIX(GetPathMetrics, NV); |
|
261 GR_GL_GET_PROC_SUFFIX(GetPathMetricRange, NV); |
|
262 GR_GL_GET_PROC_SUFFIX(GetPathSpacing, NV); |
|
263 GR_GL_GET_PROC_SUFFIX(GetPathColorGeniv, NV); |
|
264 GR_GL_GET_PROC_SUFFIX(GetPathColorGenfv, NV); |
|
265 GR_GL_GET_PROC_SUFFIX(GetPathTexGeniv, NV); |
|
266 GR_GL_GET_PROC_SUFFIX(GetPathTexGenfv, NV); |
|
267 GR_GL_GET_PROC_SUFFIX(IsPointInFillPath, NV); |
|
268 GR_GL_GET_PROC_SUFFIX(IsPointInStrokePath, NV); |
|
269 GR_GL_GET_PROC_SUFFIX(GetPathLength, NV); |
|
270 GR_GL_GET_PROC_SUFFIX(PointAlongPath, NV); |
|
271 } |
|
272 |
|
273 if (extensions.has("GL_EXT_debug_marker")) { |
|
274 GR_GL_GET_PROC_SUFFIX(InsertEventMarker, EXT); |
|
275 GR_GL_GET_PROC_SUFFIX(PushGroupMarker, EXT); |
|
276 GR_GL_GET_PROC_SUFFIX(PopGroupMarker, EXT); |
|
277 } |
|
278 |
|
279 interface->fStandard = kGL_GrGLStandard; |
|
280 interface->fExtensions.swap(&extensions); |
|
281 |
|
282 return interface; |
|
283 } else { |
|
284 return NULL; |
|
285 } |
|
286 } |