epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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. |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 10 | #include "GrGLInterface.h" |
| 11 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 12 | #define GL_GLEXT_PROTOTYPES |
| 13 | #include <GL/osmesa.h> |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 14 | |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 15 | #define GR_GL_GET_PROC(F) interface->f ## F = (GrGL ## F ## Proc) \ |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 16 | OSMesaGetProcAddress("gl" #F); |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 17 | #define GR_GL_GET_PROC_SUFFIX(F, S) interface->f ## F = (GrGL ## F ## Proc) \ |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 18 | OSMesaGetProcAddress("gl" #F #S); |
| 19 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 20 | // We use OSMesaGetProcAddress for every gl function to avoid accidentally using |
| 21 | // non-Mesa gl functions. |
| 22 | |
| 23 | const GrGLInterface* GrGLCreateMesaInterface() { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 24 | if (NULL != OSMesaGetCurrentContext()) { |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 25 | 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.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 28 | GrGLVersion glVer = GrGLGetVersionFromString(versionString); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 29 | |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 30 | if (glVer < GR_GL_VER(1,5)) { |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 31 | // We must have array and element_array buffer objects. |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 32 | return NULL; |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 33 | } |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 34 | GrGLInterface* interface = new GrGLInterface(); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 35 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 36 | GR_GL_GET_PROC(ActiveTexture); |
| 37 | GR_GL_GET_PROC(BeginQuery); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 38 | GR_GL_GET_PROC(AttachShader); |
| 39 | GR_GL_GET_PROC(BindAttribLocation); |
| 40 | GR_GL_GET_PROC(BindBuffer); |
bsalomon@google.com | bc5cf51 | 2011-09-21 16:21:07 +0000 | [diff] [blame] | 41 | GR_GL_GET_PROC(BindFragDataLocation); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 42 | GR_GL_GET_PROC(BindTexture); |
| 43 | GR_GL_GET_PROC(BlendColor); |
| 44 | GR_GL_GET_PROC(BlendFunc); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 45 | GR_GL_GET_PROC(BufferData); |
| 46 | GR_GL_GET_PROC(BufferSubData); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 47 | GR_GL_GET_PROC(Clear); |
| 48 | GR_GL_GET_PROC(ClearColor); |
| 49 | GR_GL_GET_PROC(ClearStencil); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 50 | GR_GL_GET_PROC(ColorMask); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 51 | GR_GL_GET_PROC(CompileShader); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 52 | GR_GL_GET_PROC(CompressedTexImage2D); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 53 | GR_GL_GET_PROC(CreateProgram); |
| 54 | GR_GL_GET_PROC(CreateShader); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 55 | GR_GL_GET_PROC(CullFace); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 56 | GR_GL_GET_PROC(DeleteBuffers); |
| 57 | GR_GL_GET_PROC(DeleteProgram); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 58 | GR_GL_GET_PROC(DeleteQueries); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 59 | GR_GL_GET_PROC(DeleteShader); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 60 | GR_GL_GET_PROC(DeleteTextures); |
| 61 | GR_GL_GET_PROC(DepthMask); |
| 62 | GR_GL_GET_PROC(Disable); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 63 | GR_GL_GET_PROC(DisableVertexAttribArray); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 64 | GR_GL_GET_PROC(DrawArrays); |
| 65 | GR_GL_GET_PROC(DrawBuffer); |
bsalomon@google.com | d32c5f5 | 2011-08-02 19:29:03 +0000 | [diff] [blame] | 66 | GR_GL_GET_PROC(DrawBuffers); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 67 | GR_GL_GET_PROC(DrawElements); |
| 68 | GR_GL_GET_PROC(Enable); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 69 | GR_GL_GET_PROC(EnableVertexAttribArray); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 70 | GR_GL_GET_PROC(EndQuery); |
| 71 | GR_GL_GET_PROC(Finish); |
| 72 | GR_GL_GET_PROC(Flush); |
| 73 | GR_GL_GET_PROC(FrontFace); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 74 | GR_GL_GET_PROC(GenBuffers); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 75 | GR_GL_GET_PROC(GenQueries); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 76 | GR_GL_GET_PROC(GetBufferParameteriv); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 77 | GR_GL_GET_PROC(GetError); |
| 78 | GR_GL_GET_PROC(GetIntegerv); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 79 | GR_GL_GET_PROC(GetProgramInfoLog); |
| 80 | GR_GL_GET_PROC(GetProgramiv); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 81 | if (glVer >= GR_GL_VER(3,3) || |
| 82 | GrGLHasExtensionFromString("GL_ARB_timer_query", extString)) { |
| 83 | GR_GL_GET_PROC(GetQueryObjecti64v); |
| 84 | GR_GL_GET_PROC(GetQueryObjectui64v) |
| 85 | GR_GL_GET_PROC(QueryCounter); |
| 86 | } else if (GrGLHasExtensionFromString("GL_EXT_timer_query", extString)) { |
bsalomon@google.com | f97c194 | 2011-10-19 21:35:26 +0000 | [diff] [blame] | 87 | GR_GL_GET_PROC_SUFFIX(GetQueryObjecti64v, EXT); |
| 88 | GR_GL_GET_PROC_SUFFIX(GetQueryObjectui64v, EXT); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 89 | } |
| 90 | GR_GL_GET_PROC(GetQueryObjectiv); |
| 91 | GR_GL_GET_PROC(GetQueryObjectuiv); |
| 92 | GR_GL_GET_PROC(GetQueryiv); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 93 | GR_GL_GET_PROC(GetShaderInfoLog); |
| 94 | GR_GL_GET_PROC(GetShaderiv); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 95 | GR_GL_GET_PROC(GetString); |
| 96 | GR_GL_GET_PROC(GetTexLevelParameteriv); |
| 97 | GR_GL_GET_PROC(GenTextures); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 98 | GR_GL_GET_PROC(GetUniformLocation); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 99 | GR_GL_GET_PROC(LineWidth); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 100 | GR_GL_GET_PROC(LinkProgram); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 101 | GR_GL_GET_PROC(MapBuffer); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 102 | GR_GL_GET_PROC(PixelStorei); |
| 103 | GR_GL_GET_PROC(ReadBuffer); |
| 104 | GR_GL_GET_PROC(ReadPixels); |
| 105 | GR_GL_GET_PROC(Scissor); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 106 | GR_GL_GET_PROC(ShaderSource); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 107 | GR_GL_GET_PROC(StencilFunc); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 108 | GR_GL_GET_PROC(StencilFuncSeparate); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 109 | GR_GL_GET_PROC(StencilMask); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 110 | GR_GL_GET_PROC(StencilMaskSeparate); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 111 | GR_GL_GET_PROC(StencilOp); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 112 | GR_GL_GET_PROC(StencilOpSeparate); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 113 | GR_GL_GET_PROC(TexImage2D) |
| 114 | GR_GL_GET_PROC(TexParameteri); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame^] | 115 | GR_GL_GET_PROC(TexStorage2D); |
| 116 | if (NULL == interface->fTexStorage2D) { |
| 117 | GR_GL_GET_PROC_SUFFIX(TexStorage2D, EXT); |
| 118 | } |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 119 | GR_GL_GET_PROC(TexSubImage2D); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 120 | GR_GL_GET_PROC(Uniform1f); |
| 121 | GR_GL_GET_PROC(Uniform1i); |
| 122 | GR_GL_GET_PROC(Uniform1fv); |
| 123 | GR_GL_GET_PROC(Uniform1iv); |
| 124 | GR_GL_GET_PROC(Uniform2f); |
| 125 | GR_GL_GET_PROC(Uniform2i); |
| 126 | GR_GL_GET_PROC(Uniform2fv); |
| 127 | GR_GL_GET_PROC(Uniform2iv); |
| 128 | GR_GL_GET_PROC(Uniform3f); |
| 129 | GR_GL_GET_PROC(Uniform3i); |
| 130 | GR_GL_GET_PROC(Uniform3fv); |
| 131 | GR_GL_GET_PROC(Uniform3iv); |
| 132 | GR_GL_GET_PROC(Uniform4f); |
| 133 | GR_GL_GET_PROC(Uniform4i); |
| 134 | GR_GL_GET_PROC(Uniform4fv); |
| 135 | GR_GL_GET_PROC(Uniform4iv); |
| 136 | GR_GL_GET_PROC(UniformMatrix2fv); |
| 137 | GR_GL_GET_PROC(UniformMatrix3fv); |
| 138 | GR_GL_GET_PROC(UniformMatrix4fv); |
| 139 | GR_GL_GET_PROC(UnmapBuffer); |
| 140 | GR_GL_GET_PROC(UseProgram); |
| 141 | GR_GL_GET_PROC(VertexAttrib4fv); |
| 142 | GR_GL_GET_PROC(VertexAttribPointer); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 143 | GR_GL_GET_PROC(Viewport); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 144 | |
| 145 | // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since |
| 146 | // GL_ARB_framebuffer_object doesn't use ARB suffix.) |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 147 | if (glVer >= GR_GL_VER(3,0) || |
| 148 | GrGLHasExtensionFromString("GL_ARB_framebuffer_object", |
| 149 | extString)) { |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 150 | GR_GL_GET_PROC(GenFramebuffers); |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 151 | GR_GL_GET_PROC(GetFramebufferAttachmentParameteriv); |
| 152 | GR_GL_GET_PROC(GetRenderbufferParameteriv); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 153 | GR_GL_GET_PROC(BindFramebuffer); |
| 154 | GR_GL_GET_PROC(FramebufferTexture2D); |
| 155 | GR_GL_GET_PROC(CheckFramebufferStatus); |
| 156 | GR_GL_GET_PROC(DeleteFramebuffers); |
| 157 | GR_GL_GET_PROC(RenderbufferStorage); |
| 158 | GR_GL_GET_PROC(GenRenderbuffers); |
| 159 | GR_GL_GET_PROC(DeleteRenderbuffers); |
| 160 | GR_GL_GET_PROC(FramebufferRenderbuffer); |
| 161 | GR_GL_GET_PROC(BindRenderbuffer); |
| 162 | GR_GL_GET_PROC(RenderbufferStorageMultisample); |
| 163 | GR_GL_GET_PROC(BlitFramebuffer); |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 164 | } else if (GrGLHasExtensionFromString("GL_EXT_framebuffer_object", |
| 165 | extString)) { |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 166 | GR_GL_GET_PROC_SUFFIX(GenFramebuffers, EXT); |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 167 | GR_GL_GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT); |
| 168 | GR_GL_GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT); |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 169 | GR_GL_GET_PROC_SUFFIX(BindFramebuffer, EXT); |
| 170 | GR_GL_GET_PROC_SUFFIX(FramebufferTexture2D, EXT); |
| 171 | GR_GL_GET_PROC_SUFFIX(CheckFramebufferStatus, EXT); |
| 172 | GR_GL_GET_PROC_SUFFIX(DeleteFramebuffers, EXT); |
| 173 | GR_GL_GET_PROC_SUFFIX(RenderbufferStorage, EXT); |
| 174 | GR_GL_GET_PROC_SUFFIX(GenRenderbuffers, EXT); |
| 175 | GR_GL_GET_PROC_SUFFIX(DeleteRenderbuffers, EXT); |
| 176 | GR_GL_GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT); |
| 177 | GR_GL_GET_PROC_SUFFIX(BindRenderbuffer, EXT); |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 178 | if (GrGLHasExtensionFromString("GL_EXT_framebuffer_multisample", |
| 179 | extString)) { |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 180 | GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT); |
| 181 | } |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 182 | if (GrGLHasExtensionFromString("GL_EXT_framebuffer_blit", |
| 183 | extString)) { |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 184 | GR_GL_GET_PROC_SUFFIX(BlitFramebuffer, EXT); |
| 185 | } |
| 186 | } else { |
| 187 | // we must have FBOs |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 188 | delete interface; |
| 189 | return NULL; |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 190 | } |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 191 | GR_GL_GET_PROC(BindFragDataLocationIndexed); |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 192 | interface->fBindingsExported = kDesktop_GrGLBinding; |
| 193 | return interface; |
| 194 | } else { |
| 195 | return NULL; |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 196 | } |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 197 | } |