Add the most basic implementation of a Mesh drawer as technically possible :)

This commit is contained in:
Magnus Norddahl 2022-12-28 15:56:39 +01:00 committed by Christoph Oelckers
parent 3cae271219
commit fadda8146d
4 changed files with 65 additions and 1 deletions

View file

@ -1,2 +1,52 @@
#include "hw_mesh.h"
void Mesh::Draw(FRenderState& renderstate)
{
auto pair = renderstate.AllocVertices(mVertices.Size());
memcpy(pair.first, mVertices.Data(), mVertices.Size() * sizeof(FFlatVertex));
int applyIndex = -1;
int depthFunc = -1;
for (const MeshDrawCommand& cmd : mDraws)
{
bool apply = applyIndex != cmd.ApplyIndex;
if (apply)
{
int newDepthFunc = mApplys[cmd.ApplyIndex].DepthFunc;
if (depthFunc != newDepthFunc)
{
depthFunc = newDepthFunc;
renderstate.SetDepthFunc(depthFunc);
}
applyIndex = cmd.ApplyIndex;
Apply(renderstate, mApplys[cmd.ApplyIndex]);
}
renderstate.Draw(cmd.DrawType, pair.second + cmd.Start, cmd.Count, apply);
}
}
void Mesh::Apply(FRenderState& renderstate, const MeshApplyState& state)
{
renderstate.mRenderStyle = state.RenderStyle;
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.mLightParms[0] = state.uLightDist;
renderstate.mLightParms[1] = state.uLightFactor;
renderstate.mLightParms[2] = state.uFogDensity;
renderstate.mLightParms[3] = state.uLightLevel;
}

View file

@ -1,7 +1,18 @@
#pragma once
#include "hw_meshbuilder.h"
class Mesh
{
public:
void Draw(FRenderState& renderstate);
private:
void Apply(FRenderState& renderstate, const MeshApplyState& apply);
TArray<MeshApplyState> mApplys;
TArray<MeshDrawCommand> mDraws;
TArray<FFlatVertex> mVertices;
friend class MeshBuilder;
};

View file

@ -51,7 +51,9 @@ void MeshBuilder::Apply()
std::unique_ptr<Mesh> MeshBuilder::Create()
{
auto mesh = std::make_unique<Mesh>();
mesh->mApplys = std::move(mApplys);
mesh->mDraws = std::move(mDraws);
mesh->mVertices = std::move(mVertices);
return mesh;
}

View file

@ -765,5 +765,6 @@ public:
SetColorMask(on, on, on, on);
}
friend class Mesh;
};