diff --git a/sources/Component/Shaders/ShaderComponent.cpp b/sources/Component/Shaders/ShaderComponent.cpp index 0320864e..5a1edcf9 100644 --- a/sources/Component/Shaders/ShaderComponent.cpp +++ b/sources/Component/Shaders/ShaderComponent.cpp @@ -16,29 +16,36 @@ namespace BBM RAY::Shader &ShaderComponent::getShader() { - return this->_shader; + return this->shader; } - ShaderComponent::ShaderComponent(WAL::Entity &entity, const std::string &fragmentFilePath, const std::string &vertexFilePath) + ShaderComponent::ShaderComponent(WAL::Entity &entity, + const std::string &fragmentFilePath, + const std::string &vertexFilePath, + const WAL::Callback &onFixedUpdate) : WAL::Component(entity), - _shader(vertexFilePath, fragmentFilePath), - _fragmentFilePath(fragmentFilePath), - _vertexFilePath(vertexFilePath) + shader(vertexFilePath, fragmentFilePath), + fragmentFilePath(fragmentFilePath), + vertexFilePath(vertexFilePath), + onFixedUpdate(onFixedUpdate) { } std::string ShaderComponent::getFragmentFilePath() const { - return this->_fragmentFilePath; + return this->fragmentFilePath; } std::string ShaderComponent::getVertexFilePath() const { - return this->_vertexFilePath; + return this->vertexFilePath; } - ShaderComponentModel::ShaderComponentModel(WAL::Entity &entity, std::string fragmentFilePath, std::string vertexFilePath) - : ShaderComponent(entity, std::move(fragmentFilePath), std::move(vertexFilePath)) + ShaderComponentModel::ShaderComponentModel(WAL::Entity &entity, + const std::string &fragmentFilePath, + const std::string &vertexFilePath, + const WAL::Callback &onFixedUpdate) + : ShaderComponent(entity, fragmentFilePath, vertexFilePath, onFixedUpdate) { } @@ -50,8 +57,11 @@ namespace BBM throw std::runtime_error("No model available with a shader model component. This is unsupported."); } - ShaderComponentDrawable2D::ShaderComponentDrawable2D(WAL::Entity &entity, std::string fragmentFilePath, std::string vertexFilePath) - : ShaderComponent(entity, std::move(fragmentFilePath), std::move(vertexFilePath)) + ShaderComponentDrawable2D::ShaderComponentDrawable2D(WAL::Entity &entity, + const std::string &fragmentFilePath, + const std::string &vertexFilePath, + const WAL::Callback &onFixedUpdate) + : ShaderComponent(entity, fragmentFilePath, vertexFilePath, onFixedUpdate) { } } \ No newline at end of file diff --git a/sources/Component/Shaders/ShaderComponent.hpp b/sources/Component/Shaders/ShaderComponent.hpp index 51428de2..0bea4116 100644 --- a/sources/Component/Shaders/ShaderComponent.hpp +++ b/sources/Component/Shaders/ShaderComponent.hpp @@ -5,23 +5,28 @@ #pragma once #include +#include #include #include #include #include +#include namespace BBM { class ShaderComponent : public WAL::Component { - private: - //! @brief The shader to be applied - RAY::Shader _shader; - //! @brief The path to the fragment file - std::string _fragmentFilePath; - //! @brief The path to the vertex file - std::string _vertexFilePath; public: + //! @brief The shader to be applied + RAY::Shader shader; + //! @brief The path to the fragment file + std::string fragmentFilePath; + //! @brief The path to the vertex file + std::string vertexFilePath; + + //! @brief the function called to update shaders vars + const WAL::Callback &onFixedUpdate; + //! @brief getter for _shader RAY::Shader &getShader(); @@ -37,11 +42,17 @@ namespace BBM //! @brief ctor //! @note use empty string to omit a file - ShaderComponent(WAL::Entity &entity, const std::string& fragmentFilePath, const std::string& vertexFilePath = ""); + ShaderComponent(WAL::Entity &entity, + const std::string &fragmentFilePath, + const std::string &vertexFilePath = "", + const WAL::Callback &onFixedUpdate = WAL::Callback()); + //! @brief Default copy ctor ShaderComponent(const ShaderComponent &) = default; + //! @brief Default dtor ~ShaderComponent() override = default; + //! @brief Default assignment operator ShaderComponent &operator=(const ShaderComponent &) = delete; }; @@ -55,11 +66,17 @@ namespace BBM //! @brief ctor //! @note use empty string to omit a file - ShaderComponentModel(WAL::Entity &entity, std::string fragmentFilePath, std::string vertexFilePath = ""); + ShaderComponentModel(WAL::Entity &entity, + const std::string &fragmentFilePath, + const std::string &vertexFilePath = "", + const WAL::Callback &onFixedUpdate = WAL::Callback()); + //! @brief Default copy ctor ShaderComponentModel(const ShaderComponentModel &) = default; + //! @brief Default dtor ~ShaderComponentModel() override = default; + //! @brief Default assignment operator ShaderComponentModel &operator=(const ShaderComponentModel &) = delete; }; @@ -69,11 +86,17 @@ namespace BBM public: //! @brief ctor //! @note use empty string to omit a file - ShaderComponentDrawable2D(WAL::Entity &entity, std::string fragmentFilePath, std::string vertexFilePath = ""); + ShaderComponentDrawable2D(WAL::Entity &entity, + const std::string &fragmentFilePath, + const std::string &vertexFilePath = "", + const WAL::Callback &onFixedUpdate = WAL::Callback()); + //! @brief Default copy ctor ShaderComponentDrawable2D(const ShaderComponentDrawable2D &) = default; + //! @brief Default dtor ~ShaderComponentDrawable2D() override = default; + //! @brief Default assignment operator ShaderComponentDrawable2D &operator=(const ShaderComponentDrawable2D &) = delete; }; diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index e506e258..9ba370bc 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -51,7 +51,7 @@ namespace BBM .addComponent() .addComponent() .addComponent() - .addComponent("assets/shaders/glsl330/predator.fs") + .addComponent("/home/cbihan/Downloads/mask.fs", "/home/cbihan/Downloads/mask.vs") .addComponent>() //.addComponent(0) .addComponent(RAY::ModelAnimations("assets/player/player.iqm"), 3)