mirror of
https://github.com/zeldaret/mm.git
synced 2026-07-11 22:20:22 -04:00
z_view matching (#134)
This commit is contained in:
+167
-71
@@ -141,10 +141,8 @@ void View_SetScissorForLetterbox(View* view) {
|
||||
s32 uly;
|
||||
s32 lrx;
|
||||
s32 lry;
|
||||
s32 pad2;
|
||||
GraphicsContext* gfxCtx;
|
||||
|
||||
gfxCtx = view->gfxCtx;
|
||||
OPEN_DISPS(view->gfxCtx);
|
||||
|
||||
letterboxY = ShrinkWindow_GetLetterboxMagnitude();
|
||||
letterboxX = -1; // The following is optimized to varX = 0 but affects codegen
|
||||
@@ -167,25 +165,27 @@ void View_SetScissorForLetterbox(View* view) {
|
||||
lrx = view->viewport.rightX - letterboxX;
|
||||
lry = view->viewport.bottomY - letterboxY;
|
||||
|
||||
gDPPipeSync(gfxCtx->polyOpa.p++);
|
||||
gDPPipeSync(POLY_OPA_DISP++);
|
||||
{
|
||||
s32 pad3;
|
||||
Gfx* polyOpa;
|
||||
|
||||
polyOpa = gfxCtx->polyOpa.p;
|
||||
polyOpa = POLY_OPA_DISP;
|
||||
View_WriteScissor(&polyOpa, ulx, uly, lrx, lry);
|
||||
gfxCtx->polyOpa.p = polyOpa;
|
||||
POLY_OPA_DISP = polyOpa;
|
||||
}
|
||||
|
||||
gDPPipeSync(gfxCtx->polyXlu.p++);
|
||||
gDPPipeSync(POLY_XLU_DISP++);
|
||||
{
|
||||
Gfx* polyXlu;
|
||||
s32 pad4;
|
||||
|
||||
polyXlu = gfxCtx->polyXlu.p;
|
||||
polyXlu = POLY_XLU_DISP;
|
||||
View_WriteScissor(&polyXlu, ulx, uly, lrx, lry);
|
||||
gfxCtx->polyXlu.p = polyXlu;
|
||||
POLY_XLU_DISP = polyXlu;
|
||||
}
|
||||
|
||||
CLOSE_DISPS(view->gfxCtx);
|
||||
}
|
||||
|
||||
s32 View_SetQuakeRotation(View* view, f32 x, f32 y, f32 z) {
|
||||
@@ -281,8 +281,6 @@ void View_RenderView(View* view, s32 uParm2) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef NON_MATCHING
|
||||
// saved register usage is wrong, stack, regalloc
|
||||
s32 View_RenderToPerspectiveMatrix(View* view) {
|
||||
f32 aspect;
|
||||
s32 width;
|
||||
@@ -290,28 +288,20 @@ s32 View_RenderToPerspectiveMatrix(View* view) {
|
||||
Vp* vp;
|
||||
Mtx* projection;
|
||||
Mtx* viewing;
|
||||
GraphicsContext* gfxCtx;
|
||||
GraphicsContext* gfxCtx = view->gfxCtx;
|
||||
|
||||
gfxCtx = view->gfxCtx;
|
||||
OPEN_DISPS(gfxCtx);
|
||||
|
||||
{
|
||||
Vp* _vp = (Vp*)gfxCtx->polyOpa.d - 1;
|
||||
vp = _vp;
|
||||
gfxCtx->polyOpa.d = (Gfx*)_vp;
|
||||
}
|
||||
vp = GRAPH_ALLOC(gfxCtx, sizeof(*vp));
|
||||
View_ViewportToVp(vp, &view->viewport);
|
||||
view->vp = *vp;
|
||||
|
||||
View_SetScissorForLetterbox(view);
|
||||
|
||||
gSPViewport(gfxCtx->polyOpa.p++, vp);
|
||||
gSPViewport(gfxCtx->polyXlu.p++, vp);
|
||||
gSPViewport(POLY_OPA_DISP++, vp);
|
||||
gSPViewport(POLY_XLU_DISP++, vp);
|
||||
|
||||
{
|
||||
Mtx* _m = (Mtx*)gfxCtx->polyOpa.d - 1;
|
||||
projection = _m;
|
||||
gfxCtx->polyOpa.d = (Gfx*)_m;
|
||||
}
|
||||
projection = GRAPH_ALLOC(gfxCtx, sizeof(*projection));
|
||||
view->projectionPtr = projection;
|
||||
|
||||
width = view->viewport.rightX - view->viewport.leftX;
|
||||
@@ -319,21 +309,16 @@ s32 View_RenderToPerspectiveMatrix(View* view) {
|
||||
aspect = (f32)width / (f32)height;
|
||||
|
||||
guPerspective(projection, &view->normal, view->fovy, aspect, view->zNear, view->zFar, view->scale);
|
||||
|
||||
view->projection = *projection;
|
||||
//! @bug: This cast of `projection` is invalid
|
||||
View_StepQuake(view, (RSPMatrix*)projection);
|
||||
|
||||
View_StepQuake(view, projection);
|
||||
gSPPerspNormalize(POLY_OPA_DISP++, view->normal);
|
||||
gSPMatrix(POLY_OPA_DISP++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
||||
gSPPerspNormalize(POLY_XLU_DISP++, view->normal);
|
||||
gSPMatrix(POLY_XLU_DISP++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
||||
|
||||
gSPPerspNormalize(gfxCtx->polyOpa.p++, view->normal);
|
||||
gSPMatrix(gfxCtx->polyOpa.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
||||
gSPPerspNormalize(gfxCtx->polyXlu.p++, view->normal);
|
||||
gSPMatrix(gfxCtx->polyXlu.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
||||
|
||||
{
|
||||
Mtx* _m = (Mtx*)gfxCtx->polyOpa.d - 1;
|
||||
viewing = _m;
|
||||
gfxCtx->polyOpa.d = (Gfx*)_m;
|
||||
}
|
||||
viewing = GRAPH_ALLOC(gfxCtx, sizeof(*viewing));
|
||||
view->viewingPtr = viewing;
|
||||
|
||||
if (view->eye.x == view->focalPoint.x && view->eye.y == view->focalPoint.y && view->eye.z == view->focalPoint.z) {
|
||||
@@ -345,62 +330,146 @@ s32 View_RenderToPerspectiveMatrix(View* view) {
|
||||
|
||||
view->viewing = *viewing;
|
||||
|
||||
gSPMatrix(gfxCtx->polyOpa.p++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
|
||||
gSPMatrix(gfxCtx->polyXlu.p++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
|
||||
gSPMatrix(POLY_OPA_DISP++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
|
||||
gSPMatrix(POLY_XLU_DISP++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
|
||||
|
||||
CLOSE_DISPS(gfxCtx);
|
||||
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
#pragma GLOBAL_ASM("./asm/non_matchings/code/z_view/View_RenderToPerspectiveMatrix.asm")
|
||||
#endif
|
||||
|
||||
#ifdef NON_MATCHING
|
||||
// this needs a momumental amount of work
|
||||
s32 View_RenderToOrthographicMatrix(View* view) {
|
||||
Vp* vp;
|
||||
Mtx* projection;
|
||||
GraphicsContext* gfxCtx = view->gfxCtx;
|
||||
|
||||
OPEN_DISPS(gfxCtx);
|
||||
|
||||
vp = GRAPH_ALLOC(gfxCtx, sizeof(*vp));
|
||||
View_ViewportToVp(vp, &view->viewport);
|
||||
view->vp = *vp;
|
||||
|
||||
View_SetScissorForLetterbox(view);
|
||||
|
||||
gSPViewport(POLY_OPA_DISP++, vp);
|
||||
gSPViewport(POLY_XLU_DISP++, vp);
|
||||
gSPViewport(OVERLAY_DISP++, vp);
|
||||
|
||||
projection = GRAPH_ALLOC(gfxCtx, sizeof(*projection));
|
||||
view->projectionPtr = projection;
|
||||
|
||||
guOrtho(projection, gScreenWidth * -0.5f, gScreenWidth * 0.5f, gScreenHeight * -0.5f, gScreenHeight * 0.5f,
|
||||
view->zNear, view->zFar, view->scale);
|
||||
|
||||
view->projection = *projection;
|
||||
|
||||
gSPMatrix(POLY_OPA_DISP++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
||||
gSPMatrix(POLY_XLU_DISP++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
||||
|
||||
CLOSE_DISPS(gfxCtx);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
s32 func_8013FBC8(View* view) {
|
||||
Vp* vp;
|
||||
Mtx* projection;
|
||||
GraphicsContext* gfxCtx;
|
||||
|
||||
gfxCtx = view->gfxCtx;
|
||||
|
||||
{
|
||||
Vp* _vp = (Vp*)gfxCtx->polyOpa.d - 1;
|
||||
vp = _vp;
|
||||
gfxCtx->polyOpa.d = (Gfx*)_vp;
|
||||
}
|
||||
OPEN_DISPS(gfxCtx);
|
||||
|
||||
vp = GRAPH_ALLOC(gfxCtx, sizeof(*vp));
|
||||
View_ViewportToVp(vp, &view->viewport);
|
||||
view->vp = *vp;
|
||||
|
||||
View_SetScissorForLetterbox(view);
|
||||
|
||||
gSPViewport(gfxCtx->polyOpa.p++, vp);
|
||||
gSPViewport(gfxCtx->polyXlu.p++, vp);
|
||||
gSPViewport(gfxCtx->overlay.p++, vp);
|
||||
|
||||
gDPPipeSync(OVERLAY_DISP++);
|
||||
{
|
||||
Mtx* _m = (Mtx*)gfxCtx->polyOpa.d - 1;
|
||||
projection = _m;
|
||||
gfxCtx->polyOpa.d = (Gfx*)_m;
|
||||
Gfx* overlay;
|
||||
s32 pad;
|
||||
|
||||
overlay = OVERLAY_DISP;
|
||||
View_WriteScissor(&overlay, view->viewport.leftX, view->viewport.topY, view->viewport.rightX,
|
||||
view->viewport.bottomY);
|
||||
OVERLAY_DISP = overlay;
|
||||
}
|
||||
|
||||
gSPViewport(OVERLAY_DISP++, vp);
|
||||
projection = GRAPH_ALLOC(gfxCtx, sizeof(*projection));
|
||||
view->projectionPtr = projection;
|
||||
|
||||
guOrtho(projection, -0.5f, 0.5f, gScreenWidth * -0.5f, gScreenWidth * 0.5f, gScreenHeight * -0.5f,
|
||||
gScreenHeight * 0.5f, view->zNear);
|
||||
|
||||
guOrtho(projection, gScreenWidth * -0.5f, gScreenWidth * 0.5f, gScreenHeight * -0.5f, gScreenHeight * 0.5f,
|
||||
view->zNear, view->zFar, view->scale);
|
||||
view->projection = *projection;
|
||||
|
||||
gSPMatrix(gfxCtx->polyOpa.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
||||
gSPMatrix(gfxCtx->polyXlu.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
||||
gSPMatrix(OVERLAY_DISP++, projection, G_MTX_LOAD | G_MTX_PROJECTION);
|
||||
|
||||
CLOSE_DISPS(gfxCtx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
s32 func_8013FD74(View* view) {
|
||||
f32 aspect;
|
||||
s32 width;
|
||||
s32 height;
|
||||
Vp* vp;
|
||||
Mtx* projection;
|
||||
Mtx* viewing;
|
||||
GraphicsContext* gfxCtx;
|
||||
s32 pad;
|
||||
|
||||
gfxCtx = view->gfxCtx;
|
||||
|
||||
OPEN_DISPS(gfxCtx);
|
||||
|
||||
vp = GRAPH_ALLOC(gfxCtx, sizeof(*vp));
|
||||
View_ViewportToVp(vp, &view->viewport);
|
||||
view->vp = *vp;
|
||||
|
||||
gDPPipeSync(OVERLAY_DISP++);
|
||||
{
|
||||
s32 pad;
|
||||
Gfx* overlay;
|
||||
|
||||
overlay = OVERLAY_DISP;
|
||||
View_WriteScissor(&overlay, view->viewport.leftX, view->viewport.topY, view->viewport.rightX,
|
||||
view->viewport.bottomY);
|
||||
OVERLAY_DISP = overlay;
|
||||
}
|
||||
|
||||
gSPViewport(OVERLAY_DISP++, vp);
|
||||
projection = GRAPH_ALLOC(gfxCtx, sizeof(*projection));
|
||||
view->projectionPtr = projection;
|
||||
|
||||
width = view->viewport.rightX - view->viewport.leftX;
|
||||
height = view->viewport.bottomY - view->viewport.topY;
|
||||
aspect = (f32)width / (f32)height;
|
||||
|
||||
guPerspective(projection, &view->normal, view->fovy, aspect, view->zNear, view->zFar, view->scale);
|
||||
view->projection = *projection;
|
||||
|
||||
gSPPerspNormalize(OVERLAY_DISP++, view->normal);
|
||||
gSPMatrix(OVERLAY_DISP++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
||||
|
||||
viewing = GRAPH_ALLOC(gfxCtx, sizeof(*viewing));
|
||||
view->viewingPtr = viewing;
|
||||
|
||||
if (view->eye.x == view->focalPoint.x && view->eye.y == view->focalPoint.y && view->eye.z == view->focalPoint.z) {
|
||||
view->eye.z += 2.0f;
|
||||
}
|
||||
|
||||
guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->focalPoint.x, view->focalPoint.y, view->focalPoint.z,
|
||||
view->upDir.x, view->upDir.y, view->upDir.z);
|
||||
|
||||
view->viewing = *viewing;
|
||||
|
||||
gSPMatrix(OVERLAY_DISP++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
|
||||
|
||||
CLOSE_DISPS(gfxCtx);
|
||||
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
#pragma GLOBAL_ASM("./asm/non_matchings/code/z_view/View_RenderToOrthographicMatrix.asm")
|
||||
#endif
|
||||
|
||||
#pragma GLOBAL_ASM("./asm/non_matchings/code/z_view/func_8013FBC8.asm")
|
||||
|
||||
#pragma GLOBAL_ASM("./asm/non_matchings/code/z_view/func_8013FD74.asm")
|
||||
|
||||
s32 func_80140024(View* view) {
|
||||
guLookAt(view->viewingPtr, view->eye.x, view->eye.y, view->eye.z, view->focalPoint.x, view->focalPoint.y,
|
||||
@@ -412,4 +481,31 @@ s32 func_80140024(View* view) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#pragma GLOBAL_ASM("./asm/non_matchings/code/z_view/func_801400CC.asm")
|
||||
s32 func_801400CC(View* view, Gfx** gfxp) {
|
||||
Gfx* gfx = *gfxp;
|
||||
GraphicsContext* gfxCtx = view->gfxCtx;
|
||||
Viewport* viewport = &view->viewport;
|
||||
Mtx* projection;
|
||||
Vp* vp;
|
||||
|
||||
vp = GRAPH_ALLOC(gfxCtx, sizeof(*vp));
|
||||
View_ViewportToVp(vp, viewport);
|
||||
view->vp = *vp;
|
||||
|
||||
View_SyncAndWriteScissor(view, &gfx);
|
||||
|
||||
gSPViewport(gfx++, vp);
|
||||
|
||||
projection = GRAPH_ALLOC(gfxCtx, sizeof(*projection));
|
||||
view->projectionPtr = projection;
|
||||
|
||||
guOrtho(projection, gScreenWidth * -0.5f, gScreenWidth * 0.5f, gScreenHeight * -0.5f, gScreenHeight * 0.5f,
|
||||
view->zNear, view->zFar, view->scale);
|
||||
|
||||
view->projection = *projection;
|
||||
|
||||
gSPMatrix(gfx++, projection, G_MTX_LOAD | G_MTX_PROJECTION);
|
||||
*gfxp = gfx;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user