• 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 
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         GrGLGetStringProc getString = (GrGLGetStringProc) OSMesaGetProcAddress("glGetString");
27         const char* versionString = (const char*) getString(GL_VERSION);
28         const char* extString = (const char*) getString(GL_EXTENSIONS);
29         GrGLVersion glVer = GrGLGetVersionFromString(versionString);
30 
31         if (glVer < GR_GL_VER(1,5)) {
32             // We must have array and element_array buffer objects.
33             return NULL;
34         }
35         GrGLInterface* interface = new GrGLInterface();
36 
37         GR_GL_GET_PROC(ActiveTexture);
38         GR_GL_GET_PROC(BeginQuery);
39         GR_GL_GET_PROC(AttachShader);
40         GR_GL_GET_PROC(BindAttribLocation);
41         GR_GL_GET_PROC(BindBuffer);
42         GR_GL_GET_PROC(BindFragDataLocation);
43         GR_GL_GET_PROC(BindTexture);
44         GR_GL_GET_PROC(BlendFunc);
45 
46         if (glVer >= GR_GL_VER(1,4) ||
47             GrGLHasExtensionFromString("GL_ARB_imaging", extString) ||
48             GrGLHasExtensionFromString("GL_EXT_blend_color", extString)) {
49             GR_GL_GET_PROC(BlendColor);
50         }
51 
52         GR_GL_GET_PROC(BufferData);
53         GR_GL_GET_PROC(BufferSubData);
54         GR_GL_GET_PROC(Clear);
55         GR_GL_GET_PROC(ClearColor);
56         GR_GL_GET_PROC(ClearStencil);
57         GR_GL_GET_PROC(ColorMask);
58         GR_GL_GET_PROC(CompileShader);
59         GR_GL_GET_PROC(CompressedTexImage2D);
60         GR_GL_GET_PROC(CreateProgram);
61         GR_GL_GET_PROC(CreateShader);
62         GR_GL_GET_PROC(CullFace);
63         GR_GL_GET_PROC(DeleteBuffers);
64         GR_GL_GET_PROC(DeleteProgram);
65         GR_GL_GET_PROC(DeleteQueries);
66         GR_GL_GET_PROC(DeleteShader);
67         GR_GL_GET_PROC(DeleteTextures);
68         GR_GL_GET_PROC(DepthMask);
69         GR_GL_GET_PROC(Disable);
70         GR_GL_GET_PROC(DisableVertexAttribArray);
71         GR_GL_GET_PROC(DrawArrays);
72         GR_GL_GET_PROC(DrawBuffer);
73         GR_GL_GET_PROC(DrawBuffers);
74         GR_GL_GET_PROC(DrawElements);
75         GR_GL_GET_PROC(Enable);
76         GR_GL_GET_PROC(EnableVertexAttribArray);
77         GR_GL_GET_PROC(EndQuery);
78         GR_GL_GET_PROC(Finish);
79         GR_GL_GET_PROC(Flush);
80         GR_GL_GET_PROC(FrontFace);
81         GR_GL_GET_PROC(GenBuffers);
82         GR_GL_GET_PROC(GenQueries);
83         GR_GL_GET_PROC(GetBufferParameteriv);
84         GR_GL_GET_PROC(GetError);
85         GR_GL_GET_PROC(GetIntegerv);
86         GR_GL_GET_PROC(GetProgramInfoLog);
87         GR_GL_GET_PROC(GetProgramiv);
88         if (glVer >= GR_GL_VER(3,3) ||
89             GrGLHasExtensionFromString("GL_ARB_timer_query", extString)) {
90             GR_GL_GET_PROC(GetQueryObjecti64v);
91             GR_GL_GET_PROC(GetQueryObjectui64v)
92             GR_GL_GET_PROC(QueryCounter);
93         } else if (GrGLHasExtensionFromString("GL_EXT_timer_query", extString)) {
94             GR_GL_GET_PROC_SUFFIX(GetQueryObjecti64v, EXT);
95             GR_GL_GET_PROC_SUFFIX(GetQueryObjectui64v, EXT);
96         }
97         GR_GL_GET_PROC(GetQueryObjectiv);
98         GR_GL_GET_PROC(GetQueryObjectuiv);
99         GR_GL_GET_PROC(GetQueryiv);
100         GR_GL_GET_PROC(GetShaderInfoLog);
101         GR_GL_GET_PROC(GetShaderiv);
102         GR_GL_GET_PROC(GetString);
103         GR_GL_GET_PROC(GetTexLevelParameteriv);
104         GR_GL_GET_PROC(GenTextures);
105         GR_GL_GET_PROC(GetUniformLocation);
106         GR_GL_GET_PROC(LineWidth);
107         GR_GL_GET_PROC(LinkProgram);
108         GR_GL_GET_PROC(MapBuffer);
109         GR_GL_GET_PROC(PixelStorei);
110         GR_GL_GET_PROC(ReadBuffer);
111         GR_GL_GET_PROC(ReadPixels);
112         GR_GL_GET_PROC(Scissor);
113         GR_GL_GET_PROC(ShaderSource);
114         GR_GL_GET_PROC(StencilFunc);
115         GR_GL_GET_PROC(StencilFuncSeparate);
116         GR_GL_GET_PROC(StencilMask);
117         GR_GL_GET_PROC(StencilMaskSeparate);
118         GR_GL_GET_PROC(StencilOp);
119         GR_GL_GET_PROC(StencilOpSeparate);
120         GR_GL_GET_PROC(TexImage2D)
121         GR_GL_GET_PROC(TexParameteri);
122         GR_GL_GET_PROC(TexParameteriv);
123         GR_GL_GET_PROC(TexStorage2D);
124         if (NULL == interface->fTexStorage2D) {
125             GR_GL_GET_PROC_SUFFIX(TexStorage2D, EXT);
126         }
127         GR_GL_GET_PROC(TexSubImage2D);
128         GR_GL_GET_PROC(Uniform1f);
129         GR_GL_GET_PROC(Uniform1i);
130         GR_GL_GET_PROC(Uniform1fv);
131         GR_GL_GET_PROC(Uniform1iv);
132         GR_GL_GET_PROC(Uniform2f);
133         GR_GL_GET_PROC(Uniform2i);
134         GR_GL_GET_PROC(Uniform2fv);
135         GR_GL_GET_PROC(Uniform2iv);
136         GR_GL_GET_PROC(Uniform3f);
137         GR_GL_GET_PROC(Uniform3i);
138         GR_GL_GET_PROC(Uniform3fv);
139         GR_GL_GET_PROC(Uniform3iv);
140         GR_GL_GET_PROC(Uniform4f);
141         GR_GL_GET_PROC(Uniform4i);
142         GR_GL_GET_PROC(Uniform4fv);
143         GR_GL_GET_PROC(Uniform4iv);
144         GR_GL_GET_PROC(UniformMatrix2fv);
145         GR_GL_GET_PROC(UniformMatrix3fv);
146         GR_GL_GET_PROC(UniformMatrix4fv);
147         GR_GL_GET_PROC(UnmapBuffer);
148         GR_GL_GET_PROC(UseProgram);
149         GR_GL_GET_PROC(VertexAttrib4fv);
150         GR_GL_GET_PROC(VertexAttribPointer);
151         GR_GL_GET_PROC(Viewport);
152 
153         // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
154         // GL_ARB_framebuffer_object doesn't use ARB suffix.)
155         if (glVer >= GR_GL_VER(3,0) ||
156             GrGLHasExtensionFromString("GL_ARB_framebuffer_object",
157                                         extString)) {
158             GR_GL_GET_PROC(GenFramebuffers);
159             GR_GL_GET_PROC(GetFramebufferAttachmentParameteriv);
160             GR_GL_GET_PROC(GetRenderbufferParameteriv);
161             GR_GL_GET_PROC(BindFramebuffer);
162             GR_GL_GET_PROC(FramebufferTexture2D);
163             GR_GL_GET_PROC(CheckFramebufferStatus);
164             GR_GL_GET_PROC(DeleteFramebuffers);
165             GR_GL_GET_PROC(RenderbufferStorage);
166             GR_GL_GET_PROC(GenRenderbuffers);
167             GR_GL_GET_PROC(DeleteRenderbuffers);
168             GR_GL_GET_PROC(FramebufferRenderbuffer);
169             GR_GL_GET_PROC(BindRenderbuffer);
170             GR_GL_GET_PROC(RenderbufferStorageMultisample);
171             GR_GL_GET_PROC(BlitFramebuffer);
172         } else if (GrGLHasExtensionFromString("GL_EXT_framebuffer_object",
173                                               extString)) {
174             GR_GL_GET_PROC_SUFFIX(GenFramebuffers, EXT);
175             GR_GL_GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
176             GR_GL_GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
177             GR_GL_GET_PROC_SUFFIX(BindFramebuffer, EXT);
178             GR_GL_GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
179             GR_GL_GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
180             GR_GL_GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
181             GR_GL_GET_PROC_SUFFIX(RenderbufferStorage, EXT);
182             GR_GL_GET_PROC_SUFFIX(GenRenderbuffers, EXT);
183             GR_GL_GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
184             GR_GL_GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
185             GR_GL_GET_PROC_SUFFIX(BindRenderbuffer, EXT);
186             if (GrGLHasExtensionFromString("GL_EXT_framebuffer_multisample",
187                                            extString)) {
188                 GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
189             }
190             if (GrGLHasExtensionFromString("GL_EXT_framebuffer_blit",
191                                            extString)) {
192                 GR_GL_GET_PROC_SUFFIX(BlitFramebuffer, EXT);
193             }
194         } else {
195             // we must have FBOs
196             delete interface;
197             return NULL;
198         }
199         GR_GL_GET_PROC(BindFragDataLocationIndexed);
200         interface->fBindingsExported = kDesktop_GrGLBinding;
201         return interface;
202     } else {
203         return NULL;
204     }
205 }
206