From: <z-...@us...> - 2007-11-12 21:02:17
|
Revision: 7385 http://armagetronad.svn.sourceforge.net/armagetronad/?rev=7385&view=rev Author: z-man Date: 2007-11-12 13:02:07 -0800 (Mon, 12 Nov 2007) Log Message: ----------- Added motion blurring (yay, after rotting on my hard drive for half a year) Modified Paths: -------------- armagetronad/trunk/armagetronad/config/settings_visual.cfg armagetronad/trunk/armagetronad/src/Makefile.am armagetronad/trunk/armagetronad/src/doc/install_linux.html.m4 armagetronad/trunk/armagetronad/src/engine/eDisplay.cpp armagetronad/trunk/armagetronad/src/engine/eGameObject.cpp armagetronad/trunk/armagetronad/src/render/rGL.h armagetronad/trunk/armagetronad/src/render/rSysdep.cpp armagetronad/trunk/armagetronad/src/render/rTexture.cpp armagetronad/trunk/armagetronad/src/render/rTexture.h armagetronad/trunk/armagetronad/src/tron/gArmagetron.cpp armagetronad/trunk/armagetronad/src/tron/gWall.cpp Added Paths: ----------- armagetronad/trunk/armagetronad/src/render/rGL.cpp armagetronad/trunk/armagetronad/src/render/rGLEW.h armagetronad/trunk/armagetronad/src/render/rGLuintObject.cpp armagetronad/trunk/armagetronad/src/render/rGLuintObject.h armagetronad/trunk/armagetronad/src/render/rTextureRenderTarget.cpp armagetronad/trunk/armagetronad/src/render/rTextureRenderTarget.h Modified: armagetronad/trunk/armagetronad/config/settings_visual.cfg =================================================================== --- armagetronad/trunk/armagetronad/config/settings_visual.cfg 2007-11-12 19:58:37 UTC (rev 7384) +++ armagetronad/trunk/armagetronad/config/settings_visual.cfg 2007-11-12 21:02:07 UTC (rev 7385) @@ -26,4 +26,4 @@ #FLOOR_GREEN .2 # floor color (without moviepack) #FLOOR_BLUE .3 # floor color (without moviepack) -MOTION_BLUR_TIME .015 # time over which the last rendered frames are blurred together in motion blur mode +MOTION_BLUR_TIME .0075 # time over which the last rendered frames are blurred together in motion blur mode Modified: armagetronad/trunk/armagetronad/src/Makefile.am =================================================================== --- armagetronad/trunk/armagetronad/src/Makefile.am 2007-11-12 19:58:37 UTC (rev 7384) +++ armagetronad/trunk/armagetronad/src/Makefile.am 2007-11-12 21:02:07 UTC (rev 7385) @@ -122,9 +122,10 @@ engine/eEventNotification.h engine/eEventNotification.cpp librender_a_SOURCES=render/rConsole.cpp render/rConsoleGraph.cpp render/rConsole.h render/rFont.cpp\ - render/rFont.h render/rGL.h render/rGLRender.cpp render/rModel.cpp render/rModel.h render/rRender.cpp\ + render/rFont.h render/rGL.cpp render/rGL.h render/rGLEW.h render/rGLRender.cpp render/rModel.cpp render/rModel.h render/rRender.cpp\ render/rRender.h render/rScreen.cpp render/rScreen.h render/rSDL.h render/rSysdep.cpp render/rSysdep.h\ - render/rTexture.cpp render/rTexture.h render/rViewport.cpp render/rViewport.h render/rColor.h render/rGradient.cpp render/rGradient.h + render/rTexture.cpp render/rTexture.h render/rViewport.cpp render/rViewport.h render/rColor.h render/rGradient.cpp render/rGradient.h \ + render/rTextureRenderTarget.cpp render/rTextureRenderTarget.h render/rGLuintObject.cpp render/rGLuintObject.h libtron_a_SOURCES=tron/gAIBase.cpp tron/gAIBase.h tron/gAICharacter.cpp tron/gAICharacter.h tron/gArena.cpp tron/gArena.h\ Modified: armagetronad/trunk/armagetronad/src/doc/install_linux.html.m4 =================================================================== --- armagetronad/trunk/armagetronad/src/doc/install_linux.html.m4 2007-11-12 19:58:37 UTC (rev 7384) +++ armagetronad/trunk/armagetronad/src/doc/install_linux.html.m4 2007-11-12 21:02:07 UTC (rev 7385) @@ -37,7 +37,6 @@ which itself needs the libs) ITEM(ELINK(www.libpng.org/pub/png/pngcode.html,pnglib and zlib) (they should be included in your distribution)) -ITEM(Optional: ELINK(www.libsdl.org/projects/SDL_mixer/,SDL_mixer)) ITEM([Binary versions only: libstdc++ 5.0.7 (any 5.x.y or whatever came with your System if it uses GCC 3.2 or higher should do). Use ELINK([rpmfind.net/linux/rpm2html/search.php?query=libstdc%2B%2B&submit=Search+...&system=&arch=],rpmfind) @@ -47,6 +46,10 @@ source packages instead.]) ]) +SECTION(Optional libraries,libs_opt) +ITEM(ELINK(www.libsdl.org/projects/SDL_mixer/,SDL_mixer)) +ITEM(ELINK(glew.sourceforge.net,GLEW)) + PARAGRAPH(,[ You may take a look at the ELINK(WEBBASE/compatibility.html,compatibility table) if you want to check how likely it is for Armagetron to work on your PC. Modified: armagetronad/trunk/armagetronad/src/engine/eDisplay.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/engine/eDisplay.cpp 2007-11-12 19:58:37 UTC (rev 7384) +++ armagetronad/trunk/armagetronad/src/engine/eDisplay.cpp 2007-11-12 21:02:07 UTC (rev 7385) @@ -298,6 +298,8 @@ REAL flooralpha, bool eWalls,bool gameObjects, REAL& zNear){ + sr_CheckGLError(); + /* static GLfloat S[]={1,0,0,0}; static GLfloat T[]={0,1,0,0}; @@ -505,6 +507,8 @@ else glEnable(GL_DEPTH_TEST); + sr_CheckGLError(); + if (eWalls){ glDisable(GL_CULL_FACE); draw_eWall(this,viewer,0,zNear,cameras(viewer)); @@ -536,6 +540,8 @@ } + sr_CheckGLError(); + if (gameObjects) eGameObject::RenderAll(this, cameras(viewer)); Modified: armagetronad/trunk/armagetronad/src/engine/eGameObject.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/engine/eGameObject.cpp 2007-11-12 19:58:37 UTC (rev 7384) +++ armagetronad/trunk/armagetronad/src/engine/eGameObject.cpp 2007-11-12 21:02:07 UTC (rev 7385) @@ -32,6 +32,7 @@ #include "eWall.h" #include "tConsole.h" #include "rScreen.h" +#include "rGL.h" #include "eSoundMixer.h" @@ -809,7 +810,9 @@ #ifdef DEBUG displayed_gameobject = grid->gameObjects(i); #endif + sr_CheckGLError(); grid->gameObjects(i)->Render(cam); + sr_CheckGLError(); #ifdef DEBUG displayed_gameobject = 0; #endif Added: armagetronad/trunk/armagetronad/src/render/rGL.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/render/rGL.cpp (rev 0) +++ armagetronad/trunk/armagetronad/src/render/rGL.cpp 2007-11-12 21:02:07 UTC (rev 7385) @@ -0,0 +1,53 @@ +/* + +************************************************************************* + +ArmageTron -- Just another Tron Lightcycle Game in 3D. +Copyright (C) 2006, Armagetron Advanced Development Team + +************************************************************************** + +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 the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*************************************************************************** + +*/ + +#include "rGL.h" +#include "tConsole.h" +#include "tError.h" +#include <sstream> +#include <iomanip> + +#ifdef DEBUG +void sr_CheckGLError() +{ +#ifndef DEDICATED + GLenum error = glGetError(); + if ( error != GL_NO_ERROR ) + { + std::stringstream s; + s << "GL error 0X" << std::hex << error << "\n"; + con << s.str(); + + // catch a breakpoint + static bool reported = false; + if ( !reported ) + st_Breakpoint(); + reported = true; + } +#endif +} +#endif Modified: armagetronad/trunk/armagetronad/src/render/rGL.h =================================================================== --- armagetronad/trunk/armagetronad/src/render/rGL.h 2007-11-12 19:58:37 UTC (rev 7384) +++ armagetronad/trunk/armagetronad/src/render/rGL.h 2007-11-12 21:02:07 UTC (rev 7385) @@ -1,3 +1,30 @@ +/* + +************************************************************************* + +ArmageTron -- Just another Tron Lightcycle Game in 3D. +Copyright (C) 2006, Armagetron Advanced Development Team + +************************************************************************** + +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 the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*************************************************************************** + +*/ + #ifndef AT_GL_H #define AT_GL_H @@ -7,30 +34,13 @@ #include <windows.h> #endif -#include <SDL_opengl.h> +// GLEW, if active, needs to be included before gl.h +#include "rGLEW.h" -/* -// include OpenGL header -#ifdef HAVE_SDL_OPENGL_H +// and we don't want the SDL extension definitions, they conflict with GLEW. +#define NO_SDL_GLEXT + #include <SDL_opengl.h> -#else -#ifdef HAVE_SDL_SDL_OPENGL_H -#include <SDL/SDL_opengl.h> -#else -#ifdef HAVE_OPENGL_GL_H -#include <OpenGL/gl.h> -#include <OpenGL/glu.h> -#else -#ifdef HAVE_GL_GL_H -#include <GL/gl.h> -#include <GL/glu.h> -#else -#error No suitable OpenGL header found by configure! -#endif -#endif -#endif -#endif -*/ #else @@ -40,4 +50,15 @@ typedef unsigned int GLenum; #endif +#ifndef DEBUG +inline #endif +//! for debugging purposes: checks for OpenGL errors and prints them to the console. +void sr_CheckGLError() +#ifdef DEBUG +; +#else // DEBUG +{} +#endif // DEBUG + +#endif Added: armagetronad/trunk/armagetronad/src/render/rGLEW.h =================================================================== --- armagetronad/trunk/armagetronad/src/render/rGLEW.h (rev 0) +++ armagetronad/trunk/armagetronad/src/render/rGLEW.h 2007-11-12 21:02:07 UTC (rev 7385) @@ -0,0 +1,21 @@ +#ifndef AT_GLEW_H +#define AT_GLEW_H + +#include "aa_config.h" + +// check whether GLEW is available +#ifndef DEDICATED +#ifdef HAVE_GL_GLEW_H +#ifdef HAVE_LIBGLEW + +// it is! define one handy macro indicating so +#define HAVE_GLEW + +// and include the headers +#include <GL/glew.h> + +#endif +#endif +#endif + +#endif Added: armagetronad/trunk/armagetronad/src/render/rGLuintObject.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/render/rGLuintObject.cpp (rev 0) +++ armagetronad/trunk/armagetronad/src/render/rGLuintObject.cpp 2007-11-12 21:02:07 UTC (rev 7385) @@ -0,0 +1,75 @@ +/* + +************************************************************************* + +ArmageTron -- Just another Tron Lightcycle Game in 3D. +Copyright (C) 2006, Armagetron Advanced Development Team + +************************************************************************** + +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 the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*************************************************************************** + +*/ + +#include "rGLuintObject.h" + +// heh, no parameters to document :) + +rGLuintObject::rGLuintObject() + : object_(0) +{ +} + +//! @return the GLUint representing the object, always guaranteed to be valid +rGLuintObject::operator GLuint() +{ + // auto-generate the object + Gen(); + return object_; +} + +//! @return true if the object is currently valid (meaning: Gen() has been called after Delete()) +bool rGLuintObject::IsValid() const +{ + return object_; +} + +rGLuintObject::~rGLuintObject() +{ +} + +void rGLuintObject::Gen() +{ + if ( !object_ ) + { + sr_CheckGLError(); + DoGen(); + sr_CheckGLError(); + } +} + +void rGLuintObject::Delete() +{ + if ( object_ ) + { + sr_CheckGLError(); + DoDelete(); + sr_CheckGLError(); + } + object_ = 0; +} + Added: armagetronad/trunk/armagetronad/src/render/rGLuintObject.h =================================================================== --- armagetronad/trunk/armagetronad/src/render/rGLuintObject.h (rev 0) +++ armagetronad/trunk/armagetronad/src/render/rGLuintObject.h 2007-11-12 21:02:07 UTC (rev 7385) @@ -0,0 +1,106 @@ +/* + +************************************************************************* + +ArmageTron -- Just another Tron Lightcycle Game in 3D. +Copyright (C) 2006, Armagetron Advanced Development Team + +************************************************************************** + +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 the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*************************************************************************** + +*/ + +#ifndef ArmageTron_GLUINTOBJECT_H +#define ArmageTron_GLUINTOBJECT_H + +#include "rGL.h" +#include "tError.h" + +//! safe wrapper for GL objects classifed by GLuints (textures, render buffers) +class rGLuintObject +{ +public: + rGLuintObject(); //!< default constructor + + operator GLuint(); //!< implicit conversion to GLuints, auto-creating the object + bool IsValid() const; //!< checks whether the object is valid + + virtual ~rGLuintObject(); //!< NOTE: the destructor of a derived class needs to call Delete() itself + + void Gen(); //!< reserve the object + void Delete(); //!< free the object +protected: + rGLuintObject( rGLuintObject const & ); //!< forbidden copy construcor + rGLuintObject & operator =( rGLuintObject const & ); //! forbidden copy operator + + GLuint object_; //!< the wrapped "object" +private: + virtual void DoGen() = 0; //!< really reserves the object + virtual void DoDelete() = 0; //!< really frees the object +}; + +//! unusable dummy wrapper +class rGluintObjectDummy: public rGLuintObject +{ +public: + ~rGluintObjectDummy(){ Delete(); } +private: + // the following operations are not supported, wrap your code in #ifdef HAVE_GLEW + virtual void DoGen(){ tASSERT(0); } + virtual void DoDelete(){ tASSERT(0); } +}; + +//! declare safe wrapper classes for GL objects handled by GLuints. +//! argument CLASS: the name of the wrapper class +//! FUNCTION: the name of the functions that hanlde the object; glGen resp. glDelete will be prepended. +#ifndef DEDICATED +#define rDEFINE_GLUINTOBJECT( CLASS, FUNCTION ) \ +class CLASS: public rGLuintObject \ +{ \ +public: \ + ~CLASS(){ Delete(); } \ +private: \ + virtual void DoGen(){ glGen##FUNCTION( 1, &object_ ); } \ + virtual void DoDelete(){ glDelete##FUNCTION( 1, &object_ ); } \ +} +#else // DEDICATED +// safe dummy +#define rDEFINE_GLUINTOBJECT( CLASS, FUNCTION ) typedef rGluintObjectDummy CLASS +#endif + +//! declare safe wrapper classes for GL objects handled by GLuints initialized by extensions +//! argument CLASS: the name of the wrapper class +//! FUNCTION: the name of the functions that hanlde the object; glGen resp. glDelete will be prepended. +#ifdef HAVE_GLEW +#define rDEFINE_GLUINTOBJECT_EXT(CLASS, FUNCTION ) rDEFINE_GLUINTOBJECT( CLASS, FUNCTION ) +#else // HAVE_GLEW, define unusable dummy object +#define rDEFINE_GLUINTOBJECT_EXT( CLASS, FUNCTION ) typedef rGluintObjectDummy CLASS +#endif // HAVE_GLEW + +//! declare safe wrapper for texturs +rDEFINE_GLUINTOBJECT( rGLuintObjectTexture, Textures ); + +//! declare safe wrapper for render buffers +rDEFINE_GLUINTOBJECT_EXT( rGLuintObjectRenderbuffer, RenderbuffersEXT ); + +//! declare safe wrapper for frame buffers +rDEFINE_GLUINTOBJECT_EXT( rGLuintObjectFramebuffer, FramebuffersEXT ); + +#endif + + Modified: armagetronad/trunk/armagetronad/src/render/rSysdep.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/render/rSysdep.cpp 2007-11-12 19:58:37 UTC (rev 7384) +++ armagetronad/trunk/armagetronad/src/render/rSysdep.cpp 2007-11-12 21:02:07 UTC (rev 7385) @@ -27,6 +27,9 @@ #include "defs.h" + +#include "rGL.h" + #ifndef DEDICATED #include "rSDL.h" #endif @@ -39,10 +42,11 @@ #include "aa_config.h" #include <iostream> #include "rScreen.h" -#include "rGL.h" +#include "rTexture.h" #include "tCommandLine.h" #include "tConfiguration.h" #include "tRecorder.h" +#include "rTextureRenderTarget.h" #ifndef DEDICATED #include "SDL_thread.h" @@ -589,11 +593,96 @@ } } -void sr_MotionBlurCore( REAL alpha ) +int NextPowerOfTwo( int in ) { + int x = 1; + while ( x * 32 <= in ) + x <<= 5; + while ( x < in ) + x <<= 1; + + return x; +} + +bool sr_MotionBlurCore( REAL alpha, rTextureRenderTarget & blurTarget ) +{ + sr_CheckGLError(); + if ( alpha < 0 ) alpha = 0; + { + if ( blurTarget.IsTarget() ) + { + blurTarget.Pop(); + + blurTarget.Select(); + + glDrawBuffer( GL_FRONT ); + + sr_CheckGLError(); + + // determine the texture coordinates of the lower right corner + REAL maxu = REAL(sr_screenWidth)/blurTarget.GetWidth(); + REAL maxv = REAL(sr_screenHeight)/blurTarget.GetHeight(); + + glEnable(GL_TEXTURE_2D); + + // blend the last frame and the current frame with the specified alpha value + glDisable( GL_DEPTH_TEST ); + glDepthMask(0); + + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glViewport(0,0,sr_screenWidth, sr_screenHeight); + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, + GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, + GL_NEAREST); + + glDisable(GL_ALPHA_TEST); + // glDisable(GL_BLEND); + glEnable(GL_BLEND); + glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); + + glDisable(GL_LIGHTING); + + glBegin( GL_QUADS ); + glColor4f( 1,1,1,alpha ); + + glTexCoord2f( 0, 0 ); + glVertex2f( -1, -1 ); + + glTexCoord2f( maxu, 0 ); + glVertex2f( 1, -1 ); + + glTexCoord2f( maxu, maxv ); + glVertex2f( 1, 1 ); + + glTexCoord2f( 0, maxv ); + glVertex2f( -1, 1 ); + glEnd(); + + sr_CheckGLError(); + + // clean up + glDepthMask(1); + + glDrawBuffer( GL_BACK ); + } + + blurTarget.Push(); + + sr_CheckGLError(); + + return false; + } + + return true; + #if 0 GLenum error = glGetError(); if ( error != GL_NO_ERROR ) @@ -682,12 +771,12 @@ } // frames from about this far apart get blended together -static REAL sr_motionBlurTime = .01; +static REAL sr_motionBlurTime = .0075; static tSettingItem<REAL> c_mb( "MOTION_BLUR_TIME", sr_motionBlurTime ); // blurs the motion, time is the current time -void sr_MotionBlur( double time ) +bool sr_MotionBlur( double time, std::auto_ptr< rTextureRenderTarget > & blurTarget ) { if ( currentScreensetting.vSync == ArmageTron_VSync_MotionBlur ) { @@ -726,15 +815,43 @@ --hyster; } + lastTime = time; + // really blur. if ( active ) - sr_MotionBlurCore( 1 - frameTime / sr_motionBlurTime ); + { + // determine blur texture size + int blurWidth = NextPowerOfTwo( sr_screenWidth ); + int blurHeight = NextPowerOfTwo( sr_screenHeight ); - lastTime = time; + // destroy existing blur texture if it is too small + if ( blurTarget.get() && ( blurTarget->GetWidth() < blurWidth || blurTarget->GetHeight() < blurHeight ) ) + { + blurTarget = std::auto_ptr< rTextureRenderTarget >(); + } + + // create blur texture + if ( !blurTarget.get() ) + { + blurTarget = std::auto_ptr< rTextureRenderTarget >( new rTextureRenderTarget( blurWidth, blurHeight ) ); + } + + return sr_MotionBlurCore( 1 - frameTime / sr_motionBlurTime, *blurTarget ); + } } + + // no motion blur happened when we got here + if ( blurTarget.get() && blurTarget->IsTarget() ) + { + blurTarget->Pop(); + } + + return true; } void rSysDep::SwapGL(){ + static std::auto_ptr< rTextureRenderTarget > blurTarget(0); + if ( s_benchmark ) { static PerformanceCounter counter; @@ -835,7 +952,7 @@ sr_LockSDL(); // actiate motion blur (does not use the game state, so it's OK to call here ) - sr_MotionBlur( time ); + bool shouldSwap = sr_MotionBlur( time, blurTarget ); switch( swapMode_ ) { @@ -849,22 +966,25 @@ break; } + if ( shouldSwap ) + { #if defined(SDL_OPENGL) - if (lastSuccess.useSDL) - SDL_GL_SwapBuffers(); - //#elif defined(HAVE_FXMESA) - //fxMesaSwapBuffers(); + if (lastSuccess.useSDL) + SDL_GL_SwapBuffers(); + //#elif defined(HAVE_FXMESA) + //fxMesaSwapBuffers(); #endif #ifdef DIRTY - if (!lastSuccess.useSDL){ + if (!lastSuccess.useSDL){ #if defined(WIN32) - SwapBuffers( hDC ); + SwapBuffers( hDC ); #elif defined(unix) || defined(__unix__) - glXSwapBuffers(dpy,win); + glXSwapBuffers(dpy,win); #endif - } + } #endif + } if (sr_screenshotIsPlanned){ make_screenshot(); Modified: armagetronad/trunk/armagetronad/src/render/rTexture.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/render/rTexture.cpp 2007-11-12 19:58:37 UTC (rev 7384) +++ armagetronad/trunk/armagetronad/src/render/rTexture.cpp 2007-11-12 21:02:07 UTC (rev 7385) @@ -426,7 +426,7 @@ // ****************************************************************************************** rISurfaceTexture::rISurfaceTexture( int group, bool repx, bool repy, bool storeAlpha ) - : group_( group ), textureModeLast_( -1), tint_( 0 ), repx_( repx ), repy_( repy ), storeAlpha_( storeAlpha ) + : group_( group ), textureModeLast_( -1), repx_( repx ), repy_( repy ), storeAlpha_( storeAlpha ) { } @@ -441,13 +441,6 @@ rISurfaceTexture::~rISurfaceTexture( void ) { -#ifndef DEDICATED - if (tint_ > 0) - { - glDeleteTextures(1,&tint_); - tint_ = 0; - } -#endif } // ****************************************************************************************** @@ -535,15 +528,12 @@ if(textureModeLast_!=texmod) { // unload texture if the mode changed - if ( tint_ > 0 ) - Unload(); - tASSERT( tint_ == 0 ); + tint_.Delete(); // std::cerr << "loading texture " << fileName << ':' << tint << "\n"; if (texmod>0){ RenderEnd(true); - glGenTextures(1, &tint_); glBindTexture(GL_TEXTURE_2D,tint_); if (textureModeLast_<0) @@ -622,13 +612,7 @@ void rISurfaceTexture::OnUnload( void ) { #ifndef DEDICATED - if (tint_ > 0) - { - // std::cerr << "unloading texture " << fileName << ':' << tint_ << "\n"; - glDeleteTextures(1,&tint_); - tint_ = 0; - } - + tint_.Delete(); textureModeLast_=-100; rITexture::OnUnload(); #endif Modified: armagetronad/trunk/armagetronad/src/render/rTexture.h =================================================================== --- armagetronad/trunk/armagetronad/src/render/rTexture.h 2007-11-12 19:58:37 UTC (rev 7384) +++ armagetronad/trunk/armagetronad/src/render/rTexture.h 2007-11-12 21:02:07 UTC (rev 7385) @@ -31,6 +31,7 @@ #include "tString.h" #include "tList.h" #include "rGL.h" +#include "rGLuintObject.h" struct SDL_Surface; @@ -147,9 +148,9 @@ int textureModeLast_; //!< the last texture storage mode this texture was used with - GLuint tint_; //!< the OpenGL id of this texture - bool repx_,repy_; //!< flags indicating whether the texture repeats in x and y direction - bool storeAlpha_; //!< flag indicating whether the alpha value should be stored + rGLuintObjectTexture tint_; //!< the OpenGL id of this texture + bool repx_,repy_; //!< flags indicating whether the texture repeats in x and y direction + bool storeAlpha_; //!< flag indicating whether the alpha value should be stored }; // ****************************************************************************************** Added: armagetronad/trunk/armagetronad/src/render/rTextureRenderTarget.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/render/rTextureRenderTarget.cpp (rev 0) +++ armagetronad/trunk/armagetronad/src/render/rTextureRenderTarget.cpp 2007-11-12 21:02:07 UTC (rev 7385) @@ -0,0 +1,154 @@ +/* + +************************************************************************* + +ArmageTron -- Just another Tron Lightcycle Game in 3D. +Copyright (C) 2006, Armagetron Advanced Development Team + +************************************************************************** + +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 the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*************************************************************************** + +*/ + +#include "rTextureRenderTarget.h" + +// implementation +#include "rScreen.h" +#include "tException.h" + +rTextureRenderTarget * rTextureRenderTarget::anchor = 0; + +// **************************************************************** +// * +// * rTextureRenderTarget +// * +// **************************************************************** +//! +//! @param +//! @return +//! +// **************************************************************** + +//! texture that can be used as a target for rendering + +// clears the texture +void rTextureRenderTarget::Clear() +{ + tASSERT( !IsTarget() ); + + texture_.Delete(); + depthBuffer_.Delete(); + frameBuffer_.Delete(); +} + +rTextureRenderTarget::~rTextureRenderTarget() +{ + if ( IsTarget() ) + { + Pop(); + } + + Clear(); +} + +rTextureRenderTarget::rTextureRenderTarget( int width, int height ) +{ + sr_CheckGLError(); + + width_ = width; + height_ = height; + previous = 0; + + if ( GLEW_EXT_framebuffer_object ) + { + Push(); + sr_CheckGLError(); + + // generate texture + glBindTexture( GL_TEXTURE_2D, texture_ ); + sr_CheckGLError(); + + // make texture + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ); + sr_CheckGLError(); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + + glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texture_, 0 ); + sr_CheckGLError(); + + glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, depthBuffer_ ); + sr_CheckGLError(); + + glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT32, width, height ); + sr_CheckGLError(); + + glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuffer_ ); + sr_CheckGLError(); + + GLenum status = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT); + switch( status ) + { + case GL_FRAMEBUFFER_COMPLETE_EXT: + break; + case GL_FRAMEBUFFER_UNSUPPORTED_EXT: + throw tGenericException( "Unsupported frame buffer operation" ); + default: + tASSERT( 0 ); + } + + sr_CheckGLError(); + + Pop(); + + return; + } + + throw tGenericException( "frame buffer extension not supported" ); +} + +void rTextureRenderTarget::Push() +{ + previous = anchor; + anchor = this; + + sr_CheckGLError(); + + glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, frameBuffer_ ); + + sr_CheckGLError(); +} + +void rTextureRenderTarget::Pop() +{ + tASSERT( IsTarget() ); + + sr_CheckGLError(); + glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, previous ? previous->frameBuffer_ : 0 ); + sr_CheckGLError(); + + anchor = previous; +} + +void rTextureRenderTarget::OnSelect(bool) +{ + glBindTexture( GL_TEXTURE_2D, texture_ ); +} Added: armagetronad/trunk/armagetronad/src/render/rTextureRenderTarget.h =================================================================== --- armagetronad/trunk/armagetronad/src/render/rTextureRenderTarget.h (rev 0) +++ armagetronad/trunk/armagetronad/src/render/rTextureRenderTarget.h 2007-11-12 21:02:07 UTC (rev 7385) @@ -0,0 +1,88 @@ +/* + +************************************************************************* + +ArmageTron -- Just another Tron Lightcycle Game in 3D. +Copyright (C) 2006, Armagetron Advanced Development Team + +************************************************************************** + +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 the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*************************************************************************** + +*/ + +#ifndef ArmageTron_TEXTURERENDERTARGET_H +#define ArmageTron_TEXTURERENDERTARGET_H + +#include "rGLEW.h" +#include "rTexture.h" +#include "rGLuintObject.h" + +//! texture that can be used as a target for rendering +class rTextureRenderTarget: public rITexture +{ +public: + //! clears the texture + void Clear(); + + ~rTextureRenderTarget(); + + //! creates a render target texture of the specified dimensions + rTextureRenderTarget( int width, int height ); + + //! makes this texture the active render target + void Push(); + + //! removes this texture as the active render target + void Pop(); + + bool IsTarget() const + { + return anchor == this; + } + + int GetHeight() const + { + return height_; + } + + int GetWidth() const + { + return width_; + } +protected: + virtual void OnSelect(bool); + + // nothing special to do here + virtual void OnUnload(){} +private: + rGLuintObjectTexture texture_; //!< the texture render target + rGLuintObjectRenderbuffer depthBuffer_; //!< the depth buffer + rGLuintObjectFramebuffer frameBuffer_; //!< the frame buffer + + + static rTextureRenderTarget * anchor; + rTextureRenderTarget * previous; + + int width_, height_; + GLenum colorMode, depthMode; +public: +}; + +#endif + + Modified: armagetronad/trunk/armagetronad/src/tron/gArmagetron.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/tron/gArmagetron.cpp 2007-11-12 19:58:37 UTC (rev 7384) +++ armagetronad/trunk/armagetronad/src/tron/gArmagetron.cpp 2007-11-12 21:02:07 UTC (rev 7385) @@ -682,6 +682,19 @@ try { +#ifdef HAVE_GLEW + // initialize GLEW + { + GLenum err = glewInit(); + if (GLEW_OK != err) + { + // Problem: glewInit failed, something is seriously wrong + throw tGenericException( (const char *)glewGetErrorString(err), "GLEW Error" ); + } + con << "Status: Using GLEW " << glewGetString(GLEW_VERSION) << "\n"; + } +#endif // HAVE_GLEW + //std::cout << "init disp\n"; //std::cout << "init sound\n"; Modified: armagetronad/trunk/armagetronad/src/tron/gWall.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/tron/gWall.cpp 2007-11-12 19:58:37 UTC (rev 7384) +++ armagetronad/trunk/armagetronad/src/tron/gWall.cpp 2007-11-12 21:02:07 UTC (rev 7385) @@ -881,10 +881,12 @@ } #endif + sr_CheckGLError(); if (displayList_ && cycle_->Alive() && list) glCallList(displayList_); else { + sr_CheckGLError(); dir_eWall_select(); REAL r,g,b; @@ -981,24 +983,31 @@ glEndList(); } else */ + sr_CheckGLError(); RenderNormal(p1,p2,ta,te,r,g,b,a); + sr_CheckGLError(); } else{ // complicated if (ta+gBEG_LEN>=time){ + sr_CheckGLError(); RenderBegin(p1,p2,ta,te, 1+(ta-time)/gBEG_LEN, 1+(te-time)/gBEG_LEN, r,g,b,a); + sr_CheckGLError(); } else{ + sr_CheckGLError(); REAL s=((time-gBEG_LEN)-ta)/(te-ta); eCoord pm=p1+(p2-p1)*s; RenderBegin(pm,p2, ta+(te-ta)*s,te,0, 1+(te-time)/gBEG_LEN, r,g,b,a); + sr_CheckGLError(); RenderNormal(p1,pm,ta,ta+(te-ta)*s,r,g,b,a); + sr_CheckGLError(); } } } @@ -1007,6 +1016,7 @@ bool upperlinecolor(REAL r,REAL g,REAL b, REAL a){ + sr_CheckGLError(); if (rTextureGroups::TextureMode[rTextureGroups::TEX_WALL]<0) glColor4f(1,1,1,a); else{ @@ -1021,8 +1031,11 @@ */ //glDisable(GL_TEXTURE); glDisable(GL_TEXTURE_2D); + sr_CheckGLError(); glColor4f(r,g,b,a); } + + sr_CheckGLError(); return true; } @@ -1146,11 +1159,14 @@ eCoord ppos=cycle_->PredictPosition() - cycle_->dir*REAL(gCYCLE_LEN); if ( hfrac>0 ){ + sr_CheckGLError(); sr_DepthOffset(true); + sr_CheckGLError(); //REAL H=h*hfrac; #define segs 5 upperlinecolor(r,g,b,a);//a*afunc(rat)); BeginLineStrip(); + sr_CheckGLError(); for(int i=0;i<=segs;i++){ REAL frag=i/float(segs); @@ -1160,17 +1176,22 @@ REAL H=h*hfrac*hfunc(rat); upperlinecolor(r,g,b,a*afunc(rat)); + sr_CheckGLError(); glVertex3f(x+H*cycle_->skew*sfunc(rat)*cycle_->dir.y, y-H*cycle_->skew*sfunc(rat)*cycle_->dir.x, H);//+se_cameraZ*.005); + sr_CheckGLError(); } RenderEnd(); + sr_CheckGLError(); sr_DepthOffset(false); + sr_CheckGLError(); } dir_eWall_select(); + sr_CheckGLError(); BeginQuadStrip(); @@ -1186,22 +1207,30 @@ REAL y=(p1.y+frag*(p2.y-p1.y))*(1-xfunc(rat))+ppos.y*xfunc(rat); // bottom - glEdgeFlag(GL_FALSE); + sr_CheckGLError(); + glEdgeFlag(GL_FALSE); glColor4f(r+cfunc(rat),g+cfunc(rat),b+cfunc(rat),a*afunc(rat)); + sr_CheckGLError(); glTexCoord2f(ta+(te-ta)*frag,hfrac); + sr_CheckGLError(); glVertex3f(x,y,0); + sr_CheckGLError(); // top glEdgeFlag(GL_TRUE); //glTexCoord2f(ta+(te-ta)*frag,hfrac*(1-hfunc(rat))); + sr_CheckGLError(); glTexCoord2f(ta+(te-ta)*frag,0); + sr_CheckGLError(); REAL H=h*hfrac*hfunc(rat); glVertex3f(x+H*cycle_->skew*sfunc(rat)*cycle_->dir.y, y-H*cycle_->skew*sfunc(rat)*cycle_->dir.x, H); + sr_CheckGLError(); } RenderEnd(); + sr_CheckGLError(); } #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |