CPass.h 6.4 KB

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