1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
21 #include "kwinglutils.h"
26 // Resolves given function, using getProcAddress
27 #define GL_RESOLVE( function ) function = (function ## _func)getProcAddress( #function );
28 // Same as above but tries to use function "backup" if "function" doesn't exist
29 // Useful when same functionality is also defined in an extension
30 #define GL_RESOLVE_WITH_EXT( function, backup ) \
31 function = (function ## _func)getProcAddress( #function ); \
33 function = (function ## _func)getProcAddress( #backup );
35 #ifdef KWIN_HAVE_OPENGL
41 glXGetProcAddress_func glXGetProcAddress
;
43 glXQueryDrawable_func glXQueryDrawable
;
44 // texture_from_pixmap extension functions
45 glXReleaseTexImageEXT_func glXReleaseTexImageEXT
;
46 glXBindTexImageEXT_func glXBindTexImageEXT
;
47 // glXCopySubBufferMESA
48 glXCopySubBuffer_func glXCopySubBuffer
;
49 // video_sync extension functions
50 glXGetVideoSync_func glXGetVideoSync
;
51 glXWaitVideoSync_func glXWaitVideoSync
;
53 glXGetFBConfigAttrib_func glXGetFBConfigAttrib
;
54 glXGetVisualFromFBConfig_func glXGetVisualFromFBConfig
;
55 glXCreateWindow_func glXCreateWindow
;
56 glXDestroyWindow_func glXDestroyWindow
;
57 glXCreatePixmap_func glXCreatePixmap
;
58 glXDestroyPixmap_func glXDestroyPixmap
;
59 glXGetFBConfigs_func glXGetFBConfigs
;
62 glActiveTexture_func glActiveTexture
;
63 // framebuffer_object extension functions
64 glIsRenderbuffer_func glIsRenderbuffer
;
65 glBindRenderbuffer_func glBindRenderbuffer
;
66 glDeleteRenderbuffers_func glDeleteRenderbuffers
;
67 glGenRenderbuffers_func glGenRenderbuffers
;
68 glRenderbufferStorage_func glRenderbufferStorage
;
69 glGetRenderbufferParameteriv_func glGetRenderbufferParameteriv
;
70 glIsFramebuffer_func glIsFramebuffer
;
71 glBindFramebuffer_func glBindFramebuffer
;
72 glDeleteFramebuffers_func glDeleteFramebuffers
;
73 glGenFramebuffers_func glGenFramebuffers
;
74 glCheckFramebufferStatus_func glCheckFramebufferStatus
;
75 glFramebufferTexture1D_func glFramebufferTexture1D
;
76 glFramebufferTexture2D_func glFramebufferTexture2D
;
77 glFramebufferTexture3D_func glFramebufferTexture3D
;
78 glFramebufferRenderbuffer_func glFramebufferRenderbuffer
;
79 glGetFramebufferAttachmentParameteriv_func glGetFramebufferAttachmentParameteriv
;
80 glGenerateMipmap_func glGenerateMipmap
;
82 glCreateShader_func glCreateShader
;
83 glShaderSource_func glShaderSource
;
84 glCompileShader_func glCompileShader
;
85 glDeleteShader_func glDeleteShader
;
86 glCreateProgram_func glCreateProgram
;
87 glAttachShader_func glAttachShader
;
88 glLinkProgram_func glLinkProgram
;
89 glUseProgram_func glUseProgram
;
90 glDeleteProgram_func glDeleteProgram
;
91 glGetShaderInfoLog_func glGetShaderInfoLog
;
92 glGetProgramInfoLog_func glGetProgramInfoLog
;
93 glGetProgramiv_func glGetProgramiv
;
94 glGetShaderiv_func glGetShaderiv
;
95 glUniform1f_func glUniform1f
;
96 glUniform1i_func glUniform1i
;
97 glUniform1fv_func glUniform1fv
;
98 glUniform2fv_func glUniform2fv
;
99 glValidateProgram_func glValidateProgram
;
100 glGetUniformLocation_func glGetUniformLocation
;
101 glVertexAttrib1f_func glVertexAttrib1f
;
102 glGetAttribLocation_func glGetAttribLocation
;
105 static glXFuncPtr
getProcAddress( const char* name
)
107 glXFuncPtr ret
= NULL
;
108 if( glXGetProcAddress
!= NULL
)
109 ret
= glXGetProcAddress( ( const GLubyte
* ) name
);
111 ret
= ( glXFuncPtr
) dlsym( RTLD_DEFAULT
, name
);
115 void glxResolveFunctions()
117 // handle OpenGL extensions functions
118 glXGetProcAddress
= (glXGetProcAddress_func
) getProcAddress( "glXGetProcAddress" );
119 if( glXGetProcAddress
== NULL
)
120 glXGetProcAddress
= (glXGetProcAddress_func
) getProcAddress( "glXGetProcAddressARB" );
121 glXQueryDrawable
= (glXQueryDrawable_func
) getProcAddress( "glXQueryDrawable" );
122 if( hasGLExtension( "GLX_EXT_texture_from_pixmap" ))
124 glXBindTexImageEXT
= (glXBindTexImageEXT_func
) getProcAddress( "glXBindTexImageEXT" );
125 glXReleaseTexImageEXT
= (glXReleaseTexImageEXT_func
) getProcAddress( "glXReleaseTexImageEXT" );
129 glXBindTexImageEXT
= NULL
;
130 glXReleaseTexImageEXT
= NULL
;
132 if( hasGLExtension( "GLX_MESA_copy_sub_buffer" ))
133 glXCopySubBuffer
= (glXCopySubBuffer_func
) getProcAddress( "glXCopySubBufferMESA" );
135 glXCopySubBuffer
= NULL
;
136 if( hasGLExtension( "GLX_SGI_video_sync" ))
138 glXGetVideoSync
= (glXGetVideoSync_func
) getProcAddress( "glXGetVideoSyncSGI" );
139 glXWaitVideoSync
= (glXWaitVideoSync_func
) getProcAddress( "glXWaitVideoSyncSGI" );
143 glXGetVideoSync
= NULL
;
144 glXWaitVideoSync
= NULL
;
147 GL_RESOLVE_WITH_EXT( glXGetFBConfigAttrib
, glXGetFBConfigAttribSGIX
);
148 GL_RESOLVE_WITH_EXT( glXGetVisualFromFBConfig
, glXGetVisualFromFBConfigSGIX
);
149 GL_RESOLVE( glXGetFBConfigs
);
150 GL_RESOLVE( glXCreateWindow
);
151 GL_RESOLVE( glXDestroyWindow
);
152 GL_RESOLVE( glXCreatePixmap
);
153 GL_RESOLVE( glXDestroyPixmap
);
156 void glResolveFunctions()
158 if( hasGLExtension( "GL_ARB_multitexture" ))
160 GL_RESOLVE_WITH_EXT( glActiveTexture
, glActiveTextureARB
);
161 // Get number of texture units
162 glGetIntegerv(GL_MAX_TEXTURE_UNITS
, &glTextureUnitsCount
);
166 glActiveTexture
= NULL
;
167 glTextureUnitsCount
= 0;
169 if( hasGLExtension( "GL_EXT_framebuffer_object" ))
171 glIsRenderbuffer
= (glIsRenderbuffer_func
) getProcAddress( "glIsRenderbufferEXT" );
172 glBindRenderbuffer
= (glBindRenderbuffer_func
) getProcAddress( "glBindRenderbufferEXT" );
173 glDeleteRenderbuffers
= (glDeleteRenderbuffers_func
) getProcAddress( "glDeleteRenderbuffersEXT" );
174 glGenRenderbuffers
= (glGenRenderbuffers_func
) getProcAddress( "glGenRenderbuffersEXT" );
176 glRenderbufferStorage
= (glRenderbufferStorage_func
) getProcAddress( "glRenderbufferStorageEXT" );
178 glGetRenderbufferParameteriv
= (glGetRenderbufferParameteriv_func
) getProcAddress( "glGetRenderbufferParameterivEXT" );
180 glIsFramebuffer
= (glIsFramebuffer_func
) getProcAddress( "glIsFramebufferEXT" );
181 glBindFramebuffer
= (glBindFramebuffer_func
) getProcAddress( "glBindFramebufferEXT" );
182 glDeleteFramebuffers
= (glDeleteFramebuffers_func
) getProcAddress( "glDeleteFramebuffersEXT" );
183 glGenFramebuffers
= (glGenFramebuffers_func
) getProcAddress( "glGenFramebuffersEXT" );
185 glCheckFramebufferStatus
= (glCheckFramebufferStatus_func
) getProcAddress( "glCheckFramebufferStatusEXT" );
187 glFramebufferTexture1D
= (glFramebufferTexture1D_func
) getProcAddress( "glFramebufferTexture1DEXT" );
188 glFramebufferTexture2D
= (glFramebufferTexture2D_func
) getProcAddress( "glFramebufferTexture2DEXT" );
189 glFramebufferTexture3D
= (glFramebufferTexture3D_func
) getProcAddress( "glFramebufferTexture3DEXT" );
191 glFramebufferRenderbuffer
= (glFramebufferRenderbuffer_func
) getProcAddress( "glFramebufferRenderbufferEXT" );
193 glGetFramebufferAttachmentParameteriv
= (glGetFramebufferAttachmentParameteriv_func
) getProcAddress( "glGetFramebufferAttachmentParameterivEXT" );
195 glGenerateMipmap
= (glGenerateMipmap_func
) getProcAddress( "glGenerateMipmapEXT" );
199 glIsRenderbuffer
= NULL
;
200 glBindRenderbuffer
= NULL
;
201 glDeleteRenderbuffers
= NULL
;
202 glGenRenderbuffers
= NULL
;
203 glRenderbufferStorage
= NULL
;
204 glGetRenderbufferParameteriv
= NULL
;
205 glIsFramebuffer
= NULL
;
206 glBindFramebuffer
= NULL
;
207 glDeleteFramebuffers
= NULL
;
208 glGenFramebuffers
= NULL
;
209 glCheckFramebufferStatus
= NULL
;
210 glFramebufferTexture1D
= NULL
;
211 glFramebufferTexture2D
= NULL
;
212 glFramebufferTexture3D
= NULL
;
213 glFramebufferRenderbuffer
= NULL
;
214 glGetFramebufferAttachmentParameteriv
= NULL
;
215 glGenerateMipmap
= NULL
;
217 if( hasGLExtension( "GL_ARB_shading_language_100" ) && hasGLExtension( "GL_ARB_fragment_shader" ))
219 GL_RESOLVE_WITH_EXT( glCreateShader
, glCreateShaderObjectARB
);
220 GL_RESOLVE_WITH_EXT( glShaderSource
, glShaderSourceARB
);
221 GL_RESOLVE_WITH_EXT( glCompileShader
, glCompileShaderARB
);
222 GL_RESOLVE_WITH_EXT( glDeleteShader
, glDeleteObjectARB
);
223 GL_RESOLVE_WITH_EXT( glCreateProgram
, glCreateProgramObjectARB
);
224 GL_RESOLVE_WITH_EXT( glAttachShader
, glAttachObjectARB
);
225 GL_RESOLVE_WITH_EXT( glLinkProgram
, glLinkProgramARB
);
226 GL_RESOLVE_WITH_EXT( glUseProgram
, glUseProgramObjectARB
);
227 GL_RESOLVE_WITH_EXT( glDeleteProgram
, glDeleteObjectARB
);
228 GL_RESOLVE_WITH_EXT( glGetShaderInfoLog
, glGetInfoLogARB
);
229 GL_RESOLVE_WITH_EXT( glGetProgramInfoLog
, glGetInfoLogARB
);
230 GL_RESOLVE_WITH_EXT( glGetProgramiv
, glGetObjectParameterivARB
);
231 GL_RESOLVE_WITH_EXT( glGetShaderiv
, glGetObjectParameterivARB
);
232 GL_RESOLVE_WITH_EXT( glUniform1f
, glUniform1fARB
);
233 GL_RESOLVE_WITH_EXT( glUniform1i
, glUniform1iARB
);
234 GL_RESOLVE_WITH_EXT( glUniform1fv
, glUniform1fvARB
);
235 GL_RESOLVE_WITH_EXT( glUniform2fv
, glUniform2fvARB
);
236 GL_RESOLVE_WITH_EXT( glValidateProgram
, glValidateProgramARB
);
237 GL_RESOLVE_WITH_EXT( glGetUniformLocation
, glGetUniformLocationARB
);
238 GL_RESOLVE_WITH_EXT( glVertexAttrib1f
, glVertexAttrib1fARB
);
239 GL_RESOLVE_WITH_EXT( glGetAttribLocation
, glGetAttribLocationARB
);