Skip to content

Commit 072708b

Browse files
committed
Make code much cleaner
1 parent 412eb51 commit 072708b

File tree

5 files changed

+52
-88
lines changed

5 files changed

+52
-88
lines changed

src/render/ogc/SDL_render_ogc.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,8 @@ static int OGC_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL
427427
static int OGC_RenderSetViewPort(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
428428
{
429429
const SDL_Rect *viewport = &cmd->data.viewport.rect;
430-
#ifdef __wii__
431-
if (CONF_GetAspectRatio() == CONF_ASPECT_16_9)
432-
OGC_set_viewport(viewport->x, viewport->y, viewport->w, viewport->h,
433-
viewport->w==640 ? (viewport->h*16.0f/9.0f)+1 : viewport->w);
434-
else
435-
#endif
436-
OGC_set_viewport(viewport->x, viewport->y, viewport->w, viewport->h, viewport->w);
437-
430+
431+
OGC_set_viewport(viewport->x, viewport->y, viewport->w, viewport->h);
438432
return 0;
439433
}
440434

src/video/ogc/SDL_ogcgxcommon.c

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

43-
/* On Widescreen if we pass the intended viewport width, the output will be streched
44-
* due to the fact the Wii's Widescreen is anamorphic, for this reason, we passs
45-
* a width value adjusted for widescreen, so we can modify the ortographic projection
46-
* of the viewport to allow the screen size to be displayed properly in widescreen
47-
* For example: If an app wants to output at 640x480,
48-
* it will be streched unless the projection is setup for 854x480,
49-
* so we pass 854 on widthAdjustedForWidescreen
50-
*
51-
* The reason why we can't just check for the active aspect ratio
52-
* is that if the app is using SDL Renderer with a different logical size
53-
* from the window, it'd set the viewport to a size, than when we render we set it to another
54-
* and the image ends up distorted, an example of this is VVVVVV. */
55-
void OGC_set_viewport(int x, int y, int w, int h, int widthAdjustedForWidescreen)
43+
void OGC_set_viewport(int x, int y, int w, int h)
5644
{
57-
SDL_Log("OGC_set_viewport: %d %d %d %d %d", x, y, w, h, widthAdjustedForWidescreen);
5845
Mtx44 proj;
5946

6047
GX_SetViewport(x, y, (w > 640) ? 640 : w, h, 0, 1);
6148
GX_SetScissor(x, y, (w > 640) ? 640 : w, h);
6249

6350
// matrix, t, b, l, r, n, f
64-
guOrtho(proj, 0, h, 0, widthAdjustedForWidescreen, 0, 1);
51+
guOrtho(proj, 0, h, 0, w, 0, 1);
6552
GX_LoadProjectionMtx(proj, GX_ORTHOGRAPHIC);
6653
}
6754

68-
// takes in w, h and widthAdjustedForWidescreen to pass to OGC_set_viewport
69-
void OGC_draw_init(int w, int h, int widthAdjustedForWidescreen)
55+
void OGC_draw_init(int w, int h)
7056
{
7157
Mtx mv;
7258

73-
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "OGC_draw_init called with %d, %d, %d", w, h, widthAdjustedForWidescreen);
59+
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "OGC_draw_init called with %d, %d", w, h);
7460

