Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TIndexedPolygonBuffer.ipp
Go to the documentation of this file.
2
3namespace ph
4{
5
6template<std::size_t N>
8 : m_vertexBuffer()
9 , m_indexBuffer()
10{}
11
12template<std::size_t N>
13inline std::array<math::Vector3R, N> TIndexedPolygonBuffer<N>::getPositions(const std::size_t faceIndex) const
14{
15 return getFaceAttribute(EVertexAttribute::Position_0, faceIndex);
16}
17
18template<std::size_t N>
19inline std::array<math::Vector3R, N> TIndexedPolygonBuffer<N>::getTexCoords(const std::size_t faceIndex) const
20{
21 return getFaceAttribute(EVertexAttribute::TexCoord_0, faceIndex);
22}
23
24template<std::size_t N>
25inline std::array<math::Vector3R, N> TIndexedPolygonBuffer<N>::getNormals(const std::size_t faceIndex) const
26{
27 return getFaceAttribute(EVertexAttribute::Normal_0, faceIndex);
28}
29
30template<std::size_t N>
31inline std::array<math::Vector3R, N> TIndexedPolygonBuffer<N>::getFaceAttribute(
32 const EVertexAttribute attribute,
33 const std::size_t faceIndex) const
34{
35 PH_ASSERT_LT(faceIndex, numFaces());
36
37 // Fetch attributes from the buffer.
38 // (loop should be optimized by the compiler)
39 std::array<math::Vector3R, N> result;
40 for(std::size_t i = 0; i < N; ++i)
41 {
42 result[i] = m_vertexBuffer.getAttribute(attribute, m_indexBuffer.getUInt(N * faceIndex + i));
43 }
44 return result;
45}
46
47template<std::size_t N>
48inline std::size_t TIndexedPolygonBuffer<N>::numFaces() const
49{
50 PH_ASSERT_EQ(m_indexBuffer.numUInts() % N, 0);
51 return m_indexBuffer.numUInts() / N;
52}
53
54template<std::size_t N>
56{
57 return hasFaceAttribute(EVertexAttribute::TexCoord_0);
58}
59
60template<std::size_t N>
62{
63 return hasFaceAttribute(EVertexAttribute::Normal_0);
64}
65
66template<std::size_t N>
68{
69 return m_vertexBuffer.hasAttribute(attribute);
70}
71
72template<std::size_t N>
73inline std::size_t TIndexedPolygonBuffer<N>::memoryUsage() const
74{
75 return sizeof(*this) + m_vertexBuffer.memoryUsage() + m_indexBuffer.memoryUsage();
76}
77
78template<std::size_t N>
80{
81 if(numFaces() == 0)
82 {
83 return 0.0f;
84 }
85
86 const auto numTotalBytes = static_cast<double>(memoryUsage());
87 const auto numPolygons = static_cast<double>(numFaces());
88 return static_cast<float>(numTotalBytes / numPolygons);
89}
90
91template<std::size_t N>
93{
94 return m_vertexBuffer;
95}
96
97template<std::size_t N>
99{
100 return m_vertexBuffer;
101}
102
103template<std::size_t N>
105{
106 return m_indexBuffer;
107}
108
109template<std::size_t N>
111{
112 return m_indexBuffer;
113}
114
115template<std::size_t N>
117{
118 return N;
119}
120
121template<std::size_t N>
123{
124 return numPolygonVertices() == 3;
125}
126
127}// end namespace ph
A general unsigned integer buffer for integers with any number of bits.
Definition IndexedUIntBuffer.h:27
A general vertex buffer for storing various indexed attributes.
Definition IndexedVertexBuffer.h:49
std::array< math::Vector3R, N > getTexCoords(std::size_t faceIndex) const
Definition TIndexedPolygonBuffer.ipp:19
IndexedUIntBuffer & getIndexBuffer()
Definition TIndexedPolygonBuffer.ipp:104
IndexedVertexBuffer & getVertexBuffer()
Definition TIndexedPolygonBuffer.ipp:92
std::array< math::Vector3R, N > getPositions(std::size_t faceIndex) const
Definition TIndexedPolygonBuffer.ipp:13
bool hasTexCoord() const
Definition TIndexedPolygonBuffer.ipp:55
std::size_t memoryUsage() const
Definition TIndexedPolygonBuffer.ipp:73
TIndexedPolygonBuffer()
Definition TIndexedPolygonBuffer.ipp:7
bool hasNormal() const
Definition TIndexedPolygonBuffer.ipp:61
std::array< math::Vector3R, N > getFaceAttribute(EVertexAttribute attribute, std::size_t faceIndex) const
Definition TIndexedPolygonBuffer.ipp:31
float averagePerPolygonMemoryUsage() const
Definition TIndexedPolygonBuffer.ipp:79
std::size_t numFaces() const
Definition TIndexedPolygonBuffer.ipp:48
static constexpr std::size_t numPolygonVertices()
Definition TIndexedPolygonBuffer.ipp:116
static constexpr bool isTriangular()
Definition TIndexedPolygonBuffer.ipp:122
bool hasFaceAttribute(EVertexAttribute attribute) const
Definition TIndexedPolygonBuffer.ipp:67
std::array< math::Vector3R, N > getNormals(std::size_t faceIndex) const
Definition TIndexedPolygonBuffer.ipp:25
The root for all renderer implementations.
Definition EEngineProject.h:6
EVertexAttribute
Definition IndexedVertexBuffer.h:21