FrameMaterial.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include <GL/glew.h>
  3. #include <glm/glm.hpp>
  4. #include <map>
  5. #include <memory>
  6. #include <string>
  7. #include "WallpaperEngine/Data/Model/Material.h"
  8. #include "WallpaperEngine/Render/Shaders/Shader.h"
  9. namespace WallpaperEngine::Data::Model {
  10. struct Project;
  11. }
  12. namespace WallpaperEngine::Render {
  13. class CFBO;
  14. class CWallpaper;
  15. /** A util material drawn over a whole target (bloom, combine; sub_14017FA70, sub_140183610), first pass only */
  16. class FrameMaterial {
  17. public:
  18. /** on top of the material's own (sub_140150110) */
  19. FrameMaterial (
  20. const CWallpaper& owner, const Data::Model::Project& project, const std::string& file,
  21. const Data::Model::ComboMap& combos = {}
  22. );
  23. ~FrameMaterial ();
  24. FrameMaterial (const FrameMaterial&) = delete;
  25. FrameMaterial& operator= (const FrameMaterial&) = delete;
  26. /** material +208/+216 overrides */
  27. void setTexture (int index, GLuint texture, GLenum target = GL_TEXTURE_2D);
  28. /** by material name (sub_14017E920) */
  29. void setConstant (const std::string& name, float value);
  30. void setConstant (const std::string& name, const glm::vec3& value);
  31. void setConstant (const std::string& name, const glm::vec4& value);
  32. /** by shader name */
  33. void setUniform (const std::string& name, float value);
  34. void setUniform (const std::string& name, const glm::vec2& value);
  35. void setUniform (const std::string& name, const glm::vec4& value);
  36. void draw (GLuint framebuffer, const glm::ivec2& size) const;
  37. void draw (const CFBO& target) const;
  38. private:
  39. struct Value {
  40. glm::vec4 value { 0.0f };
  41. int components = 1;
  42. bool integer = false;
  43. };
  44. void link (const std::string& vertex, const std::string& fragment, const std::string& name);
  45. void setValue (const std::string& uniform, const glm::vec4& value, int components);
  46. [[nodiscard]] std::string uniformOf (const std::string& constant) const;
  47. const CWallpaper& m_owner;
  48. std::string m_file;
  49. Data::Model::MaterialUniquePtr m_material;
  50. const Data::Model::MaterialPass* m_pass = nullptr;
  51. Data::Model::ComboMap m_combos;
  52. Data::Model::ComboMap m_overrideCombos;
  53. Data::Model::TextureMap m_noTextures;
  54. std::unique_ptr<Shaders::Shader> m_shader;
  55. GLuint m_program = GL_NONE;
  56. GLuint m_vertices = GL_NONE;
  57. /** the scene's VAO carries the output quad's attributes */
  58. GLuint m_vao = GL_NONE;
  59. GLint a_Position = -1;
  60. GLint a_TexCoord = -1;
  61. struct Texture {
  62. GLuint texture = GL_NONE;
  63. GLenum target = GL_TEXTURE_2D;
  64. };
  65. std::map<int, Texture> m_textures;
  66. std::map<std::string, Value> m_values;
  67. };
  68. } // namespace WallpaperEngine::Render