diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7c43b850b..6d62f05ab 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1122,7 +1122,6 @@ set (PCH_SOURCES common/rendering/hwrenderer/data/hw_collision.cpp common/rendering/hwrenderer/data/hw_levelmesh.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 diff --git a/src/common/rendering/hwrenderer/data/hw_mesh.cpp b/src/common/rendering/hwrenderer/data/hw_mesh.cpp deleted file mode 100644 index b66793dcf..000000000 --- a/src/common/rendering/hwrenderer/data/hw_mesh.cpp +++ /dev/null @@ -1,111 +0,0 @@ - -#include "hw_mesh.h" -#include "v_video.h" -#include "cmdlib.h" - -#define USE_MESH_VERTEX_BUFFER - -void Mesh::Draw(FRenderState& renderstate) -{ -#ifdef USE_MESH_VERTEX_BUFFER - - if (!mVertexBuffer && mVertices.Size() != 0) - { - static const FVertexBufferAttribute format[] = - { - { 0, VATTR_VERTEX, VFmt_Float4, (int)myoffsetof(FFlatVertex, x) }, - { 0, VATTR_TEXCOORD, VFmt_Float2, (int)myoffsetof(FFlatVertex, u) }, - { 0, VATTR_LIGHTMAP, VFmt_Float2, (int)myoffsetof(FFlatVertex, lu) }, - }; - mVertexBuffer.reset(screen->CreateVertexBuffer(1, 3, sizeof(FFlatVertex), format)); - mVertexBuffer->SetData(mVertices.Size() * sizeof(FFlatVertex), mVertices.Data(), BufferUsageType::Static); - } - - if (mVertexBuffer) - renderstate.SetVertexBuffer(mVertexBuffer.get(), 0, 0); - -#else - - auto pair = renderstate.AllocVertices(mVertices.Size()); - memcpy(pair.first, mVertices.Data(), mVertices.Size() * sizeof(FFlatVertex)); - -#endif - - MeshApplyState origState; - origState.applyData.RenderStyle = renderstate.mRenderStyle; - origState.applyData.SpecialEffect = renderstate.mSpecialEffect; - origState.applyData.TextureEnabled = renderstate.mTextureEnabled; - origState.applyData.FogEnabled = renderstate.mFogEnabled; - origState.applyData.BrightmapEnabled = renderstate.mBrightmapEnabled; - origState.applyData.TextureClamp = renderstate.mTextureClamp; - origState.applyData.TextureMode = renderstate.mTextureMode; - origState.applyData.TextureModeFlags = renderstate.mTextureModeFlags; - origState.surfaceUniforms = renderstate.mSurfaceUniforms; - origState.material = renderstate.mMaterial; - origState.textureMatrix.loadIdentity(); - - int applyIndex = -1; - int depthFunc = -1; - for (const MeshDrawCommand& cmd : mDraws) - { - bool apply = applyIndex != cmd.ApplyIndex; - if (apply) - { - int newDepthFunc = mApplys[cmd.ApplyIndex].applyData.DepthFunc; - if (depthFunc != newDepthFunc) - { - depthFunc = newDepthFunc; - renderstate.SetDepthFunc(depthFunc); - } - - applyIndex = cmd.ApplyIndex; - Apply(renderstate, mApplys[cmd.ApplyIndex]); - } - -#ifdef USE_MESH_VERTEX_BUFFER - renderstate.Draw(cmd.DrawType, cmd.Start, cmd.Count, apply); -#else - renderstate.Draw(cmd.DrawType, pair.second + cmd.Start, cmd.Count, apply); -#endif - } - -#ifdef USE_MESH_VERTEX_BUFFER - if (mVertexBuffer) - renderstate.SetFlatVertexBuffer(); -#endif - - for (const MeshDrawCommand& cmd : mIndexedDraws) - { - bool apply = applyIndex != cmd.ApplyIndex; - if (apply) - { - int newDepthFunc = mApplys[cmd.ApplyIndex].applyData.DepthFunc; - if (depthFunc != newDepthFunc) - { - depthFunc = newDepthFunc; - renderstate.SetDepthFunc(depthFunc); - } - - applyIndex = cmd.ApplyIndex; - Apply(renderstate, mApplys[cmd.ApplyIndex]); - } - renderstate.DrawIndexed(cmd.DrawType, cmd.Start, cmd.Count, apply); - } - - Apply(renderstate, origState); -} - -void Mesh::Apply(FRenderState& renderstate, const MeshApplyState& state) -{ - renderstate.mRenderStyle = state.applyData.RenderStyle; - renderstate.mSpecialEffect = state.applyData.SpecialEffect; - renderstate.mTextureEnabled = state.applyData.TextureEnabled; - renderstate.mFogEnabled = state.applyData.FogEnabled; - renderstate.mBrightmapEnabled = state.applyData.BrightmapEnabled; - renderstate.mTextureClamp = state.applyData.TextureClamp; - renderstate.mTextureMode = state.applyData.TextureMode; - renderstate.mTextureModeFlags = state.applyData.TextureModeFlags; - renderstate.mSurfaceUniforms = state.surfaceUniforms; - renderstate.mMaterial = state.material; - renderstate.SetTextureMatrix(state.textureMatrix); -} diff --git a/src/common/rendering/hwrenderer/data/hw_mesh.h b/src/common/rendering/hwrenderer/data/hw_mesh.h deleted file mode 100644 index 3c6313574..000000000 --- a/src/common/rendering/hwrenderer/data/hw_mesh.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "hw_meshbuilder.h" - -class Mesh -{ -public: - void Draw(FRenderState& renderstate); - -private: - void Apply(FRenderState& renderstate, const MeshApplyState& apply); - - TArray mApplys; - TArray mDraws; - TArray mIndexedDraws; - TArray mVertices; - std::unique_ptr mVertexBuffer; - - friend class MeshBuilder; -}; diff --git a/src/common/rendering/hwrenderer/data/hw_meshbuilder.cpp b/src/common/rendering/hwrenderer/data/hw_meshbuilder.cpp index 9030656b6..d36f33c5f 100644 --- a/src/common/rendering/hwrenderer/data/hw_meshbuilder.cpp +++ b/src/common/rendering/hwrenderer/data/hw_meshbuilder.cpp @@ -1,6 +1,5 @@ #include "hw_meshbuilder.h" -#include "hw_mesh.h" #include "v_video.h" MeshBuilder::MeshBuilder() @@ -79,38 +78,6 @@ void MeshBuilder::Apply() mDrawLists = &mSortedLists[state]; } -std::unique_ptr MeshBuilder::Create() -{ - if (mSortedLists.empty()) - return {}; - - auto mesh = std::make_unique(); - - int applyIndex = 0; - for (auto& it : mSortedLists) - { - mesh->mApplys.Push(it.first); - for (MeshDrawCommand& command : it.second.mDraws) - { - command.ApplyIndex = applyIndex; - mesh->mDraws.Push(command); - } - for (MeshDrawCommand& command : it.second.mIndexedDraws) - { - command.ApplyIndex = applyIndex; - mesh->mIndexedDraws.Push(command); - } - applyIndex++; - } - - // To do: the various mesh layers have to share the vertex buffer since some vertex allocations happen at the Process stage - //mesh->mVertices = std::move(mVertices); - //mVertices.Clear(); - mesh->mVertices = mVertices; - - return mesh; -} - std::pair MeshBuilder::AllocVertices(unsigned int count) { unsigned int offset = mVertices.Reserve(count); diff --git a/src/common/rendering/hwrenderer/data/hw_meshbuilder.h b/src/common/rendering/hwrenderer/data/hw_meshbuilder.h index db32dfe06..eca48c522 100644 --- a/src/common/rendering/hwrenderer/data/hw_meshbuilder.h +++ b/src/common/rendering/hwrenderer/data/hw_meshbuilder.h @@ -105,8 +105,6 @@ class MeshBuilder : public FRenderState void EnableStencil(bool on) override { } void EnableDepthTest(bool on) override { } - std::unique_ptr Create(); - struct DrawLists { TArray mDraws;