commit-bot@chromium.org | 9add5dc | 2014-04-29 20:06:22 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2014 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. |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | #include "GrGLAssembleInterface.h" |
| 11 | #include "GrGLUtil.h" |
| 12 | |
| 13 | #define GET_PROC(F) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F) |
| 14 | #define GET_PROC_SUFFIX(F, S) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F #S) |
| 15 | #define GET_PROC_LOCAL(F) GrGL ## F ## Proc F = (GrGL ## F ## Proc) get(ctx, "gl" #F) |
| 16 | |
| 17 | const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) { |
| 18 | GET_PROC_LOCAL(GetString); |
| 19 | GET_PROC_LOCAL(GetStringi); |
| 20 | GET_PROC_LOCAL(GetIntegerv); |
| 21 | |
| 22 | // GetStringi may be NULL depending on the GL version. |
| 23 | if (NULL == GetString || NULL == GetIntegerv) { |
| 24 | return NULL; |
| 25 | } |
| 26 | |
| 27 | const char* versionString = (const char*) GetString(GR_GL_VERSION); |
| 28 | GrGLVersion glVer = GrGLGetVersionFromString(versionString); |
| 29 | |
commit-bot@chromium.org | f4e67e3 | 2014-04-30 01:26:04 +0000 | [diff] [blame] | 30 | if (glVer < GR_GL_VER(1,5) || GR_GL_INVALID_VER == glVer) { |
commit-bot@chromium.org | 9add5dc | 2014-04-29 20:06:22 +0000 | [diff] [blame] | 31 | // We must have array and element_array buffer objects. |
| 32 | return NULL; |
| 33 | } |
| 34 | |
| 35 | GrGLExtensions extensions; |
| 36 | if (!extensions.init(kGL_GrGLStandard, GetString, GetStringi, GetIntegerv)) { |
| 37 | return NULL; |
| 38 | } |
| 39 | |
| 40 | GrGLInterface* interface = SkNEW(GrGLInterface()); |
| 41 | GrGLInterface::Functions* functions = &interface->fFunctions; |
| 42 | |
| 43 | GET_PROC(ActiveTexture); |
| 44 | GET_PROC(AttachShader); |
| 45 | GET_PROC(BindAttribLocation); |
| 46 | GET_PROC(BindBuffer); |
| 47 | if (glVer >= GR_GL_VER(3,0)) { |
| 48 | GET_PROC(BindFragDataLocation); |
| 49 | } |
| 50 | GET_PROC(BeginQuery); |
| 51 | GET_PROC(BindTexture); |
| 52 | GET_PROC(BlendFunc); |
| 53 | |
| 54 | if (glVer >= GR_GL_VER(1,4) || |
| 55 | extensions.has("GL_ARB_imaging") || |
| 56 | extensions.has("GL_EXT_blend_color")) { |
| 57 | GET_PROC(BlendColor); |
| 58 | } |
| 59 | |
| 60 | GET_PROC(BufferData); |
| 61 | GET_PROC(BufferSubData); |
| 62 | GET_PROC(Clear); |
| 63 | GET_PROC(ClearColor); |
| 64 | GET_PROC(ClearStencil); |
| 65 | GET_PROC(ColorMask); |
| 66 | GET_PROC(CompileShader); |
| 67 | GET_PROC(CompressedTexImage2D); |
krajcevski | 37d20f7 | 2014-06-11 10:38:47 -0700 | [diff] [blame] | 68 | GET_PROC(CompressedTexSubImage2D); |
commit-bot@chromium.org | 9add5dc | 2014-04-29 20:06:22 +0000 | [diff] [blame] | 69 | GET_PROC(CopyTexSubImage2D); |
| 70 | GET_PROC(CreateProgram); |
| 71 | GET_PROC(CreateShader); |
| 72 | GET_PROC(CullFace); |
| 73 | GET_PROC(DeleteBuffers); |
| 74 | GET_PROC(DeleteProgram); |
| 75 | GET_PROC(DeleteQueries); |
| 76 | GET_PROC(DeleteShader); |
| 77 | GET_PROC(DeleteTextures); |
| 78 | GET_PROC(DepthMask); |
| 79 | GET_PROC(Disable); |
| 80 | GET_PROC(DisableVertexAttribArray); |
| 81 | GET_PROC(DrawArrays); |
| 82 | GET_PROC(DrawBuffer); |
| 83 | GET_PROC(DrawBuffers); |
| 84 | GET_PROC(DrawElements); |
| 85 | GET_PROC(Enable); |
| 86 | GET_PROC(EnableVertexAttribArray); |
| 87 | GET_PROC(EndQuery); |
| 88 | GET_PROC(Finish); |
| 89 | GET_PROC(Flush); |
| 90 | GET_PROC(FrontFace); |
| 91 | GET_PROC(GenBuffers); |
| 92 | GET_PROC(GenerateMipmap); |
| 93 | GET_PROC(GetBufferParameteriv); |
| 94 | GET_PROC(GetError); |
| 95 | GET_PROC(GetIntegerv); |
| 96 | GET_PROC(GetQueryObjectiv); |
| 97 | GET_PROC(GetQueryObjectuiv); |
| 98 | if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) { |
| 99 | GET_PROC(GetQueryObjecti64v); |
| 100 | GET_PROC(GetQueryObjectui64v); |
| 101 | GET_PROC(QueryCounter); |
| 102 | } else if (extensions.has("GL_EXT_timer_query")) { |
| 103 | GET_PROC_SUFFIX(GetQueryObjecti64v, EXT); |
| 104 | GET_PROC_SUFFIX(GetQueryObjectui64v, EXT); |
| 105 | } |
| 106 | GET_PROC(GetQueryiv); |
| 107 | GET_PROC(GetProgramInfoLog); |
| 108 | GET_PROC(GetProgramiv); |
| 109 | GET_PROC(GetShaderInfoLog); |
| 110 | GET_PROC(GetShaderiv); |
| 111 | GET_PROC(GetString); |
| 112 | GET_PROC(GetStringi); |
| 113 | GET_PROC(GetTexLevelParameteriv); |
| 114 | GET_PROC(GenQueries); |
| 115 | GET_PROC(GenTextures); |
| 116 | GET_PROC(GetUniformLocation); |
| 117 | GET_PROC(LineWidth); |
| 118 | GET_PROC(LinkProgram); |
| 119 | GET_PROC(MapBuffer); |
| 120 | if (extensions.has("GL_EXT_direct_state_access")) { |
| 121 | GET_PROC_SUFFIX(MatrixLoadf, EXT); |
| 122 | GET_PROC_SUFFIX(MatrixLoadIdentity, EXT); |
| 123 | } |
| 124 | GET_PROC(PixelStorei); |
| 125 | GET_PROC(ReadBuffer); |
| 126 | GET_PROC(ReadPixels); |
| 127 | GET_PROC(Scissor); |
| 128 | GET_PROC(ShaderSource); |
| 129 | GET_PROC(StencilFunc); |
| 130 | GET_PROC(StencilFuncSeparate); |
| 131 | GET_PROC(StencilMask); |
| 132 | GET_PROC(StencilMaskSeparate); |
| 133 | GET_PROC(StencilOp); |
| 134 | GET_PROC(StencilOpSeparate); |
| 135 | GET_PROC(TexImage2D); |
| 136 | GET_PROC(TexParameteri); |
| 137 | GET_PROC(TexParameteriv); |
| 138 | if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) { |
| 139 | GET_PROC(TexStorage2D); |
| 140 | } else if (extensions.has("GL_EXT_texture_storage")) { |
| 141 | GET_PROC_SUFFIX(TexStorage2D, EXT); |
| 142 | } |
| 143 | GET_PROC(TexSubImage2D); |
| 144 | GET_PROC(Uniform1f); |
| 145 | GET_PROC(Uniform1i); |
| 146 | GET_PROC(Uniform1fv); |
| 147 | GET_PROC(Uniform1iv); |
| 148 | GET_PROC(Uniform2f); |
| 149 | GET_PROC(Uniform2i); |
| 150 | GET_PROC(Uniform2fv); |
| 151 | GET_PROC(Uniform2iv); |
| 152 | GET_PROC(Uniform3f); |
| 153 | GET_PROC(Uniform3i); |
| 154 | GET_PROC(Uniform3fv); |
| 155 | GET_PROC(Uniform3iv); |
| 156 | GET_PROC(Uniform4f); |
| 157 | GET_PROC(Uniform4i); |
| 158 | GET_PROC(Uniform4fv); |
| 159 | GET_PROC(Uniform4iv); |
| 160 | GET_PROC(UniformMatrix2fv); |
| 161 | GET_PROC(UniformMatrix3fv); |
| 162 | GET_PROC(UniformMatrix4fv); |
| 163 | GET_PROC(UnmapBuffer); |
| 164 | GET_PROC(UseProgram); |
| 165 | GET_PROC(VertexAttrib4fv); |
| 166 | GET_PROC(VertexAttribPointer); |
| 167 | GET_PROC(Viewport); |
| 168 | GET_PROC(BindFragDataLocationIndexed); |
| 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 |
| 172 | GET_PROC(BindVertexArray); |
| 173 | GET_PROC(GenVertexArrays); |
| 174 | GET_PROC(DeleteVertexArrays); |
| 175 | } |
| 176 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 177 | if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_map_buffer_range")) { |
| 178 | GET_PROC(MapBufferRange); |
| 179 | GET_PROC(FlushMappedBufferRange); |
| 180 | } |
| 181 | |
commit-bot@chromium.org | 9add5dc | 2014-04-29 20:06:22 +0000 | [diff] [blame] | 182 | // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since |
| 183 | // GL_ARB_framebuffer_object doesn't use ARB suffix.) |
| 184 | if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) { |
| 185 | GET_PROC(GenFramebuffers); |
| 186 | GET_PROC(GetFramebufferAttachmentParameteriv); |
| 187 | GET_PROC(GetRenderbufferParameteriv); |
| 188 | GET_PROC(BindFramebuffer); |
| 189 | GET_PROC(FramebufferTexture2D); |
| 190 | GET_PROC(CheckFramebufferStatus); |
| 191 | GET_PROC(DeleteFramebuffers); |
| 192 | GET_PROC(RenderbufferStorage); |
| 193 | GET_PROC(GenRenderbuffers); |
| 194 | GET_PROC(DeleteRenderbuffers); |
| 195 | GET_PROC(FramebufferRenderbuffer); |
| 196 | GET_PROC(BindRenderbuffer); |
| 197 | GET_PROC(RenderbufferStorageMultisample); |
| 198 | GET_PROC(BlitFramebuffer); |
| 199 | } else if (extensions.has("GL_EXT_framebuffer_object")) { |
| 200 | GET_PROC_SUFFIX(GenFramebuffers, EXT); |
| 201 | GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT); |
| 202 | GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT); |
| 203 | GET_PROC_SUFFIX(BindFramebuffer, EXT); |
| 204 | GET_PROC_SUFFIX(FramebufferTexture2D, EXT); |
| 205 | GET_PROC_SUFFIX(CheckFramebufferStatus, EXT); |
| 206 | GET_PROC_SUFFIX(DeleteFramebuffers, EXT); |
| 207 | GET_PROC_SUFFIX(RenderbufferStorage, EXT); |
| 208 | GET_PROC_SUFFIX(GenRenderbuffers, EXT); |
| 209 | GET_PROC_SUFFIX(DeleteRenderbuffers, EXT); |
| 210 | GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT); |
| 211 | GET_PROC_SUFFIX(BindRenderbuffer, EXT); |
| 212 | if (extensions.has("GL_EXT_framebuffer_multisample")) { |
| 213 | GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT); |
| 214 | } |
| 215 | if (extensions.has("GL_EXT_framebuffer_blit")) { |
| 216 | GET_PROC_SUFFIX(BlitFramebuffer, EXT); |
| 217 | } |
| 218 | } else { |
| 219 | // we must have FBOs |
| 220 | delete interface; |
| 221 | return NULL; |
| 222 | } |
| 223 | |
| 224 | if (extensions.has("GL_NV_path_rendering")) { |
| 225 | GET_PROC_SUFFIX(PathCommands, NV); |
| 226 | GET_PROC_SUFFIX(PathCoords, NV); |
commit-bot@chromium.org | 9add5dc | 2014-04-29 20:06:22 +0000 | [diff] [blame] | 227 | GET_PROC_SUFFIX(PathParameteri, NV); |
commit-bot@chromium.org | 9add5dc | 2014-04-29 20:06:22 +0000 | [diff] [blame] | 228 | GET_PROC_SUFFIX(PathParameterf, NV); |
commit-bot@chromium.org | 9add5dc | 2014-04-29 20:06:22 +0000 | [diff] [blame] | 229 | GET_PROC_SUFFIX(GenPaths, NV); |
| 230 | GET_PROC_SUFFIX(DeletePaths, NV); |
cdalton | 8dd90cb | 2014-07-17 09:28:36 -0700 | [diff] [blame] | 231 | GET_PROC_SUFFIX(IsPath, NV); |
commit-bot@chromium.org | 9add5dc | 2014-04-29 20:06:22 +0000 | [diff] [blame] | 232 | GET_PROC_SUFFIX(PathStencilFunc, NV); |
commit-bot@chromium.org | 9add5dc | 2014-04-29 20:06:22 +0000 | [diff] [blame] | 233 | GET_PROC_SUFFIX(StencilFillPath, NV); |
| 234 | GET_PROC_SUFFIX(StencilStrokePath, NV); |
| 235 | GET_PROC_SUFFIX(StencilFillPathInstanced, NV); |
| 236 | GET_PROC_SUFFIX(StencilStrokePathInstanced, NV); |
commit-bot@chromium.org | 9add5dc | 2014-04-29 20:06:22 +0000 | [diff] [blame] | 237 | GET_PROC_SUFFIX(PathTexGen, NV); |
commit-bot@chromium.org | 9add5dc | 2014-04-29 20:06:22 +0000 | [diff] [blame] | 238 | GET_PROC_SUFFIX(CoverFillPath, NV); |
| 239 | GET_PROC_SUFFIX(CoverStrokePath, NV); |
| 240 | GET_PROC_SUFFIX(CoverFillPathInstanced, NV); |
| 241 | GET_PROC_SUFFIX(CoverStrokePathInstanced, NV); |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame^] | 242 | // NV_path_rendering v1.2 (These methods may not be present) |
cdalton | c8f5204 | 2014-07-29 15:25:51 -0700 | [diff] [blame] | 243 | GET_PROC_SUFFIX(StencilThenCoverFillPath, NV); |
| 244 | GET_PROC_SUFFIX(StencilThenCoverStrokePath, NV); |
| 245 | GET_PROC_SUFFIX(StencilThenCoverFillPathInstanced, NV); |
| 246 | GET_PROC_SUFFIX(StencilThenCoverStrokePathInstanced, NV); |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame^] | 247 | // NV_path_rendering v1.3 (These methods may not be present) |
kkinnunen | 32b9a3b | 2014-07-02 22:56:35 -0700 | [diff] [blame] | 248 | GET_PROC_SUFFIX(ProgramPathFragmentInputGen, NV); |
commit-bot@chromium.org | 9add5dc | 2014-04-29 20:06:22 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | if (extensions.has("GL_EXT_debug_marker")) { |
| 252 | GET_PROC_SUFFIX(InsertEventMarker, EXT); |
| 253 | GET_PROC_SUFFIX(PushGroupMarker, EXT); |
| 254 | GET_PROC_SUFFIX(PopGroupMarker, EXT); |
| 255 | } |
| 256 | |
| 257 | if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_invalidate_subdata")) { |
| 258 | GET_PROC(InvalidateBufferData); |
| 259 | GET_PROC(InvalidateBufferSubData); |
| 260 | GET_PROC(InvalidateFramebuffer); |
| 261 | GET_PROC(InvalidateSubFramebuffer); |
| 262 | GET_PROC(InvalidateTexImage); |
| 263 | GET_PROC(InvalidateTexSubImage); |
| 264 | } |
| 265 | |
kkinnunen | 32b9a3b | 2014-07-02 22:56:35 -0700 | [diff] [blame] | 266 | if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_program_interface_query")) { |
| 267 | GET_PROC(GetProgramResourceLocation); |
| 268 | } |
| 269 | |
commit-bot@chromium.org | 9add5dc | 2014-04-29 20:06:22 +0000 | [diff] [blame] | 270 | interface->fStandard = kGL_GrGLStandard; |
| 271 | interface->fExtensions.swap(&extensions); |
| 272 | |
| 273 | return interface; |
| 274 | } |