Fix misc state init issues

This commit is contained in:
Magnus Norddahl 2022-12-28 17:06:27 +01:00 committed by Christoph Oelckers
parent fadda8146d
commit 528afe3ee3
3 changed files with 49 additions and 11 deletions

View file

@ -6,6 +6,25 @@ void Mesh::Draw(FRenderState& renderstate)
auto pair = renderstate.AllocVertices(mVertices.Size());
memcpy(pair.first, mVertices.Data(), mVertices.Size() * sizeof(FFlatVertex));
MeshApplyState origState;
origState.RenderStyle = renderstate.mRenderStyle;
origState.SpecialEffect = renderstate.mSpecialEffect;
origState.TextureEnabled = renderstate.mTextureEnabled;
origState.AlphaThreshold = renderstate.mAlphaThreshold;
origState.streamData = renderstate.mStreamData;
origState.material = renderstate.mMaterial;
origState.FogEnabled = renderstate.mFogEnabled;
origState.BrightmapEnabled = renderstate.mBrightmapEnabled;
origState.TextureClamp = renderstate.mTextureClamp;
origState.TextureMode = renderstate.mTextureMode;
origState.TextureModeFlags = renderstate.mTextureModeFlags;
origState.uLightDist = renderstate.mLightParms[0];
origState.uLightFactor = renderstate.mLightParms[1];
origState.uFogDensity = renderstate.mLightParms[2];
origState.uLightLevel = renderstate.mLightParms[3];
origState.uClipSplit[0] = renderstate.mClipSplit[0];
origState.uClipSplit[1] = renderstate.mClipSplit[1];
int applyIndex = -1;
int depthFunc = -1;
for (const MeshDrawCommand& cmd : mDraws)
@ -25,6 +44,8 @@ void Mesh::Draw(FRenderState& renderstate)
}
renderstate.Draw(cmd.DrawType, pair.second + cmd.Start, cmd.Count, apply);
}
Apply(renderstate, origState);
}
void Mesh::Apply(FRenderState& renderstate, const MeshApplyState& state)
@ -33,20 +54,17 @@ void Mesh::Apply(FRenderState& renderstate, const MeshApplyState& state)
renderstate.mSpecialEffect = state.SpecialEffect;
renderstate.mTextureEnabled = state.TextureEnabled;
renderstate.mAlphaThreshold = state.AlphaThreshold;
renderstate.mStreamData = state.streamData;
renderstate.mMaterial = state.material;
renderstate.mClipSplit[0] = state.uClipSplit[0];
renderstate.mClipSplit[1] = state.uClipSplit[1];
renderstate.mFogEnabled = state.FogEnabled;
renderstate.mBrightmapEnabled = state.BrightmapEnabled;
renderstate.mTextureClamp = state.TextureClamp;
renderstate.mTextureMode = state.TextureMode;
renderstate.mTextureModeFlags = state.TextureModeFlags;
renderstate.mLightParms[0] = state.uLightDist;
renderstate.mLightParms[1] = state.uLightFactor;
renderstate.mLightParms[2] = state.uFogDensity;
renderstate.mLightParms[3] = state.uLightLevel;
renderstate.mClipSplit[0] = state.uClipSplit[0];
renderstate.mClipSplit[1] = state.uClipSplit[1];
}

View file

@ -2,6 +2,22 @@
#include "hw_meshbuilder.h"
#include "hw_mesh.h"
MeshBuilder::MeshBuilder()
{
Reset();
// Initialize state same way as it begins in HWDrawInfo::RenderScene:
SetTextureMode(TM_NORMAL);
SetDepthMask(true);
EnableFog(true);
SetRenderStyle(STYLE_Source);
SetDepthFunc(DF_Less);
AlphaFunc(Alpha_GEqual, 0.f);
ClearDepthBias();
EnableTexture(1);
EnableBrightmap(true);
}
void MeshBuilder::Draw(int dt, int index, int count, bool apply)
{
if (apply)
@ -33,18 +49,19 @@ void MeshBuilder::Apply()
state.streamData = mStreamData;
state.material = mMaterial;
state.uClipSplit = { mClipSplit[0], mClipSplit[1] };
state.FogEnabled = mFogEnabled;
state.BrightmapEnabled = mBrightmapEnabled;
state.TextureClamp = mTextureClamp;
state.TextureMode = mTextureMode;
state.TextureModeFlags = mTextureModeFlags;
state.uLightDist = mLightParms[0];
state.uLightFactor = mLightParms[1];
state.uFogDensity = mLightParms[2];
state.uLightLevel = mLightParms[3];
state.uClipSplit = { mClipSplit[0], mClipSplit[1] };
mApplys.Push(state);
}

View file

@ -18,17 +18,18 @@ public:
StreamData streamData;
FMaterialState material;
FVector2 uClipSplit;
uint8_t FogEnabled;
uint8_t BrightmapEnabled;
int TextureClamp;
int TextureMode;
int TextureModeFlags;
float uLightLevel;
float uFogDensity;
float uLightFactor;
float uLightDist;
FVector2 uClipSplit;
};
class MeshDrawCommand
@ -43,6 +44,8 @@ public:
class MeshBuilder : public FRenderState
{
public:
MeshBuilder();
// Vertices
std::pair<FFlatVertex*, unsigned int> AllocVertices(unsigned int count) override;
@ -63,7 +66,7 @@ public:
void EnableDrawBuffers(int count, bool apply) override { }
void EnableClipDistance(int num, bool state) override { }
void SetDepthRange(float min, float max) override { }
bool SetDepthClamp(bool on) override { }
bool SetDepthClamp(bool on) override { return false; }
void SetDepthMask(bool on) override { }
void SetColorMask(bool r, bool g, bool b, bool a) override { }
void SetStencil(int offs, int op, int flags = -1) override { }