Graphics: Add GraphicalMesh and Model classes

This commit is contained in:
Jérôme Leclercq
2021-01-27 16:45:00 +01:00
parent a1e0ae3f38
commit a9e9ef2524
7 changed files with 300 additions and 66 deletions

View File

@@ -0,0 +1,50 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_GRAPHICALMESH_HPP
#define NAZARA_GRAPHICALMESH_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Utility/Mesh.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
#include <memory>
namespace Nz
{
class NAZARA_GRAPHICS_API GraphicalMesh
{
public:
GraphicalMesh(const Mesh* mesh);
GraphicalMesh(const GraphicalMesh&) = delete;
GraphicalMesh(GraphicalMesh&&) noexcept = default;
~GraphicalMesh() = default;
inline const std::shared_ptr<AbstractBuffer>& GetIndexBuffer(std::size_t subMesh) const;
inline std::size_t GetIndexCount(std::size_t subMesh) const;
inline const std::shared_ptr<AbstractBuffer>& GetVertexBuffer(std::size_t subMesh) const;
inline const VertexDeclarationConstRef& GetVertexDeclaration(std::size_t subMesh) const;
inline std::size_t GetSubMeshCount() const;
GraphicalMesh& operator=(const GraphicalMesh&) = delete;
GraphicalMesh& operator=(GraphicalMesh&&) noexcept = default;
private:
struct GraphicalSubMesh
{
std::shared_ptr<AbstractBuffer> indexBuffer;
std::shared_ptr<AbstractBuffer> vertexBuffer;
std::size_t indexCount;
VertexDeclarationConstRef vertexDeclaration;
};
std::vector<GraphicalSubMesh> m_subMeshes;
};
}
#include <Nazara/Graphics/GraphicalMesh.inl>
#endif // NAZARA_GRAPHICALMESH_HPP

View File

@@ -0,0 +1,41 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/GraphicalMesh.hpp>
#include <cassert>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
inline const std::shared_ptr<AbstractBuffer>& 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
{
assert(subMesh < m_subMeshes.size());
return m_subMeshes[subMesh].indexCount;
}
inline const std::shared_ptr<AbstractBuffer>& GraphicalMesh::GetVertexBuffer(std::size_t subMesh) const
{
assert(subMesh < m_subMeshes.size());
return m_subMeshes[subMesh].vertexBuffer;
}
inline const VertexDeclarationConstRef& GraphicalMesh::GetVertexDeclaration(std::size_t subMesh) const
{
assert(subMesh < m_subMeshes.size());
return m_subMeshes[subMesh].vertexDeclaration;
}
inline std::size_t GraphicalMesh::GetSubMeshCount() const
{
return m_subMeshes.size();
}
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -0,0 +1,55 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_MODEL_HPP
#define NAZARA_MODEL_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Renderer/RenderPipeline.hpp>
#include <Nazara/Utility/Mesh.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
#include <memory>
namespace Nz
{
class GraphicalMesh;
class Material;
class NAZARA_GRAPHICS_API Model
{
public:
Model(std::shared_ptr<GraphicalMesh> graphicalMesh);
Model(const Model&) = delete;
Model(Model&&) noexcept = default;
~Model() = default;
const std::shared_ptr<AbstractBuffer>& GetIndexBuffer(std::size_t subMeshIndex) const;
std::size_t GetIndexCount(std::size_t subMeshIndex) const;
const std::shared_ptr<RenderPipeline>& GetRenderPipeline(std::size_t subMeshIndex) const;
const std::shared_ptr<AbstractBuffer>& GetVertexBuffer(std::size_t subMeshIndex) const;
inline std::size_t GetSubMeshCount() const;
inline void SetMaterial(std::size_t subMeshIndex, std::shared_ptr<Material> material);
Model& operator=(const Model&) = delete;
Model& operator=(Model&&) noexcept = default;
private:
struct SubMeshData
{
std::shared_ptr<Material> material;
std::vector<RenderPipelineInfo::VertexBufferData> vertexBufferData;
};
std::shared_ptr<GraphicalMesh> m_graphicalMesh;
std::vector<SubMeshData> m_subMeshes;
};
}
#include <Nazara/Graphics/Model.inl>
#endif

View File

@@ -0,0 +1,23 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/Model.hpp>
#include <cassert>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
inline std::size_t Model::GetSubMeshCount() const
{
return m_subMeshes.size();
}
inline void Model::SetMaterial(std::size_t subMeshIndex, std::shared_ptr<Material> material)
{
assert(subMeshIndex < m_subMeshes.size());
m_subMeshes[subMeshIndex].material = std::move(material);
}
}
#include <Nazara/Graphics/DebugOff.hpp>