7561
guMtxIdentity(mv);
7662
/* Ideally we would use 0.5 to center the coordinates on the pixels, but
@@ -100,7 +86,7 @@ void OGC_draw_init(int w, int h, int widthAdjustedForWidescreen)
10086
GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
10187
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
10288

103-
OGC_set_viewport(0, 0, w, h, widthAdjustedForWidescreen);
89+
OGC_set_viewport(0, 0, w, h);
10490

10591
GX_InvVtxCache(); // update vertex cache
10692
}

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, int widthAdjustedForWidescreen);
33-
void OGC_set_viewport(int x, int y, int w, int h, int widthAdjustedForWidescreen);
32+
void OGC_draw_init(int w, int h);
33+
void OGC_set_viewport(int x, int y, int w, int h);
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: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,14 @@ void OGC_draw_cursor(_THIS)
196196
screen_h = _this->displays[0].current_mode.h;
197197

198198
curdata = mouse->cur_cursor->driverdata;
199-
OGC_load_texture(curdata->texels, curdata->w, curdata->h, GX_TF_RGBA8,
200-
SDL_ScaleModeNearest);
199+
#ifdef __wii__
200+
if (CONF_GetAspectRatio() == CONF_ASPECT_16_9)
201+
OGC_load_texture(curdata->texels, curdata->w, curdata->h, GX_TF_RGBA8,
202+
SDL_ScaleModeLinear);
203+
else
204+
#endif
205+
OGC_load_texture(curdata->texels, curdata->w, curdata->h, GX_TF_RGBA8,
206+
SDL_ScaleModeNearest);
201207

202208
guMtxIdentity(mv);
203209
#ifdef __wii__
@@ -215,7 +221,7 @@ void OGC_draw_cursor(_THIS)
215221
guMtxTransApply(mv, mv, mouse->x, mouse->y, 0);
216222
GX_LoadPosMtxImm(mv, GX_PNMTX1);
217223

218-
OGC_set_viewport(0, 0, screen_w, screen_h, screen_w);
224+
OGC_set_viewport(0, 0, screen_w, screen_h);
219225

220226
GX_ClearVtxDesc();
221227
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
@@ -247,8 +253,7 @@ void OGC_draw_cursor(_THIS)
247253
SDL_Renderer *renderer = SDL_GetRenderer(_this->windows);
248254
if (renderer) {
249255
OGC_set_viewport(renderer->viewport.x, renderer->viewport.y,
250-
renderer->viewport.w, renderer->viewport.h,
251-
renderer->viewport.w);
256+
renderer->viewport.w, renderer->viewport.h);
252257
}
253258
}
254259
}

src/video/ogc/SDL_ogcvideo.c

Lines changed: 33 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252

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

5756
static const GXRModeObj *s_ntsc_modes[] = {
5857
&TVNtsc240Ds,
@@ -96,11 +95,12 @@ static void init_display_mode(SDL_DisplayMode *mode, const GXRModeObj *vmode)
9695
mode->format = SDL_PIXELFORMAT_ARGB8888;
9796

9897
#ifdef __wii__
99-
if (CONF_GetAspectRatio() == CONF_ASPECT_16_9)
100-
mode->w = ((int)(vmode->fbWidth * 16.0f / 9.0f)) + 1;
101-
else
98+
if (CONF_GetAspectRatio() == CONF_ASPECT_16_9) {
99+
mode->w = vmode->fbWidth * 16.0f / 9.0f;
100+
mode->w = (mode->w + 1) & ~1;
101+
}
102102
#endif
103-
mode->w = vmode->fbWidth;
103+
mode->w = vmode->fbWidth;
104104
mode->h = vmode->efbHeight;
105105
switch (format) {
106106
case VI_DEBUG:
@@ -114,7 +114,7 @@ static void init_display_mode(SDL_DisplayMode *mode, const GXRModeObj *vmode)
114114
mode->refresh_rate = 50;
115115
break;
116116
}
117-
mode->driverdata = (GXRModeObj *)vmode;
117+
mode->driverdata = (GXRModeObj*)vmode;
118118
}
119119

120120
static void add_supported_modes(SDL_VideoDisplay *display, u32 tv_format)
@@ -153,32 +153,6 @@ static void add_supported_modes(SDL_VideoDisplay *display, u32 tv_format)
153153
init_display_mode(&mode, &s_mode320);
154154
SDL_AddDisplayMode(display, &mode);
155155

156-
// libogc uses 640 for the viWidth, but this does not work well for Widescreen
157-
// as such we extend the viWidth to 704 on a new videomode
158-
// TODO: Currently ony added on wii if it's widescreen,
159-
// but should work on GC and a 4:3 Wii
160-
// testing needed
161-
162-
#ifdef __wii__
163-
if (CONF_GetAspectRatio() == CONF_ASPECT_16_9) {
164-
memcpy(&s_mode704, gx_modes[1], sizeof(s_mode704));
165-
s_mode704.viWidth = 704;
166-
167-
// set Center point
168-
if (&s_mode704 == &TVPal576IntDfScale || &s_mode704 == &TVPal576ProgScale) {
169-
s_mode704.viXOrigin = (VI_MAX_WIDTH_PAL - s_mode704.viWidth) / 2;
170-
s_mode704.viYOrigin = (VI_MAX_HEIGHT_PAL - s_mode704.viHeight) / 2;
171-
} else {
172-
s_mode704.viXOrigin = (VI_MAX_WIDTH_NTSC - s_mode704.viWidth) / 2;
173-
s_mode704.viYOrigin = (VI_MAX_HEIGHT_NTSC - s_mode704.viHeight) / 2;
174-
}
175-
176-
// Widescreen is anamorphic, so we provide a different width for the ortho projection
177-
init_display_mode(&mode, &s_mode704);
178-
SDL_AddDisplayMode(display, &mode);
179-
}
180-
#endif
181-
182156
/* Now add all the "standard" modes from libogc */
183157
while (*gx_modes) {
184158
init_display_mode(&mode, *gx_modes);
@@ -187,10 +161,24 @@ static void add_supported_modes(SDL_VideoDisplay *display, u32 tv_format)
187161
}
188162
}
189163

