Allow altering graphics viewport (unfinished)

This commit is contained in:
UnknownShadow200 2024-04-25 11:30:18 +10:00
parent 029a59a836
commit 31d13ba41e
20 changed files with 80 additions and 33 deletions

View File

@ -603,7 +603,38 @@ void Game_TakeScreenshot(void) {
#endif #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; struct ScheduledTask entTask;
float t; float t;
@ -644,39 +675,12 @@ static void Game_RenderFrame(double delta) {
Camera.CurrentPos = Camera.Active->GetPosition(&LocalPlayer_Instance, t); Camera.CurrentPos = Camera.Active->GetPosition(&LocalPlayer_Instance, t);
/* NOTE: EnvRenderer_UpdateFog also also sets clear color */ /* NOTE: EnvRenderer_UpdateFog also also sets clear color */
EnvRenderer_UpdateFog(); EnvRenderer_UpdateFog();
UpdateViewMatrix();
AudioBackend_Tick(); AudioBackend_Tick();
/* TODO: Not calling Gfx_EndFrame doesn't work with Direct3D9 */ /* TODO: Not calling Gfx_EndFrame doesn't work with Direct3D9 */
if (Window_Main.Inactive) return; if (Window_Main.Inactive) return;
Gfx_ClearBuffers(GFX_BUFFER_COLOR | GFX_BUFFER_DEPTH); Gfx_ClearBuffers(GFX_BUFFER_COLOR | GFX_BUFFER_DEPTH);
Game_DrawFrame(delta, t);
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();
if (Game_ScreenshotRequested) Game_TakeScreenshot(); if (Game_ScreenshotRequested) Game_TakeScreenshot();
Gfx_EndFrame(); Gfx_EndFrame();

View File

@ -246,14 +246,16 @@ void Gfx_EndFrame(void);
/* Sets whether to synchronise with monitor refresh to avoid tearing, and maximum frame rate */ /* Sets whether to synchronise with monitor refresh to avoid tearing, and maximum frame rate */
/* NOTE: VSync setting may be unsupported or just ignored */ /* NOTE: VSync setting may be unsupported or just ignored */
void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMillis); 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 */ /* Gets information about the user's GPU and current backend state */
/* Backend state may include depth buffer bits, free memory, etc */ /* Backend state may include depth buffer bits, free memory, etc */
/* NOTE: Each line is separated by \n */ /* NOTE: Each line is separated by \n */
void Gfx_GetApiInfo(cc_string* info); 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 }; enum Screen3DS { TOP_SCREEN, BOTTOM_SCREEN };
#ifdef CC_BUILD_DUALSCREEN #ifdef CC_BUILD_DUALSCREEN
/* Selects which screen on the 3DS to render to */ /* Selects which screen on the 3DS to render to */

View File

@ -575,6 +575,8 @@ void Gfx_EndFrame(void) {
void Gfx_OnWindowResize(void) { } void Gfx_OnWindowResize(void) { }
void Gfx_UpdateViewport(void) { }
/*########################################################################################################################* /*########################################################################################################################*
*----------------------------------------------------------Buffers--------------------------------------------------------* *----------------------------------------------------------Buffers--------------------------------------------------------*

View File

@ -1176,6 +1176,10 @@ void Gfx_OnWindowResize(void) {
RS_UpdateViewport(); RS_UpdateViewport();
} }
void Gfx_UpdateViewport(void) {
RS_UpdateViewport();
}
static void InitPipeline(void) { static void InitPipeline(void) {
// https://docs.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-graphics-pipeline // https://docs.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-graphics-pipeline
IA_Init(); IA_Init();

View File

@ -886,4 +886,6 @@ void Gfx_OnWindowResize(void) {
/* Only resize when necessary */ /* Only resize when necessary */
UpdateSwapchain(" (resizing window)"); UpdateSwapchain(" (resizing window)");
} }
void Gfx_UpdateViewport(void) { }
#endif #endif

View File

@ -557,4 +557,6 @@ void Gfx_EndFrame(void) {
void Gfx_OnWindowResize(void) { void Gfx_OnWindowResize(void) {
glViewport(0, 0, Game.Width, Game.Height); glViewport(0, 0, Game.Width, Game.Height);
} }
void Gfx_UpdateViewport(void) { }
#endif #endif

View File

@ -312,6 +312,8 @@ void Gfx_EndFrame(void) {
void Gfx_OnWindowResize(void) { } void Gfx_OnWindowResize(void) { }
void Gfx_UpdateViewport(void) { }
cc_bool Gfx_WarnIfNecessary(void) { return false; } cc_bool Gfx_WarnIfNecessary(void) { return false; }

View File

@ -79,6 +79,8 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
void Gfx_OnWindowResize(void) { } void Gfx_OnWindowResize(void) { }
void Gfx_UpdateViewport(void) { }
void Gfx_BeginFrame(void) { void Gfx_BeginFrame(void) {
surface_t* disp = display_get(); surface_t* disp = display_get();

View File

@ -66,6 +66,8 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
void Gfx_OnWindowResize(void) { void Gfx_OnWindowResize(void) {
} }
void Gfx_UpdateViewport(void) { }
void Gfx_BeginFrame(void) { void Gfx_BeginFrame(void) {
} }

View File

@ -727,6 +727,8 @@ void Gfx_OnWindowResize(void) {
// TODO // TODO
} }
void Gfx_UpdateViewport(void) { }
void Gfx_GetApiInfo(cc_string* info) { void Gfx_GetApiInfo(cc_string* info) {
String_AppendConst(info, "-- Using PS1 --\n"); String_AppendConst(info, "-- Using PS1 --\n");
PrintMaxTextureInfo(info); PrintMaxTextureInfo(info);

View File

@ -671,6 +671,8 @@ void Gfx_OnWindowResize(void) {
// TODO // TODO
} }
void Gfx_UpdateViewport(void) { }
void Gfx_GetApiInfo(cc_string* info) { void Gfx_GetApiInfo(cc_string* info) {
String_AppendConst(info, "-- Using PS2 --\n"); String_AppendConst(info, "-- Using PS2 --\n");
PrintMaxTextureInfo(info); PrintMaxTextureInfo(info);

View File

@ -476,6 +476,8 @@ void Gfx_OnWindowResize(void) {
} }
} }
void Gfx_UpdateViewport(void) { }
/*########################################################################################################################* /*########################################################################################################################*
*-------------------------------------------------------Index buffers-----------------------------------------------------* *-------------------------------------------------------Index buffers-----------------------------------------------------*

View File

@ -283,6 +283,8 @@ void Gfx_EndFrame(void) {
void Gfx_OnWindowResize(void) { } void Gfx_OnWindowResize(void) { }
void Gfx_UpdateViewport(void) { }
static cc_uint8* gfx_vertices; static cc_uint8* gfx_vertices;
static int gfx_fields; static int gfx_fields;

View File

@ -811,6 +811,8 @@ void Gfx_EndFrame(void) {
void Gfx_OnWindowResize(void) { } void Gfx_OnWindowResize(void) { }
void Gfx_UpdateViewport(void) { }
/*########################################################################################################################* /*########################################################################################################################*
*--------------------------------------------------------GPU Buffers------------------------------------------------------* *--------------------------------------------------------GPU Buffers------------------------------------------------------*

View File

@ -435,6 +435,8 @@ void Gfx_OnWindowResize(void) {
// TODO // TODO
} }
void Gfx_UpdateViewport(void) { }
void Gfx_GetApiInfo(cc_string* info) { void Gfx_GetApiInfo(cc_string* info) {
String_AppendConst(info, "-- Using Saturn --\n"); String_AppendConst(info, "-- Using Saturn --\n");
PrintMaxTextureInfo(info); PrintMaxTextureInfo(info);

View File

@ -491,6 +491,8 @@ void Gfx_OnWindowResize(void) {
colorBuffer = fb_bmp.scan0; colorBuffer = fb_bmp.scan0;
} }
void Gfx_UpdateViewport(void) { }
void Gfx_GetApiInfo(cc_string* info) { void Gfx_GetApiInfo(cc_string* info) {
int pointerSize = sizeof(void*) * 8; int pointerSize = sizeof(void*) * 8;
String_Format1(info, "-- Using software (%i bit) --\n", &pointerSize); String_Format1(info, "-- Using software (%i bit) --\n", &pointerSize);

View File

@ -458,6 +458,9 @@ void Gfx_GetApiInfo(cc_string* info) {
void Gfx_OnWindowResize(void) { void Gfx_OnWindowResize(void) {
} }
void Gfx_UpdateViewport(void) { }
void Gfx_3DS_SetRenderScreen1(enum Screen3DS screen) { void Gfx_3DS_SetRenderScreen1(enum Screen3DS screen) {
GX2ContextState* tv_state = WHBGfxGetTVContextState(); GX2ContextState* tv_state = WHBGfxGetTVContextState();
GX2ContextState* drc_state = WHBGfxGetDRCContextState(); // TODO GX2ContextState* drc_state = WHBGfxGetDRCContextState(); // TODO

View File

@ -535,6 +535,8 @@ void Gfx_CalcPerspectiveMatrix(struct Matrix* matrix, float fov, float aspect, f
void Gfx_OnWindowResize(void) { } void Gfx_OnWindowResize(void) { }
void Gfx_UpdateViewport(void) { }
static struct Matrix _view, _proj, _mvp; static struct Matrix _view, _proj, _mvp;
void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) {

View File

@ -402,4 +402,6 @@ void Gfx_GetApiInfo(cc_string* info) {
void Gfx_OnWindowResize(void) { void Gfx_OnWindowResize(void) {
} }
void Gfx_UpdateViewport(void) { }
#endif #endif

View File

@ -325,7 +325,7 @@ void Gfx_EndFrame(void) {
} }
void Gfx_OnWindowResize(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 */ /* With cocoa backend, in some cases [NSOpenGLContext update] will actually */
/* call glViewport with the size of the window framebuffer */ /* call glViewport with the size of the window framebuffer */
/* https://github.com/glfw/glfw/issues/80 */ /* https://github.com/glfw/glfw/issues/80 */
@ -335,3 +335,7 @@ void Gfx_OnWindowResize(void) {
/* https://github.com/ClassiCube/ClassiCube/issues/888 */ /* https://github.com/ClassiCube/ClassiCube/issues/888 */
GLContext_Update(); GLContext_Update();
} }
void Gfx_UpdateViewport(void) {
glViewport(Gfx.ViewportX, Gfx.ViewportY, Gfx.ViewportWidth, Gfx.ViewportHeight);
}