Skip to content

Commit 8eaebcf

Browse files
committed
Adds WIP Widescreen Support
1 parent 7f07fe1 commit 8eaebcf

File tree

5 files changed

+79
-20
lines changed

5 files changed

+79
-20
lines changed

src/render/ogc/SDL_render_ogc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ static int OGC_RenderSetViewPort(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
427427
{
428428
const SDL_Rect *viewport = &cmd->data.viewport.rect;
429429

430-
OGC_set_viewport(viewport->x, viewport->y, viewport->w, viewport->h);
430+
OGC_set_viewport(viewport->x, viewport->y, viewport->w, viewport->h, viewport->w);
431431
return 0;
432432
}
433433

src/video/ogc/SDL_ogcgxcommon.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ static const f32 tex_pos[] __attribute__((aligned(32))) = {
4040
1.0,
4141
};
4242

43-
void OGC_set_viewport(int x, int y, int w, int h)
43+
void OGC_set_viewport(int x, int y, int w, int h, int orthoWidth)
4444
{
4545
Mtx44 proj;
4646

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

5050
// matrix, t, b, l, r, n, f
51-
guOrtho(proj, 0, h, 0, w, 0, 1);
51+
guOrtho(proj, 0, h, 0, orthoWidth, 0, 1);
5252
GX_LoadProjectionMtx(proj, GX_ORTHOGRAPHIC);
5353
}
5454

55-
void OGC_draw_init(int w, int h)
55+
void OGC_draw_init(int w, int h, int orthoWidth)
5656
{
5757
Mtx mv;
5858

@@ -86,7 +86,7 @@ void OGC_draw_init(int w, int h)
8686
GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
8787
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
8888

89-
OGC_set_viewport(0, 0, w, h);
89+
OGC_set_viewport(0, 0, w, h, orthoWidth);
9090

9191
GX_InvVtxCache(); // update vertex cache
9292
}

src/video/ogc/SDL_ogcgxcommon.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
#define GX_COLOR_AS_U32(c) *((u32*)&c)
3131

32-
void OGC_draw_init(int w, int h);
33-
void OGC_set_viewport(int x, int y, int w, int h);
32+
void OGC_draw_init(int w, int h, int orthoWidth);
33+
void OGC_set_viewport(int x, int y, int w, int h, int orthoWidth);
3434
void OGC_load_texture(void *texels, int w, int h, u8 gx_format,
3535
SDL_ScaleMode scale_mode);
3636

src/video/ogc/SDL_ogcmouse.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "SDL_ogcgxcommon.h"
3030
#include "SDL_ogcmouse.h"
3131
#include "SDL_ogcpixels.h"
32+
#include "SDL_ogcvideo.h"
3233

3334
#include "../SDL_sysvideo.h"
3435
#include "../../render/SDL_sysrender.h"
@@ -175,7 +176,7 @@ void OGC_draw_cursor(_THIS)
175176
SDL_Mouse *mouse = SDL_GetMouse();
176177
OGC_CursorData *curdata;
177178
Mtx mv;
178-
int screen_w, screen_h;
179+
int screen_w, screen_h, viewport_w;
179180
float angle = 0.0f;
180181

181182
if (!mouse || !mouse->cursor_shown ||
@@ -191,7 +192,8 @@ void OGC_draw_cursor(_THIS)
191192
if (!data->ir.valid) return;
192193
}
193194

194-
screen_w = _this->displays[0].current_mode.w;
195+
viewport_w = _this->displays[0].current_mode.w;
196+
screen_w = ((SDL_VideoData *)_this->displays[0].current_mode.driverdata)->vmode->fbWidth;
195197
screen_h = _this->displays[0].current_mode.h;
196198

197199
curdata = mouse->cur_cursor->driverdata;
@@ -200,6 +202,7 @@ void OGC_draw_cursor(_THIS)
200202

201203
guMtxIdentity(mv);
202204
guMtxScaleApply(mv, mv, screen_w / 640.0f, screen_h / 480.0f, 1.0f);
205+
203206
if (angle != 0.0f) {
204207
Mtx rot;
205208
guMtxRotDeg(rot, 'z', angle);
@@ -208,7 +211,7 @@ void OGC_draw_cursor(_THIS)
208211
guMtxTransApply(mv, mv, mouse->x, mouse->y, 0);
209212
GX_LoadPosMtxImm(mv, GX_PNMTX1);
210213

211-
OGC_set_viewport(0, 0, screen_w, screen_h);
214+
OGC_set_viewport(0, 0, screen_w, screen_h, viewport_w);
212215

213216
GX_ClearVtxDesc();
214217
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
@@ -240,7 +243,8 @@ void OGC_draw_cursor(_THIS)
240243
SDL_Renderer *renderer = SDL_GetRenderer(_this->windows);
241244
if (renderer) {
242245
OGC_set_viewport(renderer->viewport.x, renderer->viewport.y,
243-
renderer->viewport.w, renderer->viewport.h);
246+
renderer->viewport.w, renderer->viewport.h,
247+
renderer->viewport.w);
244248
}
245249
}
246250
}

src/video/ogc/SDL_ogcvideo.c

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <ogc/gx.h>
4242
#include <ogc/system.h>
4343
#include <ogc/video.h>
44+
#include <ogc/conf.h>
4445

4546
#include <opengx.h>
4647

@@ -51,6 +52,7 @@
5152

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

