BsSkybox.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. /**
  29. * Brightness multiplier that will be applied to skybox values before they're being used. Allows you to make the
  30. * skybox more or less bright. Equal to one by default.
  31. */
  32. void setBrightness(float brightness) { mBrightness = brightness; _markCoreDirty(); }
  33. /** @see setBrightness */
  34. float getBrightness() const { return mBrightness; }
  35. /** Returns an identifier that uniquely identifies the skybox. */
  36. const String& getUUID() const { return mUUID; }
  37. /**
  38. * Marks the simulation thread object as dirty and notifies the system its data should be synced with its core
  39. * thread counterpart.
  40. */
  41. virtual void _markCoreDirty(SkyboxDirtyFlag flags = SkyboxDirtyFlag::Everything) { }
  42. protected:
  43. String mUUID; /**< Identifier that uniquely identifies the skybox. */
  44. bool mIsActive; /**< Determines whether the skybox should be rendered or not. */
  45. float mBrightness; /**< Multiplier to apply to evaluated skybox values before using them. */
  46. };
  47. /** Templated base class for both core and sim thread implementations of a skybox. */
  48. template<bool Core>
  49. class BS_CORE_EXPORT TSkybox : public SkyboxBase
  50. {
  51. typedef typename TTextureType<Core>::Type TextureType;
  52. public:
  53. TSkybox();
  54. virtual ~TSkybox() { }
  55. /**
  56. * Assigns an environment map to use for sampling skybox radiance. Must be a cube-map texture, and should ideally
  57. * contain HDR data.
  58. */
  59. void setTexture(const TextureType& texture) { mTexture = texture; _markCoreDirty(SkyboxDirtyFlag::Texture); }
  60. /** Gets the texture assigned through setTexture(). */
  61. TextureType getTexture() const { return mTexture; }
  62. protected:
  63. TextureType mTexture;
  64. };
  65. /** @} */
  66. /** @addtogroup Renderer-Engine-Internal
  67. * @{
  68. */
  69. namespace ct { class Skybox; }
  70. /** Allows you to specify an environment map to use for sampling radiance of the sky. */
  71. class BS_CORE_EXPORT Skybox : public IReflectable, public CoreObject, public TSkybox<false>
  72. {
  73. public:
  74. /** Retrieves an implementation of the skybox usable only from the core thread. */
  75. SPtr<ct::Skybox> getCore() const;
  76. /** Creates a new skybox. */
  77. static SPtr<Skybox> create();
  78. protected:
  79. Skybox();
  80. /** @copydoc CoreObject::createCore */
  81. SPtr<ct::CoreObject> createCore() const override;
  82. /** @copydoc SkyboxBase::_markCoreDirty */
  83. void _markCoreDirty(SkyboxDirtyFlag flags = SkyboxDirtyFlag::Everything) override;
  84. /** @copydoc CoreObject::syncToCore */
  85. CoreSyncData syncToCore(FrameAlloc* allocator) override;
  86. /************************************************************************/
  87. /* RTTI */
  88. /************************************************************************/
  89. public:
  90. friend class SkyboxRTTI;
  91. static RTTITypeBase* getRTTIStatic();
  92. RTTITypeBase* getRTTI() const override;
  93. };
  94. namespace ct
  95. {
  96. /** Core thread usable version of a bs::Skybox */
  97. class BS_CORE_EXPORT Skybox : public CoreObject, public TSkybox<true>
  98. {
  99. public:
  100. ~Skybox();
  101. protected:
  102. friend class bs::Skybox;
  103. Skybox();
  104. /** @copydoc CoreObject::initialize */
  105. void initialize() override;
  106. /** @copydoc CoreObject::syncToCore */
  107. void syncToCore(const CoreSyncData& data) override;
  108. };
  109. }
  110. /** @} */
  111. }