CmVertexDataDesc.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmVertexDeclaration.h"
  4. namespace CamelotFramework
  5. {
  6. class CM_EXPORT VertexDataDesc : public IReflectable
  7. {
  8. public:
  9. VertexDataDesc() {}
  10. /**
  11. * @brief Informs the internal buffer that it needs to make room for the specified vertex element. If a vertex
  12. * with same stream and semantics already exists it will just be updated.
  13. *
  14. * @param type Type of the vertex element. Determines size.
  15. * @param semantic Semantic that allows the engine to connect the data to a shader input slot.
  16. * @param semanticIdx (optional) If there are multiple semantics with the same name, use different index to differentiate between them.
  17. * @param streamIdx (optional) Zero-based index of the stream. Each stream will internally be represented as a single vertex buffer.
  18. */
  19. void addVertElem(VertexElementType type, VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0);
  20. /**
  21. * @brief Query if we have vertex data for the specified semantic.
  22. */
  23. bool hasElement(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
  24. /**
  25. * @brief Creates a new vertex declaration based on set vertex elements.
  26. */
  27. VertexDeclarationPtr createDeclaration() const;
  28. UINT32 getElementSize(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
  29. UINT32 getElementOffsetFromStream(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
  30. UINT32 getVertexStride(UINT32 streamIdx) const;
  31. UINT32 getVertexStride() const;
  32. UINT32 getStreamOffset(UINT32 streamIdx) const;
  33. UINT32 getNumElements() const { return (UINT32)mVertexElements.size(); }
  34. const VertexElement& getElement(UINT32 idx) const { return mVertexElements[idx]; }
  35. private:
  36. friend class Mesh; // To avoid polluting the public interface with a bunch of nearly useless methods for outside world
  37. friend class MeshHeap;
  38. Vector<VertexElement>::type mVertexElements;
  39. UINT32 getMaxStreamIdx() const;
  40. bool hasStream(UINT32 streamIdx) const;
  41. void clearIfItExists(VertexElementType type, VertexElementSemantic semantic, UINT32 semanticIdx, UINT32 streamIdx);
  42. /************************************************************************/
  43. /* SERIALIZATION */
  44. /************************************************************************/
  45. public:
  46. friend class VertexDataDescRTTI;
  47. static RTTITypeBase* getRTTIStatic();
  48. virtual RTTITypeBase* getRTTI() const;
  49. };
  50. }