CPass.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #pragma once
  2. #include <glm/gtc/type_ptr.hpp>
  3. #include <utility>
  4. #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h"
  5. #include "WallpaperEngine/Render/Objects/Effects/CMaterial.h"
  6. #include "WallpaperEngine/Render/Shaders/Compiler.h"
  7. #include "WallpaperEngine/Assets/ITexture.h"
  8. #include "WallpaperEngine/Render/CFBO.h"
  9. namespace WallpaperEngine::Render::Objects::Effects
  10. {
  11. using namespace WallpaperEngine::Assets;
  12. using namespace WallpaperEngine::Render::Shaders::Variables;
  13. class CMaterial;
  14. class CPass
  15. {
  16. public:
  17. CPass (CMaterial* material, Core::Objects::Images::Materials::CPass* pass);
  18. void render ();
  19. void setDestination (const CFBO* drawTo);
  20. void setInput (const ITexture* input);
  21. void setTexCoord (GLuint texcoord);
  22. void setPosition (GLuint position);
  23. void setModelViewProjectionMatrix (const glm::mat4* projection);
  24. void setModelMatrix (glm::mat4 model);
  25. const CMaterial* getMaterial () const;
  26. Core::Objects::Images::Materials::CPass* getPass ();
  27. private:
  28. enum UniformType
  29. {
  30. Float = 0,
  31. Matrix4 = 1,
  32. Integer = 2,
  33. Vector2 = 3,
  34. Vector3 = 4,
  35. Vector4 = 5,
  36. Double = 6
  37. };
  38. class UniformEntry
  39. {
  40. public:
  41. UniformEntry (GLint id, std::string name, UniformType type, const void* value) :
  42. id (id), name (std::move (name)), type (type), value (value) { }
  43. GLint id;
  44. std::string name;
  45. UniformType type;
  46. const void* value;
  47. };
  48. class ReferenceUniformEntry
  49. {
  50. public:
  51. ReferenceUniformEntry (GLint id, std::string name, UniformType type, const void** value) :
  52. id (id), name (std::move (name)), type (type), value (value) { }
  53. GLint id;
  54. std::string name;
  55. UniformType type;
  56. const void** value;
  57. };
  58. class AttribEntry
  59. {
  60. public:
  61. AttribEntry (GLint id, std::string name, GLint type, GLint elements, const GLuint* value) :
  62. id (id), name (std::move (name)), type (type), elements (elements), value (value) { }
  63. GLint id;
  64. std::string name;
  65. GLint type;
  66. GLint elements;
  67. const GLuint* value;
  68. };
  69. static GLuint compileShader (Render::Shaders::Compiler* shader, GLuint type);
  70. void setupTextures ();
  71. void setupShaders ();
  72. void setupShaderVariables ();
  73. void setupUniforms ();
  74. void setupAttributes ();
  75. void addAttribute (const std::string& name, GLint type, GLint elements, const GLuint* value);
  76. void addUniform (CShaderVariable* value);
  77. void addUniform (const std::string& name, int value);
  78. void addUniform (const std::string& name, double value);
  79. void addUniform (const std::string& name, float value);
  80. void addUniform (const std::string& name, glm::vec2 value);
  81. void addUniform (const std::string& name, glm::vec3 value);
  82. void addUniform (const std::string& name, glm::vec4 value);
  83. void addUniform (const std::string& name, glm::mat4 value);
  84. void addUniform (const std::string& name, const int* value);
  85. void addUniform (const std::string& name, const double* value);
  86. void addUniform (const std::string& name, const float* value);
  87. void addUniform (const std::string& name, const glm::vec2* value);
  88. void addUniform (const std::string& name, const glm::vec3* value);
  89. void addUniform (const std::string& name, const glm::vec4* value);
  90. void addUniform (const std::string& name, const glm::mat4* value);
  91. void addUniform (const std::string& name, const int** value);
  92. void addUniform (const std::string& name, const double** value);
  93. void addUniform (const std::string& name, const float** value);
  94. void addUniform (const std::string& name, const glm::vec2** value);
  95. void addUniform (const std::string& name, const glm::vec3** value);
  96. void addUniform (const std::string& name, const glm::vec4** value);
  97. void addUniform (const std::string& name, const glm::mat4** value);
  98. template <typename T> void addUniform (const std::string& name, UniformType type, T value);
  99. template <typename T> void addUniform (const std::string& name, UniformType type, T* value);
  100. template <typename T> void addUniform (const std::string& name, UniformType type, T** value);
  101. const ITexture* resolveTexture (const ITexture* expected, int index, const ITexture* previous = nullptr);
  102. CMaterial* m_material;
  103. Core::Objects::Images::Materials::CPass* m_pass;
  104. std::vector<const ITexture*> m_textures;
  105. std::map<int, const CFBO*> m_fbos;
  106. std::map <std::string, bool> m_foundCombos;
  107. std::vector<AttribEntry*> m_attribs;
  108. std::map<std::string, UniformEntry*> m_uniforms;
  109. std::map<std::string, ReferenceUniformEntry*> m_referenceUniforms;
  110. const glm::mat4* m_modelViewProjectionMatrix;
  111. glm::mat4 m_modelMatrix;
  112. /**
  113. * Contains the final map of textures to be used
  114. */
  115. std::map <int, const ITexture*> m_finalTextures;
  116. Render::Shaders::Compiler* m_fragShader;
  117. Render::Shaders::Compiler* m_vertShader;
  118. const CFBO* m_drawTo;
  119. const ITexture* m_input;
  120. GLuint m_programID;
  121. // shader variables used temporary
  122. GLint g_Texture0Rotation;
  123. GLint g_Texture0Translation;
  124. GLuint a_TexCoord;
  125. GLuint a_Position;
  126. };
  127. }