From 6f5500d4e85613b4176e9afd3cf1b53df1aa77f9 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 25 Apr 2024 22:07:33 +1000 Subject: [PATCH] Dreamcast: WIP on split screen support --- src/Graphics_Dreamcast.c | 6 ++++++ third_party/gldc/src/sh4.c | 4 ++-- third_party/gldc/src/state.c | 16 +++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Graphics_Dreamcast.c b/src/Graphics_Dreamcast.c index e1a91a258..b0fce28ce 100644 --- a/src/Graphics_Dreamcast.c +++ b/src/Graphics_Dreamcast.c @@ -559,6 +559,12 @@ void Gfx_OnWindowResize(void) { } void Gfx_SetViewport(int x, int y, int w, int h) { + if (x == 0 && y == 0 && w == Game.Width && h == Game.Height) { + glDisable(GL_SCISSOR_TEST); + } else { + glEnable(GL_SCISSOR_TEST); + } + glViewport(x, y, w, h); glScissor (x, y, w, h); } diff --git a/third_party/gldc/src/sh4.c b/third_party/gldc/src/sh4.c index c535d6556..54e42c9b5 100644 --- a/third_party/gldc/src/sh4.c +++ b/third_party/gldc/src/sh4.c @@ -45,8 +45,8 @@ GL_FORCE_INLINE void _glPerspectiveDivideVertex(Vertex* vertex) { const float f = _glFastInvert(vertex->w); /* Convert to NDC and apply viewport */ - vertex->xyz[0] = (vertex->xyz[0] * f * 320) + 320; - vertex->xyz[1] = (vertex->xyz[1] * f * -240) + 240; + vertex->xyz[0] = (vertex->xyz[0] * f * VIEWPORT.hwidth) + VIEWPORT.x_plus_hwidth; + vertex->xyz[1] = (vertex->xyz[1] * f * VIEWPORT.hheight) + VIEWPORT.y_plus_hheight; /* Orthographic projections need to use invZ otherwise we lose the depth information. As w == 1, and clip-space range is -w to +w diff --git a/third_party/gldc/src/state.c b/third_party/gldc/src/state.c index 5b2332c22..5f6cd1400 100644 --- a/third_party/gldc/src/state.c +++ b/third_party/gldc/src/state.c @@ -253,20 +253,14 @@ void APIENTRY glGetIntegerv(GLenum pname, GLint *params) { } -Viewport VIEWPORT = { - 0, 0, 640, 480, 320.0f, 240.0f, 320.0f, 240.0f -}; +Viewport VIEWPORT; /* Set the GL viewport */ void APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height) { - VIEWPORT.x = x; - VIEWPORT.y = y; - VIEWPORT.width = width; - VIEWPORT.height = height; - VIEWPORT.hwidth = ((GLfloat) VIEWPORT.width) * 0.5f; - VIEWPORT.hheight = ((GLfloat) VIEWPORT.height) * 0.5f; - VIEWPORT.x_plus_hwidth = VIEWPORT.x + VIEWPORT.hwidth; - VIEWPORT.y_plus_hheight = VIEWPORT.y + VIEWPORT.hheight; + VIEWPORT.hwidth = ((GLfloat)width) * 0.5f; + VIEWPORT.hheight = ((GLfloat)height) * -0.5f; + VIEWPORT.x_plus_hwidth = x + VIEWPORT.hwidth; + VIEWPORT.y_plus_hheight = y + VIEWPORT.hheight; }