mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2025-01-26 03:00:55 +00:00
sdl2: reuse window on mode change
This commit is contained in:
parent
2618b1dd0b
commit
145618785c
2 changed files with 66 additions and 28 deletions
|
@ -140,8 +140,8 @@ static SDL_bool videoblitok = SDL_FALSE;
|
|||
static SDL_bool exposevideo = SDL_FALSE;
|
||||
|
||||
// SDL2 vars
|
||||
static SDL_Window *window;
|
||||
static SDL_Renderer *renderer;
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
static SDL_Texture *texture;
|
||||
static SDL_bool havefocus = SDL_TRUE;
|
||||
|
||||
|
@ -195,33 +195,50 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen)
|
|||
int bmask;
|
||||
int amask;
|
||||
|
||||
if (fullscreen && !wasfullscreen)
|
||||
if (window)
|
||||
{
|
||||
// Recreate window in fullscreen
|
||||
SDL_DestroyRenderer(renderer);
|
||||
renderer = NULL;
|
||||
SDL_DestroyWindow(window);
|
||||
window = NULL;
|
||||
Impl_CreateWindow(SDL_TRUE);
|
||||
Impl_SetWindowIcon();
|
||||
wasfullscreen = SDL_TRUE;
|
||||
if (fullscreen && !wasfullscreen)
|
||||
{
|
||||
// Recreate window in fullscreen
|
||||
/*
|
||||
SDL_DestroyRenderer(renderer);
|
||||
renderer = NULL;
|
||||
SDL_DestroyWindow(window);
|
||||
window = NULL;
|
||||
Impl_CreateWindow(SDL_TRUE);
|
||||
Impl_SetWindowIcon();
|
||||
*/
|
||||
wasfullscreen = SDL_TRUE;
|
||||
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
}
|
||||
else if (!fullscreen && wasfullscreen)
|
||||
{
|
||||
// Recreate window in windowed mode
|
||||
/*
|
||||
SDL_DestroyRenderer(renderer);
|
||||
renderer = NULL;
|
||||
SDL_DestroyWindow(window);
|
||||
window = NULL;
|
||||
Impl_CreateWindow(SDL_FALSE);
|
||||
Impl_SetWindowIcon();
|
||||
*/
|
||||
wasfullscreen = SDL_FALSE;
|
||||
SDL_SetWindowFullscreen(window, 0);
|
||||
SDL_SetWindowSize(window, width, height);
|
||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
}
|
||||
else if (!wasfullscreen)
|
||||
{
|
||||
// Reposition window only in windowed mode
|
||||
SDL_SetWindowSize(window, width, height);
|
||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
}
|
||||
}
|
||||
else if (!fullscreen && wasfullscreen)
|
||||
else
|
||||
{
|
||||
// Recreate window in windowed mode
|
||||
SDL_DestroyRenderer(renderer);
|
||||
renderer = NULL;
|
||||
SDL_DestroyWindow(window);
|
||||
window = NULL;
|
||||
Impl_CreateWindow(SDL_FALSE);
|
||||
Impl_CreateWindow(fullscreen ? SDL_TRUE : SDL_FALSE);
|
||||
Impl_SetWindowIcon();
|
||||
wasfullscreen = SDL_FALSE;
|
||||
}
|
||||
else if (!wasfullscreen)
|
||||
{
|
||||
// Reposition window only in windowed mode
|
||||
SDL_SetWindowSize(window, width, height);
|
||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
wasfullscreen = fullscreen ? SDL_TRUE : SDL_FALSE;
|
||||
}
|
||||
|
||||
SDL_RenderSetLogicalSize(renderer, width, height);
|
||||
|
@ -1308,9 +1325,20 @@ void I_UpdateNoBlit(void)
|
|||
return;
|
||||
if (exposevideo)
|
||||
{
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, texture, NULL, NULL);
|
||||
SDL_RenderPresent(renderer);
|
||||
#ifdef HWRENDER
|
||||
if (rendermode == render_opengl)
|
||||
{
|
||||
OglSdlFinishUpdate(cv_vidwait.value);
|
||||
SDL_GL_SwapWindow(window);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (rendermode == render_soft)
|
||||
{
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, texture, NULL, NULL);
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
#ifdef HWRENDER
|
||||
|
@ -1782,6 +1810,13 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen)
|
|||
flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
}
|
||||
|
||||
#ifdef HWRENDER
|
||||
if (rendermode == render_opengl)
|
||||
{
|
||||
flags |= SDL_WINDOW_OPENGL;
|
||||
}
|
||||
#endif
|
||||
|
||||
window = SDL_CreateWindow("SRB2", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
realwidth, realheight, flags);
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
|
|
|
@ -25,6 +25,9 @@ boolean OglSdlSurface(INT32 w, INT32 h, boolean isFullscreen);
|
|||
|
||||
void OglSdlFinishUpdate(boolean vidwait);
|
||||
|
||||
extern SDL_Window *window;
|
||||
extern SDL_Renderer *renderer;
|
||||
|
||||
#ifdef _CREATE_DLL_
|
||||
EXPORT void HWRAPI( OglSdlSetPalette ) (RGBA_t *palette, RGBA_t *pgamma);
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue