Skip to content

Commit

Permalink
WIP: Widescreen Video Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Fancy2209 authored Feb 4, 2025
1 parent 7f07fe1 commit 6dd2094
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/video/ogc/SDL_ogcgxcommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ static const f32 tex_pos[] __attribute__((aligned(32))) = {
1.0,
};

void OGC_set_viewport(int x, int y, int w, int h)
void OGC_set_viewport(int x, int y, int w, int h, int orthoWidth);
{
Mtx44 proj;

GX_SetViewport(x, y, w, h, 0, 1);
GX_SetScissor(x, y, w, h);

// matrix, t, b, l, r, n, f
guOrtho(proj, 0, h, 0, w, 0, 1);
guOrtho(proj, 0, h, 0, orthoWidth, 0, 1);
GX_LoadProjectionMtx(proj, GX_ORTHOGRAPHIC);
}

void OGC_draw_init(int w, int h)
void OGC_draw_init(int w, int h, int orthoWidth)
{
Mtx mv;

Expand Down Expand Up @@ -86,7 +86,7 @@ void OGC_draw_init(int w, int h)
GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);

OGC_set_viewport(0, 0, w, h);
OGC_set_viewport(0, 0, w, h, orthoWidth);

GX_InvVtxCache(); // update vertex cache
}
Expand Down
44 changes: 38 additions & 6 deletions src/video/ogc/SDL_ogcvideo.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <ogc/gx.h>
#include <ogc/system.h>
#include <ogc/video.h>
#include <ogc/conf.h>

#include <opengx.h>

Expand All @@ -51,6 +52,7 @@

/* A video mode with a 320 width; we'll build it programmatically. */
static GXRModeObj s_mode320;
static GXRModeObj s_mode704;

static const GXRModeObj *s_ntsc_modes[] = {
&TVNtsc240Ds,
Expand Down Expand Up @@ -85,14 +87,14 @@ static const GXRModeObj *s_pal_modes[] = {
static int OGC_VideoInit(_THIS);
static void OGC_VideoQuit(_THIS);

static void init_display_mode(SDL_DisplayMode *mode, const GXRModeObj *vmode)
static void init_display_mode(SDL_DisplayMode *mode, const GXRModeObj *vmode, int width = NULL)
{
u32 format = VI_FORMAT_FROM_MODE(vmode->viTVMode);

/* Use a fake 32-bpp desktop mode */
SDL_zero(*mode);
mode->format = SDL_PIXELFORMAT_ARGB8888;
mode->w = vmode->fbWidth;
width == NULL ? mode->w = vmode->fbWidth : mode->w = width;
mode->h = vmode->efbHeight;
switch (format) {
case VI_DEBUG:
Expand Down Expand Up @@ -145,6 +147,36 @@ static void add_supported_modes(SDL_VideoDisplay *display, u32 tv_format)
init_display_mode(&mode, &s_mode320);
SDL_AddDisplayMode(display, &mode);

// libogc uses 640 for the viWidth, but this does not work well for Widescreen
// as such we extend the viWidth to 704 on a new videomode
// TODO: Currently ony added on wii if it's widescreen,
// but should work on GC and a 4:3 Wii
// testing needed

#ifdef __wii__
if(CONF_GetAspectRatio() == CONF_ASPECT_16_9)
{
memcpy(&s_mode704, gx_modes[1], sizeof(s_mode704));
s_mode704.viWidth = 704;

// set Center point
if (s_mode704 == &TVPal576IntDfScale || s_mode704 == &TVPal576ProgScale)
{
s_mode704->viXOrigin = (VI_MAX_WIDTH_PAL - s_mode704->viWidth) / 2;
s_mode704->viYOrigin = (VI_MAX_HEIGHT_PAL - s_mode704->viHeight) / 2;
}
else
{
s_mode704->viXOrigin = (VI_MAX_WIDTH_NTSC - s_mode704->viWidth) / 2;
s_mode704->viYOrigin = (VI_MAX_HEIGHT_NTSC - s_mode704->viHeight) / 2;
}

// Widescreen is anamorphic, so we provide a different width for the ortho projection
init_display_mode(&mode, &s_mode704, 854);
SDL_AddDisplayMode(display, &mode);
}
#endif

/* Now add all the "standard" modes from libogc */
while (*gx_modes) {
init_display_mode(&mode, *gx_modes);
Expand All @@ -153,7 +185,7 @@ static void add_supported_modes(SDL_VideoDisplay *display, u32 tv_format)
}
}

static void setup_video_mode(_THIS, GXRModeObj *vmode)
static void setup_video_mode(_THIS, GXRModeObj *vmode, SDL_DisplayMode *mode)
{
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;

Expand All @@ -180,7 +212,7 @@ static void setup_video_mode(_THIS, GXRModeObj *vmode)
GX_SetFieldMode(vmode->field_rendering,
((vmode->viHeight == 2 * vmode->xfbHeight) ? GX_ENABLE : GX_DISABLE));

OGC_draw_init(vmode->fbWidth, vmode->efbHeight);
OGC_draw_init(vmode->fbWidth, vmode->efbHeight, mode==NULL ? vmode->fbWidth : mode->w);
}

static int OGC_SetDisplayMode(_THIS, SDL_VideoDisplay *display,
Expand All @@ -195,7 +227,7 @@ static int OGC_SetDisplayMode(_THIS, SDL_VideoDisplay *display,
if (videodata->xfb[1])
free(MEM_K1_TO_K0(videodata->xfb[1]));

setup_video_mode(_this, vmode);
setup_video_mode(_this, vmode, mode);
return 0;
}

Expand Down Expand Up @@ -282,7 +314,7 @@ int OGC_VideoInit(_THIS)
memset(videodata->gp_fifo, 0, DEFAULT_FIFO_SIZE);
GX_Init(videodata->gp_fifo, DEFAULT_FIFO_SIZE);

setup_video_mode(_this, vmode);
setup_video_mode(_this, vmode, NULL);
GX_SetCopyClear(background, GX_MAX_Z24);

GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
Expand Down

0 comments on commit 6dd2094

Please sign in to comment.