adding callbacks for updating shaders

This commit is contained in:
Clément Le Bihan
2021-06-15 12:28:49 +02:00
parent 3eac269a89
commit 1823eadc37
3 changed files with 55 additions and 22 deletions
+21 -11
View File
@@ -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<WAL::Entity &, WAL::Wal &> &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<WAL::Entity &, WAL::Wal &> &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<WAL::Entity &, WAL::Wal &> &onFixedUpdate)
: ShaderComponent(entity, fragmentFilePath, vertexFilePath, onFixedUpdate)
{
}
}
+33 -10
View File
@@ -5,23 +5,28 @@
#pragma once
#include <string>
#include <Models/Callback.hpp>
#include <Component/Component.hpp>
#include <Entity/Entity.hpp>
#include <Shaders/Shaders.hpp>
#include <Model/Model.hpp>
#include <Wal.hpp>
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<WAL::Entity &, WAL::Wal &> &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<WAL::Entity &, WAL::Wal &> &onFixedUpdate = WAL::Callback<WAL::Entity &, WAL::Wal &>());
//! @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<WAL::Entity &, WAL::Wal &> &onFixedUpdate = WAL::Callback<WAL::Entity &, WAL::Wal &>());
//! @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<WAL::Entity &, WAL::Wal &> &onFixedUpdate = WAL::Callback<WAL::Entity &, WAL::Wal &>());
//! @brief Default copy ctor
ShaderComponentDrawable2D(const ShaderComponentDrawable2D &) = default;
//! @brief Default dtor
~ShaderComponentDrawable2D() override = default;
//! @brief Default assignment operator
ShaderComponentDrawable2D &operator=(const ShaderComponentDrawable2D &) = delete;
};
+1 -1
View File
@@ -51,7 +51,7 @@ namespace BBM
.addComponent<GravityComponent>()
.addComponent<BumperTimerComponent>()
.addComponent<KeyboardComponent>()
.addComponent<ShaderComponentModel>("assets/shaders/glsl330/predator.fs")
.addComponent<ShaderComponentModel>("/home/cbihan/Downloads/mask.fs", "/home/cbihan/Downloads/mask.vs")
.addComponent<TagComponent<BlowablePass>>()
//.addComponent<GamepadComponent>(0)
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 3)