blob: 7736d954eeb60019130067c112904037124109fa [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
bungeman@google.com0e454412011-05-19 17:47:02 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.
bungeman@google.com0e454412011-05-19 17:47:02 +00007 */
8
bsalomon@google.com1744f972013-02-26 21:46:32 +00009#include "gl/GrGLExtensions.h"
tomhudson@google.com6c8c34e2012-02-14 15:31:03 +000010#include "gl/GrGLInterface.h"
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +000011#include "../GrGLUtil.h"
bungeman@google.com0e454412011-05-19 17:47:02 +000012
bsalomon@google.com373a6632011-10-19 20:43:20 +000013#define GL_GLEXT_PROTOTYPES
bsalomon@google.com6f476632013-01-08 16:33:41 +000014#include "osmesa_wrapper.h"
bungeman@google.com0e454412011-05-19 17:47:02 +000015
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +000016#define GR_GL_GET_PROC(F) interface->fFunctions.f ## F = (GrGL ## F ## Proc) \
bungeman@google.com0e454412011-05-19 17:47:02 +000017 OSMesaGetProcAddress("gl" #F);
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +000018#define GR_GL_GET_PROC_SUFFIX(F, S) interface->fFunctions.f ## F = (GrGL ## F ## Proc) \
bungeman@google.com0e454412011-05-19 17:47:02 +000019 OSMesaGetProcAddress("gl" #F #S);
20
bsalomon@google.com373a6632011-10-19 20:43:20 +000021// We use OSMesaGetProcAddress for every gl function to avoid accidentally using
22// non-Mesa gl functions.
23
24const GrGLInterface* GrGLCreateMesaInterface() {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000025 if (NULL != OSMesaGetCurrentContext()) {
bsalomon@google.com1744f972013-02-26 21:46:32 +000026
bsalomon@google.comdf8114d2013-03-01 18:10:41 +000027 GrGLGetStringProc getString = (GrGLGetStringProc) OSMesaGetProcAddress("glGetString");
28 GrGLGetStringiProc getStringi = (GrGLGetStringiProc) OSMesaGetProcAddress("glGetStringi");
29 GrGLGetIntegervProc getIntegerv =
30 (GrGLGetIntegervProc) OSMesaGetProcAddress("glGetIntegerv");
bsalomon@google.com1744f972013-02-26 21:46:32 +000031
32 GrGLExtensions extensions;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000033 if (!extensions.init(kGL_GrGLStandard, getString, getStringi, getIntegerv)) {
bsalomon@google.com1744f972013-02-26 21:46:32 +000034 return NULL;
35 }
36
bsalomon@google.com373a6632011-10-19 20:43:20 +000037 const char* versionString = (const char*) getString(GL_VERSION);
bsalomon@google.comc82b8892011-09-22 14:10:33 +000038 GrGLVersion glVer = GrGLGetVersionFromString(versionString);
bungeman@google.com0e454412011-05-19 17:47:02 +000039
bsalomon@google.comc82b8892011-09-22 14:10:33 +000040 if (glVer < GR_GL_VER(1,5)) {
bungeman@google.com0e454412011-05-19 17:47:02 +000041 // We must have array and element_array buffer objects.
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000042 return NULL;
bungeman@google.com0e454412011-05-19 17:47:02 +000043 }
commit-bot@chromium.orga3b15ed2014-01-15 19:32:03 +000044 GrGLInterface* interface = SkNEW(GrGLInterface());
bungeman@google.com0e454412011-05-19 17:47:02 +000045
bsalomon@google.com373a6632011-10-19 20:43:20 +000046 GR_GL_GET_PROC(ActiveTexture);
47 GR_GL_GET_PROC(BeginQuery);
bungeman@google.com0e454412011-05-19 17:47:02 +000048 GR_GL_GET_PROC(AttachShader);
49 GR_GL_GET_PROC(BindAttribLocation);
50 GR_GL_GET_PROC(BindBuffer);
bsalomon@google.combc5cf512011-09-21 16:21:07 +000051 GR_GL_GET_PROC(BindFragDataLocation);
bsalomon@google.com373a6632011-10-19 20:43:20 +000052 GR_GL_GET_PROC(BindTexture);
bsalomon@google.com373a6632011-10-19 20:43:20 +000053 GR_GL_GET_PROC(BlendFunc);
robertphillips@google.come7884302012-04-18 14:39:58 +000054
55 if (glVer >= GR_GL_VER(1,4) ||
bsalomon@google.com1744f972013-02-26 21:46:32 +000056 extensions.has("GL_ARB_imaging") ||
57 extensions.has("GL_EXT_blend_color")) {
robertphillips@google.come7884302012-04-18 14:39:58 +000058 GR_GL_GET_PROC(BlendColor);
bsalomon@google.com0efcc372012-06-08 20:36:22 +000059 }
robertphillips@google.come7884302012-04-18 14:39:58 +000060
bungeman@google.com0e454412011-05-19 17:47:02 +000061 GR_GL_GET_PROC(BufferData);
62 GR_GL_GET_PROC(BufferSubData);
bsalomon@google.com373a6632011-10-19 20:43:20 +000063 GR_GL_GET_PROC(Clear);
64 GR_GL_GET_PROC(ClearColor);
65 GR_GL_GET_PROC(ClearStencil);
bsalomon@google.com373a6632011-10-19 20:43:20 +000066 GR_GL_GET_PROC(ColorMask);
bungeman@google.com0e454412011-05-19 17:47:02 +000067 GR_GL_GET_PROC(CompileShader);
bsalomon@google.com373a6632011-10-19 20:43:20 +000068 GR_GL_GET_PROC(CompressedTexImage2D);
commit-bot@chromium.org98168bb2013-04-11 22:00:34 +000069 GR_GL_GET_PROC(CopyTexSubImage2D);
bungeman@google.com0e454412011-05-19 17:47:02 +000070 GR_GL_GET_PROC(CreateProgram);
71 GR_GL_GET_PROC(CreateShader);
bsalomon@google.com373a6632011-10-19 20:43:20 +000072 GR_GL_GET_PROC(CullFace);
bungeman@google.com0e454412011-05-19 17:47:02 +000073 GR_GL_GET_PROC(DeleteBuffers);
74 GR_GL_GET_PROC(DeleteProgram);
bsalomon@google.com373a6632011-10-19 20:43:20 +000075 GR_GL_GET_PROC(DeleteQueries);
bungeman@google.com0e454412011-05-19 17:47:02 +000076 GR_GL_GET_PROC(DeleteShader);
bsalomon@google.com373a6632011-10-19 20:43:20 +000077 GR_GL_GET_PROC(DeleteTextures);
78 GR_GL_GET_PROC(DepthMask);
79 GR_GL_GET_PROC(Disable);
bungeman@google.com0e454412011-05-19 17:47:02 +000080 GR_GL_GET_PROC(DisableVertexAttribArray);
bsalomon@google.com373a6632011-10-19 20:43:20 +000081 GR_GL_GET_PROC(DrawArrays);
82 GR_GL_GET_PROC(DrawBuffer);
bsalomon@google.comd32c5f52011-08-02 19:29:03 +000083 GR_GL_GET_PROC(DrawBuffers);
bsalomon@google.com373a6632011-10-19 20:43:20 +000084 GR_GL_GET_PROC(DrawElements);
85 GR_GL_GET_PROC(Enable);
bungeman@google.com0e454412011-05-19 17:47:02 +000086 GR_GL_GET_PROC(EnableVertexAttribArray);
bsalomon@google.com373a6632011-10-19 20:43:20 +000087 GR_GL_GET_PROC(EndQuery);
88 GR_GL_GET_PROC(Finish);
89 GR_GL_GET_PROC(Flush);
90 GR_GL_GET_PROC(FrontFace);
bungeman@google.com0e454412011-05-19 17:47:02 +000091 GR_GL_GET_PROC(GenBuffers);
commit-bot@chromium.orgcffff792013-07-26 16:36:04 +000092 GR_GL_GET_PROC(GenerateMipmap);
bsalomon@google.com373a6632011-10-19 20:43:20 +000093 GR_GL_GET_PROC(GenQueries);
bungeman@google.com0e454412011-05-19 17:47:02 +000094 GR_GL_GET_PROC(GetBufferParameteriv);
bsalomon@google.com373a6632011-10-19 20:43:20 +000095 GR_GL_GET_PROC(GetError);
96 GR_GL_GET_PROC(GetIntegerv);
bungeman@google.com0e454412011-05-19 17:47:02 +000097 GR_GL_GET_PROC(GetProgramInfoLog);
98 GR_GL_GET_PROC(GetProgramiv);
bsalomon@google.com1744f972013-02-26 21:46:32 +000099 if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) {
bsalomon@google.com373a6632011-10-19 20:43:20 +0000100 GR_GL_GET_PROC(GetQueryObjecti64v);
101 GR_GL_GET_PROC(GetQueryObjectui64v)
102 GR_GL_GET_PROC(QueryCounter);
bsalomon@google.com1744f972013-02-26 21:46:32 +0000103 } else if (extensions.has("GL_EXT_timer_query")) {
bsalomon@google.comf97c1942011-10-19 21:35:26 +0000104 GR_GL_GET_PROC_SUFFIX(GetQueryObjecti64v, EXT);
105 GR_GL_GET_PROC_SUFFIX(GetQueryObjectui64v, EXT);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000106 }
107 GR_GL_GET_PROC(GetQueryObjectiv);
108 GR_GL_GET_PROC(GetQueryObjectuiv);
109 GR_GL_GET_PROC(GetQueryiv);
bungeman@google.com0e454412011-05-19 17:47:02 +0000110 GR_GL_GET_PROC(GetShaderInfoLog);
111 GR_GL_GET_PROC(GetShaderiv);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000112 GR_GL_GET_PROC(GetString);
bsalomon@google.com1744f972013-02-26 21:46:32 +0000113 GR_GL_GET_PROC(GetStringi);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000114 GR_GL_GET_PROC(GetTexLevelParameteriv);
115 GR_GL_GET_PROC(GenTextures);
bungeman@google.com0e454412011-05-19 17:47:02 +0000116 GR_GL_GET_PROC(GetUniformLocation);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000117 GR_GL_GET_PROC(LineWidth);
bungeman@google.com0e454412011-05-19 17:47:02 +0000118 GR_GL_GET_PROC(LinkProgram);
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000119 GR_GL_GET_PROC(LoadIdentity);
120 GR_GL_GET_PROC(LoadMatrixf);
121 GR_GL_GET_PROC(MatrixMode);
bungeman@google.com0e454412011-05-19 17:47:02 +0000122 GR_GL_GET_PROC(MapBuffer);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000123 GR_GL_GET_PROC(PixelStorei);
124 GR_GL_GET_PROC(ReadBuffer);
125 GR_GL_GET_PROC(ReadPixels);
126 GR_GL_GET_PROC(Scissor);
bungeman@google.com0e454412011-05-19 17:47:02 +0000127 GR_GL_GET_PROC(ShaderSource);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000128 GR_GL_GET_PROC(StencilFunc);
bungeman@google.com0e454412011-05-19 17:47:02 +0000129 GR_GL_GET_PROC(StencilFuncSeparate);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000130 GR_GL_GET_PROC(StencilMask);
bungeman@google.com0e454412011-05-19 17:47:02 +0000131 GR_GL_GET_PROC(StencilMaskSeparate);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000132 GR_GL_GET_PROC(StencilOp);
bungeman@google.com0e454412011-05-19 17:47:02 +0000133 GR_GL_GET_PROC(StencilOpSeparate);
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000134 GR_GL_GET_PROC(TexGenfv);
135 GR_GL_GET_PROC(TexGeni);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000136 GR_GL_GET_PROC(TexImage2D)
137 GR_GL_GET_PROC(TexParameteri);
bsalomon@google.com6f6efa92012-05-31 18:09:11 +0000138 GR_GL_GET_PROC(TexParameteriv);
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000139 GR_GL_GET_PROC(TexStorage2D);
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000140 if (NULL == interface->fFunctions.fTexStorage2D) {
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000141 GR_GL_GET_PROC_SUFFIX(TexStorage2D, EXT);
142 }
bsalomon@google.com373a6632011-10-19 20:43:20 +0000143 GR_GL_GET_PROC(TexSubImage2D);
bungeman@google.com0e454412011-05-19 17:47:02 +0000144 GR_GL_GET_PROC(Uniform1f);
145 GR_GL_GET_PROC(Uniform1i);
146 GR_GL_GET_PROC(Uniform1fv);
147 GR_GL_GET_PROC(Uniform1iv);
148 GR_GL_GET_PROC(Uniform2f);
149 GR_GL_GET_PROC(Uniform2i);
150 GR_GL_GET_PROC(Uniform2fv);
151 GR_GL_GET_PROC(Uniform2iv);
152 GR_GL_GET_PROC(Uniform3f);
153 GR_GL_GET_PROC(Uniform3i);
154 GR_GL_GET_PROC(Uniform3fv);
155 GR_GL_GET_PROC(Uniform3iv);
156 GR_GL_GET_PROC(Uniform4f);
157 GR_GL_GET_PROC(Uniform4i);
158 GR_GL_GET_PROC(Uniform4fv);
159 GR_GL_GET_PROC(Uniform4iv);
160 GR_GL_GET_PROC(UniformMatrix2fv);
161 GR_GL_GET_PROC(UniformMatrix3fv);
162 GR_GL_GET_PROC(UniformMatrix4fv);
163 GR_GL_GET_PROC(UnmapBuffer);
164 GR_GL_GET_PROC(UseProgram);
165 GR_GL_GET_PROC(VertexAttrib4fv);
166 GR_GL_GET_PROC(VertexAttribPointer);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000167 GR_GL_GET_PROC(Viewport);
bungeman@google.com0e454412011-05-19 17:47:02 +0000168
bsalomon@google.comecd84842013-03-01 15:36:02 +0000169 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 GR_GL_GET_PROC(BindVertexArray);
172 GR_GL_GET_PROC(DeleteVertexArrays);
173 GR_GL_GET_PROC(GenVertexArrays);
174 }
175
bungeman@google.com0e454412011-05-19 17:47:02 +0000176 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
177 // GL_ARB_framebuffer_object doesn't use ARB suffix.)
bsalomon@google.com1744f972013-02-26 21:46:32 +0000178 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) {
bungeman@google.com0e454412011-05-19 17:47:02 +0000179 GR_GL_GET_PROC(GenFramebuffers);
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000180 GR_GL_GET_PROC(GetFramebufferAttachmentParameteriv);
181 GR_GL_GET_PROC(GetRenderbufferParameteriv);
bungeman@google.com0e454412011-05-19 17:47:02 +0000182 GR_GL_GET_PROC(BindFramebuffer);
183 GR_GL_GET_PROC(FramebufferTexture2D);
184 GR_GL_GET_PROC(CheckFramebufferStatus);
185 GR_GL_GET_PROC(DeleteFramebuffers);
186 GR_GL_GET_PROC(RenderbufferStorage);
187 GR_GL_GET_PROC(GenRenderbuffers);
188 GR_GL_GET_PROC(DeleteRenderbuffers);
189 GR_GL_GET_PROC(FramebufferRenderbuffer);
190 GR_GL_GET_PROC(BindRenderbuffer);
191 GR_GL_GET_PROC(RenderbufferStorageMultisample);
192 GR_GL_GET_PROC(BlitFramebuffer);
bsalomon@google.com1744f972013-02-26 21:46:32 +0000193 } else if (extensions.has("GL_EXT_framebuffer_object")) {
bungeman@google.com0e454412011-05-19 17:47:02 +0000194 GR_GL_GET_PROC_SUFFIX(GenFramebuffers, EXT);
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000195 GR_GL_GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
196 GR_GL_GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
bungeman@google.com0e454412011-05-19 17:47:02 +0000197 GR_GL_GET_PROC_SUFFIX(BindFramebuffer, EXT);
198 GR_GL_GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
199 GR_GL_GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
200 GR_GL_GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
201 GR_GL_GET_PROC_SUFFIX(RenderbufferStorage, EXT);
202 GR_GL_GET_PROC_SUFFIX(GenRenderbuffers, EXT);
203 GR_GL_GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
204 GR_GL_GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
205 GR_GL_GET_PROC_SUFFIX(BindRenderbuffer, EXT);
bsalomon@google.com1744f972013-02-26 21:46:32 +0000206 if (extensions.has("GL_EXT_framebuffer_multisample")) {
bungeman@google.com0e454412011-05-19 17:47:02 +0000207 GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
208 }
bsalomon@google.com1744f972013-02-26 21:46:32 +0000209 if (extensions.has("GL_EXT_framebuffer_blit")) {
bungeman@google.com0e454412011-05-19 17:47:02 +0000210 GR_GL_GET_PROC_SUFFIX(BlitFramebuffer, EXT);
211 }
212 } else {
213 // we must have FBOs
bsalomon@google.com6fb736f2011-09-16 18:51:57 +0000214 delete interface;
215 return NULL;
bungeman@google.com0e454412011-05-19 17:47:02 +0000216 }
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000217 GR_GL_GET_PROC(BindFragDataLocationIndexed);
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000218
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000219 if (extensions.has("GL_EXT_debug_marker")) {
220 GR_GL_GET_PROC_SUFFIX(InsertEventMarker, EXT);
221 GR_GL_GET_PROC_SUFFIX(PopGroupMarker, EXT);
222 GR_GL_GET_PROC_SUFFIX(PushGroupMarker, EXT);
223 }
224
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000225 interface->fStandard = kGL_GrGLStandard;
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000226 interface->fExtensions.swap(&extensions);
227
bsalomon@google.com6fb736f2011-09-16 18:51:57 +0000228 return interface;
229 } else {
230 return NULL;
bungeman@google.com0e454412011-05-19 17:47:02 +0000231 }
bungeman@google.com0e454412011-05-19 17:47:02 +0000232}