From 55bda985589d02225d9045fd321367009558597d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Brammer?= Date: Sun, 31 May 2009 02:09:15 +0200 Subject: [PATCH] OpenGL: Remove duplication and Direct3d stuff --- standard/inc/StdDDraw2.h | 2 -- standard/inc/StdGL.h | 3 +- standard/src/StdGL.cpp | 52 +++++++++++------------------- standard/src/StdGLCtx.cpp | 68 ++++++++++++++------------------------- 4 files changed, 44 insertions(+), 81 deletions(-) diff --git a/standard/inc/StdDDraw2.h b/standard/inc/StdDDraw2.h index e61ecb9d5..31f9922b1 100644 --- a/standard/inc/StdDDraw2.h +++ b/standard/inc/StdDDraw2.h @@ -356,10 +356,8 @@ class CStdDDraw virtual bool RestoreStateBlock() = 0; // device objects - virtual bool InitDeviceObjects() = 0; // init device dependant objects virtual bool RestoreDeviceObjects() = 0; // restore device dependant objects virtual bool InvalidateDeviceObjects() = 0; // free device dependant objects - virtual bool DeleteDeviceObjects() = 0; // free device dependant objects virtual bool DeviceReady() = 0; // return whether device exists int GetByteCnt() { return byByteCnt; } // return bytes per pixel diff --git a/standard/inc/StdGL.h b/standard/inc/StdGL.h index 3fc1fada1..b71d9e5fa 100644 --- a/standard/inc/StdGL.h +++ b/standard/inc/StdGL.h @@ -60,6 +60,7 @@ class CStdGLCtx bool PageFlip(); // present scene protected: + void SelectCommon(); // this handles are declared as pointers to structs CStdWindow * pWindow; // window to draw in #ifdef _WIN32 @@ -127,10 +128,8 @@ class CStdGL : public CStdDDraw virtual bool ApplyGammaRamp(D3DGAMMARAMP &ramp, bool fForce); virtual bool SaveDefaultGammaRamp(CStdWindow * pWindow); // device objects - bool InitDeviceObjects(); // init device dependent objects bool RestoreDeviceObjects(); // restore device dependent objects bool InvalidateDeviceObjects(); // free device dependent objects - bool DeleteDeviceObjects(); // free device dependent objects bool StoreStateBlock(); void SetTexture(); void ResetTexture(); diff --git a/standard/src/StdGL.cpp b/standard/src/StdGL.cpp index d539a8c45..da111f689 100644 --- a/standard/src/StdGL.cpp +++ b/standard/src/StdGL.cpp @@ -67,7 +67,14 @@ void CStdGL::Clear() #endif NoPrimaryClipper(); if (pTexMgr) pTexMgr->IntUnlock(); - DeleteDeviceObjects(); + InvalidateDeviceObjects(); + NoPrimaryClipper(); + // del main surfaces + if (lpPrimary) delete lpPrimary; + lpPrimary = lpBack = NULL; + RenderTarget = NULL; + // clear context + if (pCurrCtx) pCurrCtx->Deselect(); MainCtx.Clear(); pCurrCtx=NULL; #ifndef USE_SDL_MAINLOOP @@ -648,8 +655,17 @@ bool CStdGL::CreatePrimarySurfaces(BOOL Playermode, unsigned int iXRes, unsigned // create+select gl context if (!MainCtx.Init(pApp->pWindow, pApp)) return Error(" gl: Error initializing context"); - // done, init device stuff - return InitDeviceObjects(); + // BGRA Pixel Formats, Multitexturing, Texture Combine Environment Modes + if (!GLEW_VERSION_1_3) + { + return Error(" gl: OpenGL Version 1.3 or higher required."); + } + MaxTexSize = 64; + GLint s = 0; + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &s); + if (s>0) MaxTexSize = s; + + return RestoreDeviceObjects(); } void CStdGL::DrawQuadDw(SURFACE sfcTarget, float *ipVtx, DWORD dwClr1, DWORD dwClr2, DWORD dwClr3, DWORD dwClr4) @@ -754,21 +770,6 @@ void CStdGL::PerformPix(SURFACE sfcTarget, float tx, float ty, DWORD dwClr) } } -bool CStdGL::InitDeviceObjects() - { - // BGRA Pixel Formats, Multitexturing, Texture Combine Environment Modes - if (!GLEW_VERSION_1_3) - { - Log(" gl: OpenGL Version 1.3 or higher required."); - return false; - } - MaxTexSize = 64; - GLint s = 0; - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &s); - if (s>0) MaxTexSize = s; - return RestoreDeviceObjects(); - } - static void DefineShaderARB(const char * p, GLuint & s) { glBindProgramARB (GL_FRAGMENT_PROGRAM_ARB, s); @@ -941,21 +942,6 @@ bool CStdGL::CheckGLError(const char *szAtOp) CStdGL *pGL=NULL; -bool CStdGL::DeleteDeviceObjects() - { - InvalidateDeviceObjects(); - NoPrimaryClipper(); - // del font objects - // del main surfaces - if (lpPrimary) delete lpPrimary; - lpPrimary=lpBack=NULL; - RenderTarget=NULL; - // clear context - if (pCurrCtx) pCurrCtx->Deselect(); - MainCtx.Clear(); - return true; - } - void CStdGL::TaskOut() { // deactivate diff --git a/standard/src/StdGLCtx.cpp b/standard/src/StdGLCtx.cpp index 9c45f164d..facd7aa0a 100644 --- a/standard/src/StdGLCtx.cpp +++ b/standard/src/StdGLCtx.cpp @@ -23,6 +23,25 @@ #include #ifdef USE_GL + +void CStdGLCtx::SelectCommon() + { + pGL->pCurrCtx = this; + // update size + UpdateSize(); + // assign size + pGL->lpPrimary->Wdt=cx; pGL->lpPrimary->Hgt=cy; + // set some default states + glDisable(GL_DEPTH_TEST); + glShadeModel(GL_FLAT); + glDisable(GL_ALPHA_TEST); + glDisable(GL_CULL_FACE); + glEnable(GL_BLEND); + //glEnable(GL_LINE_SMOOTH); + //glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); + //glEnable(GL_POINT_SMOOTH); + } + #ifdef _WIN32 CStdGLCtx::CStdGLCtx(): hrc(0), pWindow(0), hDC(0), cx(0), cy(0) { } @@ -106,20 +125,7 @@ bool CStdGLCtx::Select(bool verbose) if (!pGL || !hrc) return false; if (!pGL->lpPrimary) return false; // make context current if (!wglMakeCurrent (hDC, hrc)) return false; - pGL->pCurrCtx = this; - // update size - UpdateSize(); - // assign size - pGL->lpPrimary->Wdt=cx; pGL->lpPrimary->Hgt=cy; - // set some default states - glDisable(GL_DEPTH_TEST); - glShadeModel(GL_FLAT); - glDisable(GL_ALPHA_TEST); - glDisable(GL_CULL_FACE); - glEnable(GL_BLEND); - //glEnable(GL_LINE_SMOOTH); - //glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); - //glEnable(GL_POINT_SMOOTH); + SelectCommon(); // update clipper - might have been done by UpdateSize // however, the wrong size might have been assumed if (!pGL->UpdateClipper()) return false; @@ -251,20 +257,7 @@ bool CStdGLCtx::Select(bool verbose) if (verbose) pGL->Error(" gl: glXMakeCurrent failed"); return false; } - pGL->pCurrCtx = this; - // update size FIXME: Don't call this every frame - UpdateSize(); - // assign size - pGL->lpPrimary->Wdt=cx; pGL->lpPrimary->Hgt=cy; - // set some default states - glDisable(GL_DEPTH_TEST); - glShadeModel(GL_FLAT); - glDisable(GL_ALPHA_TEST); - glDisable(GL_CULL_FACE); - glEnable(GL_BLEND); - //glEnable(GL_LINE_SMOOTH); - //glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); - //glEnable(GL_POINT_SMOOTH); + SelectCommon(); // update clipper - might have been done by UpdateSize // however, the wrong size might have been assumed if (!pGL->UpdateClipper()) @@ -378,27 +371,14 @@ bool CStdGLCtx::Init(CStdWindow * pWindow, CStdApp *) bool CStdGLCtx::Select(bool verbose) { - pGL->pCurrCtx = this; - // update size FIXME: Don't call this every frame - UpdateSize(); - // assign size - pGL->lpPrimary->Wdt=cx; pGL->lpPrimary->Hgt=cy; - // set some default states - glDisable(GL_DEPTH_TEST); - glShadeModel(GL_FLAT); - glDisable(GL_ALPHA_TEST); - glDisable(GL_CULL_FACE); - glEnable(GL_BLEND); - //glEnable(GL_LINE_SMOOTH); - //glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); - //glEnable(GL_POINT_SMOOTH); + SelectCommon(); // update clipper - might have been done by UpdateSize // however, the wrong size might have been assumed if (!pGL->UpdateClipper()) - { + { if (verbose) pGL->Error(" gl: UpdateClipper failed"); return false; - } + } // success return true; }