BsVertexDataDesc.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 "BsVertexDeclaration.h"
  6. namespace BansheeEngine
  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 index to
  26. * differentiate between them.
  27. * @param[in] streamIdx (optional) Zero-based index of the stream. Each stream will internally be represented
  28. * as a single vertex buffer.
  29. */
  30. void addVertElem(VertexElementType type, VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0);
  31. /** Query if we have vertex data for the specified semantic. */
  32. bool hasElement(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
  33. /** Returns the size in bytes of the vertex element with the specified semantic. */
  34. UINT32 getElementSize(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
  35. /** Returns offset of the vertex from start of the stream in bytes. */
  36. UINT32 getElementOffsetFromStream(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
  37. /** Gets vertex stride in bytes (offset from one vertex to another) in the specified stream. */
  38. UINT32 getVertexStride(UINT32 streamIdx) const;
  39. /** Gets vertex stride in bytes (offset from one vertex to another) in all the streams. */
  40. UINT32 getVertexStride() const;
  41. /** Gets offset in bytes from the start of the internal buffer to the start of the specified stream. */
  42. UINT32 getStreamOffset(UINT32 streamIdx) const;
  43. /** Returns the number of vertex elements. */
  44. UINT32 getNumElements() const { return (UINT32)mVertexElements.size(); }
  45. /** Returns the vertex element at the specified index. */
  46. const VertexElement& getElement(UINT32 idx) const { return mVertexElements[idx]; }
  47. /** Creates a list of vertex elements from internal data. */
  48. List<VertexElement> createElements() const;
  49. /** Creates a new empty vertex data descriptor. */
  50. static VertexDataDescPtr create();
  51. private:
  52. friend class Mesh;
  53. friend class MeshCore;
  54. friend class MeshHeap;
  55. friend class MeshHeapCore;
  56. /** Returns the largest stream index of all the stored vertex elements. */
  57. UINT32 getMaxStreamIdx() const;
  58. /** Checks if any of the vertex elements use the specified stream index. */
  59. bool hasStream(UINT32 streamIdx) const;
  60. /** Removes a vertex element of the specified type and semantics if it exists. */
  61. void clearIfItExists(VertexElementType type, VertexElementSemantic semantic, UINT32 semanticIdx, UINT32 streamIdx);
  62. private:
  63. Vector<VertexElement> mVertexElements;
  64. /************************************************************************/
  65. /* SERIALIZATION */
  66. /************************************************************************/
  67. public:
  68. friend class VertexDataDescRTTI;
  69. static RTTITypeBase* getRTTIStatic();
  70. virtual RTTITypeBase* getRTTI() const override;
  71. };
  72. /** @} */
  73. }