BsRenderableHandler.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "BsIReflectable.h"
  4. #include "BsRenderableProxy.h"
  5. #include "BsAABox.h"
  6. #include "BsGpuParam.h"
  7. namespace BansheeEngine
  8. {
  9. /**
  10. * @brief Renderable represents any visible object in the scene. It has a mesh,
  11. * bounds and a set of materials. Renderer will render any Renderable objects
  12. * visible by the camera.
  13. */
  14. class BS_EXPORT RenderableHandler : public IReflectable
  15. {
  16. struct MeshData
  17. {
  18. MeshData() {}
  19. MeshData(const HMesh& mesh);
  20. HMesh mesh;
  21. mutable bool isLoaded;
  22. };
  23. struct MaterialData
  24. {
  25. MaterialData() {}
  26. MaterialData(const HMaterial& material);
  27. HMaterial material;
  28. mutable bool isLoaded;
  29. };
  30. public:
  31. RenderableHandler();
  32. /**
  33. * @brief Sets the mesh to render. All sub-meshes of the mesh will be rendered,
  34. * and you may set individual materials for each sub-mesh.
  35. */
  36. void setMesh(HMesh mesh);
  37. /**
  38. * @brief Sets a material that will be used for rendering a sub-mesh with
  39. * the specified index. If a sub-mesh doesn't have a specific material set
  40. * then the primary material will be used.
  41. */
  42. void setMaterial(UINT32 idx, HMaterial material);
  43. /**
  44. * @brief Sets the primary material to use for rendering. Any sub-mesh that
  45. * doesn't have an explicit material set will use this material.
  46. *
  47. * @note This is equivalent to calling setMaterial(0, material).
  48. */
  49. void setMaterial(HMaterial material);
  50. /**
  51. * @brief Sets the layer bitfield. Renderable layer must match camera layer
  52. * in order for the camera to render the component.
  53. */
  54. void setLayer(UINT64 layer);
  55. /**
  56. * @brief Gets the layer bitfield. Renderable layer must match camera layer
  57. * in order for the camera to render the component.
  58. */
  59. UINT64 getLayer() const { return mLayer; }
  60. /**
  61. * @brief Returns the mesh used for rendering.
  62. */
  63. HMesh getMesh() const { return mMeshData.mesh; }
  64. /**
  65. * @brief Returns the material used for rendering a sub-mesh with
  66. * the specified index.
  67. */
  68. HMaterial getMaterial(UINT32 idx) const;
  69. /************************************************************************/
  70. /* CORE PROXY */
  71. /************************************************************************/
  72. /**
  73. * @brief Checks is the core dirty flag set. This is used by external systems
  74. * to know when internal data has changed and core thread potentially needs to be notified.
  75. */
  76. bool _isCoreDirty() const;
  77. /**
  78. * @brief Marks the core dirty flag as clean.
  79. */
  80. void _markCoreClean();
  81. /**
  82. * @brief Marks the core data as dirty.
  83. */
  84. void _markCoreDirty() const { mCoreDirtyFlags = 0xFFFFFFFF; }
  85. /**
  86. * @brief Creates a new core proxy from the currently set Renderable data. Core proxies ensure
  87. * that the core thread has all the necessary Renderable data, while avoiding the need
  88. * to manage Renderable itself on the core thread.
  89. *
  90. * @note You generally need to update the core thread with a new proxy whenever core
  91. * dirty flag is set.
  92. */
  93. RenderableProxyPtr _createProxy(const Matrix4& worldTransform) const;
  94. /**
  95. * @brief Returns the currently active proxy object, if any.
  96. */
  97. RenderableProxyPtr _getActiveProxy() const { return mActiveProxy; }
  98. /**
  99. * @brief Changes the currently active proxy object.
  100. */
  101. void _setActiveProxy(const RenderableProxyPtr& proxy) { mActiveProxy = proxy; }
  102. private:
  103. /**
  104. * @brief Checks if any resources were loaded since last time. Marks the core data as dirty
  105. * if they have (does nothing if all resources are already loaded).
  106. */
  107. void updateResourceLoadStates() const;
  108. private:
  109. MeshData mMeshData;
  110. Vector<MaterialData> mMaterialData;
  111. UINT64 mLayer;
  112. Vector<AABox> mWorldBounds;
  113. RenderableProxyPtr mActiveProxy;
  114. mutable UINT32 mCoreDirtyFlags;
  115. /************************************************************************/
  116. /* RTTI */
  117. /************************************************************************/
  118. public:
  119. friend class RenderableHandlerRTTI;
  120. static RTTITypeBase* getRTTIStatic();
  121. virtual RTTITypeBase* getRTTI() const;
  122. };
  123. }