BsLightProbeCache.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsPrerequisites.h"
  5. #include "BsParamBlocks.h"
  6. #include "BsRendererMaterial.h"
  7. #include "BsModule.h"
  8. namespace bs { namespace ct
  9. {
  10. /** @addtogroup Renderer-Engine-Internal
  11. * @{
  12. */
  13. /**
  14. * Keeps a cache of all textures used by light probes so they may be generated during development time, and then just
  15. * loaded during runtime.
  16. */
  17. class BS_EXPORT LightProbeCache : public Module<LightProbeCache>
  18. {
  19. public:
  20. ~LightProbeCache();
  21. /** Initializes the cache with a path at which it can find the saved textures. */
  22. void initCache(const Path& path);
  23. /** Notifies the manager that the probe with the provided UUID is dirty and needs to be re-created. */
  24. void notifyDirty(const String& uuid);
  25. /**
  26. * Checks if the radiance texture for the probe with the specified UUID is marked as dirty, or if it hasn't been
  27. * cached yet at all.
  28. */
  29. bool isRadianceDirty(const String& uuid) const;
  30. /**
  31. * Checks if the radiance texture for the probe with the specified UUID is marked as dirty, or if it hasn't been
  32. * cached yet at all.
  33. */
  34. bool isIrradianceDirty(const String& uuid) const;
  35. /** Sets a cached radiance texture and associates it with the provided UUID. */
  36. void setCachedRadianceTexture(const String& uuid, const SPtr<Texture>& texture);
  37. /** Sets a cached irradiance texture and associates it with the provided UUID. */
  38. void setCachedIrradianceTexture(const String& uuid, const SPtr<Texture>& texture);
  39. /**
  40. * Returns an radiance texture that was assigned to the specified UUID with setCachedRadianceTexture() was
  41. * called.
  42. */
  43. SPtr<Texture> getCachedRadianceTexture(const String& uuid) const;
  44. /**
  45. * Returns an irradiance texture that was assigned to the specified UUID with setCachedIrradianceTexture() was
  46. * called.
  47. */
  48. SPtr<Texture> getCachedIrradianceTexture(const String& uuid) const;
  49. /** Unloads in-memory data for a probe with the specified UUID. */
  50. void unloadCachedTexture(const String& uuid);
  51. /** Saves all cached textures in a folder at the provided path. */
  52. void saveCache(const Path& path);
  53. private:
  54. /** Information about a single light probe texture. */
  55. struct TextureInfo
  56. {
  57. SPtr<Texture> texture = nullptr;
  58. bool dirty = false;
  59. bool needsSaving = false;
  60. };
  61. /** Information about textures for a single light probe. */
  62. struct ProbeInfo
  63. {
  64. TextureInfo radiance;
  65. TextureInfo irradiance;
  66. };
  67. /** Loads a saved cached texture at the specified path. */
  68. SPtr<Texture> loadCachedTexture(const Path& path) const;
  69. /** Saves cached texture data at the specified path. */
  70. void saveCachedTexture(const TextureInfo& texInfo, const Path& path);
  71. Path mDataPath;
  72. mutable UnorderedMap<String, ProbeInfo> mProbeInfos;
  73. };
  74. /** @} */
  75. }}