Skip to content

Commit

Permalink
Implement OpenGL rendering using SDL if it's preferred.
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamyCecil committed Feb 11, 2024
1 parent 197efd7 commit 4e737a9
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 44 deletions.
66 changes: 43 additions & 23 deletions Sources/Engine/Graphics/GfxLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ CGfxLibrary::CGfxLibrary(void)
// no driver loaded
gl_pInterface = NULL; // [Cecil]
gl_hiDriver = NONE;
go_hglRC = NONE;
go_hglRC = NULL;
gl_ctDriverChanges = 0;

// DX8 not loaded either
Expand Down Expand Up @@ -1643,12 +1643,18 @@ void CGfxLibrary::UnlockDrawPort( CDrawPort *pdpToUnlock)
/* Create a new window canvas. */
void CGfxLibrary::CreateWindowCanvas(OS::Window hWnd, CViewPort **ppvpNew, CDrawPort **ppdpNew)
{
RECT rectWindow; // rectangle for the client area of the window
// Get dimensions from the window
int pixWidth, pixHeight;

// get the dimensions from the window
GetClientRect( (HWND)hWnd, &rectWindow);
PIX pixWidth = rectWindow.right - rectWindow.left;
PIX pixHeight = rectWindow.bottom - rectWindow.top;
#if !SE1_PREFER_SDL
RECT rectWindow;
GetClientRect(hWnd, &rectWindow);
pixWidth = int(rectWindow.right - rectWindow.left);
pixHeight = int(rectWindow.bottom - rectWindow.top);

#else
SDL_GL_GetDrawableSize(hWnd, &pixWidth, &pixHeight);
#endif

*ppvpNew = NULL;
*ppdpNew = NULL;
Expand All @@ -1671,6 +1677,8 @@ void CGfxLibrary::DestroyWindowCanvas(CViewPort *pvpOld) {
/////////////////////////////////////////////////////////////////////
// Work canvas functions

#if !SE1_PREFER_SDL

#define WorkCanvasCLASS "WorkCanvas Window"
static BOOL _bClassRegistered = FALSE;

Expand Down Expand Up @@ -1726,7 +1734,7 @@ void CGfxLibrary::DestroyWorkCanvas(CDrawPort *pdpOld)
::DestroyWindow(hwnd);
}


#endif // !SE1_PREFER_SDL

// optimize memory used by cached shadow maps

Expand Down Expand Up @@ -1872,12 +1880,22 @@ void CGfxLibrary::SwapBuffers(CViewPort *pvp)
if( gl_ulFlags & GLF_VSYNC) {
if( gl_iSwapInterval != gap_iSwapInterval) {
gl_iSwapInterval = gap_iSwapInterval;
pwglSwapIntervalEXT( gl_iSwapInterval);

#if !SE1_PREFER_SDL
pwglSwapIntervalEXT( gl_iSwapInterval);
#else
SDL_GL_SetSwapInterval(gl_iSwapInterval);
#endif
}
}

// swap buffers
CTempDC tdc(pvp->vp_hWnd);
pwglSwapBuffers(tdc.hdc);
#if !SE1_PREFER_SDL
CTempDC tdc(pvp->vp_hWnd);
pwglSwapBuffers(tdc.hdc);
#else
SDL_GL_SwapWindow(pvp->vp_hWnd);
#endif

// force finishing of all rendering operations (if required)
if( ogl_iFinish==3) gfxFinish();
Expand Down Expand Up @@ -1986,6 +2004,8 @@ void CGfxLibrary::SwapBuffers(CViewPort *pvp)
if( gfx_bClearScreen) pvp->vp_Raster.ra_MainDrawPort.Fill( C_BLACK|CT_OPAQUE);
//pvp->vp_Raster.ra_MainDrawPort.FillZBuffer(ZBUF_BACK);

// [Cecil] SDL: Don't bother with gamma adjustment
#if !SE1_PREFER_SDL
// adjust gamma table if supported ...
if( gl_ulFlags & GLF_ADJUSTABLEGAMMA) {
// ... and required
Expand All @@ -1995,24 +2015,24 @@ void CGfxLibrary::SwapBuffers(CViewPort *pvp)
CTempDC tdc(pvp->vp_hWnd);
SetDeviceGammaRamp( tdc.hdc, &_auwGammaTable[0]);
}
#ifdef SE1_D3D
#ifdef SE1_D3D
else if (GetCurrentAPI() == GAT_D3D) {
gl_pd3dDevice->SetGammaRamp( D3DSGR_NO_CALIBRATION, (D3DGAMMARAMP*)&_auwGammaTable[0]);
}
#endif // SE1_D3D
#endif // SE1_D3D
}
return;
}
// if not supported
else {
// just reset settings to default
gfx_fBrightness = 0;
gfx_fContrast = 1;
gfx_fGamma = 1;
gfx_fBiasR = 1;
gfx_fBiasG = 1;
gfx_fBiasB = 1;
gfx_iLevels = 256;
}
#endif // !SE1_PREFER_SDL

// just reset settings to default
gfx_fBrightness = 0;
gfx_fContrast = 1;
gfx_fGamma = 1;
gfx_fBiasR = 1;
gfx_fBiasG = 1;
gfx_fBiasB = 1;
gfx_iLevels = 256;
}


Expand Down
8 changes: 6 additions & 2 deletions Sources/Engine/Graphics/GfxLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ class ENGINE_API CGfxLibrary
DWORD gl_dwVertexShader;

// OpenGL info
#if !SE1_PREFER_SDL
HGLRC go_hglRC; // rendering context
#else
SDL_GLContext go_hglRC; // [Cecil] SDL
#endif
CTString go_strExtensions; // reported extensions
CTString go_strWinExtensions;
CTString go_strSupportedExtensions; // supported extensions
Expand Down Expand Up @@ -195,8 +199,8 @@ class ENGINE_API CGfxLibrary
void EndDriver_OGL(void);
void TestExtension_OGL( ULONG ulFlag, const char *strName); // if exist, add OpenGL extension to flag and list
void AddExtension_OGL( ULONG ulFlag, const char *strName); // unconditionally add OpenGL extension to flag and list
BOOL CreateContext_OGL( HDC hdc);
BOOL SetupPixelFormat_OGL( HDC hdc, BOOL bReport=FALSE);
BOOL CreateContext_OGL(OS::DvcContext hdc);
BOOL SetupPixelFormat_OGL(OS::DvcContext hdc, BOOL bReport=FALSE);
void InitContext_OGL(void);
BOOL SetCurrentViewport_OGL( CViewPort *pvp);
void UploadPattern_OGL( ULONG ulPatternEven);
Expand Down
Loading

0 comments on commit 4e737a9

Please sign in to comment.