From d738848eb000a80a4ca812587f98c5ba95d838fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Tue, 8 Jun 2021 12:44:52 +0200 Subject: [PATCH] readding ShaderComponent.cpp/hpp --- CMakeLists.txt | 108 +++++++++--------- sources/Component/Shaders/ShaderComponent.cpp | 49 ++++++++ sources/Component/Shaders/ShaderComponent.hpp | 78 +++++++++++++ sources/Runner/Runner.cpp | 2 + 4 files changed, 183 insertions(+), 54 deletions(-) create mode 100644 sources/Component/Shaders/ShaderComponent.cpp create mode 100644 sources/Component/Shaders/ShaderComponent.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index dfb4cd6f..6bcfed49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,60 +20,60 @@ if (EMSCRIPTEN) endif () set(SOURCES - sources/Models/GameState.hpp - sources/Runner/Runner.cpp - sources/Runner/Runner.hpp - sources/Map/Map.cpp - sources/Map/Map.hpp - sources/Component/Position/PositionComponent.cpp - sources/Component/Position/PositionComponent.hpp - sources/Component/Movable/MovableComponent.cpp - sources/Component/Movable/MovableComponent.hpp - sources/Component/Controllable/ControllableComponent.hpp - sources/Component/Controllable/ControllableComponent.cpp - sources/Component/Gamepad/GamepadComponent.cpp - sources/Component/Gamepad/GamepadComponent.hpp - sources/Component/Keyboard/KeyboardComponent.cpp - sources/Component/Keyboard/KeyboardComponent.hpp - sources/Component/Health/HealthComponent.cpp - sources/Component/Health/HealthComponent.hpp - sources/System/Movable/MovableSystem.hpp - sources/System/Movable/MovableSystem.cpp - sources/System/Controllable/ControllableSystem.cpp - sources/System/Controllable/ControllableSystem.hpp - sources/System/Gamepad/GamepadSystem.cpp - sources/System/Gamepad/GamepadSystem.hpp - sources/System/Health/HealthSystem.cpp - sources/System/Health/HealthSystem.hpp - sources/System/Keyboard/KeyboardSystem.cpp - sources/System/Keyboard/KeyboardSystem.hpp - sources/System/Movable/MovableSystem.cpp - sources/System/Movable/MovableSystem.hpp - sources/Models/Vector3.hpp - sources/Component/GridCentered/GridCenteredComponent.cpp - sources/Component/GridCentered/GridCenteredComponent.hpp - sources/System/GridCentered/GridCenteredSystem.cpp - sources/System/GridCentered/GridCenteredSystem.hpp - sources/Models/Vector2.hpp - sources/Component/Renderer/Drawable2DComponent.hpp - sources/Component/Renderer/Drawable3DComponent.hpp - sources/System/Renderer/RenderSystem.hpp - sources/System/Renderer/RenderSystem.cpp - sources/Component/Renderer/CameraComponent.cpp - sources/Component/Renderer/CameraComponent.hpp - sources/Component/Animation/AnimationsComponent.cpp - sources/Component/Animation/AnimationsComponent.hpp - sources/System/Animation/AnimationsSystem.cpp - sources/System/Animation/AnimationsSystem.hpp - sources/Component/Collision/CollisionComponent.cpp - sources/Component/Collision/CollisionComponent.hpp - sources/System/Collision/CollisionSystem.hpp - sources/System/Collision/CollisionSystem.cpp - sources/Component/Animator/AnimatorComponent.cpp - sources/Component/Animator/AnimatorComponent.hpp - sources/System/Animator/AnimatorSystem.cpp - sources/System/Animator/AnimatorSystem.hpp -) + sources/Models/GameState.hpp + sources/Runner/Runner.cpp + sources/Runner/Runner.hpp + sources/Map/Map.cpp + sources/Map/Map.hpp + sources/Component/Position/PositionComponent.cpp + sources/Component/Position/PositionComponent.hpp + sources/Component/Movable/MovableComponent.cpp + sources/Component/Movable/MovableComponent.hpp + sources/Component/Controllable/ControllableComponent.hpp + sources/Component/Controllable/ControllableComponent.cpp + sources/Component/Gamepad/GamepadComponent.cpp + sources/Component/Gamepad/GamepadComponent.hpp + sources/Component/Keyboard/KeyboardComponent.cpp + sources/Component/Keyboard/KeyboardComponent.hpp + sources/Component/Health/HealthComponent.cpp + sources/Component/Health/HealthComponent.hpp + sources/System/Movable/MovableSystem.hpp + sources/System/Movable/MovableSystem.cpp + sources/System/Controllable/ControllableSystem.cpp + sources/System/Controllable/ControllableSystem.hpp + sources/System/Gamepad/GamepadSystem.cpp + sources/System/Gamepad/GamepadSystem.hpp + sources/System/Health/HealthSystem.cpp + sources/System/Health/HealthSystem.hpp + sources/System/Keyboard/KeyboardSystem.cpp + sources/System/Keyboard/KeyboardSystem.hpp + sources/System/Movable/MovableSystem.cpp + sources/System/Movable/MovableSystem.hpp + sources/Models/Vector3.hpp + sources/Component/GridCentered/GridCenteredComponent.cpp + sources/Component/GridCentered/GridCenteredComponent.hpp + sources/System/GridCentered/GridCenteredSystem.cpp + sources/System/GridCentered/GridCenteredSystem.hpp + sources/Models/Vector2.hpp + sources/Component/Renderer/Drawable2DComponent.hpp + sources/Component/Renderer/Drawable3DComponent.hpp + sources/System/Renderer/RenderSystem.hpp + sources/System/Renderer/RenderSystem.cpp + sources/Component/Renderer/CameraComponent.cpp + sources/Component/Renderer/CameraComponent.hpp + sources/Component/Animation/AnimationsComponent.cpp + sources/Component/Animation/AnimationsComponent.hpp + sources/System/Animation/AnimationsSystem.cpp + sources/System/Animation/AnimationsSystem.hpp + sources/Component/Collision/CollisionComponent.cpp + sources/Component/Collision/CollisionComponent.hpp + sources/System/Collision/CollisionSystem.hpp + sources/System/Collision/CollisionSystem.cpp + sources/Component/Animator/AnimatorComponent.cpp + sources/Component/Animator/AnimatorComponent.hpp + sources/System/Animator/AnimatorSystem.cpp + sources/System/Animator/AnimatorSystem.hpp + sources/Component/Shaders/ShaderComponent.cpp sources/Component/Shaders/ShaderComponent.hpp) add_executable(bomberman sources/main.cpp ${SOURCES} diff --git a/sources/Component/Shaders/ShaderComponent.cpp b/sources/Component/Shaders/ShaderComponent.cpp new file mode 100644 index 00000000..a87068b6 --- /dev/null +++ b/sources/Component/Shaders/ShaderComponent.cpp @@ -0,0 +1,49 @@ +// +// Created by cbihan on 03/06/2021. +// + +#include "ShaderComponent.hpp" + +#include + +namespace BBM +{ + WAL::Component *ShaderComponent::clone(WAL::Entity &entity) const + { + return new ShaderComponent(*this); + } + + RAY::Shader &ShaderComponent::getShader() + { + return this->_shader; + } + + ShaderComponent::ShaderComponent(WAL::Entity &entity, const std::string &fragmentFilePath, const std::string &vertexFilePath) + : WAL::Component(entity), + _refEntity(entity), + _shader(vertexFilePath, fragmentFilePath), + _fragmentFilePath(fragmentFilePath), + _vertexFilePath(vertexFilePath) + { + } + + std::string ShaderComponent::getFragmentFilePath() const + { + return this->_fragmentFilePath; + } + + std::string ShaderComponent::getVertexFilePath() const + { + return this->_vertexFilePath; + } + + ShaderComponentModel::ShaderComponentModel(WAL::Entity &entity, std::string fragmentFilePath, std::string vertexFilePath) + : ShaderComponent(entity, std::move(fragmentFilePath), std::move(vertexFilePath)) + { + } + + ShaderComponentDrawable::ShaderComponentDrawable(WAL::Entity &entity, std::string fragmentFilePath, std::string vertexFilePath) + : ShaderComponent(entity, std::move(fragmentFilePath), std::move(vertexFilePath)) + { + } +} \ No newline at end of file diff --git a/sources/Component/Shaders/ShaderComponent.hpp b/sources/Component/Shaders/ShaderComponent.hpp new file mode 100644 index 00000000..c20a7e6c --- /dev/null +++ b/sources/Component/Shaders/ShaderComponent.hpp @@ -0,0 +1,78 @@ +// +// Created by cbihan on 03/06/2021. +// + +#pragma once + +#include +#include +#include +#include + +namespace BBM +{ + class ShaderComponent : public WAL::Component + { + private: + //! @brief efefefefez + WAL::Entity &_refEntity; + + //! @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 getter for _shader + RAY::Shader &getShader(); + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief get the fragment file path + std::string getFragmentFilePath() const; + + + //! @brief get the fragment file path + std::string getVertexFilePath() const; + + //! @brief ctor + //! @note use empty string to omit a file + ShaderComponent(WAL::Entity &entity, const std::string& fragmentFilePath, const std::string& vertexFilePath = ""); + //! @brief Default copy ctor + ShaderComponent(const ShaderComponent &) = default; + //! @brief Default dtor + ~ShaderComponent() override = default; + //! @brief Default assignment operator + ShaderComponent &operator=(const ShaderComponent &) = delete; + }; + + class ShaderComponentModel : public ShaderComponent + { + public: + //! @brief ctor + //! @note use empty string to omit a file + ShaderComponentModel(WAL::Entity &entity, std::string fragmentFilePath, std::string vertexFilePath = ""); + //! @brief Default copy ctor + ShaderComponentModel(const ShaderComponentModel &) = default; + //! @brief Default dtor + ~ShaderComponentModel() override = default; + //! @brief Default assignment operator + ShaderComponentModel &operator=(const ShaderComponentModel &) = delete; + }; + + class ShaderComponentDrawable : public ShaderComponent + { + public: + //! @brief ctor + //! @note use empty string to omit a file + ShaderComponentDrawable(WAL::Entity &entity, std::string fragmentFilePath, std::string vertexFilePath = ""); + //! @brief Default copy ctor + ShaderComponentDrawable(const ShaderComponentDrawable &) = default; + //! @brief Default dtor + ~ShaderComponentDrawable() override = default; + //! @brief Default assignment operator + ShaderComponentDrawable &operator=(const ShaderComponentDrawable &) = delete; + }; +} \ No newline at end of file diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index ab953439..e6a0dc33 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -26,6 +26,7 @@ #include #include "Component/Animation/AnimationsComponent.hpp" #include "System/Animation/AnimationsSystem.hpp" +#include "Component/Shaders/ShaderComponent.hpp" #include "Map/Map.hpp" namespace RAY3D = RAY::Drawables::Drawables3D; @@ -69,6 +70,7 @@ namespace BBM .addComponent() .addComponent() .addComponent() + .addComponent("assets/shaders/glsl330/predator.fs") .addComponent(RAY::ModelAnimations("assets/player/player.iqm"), 3) .addComponent(1) .addComponent()