Graphics: Separate Renderable and make Light a Renderable (LightComponent)

Former-commit-id: 6177d473f27ef493ba77417fc14461cb08b6f9e1
This commit is contained in:
Lynix 2015-06-16 00:31:04 +02:00
parent b3597d5330
commit 6d953d9e93
21 changed files with 280 additions and 140 deletions

View File

@ -7,7 +7,7 @@
#ifndef NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
#define NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
#include <Nazara/Graphics/Renderable.hpp>
#include <Nazara/Graphics/InstancedRenderable.hpp>
#include <Nazara/Utility/Node.hpp>
#include <NDK/Component.hpp>
@ -22,14 +22,14 @@ namespace Ndk
inline void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const;
inline void Attach(NzRenderableRef renderable);
inline void Attach(NzInstancedRenderableRef renderable);
inline void EnsureTransformMatrixUpdate() const;
static ComponentIndex componentIndex;
private:
void InvalidateRenderableData(const NzRenderable* renderable, nzUInt32 flags, unsigned int index);
void InvalidateRenderableData(const NzInstancedRenderable* renderable, nzUInt32 flags, unsigned int index);
inline void InvalidateTransformMatrix();
void OnAttached() override;
@ -50,10 +50,10 @@ namespace Ndk
{
}
NazaraSlot(NzRenderable, OnRenderableInvalidateInstanceData, renderableInvalidationSlot);
NazaraSlot(NzInstancedRenderable, OnInstancedRenderableInvalidateData, renderableInvalidationSlot);
mutable NzRenderable::InstanceData data;
NzRenderableRef renderable;
mutable NzInstancedRenderable::InstanceData data;
NzInstancedRenderableRef renderable;
mutable bool dataUpdated;
};

View File

@ -32,12 +32,12 @@ namespace Ndk
}
}
inline void GraphicsComponent::Attach(NzRenderableRef renderable)
inline void GraphicsComponent::Attach(NzInstancedRenderableRef renderable)
{
m_renderables.emplace_back(m_transformMatrix);
Renderable& r = m_renderables.back();
r.renderable = std::move(renderable);
r.renderableInvalidationSlot.Connect(r.renderable->OnRenderableInvalidateInstanceData, std::bind(&GraphicsComponent::InvalidateRenderableData, this, std::placeholders::_1, std::placeholders::_2, m_renderables.size()-1));
r.renderableInvalidationSlot.Connect(r.renderable->OnInstancedRenderableInvalidateData, std::bind(&GraphicsComponent::InvalidateRenderableData, this, std::placeholders::_1, std::placeholders::_2, m_renderables.size()-1));
}
inline void GraphicsComponent::EnsureTransformMatrixUpdate() const

View File

@ -0,0 +1,30 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#pragma once
#ifndef NDK_COMPONENTS_LIGHTCOMPONENT_HPP
#define NDK_COMPONENTS_LIGHTCOMPONENT_HPP
#include <Nazara/Graphics/Light.hpp>
#include <NDK/Component.hpp>
namespace Ndk
{
class NDK_API LightComponent : public Component<LightComponent>, public NzLight
{
public:
inline LightComponent(nzLightType lightType = nzLightType_Point);
LightComponent(const LightComponent& light) = default;
~LightComponent() = default;
LightComponent& operator=(const LightComponent& light) = default;
static ComponentIndex componentIndex;
};
}
#include <NDK/Components/LightComponent.inl>
#endif // NDK_COMPONENTS_LIGHTCOMPONENT_HPP

View File

@ -0,0 +1,11 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
namespace Ndk
{
inline LightComponent::LightComponent(nzLightType lightType) :
NzLight(lightType)
{
}
}

View File

@ -34,6 +34,7 @@ namespace Ndk
EntityList m_cameras;
EntityList m_drawables;
EntityList m_lights;
NzForwardRenderTechnique m_renderTechnique;
};
}

View File

@ -7,7 +7,7 @@
namespace Ndk
{
void GraphicsComponent::InvalidateRenderableData(const NzRenderable* renderable, nzUInt32 flags, unsigned int index)
void GraphicsComponent::InvalidateRenderableData(const NzInstancedRenderable* renderable, nzUInt32 flags, unsigned int index)
{
NazaraUnused(renderable);

View File

@ -0,0 +1,10 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/Components/LightComponent.hpp>
namespace Ndk
{
ComponentIndex LightComponent::componentIndex;
}

View File

@ -15,6 +15,7 @@
#include <NDK/BaseSystem.hpp>
#include <NDK/Components/CameraComponent.hpp>
#include <NDK/Components/CollisionComponent.hpp>
#include <NDK/Components/LightComponent.hpp>
#include <NDK/Components/ListenerComponent.hpp>
#include <NDK/Components/GraphicsComponent.hpp>
#include <NDK/Components/NodeComponent.hpp>
@ -57,6 +58,7 @@ namespace Ndk
// Composants
InitializeComponent<CameraComponent>("NdkCam");
InitializeComponent<CollisionComponent>("NdkColli");
InitializeComponent<LightComponent>("NdkLight");
InitializeComponent<ListenerComponent>("NdkList");
InitializeComponent<GraphicsComponent>("NdkGfx");
InitializeComponent<NodeComponent>("NdkNode");

View File

@ -6,6 +6,7 @@
#include <Nazara/Graphics/ColorBackground.hpp>
#include <NDK/Components/CameraComponent.hpp>
#include <NDK/Components/GraphicsComponent.hpp>
#include <NDK/Components/LightComponent.hpp>
#include <NDK/Components/NodeComponent.hpp>
namespace Ndk
@ -24,14 +25,22 @@ namespace Ndk
NzAbstractRenderQueue* renderQueue = m_renderTechnique.GetRenderQueue();
renderQueue->Clear();
for (const Ndk::EntityHandle& drawable : m_drawables)
for (const Ndk::EntityHandle& light : m_drawables)
{
GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>();
NodeComponent& drawableNode = drawable->GetComponent<NodeComponent>();
GraphicsComponent& graphicsComponent = light->GetComponent<GraphicsComponent>();
NodeComponent& drawableNode = light->GetComponent<NodeComponent>();
graphicsComponent.AddToRenderQueue(renderQueue);
}
for (const Ndk::EntityHandle& light : m_lights)
{
LightComponent& lightComponent = light->GetComponent<LightComponent>();
NodeComponent& drawableNode = light->GetComponent<NodeComponent>();
lightComponent.AddToRenderQueue(renderQueue, drawableNode.GetTransformMatrix());
}
NzColorBackground background;
NzSceneData sceneData;
@ -47,6 +56,7 @@ namespace Ndk
{
m_cameras.Remove(entity);
m_drawables.Remove(entity);
m_lights.Remove(entity);
}
void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded)
@ -67,6 +77,10 @@ namespace Ndk
else
m_drawables.Remove(entity);
if (entity->HasComponent<LightComponent>() && entity->HasComponent<NodeComponent>())
m_lights.Insert(entity);
else
m_lights.Remove(entity);
}
SystemIndex RenderSystem::systemIndex;

View File

@ -0,0 +1,82 @@
// Copyright (C) 2015 Jérôme Leclercq
// 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_INSTANCEDRENDERABLE_HPP
#define NAZARA_INSTANCEDRENDERABLE_HPP
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/PrimitiveList.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Math/BoundingVolume.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Math/Matrix4.hpp>
class NzAbstractRenderQueue;
class NzInstancedRenderable;
using NzInstancedRenderableConstRef = NzObjectRef<const NzInstancedRenderable>;
using NzInstancedRenderableLibrary = NzObjectLibrary<NzInstancedRenderable>;
using NzInstancedRenderableRef = NzObjectRef<NzInstancedRenderable>;
class NAZARA_GRAPHICS_API NzInstancedRenderable : public NzRefCounted
{
public:
struct InstanceData;
NzInstancedRenderable() = default;
inline NzInstancedRenderable(const NzInstancedRenderable& renderable);
virtual ~NzInstancedRenderable();
inline void EnsureBoundingVolumeUpdated() const;
virtual void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const InstanceData& instanceData) const = 0;
virtual bool Cull(const NzFrustumf& frustum, const InstanceData& instanceData) const;
virtual const NzBoundingVolumef& GetBoundingVolume() const;
virtual void InvalidateData(InstanceData* instanceData, nzUInt32 flags) const;
virtual void UpdateBoundingVolume(InstanceData* instanceData) const;
virtual void UpdateData(InstanceData* instanceData) const;
inline NzInstancedRenderable& operator=(const NzInstancedRenderable& renderable);
// Signals:
NazaraSignal(OnInstancedRenderableInvalidateData, const NzInstancedRenderable*, nzUInt32); //< Args: me, flags
NazaraSignal(OnInstancedRenderableRelease, const NzInstancedRenderable*); //< Args: me
struct InstanceData
{
InstanceData(NzMatrix4f& referenceMatrix) :
transformMatrix(referenceMatrix),
flags(0)
{
}
std::vector<nzUInt8> data;
NzBoundingVolumef volume;
NzMatrix4f& transformMatrix;
nzUInt32 flags;
};
protected:
virtual void MakeBoundingVolume() const = 0;
void InvalidateBoundingVolume();
inline void InvalidateInstanceData(nzUInt32 flags);
inline void UpdateBoundingVolume() const;
mutable NzBoundingVolumef m_boundingVolume;
private:
mutable bool m_boundingVolumeUpdated;
static NzInstancedRenderableLibrary::LibraryMap s_library;
};
#include <Nazara/Graphics/InstancedRenderable.inl>
#endif // NAZARA_INSTANCEDRENDERABLE_HPP

View File

@ -0,0 +1,39 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
inline NzInstancedRenderable::NzInstancedRenderable(const NzInstancedRenderable& renderable) :
m_boundingVolume(renderable.m_boundingVolume),
m_boundingVolumeUpdated(renderable.m_boundingVolumeUpdated)
{
}
inline void NzInstancedRenderable::EnsureBoundingVolumeUpdated() const
{
if (!m_boundingVolumeUpdated)
UpdateBoundingVolume();
}
inline void NzInstancedRenderable::InvalidateBoundingVolume()
{
m_boundingVolumeUpdated = false;
}
inline void NzInstancedRenderable::InvalidateInstanceData(nzUInt32 flags)
{
OnInstancedRenderableInvalidateData(this, flags);
}
inline NzInstancedRenderable& NzInstancedRenderable::operator=(const NzInstancedRenderable& renderable)
{
m_boundingVolume = renderable.m_boundingVolume;
m_boundingVolumeUpdated = renderable.m_boundingVolumeUpdated;
return *this;
}
inline void NzInstancedRenderable::UpdateBoundingVolume() const
{
MakeBoundingVolume();
m_boundingVolumeUpdated = true;
}

View File

@ -9,19 +9,12 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Graphics/Renderable.hpp>
class NzLight;
class NzShader;
struct NzLightUniforms;
using NzLightConstRef = NzObjectRef<const NzLight>;
using NzLightLibrary = NzObjectLibrary<NzLight>;
using NzLightRef = NzObjectRef<NzLight>;
class NAZARA_GRAPHICS_API NzLight : public NzRenderable
{
public:
@ -29,12 +22,12 @@ class NAZARA_GRAPHICS_API NzLight : public NzRenderable
NzLight(const NzLight& light) = default;
~NzLight() = default;
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const NzMatrix4f& transformMatrix) const override;
NzLight* Clone() const;
NzLight* Create() const;
bool Cull(const NzFrustumf& frustum, const InstanceData& instanceData) const override;
bool Cull(const NzFrustumf& frustum, const NzMatrix4f& transformMatrix) const override;
float GetAmbientFactor() const;
float GetAttenuation() const;
@ -58,12 +51,10 @@ class NAZARA_GRAPHICS_API NzLight : public NzRenderable
void SetOuterAngle(float outerAngle);
void SetRadius(float radius);
void UpdateBoundingVolume(InstanceData* instanceData) const;
void UpdateBoundingVolume(const NzMatrix4f& transformMatrix) override;
NzLight& operator=(const NzLight& light) = default;
template<typename... Args> static NzLightRef New(Args&&... args);
private:
void MakeBoundingVolume() const override;
@ -79,8 +70,6 @@ class NAZARA_GRAPHICS_API NzLight : public NzRenderable
float m_outerAngleCosine;
float m_outerAngleTangent;
float m_radius;
static NzLightLibrary::LibraryMap s_library;
};
struct NzLightUniforms

View File

@ -94,13 +94,4 @@ inline void NzLight::SetRadius(float radius)
InvalidateBoundingVolume();
}
template<typename... Args>
NzLightRef NzLight::New(Args&&... args)
{
std::unique_ptr<NzLight> object(new NzLight(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@ -11,7 +11,7 @@
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Graphics/Material.hpp>
#include <Nazara/Graphics/Renderable.hpp>
#include <Nazara/Graphics/InstancedRenderable.hpp>
#include <Nazara/Utility/Mesh.hpp>
struct NAZARA_GRAPHICS_API NzModelParameters
@ -31,7 +31,7 @@ using NzModelConstRef = NzObjectRef<const NzModel>;
using NzModelLoader = NzResourceLoader<NzModel, NzModelParameters>;
using NzModelRef = NzObjectRef<NzModel>;
class NAZARA_GRAPHICS_API NzModel : public NzRenderable, public NzResource
class NAZARA_GRAPHICS_API NzModel : public NzInstancedRenderable, public NzResource
{
friend NzModelLoader;
friend class NzScene;

View File

@ -9,9 +9,6 @@
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/PrimitiveList.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Math/BoundingVolume.hpp>
@ -19,62 +16,32 @@
#include <Nazara/Math/Matrix4.hpp>
class NzAbstractRenderQueue;
class NzRenderable;
using NzRenderableConstRef = NzObjectRef<const NzRenderable>;
using NzRenderableLibrary = NzObjectLibrary<NzRenderable>;
using NzRenderableRef = NzObjectRef<NzRenderable>;
class NAZARA_GRAPHICS_API NzRenderable : public NzRefCounted
class NAZARA_GRAPHICS_API NzRenderable
{
public:
struct InstanceData;
NzRenderable() = default;
inline NzRenderable(const NzRenderable& renderable);
NzRenderable(const NzRenderable& renderable) = default;
virtual ~NzRenderable();
inline void EnsureBoundingVolumeUpdated() const;
void EnsureBoundingVolumeUpdated() const;
virtual void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const InstanceData& instanceData) const = 0;
virtual bool Cull(const NzFrustumf& frustum, const InstanceData& instanceData) const;
virtual void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const NzMatrix4f& transformMatrix) const = 0;
virtual bool Cull(const NzFrustumf& frustum, const NzMatrix4f& transformMatrix) const = 0;
virtual const NzBoundingVolumef& GetBoundingVolume() const;
virtual void InvalidateData(InstanceData* instanceData, nzUInt32 flags) const;
virtual void UpdateBoundingVolume(InstanceData* instanceData) const;
virtual void UpdateData(InstanceData* instanceData) const;
virtual void UpdateBoundingVolume(const NzMatrix4f& transformMatrix);
inline NzRenderable& operator=(const NzRenderable& renderable);
// Signals:
NazaraSignal(OnRenderableInvalidateInstanceData, const NzRenderable*, nzUInt32); //< Args: me, flags
NazaraSignal(OnRenderableRelease, const NzRenderable*); //< Args: me
struct InstanceData
{
InstanceData(NzMatrix4f& referenceMatrix) :
transformMatrix(referenceMatrix),
flags(0)
{
}
std::vector<nzUInt8> data;
NzBoundingVolumef volume;
NzMatrix4f& transformMatrix;
nzUInt32 flags;
};
NzRenderable& operator=(const NzRenderable& renderable) = default;
protected:
virtual void MakeBoundingVolume() const = 0;
void InvalidateBoundingVolume();
inline void InvalidateInstanceData(nzUInt32 flags);
inline void UpdateBoundingVolume() const;
void UpdateBoundingVolume() const;
mutable NzBoundingVolumef m_boundingVolume;
private:
mutable bool m_boundingVolumeUpdated;
static NzRenderableLibrary::LibraryMap s_library;
};
#include <Nazara/Graphics/Renderable.inl>

View File

@ -2,12 +2,6 @@
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
inline NzRenderable::NzRenderable(const NzRenderable& renderable) :
m_boundingVolume(renderable.m_boundingVolume),
m_boundingVolumeUpdated(renderable.m_boundingVolumeUpdated)
{
}
inline void NzRenderable::EnsureBoundingVolumeUpdated() const
{
if (!m_boundingVolumeUpdated)
@ -19,19 +13,6 @@ inline void NzRenderable::InvalidateBoundingVolume()
m_boundingVolumeUpdated = false;
}
inline void NzRenderable::InvalidateInstanceData(nzUInt32 flags)
{
OnRenderableInvalidateInstanceData(this, flags);
}
inline NzRenderable& NzRenderable::operator=(const NzRenderable& renderable)
{
m_boundingVolume = renderable.m_boundingVolume;
m_boundingVolumeUpdated = renderable.m_boundingVolumeUpdated;
return *this;
}
inline void NzRenderable::UpdateBoundingVolume() const
{
MakeBoundingVolume();

View File

@ -9,7 +9,7 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/Material.hpp>
#include <Nazara/Graphics/Renderable.hpp>
#include <Nazara/Graphics/InstancedRenderable.hpp>
#include <Nazara/Utility/AbstractAtlas.hpp>
#include <Nazara/Utility/AbstractTextDrawer.hpp>
#include <Nazara/Utility/VertexStruct.hpp>
@ -22,7 +22,7 @@ using NzTextSpriteConstRef = NzObjectRef<const NzTextSprite>;
using NzTextSpriteLibrary = NzObjectLibrary<NzTextSprite>;
using NzTextSpriteRef = NzObjectRef<NzTextSprite>;
class NAZARA_GRAPHICS_API NzTextSprite : public NzRenderable
class NAZARA_GRAPHICS_API NzTextSprite : public NzInstancedRenderable
{
public:
NzTextSprite();

View File

@ -0,0 +1,43 @@
// Copyright (C) 2015 Jérôme Leclercq
// 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/InstancedRenderable.hpp>
#include <Nazara/Graphics/Debug.hpp>
NzInstancedRenderable::~NzInstancedRenderable()
{
OnInstancedRenderableRelease(this);
}
bool NzInstancedRenderable::Cull(const NzFrustumf& frustum, const InstanceData& instanceData) const
{
return frustum.Contains(instanceData.volume);
}
const NzBoundingVolumef& NzInstancedRenderable::GetBoundingVolume() const
{
EnsureBoundingVolumeUpdated();
return m_boundingVolume;
}
void NzInstancedRenderable::InvalidateData(InstanceData* instanceData, nzUInt32 flags) const
{
instanceData->flags |= flags;
}
void NzInstancedRenderable::UpdateBoundingVolume(InstanceData* instanceData) const
{
NazaraAssert(instanceData, "Invalid instance data");
NazaraUnused(instanceData);
instanceData->volume.Update(instanceData->transformMatrix);
}
void NzInstancedRenderable::UpdateData(InstanceData* instanceData) const
{
NazaraAssert(instanceData, "Invalid instance data");
}
NzInstancedRenderableLibrary::LibraryMap NzInstancedRenderable::s_library;

View File

@ -28,7 +28,7 @@ m_type(type)
SetRadius(5.f);
}
void NzLight::AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const InstanceData& instanceData) const
void NzLight::AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const NzMatrix4f& transformMatrix) const
{
switch (m_type)
{
@ -38,7 +38,7 @@ void NzLight::AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const Instanc
light.ambientFactor = m_ambientFactor;
light.color = m_color;
light.diffuseFactor = m_diffuseFactor;
light.direction = instanceData.transformMatrix.Transform(NzVector3f::Forward(), 0.f);
light.direction = transformMatrix.Transform(NzVector3f::Forward(), 0.f);
renderQueue->AddDirectionalLight(light);
break;
@ -52,7 +52,7 @@ void NzLight::AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const Instanc
light.color = m_color;
light.diffuseFactor = m_diffuseFactor;
light.invRadius = m_invRadius;
light.position = instanceData.transformMatrix.GetTranslation();
light.position = transformMatrix.GetTranslation();
light.radius = m_radius;
renderQueue->AddPointLight(light);
@ -66,12 +66,12 @@ void NzLight::AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const Instanc
light.attenuation = m_attenuation;
light.color = m_color;
light.diffuseFactor = m_diffuseFactor;
light.direction = instanceData.transformMatrix.Transform(NzVector3f::Forward(), 0.f);
light.direction = transformMatrix.Transform(NzVector3f::Forward(), 0.f);
light.innerAngleCosine = m_innerAngleCosine;
light.invRadius = m_invRadius;
light.outerAngleCosine = m_outerAngleCosine;
light.outerAngleTangent = m_outerAngleTangent;
light.position = instanceData.transformMatrix.GetTranslation();
light.position = transformMatrix.GetTranslation();
light.radius = m_radius;
renderQueue->AddSpotLight(light);
@ -94,7 +94,7 @@ NzLight* NzLight::Create() const
return new NzLight;
}
bool NzLight::Cull(const NzFrustumf& frustum, const InstanceData& instanceData) const
bool NzLight::Cull(const NzFrustumf& frustum, const NzMatrix4f& transformMatrix) const
{
switch (m_type)
{
@ -102,31 +102,29 @@ bool NzLight::Cull(const NzFrustumf& frustum, const InstanceData& instanceData)
return true; // Always visible
case nzLightType_Point:
return frustum.Contains(NzSpheref(instanceData.transformMatrix.GetTranslation(), m_radius)); // A sphere test is much faster (and precise)
return frustum.Contains(NzSpheref(transformMatrix.GetTranslation(), m_radius)); // A sphere test is much faster (and precise)
case nzLightType_Spot:
return frustum.Contains(instanceData.volume);
return frustum.Contains(m_boundingVolume);
}
NazaraError("Invalid light type (0x" + NzString::Number(m_type, 16) + ')');
return false;
}
void NzLight::UpdateBoundingVolume(InstanceData* instanceData) const
void NzLight::UpdateBoundingVolume(const NzMatrix4f& transformMatrix)
{
NazaraAssert(instanceData, "Invalid data");
switch (m_type)
{
case nzLightType_Directional:
break; // Nothing to do (bounding volume should be infinite)
case nzLightType_Point:
instanceData->volume.Update(instanceData->transformMatrix.GetTranslation()); // The bounding volume only needs to be shifted
m_boundingVolume.Update(transformMatrix.GetTranslation()); // The bounding volume only needs to be shifted
break;
case nzLightType_Spot:
instanceData->volume.Update(instanceData->transformMatrix);
m_boundingVolume.Update(transformMatrix);
break;
default:
@ -179,5 +177,3 @@ void NzLight::MakeBoundingVolume() const
break;
}
}
NzLightLibrary::LibraryMap NzLight::s_library;

View File

@ -5,14 +5,13 @@
#include <Nazara/Graphics/Renderable.hpp>
#include <Nazara/Graphics/Debug.hpp>
NzRenderable::~NzRenderable()
{
OnRenderableRelease(this);
}
NzRenderable::~NzRenderable() = default;
bool NzRenderable::Cull(const NzFrustumf& frustum, const InstanceData& instanceData) const
bool NzRenderable::Cull(const NzFrustumf& frustum, const NzMatrix4f& transformMatrix) const
{
return frustum.Contains(instanceData.volume);
NazaraUnused(transformMatrix);
return frustum.Contains(m_boundingVolume);
}
const NzBoundingVolumef& NzRenderable::GetBoundingVolume() const
@ -22,22 +21,7 @@ const NzBoundingVolumef& NzRenderable::GetBoundingVolume() const
return m_boundingVolume;
}
void NzRenderable::InvalidateData(InstanceData* instanceData, nzUInt32 flags) const
void NzRenderable::UpdateBoundingVolume(const NzMatrix4f& transformMatrix)
{
instanceData->flags |= flags;
m_boundingVolume.Update(transformMatrix);
}
void NzRenderable::UpdateBoundingVolume(InstanceData* instanceData) const
{
NazaraAssert(instanceData, "Invalid instance data");
NazaraUnused(instanceData);
instanceData->volume.Update(instanceData->transformMatrix);
}
void NzRenderable::UpdateData(InstanceData* instanceData) const
{
NazaraAssert(instanceData, "Invalid instance data");
}
NzRenderableLibrary::LibraryMap NzRenderable::s_library;

View File

@ -19,7 +19,7 @@ m_scale(1.f)
}
NzTextSprite::NzTextSprite(const NzTextSprite& sprite) :
NzRenderable(sprite),
NzInstancedRenderable(sprite),
m_renderInfos(sprite.m_renderInfos),
m_localVertices(sprite.m_localVertices),
m_color(sprite.m_color),
@ -88,7 +88,7 @@ float NzTextSprite::GetScale() const
void NzTextSprite::InvalidateVertices()
{
OnRenderableInvalidateInstanceData(this, 0);
InvalidateInstanceData(0);
}
bool NzTextSprite::IsDrawable() const
@ -245,7 +245,7 @@ void NzTextSprite::Update(const NzAbstractTextDrawer& drawer)
NzTextSprite& NzTextSprite::operator=(const NzTextSprite& text)
{
NzRenderable::operator=(text);
NzInstancedRenderable::operator=(text);
m_atlases.clear();