Change the matrix interface on RenderState so the backend doesn't have to try detect changes on each Apply
Include the texture matrix in the mesh builder
This commit is contained in:
parent
96ac7ba3f0
commit
eba0bee9f6
17 changed files with 126 additions and 136 deletions
|
|
@ -42,6 +42,7 @@ void Mesh::Draw(FRenderState& renderstate)
|
|||
origState.applyData.TextureModeFlags = renderstate.mTextureModeFlags;
|
||||
origState.streamData = renderstate.mStreamData;
|
||||
origState.material = renderstate.mMaterial;
|
||||
origState.textureMatrix.loadIdentity();
|
||||
|
||||
int applyIndex = -1;
|
||||
int depthFunc = -1;
|
||||
|
|
@ -106,4 +107,5 @@ void Mesh::Apply(FRenderState& renderstate, const MeshApplyState& state)
|
|||
renderstate.mTextureModeFlags = state.applyData.TextureModeFlags;
|
||||
renderstate.mStreamData = state.streamData;
|
||||
renderstate.mMaterial = state.material;
|
||||
renderstate.SetTextureMatrix(state.textureMatrix);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ void MeshBuilder::Apply()
|
|||
state.applyData.TextureModeFlags = mTextureModeFlags;
|
||||
state.streamData = mStreamData;
|
||||
state.material = mMaterial;
|
||||
state.textureMatrix = mTextureMatrix;
|
||||
|
||||
state.streamData.uVertexNormal = FVector4(0.0f, 0.0f, 0.0f, 0.0f); // Grr, this should be part of the vertex!!
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ public:
|
|||
ApplyData applyData;
|
||||
StreamData streamData;
|
||||
FMaterialState material;
|
||||
VSMatrix textureMatrix;
|
||||
|
||||
bool operator<(const MeshApplyState& other) const
|
||||
{
|
||||
|
|
@ -43,6 +44,10 @@ public:
|
|||
if (result != 0)
|
||||
return result < 0;
|
||||
|
||||
result = memcmp(&textureMatrix, &other.textureMatrix, sizeof(VSMatrix));
|
||||
if (result != 0)
|
||||
return result < 0;
|
||||
|
||||
result = memcmp(&streamData, &other.streamData, sizeof(StreamData));
|
||||
return result < 0;
|
||||
}
|
||||
|
|
@ -68,6 +73,8 @@ public:
|
|||
// Buffers
|
||||
int SetViewpoint(const HWViewpointUniforms& vp) override { return 0; }
|
||||
void SetViewpoint(int index) override { }
|
||||
void SetModelMatrix(const VSMatrix& matrix, const VSMatrix& normalMatrix) override { }
|
||||
void SetTextureMatrix(const VSMatrix& matrix) override { mTextureMatrix = matrix; }
|
||||
int UploadLights(const FDynLightData& lightdata) override { return -1; }
|
||||
int UploadBones(const TArray<VSMatrix>& bones) override { return -1; }
|
||||
|
||||
|
|
@ -109,4 +116,6 @@ private:
|
|||
|
||||
TArray<FFlatVertex> mVertices;
|
||||
int mDepthFunc = 0;
|
||||
|
||||
VSMatrix mTextureMatrix = VSMatrix::identity();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -228,8 +228,6 @@ protected:
|
|||
uint8_t mTextureEnabled:1;
|
||||
uint8_t mGlowEnabled : 1;
|
||||
uint8_t mGradientEnabled : 1;
|
||||
uint8_t mModelMatrixEnabled : 1;
|
||||
uint8_t mTextureMatrixEnabled : 1;
|
||||
uint8_t mSplitEnabled : 1;
|
||||
uint8_t mBrightmapEnabled : 1;
|
||||
|
||||
|
|
@ -262,10 +260,6 @@ protected:
|
|||
public:
|
||||
|
||||
uint64_t firstFrame = 0;
|
||||
VSMatrix mModelMatrix;
|
||||
VSMatrix mTextureMatrix;
|
||||
|
||||
public:
|
||||
|
||||
void Reset()
|
||||
{
|
||||
|
|
@ -278,8 +272,6 @@ public:
|
|||
mTextureModeFlags = 0;
|
||||
mStreamData.uDesaturationFactor = 0.0f;
|
||||
mStreamData.uAlphaThreshold = 0.5f;
|
||||
mModelMatrixEnabled = false;
|
||||
mTextureMatrixEnabled = false;
|
||||
mSplitEnabled = false;
|
||||
mStreamData.uAddColor = 0;
|
||||
mStreamData.uObjectColor = 0xffffffff;
|
||||
|
|
@ -322,8 +314,6 @@ public:
|
|||
#ifdef NPOT_EMULATION
|
||||
mStreamData.uNpotEmulation = { 0,0,0,0 };
|
||||
#endif
|
||||
mModelMatrix.loadIdentity();
|
||||
mTextureMatrix.loadIdentity();
|
||||
ClearClipSplit();
|
||||
}
|
||||
|
||||
|
|
@ -448,16 +438,6 @@ public:
|
|||
mSplitEnabled = on;
|
||||
}
|
||||
|
||||
void EnableModelMatrix(bool on)
|
||||
{
|
||||
mModelMatrixEnabled = on;
|
||||
}
|
||||
|
||||
void EnableTextureMatrix(bool on)
|
||||
{
|
||||
mTextureMatrixEnabled = on;
|
||||
}
|
||||
|
||||
void SetGlowParams(float *t, float *b)
|
||||
{
|
||||
mStreamData.uGlowTopColor = { t[0], t[1], t[2], t[3] };
|
||||
|
|
@ -759,6 +739,8 @@ public:
|
|||
// Buffers
|
||||
virtual int SetViewpoint(const HWViewpointUniforms& vp) = 0;
|
||||
virtual void SetViewpoint(int index) = 0;
|
||||
virtual void SetModelMatrix(const VSMatrix& matrix, const VSMatrix& normalMatrix) = 0;
|
||||
virtual void SetTextureMatrix(const VSMatrix& matrix) = 0;
|
||||
virtual int UploadLights(const FDynLightData& lightdata) = 0;
|
||||
virtual int UploadBones(const TArray<VSMatrix>& bones) = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -384,11 +384,12 @@ void FSkyVertexBuffer::CreateDome()
|
|||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void FSkyVertexBuffer::SetupMatrices(FGameTexture *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelMatrix, VSMatrix &textureMatrix, bool tiled, float xscale, float yscale)
|
||||
void FSkyVertexBuffer::SetupMatrices(FRenderState& state, FGameTexture *tex, float x_offset, float y_offset, bool mirror, int mode, bool tiled, float xscale, float yscale)
|
||||
{
|
||||
float texw = tex->GetDisplayWidth();
|
||||
float texh = tex->GetDisplayHeight();
|
||||
|
||||
VSMatrix modelMatrix;
|
||||
modelMatrix.loadIdentity();
|
||||
modelMatrix.rotate(-180.0f + x_offset, 0.f, 1.f, 0.f);
|
||||
|
||||
|
|
@ -433,9 +434,16 @@ void FSkyVertexBuffer::SetupMatrices(FGameTexture *tex, float x_offset, float y_
|
|||
modelMatrix.translate(0.f, (-40 + texskyoffset) * skyoffsetfactor, 0.f);
|
||||
modelMatrix.scale(1.f, 0.8f * 1.17f, 1.f);
|
||||
}
|
||||
|
||||
VSMatrix normalModelMatrix;
|
||||
normalModelMatrix.computeNormalMatrix(modelMatrix);
|
||||
state.SetModelMatrix(modelMatrix, normalModelMatrix);
|
||||
|
||||
VSMatrix textureMatrix;
|
||||
textureMatrix.loadIdentity();
|
||||
textureMatrix.scale(mirror ? -xscale : xscale, yscale, 1.f);
|
||||
textureMatrix.translate(1.f, y_offset / texh, 1.f);
|
||||
state.SetTextureMatrix(textureMatrix);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -461,8 +469,6 @@ void FSkyVertexBuffer::DoRenderDome(FRenderState& state, FGameTexture* tex, int
|
|||
if (tex && tex->isValid())
|
||||
{
|
||||
state.SetMaterial(tex, UF_Texture, 0, CLAMP_NONE, 0, -1);
|
||||
state.EnableModelMatrix(true);
|
||||
state.EnableTextureMatrix(true);
|
||||
}
|
||||
|
||||
int rc = mRows + 1;
|
||||
|
|
@ -494,8 +500,8 @@ void FSkyVertexBuffer::DoRenderDome(FRenderState& state, FGameTexture* tex, int
|
|||
RenderRow(state, DT_TriangleStrip, rc + i, primStart, false);
|
||||
}
|
||||
|
||||
state.EnableTextureMatrix(false);
|
||||
state.EnableModelMatrix(false);
|
||||
state.SetTextureMatrix(VSMatrix::identity());
|
||||
state.SetModelMatrix(VSMatrix::identity(), VSMatrix::identity());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -509,7 +515,7 @@ void FSkyVertexBuffer::RenderDome(FRenderState& state, FGameTexture* tex, float
|
|||
{
|
||||
if (tex)
|
||||
{
|
||||
SetupMatrices(tex, x_offset, y_offset, mirror, mode, state.mModelMatrix, state.mTextureMatrix, tiled, xscale, yscale);
|
||||
SetupMatrices(state, tex, x_offset, y_offset, mirror, mode, tiled, xscale, yscale);
|
||||
}
|
||||
DoRenderDome(state, tex, mode, false, color);
|
||||
}
|
||||
|
|
@ -526,14 +532,19 @@ void FSkyVertexBuffer::RenderBox(FRenderState& state, FSkyBox* tex, float x_offs
|
|||
int faces;
|
||||
|
||||
state.SetObjectColor(color);
|
||||
state.EnableModelMatrix(true);
|
||||
state.mModelMatrix.loadIdentity();
|
||||
state.mModelMatrix.scale(1, 1 / stretch, 1); // Undo the map's vertical scaling as skyboxes are true cubes.
|
||||
|
||||
VSMatrix modelMatrix;
|
||||
modelMatrix.loadIdentity();
|
||||
modelMatrix.scale(1, 1 / stretch, 1); // Undo the map's vertical scaling as skyboxes are true cubes.
|
||||
|
||||
if (!sky2)
|
||||
state.mModelMatrix.rotate(-180.0f + x_offset, skyrotatevector.X, skyrotatevector.Z, skyrotatevector.Y);
|
||||
modelMatrix.rotate(-180.0f + x_offset, skyrotatevector.X, skyrotatevector.Z, skyrotatevector.Y);
|
||||
else
|
||||
state.mModelMatrix.rotate(-180.0f + x_offset, skyrotatevector2.X, skyrotatevector2.Z, skyrotatevector2.Y);
|
||||
modelMatrix.rotate(-180.0f + x_offset, skyrotatevector2.X, skyrotatevector2.Z, skyrotatevector2.Y);
|
||||
|
||||
VSMatrix normalModelMatrix;
|
||||
normalModelMatrix.computeNormalMatrix(modelMatrix);
|
||||
state.SetModelMatrix(modelMatrix, normalModelMatrix);
|
||||
|
||||
if (tex->GetSkyFace(5))
|
||||
{
|
||||
|
|
@ -570,7 +581,7 @@ void FSkyVertexBuffer::RenderBox(FRenderState& state, FSkyBox* tex, float x_offs
|
|||
state.SetMaterial(tex->GetSkyFace(faces + 1), UF_Texture, 0, CLAMP_XY, 0, -1);
|
||||
state.Draw(DT_TriangleStrip, FaceStart(4), 4);
|
||||
|
||||
state.EnableModelMatrix(false);
|
||||
state.SetModelMatrix(VSMatrix::identity(), VSMatrix::identity());
|
||||
state.SetObjectColor(0xffffffff);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ public:
|
|||
|
||||
FSkyVertexBuffer(DFrameBuffer* fb);
|
||||
~FSkyVertexBuffer();
|
||||
void SetupMatrices(FGameTexture *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelmatrix, VSMatrix &textureMatrix, bool tiled, float xscale = 0, float vertscale = 0);
|
||||
void SetupMatrices(FRenderState& state, FGameTexture *tex, float x_offset, float y_offset, bool mirror, int mode, bool tiled, float xscale = 0, float vertscale = 0);
|
||||
std::pair<IBuffer*, IBuffer*> GetBufferObjects() const
|
||||
{
|
||||
return std::make_pair(mVertexBuffer, nullptr);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue