From 31d13ba41e073d1c1a63f807d22fe9558f254376 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 25 Apr 2024 11:30:18 +1000 Subject: [PATCH] Allow altering graphics viewport (unfinished) --- src/Game.c | 62 +++++++++++++++++++++------------------- src/Graphics.h | 8 ++++-- src/Graphics_3DS.c | 2 ++ src/Graphics_D3D11.c | 4 +++ src/Graphics_D3D9.c | 2 ++ src/Graphics_Dreamcast.c | 2 ++ src/Graphics_GCWii.c | 2 ++ src/Graphics_N64.c | 2 ++ src/Graphics_NDS.c | 2 ++ src/Graphics_PS1.c | 2 ++ src/Graphics_PS2.c | 2 ++ src/Graphics_PS3.c | 2 ++ src/Graphics_PSP.c | 2 ++ src/Graphics_PSVita.c | 2 ++ src/Graphics_Saturn.c | 2 ++ src/Graphics_SoftGPU.c | 2 ++ src/Graphics_WiiU.c | 3 ++ src/Graphics_Xbox.c | 2 ++ src/Graphics_Xbox360.c | 2 ++ src/_GLShared.h | 6 +++- 20 files changed, 80 insertions(+), 33 deletions(-) diff --git a/src/Game.c b/src/Game.c index ff4ad3ecd..7cd8a3216 100644 --- a/src/Game.c +++ b/src/Game.c @@ -603,7 +603,38 @@ void Game_TakeScreenshot(void) { #endif } -static void Game_RenderFrame(double delta) { +static CC_INLINE void Game_DrawFrame(double delta, float t) { + UpdateViewMatrix(); + + if (!Gui_GetBlocksWorld()) { + Camera.Active->GetPickedBlock(Entities.CurPlayer, &Game_SelectedPos); /* TODO: only pick when necessary */ + Camera_KeyLookUpdate(delta); + InputHandler_Tick(); + + if (Game_Anaglyph3D) { + Render3D_Anaglyph(delta, t); + } else { + Render3DFrame(delta, t); + } + } else { + RayTracer_SetInvalid(&Game_SelectedPos); + } + + Gfx_Begin2D(Game.Width, Game.Height); + Gui_RenderGui(delta); + OnscreenKeyboard_Draw3D(); +/* TODO find a better solution than this */ +#ifdef CC_BUILD_3DS + if (Game_Anaglyph3D) { + extern void Gfx_SetTopRight(void); + Gfx_SetTopRight(); + Gui_RenderGui(delta); + } +#endif + Gfx_End2D(); +} + +static CC_INLINE void Game_RenderFrame(double delta) { struct ScheduledTask entTask; float t; @@ -644,39 +675,12 @@ static void Game_RenderFrame(double delta) { Camera.CurrentPos = Camera.Active->GetPosition(&LocalPlayer_Instance, t); /* NOTE: EnvRenderer_UpdateFog also also sets clear color */ EnvRenderer_UpdateFog(); - UpdateViewMatrix(); AudioBackend_Tick(); /* TODO: Not calling Gfx_EndFrame doesn't work with Direct3D9 */ if (Window_Main.Inactive) return; Gfx_ClearBuffers(GFX_BUFFER_COLOR | GFX_BUFFER_DEPTH); - - if (!Gui_GetBlocksWorld()) { - Camera.Active->GetPickedBlock(Entities.CurPlayer, &Game_SelectedPos); /* TODO: only pick when necessary */ - Camera_KeyLookUpdate(delta); - InputHandler_Tick(); - - if (Game_Anaglyph3D) { - Render3D_Anaglyph(delta, t); - } else { - Render3DFrame(delta, t); - } - } else { - RayTracer_SetInvalid(&Game_SelectedPos); - } - - Gfx_Begin2D(Game.Width, Game.Height); - Gui_RenderGui(delta); - OnscreenKeyboard_Draw3D(); -/* TODO find a better solution than this */ -#ifdef CC_BUILD_3DS - if (Game_Anaglyph3D) { - extern void Gfx_SetTopRight(void); - Gfx_SetTopRight(); - Gui_RenderGui(delta); - } -#endif - Gfx_End2D(); + Game_DrawFrame(delta, t); if (Game_ScreenshotRequested) Game_TakeScreenshot(); Gfx_EndFrame(); diff --git a/src/Graphics.h b/src/Graphics.h index f96fa133d..86642684c 100644 --- a/src/Graphics.h +++ b/src/Graphics.h @@ -246,14 +246,16 @@ void Gfx_EndFrame(void); /* Sets whether to synchronise with monitor refresh to avoid tearing, and maximum frame rate */ /* NOTE: VSync setting may be unsupported or just ignored */ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMillis); -/* Updates state when the window's dimensions have changed */ -/* NOTE: This may require recreating the context depending on the backend */ -void Gfx_OnWindowResize(void); /* Gets information about the user's GPU and current backend state */ /* Backend state may include depth buffer bits, free memory, etc */ /* NOTE: Each line is separated by \n */ void Gfx_GetApiInfo(cc_string* info); +/* Updates state when the window's dimensions have changed */ +/* NOTE: This may require recreating the context depending on the backend */ +void Gfx_OnWindowResize(void); +void Gfx_UpdateViewport(void); + enum Screen3DS { TOP_SCREEN, BOTTOM_SCREEN }; #ifdef CC_BUILD_DUALSCREEN /* Selects which screen on the 3DS to render to */ diff --git a/src/Graphics_3DS.c b/src/Graphics_3DS.c index ad95bf669..94116177d 100644 --- a/src/Graphics_3DS.c +++ b/src/Graphics_3DS.c @@ -575,6 +575,8 @@ void Gfx_EndFrame(void) { void Gfx_OnWindowResize(void) { } +void Gfx_UpdateViewport(void) { } + /*########################################################################################################################* *----------------------------------------------------------Buffers--------------------------------------------------------* diff --git a/src/Graphics_D3D11.c b/src/Graphics_D3D11.c index 6624bcfce..9d5c4ce89 100644 --- a/src/Graphics_D3D11.c +++ b/src/Graphics_D3D11.c @@ -1176,6 +1176,10 @@ void Gfx_OnWindowResize(void) { RS_UpdateViewport(); } +void Gfx_UpdateViewport(void) { + RS_UpdateViewport(); +} + static void InitPipeline(void) { // https://docs.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-graphics-pipeline IA_Init(); diff --git a/src/Graphics_D3D9.c b/src/Graphics_D3D9.c index 073b8046e..e3649b1bf 100644 --- a/src/Graphics_D3D9.c +++ b/src/Graphics_D3D9.c @@ -886,4 +886,6 @@ void Gfx_OnWindowResize(void) { /* Only resize when necessary */ UpdateSwapchain(" (resizing window)"); } + +void Gfx_UpdateViewport(void) { } #endif diff --git a/src/Graphics_Dreamcast.c b/src/Graphics_Dreamcast.c index 9c542885d..4364a4827 100644 --- a/src/Graphics_Dreamcast.c +++ b/src/Graphics_Dreamcast.c @@ -557,4 +557,6 @@ void Gfx_EndFrame(void) { void Gfx_OnWindowResize(void) { glViewport(0, 0, Game.Width, Game.Height); } + +void Gfx_UpdateViewport(void) { } #endif diff --git a/src/Graphics_GCWii.c b/src/Graphics_GCWii.c index 8e0fa7f66..3864baa0e 100644 --- a/src/Graphics_GCWii.c +++ b/src/Graphics_GCWii.c @@ -312,6 +312,8 @@ void Gfx_EndFrame(void) { void Gfx_OnWindowResize(void) { } +void Gfx_UpdateViewport(void) { } + cc_bool Gfx_WarnIfNecessary(void) { return false; } diff --git a/src/Graphics_N64.c b/src/Graphics_N64.c index 4bc24d584..70849b0c4 100644 --- a/src/Graphics_N64.c +++ b/src/Graphics_N64.c @@ -79,6 +79,8 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) { void Gfx_OnWindowResize(void) { } +void Gfx_UpdateViewport(void) { } + void Gfx_BeginFrame(void) { surface_t* disp = display_get(); diff --git a/src/Graphics_NDS.c b/src/Graphics_NDS.c index 50dae9a0f..372628105 100644 --- a/src/Graphics_NDS.c +++ b/src/Graphics_NDS.c @@ -66,6 +66,8 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) { void Gfx_OnWindowResize(void) { } +void Gfx_UpdateViewport(void) { } + void Gfx_BeginFrame(void) { } diff --git a/src/Graphics_PS1.c b/src/Graphics_PS1.c index 1f936df42..ec2db31b9 100644 --- a/src/Graphics_PS1.c +++ b/src/Graphics_PS1.c @@ -727,6 +727,8 @@ void Gfx_OnWindowResize(void) { // TODO } +void Gfx_UpdateViewport(void) { } + void Gfx_GetApiInfo(cc_string* info) { String_AppendConst(info, "-- Using PS1 --\n"); PrintMaxTextureInfo(info); diff --git a/src/Graphics_PS2.c b/src/Graphics_PS2.c index 451cf042e..d5c5caa37 100644 --- a/src/Graphics_PS2.c +++ b/src/Graphics_PS2.c @@ -671,6 +671,8 @@ void Gfx_OnWindowResize(void) { // TODO } +void Gfx_UpdateViewport(void) { } + void Gfx_GetApiInfo(cc_string* info) { String_AppendConst(info, "-- Using PS2 --\n"); PrintMaxTextureInfo(info); diff --git a/src/Graphics_PS3.c b/src/Graphics_PS3.c index f1e5e389a..b68299eca 100644 --- a/src/Graphics_PS3.c +++ b/src/Graphics_PS3.c @@ -476,6 +476,8 @@ void Gfx_OnWindowResize(void) { } } +void Gfx_UpdateViewport(void) { } + /*########################################################################################################################* *-------------------------------------------------------Index buffers-----------------------------------------------------* diff --git a/src/Graphics_PSP.c b/src/Graphics_PSP.c index 48c25ba5a..1fa21ba0b 100644 --- a/src/Graphics_PSP.c +++ b/src/Graphics_PSP.c @@ -283,6 +283,8 @@ void Gfx_EndFrame(void) { void Gfx_OnWindowResize(void) { } +void Gfx_UpdateViewport(void) { } + static cc_uint8* gfx_vertices; static int gfx_fields; diff --git a/src/Graphics_PSVita.c b/src/Graphics_PSVita.c index 629cc64a1..fcb18f990 100644 --- a/src/Graphics_PSVita.c +++ b/src/Graphics_PSVita.c @@ -811,6 +811,8 @@ void Gfx_EndFrame(void) { void Gfx_OnWindowResize(void) { } +void Gfx_UpdateViewport(void) { } + /*########################################################################################################################* *--------------------------------------------------------GPU Buffers------------------------------------------------------* diff --git a/src/Graphics_Saturn.c b/src/Graphics_Saturn.c index b9015e008..a34c4b466 100644 --- a/src/Graphics_Saturn.c +++ b/src/Graphics_Saturn.c @@ -435,6 +435,8 @@ void Gfx_OnWindowResize(void) { // TODO } +void Gfx_UpdateViewport(void) { } + void Gfx_GetApiInfo(cc_string* info) { String_AppendConst(info, "-- Using Saturn --\n"); PrintMaxTextureInfo(info); diff --git a/src/Graphics_SoftGPU.c b/src/Graphics_SoftGPU.c index 2e32e7f6f..4557cbc1b 100644 --- a/src/Graphics_SoftGPU.c +++ b/src/Graphics_SoftGPU.c @@ -491,6 +491,8 @@ void Gfx_OnWindowResize(void) { colorBuffer = fb_bmp.scan0; } +void Gfx_UpdateViewport(void) { } + void Gfx_GetApiInfo(cc_string* info) { int pointerSize = sizeof(void*) * 8; String_Format1(info, "-- Using software (%i bit) --\n", &pointerSize); diff --git a/src/Graphics_WiiU.c b/src/Graphics_WiiU.c index 870bb726d..2e71341a8 100644 --- a/src/Graphics_WiiU.c +++ b/src/Graphics_WiiU.c @@ -458,6 +458,9 @@ void Gfx_GetApiInfo(cc_string* info) { void Gfx_OnWindowResize(void) { } + +void Gfx_UpdateViewport(void) { } + void Gfx_3DS_SetRenderScreen1(enum Screen3DS screen) { GX2ContextState* tv_state = WHBGfxGetTVContextState(); GX2ContextState* drc_state = WHBGfxGetDRCContextState(); // TODO diff --git a/src/Graphics_Xbox.c b/src/Graphics_Xbox.c index 9a87233ec..69d4c4e76 100644 --- a/src/Graphics_Xbox.c +++ b/src/Graphics_Xbox.c @@ -535,6 +535,8 @@ void Gfx_CalcPerspectiveMatrix(struct Matrix* matrix, float fov, float aspect, f void Gfx_OnWindowResize(void) { } +void Gfx_UpdateViewport(void) { } + static struct Matrix _view, _proj, _mvp; void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { diff --git a/src/Graphics_Xbox360.c b/src/Graphics_Xbox360.c index 1e5af8297..f95c75c52 100644 --- a/src/Graphics_Xbox360.c +++ b/src/Graphics_Xbox360.c @@ -402,4 +402,6 @@ void Gfx_GetApiInfo(cc_string* info) { void Gfx_OnWindowResize(void) { } + +void Gfx_UpdateViewport(void) { } #endif diff --git a/src/_GLShared.h b/src/_GLShared.h index 492dd0e3d..87fa52547 100644 --- a/src/_GLShared.h +++ b/src/_GLShared.h @@ -325,7 +325,7 @@ void Gfx_EndFrame(void) { } void Gfx_OnWindowResize(void) { - glViewport(Gfx.ViewportX, Gfx.ViewportY, Gfx.ViewportWidth, Gfx.ViewportHeight); + Gfx_UpdateViewport(); /* With cocoa backend, in some cases [NSOpenGLContext update] will actually */ /* call glViewport with the size of the window framebuffer */ /* https://github.com/glfw/glfw/issues/80 */ @@ -335,3 +335,7 @@ void Gfx_OnWindowResize(void) { /* https://github.com/ClassiCube/ClassiCube/issues/888 */ GLContext_Update(); } + +void Gfx_UpdateViewport(void) { + glViewport(Gfx.ViewportX, Gfx.ViewportY, Gfx.ViewportWidth, Gfx.ViewportHeight); +}