Merge branch 'NDK' into NDK-ShadowMapping
Conflicts: SDK/include/NDK/Systems/RenderSystem.hpp SDK/src/NDK/Systems/RenderSystem.cpp Former-commit-id: 2772ff703c9d68d536667c469aca85084be4b861
This commit is contained in:
@@ -40,6 +40,7 @@ namespace Ndk
|
||||
inline const NzFrustumf& GetFrustum() const;
|
||||
inline unsigned int GetLayer() const;
|
||||
inline const NzMatrix4f& GetProjectionMatrix() const;
|
||||
inline nzProjectionType GetProjectionType() const;
|
||||
inline const NzRenderTarget* GetTarget() const;
|
||||
inline const NzRectf& GetTargetRegion() const;
|
||||
inline const NzMatrix4f& GetViewMatrix() const;
|
||||
@@ -49,6 +50,7 @@ namespace Ndk
|
||||
|
||||
inline void SetFOV(float fov);
|
||||
inline void SetLayer(unsigned int layer);
|
||||
inline void SetProjectionType(nzProjectionType projection);
|
||||
inline void SetTarget(const NzRenderTarget* renderTarget);
|
||||
inline void SetTargetRegion(const NzRectf& region);
|
||||
inline void SetViewport(const NzRecti& viewport);
|
||||
@@ -80,6 +82,7 @@ namespace Ndk
|
||||
NazaraSlot(NzRenderTarget, OnRenderTargetRelease, m_targetReleaseSlot);
|
||||
NazaraSlot(NzRenderTarget, OnRenderTargetSizeChange, m_targetResizeSlot);
|
||||
|
||||
nzProjectionType m_projectionType;
|
||||
mutable NzFrustumf m_frustum;
|
||||
mutable NzMatrix4f m_projectionMatrix;
|
||||
mutable NzMatrix4f m_viewMatrix;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
namespace Ndk
|
||||
{
|
||||
inline CameraComponent::CameraComponent() :
|
||||
m_projectionType(nzProjectionType_Perspective),
|
||||
m_targetRegion(0.f, 0.f, 1.f, 1.f),
|
||||
m_target(nullptr),
|
||||
m_frustumUpdated(false),
|
||||
@@ -25,8 +26,9 @@ namespace Ndk
|
||||
inline CameraComponent::CameraComponent(const CameraComponent& camera) :
|
||||
Component(camera),
|
||||
NzAbstractViewer(camera),
|
||||
m_projectionType(camera.m_projectionType),
|
||||
m_targetRegion(camera.m_targetRegion),
|
||||
m_target(camera.m_target),
|
||||
m_target(nullptr),
|
||||
m_frustumUpdated(false),
|
||||
m_projectionMatrixUpdated(false),
|
||||
m_viewMatrixUpdated(false),
|
||||
@@ -37,7 +39,7 @@ namespace Ndk
|
||||
m_zNear(camera.m_zNear),
|
||||
m_layer(camera.m_layer)
|
||||
{
|
||||
|
||||
SetTarget(camera.m_target);
|
||||
}
|
||||
|
||||
inline void CameraComponent::EnsureFrustumUpdate() const
|
||||
@@ -95,6 +97,11 @@ namespace Ndk
|
||||
return m_projectionMatrix;
|
||||
}
|
||||
|
||||
inline nzProjectionType CameraComponent::GetProjectionType() const
|
||||
{
|
||||
return m_projectionType;
|
||||
}
|
||||
|
||||
inline const NzRenderTarget* CameraComponent::GetTarget() const
|
||||
{
|
||||
return m_target;
|
||||
@@ -132,8 +139,15 @@ namespace Ndk
|
||||
inline void CameraComponent::SetFOV(float fov)
|
||||
{
|
||||
NazaraAssert(!NzNumberEquals(fov, 0.f), "FOV must be different from zero");
|
||||
|
||||
m_fov = fov;
|
||||
|
||||
InvalidateProjectionMatrix();
|
||||
}
|
||||
|
||||
inline void CameraComponent::SetProjectionType(nzProjectionType projectionType)
|
||||
{
|
||||
m_projectionType = projectionType;
|
||||
|
||||
InvalidateProjectionMatrix();
|
||||
}
|
||||
|
||||
@@ -149,6 +163,7 @@ namespace Ndk
|
||||
inline void CameraComponent::SetTargetRegion(const NzRectf& region)
|
||||
{
|
||||
m_targetRegion = region;
|
||||
|
||||
InvalidateViewport();
|
||||
}
|
||||
|
||||
@@ -166,14 +181,15 @@ namespace Ndk
|
||||
inline void CameraComponent::SetZFar(float zFar)
|
||||
{
|
||||
m_zFar = zFar;
|
||||
|
||||
InvalidateProjectionMatrix();
|
||||
}
|
||||
|
||||
inline void CameraComponent::SetZNear(float zNear)
|
||||
{
|
||||
NazaraAssert(!NzNumberEquals(zNear, 0.f), "zNear cannot be zero");
|
||||
|
||||
m_zNear = zNear;
|
||||
|
||||
InvalidateProjectionMatrix();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ namespace Ndk
|
||||
{
|
||||
class NDK_API GraphicsComponent : public Component<GraphicsComponent>
|
||||
{
|
||||
friend class RenderSystem;
|
||||
|
||||
public:
|
||||
GraphicsComponent() = default;
|
||||
inline GraphicsComponent(const GraphicsComponent& graphicsComponent);
|
||||
@@ -30,6 +32,7 @@ namespace Ndk
|
||||
|
||||
private:
|
||||
void InvalidateRenderableData(const NzInstancedRenderable* renderable, nzUInt32 flags, unsigned int index);
|
||||
inline void InvalidateRenderables();
|
||||
inline void InvalidateTransformMatrix();
|
||||
|
||||
void OnAttached() override;
|
||||
|
||||
@@ -46,11 +46,16 @@ namespace Ndk
|
||||
UpdateTransformMatrix();
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::InvalidateTransformMatrix()
|
||||
inline void GraphicsComponent::InvalidateRenderables()
|
||||
{
|
||||
for (Renderable& r : m_renderables)
|
||||
r.dataUpdated = false;
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::InvalidateTransformMatrix()
|
||||
{
|
||||
m_transformMatrixUpdated = false;
|
||||
|
||||
InvalidateRenderables();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ namespace Ndk
|
||||
|
||||
EntityHandle& Swap(EntityHandle& handle);
|
||||
|
||||
NzString ToString() const;
|
||||
|
||||
operator bool() const;
|
||||
operator Entity*() const;
|
||||
Entity* operator->() const;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
|
||||
@@ -89,6 +90,20 @@ namespace Ndk
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline NzString EntityHandle::ToString() const
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << "EntityHandle(";
|
||||
if (IsValid())
|
||||
ss << "Entity(" << m_entity->GetId() << ')';
|
||||
else
|
||||
ss << "Null entity";
|
||||
|
||||
ss << ')';
|
||||
|
||||
return ss;
|
||||
}
|
||||
|
||||
inline EntityHandle::operator bool() const
|
||||
{
|
||||
return IsValid();
|
||||
@@ -143,7 +158,7 @@ namespace Ndk
|
||||
{
|
||||
out << "EntityHandle(";
|
||||
if (handle.IsValid())
|
||||
out << "Entity(" << handle->GetId() << ")";
|
||||
out << "Entity(" << handle->GetId() << ')';
|
||||
else
|
||||
out << "Null entity";
|
||||
|
||||
|
||||
@@ -28,12 +28,21 @@ namespace Ndk
|
||||
~RenderSystem() = default;
|
||||
|
||||
inline const NzBackgroundRef& GetDefaultBackground() const;
|
||||
inline const NzMatrix4f& GetCoordinateSystemMatrix() const;
|
||||
inline NzVector3f GetGlobalForward() const;
|
||||
inline NzVector3f GetGlobalRight() const;
|
||||
inline NzVector3f GetGlobalUp() const;
|
||||
|
||||
inline void SetDefaultBackground(NzBackgroundRef background);
|
||||
inline void SetGlobalForward(const NzVector3f& direction);
|
||||
inline void SetGlobalRight(const NzVector3f& direction);
|
||||
inline void SetGlobalUp(const NzVector3f& direction);
|
||||
|
||||
static SystemIndex systemIndex;
|
||||
|
||||
private:
|
||||
inline void InvalidateCoordinateSystem();
|
||||
|
||||
void OnEntityRemoved(Entity* entity) override;
|
||||
void OnEntityValidation(Entity* entity, bool justAdded) override;
|
||||
void OnUpdate(float elapsedTime) override;
|
||||
@@ -48,7 +57,9 @@ namespace Ndk
|
||||
NzBackgroundRef m_background;
|
||||
NzDepthRenderTechnique m_shadowTechnique;
|
||||
NzForwardRenderTechnique m_renderTechnique;
|
||||
NzMatrix4f m_coordinateSystemMatrix;
|
||||
NzRenderTexture m_shadowRT;
|
||||
bool m_coordinateSystemInvalidated;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,60 @@ namespace Ndk
|
||||
return m_background;
|
||||
}
|
||||
|
||||
inline const NzMatrix4f& RenderSystem::GetCoordinateSystemMatrix() const
|
||||
{
|
||||
return m_coordinateSystemMatrix;
|
||||
}
|
||||
|
||||
inline NzVector3f RenderSystem::GetGlobalForward() const
|
||||
{
|
||||
return NzVector3f(-m_coordinateSystemMatrix.m13, -m_coordinateSystemMatrix.m23, -m_coordinateSystemMatrix.m33);
|
||||
}
|
||||
|
||||
inline NzVector3f RenderSystem::GetGlobalRight() const
|
||||
{
|
||||
return NzVector3f(m_coordinateSystemMatrix.m11, m_coordinateSystemMatrix.m21, m_coordinateSystemMatrix.m31);
|
||||
}
|
||||
|
||||
inline NzVector3f RenderSystem::GetGlobalUp() const
|
||||
{
|
||||
return NzVector3f(m_coordinateSystemMatrix.m12, m_coordinateSystemMatrix.m22, m_coordinateSystemMatrix.m32);
|
||||
}
|
||||
|
||||
inline void RenderSystem::SetDefaultBackground(NzBackgroundRef background)
|
||||
{
|
||||
m_background = std::move(background);
|
||||
}
|
||||
|
||||
inline void RenderSystem::SetGlobalForward(const NzVector3f& direction)
|
||||
{
|
||||
m_coordinateSystemMatrix.m13 = -direction.x;
|
||||
m_coordinateSystemMatrix.m23 = -direction.y;
|
||||
m_coordinateSystemMatrix.m33 = -direction.z;
|
||||
|
||||
InvalidateCoordinateSystem();
|
||||
}
|
||||
|
||||
inline void RenderSystem::SetGlobalRight(const NzVector3f& direction)
|
||||
{
|
||||
m_coordinateSystemMatrix.m11 = direction.x;
|
||||
m_coordinateSystemMatrix.m21 = direction.y;
|
||||
m_coordinateSystemMatrix.m31 = direction.z;
|
||||
|
||||
InvalidateCoordinateSystem();
|
||||
}
|
||||
|
||||
inline void RenderSystem::SetGlobalUp(const NzVector3f& direction)
|
||||
{
|
||||
m_coordinateSystemMatrix.m12 = direction.x;
|
||||
m_coordinateSystemMatrix.m22 = direction.y;
|
||||
m_coordinateSystemMatrix.m32 = direction.z;
|
||||
|
||||
InvalidateCoordinateSystem();
|
||||
}
|
||||
|
||||
inline void RenderSystem::InvalidateCoordinateSystem()
|
||||
{
|
||||
m_coordinateSystemInvalidated = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user