mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
Simplify viewport setting
This commit is contained in:
parent
791e96ed2d
commit
c7fd3a05f9
@ -639,11 +639,7 @@ static CC_INLINE void Game_DrawFrame(double delta, float t) {
|
|||||||
|
|
||||||
#ifdef CC_BUILD_SPLITSCREEN
|
#ifdef CC_BUILD_SPLITSCREEN
|
||||||
static void DrawSplitscreen(double delta, float t, int i, int x, int y, int w, int h) {
|
static void DrawSplitscreen(double delta, float t, int i, int x, int y, int w, int h) {
|
||||||
Gfx.ViewportX = x;
|
Gfx_SetViewport(x, y, w, h);
|
||||||
Gfx.ViewportY = y;
|
|
||||||
Gfx.ViewportWidth = w;
|
|
||||||
Gfx.ViewportHeight = h;
|
|
||||||
Gfx_UpdateViewport();
|
|
||||||
|
|
||||||
Entities.CurPlayer = &LocalPlayer_Instances[i];
|
Entities.CurPlayer = &LocalPlayer_Instances[i];
|
||||||
LocalPlayer_SetInterpPosition(Entities.CurPlayer, t);
|
LocalPlayer_SetInterpPosition(Entities.CurPlayer, t);
|
||||||
|
@ -66,7 +66,6 @@ CC_VAR extern struct _GfxData {
|
|||||||
int MinTexWidth, MinTexHeight;
|
int MinTexWidth, MinTexHeight;
|
||||||
cc_bool ReducedPerfMode;
|
cc_bool ReducedPerfMode;
|
||||||
cc_uint8 ReducedPerfModeCooldown;
|
cc_uint8 ReducedPerfModeCooldown;
|
||||||
int ViewportX, ViewportY, ViewportWidth, ViewportHeight;
|
|
||||||
} Gfx;
|
} Gfx;
|
||||||
|
|
||||||
extern GfxResourceID Gfx_defaultIb;
|
extern GfxResourceID Gfx_defaultIb;
|
||||||
@ -254,7 +253,7 @@ void Gfx_GetApiInfo(cc_string* info);
|
|||||||
/* Updates state when the window's dimensions have changed */
|
/* Updates state when the window's dimensions have changed */
|
||||||
/* NOTE: This may require recreating the context depending on the backend */
|
/* NOTE: This may require recreating the context depending on the backend */
|
||||||
void Gfx_OnWindowResize(void);
|
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 };
|
enum Screen3DS { TOP_SCREEN, BOTTOM_SCREEN };
|
||||||
#ifdef CC_BUILD_DUALSCREEN
|
#ifdef CC_BUILD_DUALSCREEN
|
||||||
|
@ -575,7 +575,7 @@ void Gfx_EndFrame(void) {
|
|||||||
|
|
||||||
void Gfx_OnWindowResize(void) { }
|
void Gfx_OnWindowResize(void) { }
|
||||||
|
|
||||||
void Gfx_UpdateViewport(void) { }
|
void Gfx_SetViewport(int x, int y, int w, int h) { }
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
|
@ -646,12 +646,12 @@ static void RS_CreateRasterState(void) {
|
|||||||
ID3D11Device_CreateRasterizerState(device, &desc, &rs_states[1]);
|
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;
|
D3D11_VIEWPORT viewport;
|
||||||
viewport.TopLeftX = Gfx.ViewportX;
|
viewport.TopLeftX = x;
|
||||||
viewport.TopLeftY = Gfx.ViewportY;
|
viewport.TopLeftY = y;
|
||||||
viewport.Width = Gfx.ViewportWidth;
|
viewport.Width = w;
|
||||||
viewport.Height = Gfx.ViewportHeight;
|
viewport.Height = h;
|
||||||
viewport.MinDepth = 0.0f;
|
viewport.MinDepth = 0.0f;
|
||||||
viewport.MaxDepth = 1.0f;
|
viewport.MaxDepth = 1.0f;
|
||||||
ID3D11DeviceContext_RSSetViewports(context, 1, &viewport);
|
ID3D11DeviceContext_RSSetViewports(context, 1, &viewport);
|
||||||
@ -670,7 +670,7 @@ static void RS_FreeRasterStates(void) {
|
|||||||
|
|
||||||
static void RS_Init(void) {
|
static void RS_Init(void) {
|
||||||
RS_CreateRasterState();
|
RS_CreateRasterState();
|
||||||
RS_UpdateViewport();
|
Gfx_SetViewport(0, 0, Game.Width, Game.Height);
|
||||||
RS_UpdateRasterState();
|
RS_UpdateRasterState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1173,11 +1173,7 @@ void Gfx_OnWindowResize(void) {
|
|||||||
if (hr) Logger_Abort2(hr, "Failed to resize swapchain");
|
if (hr) Logger_Abort2(hr, "Failed to resize swapchain");
|
||||||
|
|
||||||
OM_InitTargets();
|
OM_InitTargets();
|
||||||
RS_UpdateViewport();
|
Gfx_SetViewport(0, 0, Game.Width, Game.Height);
|
||||||
}
|
|
||||||
|
|
||||||
void Gfx_UpdateViewport(void) {
|
|
||||||
RS_UpdateViewport();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InitPipeline(void) {
|
static void InitPipeline(void) {
|
||||||
|
@ -887,5 +887,5 @@ void Gfx_OnWindowResize(void) {
|
|||||||
UpdateSwapchain(" (resizing window)");
|
UpdateSwapchain(" (resizing window)");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_UpdateViewport(void) { }
|
void Gfx_SetViewport(int x, int y, int w, int h) { }
|
||||||
#endif
|
#endif
|
||||||
|
@ -30,7 +30,7 @@ static void InitGLState(void) {
|
|||||||
|
|
||||||
void Gfx_Create(void) {
|
void Gfx_Create(void) {
|
||||||
if (!Gfx.Created) glKosInit();
|
if (!Gfx.Created) glKosInit();
|
||||||
Gfx_UpdateViewport();
|
Gfx_SetViewport(0, 0, Game.Width, Game.Height);
|
||||||
InitGLState();
|
InitGLState();
|
||||||
|
|
||||||
Gfx.MinTexWidth = 8;
|
Gfx.MinTexWidth = 8;
|
||||||
@ -555,11 +555,11 @@ void Gfx_EndFrame(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_OnWindowResize(void) {
|
void Gfx_OnWindowResize(void) {
|
||||||
Gfx_UpdateViewport();
|
Gfx_SetViewport(0, 0, Game.Width, Game.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_UpdateViewport(void) {
|
void Gfx_SetViewport(int x, int y, int w, int h) {
|
||||||
glViewport(Gfx.ViewportX, Gfx.ViewportY, Gfx.ViewportWidth, Gfx.ViewportHeight);
|
glViewport(x, y, w, h);
|
||||||
glScissor (Gfx.ViewportX, Gfx.ViewportY, Gfx.ViewportWidth, Gfx.ViewportHeight);
|
glScissor (x, y, w, h);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -312,7 +312,7 @@ void Gfx_EndFrame(void) {
|
|||||||
|
|
||||||
void Gfx_OnWindowResize(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; }
|
cc_bool Gfx_WarnIfNecessary(void) { return false; }
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
|
|||||||
|
|
||||||
void Gfx_OnWindowResize(void) { }
|
void Gfx_OnWindowResize(void) { }
|
||||||
|
|
||||||
void Gfx_UpdateViewport(void) { }
|
void Gfx_SetViewport(int x, int y, int w, int h) { }
|
||||||
|
|
||||||
|
|
||||||
void Gfx_BeginFrame(void) {
|
void Gfx_BeginFrame(void) {
|
||||||
|
@ -66,7 +66,7 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
|
|||||||
void Gfx_OnWindowResize(void) {
|
void Gfx_OnWindowResize(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_UpdateViewport(void) { }
|
void Gfx_SetViewport(int x, int y, int w, int h) { }
|
||||||
|
|
||||||
void Gfx_BeginFrame(void) {
|
void Gfx_BeginFrame(void) {
|
||||||
}
|
}
|
||||||
|
@ -727,7 +727,7 @@ void Gfx_OnWindowResize(void) {
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_UpdateViewport(void) { }
|
void Gfx_SetViewport(int x, int y, int w, int h) { }
|
||||||
|
|
||||||
void Gfx_GetApiInfo(cc_string* info) {
|
void Gfx_GetApiInfo(cc_string* info) {
|
||||||
String_AppendConst(info, "-- Using PS1 --\n");
|
String_AppendConst(info, "-- Using PS1 --\n");
|
||||||
|
@ -671,7 +671,7 @@ void Gfx_OnWindowResize(void) {
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_UpdateViewport(void) { }
|
void Gfx_SetViewport(int x, int y, int w, int h) { }
|
||||||
|
|
||||||
void Gfx_GetApiInfo(cc_string* info) {
|
void Gfx_GetApiInfo(cc_string* info) {
|
||||||
String_AppendConst(info, "-- Using PS2 --\n");
|
String_AppendConst(info, "-- Using PS2 --\n");
|
||||||
|
@ -414,7 +414,7 @@ static void ResetFrameState(void) {
|
|||||||
GCM_USER_CLIP_PLANE_DISABLE);
|
GCM_USER_CLIP_PLANE_DISABLE);
|
||||||
|
|
||||||
// NOTE: Must be called each frame, otherwise renders upside down at 4x zoom
|
// 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
|
// 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) {
|
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];
|
f32 scale[4], offset[4];
|
||||||
|
|
||||||
u16 w = DisplayInfo.Width;
|
|
||||||
u16 h = DisplayInfo.Height;
|
|
||||||
f32 zmin = 0.0f;
|
f32 zmin = 0.0f;
|
||||||
f32 zmax = 1.0f;
|
f32 zmax = 1.0f;
|
||||||
|
y = Game.Height - y - h;
|
||||||
|
|
||||||
scale[0] = w * 0.5f;
|
scale[0] = w * 0.5f;
|
||||||
scale[1] = h * -0.5f;
|
scale[1] = h * -0.5f;
|
||||||
scale[2] = (zmax - zmin) * 0.5f;
|
scale[2] = (zmax - zmin) * 0.5f;
|
||||||
scale[3] = 0.0f;
|
scale[3] = 0.0f;
|
||||||
offset[0] = w * 0.5f;
|
offset[0] = x + w * 0.5f;
|
||||||
offset[1] = h * 0.5f;
|
offset[1] = x + h * 0.5f;
|
||||||
offset[2] = (zmax + zmin) * 0.5f;
|
offset[2] = (zmax + zmin) * 0.5f;
|
||||||
offset[3] = 0.0f;
|
offset[3] = 0.0f;
|
||||||
|
|
||||||
rsxSetViewport(context, 0, 0, w, h, zmin, zmax, scale, offset);
|
rsxSetViewport(context, x, y, w, h, zmin, zmax, scale, offset);
|
||||||
rsxSetScissor(context, 0, 0, w, h);
|
rsxSetScissor(context, x, y, w, h);
|
||||||
|
|
||||||
// TODO: even needed?
|
// TODO: even needed?
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++)
|
||||||
@ -476,8 +478,6 @@ void Gfx_OnWindowResize(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_UpdateViewport(void) { }
|
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-------------------------------------------------------Index buffers-----------------------------------------------------*
|
*-------------------------------------------------------Index buffers-----------------------------------------------------*
|
||||||
|
@ -283,7 +283,7 @@ void Gfx_EndFrame(void) {
|
|||||||
|
|
||||||
void Gfx_OnWindowResize(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;
|
static cc_uint8* gfx_vertices;
|
||||||
|
@ -811,7 +811,7 @@ void Gfx_EndFrame(void) {
|
|||||||
|
|
||||||
void Gfx_OnWindowResize(void) { }
|
void Gfx_OnWindowResize(void) { }
|
||||||
|
|
||||||
void Gfx_UpdateViewport(void) { }
|
void Gfx_SetViewport(int x, int y, int w, int h) { }
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
|
@ -435,7 +435,7 @@ void Gfx_OnWindowResize(void) {
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_UpdateViewport(void) { }
|
void Gfx_SetViewport(int x, int y, int w, int h) { }
|
||||||
|
|
||||||
void Gfx_GetApiInfo(cc_string* info) {
|
void Gfx_GetApiInfo(cc_string* info) {
|
||||||
String_AppendConst(info, "-- Using Saturn --\n");
|
String_AppendConst(info, "-- Using Saturn --\n");
|
||||||
|
@ -491,7 +491,7 @@ void Gfx_OnWindowResize(void) {
|
|||||||
colorBuffer = fb_bmp.scan0;
|
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) {
|
void Gfx_GetApiInfo(cc_string* info) {
|
||||||
int pointerSize = sizeof(void*) * 8;
|
int pointerSize = sizeof(void*) * 8;
|
||||||
|
@ -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) {
|
void Gfx_3DS_SetRenderScreen1(enum Screen3DS screen) {
|
||||||
GX2ContextState* tv_state = WHBGfxGetTVContextState();
|
GX2ContextState* tv_state = WHBGfxGetTVContextState();
|
||||||
|
@ -535,7 +535,7 @@ void Gfx_CalcPerspectiveMatrix(struct Matrix* matrix, float fov, float aspect, f
|
|||||||
|
|
||||||
void Gfx_OnWindowResize(void) { }
|
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;
|
static struct Matrix _view, _proj, _mvp;
|
||||||
|
|
||||||
|
@ -403,5 +403,5 @@ void Gfx_OnWindowResize(void) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_UpdateViewport(void) { }
|
void Gfx_SetViewport(int x, int y, int w, int h) { }
|
||||||
#endif
|
#endif
|
||||||
|
@ -325,7 +325,7 @@ void Gfx_EndFrame(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_OnWindowResize(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 */
|
/* 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 */
|
||||||
@ -336,6 +336,6 @@ void Gfx_OnWindowResize(void) {
|
|||||||
GLContext_Update();
|
GLContext_Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_UpdateViewport(void) {
|
void Gfx_SetViewport(int x, int y, int w, int h) {
|
||||||
glViewport(Gfx.ViewportX, Gfx.ViewportY, Gfx.ViewportWidth, Gfx.ViewportHeight);
|
glViewport(x, y, w, h);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user