BsVertexDataDesc.h 3.7 KB

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