BsSkybox.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsIReflectable.h"
  6. #include "BsCoreObject.h"
  7. namespace bs
  8. {
  9. /** @addtogroup Implementation
  10. * @{
  11. */
  12. /** Signals which portion of a skybox is dirty. */
  13. enum class SkyboxDirtyFlag
  14. {
  15. Texture = 0x01,
  16. Everything = 0x02
  17. };
  18. /** Base class for both core and sim thread implementations of a skybox. */
  19. class BS_CORE_EXPORT SkyboxBase
  20. {
  21. public:
  22. SkyboxBase();
  23. virtual ~SkyboxBase() { }
  24. /** Checks whether the skybox should be used or not. */
  25. bool getIsActive() const { return mIsActive; }
  26. /** Sets whether the skybox should be used or not. */
  27. void setIsActive(bool active) { mIsActive = active; _markCoreDirty(); }
  28. /** Returns an identifier that uniquely identifies the skybox. */
  29. const String& getUUID() const { return mUUID; }
  30. /**
  31. * Marks the simulation thread object as dirty and notifies the system its data should be synced with its core
  32. * thread counterpart.
  33. */
  34. virtual void _markCoreDirty(SkyboxDirtyFlag flags = SkyboxDirtyFlag::Everything) { }
  35. protected:
  36. String mUUID; /**< Identifier that uniquely identifies the skybox. */
  37. bool mIsActive; /**< Determines whether the skybox should be rendered or not. */
  38. };
  39. /** Templated base class for both core and sim thread implementations of a skybox. */
  40. template<bool Core>
  41. class BS_CORE_EXPORT TSkybox : public SkyboxBase
  42. {
  43. typedef typename TTextureType<Core>::Type TextureType;
  44. public:
  45. TSkybox();
  46. virtual ~TSkybox() { }
  47. /**
  48. * Assigns an environment map to use for sampling skybox radiance. Must be a cube-map texture, and should ideally
  49. * contain HDR data.
  50. */
  51. void setTexture(const TextureType& texture) { mTexture = texture; _markCoreDirty(SkyboxDirtyFlag::Texture); }
  52. /** Gets the texture assigned through setTexture(). */
  53. TextureType getTexture() const { return mTexture; }
  54. protected:
  55. TextureType mTexture;
  56. };
  57. /** @} */
  58. /** @addtogroup Renderer-Engine-Internal
  59. * @{
  60. */
  61. namespace ct { class Skybox; }
  62. /** Allows you to specify an environment map to use for sampling radiance of the sky. */
  63. class BS_CORE_EXPORT Skybox : public IReflectable, public CoreObject, public TSkybox<false>
  64. {
  65. public:
  66. /** Retrieves an implementation of the skybox usable only from the core thread. */
  67. SPtr<ct::Skybox> getCore() const;
  68. /** Creates a new skybox. */
  69. static SPtr<Skybox> create();
  70. protected:
  71. Skybox();
  72. /** @copydoc CoreObject::createCore */
  73. SPtr<ct::CoreObject> createCore() const override;
  74. /** @copydoc SkyboxBase::_markCoreDirty */
  75. void _markCoreDirty(SkyboxDirtyFlag flags = SkyboxDirtyFlag::Everything) override;
  76. /** @copydoc CoreObject::syncToCore */
  77. CoreSyncData syncToCore(FrameAlloc* allocator) override;
  78. /************************************************************************/
  79. /* RTTI */
  80. /************************************************************************/
  81. public:
  82. friend class SkyboxRTTI;
  83. static RTTITypeBase* getRTTIStatic();
  84. RTTITypeBase* getRTTI() const override;
  85. };
  86. namespace ct
  87. {
  88. /** Core thread usable version of a bs::Skybox */
  89. class BS_CORE_EXPORT Skybox : public CoreObject, public TSkybox<true>
  90. {
  91. public:
  92. ~Skybox();
  93. protected:
  94. friend class bs::Skybox;
  95. Skybox();
  96. /** @copydoc CoreObject::initialize */
  97. void initialize() override;
  98. /** @copydoc CoreObject::syncToCore */
  99. void syncToCore(const CoreSyncData& data) override;
  100. };
  101. }
  102. /** @} */
  103. }