Merge pull request #3070 from lioncash/vert
VertexShaderManager: Get rid of float pointer casts.
This commit is contained in:
commit
0d0704453e
|
@ -73,7 +73,7 @@ static void MultipleVec3Ortho(const Vec3 &vec, const float *proj, Vec4 &result)
|
|||
|
||||
void TransformPosition(const InputVertexData *src, OutputVertexData *dst)
|
||||
{
|
||||
const float* mat = (const float*)&xfmem.posMatrices[src->posMtx * 4];
|
||||
const float* mat = &xfmem.posMatrices[src->posMtx * 4];
|
||||
MultiplyVec3Mat34(src->position, mat, dst->mvPosition);
|
||||
|
||||
if (xfmem.projection.type == GX_PERSPECTIVE)
|
||||
|
@ -88,7 +88,7 @@ void TransformPosition(const InputVertexData *src, OutputVertexData *dst)
|
|||
|
||||
void TransformNormal(const InputVertexData *src, bool nbt, OutputVertexData *dst)
|
||||
{
|
||||
const float* mat = (const float*)&xfmem.normalMatrices[(src->posMtx & 31) * 3];
|
||||
const float* mat = &xfmem.normalMatrices[(src->posMtx & 31) * 3];
|
||||
|
||||
if (nbt)
|
||||
{
|
||||
|
@ -127,8 +127,8 @@ static void TransformTexCoordRegular(const TexMtxInfo &texinfo, int coordNum, bo
|
|||
break;
|
||||
}
|
||||
|
||||
const float *mat = (const float*)&xfmem.posMatrices[srcVertex->texMtx[coordNum] * 4];
|
||||
Vec3 *dst = &dstVertex->texCoords[coordNum];
|
||||
const float* mat = &xfmem.posMatrices[srcVertex->texMtx[coordNum] * 4];
|
||||
Vec3* dst = &dstVertex->texCoords[coordNum];
|
||||
|
||||
if (texinfo.projection == XF_TEXPROJ_ST)
|
||||
{
|
||||
|
@ -153,7 +153,7 @@ static void TransformTexCoordRegular(const TexMtxInfo &texinfo, int coordNum, bo
|
|||
|
||||
// normalize
|
||||
const PostMtxInfo &postInfo = xfmem.postMtxInfo[coordNum];
|
||||
const float *postMat = (const float*)&xfmem.postMatrices[postInfo.index * 4];
|
||||
const float* postMat = &xfmem.postMatrices[postInfo.index * 4];
|
||||
|
||||
if (specialCase)
|
||||
{
|
||||
|
|
|
@ -4,9 +4,11 @@
|
|||
|
||||
#include <cfloat>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
#include "Common/BitSet.h"
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/MathUtil.h"
|
||||
#include "Core/ConfigManager.h"
|
||||
|
@ -236,7 +238,7 @@ void VertexShaderManager::SetConstants()
|
|||
{
|
||||
int startn = nTransformMatricesChanged[0] / 4;
|
||||
int endn = (nTransformMatricesChanged[1] + 3) / 4;
|
||||
memcpy(constants.transformmatrices[startn], &xfmem.posMatrices[startn * 4], (endn - startn) * 16);
|
||||
memcpy(constants.transformmatrices[startn], &xfmem.posMatrices[startn * 4], (endn - startn) * sizeof(float4));
|
||||
dirty = true;
|
||||
nTransformMatricesChanged[0] = nTransformMatricesChanged[1] = -1;
|
||||
}
|
||||
|
@ -257,7 +259,7 @@ void VertexShaderManager::SetConstants()
|
|||
{
|
||||
int startn = nPostTransformMatricesChanged[0] / 4;
|
||||
int endn = (nPostTransformMatricesChanged[1] + 3) / 4;
|
||||
memcpy(constants.posttransformmatrices[startn], &xfmem.postMatrices[startn * 4], (endn - startn) * 16);
|
||||
memcpy(constants.posttransformmatrices[startn], &xfmem.postMatrices[startn * 4], (endn - startn) * sizeof(float4));
|
||||
dirty = true;
|
||||
nPostTransformMatricesChanged[0] = nPostTransformMatricesChanged[1] = -1;
|
||||
}
|
||||
|
@ -331,30 +333,30 @@ void VertexShaderManager::SetConstants()
|
|||
{
|
||||
bPosNormalMatrixChanged = false;
|
||||
|
||||
const float *pos = (const float *)xfmem.posMatrices + g_main_cp_state.matrix_index_a.PosNormalMtxIdx * 4;
|
||||
const float *norm = (const float *)xfmem.normalMatrices + 3 * (g_main_cp_state.matrix_index_a.PosNormalMtxIdx & 31);
|
||||
const float* pos = &xfmem.posMatrices[g_main_cp_state.matrix_index_a.PosNormalMtxIdx * 4];
|
||||
const float* norm = &xfmem.normalMatrices[3 * (g_main_cp_state.matrix_index_a.PosNormalMtxIdx & 31)];
|
||||
|
||||
memcpy(constants.posnormalmatrix, pos, 3*16);
|
||||
memcpy(constants.posnormalmatrix[3], norm, 12);
|
||||
memcpy(constants.posnormalmatrix[4], norm+3, 12);
|
||||
memcpy(constants.posnormalmatrix[5], norm+6, 12);
|
||||
memcpy(constants.posnormalmatrix, pos, 3 * sizeof(float4));
|
||||
memcpy(constants.posnormalmatrix[3], norm, 3 * sizeof(float));
|
||||
memcpy(constants.posnormalmatrix[4], norm + 3, 3 * sizeof(float));
|
||||
memcpy(constants.posnormalmatrix[5], norm + 6, 3 * sizeof(float));
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if (bTexMatricesChanged[0])
|
||||
{
|
||||
bTexMatricesChanged[0] = false;
|
||||
const float *fptrs[] =
|
||||
const float* pos_matrix_ptrs[] =
|
||||
{
|
||||
(const float *)&xfmem.posMatrices[g_main_cp_state.matrix_index_a.Tex0MtxIdx * 4],
|
||||
(const float *)&xfmem.posMatrices[g_main_cp_state.matrix_index_a.Tex1MtxIdx * 4],
|
||||
(const float *)&xfmem.posMatrices[g_main_cp_state.matrix_index_a.Tex2MtxIdx * 4],
|
||||
(const float *)&xfmem.posMatrices[g_main_cp_state.matrix_index_a.Tex3MtxIdx * 4]
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_a.Tex0MtxIdx * 4],
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_a.Tex1MtxIdx * 4],
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_a.Tex2MtxIdx * 4],
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_a.Tex3MtxIdx * 4]
|
||||
};
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (size_t i = 0; i < ArraySize(pos_matrix_ptrs); ++i)
|
||||
{
|
||||
memcpy(constants.texmatrices[3 * i], fptrs[i], 3 * 16);
|
||||
memcpy(constants.texmatrices[3 * i], pos_matrix_ptrs[i], 3 * sizeof(float4));
|
||||
}
|
||||
dirty = true;
|
||||
}
|
||||
|
@ -362,16 +364,16 @@ void VertexShaderManager::SetConstants()
|
|||
if (bTexMatricesChanged[1])
|
||||
{
|
||||
bTexMatricesChanged[1] = false;
|
||||
const float *fptrs[] = {
|
||||
(const float *)&xfmem.posMatrices[g_main_cp_state.matrix_index_b.Tex4MtxIdx * 4],
|
||||
(const float *)&xfmem.posMatrices[g_main_cp_state.matrix_index_b.Tex5MtxIdx * 4],
|
||||
(const float *)&xfmem.posMatrices[g_main_cp_state.matrix_index_b.Tex6MtxIdx * 4],
|
||||
(const float *)&xfmem.posMatrices[g_main_cp_state.matrix_index_b.Tex7MtxIdx * 4]
|
||||
const float* pos_matrix_ptrs[] = {
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_b.Tex4MtxIdx * 4],
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_b.Tex5MtxIdx * 4],
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_b.Tex6MtxIdx * 4],
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_b.Tex7MtxIdx * 4]
|
||||
};
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (size_t i = 0; i < ArraySize(pos_matrix_ptrs); ++i)
|
||||
{
|
||||
memcpy(constants.texmatrices[3*i + 12], fptrs[i], 3*16);
|
||||
memcpy(constants.texmatrices[3*i + 12], pos_matrix_ptrs[i], 3 * sizeof(float4));
|
||||
}
|
||||
dirty = true;
|
||||
}
|
||||
|
@ -531,7 +533,7 @@ void VertexShaderManager::SetConstants()
|
|||
Matrix44::Set(mtxB, g_fProjectionMatrix);
|
||||
Matrix44::Multiply(mtxB, viewMtx, mtxA); // mtxA = projection x view
|
||||
Matrix44::Multiply(s_viewportCorrection, mtxA, mtxB); // mtxB = viewportCorrection x mtxA
|
||||
memcpy(constants.projection, mtxB.data, 4*16);
|
||||
memcpy(constants.projection, mtxB.data, 4 * sizeof(float4));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -540,7 +542,7 @@ void VertexShaderManager::SetConstants()
|
|||
|
||||
Matrix44 correctedMtx;
|
||||
Matrix44::Multiply(s_viewportCorrection, projMtx, correctedMtx);
|
||||
memcpy(constants.projection, correctedMtx.data, 4*16);
|
||||
memcpy(constants.projection, correctedMtx.data, 4 * sizeof(float4));
|
||||
}
|
||||
|
||||
dirty = true;
|
||||
|
@ -695,7 +697,7 @@ void VertexShaderManager::TranslateView(float x, float y, float z)
|
|||
|
||||
Matrix33::Multiply(s_viewInvRotationMatrix, vector, result);
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (size_t i = 0; i < ArraySize(result); i++)
|
||||
s_fViewTranslationVector[i] += result[i];
|
||||
|
||||
bProjectionChanged = true;
|
||||
|
@ -732,16 +734,18 @@ void VertexShaderManager::ResetView()
|
|||
|
||||
void VertexShaderManager::TransformToClipSpace(const float* data, float* out, u32 MtxIdx)
|
||||
{
|
||||
const float* world_matrix = (const float*)xfmem.posMatrices + (MtxIdx & 0x3f) * 4;
|
||||
// We use the projection matrix calculated by vertexShaderManager, because it
|
||||
const float* world_matrix = &xfmem.posMatrices[(MtxIdx & 0x3f) * 4];
|
||||
|
||||
// We use the projection matrix calculated by VertexShaderManager, because it
|
||||
// includes any free look transformations.
|
||||
// Make sure VertexManager::SetConstants() has been called first.
|
||||
const float* proj_matrix = &g_fProjectionMatrix[0];
|
||||
|
||||
float t[3];
|
||||
t[0] = data[0] * world_matrix[0] + data[1] * world_matrix[1] + data[2] * world_matrix[2] + world_matrix[3];
|
||||
t[1] = data[0] * world_matrix[4] + data[1] * world_matrix[5] + data[2] * world_matrix[6] + world_matrix[7];
|
||||
t[2] = data[0] * world_matrix[8] + data[1] * world_matrix[9] + data[2] * world_matrix[10] + world_matrix[11];
|
||||
const float t[3] = {
|
||||
data[0] * world_matrix[0] + data[1] * world_matrix[1] + data[2] * world_matrix[2] + world_matrix[3],
|
||||
data[0] * world_matrix[4] + data[1] * world_matrix[5] + data[2] * world_matrix[6] + world_matrix[7],
|
||||
data[0] * world_matrix[8] + data[1] * world_matrix[9] + data[2] * world_matrix[10] + world_matrix[11]
|
||||
};
|
||||
|
||||
out[0] = t[0] * proj_matrix[0] + t[1] * proj_matrix[1] + t[2] * proj_matrix[2] + proj_matrix[3];
|
||||
out[1] = t[0] * proj_matrix[4] + t[1] * proj_matrix[5] + t[2] * proj_matrix[6] + proj_matrix[7];
|
||||
|
|
|
@ -267,11 +267,11 @@ struct Projection
|
|||
|
||||
struct XFMemory
|
||||
{
|
||||
u32 posMatrices[256]; // 0x0000 - 0x00ff
|
||||
float posMatrices[256]; // 0x0000 - 0x00ff
|
||||
u32 unk0[768]; // 0x0100 - 0x03ff
|
||||
u32 normalMatrices[96]; // 0x0400 - 0x045f
|
||||
float normalMatrices[96]; // 0x0400 - 0x045f
|
||||
u32 unk1[160]; // 0x0460 - 0x04ff
|
||||
u32 postMatrices[256]; // 0x0500 - 0x05ff
|
||||
float postMatrices[256]; // 0x0500 - 0x05ff
|
||||
Light lights[8]; // 0x0600 - 0x067f
|
||||
u32 unk2[2432]; // 0x0680 - 0x0fff
|
||||
u32 error; // 0x1000
|
||||
|
|
Loading…
Reference in New Issue