2
0

ShaderPrecache.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (c) 2008-2022 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Container/HashSet.h"
  5. #include "../Core/Object.h"
  6. #include "../Resource/XMLFile.h"
  7. namespace Urho3D
  8. {
  9. class Graphics;
  10. class ShaderVariation;
  11. /// Utility class for collecting used shader combinations during runtime for precaching.
  12. class URHO3D_API ShaderPrecache : public Object
  13. {
  14. URHO3D_OBJECT(ShaderPrecache, Object);
  15. public:
  16. /// Construct and begin collecting shader combinations. Load existing combinations from XML if the file exists.
  17. ShaderPrecache(Context* context, const String& fileName);
  18. /// Destruct. Write the collected shaders to XML.
  19. ~ShaderPrecache() override;
  20. /// Collect a shader combination. Called by Graphics when shaders have been set.
  21. void StoreShaders(ShaderVariation* vs, ShaderVariation* ps);
  22. /// Load shaders from an XML file.
  23. static void LoadShaders(Graphics* graphics, Deserializer& source);
  24. private:
  25. /// XML file name.
  26. String fileName_;
  27. /// XML file.
  28. XMLFile xmlFile_;
  29. /// Already encountered shader combinations, pointer version for fast queries.
  30. HashSet<Pair<ShaderVariation*, ShaderVariation*>> usedPtrCombinations_;
  31. /// Already encountered shader combinations.
  32. HashSet<String> usedCombinations_;
  33. };
  34. }