BsVertexDataDesc.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsVertexDeclaration.h"
  4. namespace BansheeEngine
  5. {
  6. /** @addtogroup Resources
  7. * @{
  8. */
  9. /**
  10. * Contains information about layout of vertices in a buffer. This is very similar to VertexDeclaration but unlike
  11. * VertexDeclaration it has no render API object to back it up and is very lightweight.
  12. */
  13. class BS_CORE_EXPORT VertexDataDesc : public IReflectable
  14. {
  15. public:
  16. VertexDataDesc() {}
  17. /**
  18. * Informs the internal buffer that it needs to make room for the specified vertex element. If a vertex with same
  19. * stream and semantics already exists it will just be updated.
  20. *
  21. * @param[in] type Type of the vertex element. Determines size.
  22. * @param[in] semantic Semantic that allows the engine to connect the data to a shader input slot.
  23. * @param[in] semanticIdx (optional) If there are multiple semantics with the same name, use different index to
  24. * differentiate between them.
  25. * @param[in] streamIdx (optional) Zero-based index of the stream. Each stream will internally be represented
  26. * as a single vertex buffer.
  27. */
  28. void addVertElem(VertexElementType type, VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0);
  29. /** Query if we have vertex data for the specified semantic. */
  30. bool hasElement(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
  31. /** Returns the size in bytes of the vertex element with the specified semantic. */
  32. UINT32 getElementSize(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
  33. /** Returns offset of the vertex from start of the stream in bytes. */
  34. UINT32 getElementOffsetFromStream(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
  35. /** Gets vertex stride in bytes (offset from one vertex to another) in the specified stream. */
  36. UINT32 getVertexStride(UINT32 streamIdx) const;
  37. /** Gets vertex stride in bytes (offset from one vertex to another) in all the streams. */
  38. UINT32 getVertexStride() const;
  39. /** Gets offset in bytes from the start of the internal buffer to the start of the specified stream. */
  40. UINT32 getStreamOffset(UINT32 streamIdx) const;
  41. /** Returns the number of vertex elements. */
  42. UINT32 getNumElements() const { return (UINT32)mVertexElements.size(); }
  43. /** Returns the vertex element at the specified index. */
  44. const VertexElement& getElement(UINT32 idx) const { return mVertexElements[idx]; }
  45. /** Creates a list of vertex elements from internal data. */
  46. List<VertexElement> createElements() const;
  47. /** Creates a new empty vertex data descriptor. */
  48. static VertexDataDescPtr create();
  49. private:
  50. friend class Mesh;
  51. friend class MeshCore;
  52. friend class MeshHeap;
  53. friend class MeshHeapCore;
  54. /** Returns the largest stream index of all the stored vertex elements. */
  55. UINT32 getMaxStreamIdx() const;
  56. /** Checks if any of the vertex elements use the specified stream index. */
  57. bool hasStream(UINT32 streamIdx) const;
  58. /** Removes a vertex element of the specified type and semantics if it exists. */
  59. void clearIfItExists(VertexElementType type, VertexElementSemantic semantic, UINT32 semanticIdx, UINT32 streamIdx);
  60. private:
  61. Vector<VertexElement> mVertexElements;
  62. /************************************************************************/
  63. /* SERIALIZATION */
  64. /************************************************************************/
  65. public:
  66. friend class VertexDataDescRTTI;
  67. static RTTITypeBase* getRTTIStatic();
  68. virtual RTTITypeBase* getRTTI() const override;
  69. };
  70. /** @} */
  71. }