diff --git a/src/Camera.c b/src/Camera.c index 645b68dcd..f94d73420 100644 --- a/src/Camera.c +++ b/src/Camera.c @@ -335,7 +335,7 @@ void Camera_SetFov(int fov) { void Camera_UpdateProjection(void) { Camera.Active->GetProjection(&Gfx.Projection); - Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx.Projection); + Gfx_LoadMatrix(MATRIX_PROJ, &Gfx.Projection); Event_RaiseVoid(&GfxEvents.ProjectionChanged); } diff --git a/src/Game.c b/src/Game.c index ac04f9295..7fe7427a5 100644 --- a/src/Game.c +++ b/src/Game.c @@ -508,8 +508,8 @@ static void UpdateViewMatrix(void) { static void Render3DFrame(float delta, float t) { Vec3 pos; - Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx.Projection); - Gfx_LoadMatrix(MATRIX_VIEW, &Gfx.View); + Gfx_LoadMatrix(MATRIX_PROJ, &Gfx.Projection); + Gfx_LoadMatrix(MATRIX_VIEW, &Gfx.View); if (EnvRenderer_ShouldRenderSkybox()) EnvRenderer_RenderSkybox(); AxisLinesRenderer_Render(); diff --git a/src/Graphics.h b/src/Graphics.h index d1cbcfacd..36d17126b 100644 --- a/src/Graphics.h +++ b/src/Graphics.h @@ -15,11 +15,14 @@ extern struct IGameComponent Gfx_Component; typedef enum VertexFormat_ { VERTEX_FORMAT_COLOURED, VERTEX_FORMAT_TEXTURED } VertexFormat; + typedef enum FogFunc_ { FOG_LINEAR, FOG_EXP, FOG_EXP2 } FogFunc; + typedef enum MatrixType_ { - MATRIX_PROJECTION, MATRIX_VIEW + MATRIX_PROJ, /* Projection matrix */ + MATRIX_VIEW /* Combined model view matrix */ } MatrixType; #define SIZEOF_VERTEX_COLOURED 16 @@ -222,10 +225,10 @@ void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex); /* Loads the given matrix over the currently active matrix */ CC_API void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix); -/* Loads the identity matrix over the currently active matrix */ -CC_API void Gfx_LoadIdentityMatrix(MatrixType type); CC_API void Gfx_EnableTextureOffset(float x, float y); CC_API void Gfx_DisableTextureOffset(void); +/* Loads given modelview and projection matrices, then calculates the combined MVP matrix */ +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp); /* Calculates an orthographic projection matrix suitable with this backend. (usually for 2D) */ void Gfx_CalcOrthoMatrix(struct Matrix* matrix, float width, float height, float zNear, float zFar); diff --git a/src/Graphics_3DS.c b/src/Graphics_3DS.c index 45cf4c1e5..652377cb2 100644 --- a/src/Graphics_3DS.c +++ b/src/Graphics_3DS.c @@ -868,7 +868,7 @@ void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { // // This can be done by rotating the projection matrix 90 degrees around Z axis // https://open.gl/transformations - if (type == MATRIX_PROJECTION) { + if (type == MATRIX_PROJ) { struct Matrix rot = Matrix_Identity; rot.row1.x = 0; rot.row1.y = 1; rot.row2.x = -1; rot.row2.y = 0; @@ -882,8 +882,10 @@ void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { ReloadUniforms(); }*/ -void Gfx_LoadIdentityMatrix(MatrixType type) { - Gfx_LoadMatrix(type, &Matrix_Identity); +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } void Gfx_EnableTextureOffset(float x, float y) { diff --git a/src/Graphics_D3D11.c b/src/Graphics_D3D11.c index 3833278f2..8e9efae62 100644 --- a/src/Graphics_D3D11.c +++ b/src/Graphics_D3D11.c @@ -601,15 +601,17 @@ static void VS_Free(void) { static struct Matrix _view, _proj; void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { - if (type == MATRIX_VIEW) _view = *matrix; - if (type == MATRIX_PROJECTION) _proj = *matrix; + if (type == MATRIX_VIEW) _view = *matrix; + if (type == MATRIX_PROJ) _proj = *matrix; Matrix_Mul(&vs_constants.mvp, &_view, &_proj); VS_UpdateConstants(); } -void Gfx_LoadIdentityMatrix(MatrixType type) { - Gfx_LoadMatrix(type, &Matrix_Identity); +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } void Gfx_EnableTextureOffset(float x, float y) { diff --git a/src/Graphics_D3D9.c b/src/Graphics_D3D9.c index 069ccb8e1..87d5ab7c8 100644 --- a/src/Graphics_D3D9.c +++ b/src/Graphics_D3D9.c @@ -719,9 +719,10 @@ void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { IDirect3DDevice9_SetTransform(device, matrix_modes[type], (const D3DMATRIX*)matrix); } -void Gfx_LoadIdentityMatrix(MatrixType type) { - if (Gfx.LostContext) return; - IDirect3DDevice9_SetTransform(device, matrix_modes[type], (const D3DMATRIX*)&Matrix_Identity); +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } static struct Matrix texMatrix = Matrix_IdentityValue; diff --git a/src/Graphics_Dreamcast.c b/src/Graphics_Dreamcast.c index 8065aae1d..80b9281da 100644 --- a/src/Graphics_Dreamcast.c +++ b/src/Graphics_Dreamcast.c @@ -449,15 +449,17 @@ static float textureOffsetX, textureOffsetY; static int textureOffset; void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { - if (type == MATRIX_PROJECTION) memcpy(&_proj, matrix, sizeof(struct Matrix)); - if (type == MATRIX_VIEW) memcpy(&_view, matrix, sizeof(struct Matrix)); + if (type == MATRIX_PROJ) memcpy(&_proj, matrix, sizeof(struct Matrix)); + if (type == MATRIX_VIEW) memcpy(&_view, matrix, sizeof(struct Matrix)); mat_load( &_proj); mat_apply(&_view); } -void Gfx_LoadIdentityMatrix(MatrixType type) { - Gfx_LoadMatrix(type, &Matrix_Identity); +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } diff --git a/src/Graphics_GCWii.c b/src/Graphics_GCWii.c index c34ba3092..688687025 100644 --- a/src/Graphics_GCWii.c +++ b/src/Graphics_GCWii.c @@ -520,7 +520,7 @@ void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { tmp[i * 4 + 3] = m[12 + i]; } - if (type == MATRIX_PROJECTION) { + if (type == MATRIX_PROJ) { GX_LoadProjectionMtx(tmp, tmp[3*4+3] == 0.0f ? GX_PERSPECTIVE : GX_ORTHOGRAPHIC); } else { @@ -528,9 +528,12 @@ void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { } } -void Gfx_LoadIdentityMatrix(MatrixType type) { - Gfx_LoadMatrix(type, &Matrix_Identity); +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } + static float texOffsetX, texOffsetY; static void UpdateTexCoordGen(void) { if (texOffsetX || texOffsetY) { diff --git a/src/Graphics_GL1.c b/src/Graphics_GL1.c index 14f730455..76e7a0bf8 100644 --- a/src/Graphics_GL1.c +++ b/src/Graphics_GL1.c @@ -443,12 +443,18 @@ static int lastMatrix; void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { if (type != lastMatrix) { lastMatrix = type; glMatrixMode(matrix_modes[type]); } - glLoadMatrixf((const float*)matrix); + + if (matrix == &Matrix_Identity) { + glLoadIdentity(); + } else { + glLoadMatrixf((const float*)matrix); + } } -void Gfx_LoadIdentityMatrix(MatrixType type) { - if (type != lastMatrix) { lastMatrix = type; glMatrixMode(matrix_modes[type]); } - glLoadIdentity(); +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } static struct Matrix texMatrix = Matrix_IdentityValue; @@ -457,7 +463,7 @@ void Gfx_EnableTextureOffset(float x, float y) { Gfx_LoadMatrix(2, &texMatrix); } -void Gfx_DisableTextureOffset(void) { Gfx_LoadIdentityMatrix(2); } +void Gfx_DisableTextureOffset(void) { Gfx_LoadMatrix(2, &Matrix_Identity); } /*########################################################################################################################* diff --git a/src/Graphics_GL2.c b/src/Graphics_GL2.c index 7d625972d..04f0d64e1 100644 --- a/src/Graphics_GL2.c +++ b/src/Graphics_GL2.c @@ -491,15 +491,18 @@ void Gfx_DepthOnlyRendering(cc_bool depthOnly) { *---------------------------------------------------------Matrices--------------------------------------------------------* *#########################################################################################################################*/ void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { - if (type == MATRIX_VIEW) _view = *matrix; - if (type == MATRIX_PROJECTION) _proj = *matrix; + if (type == MATRIX_VIEW) _view = *matrix; + if (type == MATRIX_PROJ) _proj = *matrix; Matrix_Mul(&_mvp, &_view, &_proj); DirtyUniform(UNI_MVP_MATRIX); ReloadUniforms(); } -void Gfx_LoadIdentityMatrix(MatrixType type) { - Gfx_LoadMatrix(type, &Matrix_Identity); + +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } void Gfx_EnableTextureOffset(float x, float y) { diff --git a/src/Graphics_N64.c b/src/Graphics_N64.c index 014d7e15a..9d34f3772 100644 --- a/src/Graphics_N64.c +++ b/src/Graphics_N64.c @@ -449,12 +449,18 @@ static int lastMatrix; void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { if (type != lastMatrix) { lastMatrix = type; glMatrixMode(matrix_modes[type]); } - glLoadMatrixf((const float*)matrix); + + if (matrix == &Matrix_Identity) { + glLoadIdentity(); + } else { + glLoadMatrixf((const float*)matrix); + } } -void Gfx_LoadIdentityMatrix(MatrixType type) { - if (type != lastMatrix) { lastMatrix = type; glMatrixMode(matrix_modes[type]); } - glLoadIdentity(); +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } static struct Matrix texMatrix = Matrix_IdentityValue; @@ -463,7 +469,7 @@ void Gfx_EnableTextureOffset(float x, float y) { Gfx_LoadMatrix(2, &texMatrix); } -void Gfx_DisableTextureOffset(void) { Gfx_LoadIdentityMatrix(2); } +void Gfx_DisableTextureOffset(void) { Gfx_LoadMatrix(2, &Matrix_Identity); } /*########################################################################################################################* diff --git a/src/Graphics_NDS.c b/src/Graphics_NDS.c index 16790b632..cf6306ae5 100644 --- a/src/Graphics_NDS.c +++ b/src/Graphics_NDS.c @@ -396,6 +396,12 @@ static int lastMatrix; void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { if (type != lastMatrix) { lastMatrix = type; glMatrixMode(matrix_modes[type]); } + if (matrix == &Matrix_Identity) { + glLoadIdentity(); + return; + // TODO still scale? + } + m4x4 m; const float* src = (const float*)matrix; @@ -413,9 +419,10 @@ void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { glScalef32(floattof32(64.0f), floattof32(64.0f), floattof32(64.0f)); } -void Gfx_LoadIdentityMatrix(MatrixType type) { - if (type != lastMatrix) { lastMatrix = type; glMatrixMode(matrix_modes[type]); } - glLoadIdentity(); +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } static struct Matrix texMatrix; diff --git a/src/Graphics_PS1.c b/src/Graphics_PS1.c index f1f5c3421..a653dceaa 100644 --- a/src/Graphics_PS1.c +++ b/src/Graphics_PS1.c @@ -515,8 +515,8 @@ static void LoadTransformMatrix(struct Matrix* src) { } void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { - if (type == MATRIX_VIEW) _view = *matrix; - if (type == MATRIX_PROJECTION) _proj = *matrix; + if (type == MATRIX_VIEW) _view = *matrix; + if (type == MATRIX_PROJ) _proj = *matrix; struct Matrix mvp; if (matrix == &Matrix_Identity && type == MATRIX_VIEW) { @@ -528,8 +528,10 @@ void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { LoadTransformMatrix(&mvp); } -void Gfx_LoadIdentityMatrix(MatrixType type) { - Gfx_LoadMatrix(type, &Matrix_Identity); +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } void Gfx_EnableTextureOffset(float x, float y) { diff --git a/src/Graphics_PS2.c b/src/Graphics_PS2.c index 39fc17fe3..80f0b124a 100644 --- a/src/Graphics_PS2.c +++ b/src/Graphics_PS2.c @@ -445,17 +445,18 @@ void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); } static struct Matrix _view, _proj; void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { - if (type == MATRIX_VIEW) _view = *matrix; - if (type == MATRIX_PROJECTION) _proj = *matrix; + if (type == MATRIX_VIEW) _view = *matrix; + if (type == MATRIX_PROJ) _proj = *matrix; Matrix_Mul(&mvp, &_view, &_proj); // TODO LoadMvpMatrix(&mvp); } -void Gfx_LoadIdentityMatrix(MatrixType type) { - Gfx_LoadMatrix(type, &Matrix_Identity); - // TODO +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } void Gfx_EnableTextureOffset(float x, float y) { diff --git a/src/Graphics_PS3.c b/src/Graphics_PS3.c index 54e8e219c..0575607d7 100644 --- a/src/Graphics_PS3.c +++ b/src/Graphics_PS3.c @@ -652,15 +652,17 @@ void Gfx_SetFogMode(FogFunc func) {/* TODO */ static struct Matrix _view, _proj; void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { - struct Matrix* dst = type == MATRIX_PROJECTION ? &_proj : &_view; + struct Matrix* dst = type == MATRIX_PROJ ? &_proj : &_view; *dst = *matrix; Matrix_Mul(&mvp, &_view, &_proj); VP_UpdateUniforms(); } -void Gfx_LoadIdentityMatrix(MatrixType type) { - Gfx_LoadMatrix(type, &Matrix_Identity); +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } void Gfx_EnableTextureOffset(float x, float y) { diff --git a/src/Graphics_PSP.c b/src/Graphics_PSP.c index 1d0896f2e..d1d75f34e 100644 --- a/src/Graphics_PSP.c +++ b/src/Graphics_PSP.c @@ -401,8 +401,10 @@ void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { sceGuSetMatrix(matrix_modes[type], &tmp_matrix); } -void Gfx_LoadIdentityMatrix(MatrixType type) { - sceGuSetMatrix(matrix_modes[type], &identity); +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } void Gfx_EnableTextureOffset(float x, float y) { diff --git a/src/Graphics_PSVita.c b/src/Graphics_PSVita.c index 1065bc235..9e219cbf5 100644 --- a/src/Graphics_PSVita.c +++ b/src/Graphics_PSVita.c @@ -112,7 +112,7 @@ void* AllocGPUMemory(int size, int type, int gpu_access, SceUID* ret_uid, const String_InitArray_NT(str, buffer); // https://wiki.henkaku.xyz/vita/SceSysmem - SceUID uid = sceKernelAllocMemBlock("GPU memory", type, size, NULL); + SceUID uid = sceKernelAllocMemBlock(memType, type, size, NULL); if (uid < 0) { String_Format2(&str, "Failed to allocate GPU memory block for %c (%i bytes)%N", memType, &size); Logger_Abort2(uid, buffer); @@ -1024,8 +1024,8 @@ void Gfx_SetDepthTest(cc_bool enabled) { static struct Matrix _view, _proj; void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { - if (type == MATRIX_VIEW) _view = *matrix; - if (type == MATRIX_PROJECTION) _proj = *matrix; + if (type == MATRIX_VIEW) _view = *matrix; + if (type == MATRIX_PROJ) _proj = *matrix; struct Matrix mvp __attribute__((aligned(64))); Matrix_Mul(&mvp, &_view, &_proj); @@ -1044,8 +1044,10 @@ void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { VP_ReloadUniforms(); } -void Gfx_LoadIdentityMatrix(MatrixType type) { - Gfx_LoadMatrix(type, &Matrix_Identity); +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } void Gfx_EnableTextureOffset(float x, float y) { @@ -1116,8 +1118,8 @@ void Gfx_ClearBuffers(GfxBuffers buffers) { Gfx_SetDepthTest(false); Gfx_SetVertexFormat(VERTEX_FORMAT_COLOURED); - Gfx_LoadIdentityMatrix(MATRIX_VIEW); - Gfx_LoadIdentityMatrix(MATRIX_PROJECTION); + Gfx_LoadMatrix(MATRIX_VIEW, &Matrix_Identity); + Gfx_LoadMatrix(MATRIX_PROJ, &Matrix_Identity); Gfx_BindVb(clearVB); Gfx_DrawVb_IndexedTris(4); diff --git a/src/Graphics_Saturn.c b/src/Graphics_Saturn.c index 55012136f..8224e6f97 100644 --- a/src/Graphics_Saturn.c +++ b/src/Graphics_Saturn.c @@ -382,8 +382,8 @@ static void LoadTransformMatrix(struct Matrix* src) { } void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { - if (type == MATRIX_VIEW) _view = *matrix; - if (type == MATRIX_PROJECTION) _proj = *matrix; + if (type == MATRIX_VIEW) _view = *matrix; + if (type == MATRIX_PROJ) _proj = *matrix; struct Matrix mvp; if (matrix == &Matrix_Identity && type == MATRIX_VIEW) { @@ -395,8 +395,10 @@ void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { LoadTransformMatrix(&mvp); } -void Gfx_LoadIdentityMatrix(MatrixType type) { - Gfx_LoadMatrix(type, &Matrix_Identity); +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } void Gfx_EnableTextureOffset(float x, float y) { diff --git a/src/Graphics_SoftGPU.c b/src/Graphics_SoftGPU.c index 862c8d278..33fe65f4f 100644 --- a/src/Graphics_SoftGPU.c +++ b/src/Graphics_SoftGPU.c @@ -240,17 +240,19 @@ void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); } *---------------------------------------------------------Matrices--------------------------------------------------------* *#########################################################################################################################*/ static float texOffsetX, texOffsetY; -static struct Matrix _view, _proj, mvp; +static struct Matrix _view, _proj, _mvp; void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { - if (type == MATRIX_VIEW) _view = *matrix; - if (type == MATRIX_PROJECTION) _proj = *matrix; + if (type == MATRIX_VIEW) _view = *matrix; + if (type == MATRIX_PROJ) _proj = *matrix; - Matrix_Mul(&mvp, &_view, &_proj); + Matrix_Mul(&_mvp, &_view, &_proj); } -void Gfx_LoadIdentityMatrix(MatrixType type) { - Gfx_LoadMatrix(type, &Matrix_Identity); +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } void Gfx_EnableTextureOffset(float x, float y) { @@ -332,10 +334,10 @@ static int TransformVertex3D(int index, Vertex* vertex) { char* ptr = (char*)gfx_vertices + index * gfx_stride; Vector3* pos = (Vector3*)ptr; - vertex->x = pos->x * mvp.row1.x + pos->y * mvp.row2.x + pos->z * mvp.row3.x + mvp.row4.x; - vertex->y = pos->x * mvp.row1.y + pos->y * mvp.row2.y + pos->z * mvp.row3.y + mvp.row4.y; - vertex->z = pos->x * mvp.row1.z + pos->y * mvp.row2.z + pos->z * mvp.row3.z + mvp.row4.z; - vertex->w = pos->x * mvp.row1.w + pos->y * mvp.row2.w + pos->z * mvp.row3.w + mvp.row4.w; + vertex->x = pos->x * _mvp.row1.x + pos->y * _mvp.row2.x + pos->z * _mvp.row3.x + _mvp.row4.x; + vertex->y = pos->x * _mvp.row1.y + pos->y * _mvp.row2.y + pos->z * _mvp.row3.y + _mvp.row4.y; + vertex->z = pos->x * _mvp.row1.z + pos->y * _mvp.row2.z + pos->z * _mvp.row3.z + _mvp.row4.z; + vertex->w = pos->x * _mvp.row1.w + pos->y * _mvp.row2.w + pos->z * _mvp.row3.w + _mvp.row4.w; if (gfx_format != VERTEX_FORMAT_TEXTURED) { struct VertexColoured* v = (struct VertexColoured*)ptr; diff --git a/src/Graphics_WiiU.c b/src/Graphics_WiiU.c index 60c96e4aa..bb142cbd4 100644 --- a/src/Graphics_WiiU.c +++ b/src/Graphics_WiiU.c @@ -343,8 +343,8 @@ void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) { *#########################################################################################################################*/ static struct Matrix _view, _proj; void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { - if (type == MATRIX_VIEW) _view = *matrix; - if (type == MATRIX_PROJECTION) _proj = *matrix; + if (type == MATRIX_VIEW) _view = *matrix; + if (type == MATRIX_PROJ) _proj = *matrix; // TODO dirty uniform struct Matrix mvp __attribute__((aligned(64))); @@ -353,8 +353,10 @@ void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { GX2SetVertexUniformReg(group->vertexShader->uniformVars[0].offset, 16, &mvp); } -void Gfx_LoadIdentityMatrix(MatrixType type) { - Gfx_LoadMatrix(type, &Matrix_Identity); +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } void Gfx_EnableTextureOffset(float x, float y) { diff --git a/src/Graphics_Xbox.c b/src/Graphics_Xbox.c index 8a340bd78..c39370a99 100644 --- a/src/Graphics_Xbox.c +++ b/src/Graphics_Xbox.c @@ -569,15 +569,17 @@ static void UpdateVSConstants(void) { } void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { - struct Matrix* dst = type == MATRIX_PROJECTION ? &_proj : &_view; + struct Matrix* dst = type == MATRIX_PROJ ? &_proj : &_view; *dst = *matrix; Matrix_Mul(&_mvp, &_view, &_proj); UpdateVSConstants(); } -void Gfx_LoadIdentityMatrix(MatrixType type) { - Gfx_LoadMatrix(type, &Matrix_Identity); +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } void Gfx_EnableTextureOffset(float x, float y) { diff --git a/src/Graphics_Xbox360.c b/src/Graphics_Xbox360.c index c0918cf4f..e37d89b21 100644 --- a/src/Graphics_Xbox360.c +++ b/src/Graphics_Xbox360.c @@ -317,7 +317,7 @@ void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) { static struct Matrix _view, _proj, _mvp; void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { - struct Matrix* dst = type == MATRIX_PROJECTION ? &_proj : &_view; + struct Matrix* dst = type == MATRIX_PROJ ? &_proj : &_view; *dst = *matrix; Matrix_Mul(&_mvp, &_view, &_proj); @@ -325,8 +325,10 @@ void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { Xe_SetVertexShaderConstantF(xe, 0, (float*)&_mvp, 4); } -void Gfx_LoadIdentityMatrix(MatrixType type) { - Gfx_LoadMatrix(type, &Matrix_Identity); +void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { + Gfx_LoadMatrix(MATRIX_VIEW, view); + Gfx_LoadMatrix(MATRIX_PROJ, proj); + Matrix_Mul(mvp, view, proj); } void Gfx_EnableTextureOffset(float x, float y) { diff --git a/src/HeldBlockRenderer.c b/src/HeldBlockRenderer.c index bd276f4d2..e74af7680 100644 --- a/src/HeldBlockRenderer.c +++ b/src/HeldBlockRenderer.c @@ -228,7 +228,7 @@ void HeldBlockRenderer_Render(float delta) { held_block = Inventory_SelectedBlock; view = Gfx.View; - Gfx_LoadMatrix(MATRIX_PROJECTION, &held_blockProj); + Gfx_LoadMatrix(MATRIX_PROJ, &held_blockProj); SetMatrix(); ResetHeldState(); @@ -237,7 +237,7 @@ void HeldBlockRenderer_Render(float delta) { if (!Camera.Active->isThirdPerson) HeldBlockRenderer_RenderModel(); Gfx.View = view; - Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx.Projection); + Gfx_LoadMatrix(MATRIX_PROJ, &Gfx.Projection); } diff --git a/src/Window_WiiU.c b/src/Window_WiiU.c index b50618124..01bfe1c2d 100644 --- a/src/Window_WiiU.c +++ b/src/Window_WiiU.c @@ -371,8 +371,8 @@ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { } static void DrawLauncher(void) { - Gfx_LoadIdentityMatrix(MATRIX_VIEW); - Gfx_LoadIdentityMatrix(MATRIX_PROJECTION); + Gfx_LoadMatrix(MATRIX_VIEW, &Matrix_Identity); + Gfx_LoadMatrix(MATRIX_PROJ, &Matrix_Identity); Gfx_SetDepthTest(false); Gfx_SetVertexFormat(VERTEX_FORMAT_COLOURED); diff --git a/src/_GraphicsBase.h b/src/_GraphicsBase.h index 8f46b3c14..8a6ad55d9 100644 --- a/src/_GraphicsBase.h +++ b/src/_GraphicsBase.h @@ -244,8 +244,8 @@ void Gfx_Begin2D(int width, int height) { struct Matrix ortho; /* intentionally biased more towards positive Z to reduce 2D clipping issues on the DS */ Gfx_CalcOrthoMatrix(&ortho, (float)width, (float)height, -100.0f, 1000.0f); - Gfx_LoadMatrix(MATRIX_PROJECTION, &ortho); - Gfx_LoadIdentityMatrix(MATRIX_VIEW); + Gfx_LoadMatrix(MATRIX_PROJ, &ortho); + Gfx_LoadMatrix(MATRIX_VIEW, &Matrix_Identity); Gfx_SetDepthTest(false); Gfx_SetDepthWrite(false);