BsVertexDataDesc.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "RenderAPI/BsVertexDeclaration.h"
  6. namespace bs
  7. {
  8. /** @addtogroup Resources
  9. * @{
  10. */
  11. /**
  12. * Contains information about layout of vertices in a buffer. This is very similar to VertexDeclaration but unlike
  13. * VertexDeclaration it has no render API object to back it up and is very lightweight.
  14. */
  15. class BS_CORE_EXPORT VertexDataDesc : public IReflectable
  16. {
  17. public:
  18. VertexDataDesc() {}
  19. /**
  20. * Informs the internal buffer that it needs to make room for the specified vertex element. If a vertex with same
  21. * stream and semantics already exists it will just be updated.
  22. *
  23. * @param[in] type Type of the vertex element. Determines size.
  24. * @param[in] semantic Semantic that allows the engine to connect the data to a shader input slot.
  25. * @param[in] semanticIdx (optional) If there are multiple semantics with the same name, use different
  26. * index to differentiate between them.
  27. * @param[in] streamIdx (optional) Zero-based index of the stream. Each stream will internally be
  28. * represented as a single vertex buffer.
  29. * @param[in] instanceStepRate Determines at what rate does vertex element data advance. Zero means each vertex
  30. * will advance the data pointer and receive new data (standard behaviour). Values
  31. * larger than one are relevant for instanced rendering and determine how often do
  32. * instances advance the vertex element (for example a value of 1 means each
  33. * instance will retrieve a new value for this vertex element, a value of 2 means
  34. * each second instance will, etc.).
  35. */
  36. void addVertElem(VertexElementType type, VertexElementSemantic semantic, UINT32 semanticIdx = 0,
  37. UINT32 streamIdx = 0, UINT32 instanceStepRate = 0);
  38. /** Query if we have vertex data for the specified semantic. */
  39. bool hasElement(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
  40. /** Returns the size in bytes of the vertex element with the specified semantic. */
  41. UINT32 getElementSize(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
  42. /** Returns offset of the vertex from start of the stream in bytes. */
  43. UINT32 getElementOffsetFromStream(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
  44. /** Gets vertex stride in bytes (offset from one vertex to another) in the specified stream. */
  45. UINT32 getVertexStride(UINT32 streamIdx) const;
  46. /** Gets vertex stride in bytes (offset from one vertex to another) in all the streams. */
  47. UINT32 getVertexStride() const;
  48. /** Gets offset in bytes from the start of the internal buffer to the start of the specified stream. */
  49. UINT32 getStreamOffset(UINT32 streamIdx) const;
  50. /** Returns the number of vertex elements. */
  51. UINT32 getNumElements() const { return (UINT32)mVertexElements.size(); }
  52. /** Returns the vertex element at the specified index. */
  53. const VertexElement& getElement(UINT32 idx) const { return mVertexElements[idx]; }
  54. /** Returns the vertex element with the specified semantic. */
  55. const VertexElement* getElement(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
  56. /** Creates a list of vertex elements from internal data. */
  57. List<VertexElement> createElements() const;
  58. /** Creates a new empty vertex data descriptor. */
  59. static SPtr<VertexDataDesc> create();
  60. private:
  61. friend class Mesh;
  62. friend class ct::Mesh;
  63. friend class MeshHeap;
  64. friend class ct::MeshHeap;
  65. /** Returns the largest stream index of all the stored vertex elements. */
  66. UINT32 getMaxStreamIdx() const;
  67. /** Checks if any of the vertex elements use the specified stream index. */
  68. bool hasStream(UINT32 streamIdx) const;
  69. /** Removes a vertex element of the specified type and semantics if it exists. */
  70. void clearIfItExists(VertexElementType type, VertexElementSemantic semantic, UINT32 semanticIdx, UINT32 streamIdx);
  71. private:
  72. Vector<VertexElement> mVertexElements;
  73. /************************************************************************/
  74. /* SERIALIZATION */
  75. /************************************************************************/
  76. public:
  77. friend class VertexDataDescRTTI;
  78. static RTTITypeBase* getRTTIStatic();
  79. virtual RTTITypeBase* getRTTI() const override;
  80. };
  81. /** @} */
  82. }