From: DeaDDooMER Date: Sat, 19 Jun 2021 10:37:49 +0000 (+0300) Subject: render: move screen resize handler from io-driver X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=f8c006bbcbec547e9a3beda8372076a10ed049ae;p=d2df-sdl.git render: move screen resize handler from io-driver --- diff --git a/src/game/Doom2DF.lpr b/src/game/Doom2DF.lpr index 268e281..b66ba3b 100644 --- a/src/game/Doom2DF.lpr +++ b/src/game/Doom2DF.lpr @@ -914,6 +914,24 @@ end; end; {$ENDIF} + 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; @@ -924,6 +942,7 @@ end; e_InitSoundSystem(NoSound); 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 c191583..d61dd32 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 @@ -95,38 +96,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 GetTitle (): PChar; var info: AnsiString; begin @@ -164,7 +133,8 @@ implementation SDL_WM_SetCaption(GetTitle(), nil); gFullScreen := fullscreen; gRC_FullScreen := fullscreen; - UpdateSize(w, h); + if @sys_ScreenResize <> nil then + sys_ScreenResize(w, h); result := True end end @@ -465,8 +435,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 ff52b1d..5468afb 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 @@ -99,44 +100,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 (): PChar; var info: AnsiString; begin @@ -202,7 +165,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 @@ -243,7 +207,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; @@ -451,7 +416,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