Shader.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. class Shader {
  16. public:
  17. struct ParameterSearchResult {
  18. Variables::ShaderVariable* vertex;
  19. Variables::ShaderVariable* fragment;
  20. };
  21. Shader (
  22. const AssetLocator& assetLocator, std::string filename, const ComboMap& combos, const ComboMap& overrideCombos,
  23. const TextureMap& textures, const TextureMap& overrideTextures, const ShaderConstantMap& constants
  24. );
  25. const std::string& vertex ();
  26. const std::string& fragment ();
  27. /** Empty when there is no geometry stage */
  28. const std::string& geometry ();
  29. [[nodiscard]] const ShaderUnit& getVertex () const;
  30. [[nodiscard]] const ShaderUnit& getFragment () const;
  31. [[nodiscard]] const std::map<std::string, int>& getCombos () const;
  32. /** Searches both the vertex and fragment shader units for a parameter with this name */
  33. [[nodiscard]] ParameterSearchResult findParameter (const std::string& name) const;
  34. private:
  35. ShaderUnit m_vertex;
  36. ShaderUnit m_fragment;
  37. /** GS_ENABLED shaders with a .geom, like WE's particle shaders (its renderer always sets that define) */
  38. std::unique_ptr<ShaderUnit> m_geometry;
  39. std::string m_file;
  40. const ComboMap& m_combos;
  41. const TextureMap m_passTextures;
  42. };
  43. } // namespace WallpaperEngine::Render::Shaders