forked from Mirrors/openclonk
OpenGL: Remove duplication and Direct3d stuff
parent
8d2279f231
commit
55bda98558
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -23,6 +23,25 @@
|
|||
#include <StdWindow.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue