#pragma once #include #include #include #include "../../TextureProvider.h" #include "WallpaperEngine/Data/Model/Material.h" #include "WallpaperEngine/Render/CFBO.h" #include "WallpaperEngine/Render/FBOProvider.h" #include "WallpaperEngine/Render/Helpers/ContextAware.h" #include "WallpaperEngine/Render/Shaders/Shader.h" #include "WallpaperEngine/Render/Shaders/Variables/ShaderVariable.h" namespace WallpaperEngine::Render::Objects { class CRenderable; } namespace WallpaperEngine::Render::Objects::Effects { using namespace WallpaperEngine::Render; using namespace WallpaperEngine::Render::Shaders::Variables; using namespace WallpaperEngine::Data::Model; class CPass final : public Helpers::ContextAware { public: CPass ( CRenderable& renderable, std::shared_ptr fboProvider, const MaterialPass& pass, std::optional> override, std::optional> binds, std::optional> target ); ~CPass (); void render (); void setDestination (std::shared_ptr drawTo); void setInput (std::shared_ptr input); void setPreviousInput (std::shared_ptr input); void setTexCoord (GLuint texcoord); void setPosition (GLuint position); void setModelViewProjectionMatrix (const glm::mat4* projection); void setModelViewProjectionMatrixInverse (const glm::mat4* projection); void setModelMatrix (const glm::mat4* model); void setViewProjectionMatrix (const glm::mat4* viewProjection); void setBlendingMode (BlendingMode blendingmode); [[nodiscard]] BlendingMode getBlendingMode () const; [[nodiscard]] std::shared_ptr resolveFBO (const std::string& name) const; [[nodiscard]] std::shared_ptr getFBOProvider () const; [[nodiscard]] const CRenderable& getRenderable () const; [[nodiscard]] const MaterialPass& getPass () const; [[nodiscard]] std::optional> getTarget () const; [[nodiscard]] Render::Shaders::Shader* getShader () const; [[nodiscard]] GLuint getProgramID () const; // Custom geometry rendering support (for particles, etc.) using GeometryCallback = std::function; void setGeometryCallback (GeometryCallback setupAttribs, GeometryCallback drawGeometry, GeometryCallback cleanupAttribs); // Public uniform setters for external callers (pointer-based, updated per-frame) void addUniform (const std::string& name, const float* value, int count = 1); void addUniform (const std::string& name, const glm::vec3* value); void addUniform (const std::string& name, const glm::vec4* value); void addUniform (const std::string& name, const glm::mat4* value); private: enum UniformType { Float = 0, Matrix3 = 1, Matrix4 = 2, Integer = 3, Vector2 = 4, Vector3 = 5, Vector4 = 6, Double = 7 }; class UniformEntry { public: UniformEntry (const GLint id, std::string name, UniformType type, const void* value, int count) : id (id), name (std::move (name)), type (type), value (value), count (count) { } const GLint id; std::string name; UniformType type; const void* value; int count; }; class ReferenceUniformEntry { public: ReferenceUniformEntry (const GLint id, std::string name, UniformType type, const void** value) : id (id), name (std::move (name)), type (type), value (value) { } const GLint id; std::string name; UniformType type; const void** value; }; class AttribEntry { public: AttribEntry (const GLint id, std::string name, GLint type, GLint elements, const GLuint* value) : id (id), name (std::move (name)), type (type), elements (elements), value (value) { } const GLint id; std::string name; GLint type; GLint elements; const GLuint* value; }; struct TextureAnimationState { uint32_t currentTexture = 0; glm::vec2 translation = { 0.0f, 0.0f }; glm::vec4 rotation = { 0.0f, 0.0f, 0.0f, 0.0f }; }; static GLuint compileShader (const char* shader, GLuint type); void setupShaders (); void setupShaderVariables (); void setupUniforms (); void setupTextureUniforms (); void setupAttributes (); void addAttribute (const std::string& name, GLint type, GLint elements, const GLuint* value); void addUniform (ShaderVariable* value); void addUniform (const ShaderVariable* value, const DynamicValue* setting); void addUniform (const std::string& name, int value); void addUniform (const std::string& name, double value); void addUniform (const std::string& name, float value); void addUniform (const std::string& name, glm::vec2 value); void addUniform (const std::string& name, glm::vec3 value); void addUniform (const std::string& name, glm::vec4 value); void addUniform (const std::string& name, const glm::mat3& value); void addUniform (const std::string& name, glm::mat4 value); void addUniform (const std::string& name, const int* value, int count = 1); void addUniform (const std::string& name, const double* value, int count = 1); void addUniform (const std::string& name, const glm::vec2* value); void addUniform (const std::string& name, const glm::mat3* value); void addUniform (const std::string& name, const int** value); void addUniform (const std::string& name, const double** value); void addUniform (const std::string& name, const float** value); void addUniform (const std::string& name, const glm::vec2** value); void addUniform (const std::string& name, const glm::vec3** value); void addUniform (const std::string& name, const glm::vec4** value); void addUniform (const std::string& name, const glm::mat3** value); void addUniform (const std::string& name, const glm::mat4** value); template void addUniform (const std::string& name, UniformType type, T value); template void addUniform (const std::string& name, UniformType type, T* value, int count = 1); template void addUniform (const std::string& name, UniformType type, T** value); void setupRenderFramebuffer () const; void setupRenderTexture (); [[nodiscard]] std::shared_ptr resolveTexture0 (); [[nodiscard]] TextureAnimationState resolveTextureAnimationState (const std::shared_ptr& texture) const; void bindTextureUnit (int index, const std::shared_ptr& texture, uint32_t frame) const; void bindTextureOverrides (uint32_t currentTexture, std::shared_ptr& texture0) const; void setupRenderUniforms (); void setupRenderReferenceUniforms (); void setupRenderAttributes () const; void renderGeometry () const; void cleanupRenderSetup (); std::shared_ptr resolveTexture ( std::shared_ptr expected, int index, std::shared_ptr previous = nullptr ); CRenderable& m_renderable; std::shared_ptr m_fboProvider; const MaterialPass& m_pass; const TextureMap& m_binds; const ImageEffectPassOverride& m_override; std::optional> m_target; std::map> m_fbos = {}; std::map m_combos = {}; std::vector m_attribs = {}; std::map m_uniforms = {}; std::map m_referenceUniforms = {}; BlendingMode m_blendingmode = BlendingMode_Normal; const glm::mat4* m_modelViewProjectionMatrix; const glm::mat4* m_modelViewProjectionMatrixInverse; const glm::mat4* m_modelMatrix; const glm::mat4* m_viewProjectionMatrix; /** * Contains the final map of textures to be used */ std::map> m_textures = {}; Render::Shaders::Shader* m_shader = nullptr; std::shared_ptr m_drawTo = nullptr; std::shared_ptr m_input = nullptr; std::shared_ptr m_previousInput = nullptr; glm::vec4 m_texture0Resolution = {}; GLuint m_programID; // shader variables used temporary GLint g_Texture0Rotation; GLint g_Texture0Translation; GLuint a_TexCoord; GLuint a_Position; GLuint m_vao; // Custom geometry callbacks (for particles, etc.) GeometryCallback m_setupAttribsCallback; GeometryCallback m_drawGeometryCallback; GeometryCallback m_cleanupAttribsCallback; }; } // namespace WallpaperEngine::Render::Objects::Effects