Move OpenGL defines, function prototypes and function resolving to a separate file.

Update copyright years.

svn path=/branches/work/kwin_composite/; revision=630583
This commit is contained in:
Rivo Laks 2007-02-05 19:57:05 +00:00
parent 66d8c5030b
commit 1cdcd8956f
5 changed files with 390 additions and 335 deletions

View file

@ -50,6 +50,7 @@ set(kwin_KDEINIT_SRCS
scene_xrender.cpp
scene_opengl.cpp
glutils.cpp
glutils_funcs.cpp
deleted.cpp
effects.cpp
effects/fadein.cpp

View file

@ -2,7 +2,7 @@
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006 Rivo Laks <rivolaks@hot.ee>
Copyright (C) 2006-2007 Rivo Laks <rivolaks@hot.ee>
You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
@ -13,20 +13,9 @@ License. See the file "COPYING" for the exact licensing terms.
#include <QHash>
#include <QFile>
#include <dlfcn.h>
#define MAKE_GL_VERSION(major, minor, release) ( ((major) << 16) | ((minor) << 8) | (release) )
// Resolves given function, using getProcAddress
#define GL_RESOLVE( function ) function = (function ## _func)getProcAddress( #function );
// Same as above but tries to use function "backup" if "function" doesn't exist
// Useful when same functionality is also defined in an extension
#define GL_RESOLVE_WITH_EXT( function, backup ) \
function = (function ## _func)getProcAddress( #function ); \
if( !function ) \
function = (function ## _func)getProcAddress( #backup );
namespace KWinInternal
{
@ -37,75 +26,11 @@ static int glVersion;
static int glXVersion;
// List of all supported GL and GLX extensions
static QStringList glExtensions;
int glTextureUnitsCount;
// Function pointers
glXGetProcAddress_func glXGetProcAddress;
// GLX 1.3
glXQueryDrawable_func glXQueryDrawable;
// texture_from_pixmap extension functions
glXReleaseTexImageEXT_func glXReleaseTexImageEXT;
glXBindTexImageEXT_func glXBindTexImageEXT;
// glXCopySubBufferMESA
glXCopySubBuffer_func glXCopySubBuffer;
// video_sync extension functions
glXGetVideoSync_func glXGetVideoSync;
glXWaitVideoSync_func glXWaitVideoSync;
// glActiveTexture
glActiveTexture_func glActiveTexture;
// framebuffer_object extension functions
glIsRenderbuffer_func glIsRenderbuffer;
glBindRenderbuffer_func glBindRenderbuffer;
glDeleteRenderbuffers_func glDeleteRenderbuffers;
glGenRenderbuffers_func glGenRenderbuffers;
glRenderbufferStorage_func glRenderbufferStorage;
glGetRenderbufferParameteriv_func glGetRenderbufferParameteriv;
glIsFramebuffer_func glIsFramebuffer;
glBindFramebuffer_func glBindFramebuffer;
glDeleteFramebuffers_func glDeleteFramebuffers;
glGenFramebuffers_func glGenFramebuffers;
glCheckFramebufferStatus_func glCheckFramebufferStatus;
glFramebufferTexture1D_func glFramebufferTexture1D;
glFramebufferTexture2D_func glFramebufferTexture2D;
glFramebufferTexture3D_func glFramebufferTexture3D;
glFramebufferRenderbuffer_func glFramebufferRenderbuffer;
glGetFramebufferAttachmentParameteriv_func glGetFramebufferAttachmentParameteriv;
glGenerateMipmap_func glGenerateMipmap;
// Shader functions
glCreateShader_func glCreateShader;
glShaderSource_func glShaderSource;
glCompileShader_func glCompileShader;
glDeleteShader_func glDeleteShader;
glCreateProgram_func glCreateProgram;
glAttachShader_func glAttachShader;
glLinkProgram_func glLinkProgram;
glUseProgram_func glUseProgram;
glDeleteProgram_func glDeleteProgram;
glGetShaderInfoLog_func glGetShaderInfoLog;
glGetProgramInfoLog_func glGetProgramInfoLog;
glGetProgramiv_func glGetProgramiv;
glGetShaderiv_func glGetShaderiv;
glUniform1f_func glUniform1f;
glUniform1i_func glUniform1i;
glUniform1fv_func glUniform1fv;
glUniform2fv_func glUniform2fv;
glValidateProgram_func glValidateProgram;
glGetUniformLocation_func glGetUniformLocation;
glVertexAttrib1f_func glVertexAttrib1f;
glGetAttribLocation_func glGetAttribLocation;
int glTextureUnitsCount;
// Functions
static glXFuncPtr getProcAddress( const char* name )
{
glXFuncPtr ret = NULL;
if( glXGetProcAddress != NULL )
ret = glXGetProcAddress( ( const GLubyte* ) name );
if( ret == NULL )
ret = ( glXFuncPtr ) dlsym( RTLD_DEFAULT, name );
return ret;
}
void initGLX()
{
// Get GLX version
@ -116,35 +41,7 @@ void initGLX()
glExtensions += QString((const char*)glXQueryExtensionsString(
display(), DefaultScreen( display()))).split(" ");
// handle OpenGL extensions functions
glXGetProcAddress = (glXGetProcAddress_func) getProcAddress( "glXGetProcAddress" );
if( glXGetProcAddress == NULL )
glXGetProcAddress = (glXGetProcAddress_func) getProcAddress( "glXGetProcAddressARB" );
glXQueryDrawable = (glXQueryDrawable_func) getProcAddress( "glXQueryDrawable" );
if( hasGLExtension( "GLX_EXT_texture_from_pixmap" ))
{
glXBindTexImageEXT = (glXBindTexImageEXT_func) getProcAddress( "glXBindTexImageEXT" );
glXReleaseTexImageEXT = (glXReleaseTexImageEXT_func) getProcAddress( "glXReleaseTexImageEXT" );
}
else
{
glXBindTexImageEXT = NULL;
glXReleaseTexImageEXT = NULL;
}
if( hasGLExtension( "GLX_MESA_copy_sub_buffer" ))
glXCopySubBuffer = (glXCopySubBuffer_func) getProcAddress( "glXCopySubBufferMESA" );
else
glXCopySubBuffer = NULL;
if( hasGLExtension( "GLX_SGI_video_sync" ))
{
glXGetVideoSync = (glXGetVideoSync_func) getProcAddress( "glXGetVideoSyncSGI" );
glXWaitVideoSync = (glXWaitVideoSync_func) getProcAddress( "glXWaitVideoSyncSGI" );
}
else
{
glXGetVideoSync = NULL;
glXWaitVideoSync = NULL;
}
glxResolveFunctions();
}
void initGL()
@ -158,89 +55,7 @@ void initGL()
glExtensions = QString((const char*)glGetString(GL_EXTENSIONS)).split(" ");
// handle OpenGL extensions functions
if( hasGLExtension( "GL_ARB_multitexture" ))
{
GL_RESOLVE_WITH_EXT( glActiveTexture, glActiveTextureARB );
// Get number of texture units
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &glTextureUnitsCount);
}
else
{
glActiveTexture = NULL;
glTextureUnitsCount = 0;
}
if( hasGLExtension( "GL_EXT_framebuffer_object" ))
{
glIsRenderbuffer = (glIsRenderbuffer_func) getProcAddress( "glIsRenderbufferEXT" );
glBindRenderbuffer = (glBindRenderbuffer_func) getProcAddress( "glBindRenderbufferEXT" );
glDeleteRenderbuffers = (glDeleteRenderbuffers_func) getProcAddress( "glDeleteRenderbuffersEXT" );
glGenRenderbuffers = (glGenRenderbuffers_func) getProcAddress( "glGenRenderbuffersEXT" );
glRenderbufferStorage = (glRenderbufferStorage_func) getProcAddress( "glRenderbufferStorageEXT" );
glGetRenderbufferParameteriv = (glGetRenderbufferParameteriv_func) getProcAddress( "glGetRenderbufferParameterivEXT" );
glIsFramebuffer = (glIsFramebuffer_func) getProcAddress( "glIsFramebufferEXT" );
glBindFramebuffer = (glBindFramebuffer_func) getProcAddress( "glBindFramebufferEXT" );
glDeleteFramebuffers = (glDeleteFramebuffers_func) getProcAddress( "glDeleteFramebuffersEXT" );
glGenFramebuffers = (glGenFramebuffers_func) getProcAddress( "glGenFramebuffersEXT" );
glCheckFramebufferStatus = (glCheckFramebufferStatus_func) getProcAddress( "glCheckFramebufferStatusEXT" );
glFramebufferTexture1D = (glFramebufferTexture1D_func) getProcAddress( "glFramebufferTexture1DEXT" );
glFramebufferTexture2D = (glFramebufferTexture2D_func) getProcAddress( "glFramebufferTexture2DEXT" );
glFramebufferTexture3D = (glFramebufferTexture3D_func) getProcAddress( "glFramebufferTexture3DEXT" );
glFramebufferRenderbuffer = (glFramebufferRenderbuffer_func) getProcAddress( "glFramebufferRenderbufferEXT" );
glGetFramebufferAttachmentParameteriv = (glGetFramebufferAttachmentParameteriv_func) getProcAddress( "glGetFramebufferAttachmentParameterivEXT" );
glGenerateMipmap = (glGenerateMipmap_func) getProcAddress( "glGenerateMipmapEXT" );
}
else
{
glIsRenderbuffer = NULL;
glBindRenderbuffer = NULL;
glDeleteRenderbuffers = NULL;
glGenRenderbuffers = NULL;
glRenderbufferStorage = NULL;
glGetRenderbufferParameteriv = NULL;
glIsFramebuffer = NULL;
glBindFramebuffer = NULL;
glDeleteFramebuffers = NULL;
glGenFramebuffers = NULL;
glCheckFramebufferStatus = NULL;
glFramebufferTexture1D = NULL;
glFramebufferTexture2D = NULL;
glFramebufferTexture3D = NULL;
glFramebufferRenderbuffer = NULL;
glGetFramebufferAttachmentParameteriv = NULL;
glGenerateMipmap = NULL;
}
if( hasGLExtension( "GL_ARB_shading_language_100" ) && hasGLExtension( "GL_ARB_fragment_shader" ))
{
GL_RESOLVE_WITH_EXT( glCreateShader, glCreateShaderObjectARB );
GL_RESOLVE_WITH_EXT( glShaderSource, glShaderSourceARB );
GL_RESOLVE_WITH_EXT( glCompileShader, glCompileShaderARB );
GL_RESOLVE_WITH_EXT( glDeleteShader, glDeleteObjectARB );
GL_RESOLVE_WITH_EXT( glCreateProgram, glCreateProgramObjectARB );
GL_RESOLVE_WITH_EXT( glAttachShader, glAttachObjectARB );
GL_RESOLVE_WITH_EXT( glLinkProgram, glLinkProgramARB );
GL_RESOLVE_WITH_EXT( glUseProgram, glUseProgramObjectARB );
GL_RESOLVE_WITH_EXT( glDeleteProgram, glDeleteObjectARB );
GL_RESOLVE_WITH_EXT( glGetShaderInfoLog, glGetInfoLogARB );
GL_RESOLVE_WITH_EXT( glGetProgramInfoLog, glGetInfoLogARB );
GL_RESOLVE_WITH_EXT( glGetProgramiv, glGetObjectParameterivARB );
GL_RESOLVE_WITH_EXT( glGetShaderiv, glGetObjectParameterivARB );
GL_RESOLVE_WITH_EXT( glUniform1f, glUniform1fARB );
GL_RESOLVE_WITH_EXT( glUniform1i, glUniform1iARB );
GL_RESOLVE_WITH_EXT( glUniform1fv, glUniform1fvARB );
GL_RESOLVE_WITH_EXT( glUniform2fv, glUniform2fvARB );
GL_RESOLVE_WITH_EXT( glValidateProgram, glValidateProgramARB );
GL_RESOLVE_WITH_EXT( glGetUniformLocation, glGetUniformLocationARB );
GL_RESOLVE_WITH_EXT( glVertexAttrib1f, glVertexAttrib1fARB );
GL_RESOLVE_WITH_EXT( glGetAttribLocation, glGetAttribLocationARB );
}
glResolveFunctions();
}
bool hasGLVersion(int major, int minor, int release)

150
glutils.h
View file

@ -2,7 +2,7 @@
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006 Rivo Laks <rivolaks@hot.ee>
Copyright (C) 2006-2007 Rivo Laks <rivolaks@hot.ee>
You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
@ -18,8 +18,9 @@ License. See the file "COPYING" for the exact licensing terms.
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glext.h>
#include <GL/glxext.h>
#include "glutils_funcs.h"
template< class K, class V > class QHash;
@ -75,149 +76,6 @@ class GLShader
QHash< QString, int >* mVariableLocations;
};
// Defines
/*
** GLX_EXT_texture_from_pixmap
*/
#define GLX_BIND_TO_TEXTURE_RGB_EXT 0x20D0
#define GLX_BIND_TO_TEXTURE_RGBA_EXT 0x20D1
#define GLX_BIND_TO_MIPMAP_TEXTURE_EXT 0x20D2
#define GLX_BIND_TO_TEXTURE_TARGETS_EXT 0x20D3
#define GLX_Y_INVERTED_EXT 0x20D4
#define GLX_TEXTURE_FORMAT_EXT 0x20D5
#define GLX_TEXTURE_TARGET_EXT 0x20D6
#define GLX_MIPMAP_TEXTURE_EXT 0x20D7
#define GLX_TEXTURE_FORMAT_NONE_EXT 0x20D8
#define GLX_TEXTURE_FORMAT_RGB_EXT 0x20D9
#define GLX_TEXTURE_FORMAT_RGBA_EXT 0x20DA
#define GLX_TEXTURE_1D_BIT_EXT 0x00000001
#define GLX_TEXTURE_2D_BIT_EXT 0x00000002
#define GLX_TEXTURE_RECTANGLE_BIT_EXT 0x00000004
#define GLX_TEXTURE_1D_EXT 0x20DB
#define GLX_TEXTURE_2D_EXT 0x20DC
#define GLX_TEXTURE_RECTANGLE_EXT 0x20DD
#define GLX_FRONT_LEFT_EXT 0x20DE
// Shader stuff
#define GL_COMPILE_STATUS 0x8B81
#define GL_LINK_STATUS 0x8B82
#define GL_INFO_LOG_LENGTH 0x8B84
#define GL_FRAGMENT_SHADER 0x8B30
#define GL_VERTEX_SHADER 0x8B31
// Function pointers
// finding of OpenGL extensions functions
typedef void (*glXFuncPtr)();
typedef glXFuncPtr (*glXGetProcAddress_func)( const GLubyte* );
extern glXGetProcAddress_func glXGetProcAddress;
// glXQueryDrawable (added in GLX 1.3)
typedef void (*glXQueryDrawable_func)( Display* dpy, GLXDrawable drawable,
int attribute, unsigned int *value );
extern glXQueryDrawable_func glXQueryDrawable;
// texture_from_pixmap extension functions
typedef void (*glXBindTexImageEXT_func)( Display* dpy, GLXDrawable drawable,
int buffer, const int* attrib_list );
typedef void (*glXReleaseTexImageEXT_func)( Display* dpy, GLXDrawable drawable, int buffer );
extern glXReleaseTexImageEXT_func glXReleaseTexImageEXT;
extern glXBindTexImageEXT_func glXBindTexImageEXT;
// glXCopySubBufferMESA
typedef void (*glXCopySubBuffer_func) ( Display* , GLXDrawable, int, int, int, int );
extern glXCopySubBuffer_func glXCopySubBuffer;
// video_sync extension functions
typedef void (*glXGetVideoSync_func)( unsigned int *count );
typedef void (*glXWaitVideoSync_func)( int divisor, int remainder, unsigned int *count );
extern glXGetVideoSync_func glXGetVideoSync;
extern glXWaitVideoSync_func glXWaitVideoSync;
// glActiveTexture
typedef void (*glActiveTexture_func)(GLenum);
extern glActiveTexture_func glActiveTexture;
// framebuffer_object extension functions
typedef bool (*glIsRenderbuffer_func)( GLuint renderbuffer );
typedef void (*glBindRenderbuffer_func)( GLenum target, GLuint renderbuffer );
typedef void (*glDeleteRenderbuffers_func)( GLsizei n, const GLuint *renderbuffers );
typedef void (*glGenRenderbuffers_func)( GLsizei n, GLuint *renderbuffers );
typedef void (*glRenderbufferStorage_func)( GLenum target, GLenum internalformat, GLsizei width, GLsizei height );
typedef void (*glGetRenderbufferParameteriv_func)( GLenum target, GLenum pname, GLint *params );
typedef bool (*glIsFramebuffer_func)( GLuint framebuffer );
typedef void (*glBindFramebuffer_func)( GLenum target, GLuint framebuffer );
typedef void (*glDeleteFramebuffers_func)( GLsizei n, const GLuint *framebuffers );
typedef void (*glGenFramebuffers_func)( GLsizei n, GLuint *framebuffers );
typedef void (*glCheckFramebufferStatus_func)( GLenum target );
typedef void (*glFramebufferTexture1D_func)( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level );
typedef void (*glFramebufferTexture2D_func)( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level );
typedef void (*glFramebufferTexture3D_func)( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset );
typedef void (*glFramebufferRenderbuffer_func)( GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer );
typedef void (*glGetFramebufferAttachmentParameteriv_func)( GLenum target, GLenum attachment, GLenum pname, GLint *params );
typedef void (*glGenerateMipmap_func)( GLenum target );
extern glIsRenderbuffer_func glIsRenderbuffer;
extern glBindRenderbuffer_func glBindRenderbuffer;
extern glDeleteRenderbuffers_func glDeleteRenderbuffers;
extern glGenRenderbuffers_func glGenRenderbuffers;
extern glRenderbufferStorage_func glRenderbufferStorage;
extern glGetRenderbufferParameteriv_func glGetRenderbufferParameteriv;
extern glIsFramebuffer_func glIsFramebuffer;
extern glBindFramebuffer_func glBindFramebuffer;
extern glDeleteFramebuffers_func glDeleteFramebuffers;
extern glGenFramebuffers_func glGenFramebuffers;
extern glCheckFramebufferStatus_func glCheckFramebufferStatus;
extern glFramebufferTexture1D_func glFramebufferTexture1D;
extern glFramebufferTexture2D_func glFramebufferTexture2D;
extern glFramebufferTexture3D_func glFramebufferTexture3D;
extern glFramebufferRenderbuffer_func glFramebufferRenderbuffer;
extern glGetFramebufferAttachmentParameteriv_func glGetFramebufferAttachmentParameteriv;
extern glGenerateMipmap_func glGenerateMipmap;
// Shader stuff
typedef GLuint (*glCreateShader_func)(GLenum);
typedef GLvoid (*glShaderSource_func)(GLuint, GLsizei, const GLchar**, const GLint*);
typedef GLvoid (*glCompileShader_func)(GLuint);
typedef GLvoid (*glDeleteShader_func)(GLuint);
typedef GLuint (*glCreateProgram_func)();
typedef GLvoid (*glAttachShader_func)(GLuint, GLuint);
typedef GLvoid (*glLinkProgram_func)(GLuint);
typedef GLvoid (*glUseProgram_func)(GLuint);
typedef GLvoid (*glDeleteProgram_func)(GLuint);
typedef GLvoid (*glGetShaderInfoLog_func)(GLuint, GLsizei, GLsizei*, GLchar*);
typedef GLvoid (*glGetProgramInfoLog_func)(GLuint, GLsizei, GLsizei*, GLchar*);
typedef GLvoid (*glGetProgramiv_func)(GLuint, GLenum, GLint*);
typedef GLvoid (*glGetShaderiv_func)(GLuint, GLenum, GLint*);
typedef GLvoid (*glUniform1f_func)(GLint, GLfloat);
typedef GLvoid (*glUniform1i_func)(GLint, GLint);
typedef GLvoid (*glUniform1fv_func)(GLint, GLsizei, const GLfloat*);
typedef GLvoid (*glUniform2fv_func)(GLint, GLsizei, const GLfloat*);
typedef GLvoid (*glUniform3fv_func)(GLint, GLsizei, const GLfloat*);
typedef GLvoid (*glValidateProgram_func)(GLuint);
typedef GLint (*glGetUniformLocation_func)(GLuint, const GLchar*);
typedef GLvoid (*glVertexAttrib1f_func)(GLuint, GLfloat);
typedef GLint (*glGetAttribLocation_func)(GLuint, const GLchar*);
extern glCreateShader_func glCreateShader;
extern glShaderSource_func glShaderSource;
extern glCompileShader_func glCompileShader;
extern glDeleteShader_func glDeleteShader;
extern glCreateProgram_func glCreateProgram;
extern glAttachShader_func glAttachShader;
extern glLinkProgram_func glLinkProgram;
extern glUseProgram_func glUseProgram;
extern glDeleteProgram_func glDeleteProgram;
extern glGetShaderInfoLog_func glGetShaderInfoLog;
extern glGetProgramInfoLog_func glGetProgramInfoLog;
extern glGetProgramiv_func glGetProgramiv;
extern glGetShaderiv_func glGetShaderiv;
extern glUniform1f_func glUniform1f;
extern glUniform1i_func glUniform1i;
extern glUniform1fv_func glUniform1fv;
extern glUniform2fv_func glUniform2fv;
extern glValidateProgram_func glValidateProgram;
extern glGetUniformLocation_func glGetUniformLocation;
extern glVertexAttrib1f_func glVertexAttrib1f;
extern glGetAttribLocation_func glGetAttribLocation;
} // namespace
#endif

215
glutils_funcs.cpp Normal file
View file

@ -0,0 +1,215 @@
/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
******************************************************************/
#include "glutils.h"
#include <dlfcn.h>
// Resolves given function, using getProcAddress
#define GL_RESOLVE( function ) function = (function ## _func)getProcAddress( #function );
// Same as above but tries to use function "backup" if "function" doesn't exist
// Useful when same functionality is also defined in an extension
#define GL_RESOLVE_WITH_EXT( function, backup ) \
function = (function ## _func)getProcAddress( #function ); \
if( !function ) \
function = (function ## _func)getProcAddress( #backup );
namespace KWinInternal
{
// Function pointers
glXGetProcAddress_func glXGetProcAddress;
// GLX 1.3
glXQueryDrawable_func glXQueryDrawable;
// texture_from_pixmap extension functions
glXReleaseTexImageEXT_func glXReleaseTexImageEXT;
glXBindTexImageEXT_func glXBindTexImageEXT;
// glXCopySubBufferMESA
glXCopySubBuffer_func glXCopySubBuffer;
// video_sync extension functions
glXGetVideoSync_func glXGetVideoSync;
glXWaitVideoSync_func glXWaitVideoSync;
// glActiveTexture
glActiveTexture_func glActiveTexture;
// framebuffer_object extension functions
glIsRenderbuffer_func glIsRenderbuffer;
glBindRenderbuffer_func glBindRenderbuffer;
glDeleteRenderbuffers_func glDeleteRenderbuffers;
glGenRenderbuffers_func glGenRenderbuffers;
glRenderbufferStorage_func glRenderbufferStorage;
glGetRenderbufferParameteriv_func glGetRenderbufferParameteriv;
glIsFramebuffer_func glIsFramebuffer;
glBindFramebuffer_func glBindFramebuffer;
glDeleteFramebuffers_func glDeleteFramebuffers;
glGenFramebuffers_func glGenFramebuffers;
glCheckFramebufferStatus_func glCheckFramebufferStatus;
glFramebufferTexture1D_func glFramebufferTexture1D;
glFramebufferTexture2D_func glFramebufferTexture2D;
glFramebufferTexture3D_func glFramebufferTexture3D;
glFramebufferRenderbuffer_func glFramebufferRenderbuffer;
glGetFramebufferAttachmentParameteriv_func glGetFramebufferAttachmentParameteriv;
glGenerateMipmap_func glGenerateMipmap;
// Shader functions
glCreateShader_func glCreateShader;
glShaderSource_func glShaderSource;
glCompileShader_func glCompileShader;
glDeleteShader_func glDeleteShader;
glCreateProgram_func glCreateProgram;
glAttachShader_func glAttachShader;
glLinkProgram_func glLinkProgram;
glUseProgram_func glUseProgram;
glDeleteProgram_func glDeleteProgram;
glGetShaderInfoLog_func glGetShaderInfoLog;
glGetProgramInfoLog_func glGetProgramInfoLog;
glGetProgramiv_func glGetProgramiv;
glGetShaderiv_func glGetShaderiv;
glUniform1f_func glUniform1f;
glUniform1i_func glUniform1i;
glUniform1fv_func glUniform1fv;
glUniform2fv_func glUniform2fv;
glValidateProgram_func glValidateProgram;
glGetUniformLocation_func glGetUniformLocation;
glVertexAttrib1f_func glVertexAttrib1f;
glGetAttribLocation_func glGetAttribLocation;
static glXFuncPtr getProcAddress( const char* name )
{
glXFuncPtr ret = NULL;
if( glXGetProcAddress != NULL )
ret = glXGetProcAddress( ( const GLubyte* ) name );
if( ret == NULL )
ret = ( glXFuncPtr ) dlsym( RTLD_DEFAULT, name );
return ret;
}
void glxResolveFunctions()
{
// handle OpenGL extensions functions
glXGetProcAddress = (glXGetProcAddress_func) getProcAddress( "glXGetProcAddress" );
if( glXGetProcAddress == NULL )
glXGetProcAddress = (glXGetProcAddress_func) getProcAddress( "glXGetProcAddressARB" );
glXQueryDrawable = (glXQueryDrawable_func) getProcAddress( "glXQueryDrawable" );
if( hasGLExtension( "GLX_EXT_texture_from_pixmap" ))
{
glXBindTexImageEXT = (glXBindTexImageEXT_func) getProcAddress( "glXBindTexImageEXT" );
glXReleaseTexImageEXT = (glXReleaseTexImageEXT_func) getProcAddress( "glXReleaseTexImageEXT" );
}
else
{
glXBindTexImageEXT = NULL;
glXReleaseTexImageEXT = NULL;
}
if( hasGLExtension( "GLX_MESA_copy_sub_buffer" ))
glXCopySubBuffer = (glXCopySubBuffer_func) getProcAddress( "glXCopySubBufferMESA" );
else
glXCopySubBuffer = NULL;
if( hasGLExtension( "GLX_SGI_video_sync" ))
{
glXGetVideoSync = (glXGetVideoSync_func) getProcAddress( "glXGetVideoSyncSGI" );
glXWaitVideoSync = (glXWaitVideoSync_func) getProcAddress( "glXWaitVideoSyncSGI" );
}
else
{
glXGetVideoSync = NULL;
glXWaitVideoSync = NULL;
}
}
void glResolveFunctions()
{
if( hasGLExtension( "GL_ARB_multitexture" ))
{
GL_RESOLVE_WITH_EXT( glActiveTexture, glActiveTextureARB );
// Get number of texture units
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &glTextureUnitsCount);
}
else
{
glActiveTexture = NULL;
glTextureUnitsCount = 0;
}
if( hasGLExtension( "GL_EXT_framebuffer_object" ))
{
glIsRenderbuffer = (glIsRenderbuffer_func) getProcAddress( "glIsRenderbufferEXT" );
glBindRenderbuffer = (glBindRenderbuffer_func) getProcAddress( "glBindRenderbufferEXT" );
glDeleteRenderbuffers = (glDeleteRenderbuffers_func) getProcAddress( "glDeleteRenderbuffersEXT" );
glGenRenderbuffers = (glGenRenderbuffers_func) getProcAddress( "glGenRenderbuffersEXT" );
glRenderbufferStorage = (glRenderbufferStorage_func) getProcAddress( "glRenderbufferStorageEXT" );
glGetRenderbufferParameteriv = (glGetRenderbufferParameteriv_func) getProcAddress( "glGetRenderbufferParameterivEXT" );
glIsFramebuffer = (glIsFramebuffer_func) getProcAddress( "glIsFramebufferEXT" );
glBindFramebuffer = (glBindFramebuffer_func) getProcAddress( "glBindFramebufferEXT" );
glDeleteFramebuffers = (glDeleteFramebuffers_func) getProcAddress( "glDeleteFramebuffersEXT" );
glGenFramebuffers = (glGenFramebuffers_func) getProcAddress( "glGenFramebuffersEXT" );
glCheckFramebufferStatus = (glCheckFramebufferStatus_func) getProcAddress( "glCheckFramebufferStatusEXT" );
glFramebufferTexture1D = (glFramebufferTexture1D_func) getProcAddress( "glFramebufferTexture1DEXT" );
glFramebufferTexture2D = (glFramebufferTexture2D_func) getProcAddress( "glFramebufferTexture2DEXT" );
glFramebufferTexture3D = (glFramebufferTexture3D_func) getProcAddress( "glFramebufferTexture3DEXT" );
glFramebufferRenderbuffer = (glFramebufferRenderbuffer_func) getProcAddress( "glFramebufferRenderbufferEXT" );
glGetFramebufferAttachmentParameteriv = (glGetFramebufferAttachmentParameteriv_func) getProcAddress( "glGetFramebufferAttachmentParameterivEXT" );
glGenerateMipmap = (glGenerateMipmap_func) getProcAddress( "glGenerateMipmapEXT" );
}
else
{
glIsRenderbuffer = NULL;
glBindRenderbuffer = NULL;
glDeleteRenderbuffers = NULL;
glGenRenderbuffers = NULL;
glRenderbufferStorage = NULL;
glGetRenderbufferParameteriv = NULL;
glIsFramebuffer = NULL;
glBindFramebuffer = NULL;
glDeleteFramebuffers = NULL;
glGenFramebuffers = NULL;
glCheckFramebufferStatus = NULL;
glFramebufferTexture1D = NULL;
glFramebufferTexture2D = NULL;
glFramebufferTexture3D = NULL;
glFramebufferRenderbuffer = NULL;
glGetFramebufferAttachmentParameteriv = NULL;
glGenerateMipmap = NULL;
}
if( hasGLExtension( "GL_ARB_shading_language_100" ) && hasGLExtension( "GL_ARB_fragment_shader" ))
{
GL_RESOLVE_WITH_EXT( glCreateShader, glCreateShaderObjectARB );
GL_RESOLVE_WITH_EXT( glShaderSource, glShaderSourceARB );
GL_RESOLVE_WITH_EXT( glCompileShader, glCompileShaderARB );
GL_RESOLVE_WITH_EXT( glDeleteShader, glDeleteObjectARB );
GL_RESOLVE_WITH_EXT( glCreateProgram, glCreateProgramObjectARB );
GL_RESOLVE_WITH_EXT( glAttachShader, glAttachObjectARB );
GL_RESOLVE_WITH_EXT( glLinkProgram, glLinkProgramARB );
GL_RESOLVE_WITH_EXT( glUseProgram, glUseProgramObjectARB );
GL_RESOLVE_WITH_EXT( glDeleteProgram, glDeleteObjectARB );
GL_RESOLVE_WITH_EXT( glGetShaderInfoLog, glGetInfoLogARB );
GL_RESOLVE_WITH_EXT( glGetProgramInfoLog, glGetInfoLogARB );
GL_RESOLVE_WITH_EXT( glGetProgramiv, glGetObjectParameterivARB );
GL_RESOLVE_WITH_EXT( glGetShaderiv, glGetObjectParameterivARB );
GL_RESOLVE_WITH_EXT( glUniform1f, glUniform1fARB );
GL_RESOLVE_WITH_EXT( glUniform1i, glUniform1iARB );
GL_RESOLVE_WITH_EXT( glUniform1fv, glUniform1fvARB );
GL_RESOLVE_WITH_EXT( glUniform2fv, glUniform2fvARB );
GL_RESOLVE_WITH_EXT( glValidateProgram, glValidateProgramARB );
GL_RESOLVE_WITH_EXT( glGetUniformLocation, glGetUniformLocationARB );
GL_RESOLVE_WITH_EXT( glVertexAttrib1f, glVertexAttrib1fARB );
GL_RESOLVE_WITH_EXT( glGetAttribLocation, glGetAttribLocationARB );
}
}
} // namespace

166
glutils_funcs.h Normal file
View file

@ -0,0 +1,166 @@
/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
******************************************************************/
#ifndef KWIN_GLUTILS_FUNCS_H
#define KWIN_GLUTILS_FUNCS_H
namespace KWinInternal
{
void glxResolveFunctions();
void glResolveFunctions();
// Defines
/*
** GLX_EXT_texture_from_pixmap
*/
#define GLX_BIND_TO_TEXTURE_RGB_EXT 0x20D0
#define GLX_BIND_TO_TEXTURE_RGBA_EXT 0x20D1
#define GLX_BIND_TO_MIPMAP_TEXTURE_EXT 0x20D2
#define GLX_BIND_TO_TEXTURE_TARGETS_EXT 0x20D3
#define GLX_Y_INVERTED_EXT 0x20D4
#define GLX_TEXTURE_FORMAT_EXT 0x20D5
#define GLX_TEXTURE_TARGET_EXT 0x20D6
#define GLX_MIPMAP_TEXTURE_EXT 0x20D7
#define GLX_TEXTURE_FORMAT_NONE_EXT 0x20D8
#define GLX_TEXTURE_FORMAT_RGB_EXT 0x20D9
#define GLX_TEXTURE_FORMAT_RGBA_EXT 0x20DA
#define GLX_TEXTURE_1D_BIT_EXT 0x00000001
#define GLX_TEXTURE_2D_BIT_EXT 0x00000002
#define GLX_TEXTURE_RECTANGLE_BIT_EXT 0x00000004
#define GLX_TEXTURE_1D_EXT 0x20DB
#define GLX_TEXTURE_2D_EXT 0x20DC
#define GLX_TEXTURE_RECTANGLE_EXT 0x20DD
#define GLX_FRONT_LEFT_EXT 0x20DE
// Shader stuff
#define GL_COMPILE_STATUS 0x8B81
#define GL_LINK_STATUS 0x8B82
#define GL_INFO_LOG_LENGTH 0x8B84
#define GL_FRAGMENT_SHADER 0x8B30
#define GL_VERTEX_SHADER 0x8B31
// Function pointers
// finding of OpenGL extensions functions
typedef void (*glXFuncPtr)();
typedef glXFuncPtr (*glXGetProcAddress_func)( const GLubyte* );
extern glXGetProcAddress_func glXGetProcAddress;
// glXQueryDrawable (added in GLX 1.3)
typedef void (*glXQueryDrawable_func)( Display* dpy, GLXDrawable drawable,
int attribute, unsigned int *value );
extern glXQueryDrawable_func glXQueryDrawable;
// texture_from_pixmap extension functions
typedef void (*glXBindTexImageEXT_func)( Display* dpy, GLXDrawable drawable,
int buffer, const int* attrib_list );
typedef void (*glXReleaseTexImageEXT_func)( Display* dpy, GLXDrawable drawable, int buffer );
extern glXReleaseTexImageEXT_func glXReleaseTexImageEXT;
extern glXBindTexImageEXT_func glXBindTexImageEXT;
// glXCopySubBufferMESA
typedef void (*glXCopySubBuffer_func) ( Display* , GLXDrawable, int, int, int, int );
extern glXCopySubBuffer_func glXCopySubBuffer;
// video_sync extension functions
typedef void (*glXGetVideoSync_func)( unsigned int *count );
typedef void (*glXWaitVideoSync_func)( int divisor, int remainder, unsigned int *count );
extern glXGetVideoSync_func glXGetVideoSync;
extern glXWaitVideoSync_func glXWaitVideoSync;
// glActiveTexture
typedef void (*glActiveTexture_func)(GLenum);
extern glActiveTexture_func glActiveTexture;
// framebuffer_object extension functions
typedef bool (*glIsRenderbuffer_func)( GLuint renderbuffer );
typedef void (*glBindRenderbuffer_func)( GLenum target, GLuint renderbuffer );
typedef void (*glDeleteRenderbuffers_func)( GLsizei n, const GLuint *renderbuffers );
typedef void (*glGenRenderbuffers_func)( GLsizei n, GLuint *renderbuffers );
typedef void (*glRenderbufferStorage_func)( GLenum target, GLenum internalformat, GLsizei width, GLsizei height );
typedef void (*glGetRenderbufferParameteriv_func)( GLenum target, GLenum pname, GLint *params );
typedef bool (*glIsFramebuffer_func)( GLuint framebuffer );
typedef void (*glBindFramebuffer_func)( GLenum target, GLuint framebuffer );
typedef void (*glDeleteFramebuffers_func)( GLsizei n, const GLuint *framebuffers );
typedef void (*glGenFramebuffers_func)( GLsizei n, GLuint *framebuffers );
typedef void (*glCheckFramebufferStatus_func)( GLenum target );
typedef void (*glFramebufferTexture1D_func)( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level );
typedef void (*glFramebufferTexture2D_func)( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level );
typedef void (*glFramebufferTexture3D_func)( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset );
typedef void (*glFramebufferRenderbuffer_func)( GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer );
typedef void (*glGetFramebufferAttachmentParameteriv_func)( GLenum target, GLenum attachment, GLenum pname, GLint *params );
typedef void (*glGenerateMipmap_func)( GLenum target );
extern glIsRenderbuffer_func glIsRenderbuffer;
extern glBindRenderbuffer_func glBindRenderbuffer;
extern glDeleteRenderbuffers_func glDeleteRenderbuffers;
extern glGenRenderbuffers_func glGenRenderbuffers;
extern glRenderbufferStorage_func glRenderbufferStorage;
extern glGetRenderbufferParameteriv_func glGetRenderbufferParameteriv;
extern glIsFramebuffer_func glIsFramebuffer;
extern glBindFramebuffer_func glBindFramebuffer;
extern glDeleteFramebuffers_func glDeleteFramebuffers;
extern glGenFramebuffers_func glGenFramebuffers;
extern glCheckFramebufferStatus_func glCheckFramebufferStatus;
extern glFramebufferTexture1D_func glFramebufferTexture1D;
extern glFramebufferTexture2D_func glFramebufferTexture2D;
extern glFramebufferTexture3D_func glFramebufferTexture3D;
extern glFramebufferRenderbuffer_func glFramebufferRenderbuffer;
extern glGetFramebufferAttachmentParameteriv_func glGetFramebufferAttachmentParameteriv;
extern glGenerateMipmap_func glGenerateMipmap;
// Shader stuff
typedef GLuint (*glCreateShader_func)(GLenum);
typedef GLvoid (*glShaderSource_func)(GLuint, GLsizei, const GLchar**, const GLint*);
typedef GLvoid (*glCompileShader_func)(GLuint);
typedef GLvoid (*glDeleteShader_func)(GLuint);
typedef GLuint (*glCreateProgram_func)();
typedef GLvoid (*glAttachShader_func)(GLuint, GLuint);
typedef GLvoid (*glLinkProgram_func)(GLuint);
typedef GLvoid (*glUseProgram_func)(GLuint);
typedef GLvoid (*glDeleteProgram_func)(GLuint);
typedef GLvoid (*glGetShaderInfoLog_func)(GLuint, GLsizei, GLsizei*, GLchar*);
typedef GLvoid (*glGetProgramInfoLog_func)(GLuint, GLsizei, GLsizei*, GLchar*);
typedef GLvoid (*glGetProgramiv_func)(GLuint, GLenum, GLint*);
typedef GLvoid (*glGetShaderiv_func)(GLuint, GLenum, GLint*);
typedef GLvoid (*glUniform1f_func)(GLint, GLfloat);
typedef GLvoid (*glUniform1i_func)(GLint, GLint);
typedef GLvoid (*glUniform1fv_func)(GLint, GLsizei, const GLfloat*);
typedef GLvoid (*glUniform2fv_func)(GLint, GLsizei, const GLfloat*);
typedef GLvoid (*glUniform3fv_func)(GLint, GLsizei, const GLfloat*);
typedef GLvoid (*glValidateProgram_func)(GLuint);
typedef GLint (*glGetUniformLocation_func)(GLuint, const GLchar*);
typedef GLvoid (*glVertexAttrib1f_func)(GLuint, GLfloat);
typedef GLint (*glGetAttribLocation_func)(GLuint, const GLchar*);
extern glCreateShader_func glCreateShader;
extern glShaderSource_func glShaderSource;
extern glCompileShader_func glCompileShader;
extern glDeleteShader_func glDeleteShader;
extern glCreateProgram_func glCreateProgram;
extern glAttachShader_func glAttachShader;
extern glLinkProgram_func glLinkProgram;
extern glUseProgram_func glUseProgram;
extern glDeleteProgram_func glDeleteProgram;
extern glGetShaderInfoLog_func glGetShaderInfoLog;
extern glGetProgramInfoLog_func glGetProgramInfoLog;
extern glGetProgramiv_func glGetProgramiv;
extern glGetShaderiv_func glGetShaderiv;
extern glUniform1f_func glUniform1f;
extern glUniform1i_func glUniform1i;
extern glUniform1fv_func glUniform1fv;
extern glUniform2fv_func glUniform2fv;
extern glValidateProgram_func glValidateProgram;
extern glGetUniformLocation_func glGetUniformLocation;
extern glVertexAttrib1f_func glVertexAttrib1f;
extern glGetAttribLocation_func glGetAttribLocation;
} // namespace
#endif