| OLD | NEW |
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2011 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 4 * | 3 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 8 | 7 |
| 9 | 8 |
| 10 #include "gl/GrGLInterface.h" | 9 #include "gl/GrGLInterface.h" |
| 11 #include "../GrGLUtil.h" | 10 #include "gl/GrGLAssembleInterface.h" |
| 12 | 11 |
| 13 #include <GL/glx.h> | 12 #include <GL/glx.h> |
| 14 #include <GL/gl.h> | |
| 15 #include <GL/glext.h> | |
| 16 #include <GL/glu.h> | |
| 17 | 13 |
| 18 #define GET_PROC(F) interface->fFunctions.f ## F = (GrGL ## F ## Proc) \ | 14 static GrGLFuncPtr glx_get(void* ctx, const char name[]) { |
| 19 glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F)); | 15 SkASSERT(NULL == ctx); |
| 20 #define GET_PROC_SUFFIX(F, S) interface->fFunctions.f ## F = (GrGL ## F ## Proc)
\ | 16 SkASSERT(NULL != glXGetCurrentContext()); |
| 21 glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F #S)); | 17 return glXGetProcAddress(reinterpret_cast<const GLubyte*>(name)); |
| 18 } |
| 22 | 19 |
| 23 const GrGLInterface* GrGLCreateNativeInterface() { | 20 const GrGLInterface* GrGLCreateNativeInterface() { |
| 24 if (NULL == glXGetCurrentContext()) { | 21 if (NULL == glXGetCurrentContext()) { |
| 25 return NULL; | 22 return NULL; |
| 26 } | 23 } |
| 24 return GrGLAssembleGLInterface(NULL, glx_get); |
| 25 } |
| 27 | 26 |
| 28 const char* versionString = (const char*) glGetString(GL_VERSION); | |
| 29 GrGLVersion glVer = GrGLGetVersionFromString(versionString); | |
| 30 | |
| 31 // This may or may not succeed depending on the gl version. | |
| 32 GrGLGetStringiProc glGetStringi = | |
| 33 (GrGLGetStringiProc) glXGetProcAddress(reinterpret_cast<const GLubyte*>(
"glGetStringi")); | |
| 34 | |
| 35 GrGLExtensions extensions; | |
| 36 if (!extensions.init(kGL_GrGLStandard, glGetString, glGetStringi, glGetInteg
erv)) { | |
| 37 return NULL; | |
| 38 } | |
| 39 | |
| 40 if (glVer < GR_GL_VER(1,5)) { | |
| 41 // We must have array and element_array buffer objects. | |
| 42 return NULL; | |
| 43 } | |
| 44 | |
| 45 GrGLInterface* interface = SkNEW(GrGLInterface()); | |
| 46 GrGLInterface::Functions* functions = &interface->fFunctions; | |
| 47 | |
| 48 functions->fActiveTexture = glActiveTexture; | |
| 49 GET_PROC(AttachShader); | |
| 50 GET_PROC(BindAttribLocation); | |
| 51 GET_PROC(BindBuffer); | |
| 52 GET_PROC(BindFragDataLocation); | |
| 53 GET_PROC(BeginQuery); | |
| 54 functions->fBindTexture = glBindTexture; | |
| 55 functions->fBlendFunc = glBlendFunc; | |
| 56 | |
| 57 if (glVer >= GR_GL_VER(1,4) || | |
| 58 extensions.has("GL_ARB_imaging") || | |
| 59 extensions.has("GL_EXT_blend_color")) { | |
| 60 GET_PROC(BlendColor); | |
| 61 } | |
| 62 | |
| 63 GET_PROC(BufferData); | |
| 64 GET_PROC(BufferSubData); | |
| 65 functions->fClear = glClear; | |
| 66 functions->fClearColor = glClearColor; | |
| 67 functions->fClearStencil = glClearStencil; | |
| 68 functions->fColorMask = glColorMask; | |
| 69 GET_PROC(CompileShader); | |
| 70 functions->fCompressedTexImage2D = glCompressedTexImage2D; | |
| 71 functions->fCopyTexSubImage2D = glCopyTexSubImage2D; | |
| 72 GET_PROC(CreateProgram); | |
| 73 GET_PROC(CreateShader); | |
| 74 functions->fCullFace = glCullFace; | |
| 75 GET_PROC(DeleteBuffers); | |
| 76 GET_PROC(DeleteProgram); | |
| 77 GET_PROC(DeleteQueries); | |
| 78 GET_PROC(DeleteShader); | |
| 79 functions->fDeleteTextures = glDeleteTextures; | |
| 80 functions->fDepthMask = glDepthMask; | |
| 81 functions->fDisable = glDisable; | |
| 82 GET_PROC(DisableVertexAttribArray); | |
| 83 functions->fDrawArrays = glDrawArrays; | |
| 84 functions->fDrawBuffer = glDrawBuffer; | |
| 85 GET_PROC(DrawBuffers); | |
| 86 functions->fDrawElements = glDrawElements; | |
| 87 functions->fEnable = glEnable; | |
| 88 GET_PROC(EnableVertexAttribArray); | |
| 89 GET_PROC(EndQuery); | |
| 90 functions->fFinish = glFinish; | |
| 91 functions->fFlush = glFlush; | |
| 92 functions->fFrontFace = glFrontFace; | |
| 93 GET_PROC(GenBuffers); | |
| 94 GET_PROC(GenerateMipmap); | |
| 95 GET_PROC(GetBufferParameteriv); | |
| 96 functions->fGetError = glGetError; | |
| 97 functions->fGetIntegerv = glGetIntegerv; | |
| 98 GET_PROC(GetQueryObjectiv); | |
| 99 GET_PROC(GetQueryObjectuiv); | |
| 100 if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) { | |
| 101 GET_PROC(GetQueryObjecti64v); | |
| 102 GET_PROC(GetQueryObjectui64v); | |
| 103 GET_PROC(QueryCounter); | |
| 104 } else if (extensions.has("GL_EXT_timer_query")) { | |
| 105 GET_PROC_SUFFIX(GetQueryObjecti64v, EXT); | |
| 106 GET_PROC_SUFFIX(GetQueryObjectui64v, EXT); | |
| 107 } | |
| 108 GET_PROC(GetQueryiv); | |
| 109 GET_PROC(GetProgramInfoLog); | |
| 110 GET_PROC(GetProgramiv); | |
| 111 GET_PROC(GetShaderInfoLog); | |
| 112 GET_PROC(GetShaderiv); | |
| 113 functions->fGetString = glGetString; | |
| 114 GET_PROC(GetStringi); | |
| 115 functions->fGetTexLevelParameteriv = glGetTexLevelParameteriv; | |
| 116 GET_PROC(GenQueries); | |
| 117 functions->fGenTextures = glGenTextures; | |
| 118 GET_PROC(GetUniformLocation); | |
| 119 functions->fLineWidth = glLineWidth; | |
| 120 GET_PROC(LinkProgram); | |
| 121 GET_PROC(MapBuffer); | |
| 122 if (extensions.has("GL_EXT_direct_state_access")) { | |
| 123 GET_PROC_SUFFIX(MatrixLoadf, EXT); | |
| 124 GET_PROC_SUFFIX(MatrixLoadIdentity, EXT); | |
| 125 } | |
| 126 functions->fPixelStorei = glPixelStorei; | |
| 127 functions->fReadBuffer = glReadBuffer; | |
| 128 functions->fReadPixels = glReadPixels; | |
| 129 functions->fScissor = glScissor; | |
| 130 GET_PROC(ShaderSource); | |
| 131 functions->fStencilFunc = glStencilFunc; | |
| 132 GET_PROC(StencilFuncSeparate); | |
| 133 functions->fStencilMask = glStencilMask; | |
| 134 GET_PROC(StencilMaskSeparate); | |
| 135 functions->fStencilOp = glStencilOp; | |
| 136 GET_PROC(StencilOpSeparate); | |
| 137 functions->fTexImage2D = glTexImage2D; | |
| 138 functions->fTexParameteri = glTexParameteri; | |
| 139 functions->fTexParameteriv = glTexParameteriv; | |
| 140 if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) { | |
| 141 GET_PROC(TexStorage2D); | |
| 142 } else if (extensions.has("GL_EXT_texture_storage")) { | |
| 143 GET_PROC_SUFFIX(TexStorage2D, EXT); | |
| 144 } | |
| 145 functions->fTexSubImage2D = glTexSubImage2D; | |
| 146 GET_PROC(Uniform1f); | |
| 147 GET_PROC(Uniform1i); | |
| 148 GET_PROC(Uniform1fv); | |
| 149 GET_PROC(Uniform1iv); | |
| 150 GET_PROC(Uniform2f); | |
| 151 GET_PROC(Uniform2i); | |
| 152 GET_PROC(Uniform2fv); | |
| 153 GET_PROC(Uniform2iv); | |
| 154 GET_PROC(Uniform3f); | |
| 155 GET_PROC(Uniform3i); | |
| 156 GET_PROC(Uniform3fv); | |
| 157 GET_PROC(Uniform3iv); | |
| 158 GET_PROC(Uniform4f); | |
| 159 GET_PROC(Uniform4i); | |
| 160 GET_PROC(Uniform4fv); | |
| 161 GET_PROC(Uniform4iv); | |
| 162 GET_PROC(UniformMatrix2fv); | |
| 163 GET_PROC(UniformMatrix3fv); | |
| 164 GET_PROC(UniformMatrix4fv); | |
| 165 GET_PROC(UnmapBuffer); | |
| 166 GET_PROC(UseProgram); | |
| 167 GET_PROC(VertexAttrib4fv); | |
| 168 GET_PROC(VertexAttribPointer); | |
| 169 functions->fViewport = glViewport; | |
| 170 GET_PROC(BindFragDataLocationIndexed); | |
| 171 | |
| 172 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object"))
{ | |
| 173 // no ARB suffix for GL_ARB_vertex_array_object | |
| 174 GET_PROC(BindVertexArray); | |
| 175 GET_PROC(GenVertexArrays); | |
| 176 GET_PROC(DeleteVertexArrays); | |
| 177 } | |
| 178 | |
| 179 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since | |
| 180 // GL_ARB_framebuffer_object doesn't use ARB suffix.) | |
| 181 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object"))
{ | |
| 182 GET_PROC(GenFramebuffers); | |
| 183 GET_PROC(GetFramebufferAttachmentParameteriv); | |
| 184 GET_PROC(GetRenderbufferParameteriv); | |
| 185 GET_PROC(BindFramebuffer); | |
| 186 GET_PROC(FramebufferTexture2D); | |
| 187 GET_PROC(CheckFramebufferStatus); | |
| 188 GET_PROC(DeleteFramebuffers); | |
| 189 GET_PROC(RenderbufferStorage); | |
| 190 GET_PROC(GenRenderbuffers); | |
| 191 GET_PROC(DeleteRenderbuffers); | |
| 192 GET_PROC(FramebufferRenderbuffer); | |
| 193 GET_PROC(BindRenderbuffer); | |
| 194 GET_PROC(RenderbufferStorageMultisample); | |
| 195 GET_PROC(BlitFramebuffer); | |
| 196 } else if (extensions.has("GL_EXT_framebuffer_object")) { | |
| 197 GET_PROC_SUFFIX(GenFramebuffers, EXT); | |
| 198 GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT); | |
| 199 GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT); | |
| 200 GET_PROC_SUFFIX(BindFramebuffer, EXT); | |
| 201 GET_PROC_SUFFIX(FramebufferTexture2D, EXT); | |
| 202 GET_PROC_SUFFIX(CheckFramebufferStatus, EXT); | |
| 203 GET_PROC_SUFFIX(DeleteFramebuffers, EXT); | |
| 204 GET_PROC_SUFFIX(RenderbufferStorage, EXT); | |
| 205 GET_PROC_SUFFIX(GenRenderbuffers, EXT); | |
| 206 GET_PROC_SUFFIX(DeleteRenderbuffers, EXT); | |
| 207 GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT); | |
| 208 GET_PROC_SUFFIX(BindRenderbuffer, EXT); | |
| 209 if (extensions.has("GL_EXT_framebuffer_multisample")) { | |
| 210 GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT); | |
| 211 } | |
| 212 if (extensions.has("GL_EXT_framebuffer_blit")) { | |
| 213 GET_PROC_SUFFIX(BlitFramebuffer, EXT); | |
| 214 } | |
| 215 } else { | |
| 216 // we must have FBOs | |
| 217 delete interface; | |
| 218 return NULL; | |
| 219 } | |
| 220 | |
| 221 if (extensions.has("GL_NV_path_rendering")) { | |
| 222 GET_PROC_SUFFIX(PathCommands, NV); | |
| 223 GET_PROC_SUFFIX(PathCoords, NV); | |
| 224 GET_PROC_SUFFIX(PathSubCommands, NV); | |
| 225 GET_PROC_SUFFIX(PathSubCoords, NV); | |
| 226 GET_PROC_SUFFIX(PathString, NV); | |
| 227 GET_PROC_SUFFIX(PathGlyphs, NV); | |
| 228 GET_PROC_SUFFIX(PathGlyphRange, NV); | |
| 229 GET_PROC_SUFFIX(WeightPaths, NV); | |
| 230 GET_PROC_SUFFIX(CopyPath, NV); | |
| 231 GET_PROC_SUFFIX(InterpolatePaths, NV); | |
| 232 GET_PROC_SUFFIX(TransformPath, NV); | |
| 233 GET_PROC_SUFFIX(PathParameteriv, NV); | |
| 234 GET_PROC_SUFFIX(PathParameteri, NV); | |
| 235 GET_PROC_SUFFIX(PathParameterfv, NV); | |
| 236 GET_PROC_SUFFIX(PathParameterf, NV); | |
| 237 GET_PROC_SUFFIX(PathDashArray, NV); | |
| 238 GET_PROC_SUFFIX(GenPaths, NV); | |
| 239 GET_PROC_SUFFIX(DeletePaths, NV); | |
| 240 GET_PROC_SUFFIX(IsPath, NV); | |
| 241 GET_PROC_SUFFIX(PathStencilFunc, NV); | |
| 242 GET_PROC_SUFFIX(PathStencilDepthOffset, NV); | |
| 243 GET_PROC_SUFFIX(StencilFillPath, NV); | |
| 244 GET_PROC_SUFFIX(StencilStrokePath, NV); | |
| 245 GET_PROC_SUFFIX(StencilFillPathInstanced, NV); | |
| 246 GET_PROC_SUFFIX(StencilStrokePathInstanced, NV); | |
| 247 GET_PROC_SUFFIX(PathCoverDepthFunc, NV); | |
| 248 GET_PROC_SUFFIX(PathColorGen, NV); | |
| 249 GET_PROC_SUFFIX(PathTexGen, NV); | |
| 250 GET_PROC_SUFFIX(PathFogGen, NV); | |
| 251 GET_PROC_SUFFIX(CoverFillPath, NV); | |
| 252 GET_PROC_SUFFIX(CoverStrokePath, NV); | |
| 253 GET_PROC_SUFFIX(CoverFillPathInstanced, NV); | |
| 254 GET_PROC_SUFFIX(CoverStrokePathInstanced, NV); | |
| 255 GET_PROC_SUFFIX(GetPathParameteriv, NV); | |
| 256 GET_PROC_SUFFIX(GetPathParameterfv, NV); | |
| 257 GET_PROC_SUFFIX(GetPathCommands, NV); | |
| 258 GET_PROC_SUFFIX(GetPathCoords, NV); | |
| 259 GET_PROC_SUFFIX(GetPathDashArray, NV); | |
| 260 GET_PROC_SUFFIX(GetPathMetrics, NV); | |
| 261 GET_PROC_SUFFIX(GetPathMetricRange, NV); | |
| 262 GET_PROC_SUFFIX(GetPathSpacing, NV); | |
| 263 GET_PROC_SUFFIX(GetPathColorGeniv, NV); | |
| 264 GET_PROC_SUFFIX(GetPathColorGenfv, NV); | |
| 265 GET_PROC_SUFFIX(GetPathTexGeniv, NV); | |
| 266 GET_PROC_SUFFIX(GetPathTexGenfv, NV); | |
| 267 GET_PROC_SUFFIX(IsPointInFillPath, NV); | |
| 268 GET_PROC_SUFFIX(IsPointInStrokePath, NV); | |
| 269 GET_PROC_SUFFIX(GetPathLength, NV); | |
| 270 GET_PROC_SUFFIX(PointAlongPath, NV); | |
| 271 } | |
| 272 | |
| 273 if (extensions.has("GL_EXT_debug_marker")) { | |
| 274 GET_PROC_SUFFIX(InsertEventMarker, EXT); | |
| 275 GET_PROC_SUFFIX(PushGroupMarker, EXT); | |
| 276 GET_PROC_SUFFIX(PopGroupMarker, EXT); | |
| 277 } | |
| 278 | |
| 279 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_invalidate_subdata"))
{ | |
| 280 GET_PROC(InvalidateBufferData); | |
| 281 GET_PROC(InvalidateBufferSubData); | |
| 282 GET_PROC(InvalidateFramebuffer); | |
| 283 GET_PROC(InvalidateSubFramebuffer); | |
| 284 GET_PROC(InvalidateTexImage); | |
| 285 GET_PROC(InvalidateTexSubImage); | |
| 286 } | |
| 287 | |
| 288 interface->fStandard = kGL_GrGLStandard; | |
| 289 interface->fExtensions.swap(&extensions); | |
| 290 | |
| 291 return interface; | |
| 292 } | |
| OLD | NEW |