mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2025-01-27 03:30:50 +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;
|
static SDL_bool exposevideo = SDL_FALSE;
|
||||||
|
|
||||||
// SDL2 vars
|
// SDL2 vars
|
||||||
static SDL_Window *window;
|
SDL_Window *window;
|
||||||
static SDL_Renderer *renderer;
|
SDL_Renderer *renderer;
|
||||||
static SDL_Texture *texture;
|
static SDL_Texture *texture;
|
||||||
static SDL_bool havefocus = SDL_TRUE;
|
static SDL_bool havefocus = SDL_TRUE;
|
||||||
|
|
||||||
|
@ -195,33 +195,50 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen)
|
||||||
int bmask;
|
int bmask;
|
||||||
int amask;
|
int amask;
|
||||||
|
|
||||||
if (fullscreen && !wasfullscreen)
|
if (window)
|
||||||
{
|
{
|
||||||
// Recreate window in fullscreen
|
if (fullscreen && !wasfullscreen)
|
||||||
SDL_DestroyRenderer(renderer);
|
{
|
||||||
renderer = NULL;
|
// Recreate window in fullscreen
|
||||||
SDL_DestroyWindow(window);
|
/*
|
||||||
window = NULL;
|
SDL_DestroyRenderer(renderer);
|
||||||
Impl_CreateWindow(SDL_TRUE);
|
renderer = NULL;
|
||||||
Impl_SetWindowIcon();
|
SDL_DestroyWindow(window);
|
||||||
wasfullscreen = SDL_TRUE;
|
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
|
Impl_CreateWindow(fullscreen ? SDL_TRUE : SDL_FALSE);
|
||||||
SDL_DestroyRenderer(renderer);
|
|
||||||
renderer = NULL;
|
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
window = NULL;
|
|
||||||
Impl_CreateWindow(SDL_FALSE);
|
|
||||||
Impl_SetWindowIcon();
|
Impl_SetWindowIcon();
|
||||||
wasfullscreen = SDL_FALSE;
|
wasfullscreen = fullscreen ? SDL_TRUE : 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_RenderSetLogicalSize(renderer, width, height);
|
SDL_RenderSetLogicalSize(renderer, width, height);
|
||||||
|
@ -1308,9 +1325,20 @@ void I_UpdateNoBlit(void)
|
||||||
return;
|
return;
|
||||||
if (exposevideo)
|
if (exposevideo)
|
||||||
{
|
{
|
||||||
SDL_RenderClear(renderer);
|
#ifdef HWRENDER
|
||||||
SDL_RenderCopy(renderer, texture, NULL, NULL);
|
if (rendermode == render_opengl)
|
||||||
SDL_RenderPresent(renderer);
|
{
|
||||||
|
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
|
#if 0
|
||||||
#ifdef HWRENDER
|
#ifdef HWRENDER
|
||||||
|
@ -1782,6 +1810,13 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen)
|
||||||
flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
|
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,
|
window = SDL_CreateWindow("SRB2", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||||
realwidth, realheight, flags);
|
realwidth, realheight, flags);
|
||||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||||
|
|
|
@ -25,6 +25,9 @@ boolean OglSdlSurface(INT32 w, INT32 h, boolean isFullscreen);
|
||||||
|
|
||||||
void OglSdlFinishUpdate(boolean vidwait);
|
void OglSdlFinishUpdate(boolean vidwait);
|
||||||
|
|
||||||
|
extern SDL_Window *window;
|
||||||
|
extern SDL_Renderer *renderer;
|
||||||
|
|
||||||
#ifdef _CREATE_DLL_
|
#ifdef _CREATE_DLL_
|
||||||
EXPORT void HWRAPI( OglSdlSetPalette ) (RGBA_t *palette, RGBA_t *pgamma);
|
EXPORT void HWRAPI( OglSdlSetPalette ) (RGBA_t *palette, RGBA_t *pgamma);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue