Add light support (WIP)
This commit is contained in:
64
include/Nazara/Graphics/Components/LightComponent.hpp
Normal file
64
include/Nazara/Graphics/Components/LightComponent.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GRAPHICS_COMPONENTS_LIGHTCOMPONENT_HPP
|
||||
#define NAZARA_GRAPHICS_COMPONENTS_LIGHTCOMPONENT_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ECS.hpp>
|
||||
#include <Nazara/Graphics/Light.hpp>
|
||||
#include <Nazara/Graphics/WorldInstance.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_GRAPHICS_API LightComponent
|
||||
{
|
||||
public:
|
||||
struct LightEntry;
|
||||
|
||||
inline LightComponent(bool initialyVisible = true);
|
||||
LightComponent(const LightComponent&) = default;
|
||||
LightComponent(LightComponent&&) = default;
|
||||
~LightComponent() = default;
|
||||
|
||||
inline void AttachLight(std::shared_ptr<Light> renderable, UInt32 renderMask);
|
||||
|
||||
inline void Clear();
|
||||
|
||||
inline void DetachLight(const std::shared_ptr<Light>& renderable);
|
||||
|
||||
inline const std::vector<LightEntry>& GetLights() const;
|
||||
|
||||
inline void Hide();
|
||||
|
||||
inline bool IsVisible() const;
|
||||
|
||||
inline void Show(bool show = true);
|
||||
|
||||
LightComponent& operator=(const LightComponent&) = default;
|
||||
LightComponent& operator=(LightComponent&&) = default;
|
||||
|
||||
NazaraSignal(OnLightAttached, LightComponent* /*graphicsComponent*/, const LightEntry& /*lightEntry*/);
|
||||
NazaraSignal(OnLightDetach, LightComponent* /*graphicsComponent*/, const LightEntry& /*lightEntry*/);
|
||||
NazaraSignal(OnVisibilityUpdate, LightComponent* /*graphicsComponent*/, bool /*newVisibilityState*/);
|
||||
|
||||
struct LightEntry
|
||||
{
|
||||
std::shared_ptr<Light> light;
|
||||
UInt32 renderMask;
|
||||
};
|
||||
|
||||
private:
|
||||
std::vector<LightEntry> m_lightEntries;
|
||||
bool m_isVisible;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/Components/LightComponent.inl>
|
||||
|
||||
#endif // NAZARA_GRAPHICS_COMPONENTS_LIGHTCOMPONENT_HPP
|
||||
68
include/Nazara/Graphics/Components/LightComponent.inl
Normal file
68
include/Nazara/Graphics/Components/LightComponent.inl
Normal file
@@ -0,0 +1,68 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/Components/LightComponent.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline LightComponent::LightComponent(bool initialyVisible) :
|
||||
m_isVisible(initialyVisible)
|
||||
{
|
||||
}
|
||||
|
||||
inline void LightComponent::AttachLight(std::shared_ptr<Light> light, UInt32 renderMask)
|
||||
{
|
||||
auto& entry = m_lightEntries.emplace_back();
|
||||
entry.light = std::move(light);
|
||||
entry.renderMask = renderMask;
|
||||
|
||||
OnLightAttached(this, m_lightEntries.back());
|
||||
}
|
||||
|
||||
inline void LightComponent::Clear()
|
||||
{
|
||||
for (const auto& lightEntry : m_lightEntries)
|
||||
OnLightDetach(this, lightEntry);
|
||||
|
||||
m_lightEntries.clear();
|
||||
}
|
||||
|
||||
inline void LightComponent::DetachLight(const std::shared_ptr<Light>& light)
|
||||
{
|
||||
auto it = std::find_if(m_lightEntries.begin(), m_lightEntries.end(), [&](const auto& lightEntry) { return lightEntry.light == light; });
|
||||
if (it != m_lightEntries.end())
|
||||
{
|
||||
OnLightDetach(this, *it);
|
||||
|
||||
m_lightEntries.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
inline auto LightComponent::GetLights() const -> const std::vector<LightEntry>&
|
||||
{
|
||||
return m_lightEntries;
|
||||
}
|
||||
|
||||
inline void LightComponent::Hide()
|
||||
{
|
||||
return Show(false);
|
||||
}
|
||||
|
||||
inline bool LightComponent::IsVisible() const
|
||||
{
|
||||
return m_isVisible;
|
||||
}
|
||||
|
||||
inline void LightComponent::Show(bool show)
|
||||
{
|
||||
if (m_isVisible != show)
|
||||
{
|
||||
OnVisibilityUpdate(this, show);
|
||||
m_isVisible = show;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
Reference in New Issue
Block a user