| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 "gl/GrGLInterface.h" |
| 11 #include "../GrGLUtil.h" | 11 #include "../GrGLUtil.h" |
| 12 | 12 |
| 13 #include <GL/glx.h> | 13 #include <GL/glx.h> |
| 14 #include <GL/gl.h> | 14 #include <GL/gl.h> |
| 15 #include <GL/glext.h> | 15 #include <GL/glext.h> |
| 16 #include <GL/glu.h> | 16 #include <GL/glu.h> |
| 17 | 17 |
| 18 #define GR_GL_GET_PROC(F) interface->f ## F = (GrGL ## F ## Proc) \ | 18 #define GR_GL_GET_PROC(F) interface->fFunctions.f ## F = (GrGL ## F ## Proc) \ |
| 19 glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F)); | 19 glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F)); |
| 20 #define GR_GL_GET_PROC_SUFFIX(F, S) interface->f ## F = (GrGL ## F ## Proc) \ | 20 #define GR_GL_GET_PROC_SUFFIX(F, S) interface->fFunctions.f ## F = (GrGL ## F ##
Proc) \ |
| 21 glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F #S)); | 21 glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F #S)); |
| 22 | 22 |
| 23 const GrGLInterface* GrGLCreateNativeInterface() { | 23 const GrGLInterface* GrGLCreateNativeInterface() { |
| 24 if (NULL != glXGetCurrentContext()) { | 24 if (NULL != glXGetCurrentContext()) { |
| 25 | 25 |
| 26 const char* versionString = (const char*) glGetString(GL_VERSION); | 26 const char* versionString = (const char*) glGetString(GL_VERSION); |
| 27 GrGLVersion glVer = GrGLGetVersionFromString(versionString); | 27 GrGLVersion glVer = GrGLGetVersionFromString(versionString); |
| 28 | 28 |
| 29 // This may or may not succeed depending on the gl version. | 29 // This may or may not succeed depending on the gl version. |
| 30 GrGLGetStringiProc glGetStringi = | 30 GrGLGetStringiProc glGetStringi = |
| 31 (GrGLGetStringiProc) glXGetProcAddress(reinterpret_cast<const GLubyt
e*>("glGetStringi")); | 31 (GrGLGetStringiProc) glXGetProcAddress(reinterpret_cast<const GLubyt
e*>("glGetStringi")); |
| 32 | 32 |
| 33 GrGLExtensions extensions; | 33 GrGLExtensions extensions; |
| 34 if (!extensions.init(kGL_GrGLStandard, glGetString, glGetStringi, glGetI
ntegerv)) { | 34 if (!extensions.init(kGL_GrGLStandard, glGetString, glGetStringi, glGetI
ntegerv)) { |
| 35 return NULL; | 35 return NULL; |
| 36 } | 36 } |
| 37 | 37 |
| 38 if (glVer < GR_GL_VER(1,5)) { | 38 if (glVer < GR_GL_VER(1,5)) { |
| 39 // We must have array and element_array buffer objects. | 39 // We must have array and element_array buffer objects. |
| 40 return NULL; | 40 return NULL; |
| 41 } | 41 } |
| 42 | 42 |
| 43 GrGLInterface* interface = SkNEW(GrGLInterface()); | 43 GrGLInterface* interface = SkNEW(GrGLInterface()); |
| 44 GrGLInterface::Functions* functions = &interface->fFunctions; |
| 44 | 45 |
| 45 interface->fActiveTexture = glActiveTexture; | 46 functions->fActiveTexture = glActiveTexture; |
| 46 GR_GL_GET_PROC(AttachShader); | 47 GR_GL_GET_PROC(AttachShader); |
| 47 GR_GL_GET_PROC(BindAttribLocation); | 48 GR_GL_GET_PROC(BindAttribLocation); |
| 48 GR_GL_GET_PROC(BindBuffer); | 49 GR_GL_GET_PROC(BindBuffer); |
| 49 GR_GL_GET_PROC(BindFragDataLocation); | 50 GR_GL_GET_PROC(BindFragDataLocation); |
| 50 GR_GL_GET_PROC(BeginQuery); | 51 GR_GL_GET_PROC(BeginQuery); |
| 51 interface->fBindTexture = glBindTexture; | 52 functions->fBindTexture = glBindTexture; |
| 52 interface->fBlendFunc = glBlendFunc; | 53 functions->fBlendFunc = glBlendFunc; |
| 53 | 54 |
| 54 if (glVer >= GR_GL_VER(1,4) || | 55 if (glVer >= GR_GL_VER(1,4) || |
| 55 extensions.has("GL_ARB_imaging") || | 56 extensions.has("GL_ARB_imaging") || |
| 56 extensions.has("GL_EXT_blend_color")) { | 57 extensions.has("GL_EXT_blend_color")) { |
| 57 GR_GL_GET_PROC(BlendColor); | 58 GR_GL_GET_PROC(BlendColor); |
| 58 } | 59 } |
| 59 | 60 |
| 60 GR_GL_GET_PROC(BufferData); | 61 GR_GL_GET_PROC(BufferData); |
| 61 GR_GL_GET_PROC(BufferSubData); | 62 GR_GL_GET_PROC(BufferSubData); |
| 62 interface->fClear = glClear; | 63 functions->fClear = glClear; |
| 63 interface->fClearColor = glClearColor; | 64 functions->fClearColor = glClearColor; |
| 64 interface->fClearStencil = glClearStencil; | 65 functions->fClearStencil = glClearStencil; |
| 65 interface->fClientActiveTexture = glClientActiveTexture; | 66 functions->fClientActiveTexture = glClientActiveTexture; |
| 66 interface->fColorMask = glColorMask; | 67 functions->fColorMask = glColorMask; |
| 67 GR_GL_GET_PROC(CompileShader); | 68 GR_GL_GET_PROC(CompileShader); |
| 68 interface->fCompressedTexImage2D = glCompressedTexImage2D; | 69 functions->fCompressedTexImage2D = glCompressedTexImage2D; |
| 69 interface->fCopyTexSubImage2D = glCopyTexSubImage2D; | 70 functions->fCopyTexSubImage2D = glCopyTexSubImage2D; |
| 70 GR_GL_GET_PROC(CreateProgram); | 71 GR_GL_GET_PROC(CreateProgram); |
| 71 GR_GL_GET_PROC(CreateShader); | 72 GR_GL_GET_PROC(CreateShader); |
| 72 interface->fCullFace = glCullFace; | 73 functions->fCullFace = glCullFace; |
| 73 GR_GL_GET_PROC(DeleteBuffers); | 74 GR_GL_GET_PROC(DeleteBuffers); |
| 74 GR_GL_GET_PROC(DeleteProgram); | 75 GR_GL_GET_PROC(DeleteProgram); |
| 75 GR_GL_GET_PROC(DeleteQueries); | 76 GR_GL_GET_PROC(DeleteQueries); |
| 76 GR_GL_GET_PROC(DeleteShader); | 77 GR_GL_GET_PROC(DeleteShader); |
| 77 interface->fDeleteTextures = glDeleteTextures; | 78 functions->fDeleteTextures = glDeleteTextures; |
| 78 interface->fDepthMask = glDepthMask; | 79 functions->fDepthMask = glDepthMask; |
| 79 interface->fDisable = glDisable; | 80 functions->fDisable = glDisable; |
| 80 interface->fDisableClientState = glDisableClientState; | 81 functions->fDisableClientState = glDisableClientState; |
| 81 GR_GL_GET_PROC(DisableVertexAttribArray); | 82 GR_GL_GET_PROC(DisableVertexAttribArray); |
| 82 interface->fDrawArrays = glDrawArrays; | 83 functions->fDrawArrays = glDrawArrays; |
| 83 interface->fDrawBuffer = glDrawBuffer; | 84 functions->fDrawBuffer = glDrawBuffer; |
| 84 GR_GL_GET_PROC(DrawBuffers); | 85 GR_GL_GET_PROC(DrawBuffers); |
| 85 interface->fDrawElements = glDrawElements; | 86 functions->fDrawElements = glDrawElements; |
| 86 interface->fEnable = glEnable; | 87 functions->fEnable = glEnable; |
| 87 interface->fEnableClientState = glEnableClientState; | 88 functions->fEnableClientState = glEnableClientState; |
| 88 GR_GL_GET_PROC(EnableVertexAttribArray); | 89 GR_GL_GET_PROC(EnableVertexAttribArray); |
| 89 GR_GL_GET_PROC(EndQuery); | 90 GR_GL_GET_PROC(EndQuery); |
| 90 interface->fFinish = glFinish; | 91 functions->fFinish = glFinish; |
| 91 interface->fFlush = glFlush; | 92 functions->fFlush = glFlush; |
| 92 interface->fFrontFace = glFrontFace; | 93 functions->fFrontFace = glFrontFace; |
| 93 GR_GL_GET_PROC(GenBuffers); | 94 GR_GL_GET_PROC(GenBuffers); |
| 94 GR_GL_GET_PROC(GenerateMipmap); | 95 GR_GL_GET_PROC(GenerateMipmap); |
| 95 GR_GL_GET_PROC(GetBufferParameteriv); | 96 GR_GL_GET_PROC(GetBufferParameteriv); |
| 96 interface->fGetError = glGetError; | 97 functions->fGetError = glGetError; |
| 97 interface->fGetIntegerv = glGetIntegerv; | 98 functions->fGetIntegerv = glGetIntegerv; |
| 98 GR_GL_GET_PROC(GetQueryObjectiv); | 99 GR_GL_GET_PROC(GetQueryObjectiv); |
| 99 GR_GL_GET_PROC(GetQueryObjectuiv); | 100 GR_GL_GET_PROC(GetQueryObjectuiv); |
| 100 if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) { | 101 if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) { |
| 101 GR_GL_GET_PROC(GetQueryObjecti64v); | 102 GR_GL_GET_PROC(GetQueryObjecti64v); |
| 102 GR_GL_GET_PROC(GetQueryObjectui64v); | 103 GR_GL_GET_PROC(GetQueryObjectui64v); |
| 103 GR_GL_GET_PROC(QueryCounter); | 104 GR_GL_GET_PROC(QueryCounter); |
| 104 } else if (extensions.has("GL_EXT_timer_query")) { | 105 } else if (extensions.has("GL_EXT_timer_query")) { |
| 105 GR_GL_GET_PROC_SUFFIX(GetQueryObjecti64v, EXT); | 106 GR_GL_GET_PROC_SUFFIX(GetQueryObjecti64v, EXT); |
| 106 GR_GL_GET_PROC_SUFFIX(GetQueryObjectui64v, EXT); | 107 GR_GL_GET_PROC_SUFFIX(GetQueryObjectui64v, EXT); |
| 107 } | 108 } |
| 108 GR_GL_GET_PROC(GetQueryiv); | 109 GR_GL_GET_PROC(GetQueryiv); |
| 109 GR_GL_GET_PROC(GetProgramInfoLog); | 110 GR_GL_GET_PROC(GetProgramInfoLog); |
| 110 GR_GL_GET_PROC(GetProgramiv); | 111 GR_GL_GET_PROC(GetProgramiv); |
| 111 GR_GL_GET_PROC(GetShaderInfoLog); | 112 GR_GL_GET_PROC(GetShaderInfoLog); |
| 112 GR_GL_GET_PROC(GetShaderiv); | 113 GR_GL_GET_PROC(GetShaderiv); |
| 113 interface->fGetString = glGetString; | 114 functions->fGetString = glGetString; |
| 114 GR_GL_GET_PROC(GetStringi); | 115 GR_GL_GET_PROC(GetStringi); |
| 115 interface->fGetTexLevelParameteriv = glGetTexLevelParameteriv; | 116 functions->fGetTexLevelParameteriv = glGetTexLevelParameteriv; |
| 116 GR_GL_GET_PROC(GenQueries); | 117 GR_GL_GET_PROC(GenQueries); |
| 117 interface->fGenTextures = glGenTextures; | 118 functions->fGenTextures = glGenTextures; |
| 118 GR_GL_GET_PROC(GetUniformLocation); | 119 GR_GL_GET_PROC(GetUniformLocation); |
| 119 interface->fLineWidth = glLineWidth; | 120 functions->fLineWidth = glLineWidth; |
| 120 GR_GL_GET_PROC(LinkProgram); | 121 GR_GL_GET_PROC(LinkProgram); |
| 121 GR_GL_GET_PROC(MapBuffer); | 122 GR_GL_GET_PROC(MapBuffer); |
| 122 interface->fPixelStorei = glPixelStorei; | 123 functions->fPixelStorei = glPixelStorei; |
| 123 interface->fReadBuffer = glReadBuffer; | 124 functions->fReadBuffer = glReadBuffer; |
| 124 interface->fReadPixels = glReadPixels; | 125 functions->fReadPixels = glReadPixels; |
| 125 interface->fScissor = glScissor; | 126 functions->fScissor = glScissor; |
| 126 GR_GL_GET_PROC(ShaderSource); | 127 GR_GL_GET_PROC(ShaderSource); |
| 127 interface->fStencilFunc = glStencilFunc; | 128 functions->fStencilFunc = glStencilFunc; |
| 128 GR_GL_GET_PROC(StencilFuncSeparate); | 129 GR_GL_GET_PROC(StencilFuncSeparate); |
| 129 interface->fStencilMask = glStencilMask; | 130 functions->fStencilMask = glStencilMask; |
| 130 GR_GL_GET_PROC(StencilMaskSeparate); | 131 GR_GL_GET_PROC(StencilMaskSeparate); |
| 131 interface->fStencilOp = glStencilOp; | 132 functions->fStencilOp = glStencilOp; |
| 132 GR_GL_GET_PROC(StencilOpSeparate); | 133 GR_GL_GET_PROC(StencilOpSeparate); |
| 133 interface->fTexImage2D = glTexImage2D; | 134 functions->fTexImage2D = glTexImage2D; |
| 134 interface->fTexGenf = glTexGenf; | 135 functions->fTexGenf = glTexGenf; |
| 135 interface->fTexGenfv = glTexGenfv; | 136 functions->fTexGenfv = glTexGenfv; |
| 136 interface->fTexGeni = glTexGeni; | 137 functions->fTexGeni = glTexGeni; |
| 137 interface->fTexParameteri = glTexParameteri; | 138 functions->fTexParameteri = glTexParameteri; |
| 138 interface->fTexParameteriv = glTexParameteriv; | 139 functions->fTexParameteriv = glTexParameteriv; |
| 139 if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage"))
{ | 140 if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage"))
{ |
| 140 GR_GL_GET_PROC(TexStorage2D); | 141 GR_GL_GET_PROC(TexStorage2D); |
| 141 } else if (extensions.has("GL_EXT_texture_storage")) { | 142 } else if (extensions.has("GL_EXT_texture_storage")) { |
| 142 GR_GL_GET_PROC_SUFFIX(TexStorage2D, EXT); | 143 GR_GL_GET_PROC_SUFFIX(TexStorage2D, EXT); |
| 143 } | 144 } |
| 144 interface->fTexSubImage2D = glTexSubImage2D; | 145 functions->fTexSubImage2D = glTexSubImage2D; |
| 145 GR_GL_GET_PROC(Uniform1f); | 146 GR_GL_GET_PROC(Uniform1f); |
| 146 GR_GL_GET_PROC(Uniform1i); | 147 GR_GL_GET_PROC(Uniform1i); |
| 147 GR_GL_GET_PROC(Uniform1fv); | 148 GR_GL_GET_PROC(Uniform1fv); |
| 148 GR_GL_GET_PROC(Uniform1iv); | 149 GR_GL_GET_PROC(Uniform1iv); |
| 149 GR_GL_GET_PROC(Uniform2f); | 150 GR_GL_GET_PROC(Uniform2f); |
| 150 GR_GL_GET_PROC(Uniform2i); | 151 GR_GL_GET_PROC(Uniform2i); |
| 151 GR_GL_GET_PROC(Uniform2fv); | 152 GR_GL_GET_PROC(Uniform2fv); |
| 152 GR_GL_GET_PROC(Uniform2iv); | 153 GR_GL_GET_PROC(Uniform2iv); |
| 153 GR_GL_GET_PROC(Uniform3f); | 154 GR_GL_GET_PROC(Uniform3f); |
| 154 GR_GL_GET_PROC(Uniform3i); | 155 GR_GL_GET_PROC(Uniform3i); |
| 155 GR_GL_GET_PROC(Uniform3fv); | 156 GR_GL_GET_PROC(Uniform3fv); |
| 156 GR_GL_GET_PROC(Uniform3iv); | 157 GR_GL_GET_PROC(Uniform3iv); |
| 157 GR_GL_GET_PROC(Uniform4f); | 158 GR_GL_GET_PROC(Uniform4f); |
| 158 GR_GL_GET_PROC(Uniform4i); | 159 GR_GL_GET_PROC(Uniform4i); |
| 159 GR_GL_GET_PROC(Uniform4fv); | 160 GR_GL_GET_PROC(Uniform4fv); |
| 160 GR_GL_GET_PROC(Uniform4iv); | 161 GR_GL_GET_PROC(Uniform4iv); |
| 161 GR_GL_GET_PROC(UniformMatrix2fv); | 162 GR_GL_GET_PROC(UniformMatrix2fv); |
| 162 GR_GL_GET_PROC(UniformMatrix3fv); | 163 GR_GL_GET_PROC(UniformMatrix3fv); |
| 163 GR_GL_GET_PROC(UniformMatrix4fv); | 164 GR_GL_GET_PROC(UniformMatrix4fv); |
| 164 GR_GL_GET_PROC(UnmapBuffer); | 165 GR_GL_GET_PROC(UnmapBuffer); |
| 165 GR_GL_GET_PROC(UseProgram); | 166 GR_GL_GET_PROC(UseProgram); |
| 166 GR_GL_GET_PROC(VertexAttrib4fv); | 167 GR_GL_GET_PROC(VertexAttrib4fv); |
| 167 GR_GL_GET_PROC(VertexAttribPointer); | 168 GR_GL_GET_PROC(VertexAttribPointer); |
| 168 GR_GL_GET_PROC(VertexPointer); | 169 GR_GL_GET_PROC(VertexPointer); |
| 169 interface->fViewport = glViewport; | 170 functions->fViewport = glViewport; |
| 170 GR_GL_GET_PROC(BindFragDataLocationIndexed); | 171 GR_GL_GET_PROC(BindFragDataLocationIndexed); |
| 171 | 172 |
| 172 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_objec
t")) { | 173 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_objec
t")) { |
| 173 // no ARB suffix for GL_ARB_vertex_array_object | 174 // no ARB suffix for GL_ARB_vertex_array_object |
| 174 GR_GL_GET_PROC(BindVertexArray); | 175 GR_GL_GET_PROC(BindVertexArray); |
| 175 GR_GL_GET_PROC(GenVertexArrays); | 176 GR_GL_GET_PROC(GenVertexArrays); |
| 176 GR_GL_GET_PROC(DeleteVertexArrays); | 177 GR_GL_GET_PROC(DeleteVertexArrays); |
| 177 } | 178 } |
| 178 | 179 |
| 179 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since | 180 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 } | 276 } |
| 276 | 277 |
| 277 interface->fStandard = kGL_GrGLStandard; | 278 interface->fStandard = kGL_GrGLStandard; |
| 278 interface->fExtensions.swap(&extensions); | 279 interface->fExtensions.swap(&extensions); |
| 279 | 280 |
| 280 return interface; | 281 return interface; |
| 281 } else { | 282 } else { |
| 282 return NULL; | 283 return NULL; |
| 283 } | 284 } |
| 284 } | 285 } |
| OLD | NEW |