BsVertexDataDesc.h 3.9 KB

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