BsMeshRenderData.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsRenderableProxy.h"
  4. #include "BsBounds.h"
  5. #include "BsSubMesh.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * Mesh render data provides a link between a Mesh and a Renderer. It may be modified
  10. * by both as changes occur and as the mesh is used in the renderer. Essentially it allows
  11. * the two to communicate without knowing about each other.
  12. */
  13. class BS_CORE_EXPORT MeshRenderData
  14. {
  15. public:
  16. /**
  17. * Creates a new empty render data.
  18. */
  19. MeshRenderData() {}
  20. /**
  21. * Creates render render data pointing to the specified vertex and index buffer, referencing
  22. * the provided sub-mesh index range.
  23. */
  24. MeshRenderData(const std::shared_ptr<VertexData>& vertexData, const IndexBufferPtr& indexBuffer,
  25. const SubMesh& subMesh, UINT32 vertexOffset, std::function<void()> usedOnGPUcallback);
  26. /**
  27. * Registers a new renderable proxy that references this mesh.
  28. */
  29. void addRenderableProxy(RenderableElement* proxy);
  30. /**
  31. * Unregisters a renderable proxy that references this mesh.
  32. */
  33. void removeRenderableProxy(RenderableElement* proxy);
  34. /**
  35. * Update mesh local bounds with the new provided bounds.
  36. */
  37. void updateBounds(const Bounds& bounds);
  38. /**
  39. * Get mesh local bounds.
  40. */
  41. Bounds getBounds() const { return mBounds; }
  42. /**
  43. * Set new internal buffers and a sub-mesh range.
  44. */
  45. void updateData(const std::shared_ptr<VertexData>& vertexData, const IndexBufferPtr& indexBuffer,
  46. const SubMesh& subMesh, UINT32 vertexOffset);
  47. /**
  48. * Get vertex buffers.
  49. */
  50. std::shared_ptr<VertexData> getVertexData() const { return mVertexData; }
  51. /**
  52. * Get index buffer.
  53. */
  54. IndexBufferPtr getIndexBuffer() const { return mIndexBuffer; }
  55. /**
  56. * Get sub-mesh range to render.
  57. */
  58. SubMesh getSubMesh() const { return mSubMesh; }
  59. /**
  60. * Get vertex offset;
  61. */
  62. UINT32 getVertexOffset() const { return mVertexOffset; }
  63. /**
  64. * Should be called by the renderer whenever the buffers get queued for use on the GPU.
  65. */
  66. void notifyUsedOnGPU() const;
  67. /**
  68. * Marks the render data as invalid, usually when the parent mesh was destroyed.
  69. */
  70. void _markAsInvalid();
  71. private:
  72. friend class Mesh;
  73. std::shared_ptr<VertexData> mVertexData;
  74. IndexBufferPtr mIndexBuffer;
  75. SubMesh mSubMesh;
  76. UINT32 mVertexOffset;
  77. Vector<RenderableElement*> mRenderableProxies;
  78. Bounds mBounds;
  79. std::function<void()> mUsedOnGPUCallback;
  80. bool mIsMeshValid;
  81. };
  82. }