| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2014 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "gl/GrGLInterface.h" | 10 #include "GrGLAssembleInterface.h" |
| 11 #include "../GrGLUtil.h" | 11 #include "GrGLUtil.h" |
| 12 | 12 |
| 13 #include <GL/glx.h> | 13 #define GET_PROC(F) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F) |
| 14 #include <GL/gl.h> | 14 #define GET_PROC_SUFFIX(F, S) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "
gl" #F #S) |
| 15 #include <GL/glext.h> | 15 #define GET_PROC_LOCAL(F) GrGL ## F ## Proc F = (GrGL ## F ## Proc) get(ctx, "gl
" #F) |
| 16 #include <GL/glu.h> | |
| 17 | 16 |
| 18 #define GET_PROC(F) interface->fFunctions.f ## F = (GrGL ## F ## Proc) \ | 17 const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) { |
| 19 glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F)); | 18 GET_PROC_LOCAL(GetString); |
| 20 #define GET_PROC_SUFFIX(F, S) interface->fFunctions.f ## F = (GrGL ## F ## Proc)
\ | 19 GET_PROC_LOCAL(GetStringi); |
| 21 glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F #S)); | 20 GET_PROC_LOCAL(GetIntegerv); |
| 22 | 21 |
| 23 const GrGLInterface* GrGLCreateNativeInterface() { | 22 // GetStringi may be NULL depending on the GL version. |
| 24 if (NULL == glXGetCurrentContext()) { | 23 if (NULL == GetString || NULL == GetIntegerv) { |
| 25 return NULL; | 24 return NULL; |
| 26 } | 25 } |
| 27 | 26 |
| 28 const char* versionString = (const char*) glGetString(GL_VERSION); | 27 const char* versionString = (const char*) GetString(GR_GL_VERSION); |
| 29 GrGLVersion glVer = GrGLGetVersionFromString(versionString); | 28 GrGLVersion glVer = GrGLGetVersionFromString(versionString); |
| 30 | 29 |
| 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)) { | 30 if (glVer < GR_GL_VER(1,5)) { |
| 41 // We must have array and element_array buffer objects. | 31 // We must have array and element_array buffer objects. |
| 42 return NULL; | 32 return NULL; |
| 43 } | 33 } |
| 44 | 34 |
| 35 GrGLExtensions extensions; |
| 36 if (!extensions.init(kGL_GrGLStandard, GetString, GetStringi, GetIntegerv))
{ |
| 37 return NULL; |
| 38 } |
| 39 |
| 45 GrGLInterface* interface = SkNEW(GrGLInterface()); | 40 GrGLInterface* interface = SkNEW(GrGLInterface()); |
| 46 GrGLInterface::Functions* functions = &interface->fFunctions; | 41 GrGLInterface::Functions* functions = &interface->fFunctions; |
| 47 | 42 |
| 48 functions->fActiveTexture = glActiveTexture; | 43 GET_PROC(ActiveTexture); |
| 49 GET_PROC(AttachShader); | 44 GET_PROC(AttachShader); |
| 50 GET_PROC(BindAttribLocation); | 45 GET_PROC(BindAttribLocation); |
| 51 GET_PROC(BindBuffer); | 46 GET_PROC(BindBuffer); |
| 52 GET_PROC(BindFragDataLocation); | 47 if (glVer >= GR_GL_VER(3,0)) { |
| 48 GET_PROC(BindFragDataLocation); |
| 49 } |
| 53 GET_PROC(BeginQuery); | 50 GET_PROC(BeginQuery); |
| 54 functions->fBindTexture = glBindTexture; | 51 GET_PROC(BindTexture); |
| 55 functions->fBlendFunc = glBlendFunc; | 52 GET_PROC(BlendFunc); |
| 56 | 53 |
| 57 if (glVer >= GR_GL_VER(1,4) || | 54 if (glVer >= GR_GL_VER(1,4) || |
| 58 extensions.has("GL_ARB_imaging") || | 55 extensions.has("GL_ARB_imaging") || |
| 59 extensions.has("GL_EXT_blend_color")) { | 56 extensions.has("GL_EXT_blend_color")) { |
| 60 GET_PROC(BlendColor); | 57 GET_PROC(BlendColor); |
| 61 } | 58 } |
| 62 | 59 |
| 63 GET_PROC(BufferData); | 60 GET_PROC(BufferData); |
| 64 GET_PROC(BufferSubData); | 61 GET_PROC(BufferSubData); |
| 65 functions->fClear = glClear; | 62 GET_PROC(Clear); |
| 66 functions->fClearColor = glClearColor; | 63 GET_PROC(ClearColor); |
| 67 functions->fClearStencil = glClearStencil; | 64 GET_PROC(ClearStencil); |
| 68 functions->fColorMask = glColorMask; | 65 GET_PROC(ColorMask); |
| 69 GET_PROC(CompileShader); | 66 GET_PROC(CompileShader); |
| 70 functions->fCompressedTexImage2D = glCompressedTexImage2D; | 67 GET_PROC(CompressedTexImage2D); |
| 71 functions->fCopyTexSubImage2D = glCopyTexSubImage2D; | 68 GET_PROC(CopyTexSubImage2D); |
| 72 GET_PROC(CreateProgram); | 69 GET_PROC(CreateProgram); |
| 73 GET_PROC(CreateShader); | 70 GET_PROC(CreateShader); |
| 74 functions->fCullFace = glCullFace; | 71 GET_PROC(CullFace); |
| 75 GET_PROC(DeleteBuffers); | 72 GET_PROC(DeleteBuffers); |
| 76 GET_PROC(DeleteProgram); | 73 GET_PROC(DeleteProgram); |
| 77 GET_PROC(DeleteQueries); | 74 GET_PROC(DeleteQueries); |
| 78 GET_PROC(DeleteShader); | 75 GET_PROC(DeleteShader); |
| 79 functions->fDeleteTextures = glDeleteTextures; | 76 GET_PROC(DeleteTextures); |
| 80 functions->fDepthMask = glDepthMask; | 77 GET_PROC(DepthMask); |
| 81 functions->fDisable = glDisable; | 78 GET_PROC(Disable); |
| 82 GET_PROC(DisableVertexAttribArray); | 79 GET_PROC(DisableVertexAttribArray); |
| 83 functions->fDrawArrays = glDrawArrays; | 80 GET_PROC(DrawArrays); |
| 84 functions->fDrawBuffer = glDrawBuffer; | 81 GET_PROC(DrawBuffer); |
| 85 GET_PROC(DrawBuffers); | 82 GET_PROC(DrawBuffers); |
| 86 functions->fDrawElements = glDrawElements; | 83 GET_PROC(DrawElements); |
| 87 functions->fEnable = glEnable; | 84 GET_PROC(Enable); |
| 88 GET_PROC(EnableVertexAttribArray); | 85 GET_PROC(EnableVertexAttribArray); |
| 89 GET_PROC(EndQuery); | 86 GET_PROC(EndQuery); |
| 90 functions->fFinish = glFinish; | 87 GET_PROC(Finish); |
| 91 functions->fFlush = glFlush; | 88 GET_PROC(Flush); |
| 92 functions->fFrontFace = glFrontFace; | 89 GET_PROC(FrontFace); |
| 93 GET_PROC(GenBuffers); | 90 GET_PROC(GenBuffers); |
| 94 GET_PROC(GenerateMipmap); | 91 GET_PROC(GenerateMipmap); |
| 95 GET_PROC(GetBufferParameteriv); | 92 GET_PROC(GetBufferParameteriv); |
| 96 functions->fGetError = glGetError; | 93 GET_PROC(GetError); |
| 97 functions->fGetIntegerv = glGetIntegerv; | 94 GET_PROC(GetIntegerv); |
| 98 GET_PROC(GetQueryObjectiv); | 95 GET_PROC(GetQueryObjectiv); |
| 99 GET_PROC(GetQueryObjectuiv); | 96 GET_PROC(GetQueryObjectuiv); |
| 100 if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) { | 97 if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) { |
| 101 GET_PROC(GetQueryObjecti64v); | 98 GET_PROC(GetQueryObjecti64v); |
| 102 GET_PROC(GetQueryObjectui64v); | 99 GET_PROC(GetQueryObjectui64v); |
| 103 GET_PROC(QueryCounter); | 100 GET_PROC(QueryCounter); |
| 104 } else if (extensions.has("GL_EXT_timer_query")) { | 101 } else if (extensions.has("GL_EXT_timer_query")) { |
| 105 GET_PROC_SUFFIX(GetQueryObjecti64v, EXT); | 102 GET_PROC_SUFFIX(GetQueryObjecti64v, EXT); |
| 106 GET_PROC_SUFFIX(GetQueryObjectui64v, EXT); | 103 GET_PROC_SUFFIX(GetQueryObjectui64v, EXT); |
| 107 } | 104 } |
| 108 GET_PROC(GetQueryiv); | 105 GET_PROC(GetQueryiv); |
| 109 GET_PROC(GetProgramInfoLog); | 106 GET_PROC(GetProgramInfoLog); |
| 110 GET_PROC(GetProgramiv); | 107 GET_PROC(GetProgramiv); |
| 111 GET_PROC(GetShaderInfoLog); | 108 GET_PROC(GetShaderInfoLog); |
| 112 GET_PROC(GetShaderiv); | 109 GET_PROC(GetShaderiv); |
| 113 functions->fGetString = glGetString; | 110 GET_PROC(GetString); |
| 114 GET_PROC(GetStringi); | 111 GET_PROC(GetStringi); |
| 115 functions->fGetTexLevelParameteriv = glGetTexLevelParameteriv; | 112 GET_PROC(GetTexLevelParameteriv); |
| 116 GET_PROC(GenQueries); | 113 GET_PROC(GenQueries); |
| 117 functions->fGenTextures = glGenTextures; | 114 GET_PROC(GenTextures); |
| 118 GET_PROC(GetUniformLocation); | 115 GET_PROC(GetUniformLocation); |
| 119 functions->fLineWidth = glLineWidth; | 116 GET_PROC(LineWidth); |
| 120 GET_PROC(LinkProgram); | 117 GET_PROC(LinkProgram); |
| 121 GET_PROC(MapBuffer); | 118 GET_PROC(MapBuffer); |
| 122 if (extensions.has("GL_EXT_direct_state_access")) { | 119 if (extensions.has("GL_EXT_direct_state_access")) { |
| 123 GET_PROC_SUFFIX(MatrixLoadf, EXT); | 120 GET_PROC_SUFFIX(MatrixLoadf, EXT); |
| 124 GET_PROC_SUFFIX(MatrixLoadIdentity, EXT); | 121 GET_PROC_SUFFIX(MatrixLoadIdentity, EXT); |
| 125 } | 122 } |
| 126 functions->fPixelStorei = glPixelStorei; | 123 GET_PROC(PixelStorei); |
| 127 functions->fReadBuffer = glReadBuffer; | 124 GET_PROC(ReadBuffer); |
| 128 functions->fReadPixels = glReadPixels; | 125 GET_PROC(ReadPixels); |
| 129 functions->fScissor = glScissor; | 126 GET_PROC(Scissor); |
| 130 GET_PROC(ShaderSource); | 127 GET_PROC(ShaderSource); |
| 131 functions->fStencilFunc = glStencilFunc; | 128 GET_PROC(StencilFunc); |
| 132 GET_PROC(StencilFuncSeparate); | 129 GET_PROC(StencilFuncSeparate); |
| 133 functions->fStencilMask = glStencilMask; | 130 GET_PROC(StencilMask); |
| 134 GET_PROC(StencilMaskSeparate); | 131 GET_PROC(StencilMaskSeparate); |
| 135 functions->fStencilOp = glStencilOp; | 132 GET_PROC(StencilOp); |
| 136 GET_PROC(StencilOpSeparate); | 133 GET_PROC(StencilOpSeparate); |
| 137 functions->fTexImage2D = glTexImage2D; | 134 GET_PROC(TexImage2D); |
| 138 functions->fTexParameteri = glTexParameteri; | 135 GET_PROC(TexParameteri); |
| 139 functions->fTexParameteriv = glTexParameteriv; | 136 GET_PROC(TexParameteriv); |
| 140 if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) { | 137 if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) { |
| 141 GET_PROC(TexStorage2D); | 138 GET_PROC(TexStorage2D); |
| 142 } else if (extensions.has("GL_EXT_texture_storage")) { | 139 } else if (extensions.has("GL_EXT_texture_storage")) { |
| 143 GET_PROC_SUFFIX(TexStorage2D, EXT); | 140 GET_PROC_SUFFIX(TexStorage2D, EXT); |
| 144 } | 141 } |
| 145 functions->fTexSubImage2D = glTexSubImage2D; | 142 GET_PROC(TexSubImage2D); |
| 146 GET_PROC(Uniform1f); | 143 GET_PROC(Uniform1f); |
| 147 GET_PROC(Uniform1i); | 144 GET_PROC(Uniform1i); |
| 148 GET_PROC(Uniform1fv); | 145 GET_PROC(Uniform1fv); |
| 149 GET_PROC(Uniform1iv); | 146 GET_PROC(Uniform1iv); |
| 150 GET_PROC(Uniform2f); | 147 GET_PROC(Uniform2f); |
| 151 GET_PROC(Uniform2i); | 148 GET_PROC(Uniform2i); |
| 152 GET_PROC(Uniform2fv); | 149 GET_PROC(Uniform2fv); |
| 153 GET_PROC(Uniform2iv); | 150 GET_PROC(Uniform2iv); |
| 154 GET_PROC(Uniform3f); | 151 GET_PROC(Uniform3f); |
| 155 GET_PROC(Uniform3i); | 152 GET_PROC(Uniform3i); |
| 156 GET_PROC(Uniform3fv); | 153 GET_PROC(Uniform3fv); |
| 157 GET_PROC(Uniform3iv); | 154 GET_PROC(Uniform3iv); |
| 158 GET_PROC(Uniform4f); | 155 GET_PROC(Uniform4f); |
| 159 GET_PROC(Uniform4i); | 156 GET_PROC(Uniform4i); |
| 160 GET_PROC(Uniform4fv); | 157 GET_PROC(Uniform4fv); |
| 161 GET_PROC(Uniform4iv); | 158 GET_PROC(Uniform4iv); |
| 162 GET_PROC(UniformMatrix2fv); | 159 GET_PROC(UniformMatrix2fv); |
| 163 GET_PROC(UniformMatrix3fv); | 160 GET_PROC(UniformMatrix3fv); |
| 164 GET_PROC(UniformMatrix4fv); | 161 GET_PROC(UniformMatrix4fv); |
| 165 GET_PROC(UnmapBuffer); | 162 GET_PROC(UnmapBuffer); |
| 166 GET_PROC(UseProgram); | 163 GET_PROC(UseProgram); |
| 167 GET_PROC(VertexAttrib4fv); | 164 GET_PROC(VertexAttrib4fv); |
| 168 GET_PROC(VertexAttribPointer); | 165 GET_PROC(VertexAttribPointer); |
| 169 functions->fViewport = glViewport; | 166 GET_PROC(Viewport); |
| 170 GET_PROC(BindFragDataLocationIndexed); | 167 GET_PROC(BindFragDataLocationIndexed); |
| 171 | 168 |
| 172 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object"))
{ | 169 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object"))
{ |
| 173 // no ARB suffix for GL_ARB_vertex_array_object | 170 // no ARB suffix for GL_ARB_vertex_array_object |
| 174 GET_PROC(BindVertexArray); | 171 GET_PROC(BindVertexArray); |
| 175 GET_PROC(GenVertexArrays); | 172 GET_PROC(GenVertexArrays); |
| 176 GET_PROC(DeleteVertexArrays); | 173 GET_PROC(DeleteVertexArrays); |
| 177 } | 174 } |
| 178 | 175 |
| 179 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since | 176 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 GET_PROC(InvalidateSubFramebuffer); | 280 GET_PROC(InvalidateSubFramebuffer); |
| 284 GET_PROC(InvalidateTexImage); | 281 GET_PROC(InvalidateTexImage); |
| 285 GET_PROC(InvalidateTexSubImage); | 282 GET_PROC(InvalidateTexSubImage); |
| 286 } | 283 } |
| 287 | 284 |
| 288 interface->fStandard = kGL_GrGLStandard; | 285 interface->fStandard = kGL_GrGLStandard; |
| 289 interface->fExtensions.swap(&extensions); | 286 interface->fExtensions.swap(&extensions); |
| 290 | 287 |
| 291 return interface; | 288 return interface; |
| 292 } | 289 } |
| OLD | NEW |