epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 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. |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 10 | #include "GrGLInterface.h" |
| 11 | |
| 12 | #include <GL/glx.h> |
| 13 | #include <GL/gl.h> |
| 14 | #include <GL/glext.h> |
| 15 | #include <GL/glu.h> |
| 16 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 17 | #define GR_GL_GET_PROC(F) defaultInterface->f ## F = (GrGL ## F ## Proc) \ |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 18 | glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 19 | #define GR_GL_GET_PROC_SUFFIX(F, S) defaultInterface->f ## F = (GrGL ## F ## Proc) \ |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 20 | glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F #S)); |
| 21 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 22 | void GrGLInitializeDefaultGLInterface() { |
| 23 | if (NULL != glXGetCurrentContext()) { |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 24 | int major, minor; |
| 25 | const char* versionString = (const char*) glGetString(GL_VERSION); |
| 26 | const char* extString = (const char*) glGetString(GL_EXTENSIONS); |
| 27 | gl_version_from_string(&major, &minor, versionString); |
| 28 | |
| 29 | if (major == 1 && minor < 5) { |
| 30 | // We must have array and element_array buffer objects. |
| 31 | return; |
| 32 | } |
| 33 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 34 | GrGLInterface* defaultInterface = new GrGLInterface(); |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 35 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 36 | defaultInterface->fNPOTRenderTargetSupport = kProbe_GrGLCapability; |
| 37 | defaultInterface->fMinRenderTargetHeight = kProbe_GrGLCapability; |
| 38 | defaultInterface->fMinRenderTargetWidth = kProbe_GrGLCapability; |
| 39 | |
| 40 | defaultInterface->fActiveTexture = glActiveTexture; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 41 | GR_GL_GET_PROC(AttachShader); |
| 42 | GR_GL_GET_PROC(BindAttribLocation); |
| 43 | GR_GL_GET_PROC(BindBuffer); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 44 | defaultInterface->fBindTexture = glBindTexture; |
| 45 | defaultInterface->fBlendColor = glBlendColor; |
| 46 | defaultInterface->fBlendFunc = glBlendFunc; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 47 | GR_GL_GET_PROC(BufferData); |
| 48 | GR_GL_GET_PROC(BufferSubData); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 49 | defaultInterface->fClear = glClear; |
| 50 | defaultInterface->fClearColor = glClearColor; |
| 51 | defaultInterface->fClearStencil = glClearStencil; |
| 52 | defaultInterface->fClientActiveTexture = glClientActiveTexture; |
| 53 | defaultInterface->fColorMask = glColorMask; |
| 54 | defaultInterface->fColorPointer = glColorPointer; |
| 55 | defaultInterface->fColor4ub = glColor4ub; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 56 | GR_GL_GET_PROC(CompileShader); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 57 | defaultInterface->fCompressedTexImage2D = glCompressedTexImage2D; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 58 | GR_GL_GET_PROC(CreateProgram); |
| 59 | GR_GL_GET_PROC(CreateShader); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 60 | defaultInterface->fCullFace = glCullFace; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 61 | GR_GL_GET_PROC(DeleteBuffers); |
| 62 | GR_GL_GET_PROC(DeleteProgram); |
| 63 | GR_GL_GET_PROC(DeleteShader); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 64 | defaultInterface->fDeleteTextures = glDeleteTextures; |
| 65 | defaultInterface->fDepthMask = glDepthMask; |
| 66 | defaultInterface->fDisable = glDisable; |
| 67 | defaultInterface->fDisableClientState = glDisableClientState; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 68 | GR_GL_GET_PROC(DisableVertexAttribArray); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 69 | defaultInterface->fDrawArrays = glDrawArrays; |
| 70 | defaultInterface->fDrawBuffer = glDrawBuffer; |
bsalomon@google.com | d32c5f5 | 2011-08-02 19:29:03 +0000 | [diff] [blame] | 71 | GR_GL_GET_PROC(DrawBuffers); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 72 | defaultInterface->fDrawElements = glDrawElements; |
| 73 | defaultInterface->fEnable = glEnable; |
| 74 | defaultInterface->fEnableClientState = glEnableClientState; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 75 | GR_GL_GET_PROC(EnableVertexAttribArray); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 76 | defaultInterface->fFrontFace = glFrontFace; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 77 | GR_GL_GET_PROC(GenBuffers); |
| 78 | GR_GL_GET_PROC(GetBufferParameteriv); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 79 | defaultInterface->fGetError = glGetError; |
| 80 | defaultInterface->fGetIntegerv = glGetIntegerv; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 81 | GR_GL_GET_PROC(GetProgramInfoLog); |
| 82 | GR_GL_GET_PROC(GetProgramiv); |
| 83 | GR_GL_GET_PROC(GetShaderInfoLog); |
| 84 | GR_GL_GET_PROC(GetShaderiv); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 85 | defaultInterface->fGetString = glGetString; |
| 86 | defaultInterface->fGetTexLevelParameteriv = glGetTexLevelParameteriv; |
| 87 | defaultInterface->fGenTextures = glGenTextures; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 88 | GR_GL_GET_PROC(GetUniformLocation); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 89 | defaultInterface->fLineWidth = glLineWidth; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 90 | GR_GL_GET_PROC(LinkProgram); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 91 | defaultInterface->fLoadMatrixf = glLoadMatrixf; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 92 | GR_GL_GET_PROC(MapBuffer); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 93 | defaultInterface->fMatrixMode = glMatrixMode; |
| 94 | defaultInterface->fPointSize = glPointSize; |
| 95 | defaultInterface->fPixelStorei = glPixelStorei; |
| 96 | defaultInterface->fReadBuffer = glReadBuffer; |
| 97 | defaultInterface->fReadPixels = glReadPixels; |
| 98 | defaultInterface->fScissor = glScissor; |
| 99 | defaultInterface->fShadeModel = glShadeModel; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 100 | GR_GL_GET_PROC(ShaderSource); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 101 | defaultInterface->fStencilFunc = glStencilFunc; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 102 | GR_GL_GET_PROC(StencilFuncSeparate); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 103 | defaultInterface->fStencilMask = glStencilMask; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 104 | GR_GL_GET_PROC(StencilMaskSeparate); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 105 | defaultInterface->fStencilOp = glStencilOp; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 106 | GR_GL_GET_PROC(StencilOpSeparate); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 107 | defaultInterface->fTexCoordPointer = glTexCoordPointer; |
| 108 | defaultInterface->fTexEnvi = glTexEnvi; |
| 109 | defaultInterface->fTexImage2D = glTexImage2D; |
| 110 | defaultInterface->fTexParameteri = glTexParameteri; |
| 111 | defaultInterface->fTexSubImage2D = glTexSubImage2D; |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 112 | GR_GL_GET_PROC(Uniform1f); |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 113 | GR_GL_GET_PROC(Uniform1i); |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 114 | GR_GL_GET_PROC(Uniform1fv); |
| 115 | GR_GL_GET_PROC(Uniform1iv); |
| 116 | GR_GL_GET_PROC(Uniform2f); |
| 117 | GR_GL_GET_PROC(Uniform2i); |
| 118 | GR_GL_GET_PROC(Uniform2fv); |
| 119 | GR_GL_GET_PROC(Uniform2iv); |
| 120 | GR_GL_GET_PROC(Uniform3f); |
| 121 | GR_GL_GET_PROC(Uniform3i); |
| 122 | GR_GL_GET_PROC(Uniform3fv); |
| 123 | GR_GL_GET_PROC(Uniform3iv); |
| 124 | GR_GL_GET_PROC(Uniform4f); |
| 125 | GR_GL_GET_PROC(Uniform4i); |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 126 | GR_GL_GET_PROC(Uniform4fv); |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 127 | GR_GL_GET_PROC(Uniform4iv); |
| 128 | GR_GL_GET_PROC(UniformMatrix2fv); |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 129 | GR_GL_GET_PROC(UniformMatrix3fv); |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 130 | GR_GL_GET_PROC(UniformMatrix4fv); |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 131 | GR_GL_GET_PROC(UnmapBuffer); |
| 132 | GR_GL_GET_PROC(UseProgram); |
| 133 | GR_GL_GET_PROC(VertexAttrib4fv); |
| 134 | GR_GL_GET_PROC(VertexAttribPointer); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 135 | defaultInterface->fVertexPointer = glVertexPointer; |
| 136 | defaultInterface->fViewport = glViewport; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 137 | GR_GL_GET_PROC(BindFragDataLocationIndexed); |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 138 | |
| 139 | // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since |
| 140 | // GL_ARB_framebuffer_object doesn't use ARB suffix.) |
senorblanco@chromium.org | 2dbd044 | 2011-05-04 15:29:04 +0000 | [diff] [blame] | 141 | if (major >= 3 || has_gl_extension_from_string( |
| 142 | "GL_ARB_framebuffer_object", extString)) { |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 143 | GR_GL_GET_PROC(GenFramebuffers); |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 144 | GR_GL_GET_PROC(GetFramebufferAttachmentParameteriv); |
| 145 | GR_GL_GET_PROC(GetRenderbufferParameteriv); |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 146 | GR_GL_GET_PROC(BindFramebuffer); |
| 147 | GR_GL_GET_PROC(FramebufferTexture2D); |
| 148 | GR_GL_GET_PROC(CheckFramebufferStatus); |
| 149 | GR_GL_GET_PROC(DeleteFramebuffers); |
| 150 | GR_GL_GET_PROC(RenderbufferStorage); |
| 151 | GR_GL_GET_PROC(GenRenderbuffers); |
| 152 | GR_GL_GET_PROC(DeleteRenderbuffers); |
| 153 | GR_GL_GET_PROC(FramebufferRenderbuffer); |
| 154 | GR_GL_GET_PROC(BindRenderbuffer); |
| 155 | GR_GL_GET_PROC(RenderbufferStorageMultisample); |
| 156 | GR_GL_GET_PROC(BlitFramebuffer); |
| 157 | } else if (has_gl_extension_from_string("GL_EXT_framebuffer_object", |
| 158 | extString)) { |
| 159 | GR_GL_GET_PROC_SUFFIX(GenFramebuffers, EXT); |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 160 | GR_GL_GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT); |
| 161 | GR_GL_GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT); |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 162 | GR_GL_GET_PROC_SUFFIX(BindFramebuffer, EXT); |
| 163 | GR_GL_GET_PROC_SUFFIX(FramebufferTexture2D, EXT); |
| 164 | GR_GL_GET_PROC_SUFFIX(CheckFramebufferStatus, EXT); |
| 165 | GR_GL_GET_PROC_SUFFIX(DeleteFramebuffers, EXT); |
| 166 | GR_GL_GET_PROC_SUFFIX(RenderbufferStorage, EXT); |
| 167 | GR_GL_GET_PROC_SUFFIX(GenRenderbuffers, EXT); |
| 168 | GR_GL_GET_PROC_SUFFIX(DeleteRenderbuffers, EXT); |
| 169 | GR_GL_GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT); |
| 170 | GR_GL_GET_PROC_SUFFIX(BindRenderbuffer, EXT); |
| 171 | if (has_gl_extension_from_string("GL_EXT_framebuffer_multisample", |
| 172 | extString)) { |
| 173 | GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT); |
| 174 | } |
| 175 | if (has_gl_extension_from_string("GL_EXT_framebuffer_blit", |
| 176 | extString)) { |
| 177 | GR_GL_GET_PROC_SUFFIX(BlitFramebuffer, EXT); |
| 178 | } |
| 179 | } else { |
| 180 | // we must have FBOs |
| 181 | return; |
| 182 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 183 | defaultInterface->fBindingsExported = kDesktop_GrGLBinding; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 184 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame^] | 185 | GrGLSetDefaultGLInterface(defaultInterface)->unref(); |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 186 | } |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 187 | } |