From 023ffa7dced1cf138bfe19d64cddc05c24a4325f Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 30 Jan 2005 19:50:55 +0000 Subject: [PATCH] move extension handling into a separate file --- stepmania/src/RageDisplay_OGL.cpp | 91 +++------------- stepmania/src/RageDisplay_OGL_Extensions.cpp | 104 +++++++++++++++++++ stepmania/src/RageDisplay_OGL_Extensions.h | 56 ++++++++++ 3 files changed, 173 insertions(+), 78 deletions(-) create mode 100644 stepmania/src/RageDisplay_OGL_Extensions.cpp create mode 100644 stepmania/src/RageDisplay_OGL_Extensions.h diff --git a/stepmania/src/RageDisplay_OGL.cpp b/stepmania/src/RageDisplay_OGL.cpp index 65f549a998..219212dd42 100644 --- a/stepmania/src/RageDisplay_OGL.cpp +++ b/stepmania/src/RageDisplay_OGL.cpp @@ -11,6 +11,10 @@ # include # include #else +/* XXX: Instead, try creating a directory "archutils/Darwin/include/GL", containing "gl.h" and + * "glu.h", which each contain a single line "#include ". Then, add + * "archutils/Darwin/include" to your -I paths, so the above includes will work + * without changes. */ # include # include #endif @@ -31,37 +35,13 @@ #include #include -/* Not in glext.h: */ -typedef bool (APIENTRY * PWSWAPINTERVALEXTPROC) (int interval); - - -/* Extension functions we use. Put these in a namespace instead of in oglspecs_t, - * so they can be called like regular functions. */ -static struct GLExt_t -{ - PWSWAPINTERVALEXTPROC wglSwapIntervalEXT; - PFNGLCOLORTABLEPROC glColorTableEXT; - PFNGLCOLORTABLEPARAMETERIVPROC glGetColorTableParameterivEXT; - PFNGLACTIVETEXTUREARBPROC glActiveTextureARB; - PFNGLGENBUFFERSARBPROC glGenBuffersARB; - PFNGLBINDBUFFERARBPROC glBindBufferARB; - PFNGLBUFFERDATAARBPROC glBufferDataARB; - PFNGLBUFFERSUBDATAARBPROC glBufferSubDataARB; - PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB; - PFNGLDRAWRANGEELEMENTSPROC glDrawRangeElements; - - void Reset() - { - memset( this, 0, sizeof(*this) ); - } -} GLExt; - #if defined(DARWIN) #include "archutils/Darwin/Vsync.h" #endif #include "RageDisplay.h" #include "RageDisplay_OGL.h" +#include "RageDisplay_OGL_Extensions.h" #include "RageUtil.h" #include "RageLog.h" #include "RageTimer.h" @@ -86,9 +66,6 @@ static struct GLExt_t // Globals // -static bool g_bEXT_texture_env_combine = true; -static bool g_bGL_EXT_bgra = true; - static bool g_bReversePackedPixelsWorks = true; static bool g_bColorIndexTableWorks = true; @@ -624,54 +601,12 @@ void SetupExtensions() const float fGLUVersion = strtof( (const char *) gluGetString(GLU_VERSION), NULL ); g_gluVersion = int(roundf(fGLUVersion * 10)); - /* Reset extensions. */ - GLExt.Reset(); - - /* - * Find extension functions. - * - * X11R6.7.0 (or possibly ATI's drivers) seem to be returning bogus values for glBindBufferARB - * if we don't actually check for GL_ARB_vertex_buffer_object. - * https://sf.net/tracker/download.php?group_id=37892&atid=421366&file_id=88086&aid=958820 - * https://sf.net/tracker/download.php?group_id=37892&atid=421366&file_id=85542&aid=944836 - * - * Let's check them all, to be safe. - */ + GLExt.Load( wind ); -#if defined(WIN32) - if( HasExtension("WGL_EXT_swap_control") ) - GLExt.wglSwapIntervalEXT = (PWSWAPINTERVALEXTPROC) wind->GetProcAddress("wglSwapIntervalEXT"); -#elif defined(DARWIN) - GLExt.wglSwapIntervalEXT = wglSwapIntervalEXT; -#endif + g_iMaxTextureUnits = 1; + if( GLExt.glActiveTextureARB != NULL ) + glGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, (GLint *) &g_iMaxTextureUnits ); - if( HasExtension("GL_EXT_paletted_texture") ) - { - GLExt.glColorTableEXT = (PFNGLCOLORTABLEPROC) wind->GetProcAddress("glColorTableEXT"); - GLExt.glGetColorTableParameterivEXT = (PFNGLCOLORTABLEPARAMETERIVPROC) wind->GetProcAddress("glGetColorTableParameterivEXT"); - } - - if( HasExtension("GL_ARB_multitexture") ) - { - GLExt.glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) wind->GetProcAddress("glActiveTextureARB"); - g_iMaxTextureUnits = 1; - glGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, (GLint *)&g_iMaxTextureUnits ); - } - - if( HasExtension("GL_ARB_vertex_buffer_object") ) - { - GLExt.glGenBuffersARB = (PFNGLGENBUFFERSARBPROC) wind->GetProcAddress("glGenBuffersARB"); - GLExt.glBindBufferARB = (PFNGLBINDBUFFERARBPROC) wind->GetProcAddress("glBindBufferARB"); - GLExt.glBufferDataARB = (PFNGLBUFFERDATAARBPROC) wind->GetProcAddress("glBufferDataARB"); - GLExt.glBufferSubDataARB = (PFNGLBUFFERSUBDATAARBPROC) wind->GetProcAddress("glBufferSubDataARB"); - GLExt.glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC) wind->GetProcAddress("glDeleteBuffersARB"); - } - - if( HasExtension("GL_EXT_draw_range_elements") ) - GLExt.glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC) wind->GetProcAddress("glDrawRangeElements"); - - g_bEXT_texture_env_combine = HasExtension("GL_EXT_texture_env_combine"); - g_bGL_EXT_bgra = HasExtension("GL_EXT_bgra"); CheckPalettedTextures(); CheckReversePackedPixels(); @@ -1346,7 +1281,7 @@ void RageDisplay_OGL::SetTextureModeModulate() void RageDisplay_OGL::SetTextureModeGlow() { - if( !g_bEXT_texture_env_combine ) + if( !GLExt.m_bEXT_texture_env_combine ) { /* This is changing blend state, instead of texture state, which isn't * great, but it's better than doing nothing. */ @@ -1461,7 +1396,7 @@ void RageDisplay_OGL::SetMaterial( // will have no effect. Even if lighting is off, we still // want Models to have basic color and transparency. // We can do this fake lighting by setting the vertex color. - + // XXX: unintended: SetLighting must be called before SetMaterial GLboolean bLighting; glGetBooleanv( GL_LIGHTING, &bLighting ); @@ -1850,7 +1785,7 @@ bool RageDisplay_OGL::SupportsSurfaceFormat( PixelFormat pixfmt ) switch( GL_PIXFMT_INFO[pixfmt].type ) { case GL_UNSIGNED_SHORT_1_5_5_5_REV: - return g_bGL_EXT_bgra && g_bReversePackedPixelsWorks; + return GLExt.m_bGL_EXT_bgra && g_bReversePackedPixelsWorks; default: return true; } @@ -1871,7 +1806,7 @@ bool RageDisplay_OGL::SupportsTextureFormat( PixelFormat pixfmt, bool realtime ) return GLExt.glColorTableEXT && GLExt.glGetColorTableParameterivEXT; case GL_BGR: case GL_BGRA: - return g_bGL_EXT_bgra; + return GLExt.m_bGL_EXT_bgra; default: return true; } diff --git a/stepmania/src/RageDisplay_OGL_Extensions.cpp b/stepmania/src/RageDisplay_OGL_Extensions.cpp new file mode 100644 index 0000000000..f3821adf13 --- /dev/null +++ b/stepmania/src/RageDisplay_OGL_Extensions.cpp @@ -0,0 +1,104 @@ +#include "global.h" + +#if defined(WIN32) +#include +#endif + +#if !defined(DARWIN) +# include +# include +#else +# include +# include +#endif + +#undef __glext_h_ +#include "glext.h" + +#include "RageDisplay_OGL_Extensions.h" +#include "arch/LowLevelWindow/LowLevelWindow.h" + +GLExt_t GLExt; + +bool HasExtension( CString ext ); + +#define F(n) { (void **) &GLExt.n , #n } + +struct func_t +{ + void **p; + const char *name; +}; + +static bool LoadAllOrNothing( struct func_t *funcs, LowLevelWindow *pWind ) +{ + bool bGotAll = true; + for( unsigned i = 0; funcs[i].p != NULL; ++i ) + { + *funcs[i].p = pWind->GetProcAddress( funcs[i].name ); + if( *funcs[i].p == NULL ) + { + bGotAll = false; + break; + } + } + + if( bGotAll ) + return true; + + /* If any function in the array wasn't found, clear them all. */ + for( unsigned i = 0; funcs[i].p != NULL; ++i ) + *funcs[i].p = NULL; + + return false; +} + +void GLExt_t::Load( LowLevelWindow *pWind ) +{ + memset( this, 0, sizeof(*this) ); + + m_bEXT_texture_env_combine = HasExtension("GL_EXT_texture_env_combine"); + m_bGL_EXT_bgra = HasExtension("GL_EXT_bgra"); + +#if defined(WIN32) + if( HasExtension("WGL_EXT_swap_control") ) + wglSwapIntervalEXT = (PWSWAPINTERVALEXTPROC) pWind->GetProcAddress("wglSwapIntervalEXT"); +#elif defined(DARWIN) + wglSwapIntervalEXT = wglSwapIntervalEXT; +#endif + + if( HasExtension("GL_EXT_paletted_texture") ) + { + glColorTableEXT = (PFNGLCOLORTABLEPROC) pWind->GetProcAddress("glColorTableEXT"); + glGetColorTableParameterivEXT = (PFNGLCOLORTABLEPARAMETERIVPROC) pWind->GetProcAddress("glGetColorTableParameterivEXT"); + } + + if( HasExtension("GL_ARB_multitexture") ) + glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) pWind->GetProcAddress("glActiveTextureARB"); + + /* + * Find extension functions. + * + * X11R6.7.0 (or possibly ATI's drivers) seem to be returning bogus values for glBindBufferARB + * if we don't actually check for GL_ARB_vertex_buffer_object. + * https://sf.net/tracker/download.php?group_id=37892&atid=421366&file_id=88086&aid=958820 + * https://sf.net/tracker/download.php?group_id=37892&atid=421366&file_id=85542&aid=944836 + * + * Let's check them all, to be safe. + */ + if( HasExtension("GL_ARB_vertex_buffer_object") ) + { + func_t funcs[] = { + F( glGenBuffersARB ), + F( glBindBufferARB ), + F( glBufferDataARB ), + F( glBufferSubDataARB ), + F( glDeleteBuffersARB ) + }; + + LoadAllOrNothing( funcs, pWind ); + } + + if( HasExtension("GL_EXT_draw_range_elements") ) + GLExt.glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC) pWind->GetProcAddress("glDrawRangeElements"); +} diff --git a/stepmania/src/RageDisplay_OGL_Extensions.h b/stepmania/src/RageDisplay_OGL_Extensions.h new file mode 100644 index 0000000000..720e7ef65e --- /dev/null +++ b/stepmania/src/RageDisplay_OGL_Extensions.h @@ -0,0 +1,56 @@ +#ifndef RAGE_DISPLAY_OGL_EXTENSIONS_H +#define RAGE_DISPLAY_OGL_EXTENSIONS_H + +/* Not in glext.h: */ +typedef bool (APIENTRY * PWSWAPINTERVALEXTPROC) (int interval); + +class LowLevelWindow; +struct GLExt_t +{ + bool m_bEXT_texture_env_combine; + bool m_bGL_EXT_bgra; + + PWSWAPINTERVALEXTPROC wglSwapIntervalEXT; + PFNGLCOLORTABLEPROC glColorTableEXT; + PFNGLCOLORTABLEPARAMETERIVPROC glGetColorTableParameterivEXT; + PFNGLACTIVETEXTUREARBPROC glActiveTextureARB; + PFNGLGENBUFFERSARBPROC glGenBuffersARB; + PFNGLBINDBUFFERARBPROC glBindBufferARB; + PFNGLBUFFERDATAARBPROC glBufferDataARB; + PFNGLBUFFERSUBDATAARBPROC glBufferSubDataARB; + PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB; + PFNGLDRAWRANGEELEMENTSPROC glDrawRangeElements; + + bool m_bGL_ARB_shading_language_100; + + void Load( LowLevelWindow *pWind ); +}; + +extern GLExt_t GLExt; + +#endif + +/* + * Copyright (c) 2003-2005 Glenn Maynard + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */