Simplify viewport setting

This commit is contained in:
UnknownShadow200 2024-04-25 18:36:49 +10:00
parent 791e96ed2d
commit c7fd3a05f9
20 changed files with 41 additions and 50 deletions

View File

@ -639,11 +639,7 @@ static CC_INLINE void Game_DrawFrame(double delta, float t) {
#ifdef CC_BUILD_SPLITSCREEN
static void DrawSplitscreen(double delta, float t, int i, int x, int y, int w, int h) {
Gfx.ViewportX = x;
Gfx.ViewportY = y;
Gfx.ViewportWidth = w;
Gfx.ViewportHeight = h;
Gfx_UpdateViewport();
Gfx_SetViewport(x, y, w, h);
Entities.CurPlayer = &LocalPlayer_Instances[i];
LocalPlayer_SetInterpPosition(Entities.CurPlayer, t);

View File

@ -66,7 +66,6 @@ CC_VAR extern struct _GfxData {
int MinTexWidth, MinTexHeight;
cc_bool ReducedPerfMode;
cc_uint8 ReducedPerfModeCooldown;
int ViewportX, ViewportY, ViewportWidth, ViewportHeight;
} Gfx;
extern GfxResourceID Gfx_defaultIb;
@ -254,7 +253,7 @@ 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);
void Gfx_SetViewport(int x, int y, int w, int h);
enum Screen3DS { TOP_SCREEN, BOTTOM_SCREEN };
#ifdef CC_BUILD_DUALSCREEN

View File

@ -575,7 +575,7 @@ void Gfx_EndFrame(void) {
void Gfx_OnWindowResize(void) { }
void Gfx_UpdateViewport(void) { }
void Gfx_SetViewport(int x, int y, int w, int h) { }
/*########################################################################################################################*

View File

@ -646,12 +646,12 @@ static void RS_CreateRasterState(void) {
ID3D11Device_CreateRasterizerState(device, &desc, &rs_states[1]);
}
static void RS_UpdateViewport(void) {
void Gfx_SetViewport(int x, int y, int w, int h) {
D3D11_VIEWPORT viewport;
viewport.TopLeftX = Gfx.ViewportX;
viewport.TopLeftY = Gfx.ViewportY;
viewport.Width = Gfx.ViewportWidth;
viewport.Height = Gfx.ViewportHeight;
viewport.TopLeftX = x;
viewport.TopLeftY = y;
viewport.Width = w;
viewport.Height = h;
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
ID3D11DeviceContext_RSSetViewports(context, 1, &viewport);
@ -670,7 +670,7 @@ static void RS_FreeRasterStates(void) {
static void RS_Init(void) {
RS_CreateRasterState();
RS_UpdateViewport();
Gfx_SetViewport(0, 0, Game.Width, Game.Height);
RS_UpdateRasterState();
}
@ -1173,11 +1173,7 @@ void Gfx_OnWindowResize(void) {
if (hr) Logger_Abort2(hr, "Failed to resize swapchain");
OM_InitTargets();
RS_UpdateViewport();
}
void Gfx_UpdateViewport(void) {
RS_UpdateViewport();
Gfx_SetViewport(0, 0, Game.Width, Game.Height);
}
static void InitPipeline(void) {

View File

@ -887,5 +887,5 @@ void Gfx_OnWindowResize(void) {
UpdateSwapchain(" (resizing window)");
}
void Gfx_UpdateViewport(void) { }
void Gfx_SetViewport(int x, int y, int w, int h) { }
#endif

View File

@ -30,7 +30,7 @@ static void InitGLState(void) {
void Gfx_Create(void) {
if (!Gfx.Created) glKosInit();
Gfx_UpdateViewport();
Gfx_SetViewport(0, 0, Game.Width, Game.Height);
InitGLState();
Gfx.MinTexWidth = 8;
@ -555,11 +555,11 @@ void Gfx_EndFrame(void) {
}
void Gfx_OnWindowResize(void) {
Gfx_UpdateViewport();
Gfx_SetViewport(0, 0, Game.Width, Game.Height);
}
void Gfx_UpdateViewport(void) {
glViewport(Gfx.ViewportX, Gfx.ViewportY, Gfx.ViewportWidth, Gfx.ViewportHeight);
glScissor (Gfx.ViewportX, Gfx.ViewportY, Gfx.ViewportWidth, Gfx.ViewportHeight);
void Gfx_SetViewport(int x, int y, int w, int h) {
glViewport(x, y, w, h);
glScissor (x, y, w, h);
}
#endif

View File

@ -312,7 +312,7 @@ void Gfx_EndFrame(void) {
void Gfx_OnWindowResize(void) { }
void Gfx_UpdateViewport(void) { }
void Gfx_SetViewport(int x, int y, int w, int h) { }
cc_bool Gfx_WarnIfNecessary(void) { return false; }

View File

@ -79,7 +79,7 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
void Gfx_OnWindowResize(void) { }
void Gfx_UpdateViewport(void) { }
void Gfx_SetViewport(int x, int y, int w, int h) { }
void Gfx_BeginFrame(void) {

View File

@ -66,7 +66,7 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
void Gfx_OnWindowResize(void) {
}
void Gfx_UpdateViewport(void) { }
void Gfx_SetViewport(int x, int y, int w, int h) { }
void Gfx_BeginFrame(void) {
}

View File

@ -727,7 +727,7 @@ void Gfx_OnWindowResize(void) {
// TODO
}
void Gfx_UpdateViewport(void) { }
void Gfx_SetViewport(int x, int y, int w, int h) { }
void Gfx_GetApiInfo(cc_string* info) {
String_AppendConst(info, "-- Using PS1 --\n");

View File

@ -671,7 +671,7 @@ void Gfx_OnWindowResize(void) {
// TODO
}
void Gfx_UpdateViewport(void) { }
void Gfx_SetViewport(int x, int y, int w, int h) { }
void Gfx_GetApiInfo(cc_string* info) {
String_AppendConst(info, "-- Using PS2 --\n");

View File

@ -414,7 +414,7 @@ static void ResetFrameState(void) {
GCM_USER_CLIP_PLANE_DISABLE);
// NOTE: Must be called each frame, otherwise renders upside down at 4x zoom
Gfx_OnWindowResize();
Gfx_SetViewport(0, 0, Game.Width, Game.Height);
}
// https://github.com/ps3dev/PSL1GHT/blob/master/ppu/include/rsx/rsx.h#L30
@ -450,24 +450,26 @@ void Gfx_EndFrame(void) {
}
void Gfx_OnWindowResize(void) {
Gfx_SetViewport(0, 0, Game.Width, Game.Height);
}
void Gfx_SetViewport(int x, int y, int w, int h) {
f32 scale[4], offset[4];
u16 w = DisplayInfo.Width;
u16 h = DisplayInfo.Height;
f32 zmin = 0.0f;
f32 zmax = 1.0f;
y = Game.Height - y - h;
scale[0] = w * 0.5f;
scale[1] = h * -0.5f;
scale[2] = (zmax - zmin) * 0.5f;
scale[3] = 0.0f;
offset[0] = w * 0.5f;
offset[1] = h * 0.5f;
offset[0] = x + w * 0.5f;
offset[1] = x + h * 0.5f;
offset[2] = (zmax + zmin) * 0.5f;
offset[3] = 0.0f;
rsxSetViewport(context, 0, 0, w, h, zmin, zmax, scale, offset);
rsxSetScissor(context, 0, 0, w, h);
rsxSetViewport(context, x, y, w, h, zmin, zmax, scale, offset);
rsxSetScissor(context, x, y, w, h);
// TODO: even needed?
for (int i = 0; i < 8; i++)
@ -476,8 +478,6 @@ void Gfx_OnWindowResize(void) {
}
}
void Gfx_UpdateViewport(void) { }
/*########################################################################################################################*
*-------------------------------------------------------Index buffers-----------------------------------------------------*

View File

@ -283,7 +283,7 @@ void Gfx_EndFrame(void) {
void Gfx_OnWindowResize(void) { }
void Gfx_UpdateViewport(void) { }
void Gfx_SetViewport(int x, int y, int w, int h) { }
static cc_uint8* gfx_vertices;

View File

@ -811,7 +811,7 @@ void Gfx_EndFrame(void) {
void Gfx_OnWindowResize(void) { }
void Gfx_UpdateViewport(void) { }
void Gfx_SetViewport(int x, int y, int w, int h) { }
/*########################################################################################################################*

View File

@ -435,7 +435,7 @@ void Gfx_OnWindowResize(void) {
// TODO
}
void Gfx_UpdateViewport(void) { }
void Gfx_SetViewport(int x, int y, int w, int h) { }
void Gfx_GetApiInfo(cc_string* info) {
String_AppendConst(info, "-- Using Saturn --\n");

View File

@ -491,7 +491,7 @@ void Gfx_OnWindowResize(void) {
colorBuffer = fb_bmp.scan0;
}
void Gfx_UpdateViewport(void) { }
void Gfx_SetViewport(int x, int y, int w, int h) { }
void Gfx_GetApiInfo(cc_string* info) {
int pointerSize = sizeof(void*) * 8;

View File

@ -459,7 +459,7 @@ void Gfx_OnWindowResize(void) {
}
void Gfx_UpdateViewport(void) { }
void Gfx_SetViewport(int x, int y, int w, int h) { }
void Gfx_3DS_SetRenderScreen1(enum Screen3DS screen) {
GX2ContextState* tv_state = WHBGfxGetTVContextState();

View File

@ -535,7 +535,7 @@ void Gfx_CalcPerspectiveMatrix(struct Matrix* matrix, float fov, float aspect, f
void Gfx_OnWindowResize(void) { }
void Gfx_UpdateViewport(void) { }
void Gfx_SetViewport(int x, int y, int w, int h) { }
static struct Matrix _view, _proj, _mvp;

View File

@ -403,5 +403,5 @@ void Gfx_OnWindowResize(void) {
}
void Gfx_UpdateViewport(void) { }
void Gfx_SetViewport(int x, int y, int w, int h) { }
#endif

View File

@ -325,7 +325,7 @@ void Gfx_EndFrame(void) {
}
void Gfx_OnWindowResize(void) {
Gfx_UpdateViewport();
Gfx_SetViewport(0, 0, Game.Width, Game.Height);
/* 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 */
@ -336,6 +336,6 @@ void Gfx_OnWindowResize(void) {
GLContext_Update();
}
void Gfx_UpdateViewport(void) {
glViewport(Gfx.ViewportX, Gfx.ViewportY, Gfx.ViewportWidth, Gfx.ViewportHeight);
void Gfx_SetViewport(int x, int y, int w, int h) {
glViewport(x, y, w, h);
}