mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-26 14:01:45 +00:00
Add a basic renderstate->mesh builder class
This commit is contained in:
parent
b5e2de91a4
commit
4be3e2d53a
7 changed files with 168 additions and 0 deletions
|
@ -1107,6 +1107,8 @@ set (PCH_SOURCES
|
|||
common/rendering/hwrenderer/data/hw_shadowmap.cpp
|
||||
common/rendering/hwrenderer/data/hw_shaderpatcher.cpp
|
||||
common/rendering/hwrenderer/data/hw_collision.cpp
|
||||
common/rendering/hwrenderer/data/hw_meshbuilder.cpp
|
||||
common/rendering/hwrenderer/data/hw_mesh.cpp
|
||||
common/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp
|
||||
common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp
|
||||
common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "cmdlib.h"
|
||||
#include "printf.h"
|
||||
#include "hwrenderer/data/buffers.h"
|
||||
#include "hw_renderstate.h"
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
|
@ -176,3 +177,9 @@ void FFlatVertexBuffer::Copy(int start, int count)
|
|||
mVertexBuffer = old;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
||||
std::pair<FFlatVertex*, unsigned int> FRenderState::AllocVertices(unsigned int count)
|
||||
{
|
||||
return screen->mVertexData->AllocVertices(count);
|
||||
}
|
||||
|
|
2
src/common/rendering/hwrenderer/data/hw_mesh.cpp
Normal file
2
src/common/rendering/hwrenderer/data/hw_mesh.cpp
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
#include "hw_mesh.h"
|
7
src/common/rendering/hwrenderer/data/hw_mesh.h
Normal file
7
src/common/rendering/hwrenderer/data/hw_mesh.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
class Mesh
|
||||
{
|
||||
public:
|
||||
|
||||
};
|
62
src/common/rendering/hwrenderer/data/hw_meshbuilder.cpp
Normal file
62
src/common/rendering/hwrenderer/data/hw_meshbuilder.cpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
|
||||
#include "hw_meshbuilder.h"
|
||||
#include "hw_mesh.h"
|
||||
|
||||
void MeshBuilder::Draw(int dt, int index, int count, bool apply)
|
||||
{
|
||||
if (apply)
|
||||
Apply();
|
||||
|
||||
MeshDrawCommand command;
|
||||
command.DrawType = dt;
|
||||
command.Start = index;
|
||||
command.Count = count;
|
||||
command.ApplyIndex = mApplys.Size() - 1;
|
||||
mDraws.Push(command);
|
||||
}
|
||||
|
||||
void MeshBuilder::SetDepthFunc(int func)
|
||||
{
|
||||
mDepthFunc = func;
|
||||
}
|
||||
|
||||
void MeshBuilder::Apply()
|
||||
{
|
||||
MeshApplyState state;
|
||||
|
||||
state.RenderStyle = mRenderStyle;
|
||||
state.SpecialEffect = mSpecialEffect;
|
||||
state.TextureEnabled = mTextureEnabled;
|
||||
state.AlphaThreshold = mAlphaThreshold;
|
||||
state.DepthFunc = mDepthFunc;
|
||||
|
||||
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.uLightDist = mLightParms[0];
|
||||
state.uLightFactor = mLightParms[1];
|
||||
state.uFogDensity = mLightParms[2];
|
||||
state.uLightLevel = mLightParms[3];
|
||||
|
||||
mApplys.Push(state);
|
||||
}
|
||||
|
||||
std::unique_ptr<Mesh> MeshBuilder::Create()
|
||||
{
|
||||
auto mesh = std::make_unique<Mesh>();
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
std::pair<FFlatVertex*, unsigned int> MeshBuilder::AllocVertices(unsigned int count)
|
||||
{
|
||||
unsigned int offset = mVertices.Reserve(count);
|
||||
return { &mVertices[offset], offset };
|
||||
}
|
83
src/common/rendering/hwrenderer/data/hw_meshbuilder.h
Normal file
83
src/common/rendering/hwrenderer/data/hw_meshbuilder.h
Normal file
|
@ -0,0 +1,83 @@
|
|||
#pragma once
|
||||
|
||||
#include "hw_renderstate.h"
|
||||
#include "hw_material.h"
|
||||
#include "flatvertices.h"
|
||||
|
||||
class Mesh;
|
||||
|
||||
class MeshApplyState
|
||||
{
|
||||
public:
|
||||
FRenderStyle RenderStyle;
|
||||
int SpecialEffect;
|
||||
bool TextureEnabled;
|
||||
float AlphaThreshold;
|
||||
int DepthFunc;
|
||||
|
||||
StreamData streamData;
|
||||
FMaterialState material;
|
||||
|
||||
FVector2 uClipSplit;
|
||||
|
||||
uint8_t FogEnabled;
|
||||
uint8_t BrightmapEnabled;
|
||||
int TextureClamp;
|
||||
int TextureMode;
|
||||
|
||||
float uLightLevel;
|
||||
float uFogDensity;
|
||||
float uLightFactor;
|
||||
float uLightDist;
|
||||
};
|
||||
|
||||
class MeshDrawCommand
|
||||
{
|
||||
public:
|
||||
int DrawType;
|
||||
int Start;
|
||||
int Count;
|
||||
int ApplyIndex;
|
||||
};
|
||||
|
||||
class MeshBuilder : public FRenderState
|
||||
{
|
||||
public:
|
||||
// Vertices
|
||||
std::pair<FFlatVertex*, unsigned int> AllocVertices(unsigned int count) override;
|
||||
|
||||
// Draw commands
|
||||
void Draw(int dt, int index, int count, bool apply = true) override;
|
||||
void DrawIndexed(int dt, int index, int count, bool apply = true) override { } // TBD: this is only used for the sector flat rendering.
|
||||
|
||||
// Immediate render state change commands. These only change infrequently and should not clutter the render state.
|
||||
void SetDepthFunc(int func) override;
|
||||
|
||||
// Commands not relevant for mesh building
|
||||
void Clear(int targets) override { }
|
||||
void ClearScreen() override { }
|
||||
void SetScissor(int x, int y, int w, int h) override { }
|
||||
void SetViewport(int x, int y, int w, int h) override { }
|
||||
void EnableMultisampling(bool on) override { }
|
||||
void EnableLineSmooth(bool on) override { }
|
||||
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 { }
|
||||
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 { }
|
||||
void SetCulling(int mode) override { }
|
||||
void EnableStencil(bool on) override { }
|
||||
void EnableDepthTest(bool on) override { }
|
||||
|
||||
std::unique_ptr<Mesh> Create();
|
||||
|
||||
private:
|
||||
void Apply();
|
||||
|
||||
TArray<MeshApplyState> mApplys;
|
||||
TArray<MeshDrawCommand> mDraws;
|
||||
TArray<FFlatVertex> mVertices;
|
||||
int mDepthFunc = 0;
|
||||
};
|
|
@ -118,6 +118,8 @@ struct FDepthBiasState
|
|||
}
|
||||
};
|
||||
|
||||
struct FFlatVertex;
|
||||
|
||||
enum EPassType
|
||||
{
|
||||
NORMAL_PASS,
|
||||
|
@ -731,6 +733,9 @@ public:
|
|||
|
||||
// API-dependent render interface
|
||||
|
||||
// Vertices
|
||||
virtual std::pair<FFlatVertex*, unsigned int> AllocVertices(unsigned int count);
|
||||
|
||||
// Draw commands
|
||||
virtual void ClearScreen() = 0;
|
||||
virtual void Draw(int dt, int index, int count, bool apply = true) = 0;
|
||||
|
|
Loading…
Reference in a new issue