Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
Mesh.h
Go to the documentation of this file.
1#pragma once
2
3#include <Common/primitive_type.h>
4#include <Common/assertion.h>
5#include <Utility/TSpan.h>
6
7#include <array>
8#include <memory>
9#include <vector>
10#include <cstddef>
11
12namespace ph::editor::ghi
13{
14
15class VertexStorage;
16class IndexStorage;
17
19{
20public:
21 inline constexpr static uint8 MAX_ATTRIBUTE_BINDINGS = 16;
22
23 struct AttributeBinding final
24 {
27 };
28
30 std::array<AttributeBinding, MAX_ATTRIBUTE_BINDINGS> attributeBindings;
31
33
37
38 bool isEmpty() const;
39};
40
41class Mesh
42{
43public:
44 Mesh(
45 const MeshVertexLayoutInfo& layout,
46 TSpanView<std::shared_ptr<VertexStorage>> vertexStorages);
47
48 Mesh(
49 const MeshVertexLayoutInfo& layout,
50 TSpanView<std::shared_ptr<VertexStorage>> vertexStorages,
51 const std::shared_ptr<IndexStorage>& indexStorage);
52
53 virtual ~Mesh();
54
55 virtual void bind() = 0;
56
57 const MeshVertexLayoutInfo& getLayout() const;
58
59 std::size_t numVertexStorages() const;
60 const VertexStorage& getVertexStorage(std::size_t storageIndex) const;
61 VertexStorage& getVertexStorage(std::size_t storageIndex);
62 std::shared_ptr<VertexStorage> getVertexStorageResource(std::size_t storageIndex) const;
63
64 bool hasIndexStorage() const;
65 const IndexStorage& getIndexStorage() const;
67 std::shared_ptr<IndexStorage> getIndexStorageResource() const;
68
69private:
70 MeshVertexLayoutInfo m_layout;
71 std::vector<std::shared_ptr<VertexStorage>> m_vertexStorages;
72 std::shared_ptr<IndexStorage> m_indexStorage;
73};
74
76{
77 return numAttributes == 0;
78}
79
81{
82 return m_layout;
83}
84
85inline std::size_t Mesh::numVertexStorages() const
86{
87 return m_vertexStorages.size();
88}
89
90inline const VertexStorage& Mesh::getVertexStorage(const std::size_t storageIndex) const
91{
92 PH_ASSERT_LT(storageIndex, m_vertexStorages.size());
93 PH_ASSERT(m_vertexStorages[storageIndex]);
94 return *m_vertexStorages[storageIndex].get();
95}
96
97inline VertexStorage& Mesh::getVertexStorage(const std::size_t storageIndex)
98{
99 PH_ASSERT_LT(storageIndex, m_vertexStorages.size());
100 PH_ASSERT(m_vertexStorages[storageIndex]);
101 return *m_vertexStorages[storageIndex];
102}
103
104inline bool Mesh::hasIndexStorage() const
105{
106 return m_indexStorage != nullptr;
107}
108
110{
111 PH_ASSERT(m_indexStorage);
112 return *m_indexStorage;
113}
114
116{
117 PH_ASSERT(m_indexStorage);
118 return *m_indexStorage;
119}
120
121}// end namespace ph::editor::ghi
Definition IndexStorage.h:11
Definition Mesh.h:42
std::shared_ptr< IndexStorage > getIndexStorageResource() const
Definition Mesh.cpp:38
virtual void bind()=0
const MeshVertexLayoutInfo & getLayout() const
Definition Mesh.h:80
const VertexStorage & getVertexStorage(std::size_t storageIndex) const
Definition Mesh.h:90
const IndexStorage & getIndexStorage() const
Definition Mesh.h:109
bool hasIndexStorage() const
Definition Mesh.h:104
std::size_t numVertexStorages() const
Definition Mesh.h:85
std::shared_ptr< VertexStorage > getVertexStorageResource(std::size_t storageIndex) const
Definition Mesh.cpp:31
Mesh(const MeshVertexLayoutInfo &layout, TSpanView< std::shared_ptr< VertexStorage > > vertexStorages)
Definition Mesh.cpp:11
static constexpr uint8 MAX_ATTRIBUTE_BINDINGS
Definition Mesh.h:21
bool isEmpty() const
Definition Mesh.h:75
std::array< AttributeBinding, MAX_ATTRIBUTE_BINDINGS > attributeBindings
Definition Mesh.h:30
MeshVertexLayoutInfo()
Empty layout.
Definition Mesh.cpp:6
uint8 numAttributes
Definition Mesh.h:32
Definition VertexStorage.h:13
Definition PlatformDisplay.h:13