diff --git a/src/Game.c b/src/Game.c index 3d9cfded0..2af32274e 100644 --- a/src/Game.c +++ b/src/Game.c @@ -638,6 +638,7 @@ static CC_INLINE void Game_DrawFrame(float delta, float t) { #ifdef CC_BUILD_SPLITSCREEN static void DrawSplitscreen(float delta, float t, int i, int x, int y, int w, int h) { Gfx_SetViewport(x, y, w, h); + Gfx_SetScissor( x, y, w, h); Entities.CurPlayer = &LocalPlayer_Instances[i]; LocalPlayer_SetInterpPosition(Entities.CurPlayer, t); diff --git a/src/Graphics.h b/src/Graphics.h index b84e1dc0c..c6cc9fae9 100644 --- a/src/Graphics.h +++ b/src/Graphics.h @@ -254,6 +254,7 @@ void Gfx_GetApiInfo(cc_string* info); /* NOTE: This may require recreating the context depending on the backend */ void Gfx_OnWindowResize(void); void Gfx_SetViewport(int x, int y, int w, int h); +void Gfx_SetScissor (int x, int y, int w, int h); enum Screen3DS { TOP_SCREEN, BOTTOM_SCREEN }; #ifdef CC_BUILD_DUALSCREEN diff --git a/src/Graphics_3DS.c b/src/Graphics_3DS.c index 443380311..9c73069c4 100644 --- a/src/Graphics_3DS.c +++ b/src/Graphics_3DS.c @@ -589,6 +589,7 @@ void Gfx_EndFrame(void) { void Gfx_OnWindowResize(void) { } void Gfx_SetViewport(int x, int y, int w, int h) { } +void Gfx_SetScissor (int x, int y, int w, int h) { } /*########################################################################################################################* diff --git a/src/Graphics_D3D9.c b/src/Graphics_D3D9.c index 91ef33a58..7f0a14bc9 100644 --- a/src/Graphics_D3D9.c +++ b/src/Graphics_D3D9.c @@ -881,5 +881,14 @@ void Gfx_OnWindowResize(void) { UpdateSwapchain(" (resizing window)"); } -void Gfx_SetViewport(int x, int y, int w, int h) { } +void Gfx_SetViewport(int x, int y, int w, int h) { + D3DVIEWPORT9 vp; + vp.X = x; + vp.Y = y; + vp.Width = w; + vp.Height = h; + vp.MinZ = 0.0f; + vp.MaxZ = 1.0f; + IDirect3DDevice9_SetViewport(device, &vp); +} #endif diff --git a/src/Graphics_Dreamcast.c b/src/Graphics_Dreamcast.c index 58d4d7190..f51cedf59 100644 --- a/src/Graphics_Dreamcast.c +++ b/src/Graphics_Dreamcast.c @@ -52,7 +52,6 @@ void Gfx_Create(void) { if (!Gfx.Created) InitPowerVR(); if (!Gfx.Created) glKosInit(); - Gfx_SetViewport(0, 0, Game.Width, Game.Height); InitGLState(); Gfx.MinTexWidth = 8; diff --git a/src/Graphics_GCWii.c b/src/Graphics_GCWii.c index b79cff61b..14b838fb6 100644 --- a/src/Graphics_GCWii.c +++ b/src/Graphics_GCWii.c @@ -29,6 +29,8 @@ static void InitGX(void) { GX_Init(fifo_buffer, FIFO_SIZE); Gfx_SetViewport(0, 0, mode->fbWidth, mode->efbHeight); + Gfx_SetScissor( 0, 0, mode->fbWidth, mode->efbHeight); + GX_SetDispCopyYScale((f32)mode->xfbHeight / (f32)mode->efbHeight); GX_SetDispCopySrc(0, 0, mode->fbWidth, mode->efbHeight); GX_SetDispCopyDst(mode->fbWidth, mode->xfbHeight); @@ -316,6 +318,9 @@ void Gfx_OnWindowResize(void) { } void Gfx_SetViewport(int x, int y, int w, int h) { GX_SetViewport(x, y, w, h, 0, 1); +} + +void Gfx_SetScissor(int x, int y, int w, int h) { GX_SetScissor(x, y, w, h); } diff --git a/src/Graphics_N64.c b/src/Graphics_N64.c index b895cb94b..00c620513 100644 --- a/src/Graphics_N64.c +++ b/src/Graphics_N64.c @@ -80,6 +80,7 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) { void Gfx_OnWindowResize(void) { } void Gfx_SetViewport(int x, int y, int w, int h) { } +void Gfx_SetScissor (int x, int y, int w, int h) { } void Gfx_BeginFrame(void) { diff --git a/src/Graphics_NDS.c b/src/Graphics_NDS.c index d01cb0929..903d4106e 100644 --- a/src/Graphics_NDS.c +++ b/src/Graphics_NDS.c @@ -69,6 +69,7 @@ void Gfx_OnWindowResize(void) { } void Gfx_SetViewport(int x, int y, int w, int h) { } +void Gfx_SetScissor (int x, int y, int w, int h) { } void Gfx_BeginFrame(void) { } diff --git a/src/Graphics_PS1.c b/src/Graphics_PS1.c index c841e00bf..eced7fcf3 100644 --- a/src/Graphics_PS1.c +++ b/src/Graphics_PS1.c @@ -858,6 +858,7 @@ void Gfx_OnWindowResize(void) { } void Gfx_SetViewport(int x, int y, int w, int h) { } +void Gfx_SetScissor (int x, int y, int w, int h) { } void Gfx_GetApiInfo(cc_string* info) { String_AppendConst(info, "-- Using PS1 --\n"); diff --git a/src/Graphics_PS2.c b/src/Graphics_PS2.c index 5726a37f0..9ca3c30a7 100644 --- a/src/Graphics_PS2.c +++ b/src/Graphics_PS2.c @@ -126,7 +126,6 @@ void Gfx_Create(void) { formatDirty = true; InitDrawingEnv(); InitDMABuffers(); - Gfx_SetViewport(0, 0, Window_Main.Width, Window_Main.Height); tex_offset = graph_vram_allocate(256, 256, GS_PSM_32, GRAPH_ALIGN_BLOCK); context = 1; @@ -803,7 +802,8 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) { } void Gfx_OnWindowResize(void) { - // TODO + Gfx_SetViewport(0, 0, Game.Width, Game.Height); + Gfx_SetScissor( 0, 0, Game.Width, Game.Height); } void Gfx_SetViewport(int x, int y, int w, int h) { @@ -811,7 +811,9 @@ void Gfx_SetViewport(int x, int y, int w, int h) { vp_hheight = h / 2; vp_x_hwidth = x + vp_hwidth; vp_y_hheight = y + vp_hheight; +} +void Gfx_SetScissor(int x, int y, int w, int h) { int context = 0; PACK_GIFTAG(q, GIF_SET_TAG(1,0,0,0, GIF_FLG_PACKED, 1), GIF_REG_AD); diff --git a/src/Graphics_PS3.c b/src/Graphics_PS3.c index 4fec40db1..0c64a84bb 100644 --- a/src/Graphics_PS3.c +++ b/src/Graphics_PS3.c @@ -406,6 +406,7 @@ static void ResetFrameState(void) { // NOTE: Must be called each frame, otherwise renders upside down at 4x zoom Gfx_SetViewport(0, 0, Game.Width, Game.Height); + Gfx_SetScissor (0, 0, Game.Width, Game.Height); } // https://github.com/ps3dev/PSL1GHT/blob/master/ppu/include/rsx/rsx.h#L30 @@ -442,6 +443,7 @@ void Gfx_EndFrame(void) { void Gfx_OnWindowResize(void) { Gfx_SetViewport(0, 0, Game.Width, Game.Height); + Gfx_SetScissor (0, 0, Game.Width, Game.Height); } void Gfx_SetViewport(int x, int y, int w, int h) { @@ -460,7 +462,6 @@ void Gfx_SetViewport(int x, int y, int w, int h) { offset[3] = 0.0f; 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++) @@ -469,6 +470,10 @@ void Gfx_SetViewport(int x, int y, int w, int h) { } } +void Gfx_SetScissor(int x, int y, int w, int h) { + rsxSetScissor(context, x, y, w, h); +} + /*########################################################################################################################* *-------------------------------------------------------Index buffers-----------------------------------------------------* diff --git a/src/Graphics_PSP.c b/src/Graphics_PSP.c index 6ed8efc8a..ccf21bb95 100644 --- a/src/Graphics_PSP.c +++ b/src/Graphics_PSP.c @@ -284,6 +284,7 @@ void Gfx_EndFrame(void) { void Gfx_OnWindowResize(void) { } void Gfx_SetViewport(int x, int y, int w, int h) { } +void Gfx_SetScissor (int x, int y, int w, int h) { } static cc_uint8* gfx_vertices; diff --git a/src/Graphics_PSVita.c b/src/Graphics_PSVita.c index a9a1b9c43..ba5c8dfec 100644 --- a/src/Graphics_PSVita.c +++ b/src/Graphics_PSVita.c @@ -822,6 +822,7 @@ void Gfx_EndFrame(void) { void Gfx_OnWindowResize(void) { } void Gfx_SetViewport(int x, int y, int w, int h) { } +void Gfx_SetScissor (int x, int y, int w, int h) { } /*########################################################################################################################* diff --git a/src/Graphics_Saturn.c b/src/Graphics_Saturn.c index e91937d68..123657aaf 100644 --- a/src/Graphics_Saturn.c +++ b/src/Graphics_Saturn.c @@ -555,6 +555,7 @@ void Gfx_OnWindowResize(void) { } void Gfx_SetViewport(int x, int y, int w, int h) { } +void Gfx_SetScissor (int x, int y, int w, int h) { } void Gfx_GetApiInfo(cc_string* info) { String_AppendConst(info, "-- Using Saturn --\n"); diff --git a/src/Graphics_SoftGPU.c b/src/Graphics_SoftGPU.c index 79e4a69c0..a6175688c 100644 --- a/src/Graphics_SoftGPU.c +++ b/src/Graphics_SoftGPU.c @@ -947,6 +947,7 @@ void Gfx_OnWindowResize(void) { } void Gfx_SetViewport(int x, int y, int w, int h) { } +void Gfx_SetScissor (int x, int y, int w, int h) { } void Gfx_GetApiInfo(cc_string* info) { int pointerSize = sizeof(void*) * 8; diff --git a/src/Graphics_WiiU.c b/src/Graphics_WiiU.c index ea565fa6c..169f95f9d 100644 --- a/src/Graphics_WiiU.c +++ b/src/Graphics_WiiU.c @@ -468,8 +468,11 @@ void Gfx_OnWindowResize(void) { } void Gfx_SetViewport(int x, int y, int w, int h) { - GX2SetViewport(x, y, w, h, 0.0f, 1.0f); - GX2SetScissor( x, y, w, h); + GX2SetViewport(x, y, w, h, 0.0f, 1.0f); +} + +void Gfx_SetScissor(int x, int y, int w, int h) { + GX2SetScissor( x, y, w, h); } void Gfx_3DS_SetRenderScreen1(enum Screen3DS screen) { diff --git a/src/Graphics_Xbox.c b/src/Graphics_Xbox.c index 6fcdedb51..92e802c76 100644 --- a/src/Graphics_Xbox.c +++ b/src/Graphics_Xbox.c @@ -590,19 +590,19 @@ void Gfx_DisableTextureOffset(void) { } void Gfx_SetViewport(int x, int y, int w, int h) { - vp_scale.x = w * 0.5f; - vp_scale.y = h * -0.5f; - vp_offset.x = x + w * 0.5f; - vp_offset.y = y + h * 0.5f; - - uint32_t* p; - p = pb_begin(); - // NV097_SET_SURFACE_CLIP_HORIZONTAL followed by NV097_SET_SURFACE_CLIP_VERTICAL - p = pb_push2(p, NV097_SET_SURFACE_CLIP_HORIZONTAL, x | (w << 16), y | (h << 16)); - pb_end(p); + vp_scale.x = w * 0.5f; + vp_scale.y = h * -0.5f; + vp_offset.x = x + w * 0.5f; + vp_offset.y = y + h * 0.5f; } - +void Gfx_SetScissor(int x, int y, int w, int h) { + uint32_t* p; + p = pb_begin(); + // NV097_SET_SURFACE_CLIP_HORIZONTAL followed by NV097_SET_SURFACE_CLIP_VERTICAL + p = pb_push2(p, NV097_SET_SURFACE_CLIP_HORIZONTAL, x | (w << 16), y | (h << 16)); + pb_end(p); +} /*########################################################################################################################* diff --git a/src/Graphics_Xbox360.c b/src/Graphics_Xbox360.c index f657f16ca..ae3382615 100644 --- a/src/Graphics_Xbox360.c +++ b/src/Graphics_Xbox360.c @@ -404,4 +404,5 @@ void Gfx_OnWindowResize(void) { } void Gfx_SetViewport(int x, int y, int w, int h) { } +void Gfx_SetScissor (int x, int y, int w, int h) { } #endif