mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-18 07:22:28 +00:00
Merge branch 'sdlglcontext' into 'master'
Only initialise OpenGL if the user intends to load it (for real this time) See merge request STJr/SRB2!796
This commit is contained in:
commit
2dfe276a73
11 changed files with 99 additions and 73 deletions
|
@ -19,10 +19,10 @@ boolean allow_fullscreen = false;
|
||||||
consvar_t cv_vidwait = {"vid_wait", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
|
consvar_t cv_vidwait = {"vid_wait", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
|
||||||
|
|
||||||
void I_StartupGraphics(void){}
|
void I_StartupGraphics(void){}
|
||||||
void I_StartupHardwareGraphics(void){}
|
|
||||||
|
|
||||||
void I_ShutdownGraphics(void){}
|
void I_ShutdownGraphics(void){}
|
||||||
|
|
||||||
|
void VID_StartupOpenGL(void){}
|
||||||
|
|
||||||
void I_SetPalette(RGBA_t *palette)
|
void I_SetPalette(RGBA_t *palette)
|
||||||
{
|
{
|
||||||
(void)palette;
|
(void)palette;
|
||||||
|
@ -52,10 +52,8 @@ INT32 VID_SetMode(INT32 modenum)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VID_CheckRenderer(void)
|
void VID_CheckRenderer(void) {}
|
||||||
{
|
void VID_CheckGLLoaded(rendermode_t oldrender) {}
|
||||||
// ..............
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *VID_GetModeName(INT32 modenum)
|
const char *VID_GetModeName(INT32 modenum)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1285,11 +1285,10 @@ void D_SRB2Main(void)
|
||||||
|
|
||||||
// Set cv_renderer to the new render mode
|
// Set cv_renderer to the new render mode
|
||||||
VID_CheckRenderer();
|
VID_CheckRenderer();
|
||||||
SCR_ChangeRendererCVars(setrenderneeded);
|
SCR_ChangeRendererCVars(rendermode);
|
||||||
|
|
||||||
// check the renderer's state, and then clear setrenderneeded
|
// check the renderer's state
|
||||||
D_CheckRendererState();
|
D_CheckRendererState();
|
||||||
setrenderneeded = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wipegamestate = gamestate;
|
wipegamestate = gamestate;
|
||||||
|
|
|
@ -339,7 +339,4 @@ void I_StartupGraphics(void)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void I_StartupHardwareGraphics(void)
|
void VID_StartupOpenGL(void) {}
|
||||||
{
|
|
||||||
// oh yeah woo yeah oh yeah woo yeah oh yeah woo yeah oh yeah woo yeah oh yeah woo yeah oh yeah woo yeah oh yeah woo y
|
|
||||||
}
|
|
||||||
|
|
|
@ -378,10 +378,8 @@ INT32 VID_SetMode (INT32 modenum) //, UINT8 *palette)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VID_CheckRenderer(void)
|
void VID_CheckRenderer(void) {}
|
||||||
{
|
void VID_CheckGLLoaded(rendermode_t oldrender) {}
|
||||||
// ..............
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,10 @@ boolean allow_fullscreen = false;
|
||||||
consvar_t cv_vidwait = {"vid_wait", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
|
consvar_t cv_vidwait = {"vid_wait", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
|
||||||
|
|
||||||
void I_StartupGraphics(void){}
|
void I_StartupGraphics(void){}
|
||||||
void I_StartupHardwareGraphics(void){}
|
|
||||||
|
|
||||||
void I_ShutdownGraphics(void){}
|
void I_ShutdownGraphics(void){}
|
||||||
|
|
||||||
|
void VID_StartupOpenGL(void){}
|
||||||
|
|
||||||
void I_SetPalette(RGBA_t *palette)
|
void I_SetPalette(RGBA_t *palette)
|
||||||
{
|
{
|
||||||
(void)palette;
|
(void)palette;
|
||||||
|
@ -40,10 +40,8 @@ INT32 VID_SetMode(INT32 modenum)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VID_CheckRenderer(void)
|
void VID_CheckRenderer(void) {}
|
||||||
{
|
void VID_CheckGLLoaded(rendermode_t oldrender) {}
|
||||||
// ..............
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *VID_GetModeName(INT32 modenum)
|
const char *VID_GetModeName(INT32 modenum)
|
||||||
{
|
{
|
||||||
|
|
|
@ -6619,7 +6619,6 @@ void HWR_Shutdown(void)
|
||||||
CONS_Printf("HWR_Shutdown()\n");
|
CONS_Printf("HWR_Shutdown()\n");
|
||||||
HWR_FreeExtraSubsectors();
|
HWR_FreeExtraSubsectors();
|
||||||
HWR_FreePolyPool();
|
HWR_FreePolyPool();
|
||||||
HWR_FreeMipmapCache();
|
|
||||||
HWR_FreeTextureCache();
|
HWR_FreeTextureCache();
|
||||||
HWD.pfnFlushScreenTextures();
|
HWD.pfnFlushScreenTextures();
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,10 @@ typedef enum
|
||||||
*/
|
*/
|
||||||
extern rendermode_t rendermode;
|
extern rendermode_t rendermode;
|
||||||
|
|
||||||
/** \brief hardware renderer loaded
|
/** \brief OpenGL state
|
||||||
0 = never loaded, 1 = loaded successfully, -1 = failed loading
|
0 = never loaded, 1 = loaded successfully, -1 = failed loading
|
||||||
*/
|
*/
|
||||||
extern INT32 hwrenderloaded;
|
extern INT32 vid_opengl_state;
|
||||||
|
|
||||||
/** \brief use highcolor modes if true
|
/** \brief use highcolor modes if true
|
||||||
*/
|
*/
|
||||||
|
@ -49,11 +49,7 @@ extern boolean highcolor;
|
||||||
*/
|
*/
|
||||||
void I_StartupGraphics(void);
|
void I_StartupGraphics(void);
|
||||||
|
|
||||||
/** \brief setup hardware mode
|
/** \brief shutdown video mode
|
||||||
*/
|
|
||||||
void I_StartupHardwareGraphics(void);
|
|
||||||
|
|
||||||
/** \brief restore old video mode
|
|
||||||
*/
|
*/
|
||||||
void I_ShutdownGraphics(void);
|
void I_ShutdownGraphics(void);
|
||||||
|
|
||||||
|
@ -97,6 +93,14 @@ INT32 VID_SetMode(INT32 modenum);
|
||||||
*/
|
*/
|
||||||
void VID_CheckRenderer(void);
|
void VID_CheckRenderer(void);
|
||||||
|
|
||||||
|
/** \brief Load OpenGL mode
|
||||||
|
*/
|
||||||
|
void VID_StartupOpenGL(void);
|
||||||
|
|
||||||
|
/** \brief Checks if OpenGL loaded
|
||||||
|
*/
|
||||||
|
void VID_CheckGLLoaded(rendermode_t oldrender);
|
||||||
|
|
||||||
/** \brief The VID_GetModeName function
|
/** \brief The VID_GetModeName function
|
||||||
|
|
||||||
\param modenum video mode number
|
\param modenum video mode number
|
||||||
|
|
|
@ -2098,7 +2098,7 @@ static void M_VideoOptions(INT32 choice)
|
||||||
{
|
{
|
||||||
(void)choice;
|
(void)choice;
|
||||||
#ifdef HWRENDER
|
#ifdef HWRENDER
|
||||||
if (hwrenderloaded == -1)
|
if (vid_opengl_state == -1)
|
||||||
{
|
{
|
||||||
OP_VideoOptionsMenu[op_video_renderer].status = (IT_TRANSTEXT | IT_PAIR);
|
OP_VideoOptionsMenu[op_video_renderer].status = (IT_TRANSTEXT | IT_PAIR);
|
||||||
OP_VideoOptionsMenu[op_video_renderer].patch = "Renderer";
|
OP_VideoOptionsMenu[op_video_renderer].patch = "Renderer";
|
||||||
|
|
|
@ -453,7 +453,7 @@ void SCR_ActuallyChangeRenderer(void)
|
||||||
|
|
||||||
#ifdef HWRENDER
|
#ifdef HWRENDER
|
||||||
// Well, it didn't even load anyway.
|
// Well, it didn't even load anyway.
|
||||||
if ((hwrenderloaded == -1) && (setrenderneeded == render_opengl))
|
if ((vid_opengl_state == -1) && (setrenderneeded == render_opengl))
|
||||||
{
|
{
|
||||||
if (M_CheckParm("-nogl"))
|
if (M_CheckParm("-nogl"))
|
||||||
CONS_Alert(CONS_ERROR, "OpenGL rendering was disabled!\n");
|
CONS_Alert(CONS_ERROR, "OpenGL rendering was disabled!\n");
|
||||||
|
@ -478,7 +478,7 @@ void SCR_ChangeRenderer(void)
|
||||||
{
|
{
|
||||||
target_renderer = cv_renderer.value;
|
target_renderer = cv_renderer.value;
|
||||||
#ifdef HWRENDER
|
#ifdef HWRENDER
|
||||||
if (M_CheckParm("-opengl") && (hwrenderloaded == 1))
|
if (M_CheckParm("-opengl") && (vid_opengl_state == 1))
|
||||||
target_renderer = rendermode = render_opengl;
|
target_renderer = rendermode = render_opengl;
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -104,7 +104,7 @@ static consvar_t cv_stretch = {"stretch", "Off", CV_SAVE|CV_NOSHOWHELP, CV_OnOff
|
||||||
static consvar_t cv_alwaysgrabmouse = {"alwaysgrabmouse", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
|
static consvar_t cv_alwaysgrabmouse = {"alwaysgrabmouse", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
|
||||||
|
|
||||||
UINT8 graphics_started = 0; // Is used in console.c and screen.c
|
UINT8 graphics_started = 0; // Is used in console.c and screen.c
|
||||||
INT32 hwrenderloaded = 0;
|
INT32 vid_opengl_state = 0;
|
||||||
|
|
||||||
// To disable fullscreen at startup; is set in VID_PrepareModeList
|
// To disable fullscreen at startup; is set in VID_PrepareModeList
|
||||||
boolean allow_fullscreen = false;
|
boolean allow_fullscreen = false;
|
||||||
|
@ -1440,7 +1440,7 @@ static SDL_bool Impl_CreateContext(void)
|
||||||
{
|
{
|
||||||
// Renderer-specific stuff
|
// Renderer-specific stuff
|
||||||
#ifdef HWRENDER
|
#ifdef HWRENDER
|
||||||
if ((rendermode == render_opengl) && (hwrenderloaded != -1))
|
if ((rendermode == render_opengl) && (vid_opengl_state != -1))
|
||||||
{
|
{
|
||||||
if (!sdlglcontext)
|
if (!sdlglcontext)
|
||||||
sdlglcontext = SDL_GL_CreateContext(window);
|
sdlglcontext = SDL_GL_CreateContext(window);
|
||||||
|
@ -1473,10 +1473,10 @@ static SDL_bool Impl_CreateContext(void)
|
||||||
return SDL_TRUE;
|
return SDL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HWRENDER
|
void VID_CheckGLLoaded(rendermode_t oldrender)
|
||||||
static void VID_CheckGLLoaded(rendermode_t oldrender)
|
|
||||||
{
|
{
|
||||||
if (hwrenderloaded == -1) // Well, it didn't work the first time anyway.
|
#ifdef HWRENDER
|
||||||
|
if (vid_opengl_state == -1) // Well, it didn't work the first time anyway.
|
||||||
{
|
{
|
||||||
rendermode = oldrender;
|
rendermode = oldrender;
|
||||||
if (chosenrendermode == render_opengl) // fallback to software
|
if (chosenrendermode == render_opengl) // fallback to software
|
||||||
|
@ -1488,40 +1488,66 @@ static void VID_CheckGLLoaded(rendermode_t oldrender)
|
||||||
setrenderneeded = 0;
|
setrenderneeded = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void VID_CheckRenderer(void)
|
void VID_CheckRenderer(void)
|
||||||
{
|
{
|
||||||
SDL_bool rendererchanged = SDL_FALSE;
|
boolean rendererchanged = false;
|
||||||
|
boolean contextcreated = false;
|
||||||
rendermode_t oldrenderer = rendermode;
|
rendermode_t oldrenderer = rendermode;
|
||||||
|
|
||||||
if (dedicated)
|
if (dedicated)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef HWRENDER
|
|
||||||
if (!graphics_started)
|
|
||||||
VID_CheckGLLoaded(oldrenderer);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (setrenderneeded)
|
if (setrenderneeded)
|
||||||
{
|
{
|
||||||
rendermode = setrenderneeded;
|
rendermode = setrenderneeded;
|
||||||
rendererchanged = SDL_TRUE;
|
rendererchanged = true;
|
||||||
|
|
||||||
#ifdef HWRENDER
|
#ifdef HWRENDER
|
||||||
if (rendermode == render_opengl)
|
if (rendermode == render_opengl)
|
||||||
{
|
{
|
||||||
VID_CheckGLLoaded(oldrenderer);
|
VID_CheckGLLoaded(oldrenderer);
|
||||||
|
|
||||||
// Initialise OpenGL before calling SDLSetMode!!!
|
// Initialise OpenGL before calling SDLSetMode!!!
|
||||||
if (hwrenderloaded != 1)
|
// This is because SDLSetMode calls OglSdlSurface.
|
||||||
I_StartupHardwareGraphics();
|
if (vid_opengl_state == 0)
|
||||||
else if (hwrenderloaded == -1)
|
{
|
||||||
rendererchanged = SDL_FALSE;
|
VID_StartupOpenGL();
|
||||||
|
// Loaded successfully!
|
||||||
|
if (vid_opengl_state == 1)
|
||||||
|
{
|
||||||
|
// Destroy the current window, if it exists.
|
||||||
|
if (window)
|
||||||
|
{
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
window = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destroy the current window rendering context, if that also exists.
|
||||||
|
if (renderer)
|
||||||
|
{
|
||||||
|
SDL_DestroyRenderer(renderer);
|
||||||
|
renderer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new window.
|
||||||
|
Impl_CreateWindow(USE_FULLSCREEN);
|
||||||
|
|
||||||
|
// From there, the OpenGL context was already created.
|
||||||
|
contextcreated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (vid_opengl_state == -1)
|
||||||
|
rendererchanged = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (!contextcreated)
|
||||||
Impl_CreateContext();
|
Impl_CreateContext();
|
||||||
|
|
||||||
|
setrenderneeded = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDLSetMode(vid.width, vid.height, USE_FULLSCREEN, (rendererchanged ? SDL_FALSE : SDL_TRUE));
|
SDLSetMode(vid.width, vid.height, USE_FULLSCREEN, (rendererchanged ? SDL_FALSE : SDL_TRUE));
|
||||||
|
@ -1534,15 +1560,25 @@ void VID_CheckRenderer(void)
|
||||||
SDL_FreeSurface(bufSurface);
|
SDL_FreeSurface(bufSurface);
|
||||||
bufSurface = NULL;
|
bufSurface = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rendererchanged)
|
||||||
|
{
|
||||||
#ifdef HWRENDER
|
#ifdef HWRENDER
|
||||||
if (hwrenderloaded == 1) // Only if OpenGL ever loaded!
|
if (vid_opengl_state == 1) // Only if OpenGL ever loaded!
|
||||||
HWR_FreeTextureCache();
|
HWR_FreeTextureCache();
|
||||||
#endif
|
#endif
|
||||||
SCR_SetDrawFuncs();
|
SCR_SetDrawFuncs();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#ifdef HWRENDER
|
#ifdef HWRENDER
|
||||||
else if (rendermode == render_opengl)
|
else if (rendermode == render_opengl)
|
||||||
|
{
|
||||||
|
if (rendererchanged)
|
||||||
|
{
|
||||||
R_InitHardwareMode();
|
R_InitHardwareMode();
|
||||||
|
V_SetPalette(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
(void)oldrenderer;
|
(void)oldrenderer;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1586,7 +1622,7 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen)
|
||||||
flags |= SDL_WINDOW_BORDERLESS;
|
flags |= SDL_WINDOW_BORDERLESS;
|
||||||
|
|
||||||
#ifdef HWRENDER
|
#ifdef HWRENDER
|
||||||
if (hwrenderloaded != -1)
|
if (vid_opengl_state == 1)
|
||||||
flags |= SDL_WINDOW_OPENGL;
|
flags |= SDL_WINDOW_OPENGL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1720,11 +1756,12 @@ void I_StartupGraphics(void)
|
||||||
|
|
||||||
//SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY>>1,SDL_DEFAULT_REPEAT_INTERVAL<<2);
|
//SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY>>1,SDL_DEFAULT_REPEAT_INTERVAL<<2);
|
||||||
VID_Command_ModeList_f();
|
VID_Command_ModeList_f();
|
||||||
|
|
||||||
#ifdef HWRENDER
|
#ifdef HWRENDER
|
||||||
if (M_CheckParm("-nogl"))
|
if (M_CheckParm("-nogl"))
|
||||||
hwrenderloaded = -1; // Don't call SDL_GL_LoadLibrary
|
vid_opengl_state = -1; // Don't startup OpenGL
|
||||||
else
|
else if (chosenrendermode == render_opengl)
|
||||||
I_StartupHardwareGraphics();
|
VID_StartupOpenGL();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Fury: we do window initialization after GL setup to allow
|
// Fury: we do window initialization after GL setup to allow
|
||||||
|
@ -1779,12 +1816,13 @@ void I_StartupGraphics(void)
|
||||||
graphics_started = true;
|
graphics_started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void I_StartupHardwareGraphics(void)
|
void VID_StartupOpenGL(void)
|
||||||
{
|
{
|
||||||
#ifdef HWRENDER
|
#ifdef HWRENDER
|
||||||
static boolean glstartup = false;
|
static boolean glstartup = false;
|
||||||
if (!glstartup)
|
if (!glstartup)
|
||||||
{
|
{
|
||||||
|
CONS_Printf("VID_StartupOpenGL()...\n");
|
||||||
HWD.pfnInit = hwSym("Init",NULL);
|
HWD.pfnInit = hwSym("Init",NULL);
|
||||||
HWD.pfnFinishUpdate = NULL;
|
HWD.pfnFinishUpdate = NULL;
|
||||||
HWD.pfnDraw2DLine = hwSym("Draw2DLine",NULL);
|
HWD.pfnDraw2DLine = hwSym("Draw2DLine",NULL);
|
||||||
|
@ -1816,13 +1854,13 @@ void I_StartupHardwareGraphics(void)
|
||||||
// check gl renderer lib
|
// check gl renderer lib
|
||||||
if (HWD.pfnGetRenderVersion() != VERSION)
|
if (HWD.pfnGetRenderVersion() != VERSION)
|
||||||
{
|
{
|
||||||
CONS_Alert(CONS_ERROR, M_GetText("The version of the renderer doesn't match the version of the executable\nBe sure you have installed SRB2 properly.\n"));
|
CONS_Alert(CONS_ERROR, M_GetText("The version of the renderer doesn't match the version of the executable!\nBe sure you have installed SRB2 properly.\n"));
|
||||||
hwrenderloaded = -1;
|
vid_opengl_state = -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
hwrenderloaded = HWD.pfnInit(I_Error) ? 1 : -1; // let load the OpenGL library
|
vid_opengl_state = HWD.pfnInit(I_Error) ? 1 : -1; // let load the OpenGL library
|
||||||
|
|
||||||
if (hwrenderloaded == -1)
|
if (vid_opengl_state == -1)
|
||||||
{
|
{
|
||||||
rendermode = render_soft;
|
rendermode = render_soft;
|
||||||
setrenderneeded = 0;
|
setrenderneeded = 0;
|
||||||
|
|
|
@ -239,10 +239,7 @@ void I_StartupGraphics(void)
|
||||||
if (!dedicated) graphics_started = true;
|
if (!dedicated) graphics_started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void I_StartupHardwareGraphics(void)
|
void VID_StartupOpenGL(void){}
|
||||||
{
|
|
||||||
// oh yeah woo yeah oh yeah woo yeah oh yeah woo yeah oh yeah woo yeah oh yeah woo yeah oh yeah woo yeah oh yeah woo y
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------
|
// ------------------
|
||||||
// I_ShutdownGraphics
|
// I_ShutdownGraphics
|
||||||
|
@ -951,10 +948,8 @@ INT32 VID_SetMode(INT32 modenum)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VID_CheckRenderer(void)
|
void VID_CheckRenderer(void) {}
|
||||||
{
|
void VID_CheckGLLoaded(rendermode_t oldrender) {}
|
||||||
// ..............
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========================================================================
|
// ========================================================================
|
||||||
// Free the video buffer of the last video mode,
|
// Free the video buffer of the last video mode,
|
||||||
|
|
Loading…
Reference in a new issue