Skip to content

Commit 876bbfb

Browse files
mardyWinterMute
authored andcommitted
ogc: simplify viewport setup
We can just use an identity matrix for the model view matrix. The only transformation we apply is the 0.5 shift to get the coordinates centered on the pixels.
1 parent 8ad106a commit 876bbfb

4 files changed

Lines changed: 14 additions & 35 deletions

File tree

src/render/ogc/SDL_render_ogc.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,7 @@ static int OGC_RenderSetViewPort(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
333333
{
334334
const SDL_Rect *viewport = &cmd->data.viewport.rect;
335335

336-
float v_aspect = viewport->h / 2.0;
337-
float h_aspect = viewport->w / 2.0;
338-
OGC_set_viewport(viewport->x, viewport->y, viewport->w, viewport->h,
339-
h_aspect, v_aspect);
336+
OGC_set_viewport(viewport->x, viewport->y, viewport->w, viewport->h);
340337
return 0;
341338
}
342339

src/video/ogc/SDL_ogcgxcommon.c

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,6 @@
2929
#include <ogc/gx.h>
3030
#include <ogc/video.h>
3131

32-
typedef struct tagcamera {
33-
guVector pos;
34-
guVector up;
35-
guVector view;
36-
} camera;
37-
38-
static camera cam = {
39-
{ 0.0F, 0.0F, 0.0F },
40-
{ 0.0F, -0.5F, 0.0F },
41-
{ 0.0F, 0.0F, 0.5F }
42-
};
43-
4432
static const f32 tex_pos[] __attribute__((aligned(32))) = {
4533
0.0,
4634
0.0,
@@ -52,30 +40,28 @@ static const f32 tex_pos[] __attribute__((aligned(32))) = {
5240
1.0,
5341
};
5442

55-
void OGC_set_viewport(int x, int y, int w, int h, float h_aspect, float v_aspect)
43+
void OGC_set_viewport(int x, int y, int w, int h)
5644
{
57-
Mtx m, mv, view;
5845
Mtx44 proj;
5946

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

63-
memset(&view, 0, sizeof(Mtx));
64-
guLookAt(view, &cam.pos, &cam.up, &cam.view);
65-
guMtxIdentity(m);
66-
guMtxTransApply(m, m, 0.5 + (-w / 2.0), 0.5 + (-h / 2.0), 1000);
67-
guMtxConcat(view, m, mv);
68-
GX_LoadPosMtxImm(mv, GX_PNMTX0);
69-
7050
// matrix, t, b, l, r, n, f
71-
guOrtho(proj, v_aspect, -v_aspect, -h_aspect, h_aspect, 100, 1000);
51+
guOrtho(proj, 0, h, 0, w, 0, 1);
7252
GX_LoadProjectionMtx(proj, GX_ORTHOGRAPHIC);
7353
}
7454

75-
void OGC_draw_init(int w, int h, int h_aspect, int v_aspect)
55+
void OGC_draw_init(int w, int h)
7656
{
57+
Mtx mv;
58+
7759
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "OGC_draw_init called with %d, %d", w, h);
7860

61+
guMtxIdentity(mv);
62+
guMtxTransApply(mv, mv, 0.5, 0.5, 0);
63+
GX_LoadPosMtxImm(mv, GX_PNMTX0);
64+
7965
GX_ClearVtxDesc();
8066
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
8167
GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8);
@@ -94,7 +80,7 @@ void OGC_draw_init(int w, int h, int h_aspect, int v_aspect)
9480
GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
9581
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
9682

97-
OGC_set_viewport(0, 0, w, h, h_aspect, v_aspect);
83+
OGC_set_viewport(0, 0, w, h);
9884

9985
GX_InvVtxCache(); // update vertex cache
10086
}

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 h_aspect, int v_aspect);
33-
void OGC_set_viewport(int x, int y, int w, int h, float h_aspect, float v_aspect);
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_ogcvideo.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ int OGC_VideoInit(_THIS)
107107
SDL_DisplayMode mode;
108108
GXRModeObj *vmode;
109109
static const GXColor background = { 0, 0, 0, 255 };
110-
int h_aspect, v_aspect;
111110

112111
VIDEO_Init();
113112

@@ -142,10 +141,7 @@ int OGC_VideoInit(_THIS)
142141

143142
GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
144143

145-
/* Should we need to adjust the aspect, this is the place to do it */
146-
h_aspect = 320;
147-
v_aspect = 240;
148-
OGC_draw_init(vmode->fbWidth, vmode->efbHeight, h_aspect, v_aspect);
144+
OGC_draw_init(vmode->fbWidth, vmode->efbHeight);
149145

150146
GX_Flush();
151147

0 commit comments

Comments
 (0)