190-
static void setup_video_mode(_THIS, GXRModeObj *vmode, int widthAdjustedForWidescreen)
164+
static void setup_video_mode(_THIS, GXRModeObj *vmode)
191165
{
192166
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
193167

168+
// TODO: Should I make this only happen if the aspect ratio isn't 4:3?
169+
if(vmode->viWidth == 240 || vmode->viWidth == 640)
170+
vmode->viWidth = vmode->viWidth + (VI_MAX_WIDTH_NTSC - 640);
171+
172+
// set Center point
173+
if (VI_FORMAT_FROM_MODE(vmode->viTVMode) == VI_PAL) {
174+
vmode->viXOrigin = (VI_MAX_WIDTH_PAL - vmode->viWidth) / 2;
175+
vmode->viYOrigin = (VI_MAX_HEIGHT_PAL - vmode->viHeight) / 2;
176+
} else {
177+
vmode->viXOrigin = (VI_MAX_WIDTH_NTSC - vmode->viWidth) / 2;
178+
vmode->viYOrigin = (VI_MAX_HEIGHT_NTSC - vmode->viHeight) / 2;
179+
}
180+
181+
194182
VIDEO_SetBlack(true);
195183
VIDEO_Configure(vmode);
196184

@@ -215,7 +203,7 @@ static void setup_video_mode(_THIS, GXRModeObj *vmode, int widthAdjustedForWides
215203
GX_SetFieldMode(vmode->field_rendering,
216204
((vmode->viHeight == 2 * vmode->xfbHeight) ? GX_ENABLE : GX_DISABLE));
217205

218-
OGC_draw_init(vmode->fbWidth, vmode->efbHeight, widthAdjustedForWidescreen);
206+
OGC_draw_init(vmode->fbWidth, vmode->efbHeight);
219207
}
220208

221209
static int OGC_SetDisplayMode(_THIS, SDL_VideoDisplay *display,
@@ -230,7 +218,7 @@ static int OGC_SetDisplayMode(_THIS, SDL_VideoDisplay *display,
230218
if (videodata->xfb[1])
231219
free(MEM_K1_TO_K0(videodata->xfb[1]));
232220

233-
setup_video_mode(_this, vmode, mode->w);
221+
setup_video_mode(_this, vmode);
234222
return 0;
235223
}
236224

@@ -312,30 +300,21 @@ int OGC_VideoInit(_THIS)
312300
VIDEO_Init();
313301

314302
vmode = VIDEO_GetPreferredMode(NULL);
315-
#ifdef __wii__
316-
if (CONF_GetAspectRatio() == CONF_ASPECT_16_9) {
317-
vmode->viWidth = 704;
318-
319-
// set Center point
320-
if (&s_mode704 == &TVPal576IntDfScale || &s_mode704 == &TVPal576ProgScale) {
321-
vmode->viXOrigin = (VI_MAX_WIDTH_PAL - vmode->viWidth) / 2;
322-
vmode->viYOrigin = (VI_MAX_HEIGHT_PAL - vmode->viHeight) / 2;
323-
} else {
324-
vmode->viXOrigin = (VI_MAX_WIDTH_NTSC - vmode->viWidth) / 2;
325-
vmode->viYOrigin = (VI_MAX_HEIGHT_NTSC - vmode->viHeight) / 2;
326-
}
303+
vmode->viWidth = VI_MAX_WIDTH_NTSC; // VI_MAX_WIDTH is the same for all regions
304+
// set Center point
305+
if (VI_FORMAT_FROM_MODE(vmode->viTVMode) == VI_PAL) {
306+
vmode->viXOrigin = (VI_MAX_WIDTH_PAL - vmode->viWidth) / 2;
307+
vmode->viYOrigin = (VI_MAX_HEIGHT_PAL - vmode->viHeight) / 2;
308+
} else {
309+
vmode->viXOrigin = (VI_MAX_WIDTH_NTSC - vmode->viWidth) / 2;
310+
vmode->viYOrigin = (VI_MAX_HEIGHT_NTSC - vmode->viHeight) / 2;
327311
}
328-
#endif
312+
329313
videodata->gp_fifo = memalign(32, DEFAULT_FIFO_SIZE);
330314
memset(videodata->gp_fifo, 0, DEFAULT_FIFO_SIZE);
331315
GX_Init(videodata->gp_fifo, DEFAULT_FIFO_SIZE);
332316

333-
#ifdef __wii__
334-
if (CONF_GetAspectRatio() == CONF_ASPECT_16_9)
335-
setup_video_mode(_this, vmode, 854);
336-
else
337-
#endif
338-
setup_video_mode(_this, vmode, vmode->fbWidth);
317+
setup_video_mode(_this, vmode);
339318
GX_SetCopyClear(background, GX_MAX_Z24);
340319

341320
GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);

0 commit comments

Comments
 (0)