Graphics/GraphicalMesh: Allow to update submeshes

This commit is contained in:
SirLynix
2022-06-16 18:19:48 +02:00
parent 2cc4944f58
commit 62ba4f172b
8 changed files with 73 additions and 25 deletions

View File

@@ -8,6 +8,7 @@
#define NAZARA_GRAPHICS_GRAPHICALMESH_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Utils/Signal.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Renderer/RenderBuffer.hpp>
#include <Nazara/Utility/Mesh.hpp>
@@ -19,32 +20,44 @@ namespace Nz
class NAZARA_GRAPHICS_API GraphicalMesh
{
public:
GraphicalMesh(const Mesh& mesh);
struct SubMesh;
GraphicalMesh() = default;
GraphicalMesh(const GraphicalMesh&) = delete;
GraphicalMesh(GraphicalMesh&&) noexcept = default;
~GraphicalMesh() = default;
inline std::size_t AddSubMesh(SubMesh subMesh);
inline void Clear();
inline const std::shared_ptr<RenderBuffer>& GetIndexBuffer(std::size_t subMesh) const;
inline std::size_t GetIndexCount(std::size_t subMesh) const;
inline UInt32 GetIndexCount(std::size_t subMesh) const;
inline IndexType GetIndexType(std::size_t subMesh) const;
inline const std::shared_ptr<RenderBuffer>& GetVertexBuffer(std::size_t subMesh) const;
inline const std::shared_ptr<const VertexDeclaration>& GetVertexDeclaration(std::size_t subMesh) const;
inline std::size_t GetSubMeshCount() const;
GraphicalMesh& operator=(const GraphicalMesh&) = delete;
GraphicalMesh& operator=(GraphicalMesh&&) noexcept = default;
inline void UpdateSubMeshIndexCount(std::size_t subMeshIndex, UInt32 indexCount);
private:
struct GraphicalSubMesh
GraphicalMesh& operator=(const GraphicalMesh&) = delete;
GraphicalMesh& operator=(GraphicalMesh&&) = delete;
struct SubMesh
{
std::shared_ptr<RenderBuffer> indexBuffer;
std::shared_ptr<RenderBuffer> vertexBuffer;
std::size_t indexCount;
std::shared_ptr<const VertexDeclaration> vertexDeclaration;
IndexType indexType;
UInt32 indexCount;
};
std::vector<GraphicalSubMesh> m_subMeshes;
static std::shared_ptr<GraphicalMesh> BuildFromMesh(const Mesh& mesh);
NazaraSignal(OnInvalidated, GraphicalMesh* /*gfxMesh*/);
private:
std::vector<SubMesh> m_subMeshes;
};
}

View File

@@ -8,13 +8,30 @@
namespace Nz
{
inline std::size_t GraphicalMesh::AddSubMesh(SubMesh subMesh)
{
std::size_t subMeshIndex = m_subMeshes.size();
m_subMeshes.emplace_back(std::move(subMesh));
OnInvalidated(this);
return subMeshIndex;
}
inline void GraphicalMesh::Clear()
{
m_subMeshes.clear();
OnInvalidated(this);
}
inline const std::shared_ptr<RenderBuffer>& GraphicalMesh::GetIndexBuffer(std::size_t subMesh) const
{
assert(subMesh < m_subMeshes.size());
return m_subMeshes[subMesh].indexBuffer;
}
inline std::size_t GraphicalMesh::GetIndexCount(std::size_t subMesh) const
inline UInt32 GraphicalMesh::GetIndexCount(std::size_t subMesh) const
{
assert(subMesh < m_subMeshes.size());
return m_subMeshes[subMesh].indexCount;
@@ -42,6 +59,14 @@ namespace Nz
{
return m_subMeshes.size();
}
inline void GraphicalMesh::UpdateSubMeshIndexCount(std::size_t subMeshIndex, UInt32 indexCount)
{
NazaraAssert(subMeshIndex < m_subMeshes.size(), "invalid submesh index");
m_subMeshes[subMeshIndex].indexCount = indexCount;
OnInvalidated(this);
}
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -9,6 +9,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/GraphicalMesh.hpp>
#include <Nazara/Graphics/InstancedRenderable.hpp>
#include <Nazara/Renderer/RenderPipeline.hpp>
#include <Nazara/Utility/Mesh.hpp>
@@ -17,7 +18,6 @@
namespace Nz
{
class GraphicalMesh;
class Material;
class NAZARA_GRAPHICS_API Model : public InstancedRenderable
@@ -50,6 +50,8 @@ namespace Nz
std::vector<RenderPipelineInfo::VertexBufferData> vertexBufferData;
};
NazaraSlot(GraphicalMesh, OnInvalidated, m_onInvalidated);
std::shared_ptr<GraphicalMesh> m_graphicalMesh;
std::vector<SubMeshData> m_submeshes;
Recti m_scissorBox;