mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 17:12:25 -05:00
WIP rework on gfx matrix loading
This commit is contained in:
parent
2323b12599
commit
a1d5d241fa
25 changed files with 145 additions and 91 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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); }
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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); }
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue