2
0

BsMeshRenderData.h 2.3 KB

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