From e4186a2f4f35eec5321707bdc4eb2cbc94edccd0 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Sat, 19 Jun 2021 13:37:49 +0300 Subject: [PATCH] render: move screen resize handler from io-driver --- src/game/Doom2DF.lpr | 19 ++++++++++++++ src/game/opengl/r_render.pas | 28 ++++++++++++++++++++- src/game/sdl/g_system.pas | 40 ++++------------------------- src/game/sdl2/g_system.pas | 49 ++++++------------------------------ src/game/stub/g_system.pas | 1 + 5 files changed, 60 insertions(+), 77 deletions(-) diff --git a/src/game/Doom2DF.lpr b/src/game/Doom2DF.lpr index d1fbc06..6022ee6 100644 --- a/src/game/Doom2DF.lpr +++ b/src/game/Doom2DF.lpr @@ -951,6 +951,24 @@ end; end; end; + procedure ScreenResize (w, h: Integer); + begin + r_Render_Resize(w, h); + {$IFDEF ENABLE_HOLMES} + fuiScrWdt := w; + fuiScrHgt := h; + {$ENDIF} + g_Game_SetupScreenSize; + {$IFNDEF ANDROID} + (* This will fix menu reset on keyboard showing *) + g_Menu_Reset; + {$ENDIF} + //g_Game_ClearLoading; + {$IFDEF ENABLE_HOLMES} + if assigned(oglInitCB) then oglInitCB; + {$ENDIF} + end; + procedure Startup; begin Randomize; @@ -961,6 +979,7 @@ end; InitSound; sys_Init; sys_CharPress := @CharPress; (* install hook *) + sys_ScreenResize := @ScreenResize; (* install hook *) g_Options_SetDefault; g_Options_SetDefaultVideo; g_Console_Initialize; diff --git a/src/game/opengl/r_render.pas b/src/game/opengl/r_render.pas index 9f8b754..668fb90 100644 --- a/src/game/opengl/r_render.pas +++ b/src/game/opengl/r_render.pas @@ -19,10 +19,11 @@ interface procedure r_Render_Initialize; procedure r_Render_Finalize; + procedure r_Render_Resize (w, h: Integer); implementation - uses SysUtils, Classes, g_system, g_game, g_options, r_window, r_graphics, r_console, r_playermodel; + uses SysUtils, Classes, e_log, g_system, g_game, g_options, r_window, r_graphics, r_console, r_playermodel; procedure r_Render_Initialize; begin @@ -40,4 +41,29 @@ implementation e_ReleaseEngine end; + procedure r_Render_Resize (w, h: Integer); + begin + gWinSizeX := w; + gWinSizeY := h; + gRC_Width := w; + gRC_Height := h; + if glRenderToFBO then + begin + // store real window size in gWinSize, downscale resolution now + w := round(w / r_pixel_scale); + h := round(h / r_pixel_scale); + if not e_ResizeFramebuffer(w, h) then + begin + e_LogWriteln('GL: could not create framebuffer, falling back to --no-fbo'); + glRenderToFBO := False; + w := gWinSizeX; + h := gWinSizeY; + end; + end; + gScreenWidth := w; + gScreenHeight := h; + e_ResizeWindow(w, h); + e_InitGL + end; + end. diff --git a/src/game/sdl/g_system.pas b/src/game/sdl/g_system.pas index 99b338c..bb8c66a 100644 --- a/src/game/sdl/g_system.pas +++ b/src/game/sdl/g_system.pas @@ -39,6 +39,7 @@ interface var (* hooks *) sys_CharPress: procedure (ch: AnsiChar) = nil; + sys_ScreenResize: procedure (w, h: Integer) = nil; implementation @@ -112,38 +113,6 @@ implementation {$ENDIF} end; - procedure UpdateSize (w, h: Integer); - begin - gWinSizeX := w; - gWinSizeY := h; - gRC_Width := w; - gRC_Height := h; - if glRenderToFBO then - begin - // store real window size in gWinSize, downscale resolution now - w := round(w / r_pixel_scale); - h := round(h / r_pixel_scale); - if not e_ResizeFramebuffer(w, h) then - begin - e_LogWriteln('GL: could not create framebuffer, falling back to --no-fbo'); - glRenderToFBO := False; - w := gWinSizeX; - h := gWinSizeY; - end; - end; - gScreenWidth := w; - gScreenHeight := h; - {$IFDEF ENABLE_HOLMES} - fuiScrWdt := w; - fuiScrHgt := h; - {$ENDIF} - e_ResizeWindow(w, h); - e_InitGL; - g_Game_SetupScreenSize; - g_Menu_Reset; - g_Game_ClearLoading; - end; - function GetDriver (): AnsiString; var buf: array [0..31] of AnsiChar; begin @@ -190,7 +159,8 @@ implementation SDL_WM_SetCaption(PChar(title), nil); gFullScreen := fullscreen; gRC_FullScreen := fullscreen; - UpdateSize(w, h); + if @sys_ScreenResize <> nil then + sys_ScreenResize(w, h); result := True end end @@ -658,8 +628,8 @@ implementation begin if g_dbg_input then e_LogWritefln('Input Debug: SDL_VIDEORESIZE %s %s', [ev.w, ev.h]); - if modeResize = 1 then - UpdateSize(ev.w, ev.h) + if (modeResize = 1) and (@sys_ScreenResize <> nil) then + sys_ScreenResize(ev.w, ev.h) else if modeResize > 1 then InitWindow(ev.w, ev.h, gBPP, gFullscreen) end; diff --git a/src/game/sdl2/g_system.pas b/src/game/sdl2/g_system.pas index bf44cea..5e91cc0 100644 --- a/src/game/sdl2/g_system.pas +++ b/src/game/sdl2/g_system.pas @@ -39,6 +39,7 @@ interface var (* hooks *) sys_CharPress: procedure (ch: AnsiChar) = nil; + sys_ScreenResize: procedure (w, h: Integer) = nil; implementation @@ -109,44 +110,6 @@ implementation {$ENDIF} end; - procedure UpdateSize (w, h: Integer); - begin - gWinSizeX := w; - gWinSizeY := h; - gRC_Width := w; - gRC_Height := h; - if glRenderToFBO then - begin - // store real window size in gWinSize, downscale resolution now - w := round(w / r_pixel_scale); - h := round(h / r_pixel_scale); - if not e_ResizeFramebuffer(w, h) then - begin - e_LogWriteln('GL: could not create framebuffer, falling back to --no-fbo'); - glRenderToFBO := False; - w := gWinSizeX; - h := gWinSizeY; - end; - end; - gScreenWidth := w; - gScreenHeight := h; - {$IFDEF ENABLE_HOLMES} - fuiScrWdt := w; - fuiScrHgt := h; - {$ENDIF} - e_ResizeWindow(w, h); - e_InitGL; - g_Game_SetupScreenSize; - {$IFNDEF ANDROID} - (* This will fix menu reset on keyboard showing *) - g_Menu_Reset; - {$ENDIF} - g_Game_ClearLoading; - {$IFDEF ENABLE_HOLMES} - if assigned(oglInitCB) then oglInitCB; - {$ENDIF} - end; - function GetTitle (): AnsiString; var info: AnsiString; begin @@ -213,7 +176,8 @@ implementation gWinMaximized := maximized; gRC_FullScreen := fullscreen; gRC_Maximized := maximized; - UpdateSize(w, h); + if @sys_ScreenResize <> nil then + sys_ScreenResize(w, h); result := true end else @@ -254,7 +218,8 @@ implementation gWinMaximized := maximized; gRC_FullScreen := fullscreen; gRC_Maximized := maximized; - UpdateSize(w, h); + if @sys_ScreenResize <> nil then + sys_ScreenResize(w, h); result := true end end; @@ -462,7 +427,9 @@ implementation if g_dbg_input then e_LogWritefln('Window Event: event = %s, data1 = %s, data2 = %s', [ev.event, ev.data1, ev.data2]); case ev.event of - SDL_WINDOWEVENT_RESIZED: UpdateSize(ev.data1, ev.data2); + SDL_WINDOWEVENT_RESIZED: + if @sys_ScreenResize <> nil then + sys_ScreenResize(ev.data1, ev.data2); SDL_WINDOWEVENT_EXPOSED: sys_Repaint; SDL_WINDOWEVENT_CLOSE: result := true; SDL_WINDOWEVENT_MOVED: diff --git a/src/game/stub/g_system.pas b/src/game/stub/g_system.pas index 4e4f423..9d14f24 100644 --- a/src/game/stub/g_system.pas +++ b/src/game/stub/g_system.pas @@ -39,6 +39,7 @@ interface var (* hooks *) sys_CharPress: procedure (ch: AnsiChar) = nil; + sys_ScreenResize: procedure (w, h: Integer) = nil; implementation -- 2.29.2