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 | |
bsalomon@google.com | 1744f97 | 2013-02-26 21:46:32 +0000 | [diff] [blame] | 9 | #include "gl/GrGLExtensions.h" |
tomhudson@google.com | 6c8c34e | 2012-02-14 15:31:03 +0000 | [diff] [blame] | 10 | #include "gl/GrGLInterface.h" |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 11 | #include "../GrGLUtil.h" |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 12 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 13 | #define GL_GLEXT_PROTOTYPES |
bsalomon@google.com | 6f47663 | 2013-01-08 16:33:41 +0000 | [diff] [blame] | 14 | #include "osmesa_wrapper.h" |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 15 | |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 16 | #define GET_PROC(F) interface->fFunctions.f ## F = (GrGL ## F ## Proc) \ |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 17 | OSMesaGetProcAddress("gl" #F); |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 18 | #define GET_PROC_SUFFIX(F, S) interface->fFunctions.f ## F = (GrGL ## F ## Proc) \ |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 19 | OSMesaGetProcAddress("gl" #F #S); |
| 20 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 21 | // We use OSMesaGetProcAddress for every gl function to avoid accidentally using |
| 22 | // non-Mesa gl functions. |
| 23 | |
| 24 | const GrGLInterface* GrGLCreateMesaInterface() { |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 25 | if (NULL == OSMesaGetCurrentContext()) { |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 26 | return NULL; |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 27 | } |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 28 | |
| 29 | GrGLGetStringProc getString = (GrGLGetStringProc) OSMesaGetProcAddress("glGetString"); |
| 30 | GrGLGetStringiProc getStringi = (GrGLGetStringiProc) OSMesaGetProcAddress("glGetStringi"); |
| 31 | GrGLGetIntegervProc getIntegerv = |
| 32 | (GrGLGetIntegervProc) OSMesaGetProcAddress("glGetIntegerv"); |
| 33 | |
| 34 | GrGLExtensions extensions; |
| 35 | if (!extensions.init(kGL_GrGLStandard, getString, getStringi, getIntegerv)) { |
| 36 | return NULL; |
| 37 | } |
| 38 | |
| 39 | const char* versionString = (const char*) getString(GL_VERSION); |
| 40 | GrGLVersion glVer = GrGLGetVersionFromString(versionString); |
| 41 | |
| 42 | if (glVer < GR_GL_VER(1,5)) { |
| 43 | // We must have array and element_array buffer objects. |
| 44 | return NULL; |
| 45 | } |
| 46 | GrGLInterface* interface = SkNEW(GrGLInterface()); |
| 47 | |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 48 | GET_PROC(ActiveTexture); |
| 49 | GET_PROC(BeginQuery); |
| 50 | GET_PROC(AttachShader); |
| 51 | GET_PROC(BindAttribLocation); |
| 52 | GET_PROC(BindBuffer); |
| 53 | GET_PROC(BindFragDataLocation); |
| 54 | GET_PROC(BindTexture); |
| 55 | GET_PROC(BlendFunc); |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 56 | |
| 57 | if (glVer >= GR_GL_VER(1,4) || |
| 58 | extensions.has("GL_ARB_imaging") || |
| 59 | extensions.has("GL_EXT_blend_color")) { |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 60 | GET_PROC(BlendColor); |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 61 | } |
| 62 | |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 63 | GET_PROC(BufferData); |
| 64 | GET_PROC(BufferSubData); |
| 65 | GET_PROC(Clear); |
| 66 | GET_PROC(ClearColor); |
| 67 | GET_PROC(ClearStencil); |
| 68 | GET_PROC(ColorMask); |
| 69 | GET_PROC(CompileShader); |
| 70 | GET_PROC(CompressedTexImage2D); |
| 71 | GET_PROC(CopyTexSubImage2D); |
| 72 | GET_PROC(CreateProgram); |
| 73 | GET_PROC(CreateShader); |
| 74 | GET_PROC(CullFace); |
| 75 | GET_PROC(DeleteBuffers); |
| 76 | GET_PROC(DeleteProgram); |
| 77 | GET_PROC(DeleteQueries); |
| 78 | GET_PROC(DeleteShader); |
| 79 | GET_PROC(DeleteTextures); |
| 80 | GET_PROC(DepthMask); |
| 81 | GET_PROC(Disable); |
| 82 | GET_PROC(DisableVertexAttribArray); |
| 83 | GET_PROC(DrawArrays); |
| 84 | GET_PROC(DrawBuffer); |
| 85 | GET_PROC(DrawBuffers); |
| 86 | GET_PROC(DrawElements); |
| 87 | GET_PROC(Enable); |
| 88 | GET_PROC(EnableVertexAttribArray); |
| 89 | GET_PROC(EndQuery); |
| 90 | GET_PROC(Finish); |
| 91 | GET_PROC(Flush); |
| 92 | GET_PROC(FrontFace); |
| 93 | GET_PROC(GenBuffers); |
| 94 | GET_PROC(GenerateMipmap); |
| 95 | GET_PROC(GenQueries); |
| 96 | GET_PROC(GetBufferParameteriv); |
| 97 | GET_PROC(GetError); |
| 98 | GET_PROC(GetIntegerv); |
| 99 | GET_PROC(GetProgramInfoLog); |
| 100 | GET_PROC(GetProgramiv); |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 101 | if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) { |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 102 | GET_PROC(GetQueryObjecti64v); |
| 103 | GET_PROC(GetQueryObjectui64v) |
| 104 | GET_PROC(QueryCounter); |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 105 | } else if (extensions.has("GL_EXT_timer_query")) { |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 106 | GET_PROC_SUFFIX(GetQueryObjecti64v, EXT); |
| 107 | GET_PROC_SUFFIX(GetQueryObjectui64v, EXT); |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 108 | } |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 109 | GET_PROC(GetQueryObjectiv); |
| 110 | GET_PROC(GetQueryObjectuiv); |
| 111 | GET_PROC(GetQueryiv); |
| 112 | GET_PROC(GetShaderInfoLog); |
| 113 | GET_PROC(GetShaderiv); |
| 114 | GET_PROC(GetString); |
| 115 | GET_PROC(GetStringi); |
| 116 | GET_PROC(GetTexLevelParameteriv); |
| 117 | GET_PROC(GenTextures); |
| 118 | GET_PROC(GetUniformLocation); |
| 119 | GET_PROC(LineWidth); |
| 120 | GET_PROC(LinkProgram); |
| 121 | GET_PROC(MapBuffer); |
commit-bot@chromium.org | f669672 | 2014-04-25 06:21:30 +0000 | [diff] [blame] | 122 | if (extensions.has("GL_EXT_direct_state_access")) { |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 123 | GET_PROC_SUFFIX(MatrixLoadf, EXT); |
| 124 | GET_PROC_SUFFIX(MatrixLoadIdentity, EXT); |
commit-bot@chromium.org | f669672 | 2014-04-25 06:21:30 +0000 | [diff] [blame] | 125 | } |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 126 | GET_PROC(PixelStorei); |
| 127 | GET_PROC(ReadBuffer); |
| 128 | GET_PROC(ReadPixels); |
| 129 | GET_PROC(Scissor); |
| 130 | GET_PROC(ShaderSource); |
| 131 | GET_PROC(StencilFunc); |
| 132 | GET_PROC(StencilFuncSeparate); |
| 133 | GET_PROC(StencilMask); |
| 134 | GET_PROC(StencilMaskSeparate); |
| 135 | GET_PROC(StencilOp); |
| 136 | GET_PROC(StencilOpSeparate); |
| 137 | GET_PROC(TexImage2D) |
| 138 | GET_PROC(TexParameteri); |
| 139 | GET_PROC(TexParameteriv); |
| 140 | GET_PROC(TexStorage2D); |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 141 | if (NULL == interface->fFunctions.fTexStorage2D) { |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 142 | GET_PROC_SUFFIX(TexStorage2D, EXT); |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 143 | } |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 144 | GET_PROC(TexSubImage2D); |
| 145 | GET_PROC(Uniform1f); |
| 146 | GET_PROC(Uniform1i); |
| 147 | GET_PROC(Uniform1fv); |
| 148 | GET_PROC(Uniform1iv); |
| 149 | GET_PROC(Uniform2f); |
| 150 | GET_PROC(Uniform2i); |
| 151 | GET_PROC(Uniform2fv); |
| 152 | GET_PROC(Uniform2iv); |
| 153 | GET_PROC(Uniform3f); |
| 154 | GET_PROC(Uniform3i); |
| 155 | GET_PROC(Uniform3fv); |
| 156 | GET_PROC(Uniform3iv); |
| 157 | GET_PROC(Uniform4f); |
| 158 | GET_PROC(Uniform4i); |
| 159 | GET_PROC(Uniform4fv); |
| 160 | GET_PROC(Uniform4iv); |
| 161 | GET_PROC(UniformMatrix2fv); |
| 162 | GET_PROC(UniformMatrix3fv); |
| 163 | GET_PROC(UniformMatrix4fv); |
| 164 | GET_PROC(UnmapBuffer); |
| 165 | GET_PROC(UseProgram); |
| 166 | GET_PROC(VertexAttrib4fv); |
| 167 | GET_PROC(VertexAttribPointer); |
| 168 | GET_PROC(Viewport); |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 169 | |
| 170 | if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object")) { |
| 171 | // no ARB suffix for GL_ARB_vertex_array_object |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 172 | GET_PROC(BindVertexArray); |
| 173 | GET_PROC(DeleteVertexArrays); |
| 174 | GET_PROC(GenVertexArrays); |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since |
| 178 | // GL_ARB_framebuffer_object doesn't use ARB suffix.) |
| 179 | if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) { |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 180 | GET_PROC(GenFramebuffers); |
| 181 | GET_PROC(GetFramebufferAttachmentParameteriv); |
| 182 | GET_PROC(GetRenderbufferParameteriv); |
| 183 | GET_PROC(BindFramebuffer); |
| 184 | GET_PROC(FramebufferTexture2D); |
| 185 | GET_PROC(CheckFramebufferStatus); |
| 186 | GET_PROC(DeleteFramebuffers); |
| 187 | GET_PROC(RenderbufferStorage); |
| 188 | GET_PROC(GenRenderbuffers); |
| 189 | GET_PROC(DeleteRenderbuffers); |
| 190 | GET_PROC(FramebufferRenderbuffer); |
| 191 | GET_PROC(BindRenderbuffer); |
| 192 | GET_PROC(RenderbufferStorageMultisample); |
| 193 | GET_PROC(BlitFramebuffer); |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 194 | } else if (extensions.has("GL_EXT_framebuffer_object")) { |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 195 | GET_PROC_SUFFIX(GenFramebuffers, EXT); |
| 196 | GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT); |
| 197 | GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT); |
| 198 | GET_PROC_SUFFIX(BindFramebuffer, EXT); |
| 199 | GET_PROC_SUFFIX(FramebufferTexture2D, EXT); |
| 200 | GET_PROC_SUFFIX(CheckFramebufferStatus, EXT); |
| 201 | GET_PROC_SUFFIX(DeleteFramebuffers, EXT); |
| 202 | GET_PROC_SUFFIX(RenderbufferStorage, EXT); |
| 203 | GET_PROC_SUFFIX(GenRenderbuffers, EXT); |
| 204 | GET_PROC_SUFFIX(DeleteRenderbuffers, EXT); |
| 205 | GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT); |
| 206 | GET_PROC_SUFFIX(BindRenderbuffer, EXT); |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 207 | if (extensions.has("GL_EXT_framebuffer_multisample")) { |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 208 | GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT); |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 209 | } |
| 210 | if (extensions.has("GL_EXT_framebuffer_blit")) { |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 211 | GET_PROC_SUFFIX(BlitFramebuffer, EXT); |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 212 | } |
| 213 | } else { |
| 214 | // we must have FBOs |
| 215 | delete interface; |
| 216 | return NULL; |
| 217 | } |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 218 | GET_PROC(BindFragDataLocationIndexed); |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 219 | |
| 220 | if (extensions.has("GL_EXT_debug_marker")) { |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 221 | GET_PROC_SUFFIX(InsertEventMarker, EXT); |
| 222 | GET_PROC_SUFFIX(PopGroupMarker, EXT); |
| 223 | GET_PROC_SUFFIX(PushGroupMarker, EXT); |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 224 | } |
| 225 | |
bsalomon@google.com | a34bb60 | 2014-04-01 13:07:29 +0000 | [diff] [blame] | 226 | if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_invalidate_subdata")) { |
commit-bot@chromium.org | 06d4cda | 2014-04-28 19:41:24 +0000 | [diff] [blame] | 227 | GET_PROC(InvalidateBufferData); |
| 228 | GET_PROC(InvalidateBufferSubData); |
| 229 | GET_PROC(InvalidateFramebuffer); |
| 230 | GET_PROC(InvalidateSubFramebuffer); |
| 231 | GET_PROC(InvalidateTexImage); |
| 232 | GET_PROC(InvalidateTexSubImage); |
bsalomon@google.com | a34bb60 | 2014-04-01 13:07:29 +0000 | [diff] [blame] | 233 | } |
| 234 | |
commit-bot@chromium.org | 7c0d72f | 2014-03-31 18:34:16 +0000 | [diff] [blame] | 235 | interface->fStandard = kGL_GrGLStandard; |
| 236 | interface->fExtensions.swap(&extensions); |
| 237 | |
| 238 | return interface; |
bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 239 | } |