You.i Engine
YiMesh.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_MESH_H_
3 #define _YI_MESH_H_
4 
6 #include "scenetree/YiAABB.h"
8 
9 #include <glm/mat4x4.hpp>
10 
11 #include <memory>
12 
33 class CYIMesh
34 {
35 public:
39  enum class GeometryPrimitive : uint8_t
40  {
41  Triangles,
43  Points
44  };
45 
51  enum class BufferOwnership : uint8_t
52  {
53  Owned,
54  Shared
55  };
56 
70  {
71  size_t bufferIndex;
72  uint32_t attribute;
73  uint32_t numElements;
74  uint32_t stride;
75  uint32_t byteOffset;
76  };
77 
79 
94  static const uint32_t YI_POSITION = 0;
95  static const uint32_t YI_TEXCOORD = 1;
96  static const uint32_t YI_NORMAL = 2;
97  static const uint32_t YI_COLOR = 3;
99 
100  CYIMesh();
101  virtual ~CYIMesh();
102 
117  void SetTransform(const glm::mat4 &transform);
118 
122  const glm::mat4 &GetTransform() const;
123 
130  size_t AddVertexBuffer(std::shared_ptr<CYIAssetBufferObjectData> pData, BufferOwnership ownership);
131 
136  void SetIndexBuffer(std::shared_ptr<CYIAssetBufferObjectData> pData, BufferOwnership ownership);
137 
142  void SetBindings(const std::vector<YI_ATTRIBUTE_BINDING> &bindings);
143 
148  void SetBindings(std::initializer_list<YI_ATTRIBUTE_BINDING> bindings);
149 
153  std::vector<CYIMesh::YI_ATTRIBUTE_BINDING> GetBindings() const;
154 
160  void SetAxisAlignedBoundingBox(const CYIAABB &aabb);
161 
165  const CYIAABB &GetAxisAlignedBoundingBox() const;
166 
170  const std::shared_ptr<CYIAssetBufferObjectData> &GetVertexBuffer(size_t bufferIndex) const;
171 
175  const std::shared_ptr<CYIAssetBufferObjectData> &GetIndexBuffer() const;
176 
180  void RemoveVertexBuffer(size_t bufferIndex);
181 
185  void RemoveIndexBuffer();
186 
190  const YI_ATTRIBUTE_BINDING &GetBinding(size_t bindingIndex) const;
191 
195  size_t GetNumVertexBuffers() const;
196 
200  size_t GetNumBindings() const;
201 
206  void SetPrimitive(GeometryPrimitive primitive);
207 
212 
216  size_t GetIndexCount() const;
217 
221  void SetIndexCount(size_t count);
222 
228  size_t GetStartOffset() const;
229 
237  void SetStartOffset(size_t startOffset);
238 
243  void SetDepthTesting(bool enabled);
244 
248  bool GetDepthTesting() const;
249 
253  bool IsLoaded() const;
254 
255 protected:
257  {
258  VertexBuffer(std::shared_ptr<CYIAssetBufferObjectData> data, BufferOwnership ownership);
259 
260  std::shared_ptr<CYIAssetBufferObjectData> data;
262  };
263 
265  std::shared_ptr<CYIAssetBufferObjectData> m_IBO;
267  glm::mat4 m_transform;
269  size_t m_indexCount;
274  mutable bool m_isLoaded;
275 };
276 
279 #endif // _YI_MESH_H_
size_t GetNumVertexBuffers() const
size_t AddVertexBuffer(std::shared_ptr< CYIAssetBufferObjectData > pData, BufferOwnership ownership)
A std::vector wrapper that makes use of pre-allocated memory for storing up to StackCapacity items...
Definition: YiSmallVector.h:32
size_t m_indexCount
Definition: YiMesh.h:269
uint32_t byteOffset
Definition: YiMesh.h:75
Class representing an instance of geometry information.
Definition: YiMesh.h:33
size_t GetStartOffset() const
static const uint32_t YI_COLOR
Definition: YiMesh.h:97
glm::mat4 m_transform
Definition: YiMesh.h:267
std::vector< CYIMesh::YI_ATTRIBUTE_BINDING > GetBindings() const
static const uint32_t YI_NORMAL
Definition: YiMesh.h:96
GeometryPrimitive GetPrimitive() const
uint32_t numElements
Definition: YiMesh.h:73
const glm::mat4 & GetTransform() const
Definition: YiMesh.h:256
bool IsLoaded() const
BufferOwnership ownership
Definition: YiMesh.h:261
void SetStartOffset(size_t startOffset)
BufferOwnership m_IBOOwnership
Definition: YiMesh.h:273
bool GetDepthTesting() const
void SetPrimitive(GeometryPrimitive primitive)
void SetTransform(const glm::mat4 &transform)
size_t bufferIndex
Definition: YiMesh.h:71
CYISmallVector< VertexBuffer, 1 > m_VBOs
Definition: YiMesh.h:264
bool m_isLoaded
Definition: YiMesh.h:274
std::shared_ptr< CYIAssetBufferObjectData > m_IBO
Definition: YiMesh.h:265
BufferOwnership
Definition: YiMesh.h:51
uint32_t stride
Definition: YiMesh.h:74
size_t GetIndexCount() const
void SetIndexCount(size_t count)
bool m_hasDepth
Definition: YiMesh.h:271
virtual ~CYIMesh()
const std::shared_ptr< CYIAssetBufferObjectData > & GetIndexBuffer() const
void SetBindings(const std::vector< YI_ATTRIBUTE_BINDING > &bindings)
This class represents an Axis-Aligned Bounding Box.
Definition: YiAABB.h:24
size_t GetNumBindings() const
void SetIndexBuffer(std::shared_ptr< CYIAssetBufferObjectData > pData, BufferOwnership ownership)
void RemoveIndexBuffer()
static const uint32_t YI_TEXCOORD
Definition: YiMesh.h:95
void RemoveVertexBuffer(size_t bufferIndex)
const YI_ATTRIBUTE_BINDING & GetBinding(size_t bindingIndex) const
void SetAxisAlignedBoundingBox(const CYIAABB &aabb)
size_t m_startOffset
Definition: YiMesh.h:270
uint32_t attribute
Definition: YiMesh.h:72
Definition: YiMesh.h:69
static const uint32_t YI_POSITION
Definition: YiMesh.h:94
void SetDepthTesting(bool enabled)
const CYIAABB & GetAxisAlignedBoundingBox() const
GeometryPrimitive
Definition: YiMesh.h:39
const std::shared_ptr< CYIAssetBufferObjectData > & GetVertexBuffer(size_t bufferIndex) const
CYISmallVector< YI_ATTRIBUTE_BINDING, 2 > m_Attributes
Definition: YiMesh.h:266
CYIAABB m_AABB
Definition: YiMesh.h:268
GeometryPrimitive m_primitive
Definition: YiMesh.h:272
std::shared_ptr< CYIAssetBufferObjectData > data
Definition: YiMesh.h:260