michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include "gl/GrGLInterface.h" michael@0: #include "../GrGLUtil.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #define GR_GL_GET_PROC(F) interface->fFunctions.f ## F = (GrGL ## F ## Proc) \ michael@0: glXGetProcAddress(reinterpret_cast("gl" #F)); michael@0: #define GR_GL_GET_PROC_SUFFIX(F, S) interface->fFunctions.f ## F = (GrGL ## F ## Proc) \ michael@0: glXGetProcAddress(reinterpret_cast("gl" #F #S)); michael@0: michael@0: const GrGLInterface* GrGLCreateNativeInterface() { michael@0: if (NULL != glXGetCurrentContext()) { michael@0: michael@0: const char* versionString = (const char*) glGetString(GL_VERSION); michael@0: GrGLVersion glVer = GrGLGetVersionFromString(versionString); michael@0: michael@0: // This may or may not succeed depending on the gl version. michael@0: GrGLGetStringiProc glGetStringi = michael@0: (GrGLGetStringiProc) glXGetProcAddress(reinterpret_cast("glGetStringi")); michael@0: michael@0: GrGLExtensions extensions; michael@0: if (!extensions.init(kGL_GrGLStandard, glGetString, glGetStringi, glGetIntegerv)) { michael@0: return NULL; michael@0: } michael@0: michael@0: if (glVer < GR_GL_VER(1,5)) { michael@0: // We must have array and element_array buffer objects. michael@0: return NULL; michael@0: } michael@0: michael@0: GrGLInterface* interface = SkNEW(GrGLInterface()); michael@0: GrGLInterface::Functions* functions = &interface->fFunctions; michael@0: michael@0: functions->fActiveTexture = glActiveTexture; michael@0: GR_GL_GET_PROC(AttachShader); michael@0: GR_GL_GET_PROC(BindAttribLocation); michael@0: GR_GL_GET_PROC(BindBuffer); michael@0: GR_GL_GET_PROC(BindFragDataLocation); michael@0: GR_GL_GET_PROC(BeginQuery); michael@0: functions->fBindTexture = glBindTexture; michael@0: functions->fBlendFunc = glBlendFunc; michael@0: michael@0: if (glVer >= GR_GL_VER(1,4) || michael@0: extensions.has("GL_ARB_imaging") || michael@0: extensions.has("GL_EXT_blend_color")) { michael@0: GR_GL_GET_PROC(BlendColor); michael@0: } michael@0: michael@0: GR_GL_GET_PROC(BufferData); michael@0: GR_GL_GET_PROC(BufferSubData); michael@0: functions->fClear = glClear; michael@0: functions->fClearColor = glClearColor; michael@0: functions->fClearStencil = glClearStencil; michael@0: functions->fColorMask = glColorMask; michael@0: GR_GL_GET_PROC(CompileShader); michael@0: functions->fCompressedTexImage2D = glCompressedTexImage2D; michael@0: functions->fCopyTexSubImage2D = glCopyTexSubImage2D; michael@0: GR_GL_GET_PROC(CreateProgram); michael@0: GR_GL_GET_PROC(CreateShader); michael@0: functions->fCullFace = glCullFace; michael@0: GR_GL_GET_PROC(DeleteBuffers); michael@0: GR_GL_GET_PROC(DeleteProgram); michael@0: GR_GL_GET_PROC(DeleteQueries); michael@0: GR_GL_GET_PROC(DeleteShader); michael@0: functions->fDeleteTextures = glDeleteTextures; michael@0: functions->fDepthMask = glDepthMask; michael@0: functions->fDisable = glDisable; michael@0: GR_GL_GET_PROC(DisableVertexAttribArray); michael@0: functions->fDrawArrays = glDrawArrays; michael@0: functions->fDrawBuffer = glDrawBuffer; michael@0: GR_GL_GET_PROC(DrawBuffers); michael@0: functions->fDrawElements = glDrawElements; michael@0: functions->fEnable = glEnable; michael@0: GR_GL_GET_PROC(EnableVertexAttribArray); michael@0: GR_GL_GET_PROC(EndQuery); michael@0: functions->fFinish = glFinish; michael@0: functions->fFlush = glFlush; michael@0: functions->fFrontFace = glFrontFace; michael@0: GR_GL_GET_PROC(GenBuffers); michael@0: GR_GL_GET_PROC(GenerateMipmap); michael@0: GR_GL_GET_PROC(GetBufferParameteriv); michael@0: functions->fGetError = glGetError; michael@0: functions->fGetIntegerv = glGetIntegerv; michael@0: GR_GL_GET_PROC(GetQueryObjectiv); michael@0: GR_GL_GET_PROC(GetQueryObjectuiv); michael@0: if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) { michael@0: GR_GL_GET_PROC(GetQueryObjecti64v); michael@0: GR_GL_GET_PROC(GetQueryObjectui64v); michael@0: GR_GL_GET_PROC(QueryCounter); michael@0: } else if (extensions.has("GL_EXT_timer_query")) { michael@0: GR_GL_GET_PROC_SUFFIX(GetQueryObjecti64v, EXT); michael@0: GR_GL_GET_PROC_SUFFIX(GetQueryObjectui64v, EXT); michael@0: } michael@0: GR_GL_GET_PROC(GetQueryiv); michael@0: GR_GL_GET_PROC(GetProgramInfoLog); michael@0: GR_GL_GET_PROC(GetProgramiv); michael@0: GR_GL_GET_PROC(GetShaderInfoLog); michael@0: GR_GL_GET_PROC(GetShaderiv); michael@0: functions->fGetString = glGetString; michael@0: GR_GL_GET_PROC(GetStringi); michael@0: functions->fGetTexLevelParameteriv = glGetTexLevelParameteriv; michael@0: GR_GL_GET_PROC(GenQueries); michael@0: functions->fGenTextures = glGenTextures; michael@0: GR_GL_GET_PROC(GetUniformLocation); michael@0: functions->fLineWidth = glLineWidth; michael@0: GR_GL_GET_PROC(LinkProgram); michael@0: GR_GL_GET_PROC(MapBuffer); michael@0: functions->fPixelStorei = glPixelStorei; michael@0: functions->fReadBuffer = glReadBuffer; michael@0: functions->fReadPixels = glReadPixels; michael@0: functions->fScissor = glScissor; michael@0: GR_GL_GET_PROC(ShaderSource); michael@0: functions->fStencilFunc = glStencilFunc; michael@0: GR_GL_GET_PROC(StencilFuncSeparate); michael@0: functions->fStencilMask = glStencilMask; michael@0: GR_GL_GET_PROC(StencilMaskSeparate); michael@0: functions->fStencilOp = glStencilOp; michael@0: GR_GL_GET_PROC(StencilOpSeparate); michael@0: functions->fTexImage2D = glTexImage2D; michael@0: functions->fTexGenfv = glTexGenfv; michael@0: functions->fTexGeni = glTexGeni; michael@0: functions->fTexParameteri = glTexParameteri; michael@0: functions->fTexParameteriv = glTexParameteriv; michael@0: if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) { michael@0: GR_GL_GET_PROC(TexStorage2D); michael@0: } else if (extensions.has("GL_EXT_texture_storage")) { michael@0: GR_GL_GET_PROC_SUFFIX(TexStorage2D, EXT); michael@0: } michael@0: functions->fTexSubImage2D = glTexSubImage2D; michael@0: GR_GL_GET_PROC(Uniform1f); michael@0: GR_GL_GET_PROC(Uniform1i); michael@0: GR_GL_GET_PROC(Uniform1fv); michael@0: GR_GL_GET_PROC(Uniform1iv); michael@0: GR_GL_GET_PROC(Uniform2f); michael@0: GR_GL_GET_PROC(Uniform2i); michael@0: GR_GL_GET_PROC(Uniform2fv); michael@0: GR_GL_GET_PROC(Uniform2iv); michael@0: GR_GL_GET_PROC(Uniform3f); michael@0: GR_GL_GET_PROC(Uniform3i); michael@0: GR_GL_GET_PROC(Uniform3fv); michael@0: GR_GL_GET_PROC(Uniform3iv); michael@0: GR_GL_GET_PROC(Uniform4f); michael@0: GR_GL_GET_PROC(Uniform4i); michael@0: GR_GL_GET_PROC(Uniform4fv); michael@0: GR_GL_GET_PROC(Uniform4iv); michael@0: GR_GL_GET_PROC(UniformMatrix2fv); michael@0: GR_GL_GET_PROC(UniformMatrix3fv); michael@0: GR_GL_GET_PROC(UniformMatrix4fv); michael@0: GR_GL_GET_PROC(UnmapBuffer); michael@0: GR_GL_GET_PROC(UseProgram); michael@0: GR_GL_GET_PROC(VertexAttrib4fv); michael@0: GR_GL_GET_PROC(VertexAttribPointer); michael@0: functions->fViewport = glViewport; michael@0: GR_GL_GET_PROC(BindFragDataLocationIndexed); michael@0: michael@0: if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object")) { michael@0: // no ARB suffix for GL_ARB_vertex_array_object michael@0: GR_GL_GET_PROC(BindVertexArray); michael@0: GR_GL_GET_PROC(GenVertexArrays); michael@0: GR_GL_GET_PROC(DeleteVertexArrays); michael@0: } michael@0: michael@0: // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since michael@0: // GL_ARB_framebuffer_object doesn't use ARB suffix.) michael@0: if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) { michael@0: GR_GL_GET_PROC(GenFramebuffers); michael@0: GR_GL_GET_PROC(GetFramebufferAttachmentParameteriv); michael@0: GR_GL_GET_PROC(GetRenderbufferParameteriv); michael@0: GR_GL_GET_PROC(BindFramebuffer); michael@0: GR_GL_GET_PROC(FramebufferTexture2D); michael@0: GR_GL_GET_PROC(CheckFramebufferStatus); michael@0: GR_GL_GET_PROC(DeleteFramebuffers); michael@0: GR_GL_GET_PROC(RenderbufferStorage); michael@0: GR_GL_GET_PROC(GenRenderbuffers); michael@0: GR_GL_GET_PROC(DeleteRenderbuffers); michael@0: GR_GL_GET_PROC(FramebufferRenderbuffer); michael@0: GR_GL_GET_PROC(BindRenderbuffer); michael@0: GR_GL_GET_PROC(RenderbufferStorageMultisample); michael@0: GR_GL_GET_PROC(BlitFramebuffer); michael@0: } else if (extensions.has("GL_EXT_framebuffer_object")) { michael@0: GR_GL_GET_PROC_SUFFIX(GenFramebuffers, EXT); michael@0: GR_GL_GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT); michael@0: GR_GL_GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT); michael@0: GR_GL_GET_PROC_SUFFIX(BindFramebuffer, EXT); michael@0: GR_GL_GET_PROC_SUFFIX(FramebufferTexture2D, EXT); michael@0: GR_GL_GET_PROC_SUFFIX(CheckFramebufferStatus, EXT); michael@0: GR_GL_GET_PROC_SUFFIX(DeleteFramebuffers, EXT); michael@0: GR_GL_GET_PROC_SUFFIX(RenderbufferStorage, EXT); michael@0: GR_GL_GET_PROC_SUFFIX(GenRenderbuffers, EXT); michael@0: GR_GL_GET_PROC_SUFFIX(DeleteRenderbuffers, EXT); michael@0: GR_GL_GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT); michael@0: GR_GL_GET_PROC_SUFFIX(BindRenderbuffer, EXT); michael@0: if (extensions.has("GL_EXT_framebuffer_multisample")) { michael@0: GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT); michael@0: } michael@0: if (extensions.has("GL_EXT_framebuffer_blit")) { michael@0: GR_GL_GET_PROC_SUFFIX(BlitFramebuffer, EXT); michael@0: } michael@0: } else { michael@0: // we must have FBOs michael@0: delete interface; michael@0: return NULL; michael@0: } michael@0: michael@0: GR_GL_GET_PROC(LoadIdentity); michael@0: GR_GL_GET_PROC(LoadMatrixf); michael@0: GR_GL_GET_PROC(MatrixMode); michael@0: michael@0: if (extensions.has("GL_NV_path_rendering")) { michael@0: GR_GL_GET_PROC_SUFFIX(PathCommands, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PathCoords, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PathSubCommands, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PathSubCoords, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PathString, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PathGlyphs, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PathGlyphRange, NV); michael@0: GR_GL_GET_PROC_SUFFIX(WeightPaths, NV); michael@0: GR_GL_GET_PROC_SUFFIX(CopyPath, NV); michael@0: GR_GL_GET_PROC_SUFFIX(InterpolatePaths, NV); michael@0: GR_GL_GET_PROC_SUFFIX(TransformPath, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PathParameteriv, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PathParameteri, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PathParameterfv, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PathParameterf, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PathDashArray, NV); michael@0: GR_GL_GET_PROC_SUFFIX(GenPaths, NV); michael@0: GR_GL_GET_PROC_SUFFIX(DeletePaths, NV); michael@0: GR_GL_GET_PROC_SUFFIX(IsPath, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PathStencilFunc, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PathStencilDepthOffset, NV); michael@0: GR_GL_GET_PROC_SUFFIX(StencilFillPath, NV); michael@0: GR_GL_GET_PROC_SUFFIX(StencilStrokePath, NV); michael@0: GR_GL_GET_PROC_SUFFIX(StencilFillPathInstanced, NV); michael@0: GR_GL_GET_PROC_SUFFIX(StencilStrokePathInstanced, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PathCoverDepthFunc, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PathColorGen, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PathTexGen, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PathFogGen, NV); michael@0: GR_GL_GET_PROC_SUFFIX(CoverFillPath, NV); michael@0: GR_GL_GET_PROC_SUFFIX(CoverStrokePath, NV); michael@0: GR_GL_GET_PROC_SUFFIX(CoverFillPathInstanced, NV); michael@0: GR_GL_GET_PROC_SUFFIX(CoverStrokePathInstanced, NV); michael@0: GR_GL_GET_PROC_SUFFIX(GetPathParameteriv, NV); michael@0: GR_GL_GET_PROC_SUFFIX(GetPathParameterfv, NV); michael@0: GR_GL_GET_PROC_SUFFIX(GetPathCommands, NV); michael@0: GR_GL_GET_PROC_SUFFIX(GetPathCoords, NV); michael@0: GR_GL_GET_PROC_SUFFIX(GetPathDashArray, NV); michael@0: GR_GL_GET_PROC_SUFFIX(GetPathMetrics, NV); michael@0: GR_GL_GET_PROC_SUFFIX(GetPathMetricRange, NV); michael@0: GR_GL_GET_PROC_SUFFIX(GetPathSpacing, NV); michael@0: GR_GL_GET_PROC_SUFFIX(GetPathColorGeniv, NV); michael@0: GR_GL_GET_PROC_SUFFIX(GetPathColorGenfv, NV); michael@0: GR_GL_GET_PROC_SUFFIX(GetPathTexGeniv, NV); michael@0: GR_GL_GET_PROC_SUFFIX(GetPathTexGenfv, NV); michael@0: GR_GL_GET_PROC_SUFFIX(IsPointInFillPath, NV); michael@0: GR_GL_GET_PROC_SUFFIX(IsPointInStrokePath, NV); michael@0: GR_GL_GET_PROC_SUFFIX(GetPathLength, NV); michael@0: GR_GL_GET_PROC_SUFFIX(PointAlongPath, NV); michael@0: } michael@0: michael@0: if (extensions.has("GL_EXT_debug_marker")) { michael@0: GR_GL_GET_PROC_SUFFIX(InsertEventMarker, EXT); michael@0: GR_GL_GET_PROC_SUFFIX(PushGroupMarker, EXT); michael@0: GR_GL_GET_PROC_SUFFIX(PopGroupMarker, EXT); michael@0: } michael@0: michael@0: interface->fStandard = kGL_GrGLStandard; michael@0: interface->fExtensions.swap(&extensions); michael@0: michael@0: return interface; michael@0: } else { michael@0: return NULL; michael@0: } michael@0: }