From d821c4f1b534a3d7b4998433f3c146c20ea72bab Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 7 Apr 2003 00:54:32 +0000 Subject: [PATCH] add LowLevelWindow --- stepmania/src/RageDisplay.cpp | 128 ++++-------------- stepmania/src/StepMania.dsp | 26 +++- stepmania/src/StepMania.vcproj | 13 ++ .../src/arch/LowLevelWindow/LowLevelWindow.h | 30 ++++ .../LowLevelWindow/LowLevelWindow_SDL.cpp | 106 +++++++++++++++ .../arch/LowLevelWindow/LowLevelWindow_SDL.h | 27 ++++ stepmania/src/arch/arch.cpp | 1 + stepmania/src/arch/arch.h | 2 + stepmania/src/arch/arch_default.h | 2 + 9 files changed, 232 insertions(+), 103 deletions(-) create mode 100644 stepmania/src/arch/LowLevelWindow/LowLevelWindow.h create mode 100644 stepmania/src/arch/LowLevelWindow/LowLevelWindow_SDL.cpp create mode 100644 stepmania/src/arch/LowLevelWindow/LowLevelWindow_SDL.h diff --git a/stepmania/src/RageDisplay.cpp b/stepmania/src/RageDisplay.cpp index 59637f9827..db769bee5f 100644 --- a/stepmania/src/RageDisplay.cpp +++ b/stepmania/src/RageDisplay.cpp @@ -24,6 +24,9 @@ #include "GameConstantsAndTypes.h" #include "StepMania.h" +#include "arch/arch.h" +#include "arch/LowLevelWindow/LowLevelWindow.h" + #include RageDisplay* DISPLAY = NULL; @@ -31,15 +34,12 @@ RageDisplay* DISPLAY = NULL; //////////// // Globals //////////// -bool g_Windowed; -GLenum g_vertMode = GL_TRIANGLES; RageTimer g_LastCheckTimer; int g_iNumVerts; int g_iFPS, g_iVPF, g_iCFPS; int g_PerspectiveMode = 0; -int g_CurrentHeight, g_CurrentWidth, g_CurrentBPP; int g_ModelMatrixCnt=0; int RageDisplay::GetFPS() const { return g_iFPS; } int RageDisplay::GetVPF() const { return g_iVPF; } @@ -58,6 +58,9 @@ PFNGLCOLORTABLEPARAMETERIVPROC GLExt::glGetColorTableParameterivEXT; * no GL_T2F_C4F_V3F. */ const GLenum RageVertexFormat = GL_T2F_C4F_N3F_V3F; + +LowLevelWindow *wind; + void GetGLExtensions(set &ext) { const char *buf = (const char *)glGetString(GL_EXTENSIONS); @@ -74,7 +77,9 @@ RageDisplay::RageDisplay( bool windowed, int width, int height, int bpp, int rat LOG->Trace( "RageDisplay::RageDisplay()" ); m_oglspecs = new oglspecs_t; - + + wind = MakeLowLevelWindow(); + SetVideoMode( windowed, width, height, bpp, rate, vsync ); // Log driver details @@ -158,7 +163,7 @@ void RageDisplay::SetupOpenGL() RageDisplay::~RageDisplay() { - SDL_QuitSubSystem(SDL_INIT_VIDEO); + delete wind; delete m_oglspecs; } @@ -179,9 +184,9 @@ void RageDisplay::SetupExtensions() m_oglspecs->EXT_paletted_texture = HasExtension("GL_EXT_paletted_texture"); /* Find extension functions. */ - GLExt::wglSwapIntervalEXT = (PWSWAPINTERVALEXTPROC) SDL_GL_GetProcAddress("wglSwapIntervalEXT"); - GLExt::glColorTableEXT = (PFNGLCOLORTABLEPROC) SDL_GL_GetProcAddress("glColorTableEXT"); - GLExt::glGetColorTableParameterivEXT = (PFNGLCOLORTABLEPARAMETERIVPROC) SDL_GL_GetProcAddress("glGetColorTableParameterivEXT"); + GLExt::wglSwapIntervalEXT = (PWSWAPINTERVALEXTPROC) wind->GetProcAddress("wglSwapIntervalEXT"); + GLExt::glColorTableEXT = (PFNGLCOLORTABLEPROC) wind->GetProcAddress("glColorTableEXT"); + GLExt::glGetColorTableParameterivEXT = (PFNGLCOLORTABLEPARAMETERIVPROC) wind->GetProcAddress("glGetColorTableParameterivEXT"); /* Make sure we have all components for detected extensions. */ if(m_oglspecs->WGL_EXT_swap_control) @@ -207,82 +212,14 @@ void RageDisplay::SetupExtensions() bool RageDisplay::SetVideoMode( bool windowed, int width, int height, int bpp, int rate, bool vsync ) { // LOG->Trace( "RageDisplay::SetVideoMode( %d, %d, %d, %d, %d, %d )", windowed, width, height, bpp, rate, vsync ); - if(!SDL_WasInit(SDL_INIT_VIDEO)) - SDL_InitSubSystem(SDL_INIT_VIDEO); + bool NewOpenGLContext = wind->SetVideoMode( windowed, width, height, bpp, rate, vsync ); - int flags = 0; - if( !windowed ) - flags |= SDL_FULLSCREEN; - flags |= SDL_DOUBLEBUF; - flags |= SDL_RESIZABLE; - flags |= SDL_OPENGL; - - g_Windowed = windowed; - SDL_ShowCursor( g_Windowed ); - - ASSERT( bpp == 16 || bpp == 32 ); - switch( bpp ) + if(NewOpenGLContext) { - case 16: - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); - break; - case 32: - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); - } - - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, true); - -#ifdef SDL_HAS_REFRESH_RATE - if(rate == REFRESH_DEFAULT) - SDL_SM_SetRefreshRate(0); - else - SDL_SM_SetRefreshRate(rate); -#endif - - bool NewOpenGLContext = false; - - SDL_Surface *screen = SDL_SetVideoMode(width, height, bpp, flags); - if(!screen) - RageException::Throw("SDL_SetVideoMode failed: %s", SDL_GetError()); - - /* XXX: This event only exists in the SDL tree, and is only needed in - * Windows. Eventually, it'll probably get upstreamed, and once it's - * in the real branch we can remove this #if. */ -#if defined(WIN32) - SDL_Event e; - if(SDL_PeepEvents(&e, 1, SDL_GETEVENT, SDL_OPENGLRESETMASK)) - { - LOG->Trace("New OpenGL context"); - /* We have a new OpenGL context, so we have to tell our textures that * their OpenGL texture number is invalid. */ if(TEXTUREMAN) TEXTUREMAN->InvalidateTextures(); - - SDL_WM_SetCaption("StepMania", "StepMania"); - - NewOpenGLContext = true; - } -#endif - - { - /* Find out what we really got. */ - int r,g,b,a, colorbits, depth, stencil; - - SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &r); - SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &g); - SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &b); - SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &a); - SDL_GL_GetAttribute(SDL_GL_BUFFER_SIZE, &colorbits); - SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &depth); - SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencil); - LOG->Info("Got %i bpp (%i%i%i%i), %i depth, %i stencil", - colorbits, r, g, b, a, depth, stencil); } SetupOpenGL(); @@ -298,10 +235,6 @@ bool RageDisplay::SetVideoMode( bool windowed, int width, int height, int bpp, i GLExt::wglSwapIntervalEXT(vsync); } - g_CurrentWidth = screen->w; - g_CurrentHeight = screen->h; - g_CurrentBPP = bpp; - SetViewport(0,0); /* Clear any junk that's in the framebuffer. */ @@ -377,8 +310,7 @@ void RageDisplay::DumpOpenGLDebugInfo() void RageDisplay::ResolutionChanged(int width, int height) { - g_CurrentWidth = width; - g_CurrentHeight = height; + wind->ResolutionChanged(width, height); SetViewport(0,0); @@ -391,10 +323,10 @@ void RageDisplay::SetViewport(int shift_left, int shift_down) { /* left and down are on a 0..SCREEN_WIDTH, 0..SCREEN_HEIGHT scale. * Scale them to the actual viewport range. */ - shift_left = int( shift_left * float(g_CurrentWidth) / SCREEN_WIDTH ); - shift_down = int( shift_down * float(g_CurrentWidth) / SCREEN_WIDTH ); + shift_left = int( shift_left * float(wind->GetWidth()) / SCREEN_WIDTH ); + shift_down = int( shift_down * float(wind->GetWidth()) / SCREEN_WIDTH ); - glViewport(shift_left, -shift_down, g_CurrentWidth, g_CurrentHeight); + glViewport(shift_left, -shift_down, wind->GetWidth(), wind->GetHeight()); } int RageDisplay::GetMaxTextureSize() const @@ -412,7 +344,7 @@ void RageDisplay::Clear() void RageDisplay::Flip() { - SDL_GL_SwapBuffers(); + wind->SwapBuffers(); g_iFramesRenderedSinceLastCheck++; g_iFramesRenderedSinceLastReset++; @@ -454,21 +386,21 @@ void RageDisplay::SaveScreenshot( CString sPath ) ASSERT( sPath.Right(3).CompareNoCase("bmp") == 0 ); // we can only save bitmaps SDL_Surface *image = SDL_CreateRGBSurface( - SDL_SWSURFACE, g_CurrentWidth, g_CurrentHeight, + SDL_SWSURFACE, wind->GetWidth(), wind->GetHeight(), 24, 0x0000FF, 0x00FF00, 0xFF0000, 0x000000); SDL_Surface *temp = SDL_CreateRGBSurface( - SDL_SWSURFACE, g_CurrentWidth, g_CurrentHeight, + SDL_SWSURFACE, wind->GetWidth(), wind->GetHeight(), 24, 0x0000FF, 0x00FF00, 0xFF0000, 0x000000); - glReadPixels(0, 0, g_CurrentWidth, g_CurrentHeight, GL_RGB, + glReadPixels(0, 0, wind->GetWidth(), wind->GetHeight(), GL_RGB, GL_UNSIGNED_BYTE, image->pixels); // flip vertically - for( int y=0; yGetHeight(); y++ ) memcpy( - (char *)temp->pixels + 3 * g_CurrentWidth * y, - (char *)image->pixels + 3 * g_CurrentWidth * (g_CurrentHeight-1-y), - 3*g_CurrentWidth ); + (char *)temp->pixels + 3 * wind->GetWidth() * y, + (char *)image->pixels + 3 * wind->GetWidth() * (wind->GetHeight()-1-y), + 3*wind->GetWidth() ); SDL_SaveBMP( temp, sPath ); @@ -479,7 +411,7 @@ void RageDisplay::SaveScreenshot( CString sPath ) bool RageDisplay::IsWindowed() const { - return g_Windowed; + return wind->IsWindowed(); } void RageDisplay::DrawQuad( const RageVertex v[4] ) // upper-left, upper-right, lower-right, lower-left @@ -582,8 +514,8 @@ void RageDisplay::DrawLoop_LinesAndPoints( const RageVertex v[], int iNumVerts, /* Our line width is wrt the regular internal SCREEN_WIDTHxSCREEN_HEIGHT screen, * but these width functions actually want raster sizes (that is, actual pixels). * Scale the line width and point size by the average ratio of the scale. */ - float WidthVal = float(g_CurrentWidth) / SCREEN_WIDTH; - float HeightVal = float(g_CurrentHeight) / SCREEN_HEIGHT; + float WidthVal = float(wind->GetWidth()) / SCREEN_WIDTH; + float HeightVal = float(wind->GetHeight()) / SCREEN_HEIGHT; LineWidth *= (WidthVal + HeightVal) / 2; /* Clamp the width to the hardware max for both lines and points (whichever diff --git a/stepmania/src/StepMania.dsp b/stepmania/src/StepMania.dsp index bfe467337f..6b3df0f1dc 100644 --- a/stepmania/src/StepMania.dsp +++ b/stepmania/src/StepMania.dsp @@ -1,5 +1,5 @@ # Microsoft Developer Studio Project File - Name="StepMania" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 60000 +# Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Application" 0x0101 @@ -57,10 +57,10 @@ LINK32=link.exe # SUBTRACT LINK32 /verbose /pdb:none # Begin Special Build Tool IntDir=.\../Release6 -TargetDir=\stepmania\stepmania +TargetDir=\temp\stepmania TargetName=StepMania SOURCE="$(InputPath)" -PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ +PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi # End Special Build Tool @@ -92,10 +92,10 @@ LINK32=link.exe # SUBTRACT LINK32 /verbose /profile /pdb:none /incremental:no /nodefaultlib # Begin Special Build Tool IntDir=.\../Debug6 -TargetDir=\stepmania\stepmania +TargetDir=\temp\stepmania TargetName=StepMania-debug SOURCE="$(InputPath)" -PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ +PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi # End Special Build Tool @@ -752,6 +752,22 @@ SOURCE=.\arch\MovieTexture\MovieTexture_DShowHelper.cpp SOURCE=.\arch\MovieTexture\MovieTexture_DShowHelper.h # End Source File # End Group +# Begin Group "LowLevelWindow" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\arch\LowLevelWindow\LowLevelWindow.h +# End Source File +# Begin Source File + +SOURCE=.\arch\LowLevelWindow\LowLevelWindow_SDL.cpp +# End Source File +# Begin Source File + +SOURCE=.\arch\LowLevelWindow\LowLevelWindow_SDL.h +# End Source File +# End Group # Begin Source File SOURCE=.\arch\arch.cpp diff --git a/stepmania/src/StepMania.vcproj b/stepmania/src/StepMania.vcproj index 97625f970b..8d0d4695d0 100644 --- a/stepmania/src/StepMania.vcproj +++ b/stepmania/src/StepMania.vcproj @@ -898,6 +898,19 @@ cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ RelativePath="arch\MovieTexture\MovieTexture_DShowHelper.h"> + + + + + + + + Trace("New OpenGL context"); + + SDL_WM_SetCaption("StepMania", "StepMania"); + + NewOpenGLContext = true; + } +#endif + + { + /* Find out what we really got. */ + int r,g,b,a, colorbits, depth, stencil; + + SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &r); + SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &g); + SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &b); + SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &a); + SDL_GL_GetAttribute(SDL_GL_BUFFER_SIZE, &colorbits); + SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &depth); + SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencil); + LOG->Info("Got %i bpp (%i%i%i%i), %i depth, %i stencil", + colorbits, r, g, b, a, depth, stencil); + } + + CurrentWidth = screen->w; + CurrentHeight = screen->h; + CurrentBPP = bpp; + + return NewOpenGLContext; +} + +void LowLevelWindow_SDL::SwapBuffers() +{ + SDL_GL_SwapBuffers(); +} diff --git a/stepmania/src/arch/LowLevelWindow/LowLevelWindow_SDL.h b/stepmania/src/arch/LowLevelWindow/LowLevelWindow_SDL.h new file mode 100644 index 0000000000..db6563a964 --- /dev/null +++ b/stepmania/src/arch/LowLevelWindow/LowLevelWindow_SDL.h @@ -0,0 +1,27 @@ +#ifndef LOW_LEVEL_WINDOW_SDL_H +#define LOW_LEVEL_WINDOW_SDL_H + +#include "LowLevelWindow.h" + +class LowLevelWindow_SDL: public LowLevelWindow +{ + bool Windowed; + int CurrentHeight, CurrentWidth, CurrentBPP; + +public: + LowLevelWindow_SDL(); + ~LowLevelWindow_SDL(); + void *GetProcAddress(CString s); + bool SetVideoMode( bool windowed, int width, int height, int bpp, int rate, bool vsync ); + void SwapBuffers(); + void ResolutionChanged(int width, int height) { CurrentWidth = width; CurrentHeight = height; } + + bool IsWindowed() const { return Windowed; } + int GetWidth() const { return CurrentWidth; } + int GetHeight() const { return CurrentHeight; } + int GetBPP() const { return CurrentBPP; } +}; +#undef ARCH_LOW_LEVEL_WINDOW +#define ARCH_LOW_LEVEL_WINDOW LowLevelWindow_SDL + +#endif diff --git a/stepmania/src/arch/arch.cpp b/stepmania/src/arch/arch.cpp index 5e3c9319b9..0ba296e6a5 100644 --- a/stepmania/src/arch/arch.cpp +++ b/stepmania/src/arch/arch.cpp @@ -23,6 +23,7 @@ LoadingWindow *MakeLoadingWindow() { return new ARCH_LOADING_WINDOW; } ErrorDialog *MakeErrorDialog() { return new ARCH_ERROR_DIALOG; } ArchHooks *MakeArchHooks() { return new ARCH_HOOKS; } +LowLevelWindow *MakeLowLevelWindow() { return new ARCH_LOW_LEVEL_WINDOW; } void MakeInputHandlers(vector &Add) { diff --git a/stepmania/src/arch/arch.h b/stepmania/src/arch/arch.h index cd63afee92..7b1329af20 100644 --- a/stepmania/src/arch/arch.h +++ b/stepmania/src/arch/arch.h @@ -7,10 +7,12 @@ class LoadingWindow; class RageSoundDriver; class ArchHooks; class InputHandler; +class LowLevelWindow; ErrorDialog *MakeErrorDialog(); LoadingWindow *MakeLoadingWindow(); ArchHooks *MakeArchHooks(); +LowLevelWindow *MakeLowLevelWindow(); void MakeInputHandlers(vector &Add); RageSoundDriver *MakeRageSoundDriver(CString drivers); diff --git a/stepmania/src/arch/arch_default.h b/stepmania/src/arch/arch_default.h index 6cf36b78cc..17ee7dd094 100644 --- a/stepmania/src/arch/arch_default.h +++ b/stepmania/src/arch/arch_default.h @@ -6,9 +6,11 @@ /* Load default fallback drivers; some of these may be overridden by arch-specific drivers. */ #include "LoadingWindow/LoadingWindow_SDL.h" +/* XXX: null, none, Null--pick one */ #include "ErrorDialog/ErrorDialog_null.h" #include "ArchHooks/ArchHooks_none.h" #include "Sound/RageSoundDriver_Null.h" +#include "LowLevelWindow/LowLevelWindow_SDL.h" #endif