mirror of
https://git.code.sf.net/p/quake/newtree
synced 2024-11-22 12:11:34 +00:00
New functionality: QuakeForge now has a general OpenGL extension-loading
interface. To detect an extension, call QFGL_ExtensionPresent(). To get the address of an extension function, call QFGL_ExtensionAddress(). This function uses the preferred method for finding a function, based on whatever OS and windowing system you use.
This commit is contained in:
parent
ba1b5f8974
commit
732dc94090
2 changed files with 289 additions and 0 deletions
109
include/qfgl_ext.h
Normal file
109
include/qfgl_ext.h
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
/*
|
||||||
|
qfgl_ext.h
|
||||||
|
|
||||||
|
QuakeForge OpenGL extension interface definitions
|
||||||
|
|
||||||
|
Copyright (C) 2000 Jeff Teunissen <deek@dusknet.dhs.org>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __qfgl_ext_h_
|
||||||
|
#define __qfgl_ext_h_
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <GL/gl.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_GL_GLX_H
|
||||||
|
# include <GL/glx.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_GL_GLEXT_H
|
||||||
|
# include <GL/glext.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_WINDOWS_H
|
||||||
|
# include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "qtypes.h"
|
||||||
|
|
||||||
|
/* Standard OpenGL external function defs */
|
||||||
|
typedef void (GLAPIENTRY *QF_glBlendColor) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
|
||||||
|
typedef void (GLAPIENTRY *QF_glBlendEquation) (GLenum mode);
|
||||||
|
typedef void (GLAPIENTRY *QF_glDrawRangeElements) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
|
||||||
|
typedef void (GLAPIENTRY *QF_glColorTable) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table);
|
||||||
|
typedef void (GLAPIENTRY *QF_glColorTableParameterfv) (GLenum target, GLenum pname, const GLfloat *params);
|
||||||
|
typedef void (GLAPIENTRY *QF_glColorTableParameteriv) (GLenum target, GLenum pname, const GLint *params);
|
||||||
|
typedef void (GLAPIENTRY *QF_glCopyColorTable) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
|
||||||
|
typedef void (GLAPIENTRY *QF_glGetColorTable) (GLenum target, GLenum format, GLenum type, GLvoid *table);
|
||||||
|
typedef void (GLAPIENTRY *QF_glGetColorTableParameterfv) (GLenum target, GLenum pname, GLfloat *params);
|
||||||
|
typedef void (GLAPIENTRY *QF_glGetColorTableParameteriv) (GLenum target, GLenum pname, GLint *params);
|
||||||
|
typedef void (GLAPIENTRY *QF_glColorSubTable) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data);
|
||||||
|
typedef void (GLAPIENTRY *QF_glCopyColorSubTable) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width);
|
||||||
|
typedef void (GLAPIENTRY *QF_glConvolutionFilter1D) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image);
|
||||||
|
typedef void (GLAPIENTRY *QF_glConvolutionFilter2D) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image);
|
||||||
|
typedef void (GLAPIENTRY *QF_glConvolutionParameterf) (GLenum target, GLenum pname, GLfloat params);
|
||||||
|
typedef void (GLAPIENTRY *QF_glConvolutionParameterfv) (GLenum target, GLenum pname, const GLfloat *params);
|
||||||
|
typedef void (GLAPIENTRY *QF_glConvolutionParameteri) (GLenum target, GLenum pname, GLint params);
|
||||||
|
typedef void (GLAPIENTRY *QF_glConvolutionParameteriv) (GLenum target, GLenum pname, const GLint *params);
|
||||||
|
typedef void (GLAPIENTRY *QF_glCopyConvolutionFilter1D) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
|
||||||
|
typedef void (GLAPIENTRY *QF_glCopyConvolutionFilter2D) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height);
|
||||||
|
typedef void (GLAPIENTRY *QF_glGetConvolutionFilter) (GLenum target, GLenum format, GLenum type, GLvoid *image);
|
||||||
|
typedef void (GLAPIENTRY *QF_glGetConvolutionParameterfv) (GLenum target, GLenum pname, GLfloat *params);
|
||||||
|
typedef void (GLAPIENTRY *QF_glGetConvolutionParameteriv) (GLenum target, GLenum pname, GLint *params);
|
||||||
|
typedef void (GLAPIENTRY *QF_glGetSeparableFilter) (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span);
|
||||||
|
typedef void (GLAPIENTRY *QF_glSeparableFilter2D) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column);
|
||||||
|
typedef void (GLAPIENTRY *QF_glGetHistogram) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values);
|
||||||
|
typedef void (GLAPIENTRY *QF_glGetHistogramParameterfv) (GLenum target, GLenum pname, GLfloat *params);
|
||||||
|
typedef void (GLAPIENTRY *QF_glGetHistogramParameteriv) (GLenum target, GLenum pname, GLint *params);
|
||||||
|
typedef void (GLAPIENTRY *QF_glGetMinmax) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values);
|
||||||
|
typedef void (GLAPIENTRY *QF_glGetMinmaxParameterfv) (GLenum target, GLenum pname, GLfloat *params);
|
||||||
|
typedef void (GLAPIENTRY *QF_glGetMinmaxParameteriv) (GLenum target, GLenum pname, GLint *params);
|
||||||
|
typedef void (GLAPIENTRY *QF_glHistogram) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink);
|
||||||
|
typedef void (GLAPIENTRY *QF_glMinmax) (GLenum target, GLenum internalformat, GLboolean sink);
|
||||||
|
typedef void (GLAPIENTRY *QF_glResetHistogram) (GLenum target);
|
||||||
|
typedef void (GLAPIENTRY *QF_glResetMinmax) (GLenum target);
|
||||||
|
typedef void (GLAPIENTRY *QF_glTexImage3D) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
|
||||||
|
typedef void (GLAPIENTRY *QF_glTexSubImage3D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels);
|
||||||
|
typedef void (GLAPIENTRY *QF_glCopyTexSubImage3D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
|
||||||
|
|
||||||
|
// GL_EXT_paletted_texture
|
||||||
|
typedef void (GLAPIENTRY *QF_glColorTableEXT) (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *table);
|
||||||
|
typedef void (GLAPIENTRY *QF_glGetColorTableEXT) (GLenum target, GLenum format, GLenum type, GLvoid *data);
|
||||||
|
typedef void (GLAPIENTRY *QF_glGetColorTableParameterivEXT) (GLenum target, GLenum pname, GLint *params);
|
||||||
|
typedef void (GLAPIENTRY *QF_glGetColorTableParameterfvEXT) (GLenum target, GLenum pname, GLfloat *params);
|
||||||
|
|
||||||
|
// 3Dfx
|
||||||
|
typedef void (GLAPIENTRY *QF_gl3DfxSetPaletteEXT) (GLuint *pal);
|
||||||
|
|
||||||
|
// GLX 1.3
|
||||||
|
typedef void *(GLAPIENTRY *QF_glXGetProcAddressARB) (const GLubyte *procName);
|
||||||
|
|
||||||
|
// WGL (Windows GL)
|
||||||
|
typedef const GLubyte *(GLAPIENTRY *QF_wglGetExtensionsStringEXT) (void);
|
||||||
|
|
||||||
|
/* QuakeForge extension functions */
|
||||||
|
qboolean QFGL_ExtensionPresent (const char *);
|
||||||
|
void *QFGL_ExtensionAddress (const char *);
|
||||||
|
|
||||||
|
#endif // __qfgl_ext_h_
|
180
source/qfgl_ext.c
Normal file
180
source/qfgl_ext.c
Normal file
|
@ -0,0 +1,180 @@
|
||||||
|
/*
|
||||||
|
qfgl_ext.c
|
||||||
|
|
||||||
|
QuakeForge OpenGL extension interface definitions
|
||||||
|
|
||||||
|
Copyright (C) 2000 Jeff Teunissen <deek@dusknet.dhs.org>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_DLFCN_H
|
||||||
|
# include <dlfcn.h>
|
||||||
|
#endif
|
||||||
|
#ifndef RTLD_LAZY
|
||||||
|
# ifdef DL_LAZY
|
||||||
|
# define RTLD_LAZY DL_LAZY
|
||||||
|
# else
|
||||||
|
# define RTLD_LAZY 0
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <GL/gl.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_GL_GLX_H
|
||||||
|
# include <GL/glx.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_GL_GLEXT_H
|
||||||
|
# include <GL/glext.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_WINDOWS_H
|
||||||
|
# include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "qfgl_ext.h"
|
||||||
|
#include "qtypes.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
ParseExtensionList
|
||||||
|
|
||||||
|
It takes a bit of care to be fool-proof about parsing an OpenGL extensions
|
||||||
|
string. Don't be fooled by sub-strings, etc.
|
||||||
|
*/
|
||||||
|
qboolean
|
||||||
|
QFGL_ParseExtensionList (const GLubyte *list, const char *name)
|
||||||
|
{
|
||||||
|
const char *start;
|
||||||
|
char *where, *terminator;
|
||||||
|
|
||||||
|
// Extension names must not have spaces.
|
||||||
|
where = (GLubyte *) strchr (name, ' ');
|
||||||
|
if (where || *name == '\0')
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
start = list;
|
||||||
|
for (;;) {
|
||||||
|
where = strstr (start, name);
|
||||||
|
if (!where)
|
||||||
|
break;
|
||||||
|
terminator = where + strlen (name);
|
||||||
|
if (where == start || *(where - 1) == ' ')
|
||||||
|
if (*terminator == ' ' || *terminator == '\0')
|
||||||
|
return 1;
|
||||||
|
start = terminator;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
qboolean
|
||||||
|
QFGL_ExtensionPresent (const char *name)
|
||||||
|
{
|
||||||
|
static const GLubyte *gl_extensions = NULL;
|
||||||
|
#ifdef _WIN32
|
||||||
|
static const GLubyte *wgl_extensions = NULL;
|
||||||
|
|
||||||
|
static qboolean extensionFunc_present = true;
|
||||||
|
static QF_wglGetExtensionsStringEXT extensionFunc = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!gl_extensions) { // get and save GL extension list
|
||||||
|
gl_extensions = glGetString (GL_EXTENSIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (!wgl_extensions) { // get and save WGL extension list
|
||||||
|
if (extensionFunc_present && !extensionFunc) {
|
||||||
|
if (!(QFGL_ParseExtensionList (gl_extensions, "WGL_EXT_extensions_string"))) {
|
||||||
|
extensionFunc_present = false;
|
||||||
|
} else {
|
||||||
|
extensionFunc = QFGL_ExtensionAddress ("WGL_EXT_extension_string");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (extensionFunc_present)
|
||||||
|
wgl_extensions = extensionFunc ();
|
||||||
|
else
|
||||||
|
wgl_extensions = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (QFGL_ParseExtensionList (gl_extensions, name))
|
||||||
|
return true;
|
||||||
|
if (QFGL_ParseExtensionList (wgl_extensions, name))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
|
return QFGL_ParseExtensionList (gl_extensions, name);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void *
|
||||||
|
QFGL_ExtensionAddress (const char *name)
|
||||||
|
{
|
||||||
|
#if defined(HAVE_GLX) && defined(HAVE_DLOPEN)
|
||||||
|
void *dlhand = NULL;
|
||||||
|
|
||||||
|
static qboolean glProcAddress_present = true;
|
||||||
|
static QF_glXGetProcAddressARB qfglXGetProcAddress = NULL;
|
||||||
|
|
||||||
|
if (glProcAddress_present && !qfglXGetProcAddress) {
|
||||||
|
if (QFGL_ExtensionPresent ("GLX_ARB_get_proc_address")) {
|
||||||
|
if ((dlhand = dlopen (NULL, RTLD_LAZY))) {
|
||||||
|
qfglXGetProcAddress = dlsym (dlhand, "glXGetProcAddressARB");
|
||||||
|
dlclose (dlhand);
|
||||||
|
} else {
|
||||||
|
glProcAddress_present = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
glProcAddress_present = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (name) {
|
||||||
|
#if defined(HAVE_GLX) && defined(HAVE_DLOPEN)
|
||||||
|
if (glProcAddress_present) {
|
||||||
|
return qfglXGetProcAddress ((const GLubyte *) name);
|
||||||
|
} else {
|
||||||
|
if ((dlhand = dlopen (NULL, RTLD_LAZY))) {
|
||||||
|
void *handle;
|
||||||
|
handle = dlsym (dlhand, name);
|
||||||
|
dlclose (dlhand);
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# ifdef _WIN32
|
||||||
|
return wglGetProcAddress (name);
|
||||||
|
# else
|
||||||
|
return NULL;
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
Loading…
Reference in a new issue