Shader.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #include <iostream>
  3. #include <map>
  4. #include <memory>
  5. #include <vector>
  6. #include "../TextureProvider.h"
  7. #include "WallpaperEngine/Render/Shaders/Variables/ShaderVariable.h"
  8. #include "GLSLContext.h"
  9. #include "ShaderUnit.h"
  10. #include "WallpaperEngine/Data/Model/Types.h"
  11. namespace WallpaperEngine::Render::Shaders {
  12. using json = nlohmann::json;
  13. using namespace WallpaperEngine::Render;
  14. using namespace WallpaperEngine::Data::Model;
  15. /**
  16. * A basic shader loader that adds basic function definitions to every loaded shader
  17. */
  18. class Shader {
  19. public:
  20. struct ParameterSearchResult {
  21. Variables::ShaderVariable* vertex;
  22. Variables::ShaderVariable* fragment;
  23. };
  24. Shader (
  25. const AssetLocator& assetLocator, std::string filename, const ComboMap& combos, const ComboMap& overrideCombos,
  26. const TextureMap& textures, const TextureMap& overrideTextures, const ShaderConstantMap& constants
  27. );
  28. const std::string& vertex ();
  29. const std::string& fragment ();
  30. /** Empty when there is no geometry stage */
  31. const std::string& geometry ();
  32. [[nodiscard]] const ShaderUnit& getVertex () const;
  33. [[nodiscard]] const ShaderUnit& getFragment () const;
  34. [[nodiscard]] const std::map<std::string, int>& getCombos () const;
  35. /** Searches both the vertex and fragment shader units for a parameter with this name */
  36. [[nodiscard]] ParameterSearchResult findParameter (const std::string& name) const;
  37. private:
  38. ShaderUnit m_vertex;
  39. ShaderUnit m_fragment;
  40. /** GS_ENABLED shaders with a .geom, like WE's particle shaders (its renderer always sets that define) */
  41. std::unique_ptr<ShaderUnit> m_geometry;
  42. std::string m_file;
  43. std::vector<Variables::ShaderVariable*> m_parameters = {};
  44. const ComboMap& m_combos;
  45. const TextureMap m_passTextures;
  46. };
  47. } // namespace WallpaperEngine::Render::Shaders