5557
static const GXRModeObj *s_ntsc_modes[] = {
5658
&TVNtsc240Ds,
@@ -85,14 +87,14 @@ static const GXRModeObj *s_pal_modes[] = {
8587
static int OGC_VideoInit(_THIS);
8688
static void OGC_VideoQuit(_THIS);
8789

88-
static void init_display_mode(SDL_DisplayMode *mode, const GXRModeObj *vmode)
90+
static void init_display_mode(SDL_DisplayMode *mode, const GXRModeObj *vmode, int width)
8991
{
9092
u32 format = VI_FORMAT_FROM_MODE(vmode->viTVMode);
9193

9294
/* Use a fake 32-bpp desktop mode */
9395
SDL_zero(*mode);
9496
mode->format = SDL_PIXELFORMAT_ARGB8888;
95-
mode->w = vmode->fbWidth;
97+
mode->w = width;
9698
mode->h = vmode->efbHeight;
9799
switch (format) {
98100
case VI_DEBUG:
@@ -142,18 +144,48 @@ static void add_supported_modes(SDL_VideoDisplay *display, u32 tv_format)
142144
* take care of the horizontal scale for us. */
143145
memcpy(&s_mode320, gx_modes[0], sizeof(s_mode320));
144146
s_mode320.fbWidth = 320;
145-
init_display_mode(&mode, &s_mode320);
147+
init_display_mode(&mode, &s_mode320, s_mode320.fbWidth);
146148
SDL_AddDisplayMode(display, &mode);
147149

150+
// libogc uses 640 for the viWidth, but this does not work well for Widescreen
151+
// as such we extend the viWidth to 704 on a new videomode
152+
// TODO: Currently ony added on wii if it's widescreen,
153+
// but should work on GC and a 4:3 Wii
154+
// testing needed
155+
156+
#ifdef __wii__
157+
if(CONF_GetAspectRatio() == CONF_ASPECT_16_9)
158+
{
159+
memcpy(&s_mode704, gx_modes[1], sizeof(s_mode704));
160+
s_mode704.viWidth = 704;
161+
162+
// set Center point
163+
if (&s_mode704 == &TVPal576IntDfScale || &s_mode704 == &TVPal576ProgScale)
164+
{
165+
s_mode704.viXOrigin = (VI_MAX_WIDTH_PAL - s_mode704.viWidth) / 2;
166+
s_mode704.viYOrigin = (VI_MAX_HEIGHT_PAL - s_mode704.viHeight) / 2;
167+
}
168+
else
169+
{
170+
s_mode704.viXOrigin = (VI_MAX_WIDTH_NTSC - s_mode704.viWidth) / 2;
171+
s_mode704.viYOrigin = (VI_MAX_HEIGHT_NTSC - s_mode704.viHeight) / 2;
172+
}
173+
174+
// Widescreen is anamorphic, so we provide a different width for the ortho projection
175+
init_display_mode(&mode, &s_mode704, 854);
176+
SDL_AddDisplayMode(display, &mode);
177+
}
178+
#endif
179+
148180
/* Now add all the "standard" modes from libogc */
149181
while (*gx_modes) {
150-
init_display_mode(&mode, *gx_modes);
182+
init_display_mode(&mode, *gx_modes, (*gx_modes)->fbWidth);
151183
SDL_AddDisplayMode(display, &mode);
152184
gx_modes++;
153185
}
154186
}
155187

156-
static void setup_video_mode(_THIS, GXRModeObj *vmode)
188+
static void setup_video_mode(_THIS, GXRModeObj *vmode, int orthoWidth)
157189
{
158190
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
159191

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

183-
OGC_draw_init(vmode->fbWidth, vmode->efbHeight);
215+
OGC_draw_init(vmode->fbWidth, vmode->efbHeight, orthoWidth);
184216
}
185217

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

198-
setup_video_mode(_this, vmode);
230+
setup_video_mode(_this, vmode, mode->w);
199231
return 0;
200232
}
201233

@@ -277,12 +309,30 @@ int OGC_VideoInit(_THIS)
277309
VIDEO_Init();
278310

279311
vmode = VIDEO_GetPreferredMode(NULL);
312+
vmode->viWidth = 704;
313+
314+
// set Center point
315+
if (&s_mode704 == &TVPal576IntDfScale || &s_mode704 == &TVPal576ProgScale)
316+
{
317+
vmode->viXOrigin = (VI_MAX_WIDTH_PAL - vmode->viWidth) / 2;
318+
vmode->viYOrigin = (VI_MAX_HEIGHT_PAL - vmode->viHeight) / 2;
319+
}
320+
else
321+
{
322+
vmode->viXOrigin = (VI_MAX_WIDTH_NTSC - vmode->viWidth) / 2;
323+
vmode->viYOrigin = (VI_MAX_HEIGHT_NTSC - vmode->viHeight) / 2;
324+
}
280325

281326
videodata->gp_fifo = memalign(32, DEFAULT_FIFO_SIZE);
282327
memset(videodata->gp_fifo, 0, DEFAULT_FIFO_SIZE);
283328
GX_Init(videodata->gp_fifo, DEFAULT_FIFO_SIZE);
284329

285-
setup_video_mode(_this, vmode);
330+
#ifdef __wii__
331+
if(CONF_GetAspectRatio() == CONF_ASPECT_16_9)
332+
setup_video_mode(_this, vmode, 854);
333+
else
334+
#endif
335+
setup_video_mode(_this, vmode, vmode->fbWidth);
286336
GX_SetCopyClear(background, GX_MAX_Z24);
287337

288338
GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
@@ -293,7 +343,12 @@ int OGC_VideoInit(_THIS)
293343

294344
GX_Flush();
295345

296-
init_display_mode(&mode, vmode);
346+
#ifdef __wii__
347+
if(CONF_GetAspectRatio() == CONF_ASPECT_16_9)
348+
init_display_mode(&mode, vmode, 854);
349+
else
350+
#endif
351+
init_display_mode(&mode, vmode, vmode->fbWidth);
297352
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
298353
return -1;
299354
}

0 commit comments

Comments
 (0)