blob: 2f712e365083e249864e548fa8d7e90a66c63445 [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
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
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
14#include <GL/osmesa.h>
bungeman@google.com0e454412011-05-19 17:47:02 +000015
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000016#define GR_GL_GET_PROC(F) interface->f ## F = (GrGL ## F ## Proc) \
bungeman@google.com0e454412011-05-19 17:47:02 +000017 OSMesaGetProcAddress("gl" #F);
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000018#define GR_GL_GET_PROC_SUFFIX(F, S) interface->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.com373a6632011-10-19 20:43:20 +000026 GrGLGetStringProc getString = (GrGLGetStringProc) OSMesaGetProcAddress("glGetString");
27 const char* versionString = (const char*) getString(GL_VERSION);
28 const char* extString = (const char*) getString(GL_EXTENSIONS);
bsalomon@google.comc82b8892011-09-22 14:10:33 +000029 GrGLVersion glVer = GrGLGetVersionFromString(versionString);
bungeman@google.com0e454412011-05-19 17:47:02 +000030
bsalomon@google.comc82b8892011-09-22 14:10:33 +000031 if (glVer < GR_GL_VER(1,5)) {
bungeman@google.com0e454412011-05-19 17:47:02 +000032 // We must have array and element_array buffer objects.
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000033 return NULL;
bungeman@google.com0e454412011-05-19 17:47:02 +000034 }
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000035 GrGLInterface* interface = new GrGLInterface();
bungeman@google.com0e454412011-05-19 17:47:02 +000036
bsalomon@google.com373a6632011-10-19 20:43:20 +000037 GR_GL_GET_PROC(ActiveTexture);
38 GR_GL_GET_PROC(BeginQuery);
bungeman@google.com0e454412011-05-19 17:47:02 +000039 GR_GL_GET_PROC(AttachShader);
40 GR_GL_GET_PROC(BindAttribLocation);
41 GR_GL_GET_PROC(BindBuffer);
bsalomon@google.combc5cf512011-09-21 16:21:07 +000042 GR_GL_GET_PROC(BindFragDataLocation);
bsalomon@google.com373a6632011-10-19 20:43:20 +000043 GR_GL_GET_PROC(BindTexture);
bsalomon@google.com373a6632011-10-19 20:43:20 +000044 GR_GL_GET_PROC(BlendFunc);
robertphillips@google.come7884302012-04-18 14:39:58 +000045
46 if (glVer >= GR_GL_VER(1,4) ||
bsalomon@google.com0efcc372012-06-08 20:36:22 +000047 GrGLHasExtensionFromString("GL_ARB_imaging", extString) ||
48 GrGLHasExtensionFromString("GL_EXT_blend_color", extString)) {
robertphillips@google.come7884302012-04-18 14:39:58 +000049 GR_GL_GET_PROC(BlendColor);
bsalomon@google.com0efcc372012-06-08 20:36:22 +000050 }
robertphillips@google.come7884302012-04-18 14:39:58 +000051
bungeman@google.com0e454412011-05-19 17:47:02 +000052 GR_GL_GET_PROC(BufferData);
53 GR_GL_GET_PROC(BufferSubData);
bsalomon@google.com373a6632011-10-19 20:43:20 +000054 GR_GL_GET_PROC(Clear);
55 GR_GL_GET_PROC(ClearColor);
56 GR_GL_GET_PROC(ClearStencil);
bsalomon@google.com373a6632011-10-19 20:43:20 +000057 GR_GL_GET_PROC(ColorMask);
bungeman@google.com0e454412011-05-19 17:47:02 +000058 GR_GL_GET_PROC(CompileShader);
bsalomon@google.com373a6632011-10-19 20:43:20 +000059 GR_GL_GET_PROC(CompressedTexImage2D);
bungeman@google.com0e454412011-05-19 17:47:02 +000060 GR_GL_GET_PROC(CreateProgram);
61 GR_GL_GET_PROC(CreateShader);
bsalomon@google.com373a6632011-10-19 20:43:20 +000062 GR_GL_GET_PROC(CullFace);
bungeman@google.com0e454412011-05-19 17:47:02 +000063 GR_GL_GET_PROC(DeleteBuffers);
64 GR_GL_GET_PROC(DeleteProgram);
bsalomon@google.com373a6632011-10-19 20:43:20 +000065 GR_GL_GET_PROC(DeleteQueries);
bungeman@google.com0e454412011-05-19 17:47:02 +000066 GR_GL_GET_PROC(DeleteShader);
bsalomon@google.com373a6632011-10-19 20:43:20 +000067 GR_GL_GET_PROC(DeleteTextures);
68 GR_GL_GET_PROC(DepthMask);
69 GR_GL_GET_PROC(Disable);
bungeman@google.com0e454412011-05-19 17:47:02 +000070 GR_GL_GET_PROC(DisableVertexAttribArray);
bsalomon@google.com373a6632011-10-19 20:43:20 +000071 GR_GL_GET_PROC(DrawArrays);
72 GR_GL_GET_PROC(DrawBuffer);
bsalomon@google.comd32c5f52011-08-02 19:29:03 +000073 GR_GL_GET_PROC(DrawBuffers);
bsalomon@google.com373a6632011-10-19 20:43:20 +000074 GR_GL_GET_PROC(DrawElements);
75 GR_GL_GET_PROC(Enable);
bungeman@google.com0e454412011-05-19 17:47:02 +000076 GR_GL_GET_PROC(EnableVertexAttribArray);
bsalomon@google.com373a6632011-10-19 20:43:20 +000077 GR_GL_GET_PROC(EndQuery);
78 GR_GL_GET_PROC(Finish);
79 GR_GL_GET_PROC(Flush);
80 GR_GL_GET_PROC(FrontFace);
bungeman@google.com0e454412011-05-19 17:47:02 +000081 GR_GL_GET_PROC(GenBuffers);
bsalomon@google.com373a6632011-10-19 20:43:20 +000082 GR_GL_GET_PROC(GenQueries);
bungeman@google.com0e454412011-05-19 17:47:02 +000083 GR_GL_GET_PROC(GetBufferParameteriv);
bsalomon@google.com373a6632011-10-19 20:43:20 +000084 GR_GL_GET_PROC(GetError);
85 GR_GL_GET_PROC(GetIntegerv);
bungeman@google.com0e454412011-05-19 17:47:02 +000086 GR_GL_GET_PROC(GetProgramInfoLog);
87 GR_GL_GET_PROC(GetProgramiv);
bsalomon@google.com373a6632011-10-19 20:43:20 +000088 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)) {
bsalomon@google.comf97c1942011-10-19 21:35:26 +000094 GR_GL_GET_PROC_SUFFIX(GetQueryObjecti64v, EXT);
95 GR_GL_GET_PROC_SUFFIX(GetQueryObjectui64v, EXT);
bsalomon@google.com373a6632011-10-19 20:43:20 +000096 }
97 GR_GL_GET_PROC(GetQueryObjectiv);
98 GR_GL_GET_PROC(GetQueryObjectuiv);
99 GR_GL_GET_PROC(GetQueryiv);
bungeman@google.com0e454412011-05-19 17:47:02 +0000100 GR_GL_GET_PROC(GetShaderInfoLog);
101 GR_GL_GET_PROC(GetShaderiv);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000102 GR_GL_GET_PROC(GetString);
103 GR_GL_GET_PROC(GetTexLevelParameteriv);
104 GR_GL_GET_PROC(GenTextures);
bungeman@google.com0e454412011-05-19 17:47:02 +0000105 GR_GL_GET_PROC(GetUniformLocation);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000106 GR_GL_GET_PROC(LineWidth);
bungeman@google.com0e454412011-05-19 17:47:02 +0000107 GR_GL_GET_PROC(LinkProgram);
bungeman@google.com0e454412011-05-19 17:47:02 +0000108 GR_GL_GET_PROC(MapBuffer);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000109 GR_GL_GET_PROC(PixelStorei);
110 GR_GL_GET_PROC(ReadBuffer);
111 GR_GL_GET_PROC(ReadPixels);
112 GR_GL_GET_PROC(Scissor);
bungeman@google.com0e454412011-05-19 17:47:02 +0000113 GR_GL_GET_PROC(ShaderSource);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000114 GR_GL_GET_PROC(StencilFunc);
bungeman@google.com0e454412011-05-19 17:47:02 +0000115 GR_GL_GET_PROC(StencilFuncSeparate);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000116 GR_GL_GET_PROC(StencilMask);
bungeman@google.com0e454412011-05-19 17:47:02 +0000117 GR_GL_GET_PROC(StencilMaskSeparate);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000118 GR_GL_GET_PROC(StencilOp);
bungeman@google.com0e454412011-05-19 17:47:02 +0000119 GR_GL_GET_PROC(StencilOpSeparate);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000120 GR_GL_GET_PROC(TexImage2D)
121 GR_GL_GET_PROC(TexParameteri);
bsalomon@google.com6f6efa92012-05-31 18:09:11 +0000122 GR_GL_GET_PROC(TexParameteriv);
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000123 GR_GL_GET_PROC(TexStorage2D);
124 if (NULL == interface->fTexStorage2D) {
125 GR_GL_GET_PROC_SUFFIX(TexStorage2D, EXT);
126 }
bsalomon@google.com373a6632011-10-19 20:43:20 +0000127 GR_GL_GET_PROC(TexSubImage2D);
bungeman@google.com0e454412011-05-19 17:47:02 +0000128 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);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000151 GR_GL_GET_PROC(Viewport);
bungeman@google.com0e454412011-05-19 17:47:02 +0000152
153 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
154 // GL_ARB_framebuffer_object doesn't use ARB suffix.)
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000155 if (glVer >= GR_GL_VER(3,0) ||
156 GrGLHasExtensionFromString("GL_ARB_framebuffer_object",
157 extString)) {
bungeman@google.com0e454412011-05-19 17:47:02 +0000158 GR_GL_GET_PROC(GenFramebuffers);
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000159 GR_GL_GET_PROC(GetFramebufferAttachmentParameteriv);
160 GR_GL_GET_PROC(GetRenderbufferParameteriv);
bungeman@google.com0e454412011-05-19 17:47:02 +0000161 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);
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000172 } else if (GrGLHasExtensionFromString("GL_EXT_framebuffer_object",
173 extString)) {
bungeman@google.com0e454412011-05-19 17:47:02 +0000174 GR_GL_GET_PROC_SUFFIX(GenFramebuffers, EXT);
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000175 GR_GL_GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
176 GR_GL_GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
bungeman@google.com0e454412011-05-19 17:47:02 +0000177 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);
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000186 if (GrGLHasExtensionFromString("GL_EXT_framebuffer_multisample",
187 extString)) {
bungeman@google.com0e454412011-05-19 17:47:02 +0000188 GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
189 }
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000190 if (GrGLHasExtensionFromString("GL_EXT_framebuffer_blit",
191 extString)) {
bungeman@google.com0e454412011-05-19 17:47:02 +0000192 GR_GL_GET_PROC_SUFFIX(BlitFramebuffer, EXT);
193 }
194 } else {
195 // we must have FBOs
bsalomon@google.com6fb736f2011-09-16 18:51:57 +0000196 delete interface;
197 return NULL;
bungeman@google.com0e454412011-05-19 17:47:02 +0000198 }
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000199 GR_GL_GET_PROC(BindFragDataLocationIndexed);
bsalomon@google.com6fb736f2011-09-16 18:51:57 +0000200 interface->fBindingsExported = kDesktop_GrGLBinding;
201 return interface;
202 } else {
203 return NULL;
bungeman@google.com0e454412011-05-19 17:47:02 +0000204 }
bungeman@google.com0e454412011-05-19 17:47:02 +0000205}