Generalize C3D_FVUnifMtx to support 2x4, 3x4 and 4x4 matrices
This commit is contained in:
parent
4814f804c6
commit
ae4d9aba93
@ -168,8 +168,8 @@ static void sceneRender(float iod)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the uniforms
|
// Update the uniforms
|
||||||
C3D_FVUnifMtx(GPU_VERTEX_SHADER, uLoc_projection, &projection);
|
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection);
|
||||||
C3D_FVUnifMtx(GPU_VERTEX_SHADER, uLoc_modelView, &modelView);
|
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_modelView, &modelView);
|
||||||
|
|
||||||
// Draw the VBO
|
// Draw the VBO
|
||||||
C3D_DrawArrays(GPU_TRIANGLES, 0, vertex_list_count);
|
C3D_DrawArrays(GPU_TRIANGLES, 0, vertex_list_count);
|
||||||
|
@ -47,7 +47,7 @@ static void sceneInit(void)
|
|||||||
static void sceneRender(void)
|
static void sceneRender(void)
|
||||||
{
|
{
|
||||||
// Update the uniforms
|
// Update the uniforms
|
||||||
C3D_FVUnifMtx(GPU_VERTEX_SHADER, uLoc_projection, &projection);
|
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection);
|
||||||
|
|
||||||
// Draw the triangle directly
|
// Draw the triangle directly
|
||||||
C3D_ImmDrawBegin(GPU_TRIANGLES);
|
C3D_ImmDrawBegin(GPU_TRIANGLES);
|
||||||
|
@ -71,7 +71,7 @@ static void sceneInit(void)
|
|||||||
static void sceneRender(void)
|
static void sceneRender(void)
|
||||||
{
|
{
|
||||||
// Update the uniforms
|
// Update the uniforms
|
||||||
C3D_FVUnifMtx(GPU_VERTEX_SHADER, uLoc_projection, &projection);
|
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection);
|
||||||
|
|
||||||
// Draw the VBO
|
// Draw the VBO
|
||||||
C3D_DrawArrays(GPU_TRIANGLES, 0, vertex_list_count);
|
C3D_DrawArrays(GPU_TRIANGLES, 0, vertex_list_count);
|
||||||
|
@ -161,9 +161,9 @@ static void sceneRender(void)
|
|||||||
angleY += M_PI / 360;
|
angleY += M_PI / 360;
|
||||||
|
|
||||||
// Update the uniforms
|
// Update the uniforms
|
||||||
C3D_FVUnifMtx(GPU_VERTEX_SHADER, uLoc_projection, &projection);
|
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection);
|
||||||
C3D_FVUnifMtx(GPU_VERTEX_SHADER, uLoc_modelView, &modelView);
|
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_modelView, &modelView);
|
||||||
C3D_FVUnifMtx(GPU_VERTEX_SHADER, uLoc_material, &material);
|
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_material, &material);
|
||||||
C3D_FVUnifSet(GPU_VERTEX_SHADER, uLoc_lightVec, 0.0f, 0.0f, -1.0f, 0.0f);
|
C3D_FVUnifSet(GPU_VERTEX_SHADER, uLoc_lightVec, 0.0f, 0.0f, -1.0f, 0.0f);
|
||||||
C3D_FVUnifSet(GPU_VERTEX_SHADER, uLoc_lightHalfVec, 0.0f, 0.0f, -1.0f, 0.0f);
|
C3D_FVUnifSet(GPU_VERTEX_SHADER, uLoc_lightHalfVec, 0.0f, 0.0f, -1.0f, 0.0f);
|
||||||
C3D_FVUnifSet(GPU_VERTEX_SHADER, uLoc_lightClr, 1.0f, 1.0f, 1.0f, 1.0f);
|
C3D_FVUnifSet(GPU_VERTEX_SHADER, uLoc_lightClr, 1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
@ -25,12 +25,27 @@ static inline C3D_IVec* C3D_IVUnifWritePtr(GPU_SHADER_TYPE type, int id)
|
|||||||
return &C3D_IVUnif[type][id];
|
return &C3D_IVUnif[type][id];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void C3D_FVUnifMtx(GPU_SHADER_TYPE type, int id, C3D_Mtx* mtx)
|
static inline void C3D_FVUnifMtxNx4(GPU_SHADER_TYPE type, int id, C3D_Mtx* mtx, int num)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
C3D_FVec* ptr = C3D_FVUnifWritePtr(type, id, 4);
|
C3D_FVec* ptr = C3D_FVUnifWritePtr(type, id, num);
|
||||||
for (i = 0; i < 4; i ++)
|
for (i = 0; i < num; i ++)
|
||||||
ptr[i] = mtx->r[i];
|
ptr[i] = mtx->r[i]; // Struct copy.
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void C3D_FVUnifMtx4x4(GPU_SHADER_TYPE type, int id, C3D_Mtx* mtx)
|
||||||
|
{
|
||||||
|
C3D_FVUnifMtxNx4(type, id, mtx, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void C3D_FVUnifMtx3x4(GPU_SHADER_TYPE type, int id, C3D_Mtx* mtx)
|
||||||
|
{
|
||||||
|
C3D_FVUnifMtxNx4(type, id, mtx, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void C3D_FVUnifMtx2x4(GPU_SHADER_TYPE type, int id, C3D_Mtx* mtx)
|
||||||
|
{
|
||||||
|
C3D_FVUnifMtxNx4(type, id, mtx, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void C3D_FVUnifSet(GPU_SHADER_TYPE type, int id, float x, float y, float z, float w)
|
static inline void C3D_FVUnifSet(GPU_SHADER_TYPE type, int id, float x, float y, float z, float w)
|
||||||
|
@ -36,10 +36,7 @@ void MtxStack_Update(C3D_MtxStack* stk)
|
|||||||
if (!stk->isDirty) return;
|
if (!stk->isDirty) return;
|
||||||
|
|
||||||
if (stk->unifPos != 0xFF)
|
if (stk->unifPos != 0xFF)
|
||||||
{
|
C3D_FVUnifMtxNx4(stk->unifType, stk->unifPos, &stk->m[stk->pos], stk->unifLen);
|
||||||
C3D_FVec* out = C3D_FVUnifWritePtr(stk->unifType, stk->unifPos, stk->unifLen);
|
|
||||||
memcpy(out, &stk->m[stk->pos], (u32)stk->unifLen * sizeof(C3D_FVec));
|
|
||||||
}
|
|
||||||
|
|
||||||
stk->isDirty = false;
|
stk->isDirty = false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user