• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "gl/GrGLExtensions.h"
10 #include "gl/GrGLInterface.h"
11 #include "../GrGLUtil.h"
12 
13 #define GL_GLEXT_PROTOTYPES
14 #include "osmesa_wrapper.h"
15 
16 #define GR_GL_GET_PROC(F) interface->f ## F = (GrGL ## F ## Proc) \
17         OSMesaGetProcAddress("gl" #F);
18 #define GR_GL_GET_PROC_SUFFIX(F, S) interface->f ## F = (GrGL ## F ## Proc) \
19         OSMesaGetProcAddress("gl" #F #S);
20 
21 // We use OSMesaGetProcAddress for every gl function to avoid accidentally using
22 // non-Mesa gl functions.
23 
GrGLCreateMesaInterface()24 const GrGLInterface* GrGLCreateMesaInterface() {
25     if (NULL != OSMesaGetCurrentContext()) {
26 
27         GrGLGetStringProc getString = (GrGLGetStringProc) OSMesaGetProcAddress("glGetString");
28         GrGLGetStringiProc getStringi = (GrGLGetStringiProc) OSMesaGetProcAddress("glGetStringi");
29         GrGLGetIntegervProc getIntegerv =
30             (GrGLGetIntegervProc) OSMesaGetProcAddress("glGetIntegerv");
31 
32         GrGLExtensions extensions;
33         if (!extensions.init(kDesktop_GrGLBinding, getString, getStringi, getIntegerv)) {
34             return NULL;
35         }
36 
37         const char* versionString = (const char*) getString(GL_VERSION);
38         GrGLVersion glVer = GrGLGetVersionFromString(versionString);
39 
40         if (glVer < GR_GL_VER(1,5)) {
41             // We must have array and element_array buffer objects.
42             return NULL;
43         }
44         GrGLInterface* interface = new GrGLInterface();
45 
46         GR_GL_GET_PROC(ActiveTexture);
47         GR_GL_GET_PROC(BeginQuery);
48         GR_GL_GET_PROC(AttachShader);
49         GR_GL_GET_PROC(BindAttribLocation);
50         GR_GL_GET_PROC(BindBuffer);
51         GR_GL_GET_PROC(BindFragDataLocation);
52         GR_GL_GET_PROC(BindTexture);
53         GR_GL_GET_PROC(BlendFunc);
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         GR_GL_GET_PROC(Clear);
64         GR_GL_GET_PROC(ClearColor);
65         GR_GL_GET_PROC(ClearStencil);
66         GR_GL_GET_PROC(ClientActiveTexture);
67         GR_GL_GET_PROC(ColorMask);
68         GR_GL_GET_PROC(CompileShader);
69         GR_GL_GET_PROC(CompressedTexImage2D);
70         GR_GL_GET_PROC(CopyTexSubImage2D);
71         GR_GL_GET_PROC(CreateProgram);
72         GR_GL_GET_PROC(CreateShader);
73         GR_GL_GET_PROC(CullFace);
74         GR_GL_GET_PROC(DeleteBuffers);
75         GR_GL_GET_PROC(DeleteProgram);
76         GR_GL_GET_PROC(DeleteQueries);
77         GR_GL_GET_PROC(DeleteShader);
78         GR_GL_GET_PROC(DeleteTextures);
79         GR_GL_GET_PROC(DepthMask);
80         GR_GL_GET_PROC(Disable);
81         GR_GL_GET_PROC(DisableClientState);
82         GR_GL_GET_PROC(DisableVertexAttribArray);
83         GR_GL_GET_PROC(DrawArrays);
84         GR_GL_GET_PROC(DrawBuffer);
85         GR_GL_GET_PROC(DrawBuffers);
86         GR_GL_GET_PROC(DrawElements);
87         GR_GL_GET_PROC(Enable);
88         GR_GL_GET_PROC(EnableClientState);
89         GR_GL_GET_PROC(EnableVertexAttribArray);
90         GR_GL_GET_PROC(EndQuery);
91         GR_GL_GET_PROC(Finish);
92         GR_GL_GET_PROC(Flush);
93         GR_GL_GET_PROC(FrontFace);
94         GR_GL_GET_PROC(GenBuffers);
95         GR_GL_GET_PROC(GenerateMipmap);
96         GR_GL_GET_PROC(GenQueries);
97         GR_GL_GET_PROC(GetBufferParameteriv);
98         GR_GL_GET_PROC(GetError);
99         GR_GL_GET_PROC(GetIntegerv);
100         GR_GL_GET_PROC(GetProgramInfoLog);
101         GR_GL_GET_PROC(GetProgramiv);
102         if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) {
103             GR_GL_GET_PROC(GetQueryObjecti64v);
104             GR_GL_GET_PROC(GetQueryObjectui64v)
105             GR_GL_GET_PROC(QueryCounter);
106         } else if (extensions.has("GL_EXT_timer_query")) {
107             GR_GL_GET_PROC_SUFFIX(GetQueryObjecti64v, EXT);
108             GR_GL_GET_PROC_SUFFIX(GetQueryObjectui64v, EXT);
109         }
110         GR_GL_GET_PROC(GetQueryObjectiv);
111         GR_GL_GET_PROC(GetQueryObjectuiv);
112         GR_GL_GET_PROC(GetQueryiv);
113         GR_GL_GET_PROC(GetShaderInfoLog);
114         GR_GL_GET_PROC(GetShaderiv);
115         GR_GL_GET_PROC(GetString);
116         GR_GL_GET_PROC(GetStringi);
117         GR_GL_GET_PROC(GetTexLevelParameteriv);
118         GR_GL_GET_PROC(GenTextures);
119         GR_GL_GET_PROC(GetUniformLocation);
120         GR_GL_GET_PROC(LineWidth);
121         GR_GL_GET_PROC(LinkProgram);
122         GR_GL_GET_PROC(LoadIdentity);
123         GR_GL_GET_PROC(LoadMatrixf);
124         GR_GL_GET_PROC(MatrixMode);
125         GR_GL_GET_PROC(MapBuffer);
126         GR_GL_GET_PROC(PixelStorei);
127         GR_GL_GET_PROC(ReadBuffer);
128         GR_GL_GET_PROC(ReadPixels);
129         GR_GL_GET_PROC(Scissor);
130         GR_GL_GET_PROC(ShaderSource);
131         GR_GL_GET_PROC(StencilFunc);
132         GR_GL_GET_PROC(StencilFuncSeparate);
133         GR_GL_GET_PROC(StencilMask);
134         GR_GL_GET_PROC(StencilMaskSeparate);
135         GR_GL_GET_PROC(StencilOp);
136         GR_GL_GET_PROC(StencilOpSeparate);
137         GR_GL_GET_PROC(TexGenf);
138         GR_GL_GET_PROC(TexGenfv);
139         GR_GL_GET_PROC(TexGeni);
140         GR_GL_GET_PROC(TexImage2D)
141         GR_GL_GET_PROC(TexParameteri);
142         GR_GL_GET_PROC(TexParameteriv);
143         GR_GL_GET_PROC(TexStorage2D);
144         if (NULL == interface->fTexStorage2D) {
145             GR_GL_GET_PROC_SUFFIX(TexStorage2D, EXT);
146         }
147         GR_GL_GET_PROC(TexSubImage2D);
148         GR_GL_GET_PROC(Uniform1f);
149         GR_GL_GET_PROC(Uniform1i);
150         GR_GL_GET_PROC(Uniform1fv);
151         GR_GL_GET_PROC(Uniform1iv);
152         GR_GL_GET_PROC(Uniform2f);
153         GR_GL_GET_PROC(Uniform2i);
154         GR_GL_GET_PROC(Uniform2fv);
155         GR_GL_GET_PROC(Uniform2iv);
156         GR_GL_GET_PROC(Uniform3f);
157         GR_GL_GET_PROC(Uniform3i);
158         GR_GL_GET_PROC(Uniform3fv);
159         GR_GL_GET_PROC(Uniform3iv);
160         GR_GL_GET_PROC(Uniform4f);
161         GR_GL_GET_PROC(Uniform4i);
162         GR_GL_GET_PROC(Uniform4fv);
163         GR_GL_GET_PROC(Uniform4iv);
164         GR_GL_GET_PROC(UniformMatrix2fv);
165         GR_GL_GET_PROC(UniformMatrix3fv);
166         GR_GL_GET_PROC(UniformMatrix4fv);
167         GR_GL_GET_PROC(UnmapBuffer);
168         GR_GL_GET_PROC(UseProgram);
169         GR_GL_GET_PROC(VertexAttrib4fv);
170         GR_GL_GET_PROC(VertexAttribPointer);
171         GR_GL_GET_PROC(VertexPointer);
172         GR_GL_GET_PROC(Viewport);
173 
174         if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object")) {
175             // no ARB suffix for GL_ARB_vertex_array_object
176             GR_GL_GET_PROC(BindVertexArray);
177             GR_GL_GET_PROC(DeleteVertexArrays);
178             GR_GL_GET_PROC(GenVertexArrays);
179         }
180 
181         // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
182         // GL_ARB_framebuffer_object doesn't use ARB suffix.)
183         if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) {
184             GR_GL_GET_PROC(GenFramebuffers);
185             GR_GL_GET_PROC(GetFramebufferAttachmentParameteriv);
186             GR_GL_GET_PROC(GetRenderbufferParameteriv);
187             GR_GL_GET_PROC(BindFramebuffer);
188             GR_GL_GET_PROC(FramebufferTexture2D);
189             GR_GL_GET_PROC(CheckFramebufferStatus);
190             GR_GL_GET_PROC(DeleteFramebuffers);
191             GR_GL_GET_PROC(RenderbufferStorage);
192             GR_GL_GET_PROC(GenRenderbuffers);
193             GR_GL_GET_PROC(DeleteRenderbuffers);
194             GR_GL_GET_PROC(FramebufferRenderbuffer);
195             GR_GL_GET_PROC(BindRenderbuffer);
196             GR_GL_GET_PROC(RenderbufferStorageMultisample);
197             GR_GL_GET_PROC(BlitFramebuffer);
198         } else if (extensions.has("GL_EXT_framebuffer_object")) {
199             GR_GL_GET_PROC_SUFFIX(GenFramebuffers, EXT);
200             GR_GL_GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
201             GR_GL_GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
202             GR_GL_GET_PROC_SUFFIX(BindFramebuffer, EXT);
203             GR_GL_GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
204             GR_GL_GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
205             GR_GL_GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
206             GR_GL_GET_PROC_SUFFIX(RenderbufferStorage, EXT);
207             GR_GL_GET_PROC_SUFFIX(GenRenderbuffers, EXT);
208             GR_GL_GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
209             GR_GL_GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
210             GR_GL_GET_PROC_SUFFIX(BindRenderbuffer, EXT);
211             if (extensions.has("GL_EXT_framebuffer_multisample")) {
212                 GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
213             }
214             if (extensions.has("GL_EXT_framebuffer_blit")) {
215                 GR_GL_GET_PROC_SUFFIX(BlitFramebuffer, EXT);
216             }
217         } else {
218             // we must have FBOs
219             delete interface;
220             return NULL;
221         }
222         GR_GL_GET_PROC(BindFragDataLocationIndexed);
223         interface->fBindingsExported = kDesktop_GrGLBinding;
224         return interface;
225     } else {
226         return NULL;
227     }
228 }
229