blob: f289bcb7fd200a873fb70ec625d1b386cd70c0ce [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
bungeman@google.com0e454412011-05-19 17:47:02 +000010#include "GrGLInterface.h"
11
bsalomon@google.com373a6632011-10-19 20:43:20 +000012#define GL_GLEXT_PROTOTYPES
13#include <GL/osmesa.h>
bungeman@google.com0e454412011-05-19 17:47:02 +000014
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000015#define GR_GL_GET_PROC(F) interface->f ## F = (GrGL ## F ## Proc) \
bungeman@google.com0e454412011-05-19 17:47:02 +000016 OSMesaGetProcAddress("gl" #F);
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000017#define GR_GL_GET_PROC_SUFFIX(F, S) interface->f ## F = (GrGL ## F ## Proc) \
bungeman@google.com0e454412011-05-19 17:47:02 +000018 OSMesaGetProcAddress("gl" #F #S);
19
bsalomon@google.com373a6632011-10-19 20:43:20 +000020// We use OSMesaGetProcAddress for every gl function to avoid accidentally using
21// non-Mesa gl functions.
22
23const GrGLInterface* GrGLCreateMesaInterface() {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000024 if (NULL != OSMesaGetCurrentContext()) {
bsalomon@google.com373a6632011-10-19 20:43:20 +000025 GrGLGetStringProc getString = (GrGLGetStringProc) OSMesaGetProcAddress("glGetString");
26 const char* versionString = (const char*) getString(GL_VERSION);
27 const char* extString = (const char*) getString(GL_EXTENSIONS);
bsalomon@google.comc82b8892011-09-22 14:10:33 +000028 GrGLVersion glVer = GrGLGetVersionFromString(versionString);
bungeman@google.com0e454412011-05-19 17:47:02 +000029
bsalomon@google.comc82b8892011-09-22 14:10:33 +000030 if (glVer < GR_GL_VER(1,5)) {
bungeman@google.com0e454412011-05-19 17:47:02 +000031 // We must have array and element_array buffer objects.
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000032 return NULL;
bungeman@google.com0e454412011-05-19 17:47:02 +000033 }
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000034 GrGLInterface* interface = new GrGLInterface();
35 interface->fNPOTRenderTargetSupport = kProbe_GrGLCapability;
36 interface->fMinRenderTargetHeight = kProbe_GrGLCapability;
37 interface->fMinRenderTargetWidth = kProbe_GrGLCapability;
bungeman@google.com0e454412011-05-19 17:47:02 +000038
bsalomon@google.com373a6632011-10-19 20:43:20 +000039 GR_GL_GET_PROC(ActiveTexture);
40 GR_GL_GET_PROC(BeginQuery);
bungeman@google.com0e454412011-05-19 17:47:02 +000041 GR_GL_GET_PROC(AttachShader);
42 GR_GL_GET_PROC(BindAttribLocation);
43 GR_GL_GET_PROC(BindBuffer);
bsalomon@google.combc5cf512011-09-21 16:21:07 +000044 GR_GL_GET_PROC(BindFragDataLocation);
bsalomon@google.com373a6632011-10-19 20:43:20 +000045 GR_GL_GET_PROC(BindTexture);
46 GR_GL_GET_PROC(BlendColor);
47 GR_GL_GET_PROC(BlendFunc);
bungeman@google.com0e454412011-05-19 17:47:02 +000048 GR_GL_GET_PROC(BufferData);
49 GR_GL_GET_PROC(BufferSubData);
bsalomon@google.com373a6632011-10-19 20:43:20 +000050 GR_GL_GET_PROC(Clear);
51 GR_GL_GET_PROC(ClearColor);
52 GR_GL_GET_PROC(ClearStencil);
bsalomon@google.com373a6632011-10-19 20:43:20 +000053 GR_GL_GET_PROC(ColorMask);
bungeman@google.com0e454412011-05-19 17:47:02 +000054 GR_GL_GET_PROC(CompileShader);
bsalomon@google.com373a6632011-10-19 20:43:20 +000055 GR_GL_GET_PROC(CompressedTexImage2D);
bungeman@google.com0e454412011-05-19 17:47:02 +000056 GR_GL_GET_PROC(CreateProgram);
57 GR_GL_GET_PROC(CreateShader);
bsalomon@google.com373a6632011-10-19 20:43:20 +000058 GR_GL_GET_PROC(CullFace);
bungeman@google.com0e454412011-05-19 17:47:02 +000059 GR_GL_GET_PROC(DeleteBuffers);
60 GR_GL_GET_PROC(DeleteProgram);
bsalomon@google.com373a6632011-10-19 20:43:20 +000061 GR_GL_GET_PROC(DeleteQueries);
bungeman@google.com0e454412011-05-19 17:47:02 +000062 GR_GL_GET_PROC(DeleteShader);
bsalomon@google.com373a6632011-10-19 20:43:20 +000063 GR_GL_GET_PROC(DeleteTextures);
64 GR_GL_GET_PROC(DepthMask);
65 GR_GL_GET_PROC(Disable);
bungeman@google.com0e454412011-05-19 17:47:02 +000066 GR_GL_GET_PROC(DisableVertexAttribArray);
bsalomon@google.com373a6632011-10-19 20:43:20 +000067 GR_GL_GET_PROC(DrawArrays);
68 GR_GL_GET_PROC(DrawBuffer);
bsalomon@google.comd32c5f52011-08-02 19:29:03 +000069 GR_GL_GET_PROC(DrawBuffers);
bsalomon@google.com373a6632011-10-19 20:43:20 +000070 GR_GL_GET_PROC(DrawElements);
71 GR_GL_GET_PROC(Enable);
bungeman@google.com0e454412011-05-19 17:47:02 +000072 GR_GL_GET_PROC(EnableVertexAttribArray);
bsalomon@google.com373a6632011-10-19 20:43:20 +000073 GR_GL_GET_PROC(EndQuery);
74 GR_GL_GET_PROC(Finish);
75 GR_GL_GET_PROC(Flush);
76 GR_GL_GET_PROC(FrontFace);
bungeman@google.com0e454412011-05-19 17:47:02 +000077 GR_GL_GET_PROC(GenBuffers);
bsalomon@google.com373a6632011-10-19 20:43:20 +000078 GR_GL_GET_PROC(GenQueries);
bungeman@google.com0e454412011-05-19 17:47:02 +000079 GR_GL_GET_PROC(GetBufferParameteriv);
bsalomon@google.com373a6632011-10-19 20:43:20 +000080 GR_GL_GET_PROC(GetError);
81 GR_GL_GET_PROC(GetIntegerv);
bungeman@google.com0e454412011-05-19 17:47:02 +000082 GR_GL_GET_PROC(GetProgramInfoLog);
83 GR_GL_GET_PROC(GetProgramiv);
bsalomon@google.com373a6632011-10-19 20:43:20 +000084 if (glVer >= GR_GL_VER(3,3) ||
85 GrGLHasExtensionFromString("GL_ARB_timer_query", extString)) {
86 GR_GL_GET_PROC(GetQueryObjecti64v);
87 GR_GL_GET_PROC(GetQueryObjectui64v)
88 GR_GL_GET_PROC(QueryCounter);
89 } else if (GrGLHasExtensionFromString("GL_EXT_timer_query", extString)) {
bsalomon@google.comf97c1942011-10-19 21:35:26 +000090 GR_GL_GET_PROC_SUFFIX(GetQueryObjecti64v, EXT);
91 GR_GL_GET_PROC_SUFFIX(GetQueryObjectui64v, EXT);
bsalomon@google.com373a6632011-10-19 20:43:20 +000092 }
93 GR_GL_GET_PROC(GetQueryObjectiv);
94 GR_GL_GET_PROC(GetQueryObjectuiv);
95 GR_GL_GET_PROC(GetQueryiv);
bungeman@google.com0e454412011-05-19 17:47:02 +000096 GR_GL_GET_PROC(GetShaderInfoLog);
97 GR_GL_GET_PROC(GetShaderiv);
bsalomon@google.com373a6632011-10-19 20:43:20 +000098 GR_GL_GET_PROC(GetString);
99 GR_GL_GET_PROC(GetTexLevelParameteriv);
100 GR_GL_GET_PROC(GenTextures);
bungeman@google.com0e454412011-05-19 17:47:02 +0000101 GR_GL_GET_PROC(GetUniformLocation);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000102 GR_GL_GET_PROC(LineWidth);
bungeman@google.com0e454412011-05-19 17:47:02 +0000103 GR_GL_GET_PROC(LinkProgram);
bungeman@google.com0e454412011-05-19 17:47:02 +0000104 GR_GL_GET_PROC(MapBuffer);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000105 GR_GL_GET_PROC(PixelStorei);
106 GR_GL_GET_PROC(ReadBuffer);
107 GR_GL_GET_PROC(ReadPixels);
108 GR_GL_GET_PROC(Scissor);
bungeman@google.com0e454412011-05-19 17:47:02 +0000109 GR_GL_GET_PROC(ShaderSource);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000110 GR_GL_GET_PROC(StencilFunc);
bungeman@google.com0e454412011-05-19 17:47:02 +0000111 GR_GL_GET_PROC(StencilFuncSeparate);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000112 GR_GL_GET_PROC(StencilMask);
bungeman@google.com0e454412011-05-19 17:47:02 +0000113 GR_GL_GET_PROC(StencilMaskSeparate);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000114 GR_GL_GET_PROC(StencilOp);
bungeman@google.com0e454412011-05-19 17:47:02 +0000115 GR_GL_GET_PROC(StencilOpSeparate);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000116 GR_GL_GET_PROC(TexImage2D)
117 GR_GL_GET_PROC(TexParameteri);
118 GR_GL_GET_PROC(TexSubImage2D);
bungeman@google.com0e454412011-05-19 17:47:02 +0000119 GR_GL_GET_PROC(Uniform1f);
120 GR_GL_GET_PROC(Uniform1i);
121 GR_GL_GET_PROC(Uniform1fv);
122 GR_GL_GET_PROC(Uniform1iv);
123 GR_GL_GET_PROC(Uniform2f);
124 GR_GL_GET_PROC(Uniform2i);
125 GR_GL_GET_PROC(Uniform2fv);
126 GR_GL_GET_PROC(Uniform2iv);
127 GR_GL_GET_PROC(Uniform3f);
128 GR_GL_GET_PROC(Uniform3i);
129 GR_GL_GET_PROC(Uniform3fv);
130 GR_GL_GET_PROC(Uniform3iv);
131 GR_GL_GET_PROC(Uniform4f);
132 GR_GL_GET_PROC(Uniform4i);
133 GR_GL_GET_PROC(Uniform4fv);
134 GR_GL_GET_PROC(Uniform4iv);
135 GR_GL_GET_PROC(UniformMatrix2fv);
136 GR_GL_GET_PROC(UniformMatrix3fv);
137 GR_GL_GET_PROC(UniformMatrix4fv);
138 GR_GL_GET_PROC(UnmapBuffer);
139 GR_GL_GET_PROC(UseProgram);
140 GR_GL_GET_PROC(VertexAttrib4fv);
141 GR_GL_GET_PROC(VertexAttribPointer);
bsalomon@google.com373a6632011-10-19 20:43:20 +0000142 GR_GL_GET_PROC(Viewport);
bungeman@google.com0e454412011-05-19 17:47:02 +0000143
144 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
145 // GL_ARB_framebuffer_object doesn't use ARB suffix.)
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000146 if (glVer >= GR_GL_VER(3,0) ||
147 GrGLHasExtensionFromString("GL_ARB_framebuffer_object",
148 extString)) {
bungeman@google.com0e454412011-05-19 17:47:02 +0000149 GR_GL_GET_PROC(GenFramebuffers);
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000150 GR_GL_GET_PROC(GetFramebufferAttachmentParameteriv);
151 GR_GL_GET_PROC(GetRenderbufferParameteriv);
bungeman@google.com0e454412011-05-19 17:47:02 +0000152 GR_GL_GET_PROC(BindFramebuffer);
153 GR_GL_GET_PROC(FramebufferTexture2D);
154 GR_GL_GET_PROC(CheckFramebufferStatus);
155 GR_GL_GET_PROC(DeleteFramebuffers);
156 GR_GL_GET_PROC(RenderbufferStorage);
157 GR_GL_GET_PROC(GenRenderbuffers);
158 GR_GL_GET_PROC(DeleteRenderbuffers);
159 GR_GL_GET_PROC(FramebufferRenderbuffer);
160 GR_GL_GET_PROC(BindRenderbuffer);
161 GR_GL_GET_PROC(RenderbufferStorageMultisample);
162 GR_GL_GET_PROC(BlitFramebuffer);
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000163 } else if (GrGLHasExtensionFromString("GL_EXT_framebuffer_object",
164 extString)) {
bungeman@google.com0e454412011-05-19 17:47:02 +0000165 GR_GL_GET_PROC_SUFFIX(GenFramebuffers, EXT);
bsalomon@google.comcee661a2011-07-26 12:32:36 +0000166 GR_GL_GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
167 GR_GL_GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
bungeman@google.com0e454412011-05-19 17:47:02 +0000168 GR_GL_GET_PROC_SUFFIX(BindFramebuffer, EXT);
169 GR_GL_GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
170 GR_GL_GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
171 GR_GL_GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
172 GR_GL_GET_PROC_SUFFIX(RenderbufferStorage, EXT);
173 GR_GL_GET_PROC_SUFFIX(GenRenderbuffers, EXT);
174 GR_GL_GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
175 GR_GL_GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
176 GR_GL_GET_PROC_SUFFIX(BindRenderbuffer, EXT);
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000177 if (GrGLHasExtensionFromString("GL_EXT_framebuffer_multisample",
178 extString)) {
bungeman@google.com0e454412011-05-19 17:47:02 +0000179 GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
180 }
bsalomon@google.comc82b8892011-09-22 14:10:33 +0000181 if (GrGLHasExtensionFromString("GL_EXT_framebuffer_blit",
182 extString)) {
bungeman@google.com0e454412011-05-19 17:47:02 +0000183 GR_GL_GET_PROC_SUFFIX(BlitFramebuffer, EXT);
184 }
185 } else {
186 // we must have FBOs
bsalomon@google.com6fb736f2011-09-16 18:51:57 +0000187 delete interface;
188 return NULL;
bungeman@google.com0e454412011-05-19 17:47:02 +0000189 }
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000190 GR_GL_GET_PROC(BindFragDataLocationIndexed);
bsalomon@google.com6fb736f2011-09-16 18:51:57 +0000191 interface->fBindingsExported = kDesktop_GrGLBinding;
192 return interface;
193 } else {
194 return NULL;
bungeman@google.com0e454412011-05-19 17:47:02 +0000195 }
bungeman@google.com0e454412011-05-19 17:47:02 +0000196}