Graphics: Remove deprecated scene interface

Former-commit-id: 6b5d3c22827912d664c4f8c9c4051c824180bb51
This commit is contained in:
Lynix 2015-06-24 13:55:35 +02:00
parent 58f91d6e39
commit a4bd84a6e3
25 changed files with 2 additions and 2163 deletions

View File

@ -33,7 +33,6 @@
#include <Nazara/Graphics/AbstractRenderQueue.hpp> #include <Nazara/Graphics/AbstractRenderQueue.hpp>
#include <Nazara/Graphics/AbstractRenderTechnique.hpp> #include <Nazara/Graphics/AbstractRenderTechnique.hpp>
#include <Nazara/Graphics/AbstractViewer.hpp> #include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Graphics/Camera.hpp>
#include <Nazara/Graphics/ColorBackground.hpp> #include <Nazara/Graphics/ColorBackground.hpp>
#include <Nazara/Graphics/Config.hpp> #include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/DeferredBloomPass.hpp> #include <Nazara/Graphics/DeferredBloomPass.hpp>
@ -65,15 +64,11 @@
#include <Nazara/Graphics/ParticleStruct.hpp> #include <Nazara/Graphics/ParticleStruct.hpp>
#include <Nazara/Graphics/ParticleSystem.hpp> #include <Nazara/Graphics/ParticleSystem.hpp>
#include <Nazara/Graphics/RenderTechniques.hpp> #include <Nazara/Graphics/RenderTechniques.hpp>
#include <Nazara/Graphics/Scene.hpp>
#include <Nazara/Graphics/SceneNode.hpp>
#include <Nazara/Graphics/SceneRoot.hpp>
#include <Nazara/Graphics/SkeletalModel.hpp> #include <Nazara/Graphics/SkeletalModel.hpp>
#include <Nazara/Graphics/SkinningManager.hpp> #include <Nazara/Graphics/SkinningManager.hpp>
#include <Nazara/Graphics/SkyboxBackground.hpp> #include <Nazara/Graphics/SkyboxBackground.hpp>
#include <Nazara/Graphics/Sprite.hpp> #include <Nazara/Graphics/Sprite.hpp>
#include <Nazara/Graphics/TextSprite.hpp> #include <Nazara/Graphics/TextSprite.hpp>
#include <Nazara/Graphics/TextureBackground.hpp> #include <Nazara/Graphics/TextureBackground.hpp>
#include <Nazara/Graphics/View.hpp>
#endif // NAZARA_GLOBAL_GRAPHICS_HPP #endif // NAZARA_GLOBAL_GRAPHICS_HPP

View File

@ -1,85 +0,0 @@
// 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_CAMERA_HPP
#define NAZARA_CAMERA_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Utility/Node.hpp>
class NAZARA_GRAPHICS_API NzCamera : public NzAbstractViewer, public NzNode
{
public:
NzCamera();
~NzCamera() = default;
void EnsureFrustumUpdate() const;
void EnsureProjectionMatrixUpdate() const;
void EnsureViewMatrixUpdate() const;
void EnsureViewportUpdate() const;
float GetAspectRatio() const;
NzVector3f GetEyePosition() const;
NzVector3f GetForward() const;
float GetFOV() const;
const NzFrustumf& GetFrustum() const;
NzVector3f GetGlobalForward() const;
NzVector3f GetGlobalRight() const;
NzVector3f GetGlobalUp() const;
const NzMatrix4f& GetProjectionMatrix() const;
const NzRenderTarget* GetTarget() const;
const NzRectf& GetTargetRegion() const;
const NzMatrix4f& GetViewMatrix() const;
const NzRecti& GetViewport() const;
float GetZFar() const;
float GetZNear() const;
void SetFOV(float fov);
void SetTarget(const NzRenderTarget* renderTarget);
void SetTarget(const NzRenderTarget& renderTarget);
void SetTargetRegion(const NzRectf& region);
void SetViewport(const NzRecti& viewport);
void SetZFar(float zFar);
void SetZNear(float zNear);
private:
void ApplyView() const override;
void InvalidateNode() override;
void OnRenderTargetRelease(const NzRenderTarget* renderTarget);
void OnRenderTargetSizeChange(const NzRenderTarget* renderTarget);
void UpdateFrustum() const;
void UpdateProjectionMatrix() const;
void UpdateViewMatrix() const;
void UpdateViewport() const;
NazaraSlot(NzRenderTarget, OnRenderTargetRelease, m_targetReleaseSlot);
NazaraSlot(NzRenderTarget, OnRenderTargetSizeChange, m_targetResizeSlot);
mutable NzFrustumf m_frustum;
mutable NzMatrix4f m_projectionMatrix;
mutable NzMatrix4f m_viewMatrix;
NzRectf m_targetRegion;
mutable NzRecti m_viewport;
const NzRenderTarget* m_target;
mutable bool m_frustumUpdated;
mutable bool m_projectionMatrixUpdated;
mutable bool m_viewMatrixUpdated;
mutable bool m_viewportUpdated;
mutable float m_aspectRatio;
float m_fov;
float m_zFar;
float m_zNear;
};
#endif // NAZARA_CAMERA_HPP

View File

@ -1,117 +0,0 @@
// 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_SCENE_HPP
#define NAZARA_SCENE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Core/Updatable.hpp>
#include <Nazara/Graphics/AbstractBackground.hpp>
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
#include <Nazara/Graphics/SceneRoot.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <memory>
#include <unordered_map>
#include <vector>
class NzAbstractRenderQueue;
class NzAbstractViewer;
class NzNode;
class NzSceneNode;
class NAZARA_GRAPHICS_API NzScene
{
friend NzSceneNode;
public:
NzScene();
~NzScene() = default;
void AddToVisibilityList(NzUpdatable* object);
template<typename T, typename... Args> T* CreateNode(Args&&... args);
template<typename T, typename... Args> T* CreateNode(const NzString& name, Args&&... args);
template<typename T, typename... Args> T* CreateNode(const NzString& name, const NzString& templateNodeName);
void Clear();
void Cull();
void Draw();
void EnableBackground(bool enable);
NzSceneNode* FindNode(const NzString& name);
const NzSceneNode* FindNode(const NzString& name) const;
template<typename T> T* FindNodeAs(const NzString& name);
template<typename T> const T* FindNodeAs(const NzString& name) const;
NzColor GetAmbientColor() const;
NzAbstractBackground* GetBackground() const;
NzVector3f GetBackward() const;
NzVector3f GetDown() const;
NzVector3f GetForward() const;
NzVector3f GetLeft() const;
NzAbstractRenderTechnique* GetRenderTechnique() const;
NzVector3f GetRight() const;
NzSceneNode& GetRoot();
const NzSceneNode& GetRoot() const;
NzAbstractViewer* GetViewer() const;
NzVector3f GetUp() const;
float GetUpdateTime() const;
unsigned int GetUpdatePerSecond() const;
bool IsBackgroundEnabled() const;
void RegisterForUpdate(NzUpdatable* object);
void RemoveNode(NzSceneNode* node);
void RemoveNode(const NzString& name);
void RenderFrame();
void SetAmbientColor(const NzColor& color);
void SetBackground(NzAbstractBackground* background);
void SetRenderTechnique(NzAbstractRenderTechnique* renderTechnique);
void SetViewer(NzAbstractViewer* viewer);
void SetViewer(NzAbstractViewer& viewer);
void SetUpdatePerSecond(unsigned int updatePerSecond);
void UnregisterForUpdate(NzUpdatable* object);
void Update();
void UpdateVisible();
operator const NzSceneNode&() const;
private:
bool ChangeNodeName(NzSceneNode* node, const NzString& newName);
bool RegisterSceneNode(const NzString& name, NzSceneNode* node);
void RecursiveFrustumCull(NzAbstractRenderQueue* renderQueue, const NzFrustumf& frustum, NzNode* node);
mutable std::unique_ptr<NzAbstractBackground> m_background;
mutable std::unique_ptr<NzAbstractRenderTechnique> m_renderTechnique;
std::unordered_map<NzString, NzSceneNode*> m_nodeMap;
std::vector<std::unique_ptr<NzSceneNode>> m_nodes;
std::vector<NzUpdatable*> m_updateList;
std::vector<NzUpdatable*> m_visibleUpdateList;
NzClock m_updateClock;
NzColor m_ambientColor;
NzSceneRoot m_root;
NzAbstractViewer* m_viewer;
bool m_backgroundEnabled;
bool m_update;
float m_frameTime;
float m_updateTime;
mutable int m_renderTechniqueRanking;
unsigned int m_updatePerSecond;
};
#include <Nazara/Graphics/Scene.inl>
#endif // NAZARA_SCENE_HPP

View File

@ -1,139 +0,0 @@
// 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/Enums.hpp>
#include <Nazara/Graphics/Debug.hpp>
///TODO: Déplacer vers SceneNode et exposer
// Pour être sûr que ce code soit à jour
static_assert(nzSceneNodeType_Max == 6, "Please update the code below");
class NzLight;
class NzModel;
class NzParticleEmitter;
class NzSceneRoot;
class NzSprite;
class NzTextSprite;
template<typename T>
constexpr nzSceneNodeType NzImplGetType()
{
return nzSceneNodeType_User;
}
template<>
inline constexpr nzSceneNodeType NzImplGetType<NzLight>()
{
return nzSceneNodeType_Light;
}
template<>
inline constexpr nzSceneNodeType NzImplGetType<NzModel>()
{
return nzSceneNodeType_Model;
}
template<>
inline constexpr nzSceneNodeType NzImplGetType<NzParticleEmitter>()
{
return nzSceneNodeType_ParticleEmitter;
}
template<>
inline constexpr nzSceneNodeType NzImplGetType<NzSceneRoot>()
{
return nzSceneNodeType_Root;
}
template<>
inline constexpr nzSceneNodeType NzImplGetType<NzSprite>()
{
return nzSceneNodeType_Sprite;
}
template<>
inline constexpr nzSceneNodeType NzImplGetType<NzTextSprite>()
{
return nzSceneNodeType_TextSprite;
}
template<typename T, typename... Args>
T* NzScene::CreateNode(Args&&... args)
{
std::unique_ptr<T> node(new T(std::forward<Args>(args)...));
if (!RegisterSceneNode(NzString(), node.get()))
return nullptr;
return node.release();
}
template<typename T, typename... Args>
T* NzScene::CreateNode(const NzString& name, Args&&... args)
{
std::unique_ptr<T> node(new T(std::forward<Args>(args)...));
if (!RegisterSceneNode(name, node.get()))
return nullptr;
return node.release();
}
template<typename T, typename... Args>
T* NzScene::CreateNode(const NzString& name, const NzString& templateNodeName)
{
auto it = m_nodeMap.find(templateNodeName);
if (it == m_nodeMap.end())
{
NazaraError("Node \"" + templateNodeName + "\" is not registred");
return nullptr;
}
NzSceneNode* sceneNode = it->second;
if (sceneNode->GetSceneNodeType() != NzImplGetType<T>())
{
NazaraError("Scene node type of T (" + NzString::Number(NzImplGetType<T>()) + ") doesn't match template scene node type (" + NzString::Number(sceneNode->GetSceneNodeType()) + ")");
return nullptr;
}
std::unique_ptr<T> node(static_cast<T*>(sceneNode)->Copy());
if (!RegisterSceneNode(name, node.get()))
return nullptr;
return node.release();
}
template<typename T>
T* NzScene::FindNodeAs(const NzString& name)
{
NzSceneNode* sceneNode = FindNode(name);
if (!sceneNode)
return nullptr;
if (sceneNode->GetSceneNodeType() != NzImplGetType<T>())
{
NazaraError("Scene node type of T (" + NzString::Number(NzImplGetType<T>()) + ") doesn't match \"" + name + "\" scene node type (" + NzString::Number(sceneNode->GetSceneNodeType()) + ")");
return nullptr;
}
return static_cast<T*>(sceneNode);
}
template<typename T>
const T* NzScene::FindNodeAs(const NzString& name) const
{
const NzSceneNode* sceneNode = FindNode(name);
if (!sceneNode)
return nullptr;
if (sceneNode->GetSceneNodeType() != NzImplGetType<T>())
{
NazaraError("Scene node type of T (" + NzString::Number(NzImplGetType<T>()) + ") doesn't match \"" + name + "\" scene node type (" + NzString::Number(sceneNode->GetSceneNodeType()) + ")");
return nullptr;
}
return static_cast<const T*>(sceneNode);
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@ -1,89 +0,0 @@
// 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_SCENENODE_HPP
#define NAZARA_SCENENODE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Math/BoundingVolume.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Utility/Node.hpp>
class NzAbstractRenderQueue;
class NzScene;
class NAZARA_GRAPHICS_API NzSceneNode : public NzNode
{
friend NzScene;
public:
NzSceneNode();
NzSceneNode(const NzSceneNode& sceneNode);
NzSceneNode(NzSceneNode&& sceneNode) = delete;
virtual ~NzSceneNode();
virtual void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const = 0;
// Idiôme "virtual constructor"
virtual NzSceneNode* Clone() const = 0;
virtual NzSceneNode* Create() const = 0;
void EnableDrawing(bool drawingEnabled);
NzVector3f GetBackward() const;
virtual const NzBoundingVolumef& GetBoundingVolume() const;
NzVector3f GetDown() const;
NzVector3f GetForward() const;
NzVector3f GetLeft() const;
const NzString& GetName() const;
nzNodeType GetNodeType() const final;
NzVector3f GetRight() const;
NzScene* GetScene() const;
virtual nzSceneNodeType GetSceneNodeType() const = 0;
NzVector3f GetUp() const;
void InvalidateAABB();
virtual bool IsDrawable() const = 0;
bool IsDrawingEnabled() const;
bool IsVisible() const;
void Remove();
bool SetName(const NzString& name);
NzSceneNode& operator=(const NzSceneNode& sceneNode);
NzSceneNode& operator=(NzSceneNode&& sceneNode) = delete;
protected:
virtual bool FrustumCull(const NzFrustumf& frustum) const;
virtual void InvalidateNode() override;
virtual void MakeBoundingVolume() const = 0;
virtual void OnParenting(const NzNode* parent) override;
virtual void OnVisibilityChange(bool visibility);
void RecursiveSetScene(NzScene* scene, NzNode* node);
virtual void Register();
void SetNameInternal(const NzString& name);
void SetScene(NzScene* scene);
virtual void Unregister();
virtual void Update();
virtual void UpdateBoundingVolume() const;
mutable NzBoundingVolumef m_boundingVolume;
NzScene* m_scene;
mutable bool m_boundingVolumeUpdated;
bool m_drawingEnabled;
bool m_visible;
private:
void UpdateVisibility(const NzFrustumf& frustum);
NzString m_name;
};
#endif // NAZARA_SCENENODE_HPP

View File

@ -1,38 +0,0 @@
// 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_SCENEROOT_HPP
#define NAZARA_SCENEROOT_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/SceneNode.hpp>
class NzScene;
class NAZARA_GRAPHICS_API NzSceneRoot : public NzSceneNode
{
friend NzScene;
public:
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
nzSceneNodeType GetSceneNodeType() const override;
bool IsDrawable() const;
private:
NzSceneRoot(NzScene* scene);
virtual ~NzSceneRoot();
NzSceneRoot* Clone() const;
NzSceneRoot* Create() const;
void MakeBoundingVolume() const override;
void Register();
void Unregister();
};
#endif // NAZARA_SCENEROOT_HPP

View File

@ -10,7 +10,6 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/InstancedRenderable.hpp> #include <Nazara/Graphics/InstancedRenderable.hpp>
#include <Nazara/Graphics/Material.hpp> #include <Nazara/Graphics/Material.hpp>
#include <Nazara/Graphics/SceneNode.hpp>
#include <Nazara/Utility/VertexStruct.hpp> #include <Nazara/Utility/VertexStruct.hpp>
#include <array> #include <array>

View File

@ -1,97 +0,0 @@
// 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_VIEW_HPP
#define NAZARA_VIEW_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Utility/Node.hpp>
class NAZARA_GRAPHICS_API NzView : public NzAbstractViewer, public NzNode
{
public:
NzView();
NzView(const NzVector2f& size);
~NzView() = default;
void EnsureFrustumUpdate() const;
void EnsureProjectionMatrixUpdate() const;
void EnsureViewMatrixUpdate() const;
void EnsureViewportUpdate() const;
float GetAspectRatio() const;
NzVector3f GetEyePosition() const;
NzVector3f GetForward() const;
const NzFrustumf& GetFrustum() const;
NzVector3f GetGlobalForward() const;
NzVector3f GetGlobalRight() const;
NzVector3f GetGlobalUp() const;
const NzMatrix4f& GetInvViewProjMatrix() const;
const NzMatrix4f& GetProjectionMatrix() const;
const NzVector2f& GetSize() const;
const NzRenderTarget* GetTarget() const;
const NzRectf& GetTargetRegion() const;
const NzMatrix4f& GetViewMatrix() const;
const NzMatrix4f& GetViewProjMatrix() const;
const NzRecti& GetViewport() const;
float GetZFar() const;
float GetZNear() const;
NzVector2f MapPixelToWorld(const NzVector2i& pixel);
NzVector2i MapWorldToPixel(const NzVector2f& coords);
void SetSize(const NzVector2f& size);
void SetSize(float width, float height);
void SetTarget(const NzRenderTarget* renderTarget);
void SetTarget(const NzRenderTarget& renderTarget);
void SetTargetRegion(const NzRectf& region);
void SetViewport(const NzRecti& viewport);
void SetZFar(float zFar);
void SetZNear(float zNear);
private:
void ApplyView() const override;
void InvalidateNode() override;
void OnRenderTargetRelease(const NzRenderTarget* renderTarget);
void OnRenderTargetSizeChange(const NzRenderTarget* renderTarget);
void UpdateFrustum() const;
void UpdateInvViewProjMatrix() const;
void UpdateProjectionMatrix() const;
void UpdateViewMatrix() const;
void UpdateViewProjMatrix() const;
void UpdateViewport() const;
NazaraSlot(NzRenderTarget, OnRenderTargetRelease, m_targetReleaseSlot);
NazaraSlot(NzRenderTarget, OnRenderTargetSizeChange, m_targetResizeSlot);
mutable NzFrustumf m_frustum;
mutable NzMatrix4f m_invViewProjMatrix;
mutable NzMatrix4f m_projectionMatrix;
mutable NzMatrix4f m_viewMatrix;
mutable NzMatrix4f m_viewProjMatrix;
NzRectf m_targetRegion;
mutable NzRecti m_viewport;
NzVector2f m_size;
const NzRenderTarget* m_target;
mutable bool m_frustumUpdated;
mutable bool m_invViewProjMatrixUpdated;
mutable bool m_projectionMatrixUpdated;
mutable bool m_viewMatrixUpdated;
mutable bool m_viewProjMatrixUpdated;
mutable bool m_viewportUpdated;
float m_zFar;
float m_zNear;
};
#endif // NAZARA_VIEW_HPP

View File

@ -1,354 +0,0 @@
// 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/Camera.hpp>
#include <Nazara/Graphics/Scene.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Graphics/Debug.hpp>
NzCamera::NzCamera() :
m_targetRegion(0.f, 0.f, 1.f, 1.f),
m_target(nullptr),
m_frustumUpdated(false),
m_projectionMatrixUpdated(false),
m_viewMatrixUpdated(false),
m_viewportUpdated(false),
m_aspectRatio(0.f),
m_fov(70.f),
m_zFar(100.f),
m_zNear(1.f)
{
}
void NzCamera::EnsureFrustumUpdate() const
{
if (!m_frustumUpdated)
UpdateFrustum();
}
void NzCamera::EnsureProjectionMatrixUpdate() const
{
if (!m_projectionMatrixUpdated)
UpdateProjectionMatrix();
}
void NzCamera::EnsureViewMatrixUpdate() const
{
if (!m_viewMatrixUpdated)
UpdateViewMatrix();
}
void NzCamera::EnsureViewportUpdate() const
{
if (!m_viewportUpdated)
UpdateViewport();
}
float NzCamera::GetAspectRatio() const
{
return m_aspectRatio;
}
NzVector3f NzCamera::GetEyePosition() const
{
return GetPosition(nzCoordSys_Global);
}
NzVector3f NzCamera::GetForward() const
{
return NzNode::GetForward();
}
float NzCamera::GetFOV() const
{
return m_fov;
}
const NzFrustumf& NzCamera::GetFrustum() const
{
if (!m_frustumUpdated)
UpdateFrustum();
return m_frustum;
}
NzVector3f NzCamera::GetGlobalForward() const
{
return NzVector3f::Forward();
}
NzVector3f NzCamera::GetGlobalRight() const
{
return NzVector3f::Right();
}
NzVector3f NzCamera::GetGlobalUp() const
{
return NzVector3f::Up();
}
const NzMatrix4f& NzCamera::GetProjectionMatrix() const
{
if (!m_projectionMatrixUpdated)
UpdateProjectionMatrix();
return m_projectionMatrix;
}
const NzRenderTarget* NzCamera::GetTarget() const
{
return m_target;
}
const NzRectf& NzCamera::GetTargetRegion() const
{
return m_targetRegion;
}
const NzMatrix4f& NzCamera::GetViewMatrix() const
{
if (!m_viewMatrixUpdated)
UpdateViewMatrix();
return m_viewMatrix;
}
const NzRecti& NzCamera::GetViewport() const
{
#if NAZARA_GRAPHICS_SAFE
if (!m_target)
{
NazaraError("Camera has no render target");
return m_viewport;
}
#endif
if (!m_viewportUpdated)
UpdateViewport();
return m_viewport;
}
float NzCamera::GetZFar() const
{
return m_zFar;
}
float NzCamera::GetZNear() const
{
return m_zNear;
}
void NzCamera::SetFOV(float fov)
{
#if NAZARA_GRAPHICS_SAFE
if (NzNumberEquals(fov, 0.f))
{
NazaraError("FOV must be different from zero");
return;
}
#endif
m_fov = fov;
m_frustumUpdated = false;
m_projectionMatrixUpdated = false;
}
void NzCamera::SetTarget(const NzRenderTarget* renderTarget)
{
m_target = renderTarget;
if (m_target)
{
m_targetReleaseSlot.Connect(m_target->OnRenderTargetRelease, this, &NzCamera::OnRenderTargetRelease);
m_targetResizeSlot.Connect(m_target->OnRenderTargetSizeChange, this, &NzCamera::OnRenderTargetSizeChange);
}
else
{
m_targetReleaseSlot.Disconnect();
m_targetResizeSlot.Disconnect();
}
m_frustumUpdated = false;
m_projectionMatrixUpdated = false;
m_viewportUpdated = false;
}
void NzCamera::SetTarget(const NzRenderTarget& renderTarget)
{
SetTarget(&renderTarget);
}
void NzCamera::SetTargetRegion(const NzRectf& region)
{
m_targetRegion = region;
m_frustumUpdated = false;
m_projectionMatrixUpdated = false;
m_viewportUpdated = false;
}
void NzCamera::SetViewport(const NzRecti& viewport)
{
#if NAZARA_GRAPHICS_SAFE
if (!m_target)
{
NazaraError("Camera has no render target");
return;
}
#endif
// On calcule la région nécessaire pour produire ce viewport avec la taille actuelle de la cible
float invWidth = 1.f/m_target->GetWidth();
float invHeight = 1.f/m_target->GetHeight();
SetTargetRegion(NzRectf(invWidth * viewport.x, invHeight * viewport.y, invWidth * viewport.width, invHeight * viewport.height));
}
void NzCamera::SetZFar(float zFar)
{
m_zFar = zFar;
m_frustumUpdated = false;
m_projectionMatrixUpdated = false;
}
void NzCamera::SetZNear(float zNear)
{
#if NAZARA_GRAPHICS_SAFE
if (zNear < 0.f || NzNumberEquals(zNear, 0.f))
{
NazaraError("ZNear shall be a strictly positive number");
return;
}
#endif
m_zNear = zNear;
m_frustumUpdated = false;
m_projectionMatrixUpdated = false;
}
void NzCamera::ApplyView() const
{
#if NAZARA_GRAPHICS_SAFE
if (!m_target)
{
NazaraError("Camera has no render target");
return;
}
#endif
if (!m_projectionMatrixUpdated)
UpdateProjectionMatrix();
if (!m_viewMatrixUpdated)
UpdateViewMatrix();
if (!m_viewportUpdated)
UpdateViewport();
NzRenderer::SetMatrix(nzMatrixType_Projection, m_projectionMatrix);
NzRenderer::SetMatrix(nzMatrixType_View, m_viewMatrix);
NzRenderer::SetTarget(m_target);
NzRenderer::SetViewport(m_viewport);
}
void NzCamera::InvalidateNode()
{
NzNode::InvalidateNode();
// Le frustum et la view matrix dépendent des paramètres du node, invalidons-les
m_frustumUpdated = false;
m_viewMatrixUpdated = false;
}
void NzCamera::OnRenderTargetRelease(const NzRenderTarget* renderTarget)
{
if (renderTarget == m_target)
m_target = nullptr;
else
NazaraInternalError("Not listening to " + NzString::Pointer(renderTarget));
}
void NzCamera::OnRenderTargetSizeChange(const NzRenderTarget* renderTarget)
{
if (renderTarget == m_target)
{
m_frustumUpdated = false;
m_projectionMatrixUpdated = false;
m_viewportUpdated = false;
}
else
NazaraInternalError("Not listening to " + NzString::Pointer(renderTarget));
}
void NzCamera::UpdateFrustum() const
{
if (!m_projectionMatrixUpdated)
UpdateProjectionMatrix();
if (!m_viewMatrixUpdated)
UpdateViewMatrix();
m_frustum.Extract(m_viewMatrix, m_projectionMatrix);
m_frustumUpdated = true;
}
void NzCamera::UpdateProjectionMatrix() const
{
#if NAZARA_GRAPHICS_SAFE
// Il n'y a pas grand chose à faire d'autre qu'un avertissement à ce stade
if (m_zNear >= m_zFar)
NazaraWarning("ZNear is greater or equal to ZFar (" + NzString::Number(m_zNear) + " >= " + NzString::Number(m_zFar) + ").");
#endif
if (!m_viewportUpdated)
UpdateViewport(); // Peut affecter l'aspect ratio
m_projectionMatrix.MakePerspective(m_fov, m_aspectRatio, m_zNear, m_zFar);
m_projectionMatrixUpdated = true;
}
void NzCamera::UpdateViewMatrix() const
{
if (!m_derivedUpdated)
UpdateDerived();
m_viewMatrix.MakeViewMatrix(m_derivedPosition, m_derivedRotation);
m_viewMatrixUpdated = true;
}
void NzCamera::UpdateViewport() const
{
#if NAZARA_GRAPHICS_SAFE
if (!m_target)
{
NazaraError("Camera has no render target");
return;
}
#endif
unsigned int width = m_target->GetWidth();
unsigned int height = std::max(m_target->GetHeight(), 1U);
float vWidth = width * m_targetRegion.width;
float vHeight = height * m_targetRegion.height;
float aspectRatio = vWidth/vHeight;
if (!NzNumberEquals(m_aspectRatio, aspectRatio, 0.001f))
{
m_aspectRatio = aspectRatio;
m_frustumUpdated = false;
m_projectionMatrixUpdated = false;
}
m_viewport.x = static_cast<int>(width * m_targetRegion.x);
m_viewport.y = static_cast<int>(height * m_targetRegion.y);
m_viewport.width = static_cast<int>(vWidth);
m_viewport.height = static_cast<int>(vHeight);
m_viewportUpdated = true;
}

View File

@ -4,7 +4,6 @@
#include <Nazara/Graphics/DeferredDOFPass.hpp> #include <Nazara/Graphics/DeferredDOFPass.hpp>
#include <Nazara/Graphics/AbstractViewer.hpp> #include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Graphics/Scene.hpp>
#include <Nazara/Renderer/Renderer.hpp> #include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/RenderTexture.hpp> #include <Nazara/Renderer/RenderTexture.hpp>
#include <memory> #include <memory>

View File

@ -4,7 +4,6 @@
#include <Nazara/Graphics/DeferredFinalPass.hpp> #include <Nazara/Graphics/DeferredFinalPass.hpp>
#include <Nazara/Graphics/AbstractViewer.hpp> #include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Graphics/Scene.hpp>
#include <Nazara/Renderer/Renderer.hpp> #include <Nazara/Renderer/Renderer.hpp>
#include <memory> #include <memory>
#include <Nazara/Graphics/Debug.hpp> #include <Nazara/Graphics/Debug.hpp>

View File

@ -4,7 +4,6 @@
#include <Nazara/Graphics/DeferredFogPass.hpp> #include <Nazara/Graphics/DeferredFogPass.hpp>
#include <Nazara/Graphics/AbstractViewer.hpp> #include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Graphics/Scene.hpp>
#include <Nazara/Renderer/Renderer.hpp> #include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/RenderTexture.hpp> #include <Nazara/Renderer/RenderTexture.hpp>
#include <memory> #include <memory>

View File

@ -8,7 +8,6 @@
#include <Nazara/Graphics/AbstractViewer.hpp> #include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Graphics/DeferredRenderTechnique.hpp> #include <Nazara/Graphics/DeferredRenderTechnique.hpp>
#include <Nazara/Graphics/ForwardRenderTechnique.hpp> #include <Nazara/Graphics/ForwardRenderTechnique.hpp>
#include <Nazara/Graphics/Scene.hpp>
#include <Nazara/Renderer/Renderer.hpp> #include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Graphics/Debug.hpp> #include <Nazara/Graphics/Debug.hpp>

View File

@ -8,7 +8,6 @@
#include <Nazara/Graphics/AbstractViewer.hpp> #include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Graphics/DeferredRenderTechnique.hpp> #include <Nazara/Graphics/DeferredRenderTechnique.hpp>
#include <Nazara/Graphics/Material.hpp> #include <Nazara/Graphics/Material.hpp>
#include <Nazara/Graphics/Scene.hpp>
#include <Nazara/Renderer/Renderer.hpp> #include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/RenderTexture.hpp> #include <Nazara/Renderer/RenderTexture.hpp>
#include <Nazara/Utility/BufferMapper.hpp> #include <Nazara/Utility/BufferMapper.hpp>

View File

@ -5,7 +5,6 @@
#include <Nazara/Graphics/DeferredPhongLightingPass.hpp> #include <Nazara/Graphics/DeferredPhongLightingPass.hpp>
#include <Nazara/Graphics/AbstractViewer.hpp> #include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Graphics/DeferredRenderQueue.hpp> #include <Nazara/Graphics/DeferredRenderQueue.hpp>
#include <Nazara/Graphics/Scene.hpp>
#include <Nazara/Renderer/Renderer.hpp> #include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/RenderTexture.hpp> #include <Nazara/Renderer/RenderTexture.hpp>
#include <Nazara/Utility/StaticMesh.hpp> #include <Nazara/Utility/StaticMesh.hpp>

View File

@ -9,7 +9,7 @@
#include <Nazara/Graphics/DeferredRenderTechnique.hpp> #include <Nazara/Graphics/DeferredRenderTechnique.hpp>
#include <Nazara/Core/ErrorFlags.hpp> #include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Graphics/AbstractBackground.hpp> #include <Nazara/Graphics/AbstractBackground.hpp>
#include <Nazara/Graphics/Camera.hpp> #include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Graphics/DeferredBloomPass.hpp> #include <Nazara/Graphics/DeferredBloomPass.hpp>
#include <Nazara/Graphics/DeferredDOFPass.hpp> #include <Nazara/Graphics/DeferredDOFPass.hpp>
#include <Nazara/Graphics/DeferredFinalPass.hpp> #include <Nazara/Graphics/DeferredFinalPass.hpp>
@ -21,7 +21,6 @@
#include <Nazara/Graphics/Drawable.hpp> #include <Nazara/Graphics/Drawable.hpp>
#include <Nazara/Graphics/Light.hpp> #include <Nazara/Graphics/Light.hpp>
#include <Nazara/Graphics/Material.hpp> #include <Nazara/Graphics/Material.hpp>
#include <Nazara/Graphics/Scene.hpp>
#include <Nazara/Graphics/Sprite.hpp> #include <Nazara/Graphics/Sprite.hpp>
#include <Nazara/Renderer/Config.hpp> #include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/OpenGL.hpp> #include <Nazara/Renderer/OpenGL.hpp>

View File

@ -6,7 +6,7 @@
#include <Nazara/Core/ErrorFlags.hpp> #include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Core/OffsetOf.hpp> #include <Nazara/Core/OffsetOf.hpp>
#include <Nazara/Graphics/AbstractBackground.hpp> #include <Nazara/Graphics/AbstractBackground.hpp>
#include <Nazara/Graphics/Camera.hpp> #include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Graphics/Drawable.hpp> #include <Nazara/Graphics/Drawable.hpp>
#include <Nazara/Graphics/Light.hpp> #include <Nazara/Graphics/Light.hpp>
#include <Nazara/Graphics/Material.hpp> #include <Nazara/Graphics/Material.hpp>

View File

@ -5,7 +5,6 @@
#include <Nazara/Graphics/Light.hpp> #include <Nazara/Graphics/Light.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Graphics/AbstractRenderQueue.hpp> #include <Nazara/Graphics/AbstractRenderQueue.hpp>
#include <Nazara/Graphics/Camera.hpp>
#include <Nazara/Math/Algorithm.hpp> #include <Nazara/Math/Algorithm.hpp>
#include <Nazara/Math/Sphere.hpp> #include <Nazara/Math/Sphere.hpp>
#include <Nazara/Renderer/Renderer.hpp> #include <Nazara/Renderer/Renderer.hpp>

View File

@ -4,7 +4,6 @@
#include <Nazara/Graphics/Model.hpp> #include <Nazara/Graphics/Model.hpp>
#include <Nazara/Graphics/AbstractRenderQueue.hpp> #include <Nazara/Graphics/AbstractRenderQueue.hpp>
#include <Nazara/Graphics/Camera.hpp>
#include <Nazara/Graphics/Config.hpp> #include <Nazara/Graphics/Config.hpp>
#include <Nazara/Utility/MeshData.hpp> #include <Nazara/Utility/MeshData.hpp>
#include <Nazara/Utility/StaticMesh.hpp> #include <Nazara/Utility/StaticMesh.hpp>

View File

@ -1,465 +0,0 @@
// 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/Scene.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Graphics/Camera.hpp>
#include <Nazara/Graphics/ColorBackground.hpp>
#include <Nazara/Graphics/RenderTechniques.hpp>
#include <Nazara/Graphics/SkinningManager.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <functional>
#include <Nazara/Graphics/Debug.hpp>
NzScene::NzScene() :
m_ambientColor(25, 25, 25),
m_root(this),
m_viewer(nullptr),
m_backgroundEnabled(true),
m_update(false),
m_updatePerSecond(60)
{
}
void NzScene::AddToVisibilityList(NzUpdatable* object)
{
m_visibleUpdateList.push_back(object);
}
void NzScene::Clear()
{
m_nodeMap.clear();
m_nodes.clear();
}
void NzScene::Cull()
{
#if NAZARA_GRAPHICS_SAFE
if (!m_viewer)
{
NazaraError("No viewer");
return;
}
#endif
NzAbstractRenderQueue* renderQueue = GetRenderTechnique()->GetRenderQueue();
renderQueue->Clear(false);
m_visibleUpdateList.clear();
// Frustum culling
RecursiveFrustumCull(renderQueue, m_viewer->GetFrustum(), &m_root);
///TODO: Occlusion culling
}
void NzScene::Draw()
{
#if NAZARA_GRAPHICS_SAFE
if (!m_viewer)
{
NazaraError("No viewer");
return;
}
#endif
m_viewer->ApplyView();
try
{
NzSceneData sceneData;
sceneData.ambientColor = m_ambientColor;
sceneData.background = (m_backgroundEnabled) ? m_background.get() : nullptr;
sceneData.viewer = m_viewer;
NzErrorFlags errFlags(nzErrorFlag_ThrowException, true);
m_renderTechnique->Draw(sceneData);
}
catch (const std::exception& e)
{
NzString oldName = m_renderTechnique->GetName();
if (m_renderTechniqueRanking > 0)
{
m_renderTechnique.reset(NzRenderTechniques::GetByRanking(m_renderTechniqueRanking-1, &m_renderTechniqueRanking));
NazaraError("Render technique \"" + oldName + "\" failed (" + NzString(e.what()) + "), falling back to \"" + m_renderTechnique->GetName() + '"');
}
else
{
NzErrorFlags errFlags(nzErrorFlag_ThrowException);
NazaraError("Render technique \"" + oldName + "\" failed (" + NzString(e.what()) + ") and no fallback is available");
}
return;
}
}
void NzScene::EnableBackground(bool enable)
{
m_backgroundEnabled = enable;
}
NzSceneNode* NzScene::FindNode(const NzString& name)
{
auto it = m_nodeMap.find(name);
if (it == m_nodeMap.end())
return nullptr;
return it->second;
}
const NzSceneNode* NzScene::FindNode(const NzString& name) const
{
auto it = m_nodeMap.find(name);
if (it == m_nodeMap.end())
return nullptr;
return it->second;
}
NzColor NzScene::GetAmbientColor() const
{
return m_ambientColor;
}
NzAbstractBackground* NzScene::GetBackground() const
{
if (!m_background)
m_background.reset(new NzColorBackground);
return m_background.get();
}
NzVector3f NzScene::GetBackward() const
{
#if NAZARA_GRAPHICS_SAFE
if (!m_viewer)
{
NazaraError("No viewer");
return NzVector3f::Backward();
}
#endif
//return -m_viewer->GetGlobalForward();
return NzVector3f::Backward();
}
NzVector3f NzScene::GetDown() const
{
#if NAZARA_GRAPHICS_SAFE
if (!m_viewer)
{
NazaraError("No viewer");
return NzVector3f::Down();
}
#endif
//return -m_viewer->GetGlobalUp();
return NzVector3f::Down();
}
NzVector3f NzScene::GetForward() const
{
#if NAZARA_GRAPHICS_SAFE
if (!m_viewer)
{
NazaraError("No viewer");
return NzVector3f::Forward();
}
#endif
//return m_viewer->GetGlobalForward();
return NzVector3f::Forward();
}
NzVector3f NzScene::GetLeft() const
{
#if NAZARA_GRAPHICS_SAFE
if (!m_viewer)
{
NazaraError("No viewer");
return NzVector3f::Left();
}
#endif
//return -m_viewer->GetGlobalRight();
return NzVector3f::Left();
}
NzAbstractRenderTechnique* NzScene::GetRenderTechnique() const
{
if (!m_renderTechnique)
m_renderTechnique.reset(NzRenderTechniques::GetByRanking(-1, &m_renderTechniqueRanking));
return m_renderTechnique.get();
}
NzVector3f NzScene::GetRight() const
{
#if NAZARA_GRAPHICS_SAFE
if (!m_viewer)
{
NazaraError("No viewer");
return NzVector3f::Right();
}
#endif
//return m_viewer->GetGlobalRight();
return NzVector3f::Right();
}
NzSceneNode& NzScene::GetRoot()
{
return m_root;
}
const NzSceneNode& NzScene::GetRoot() const
{
return m_root;
}
NzAbstractViewer* NzScene::GetViewer() const
{
return m_viewer;
}
NzVector3f NzScene::GetUp() const
{
#if NAZARA_GRAPHICS_SAFE
if (!m_viewer)
{
NazaraError("No viewer");
return NzVector3f::Up();
}
#endif
//return m_viewer->GetGlobalUp();
return NzVector3f::Up();
}
float NzScene::GetUpdateTime() const
{
return m_updateTime;
}
unsigned int NzScene::GetUpdatePerSecond() const
{
return m_updatePerSecond;
}
bool NzScene::IsBackgroundEnabled() const
{
return m_backgroundEnabled;
}
void NzScene::RegisterForUpdate(NzUpdatable* object)
{
#if NAZARA_GRAPHICS_SAFE
if (!object)
{
NazaraError("Invalid object");
return;
}
#endif
m_updateList.push_back(object);
}
void NzScene::RemoveNode(NzSceneNode* node)
{
if (!node)
return;
// C'est moche mais je n'ai pas d'autre choix que d'utiliser un std::unique_ptr pour utiliser std::find
std::unique_ptr<NzSceneNode> ptr(node);
auto it = std::find(m_nodes.begin(), m_nodes.end(), ptr);
ptr.release();
if (it == m_nodes.end())
{
NazaraError("This scene node doesn't belong to this scene");
return;
}
NzString nodeName = node->GetName();
if (!nodeName.IsEmpty())
m_nodeMap.erase(nodeName);
m_nodes.erase(it);
}
void NzScene::RemoveNode(const NzString& name)
{
RemoveNode(FindNode(name));
}
void NzScene::RenderFrame()
{
try
{
NzErrorFlags errFlags(nzErrorFlag_ThrowException, true);
Update();
Cull();
UpdateVisible();
Draw();
}
catch (const std::exception& e)
{
NazaraError("Failed to render frame: " + NzString(e.what()));
}
}
void NzScene::SetAmbientColor(const NzColor& color)
{
m_ambientColor = color;
}
void NzScene::SetBackground(NzAbstractBackground* background)
{
m_background.reset(background);
}
void NzScene::SetRenderTechnique(NzAbstractRenderTechnique* renderTechnique)
{
m_renderTechnique.reset(renderTechnique);
}
void NzScene::SetViewer(NzAbstractViewer* viewer)
{
if (m_viewer != viewer)
{
m_viewer = viewer;
// Invalidation de tous les nodes de la scène (utile pour la régénération des sommets dépendant du viewer)
m_root.InvalidateNode();
}
}
void NzScene::SetViewer(NzAbstractViewer& viewer)
{
SetViewer(&viewer);
}
void NzScene::SetUpdatePerSecond(unsigned int updatePerSecond)
{
m_updatePerSecond = updatePerSecond;
}
void NzScene::UnregisterForUpdate(NzUpdatable* object)
{
#if NAZARA_GRAPHICS_SAFE
if (!object)
{
NazaraError("Invalid object");
return;
}
#endif
auto it = std::find(m_updateList.begin(), m_updateList.end(), object);
if (it != m_updateList.end())
m_updateList.erase(it);
}
void NzScene::Update()
{
m_update = (m_updatePerSecond == 0 || m_updateClock.GetMilliseconds() > 1000/m_updatePerSecond);
if (m_update)
{
m_updateTime = m_updateClock.GetSeconds();
m_updateClock.Restart();
for (NzUpdatable* updatable : m_updateList)
///TODO: Multihreading
updatable->Update();
}
}
void NzScene::UpdateVisible()
{
NzSkinningManager::Skin();
if (m_update)
{
for (NzUpdatable* node : m_visibleUpdateList)
node->Update();
}
}
NzScene::operator const NzSceneNode&() const
{
return m_root;
}
bool NzScene::ChangeNodeName(NzSceneNode* node, const NzString& newName)
{
#ifdef NAZARA_DEBUG
std::unique_ptr<NzSceneNode> ptr(node);
auto it = std::find(m_nodes.begin(), m_nodes.end(), ptr);
ptr.release();
if (it == m_nodes.end())
{
NazaraInternalError("Node isn't part of the scene");
return false;
}
#endif
if (!newName.IsEmpty())
{
auto pair = m_nodeMap.insert(std::make_pair(newName, node));
if (!pair.second)
{
NazaraError("Name \"" + newName + "\" is already in use");
return false;
}
}
NzString oldName = node->GetName();
if (!oldName.IsEmpty())
m_nodeMap.erase(oldName);
node->SetNameInternal(newName);
return true;
}
bool NzScene::RegisterSceneNode(const NzString& name, NzSceneNode* node)
{
if (!name.IsEmpty())
{
if (m_nodeMap.find(name) != m_nodeMap.end())
{
NazaraError("Node " + name + " is already registred");
return false;
}
m_nodeMap[name] = node;
}
node->SetNameInternal(name);
node->SetParent(m_root, true);
m_nodes.emplace_back(node);
return true;
}
void NzScene::RecursiveFrustumCull(NzAbstractRenderQueue* renderQueue, const NzFrustumf& frustum, NzNode* node)
{
for (NzNode* child : node->GetChilds())
{
if (child->GetNodeType() == nzNodeType_Scene)
{
NzSceneNode* sceneNode = static_cast<NzSceneNode*>(child);
///TODO: Empêcher le rendu des enfants si le parent est cullé selon un flag
sceneNode->UpdateVisibility(frustum);
if (sceneNode->IsVisible())
sceneNode->AddToRenderQueue(renderQueue);
}
if (child->HasChilds())
RecursiveFrustumCull(renderQueue, frustum, child);
}
}

View File

@ -1,293 +0,0 @@
// 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/SceneNode.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/Scene.hpp>
#include <Nazara/Graphics/Debug.hpp>
///FIXME: Constructeur de copie
NzSceneNode::NzSceneNode() :
m_scene(nullptr),
m_boundingVolumeUpdated(false),
m_drawingEnabled(true),
m_visible(false)
{
}
NzSceneNode::NzSceneNode(const NzSceneNode& sceneNode) :
NzNode(sceneNode),
m_scene(nullptr),
m_boundingVolumeUpdated(false),
m_drawingEnabled(sceneNode.m_drawingEnabled),
m_visible(false)
{
}
NzSceneNode::~NzSceneNode() = default;
void NzSceneNode::EnableDrawing(bool drawingEnabled)
{
m_drawingEnabled = drawingEnabled;
}
NzVector3f NzSceneNode::GetBackward() const
{
if (m_scene)
{
if (!m_derivedUpdated)
UpdateDerived();
return m_derivedRotation * m_scene->GetBackward();
}
else
return NzNode::GetBackward();
}
const NzBoundingVolumef& NzSceneNode::GetBoundingVolume() const
{
if (!m_boundingVolumeUpdated)
UpdateBoundingVolume();
return m_boundingVolume;
}
NzVector3f NzSceneNode::GetDown() const
{
if (m_scene)
{
if (!m_derivedUpdated)
UpdateDerived();
return m_derivedRotation * m_scene->GetDown();
}
else
return NzNode::GetDown();
}
NzVector3f NzSceneNode::GetForward() const
{
if (m_scene)
{
if (!m_derivedUpdated)
UpdateDerived();
return m_derivedRotation * m_scene->GetForward();
}
else
return NzNode::GetForward();
}
NzVector3f NzSceneNode::GetLeft() const
{
if (m_scene)
{
if (!m_derivedUpdated)
UpdateDerived();
return m_derivedRotation * m_scene->GetLeft();
}
else
return NzNode::GetLeft();
}
const NzString& NzSceneNode::GetName() const
{
return m_name;
}
nzNodeType NzSceneNode::GetNodeType() const
{
return nzNodeType_Scene;
}
NzVector3f NzSceneNode::GetRight() const
{
if (m_scene)
{
if (!m_derivedUpdated)
UpdateDerived();
return m_derivedRotation * m_scene->GetRight();
}
else
return NzNode::GetRight();
}
NzScene* NzSceneNode::GetScene() const
{
return m_scene;
}
NzVector3f NzSceneNode::GetUp() const
{
if (m_scene)
{
if (!m_derivedUpdated)
UpdateDerived();
return m_derivedRotation * m_scene->GetUp();
}
else
return NzNode::GetUp();
}
bool NzSceneNode::IsDrawingEnabled() const
{
return m_drawingEnabled;
}
bool NzSceneNode::IsVisible() const
{
return m_visible;
}
void NzSceneNode::Remove()
{
if (m_scene)
m_scene->RemoveNode(this);
else
NazaraError("SceneNode::Remove() called on a template node");
}
bool NzSceneNode::SetName(const NzString& name)
{
if (m_scene)
// On demande à la scène de changer notre nom
return m_scene->ChangeNodeName(this, name);
else
{
// Pas de scène ? Changeons notre nom nous-même
SetNameInternal(name);
return true;
}
}
NzSceneNode& NzSceneNode::operator=(const NzSceneNode& sceneNode)
{
NzNode::operator=(sceneNode);
// La scène est affectée via le parenting du node
m_drawingEnabled = sceneNode.m_drawingEnabled;
m_visible = false;
return *this;
}
bool NzSceneNode::FrustumCull(const NzFrustumf& frustum) const
{
return frustum.Contains(GetBoundingVolume());
}
void NzSceneNode::InvalidateNode()
{
NzNode::InvalidateNode();
m_boundingVolumeUpdated = false;
}
void NzSceneNode::OnParenting(const NzNode* parent)
{
NzNode::OnParenting(parent);
if (parent)
{
///FIXME: Remonter jusqu'au premier parent de type SceneNode plutôt que de s'arrêter au premier venu
if (parent->GetNodeType() == nzNodeType_Scene)
SetScene(static_cast<const NzSceneNode*>(parent)->m_scene);
}
else
SetScene(nullptr);
}
void NzSceneNode::OnVisibilityChange(bool visibility)
{
NazaraUnused(visibility);
///TODO: Envoyer l'évènements aux listeners
}
void NzSceneNode::RecursiveSetScene(NzScene* scene, NzNode* node)
{
const std::vector<NzNode*>& childs = node->GetChilds();
for (NzNode* child : childs)
{
if (child->GetNodeType() == nzNodeType_Scene)
{
NzSceneNode* sceneNode = static_cast<NzSceneNode*>(child);
sceneNode->SetScene(scene);
}
if (node->HasChilds())
RecursiveSetScene(scene, node);
}
}
void NzSceneNode::Register()
{
}
void NzSceneNode::SetNameInternal(const NzString& name)
{
m_name = name;
}
void NzSceneNode::SetScene(NzScene* scene)
{
if (m_scene != scene)
{
if (m_scene)
Unregister();
m_scene = scene;
if (m_scene)
Register();
RecursiveSetScene(scene, this);
}
}
void NzSceneNode::Unregister()
{
}
void NzSceneNode::Update()
{
}
void NzSceneNode::UpdateBoundingVolume() const
{
if (m_boundingVolume.IsNull())
MakeBoundingVolume();
if (!m_transformMatrixUpdated)
UpdateTransformMatrix();
m_boundingVolume.Update(m_transformMatrix);
m_boundingVolumeUpdated = true;
}
void NzSceneNode::UpdateVisibility(const NzFrustumf& frustum)
{
bool wasVisible = m_visible;
if (m_drawingEnabled)
{
#if NAZARA_GRAPHICS_SAFE
if (!IsDrawable())
{
NazaraError("SceneNode is not drawable");
return;
}
#endif
m_visible = FrustumCull(frustum);
}
else
m_visible = false;
if (m_visible != wasVisible)
OnVisibilityChange(m_visible);
}

View File

@ -1,58 +0,0 @@
// 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/SceneRoot.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Graphics/Debug.hpp>
NzSceneRoot::NzSceneRoot(NzScene* scene)
{
m_scene = scene;
}
NzSceneRoot::~NzSceneRoot() = default;
void NzSceneRoot::AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const
{
NazaraUnused(renderQueue);
NazaraInternalError("SceneNode::AddToRenderQueue() called on SceneRoot");
}
nzSceneNodeType NzSceneRoot::GetSceneNodeType() const
{
return nzSceneNodeType_Root;
}
bool NzSceneRoot::IsDrawable() const
{
return true;
}
NzSceneRoot* NzSceneRoot::Clone() const
{
NazaraInternalError("SceneNode::Clone() called on SceneRoot");
return nullptr;
}
NzSceneRoot* NzSceneRoot::Create() const
{
NazaraInternalError("SceneNode::Create() called on SceneRoot");
return nullptr;
}
void NzSceneRoot::MakeBoundingVolume() const
{
m_boundingVolume.MakeInfinite();
}
void NzSceneRoot::Register()
{
NazaraInternalError("SceneNode::Register() called on SceneRoot");
}
void NzSceneRoot::Unregister()
{
NazaraInternalError("SceneNode::Unregister() called on SceneRoot");
}

View File

@ -4,10 +4,8 @@
#include <Nazara/Graphics/SkeletalModel.hpp> #include <Nazara/Graphics/SkeletalModel.hpp>
#include <Nazara/Graphics/AbstractRenderQueue.hpp> #include <Nazara/Graphics/AbstractRenderQueue.hpp>
#include <Nazara/Graphics/Camera.hpp>
#include <Nazara/Graphics/Config.hpp> #include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/SkinningManager.hpp> #include <Nazara/Graphics/SkinningManager.hpp>
#include <Nazara/Graphics/Scene.hpp>
#include <Nazara/Utility/BufferMapper.hpp> #include <Nazara/Utility/BufferMapper.hpp>
#include <Nazara/Utility/MeshData.hpp> #include <Nazara/Utility/MeshData.hpp>
#include <Nazara/Utility/SkeletalMesh.hpp> #include <Nazara/Utility/SkeletalMesh.hpp>

View File

@ -5,7 +5,6 @@
#include <Nazara/Graphics/Sprite.hpp> #include <Nazara/Graphics/Sprite.hpp>
#include <Nazara/Graphics/AbstractRenderQueue.hpp> #include <Nazara/Graphics/AbstractRenderQueue.hpp>
#include <Nazara/Graphics/AbstractViewer.hpp> #include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Graphics/Scene.hpp>
#include <cstring> #include <cstring>
#include <memory> #include <memory>
#include <Nazara/Graphics/Debug.hpp> #include <Nazara/Graphics/Debug.hpp>

View File

@ -1,408 +0,0 @@
// 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/View.hpp>
#include <Nazara/Graphics/Scene.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Graphics/Debug.hpp>
NzView::NzView() :
m_targetRegion(0.f, 0.f, 1.f, 1.f),
m_size(0.f),
m_target(nullptr),
m_frustumUpdated(false),
m_invViewProjMatrixUpdated(false),
m_projectionMatrixUpdated(false),
m_viewMatrixUpdated(false),
m_viewProjMatrixUpdated(false),
m_viewportUpdated(false),
m_zFar(1.f),
m_zNear(-1.f)
{
}
NzView::NzView(const NzVector2f& size) :
NzView() // On délègue
{
SetSize(size);
}
void NzView::EnsureFrustumUpdate() const
{
if (!m_frustumUpdated)
UpdateFrustum();
}
void NzView::EnsureProjectionMatrixUpdate() const
{
if (!m_projectionMatrixUpdated)
UpdateProjectionMatrix();
}
void NzView::EnsureViewMatrixUpdate() const
{
if (!m_viewMatrixUpdated)
UpdateViewMatrix();
}
void NzView::EnsureViewportUpdate() const
{
if (!m_viewportUpdated)
UpdateViewport();
}
float NzView::GetAspectRatio() const
{
return 1.f;
}
NzVector3f NzView::GetEyePosition() const
{
return GetPosition(nzCoordSys_Global);
}
NzVector3f NzView::GetForward() const
{
return NzNode::GetForward();
}
const NzFrustumf& NzView::GetFrustum() const
{
if (!m_frustumUpdated)
UpdateFrustum();
return m_frustum;
}
NzVector3f NzView::GetGlobalForward() const
{
return NzVector3f::UnitZ();
}
NzVector3f NzView::GetGlobalRight() const
{
return NzVector3f::UnitX();
}
NzVector3f NzView::GetGlobalUp() const
{
return -NzVector3f::UnitY();
}
const NzMatrix4f& NzView::GetInvViewProjMatrix() const
{
if (!m_invViewProjMatrixUpdated)
UpdateInvViewProjMatrix();
return m_invViewProjMatrix;
}
const NzMatrix4f& NzView::GetProjectionMatrix() const
{
if (!m_projectionMatrixUpdated)
UpdateProjectionMatrix();
return m_projectionMatrix;
}
const NzVector2f& NzView::GetSize() const
{
return m_size;
}
const NzRenderTarget* NzView::GetTarget() const
{
return m_target;
}
const NzRectf& NzView::GetTargetRegion() const
{
return m_targetRegion;
}
const NzMatrix4f& NzView::GetViewMatrix() const
{
if (!m_viewMatrixUpdated)
UpdateViewMatrix();
return m_viewMatrix;
}
const NzMatrix4f& NzView::GetViewProjMatrix() const
{
if (!m_viewProjMatrixUpdated)
UpdateViewProjMatrix();
return m_viewProjMatrix;
}
const NzRecti& NzView::GetViewport() const
{
#if NAZARA_GRAPHICS_SAFE
if (!m_target)
{
NazaraError("Camera has no render target");
return m_viewport;
}
#endif
if (!m_viewportUpdated)
UpdateViewport();
return m_viewport;
}
float NzView::GetZFar() const
{
return m_zFar;
}
float NzView::GetZNear() const
{
return m_zNear;
}
NzVector2f NzView::MapPixelToWorld(const NzVector2i& pixel)
{
if (!m_invViewProjMatrixUpdated)
UpdateInvViewProjMatrix();
if (!m_viewportUpdated)
UpdateViewport();
// Conversion du viewport en flottant
NzRectf viewport(m_viewport);
NzVector2f normalized;
normalized.x = -1.f + 2.f * (pixel.x - viewport.x) / viewport.width;
normalized.y = 1.f - 2.f * (pixel.y - viewport.y) / viewport.height;
return m_invViewProjMatrix.Transform(normalized);
}
NzVector2i NzView::MapWorldToPixel(const NzVector2f& coords)
{
if (!m_viewProjMatrixUpdated)
UpdateViewProjMatrix();
if (!m_viewportUpdated)
UpdateViewport();
// Conversion du viewport en flottant
NzRectf viewport(m_viewport);
NzVector2f normalized = m_viewProjMatrix.Transform(coords);
NzVector2i pixel;
pixel.x = static_cast<int>(( normalized.x + 1.f) * viewport.width / 2.f + viewport.x);
pixel.y = static_cast<int>((-normalized.y + 1.f) * viewport.width / 2.f + viewport.y);
return pixel;
}
void NzView::SetSize(const NzVector2f& size)
{
SetSize(size.x, size.y);
}
void NzView::SetSize(float width, float height)
{
m_size.Set(width, height);
m_projectionMatrixUpdated = false;
}
void NzView::SetTarget(const NzRenderTarget* renderTarget)
{
m_target = renderTarget;
if (m_target)
{
m_targetReleaseSlot.Connect(m_target->OnRenderTargetRelease, this, &NzView::OnRenderTargetRelease);
m_targetResizeSlot.Connect(m_target->OnRenderTargetSizeChange, this, &NzView::OnRenderTargetSizeChange);
}
else
{
m_targetReleaseSlot.Disconnect();
m_targetResizeSlot.Disconnect();
}
}
void NzView::SetTarget(const NzRenderTarget& renderTarget)
{
SetTarget(&renderTarget);
}
void NzView::SetTargetRegion(const NzRectf& region)
{
m_targetRegion = region;
m_frustumUpdated = false;
m_invViewProjMatrixUpdated = false;
m_projectionMatrixUpdated = false;
m_viewProjMatrixUpdated = false;
m_viewportUpdated = false;
}
void NzView::SetViewport(const NzRecti& viewport)
{
#if NAZARA_GRAPHICS_SAFE
if (!m_target)
{
NazaraError("Camera has no render target");
return;
}
#endif
// On calcule la région nécessaire pour produire ce viewport avec la taille actuelle de la cible
float invWidth = 1.f/m_target->GetWidth();
float invHeight = 1.f/m_target->GetHeight();
SetTargetRegion(NzRectf(invWidth * viewport.x, invHeight * viewport.y, invWidth * viewport.width, invHeight * viewport.height));
}
void NzView::SetZFar(float zFar)
{
m_zFar = zFar;
m_frustumUpdated = false;
m_invViewProjMatrixUpdated = false;
m_projectionMatrixUpdated = false;
m_viewProjMatrixUpdated = false;
}
void NzView::SetZNear(float zNear)
{
m_zNear = zNear;
m_frustumUpdated = false;
m_invViewProjMatrixUpdated = false;
m_projectionMatrixUpdated = false;
m_viewProjMatrixUpdated = false;
}
void NzView::ApplyView() const
{
#if NAZARA_GRAPHICS_SAFE
if (!m_target)
{
NazaraError("Camera has no render target");
return;
}
#endif
if (!m_projectionMatrixUpdated)
UpdateProjectionMatrix();
if (!m_viewMatrixUpdated)
UpdateViewMatrix();
if (!m_viewportUpdated)
UpdateViewport();
NzRenderer::SetMatrix(nzMatrixType_Projection, m_projectionMatrix);
NzRenderer::SetMatrix(nzMatrixType_View, m_viewMatrix);
NzRenderer::SetTarget(m_target);
NzRenderer::SetViewport(m_viewport);
}
void NzView::InvalidateNode()
{
NzNode::InvalidateNode();
// Le frustum et la view matrix dépendent des paramètres du node, invalidons-les
m_frustumUpdated = false;
m_invViewProjMatrixUpdated = false;
m_viewMatrixUpdated = false;
m_viewProjMatrixUpdated = false;
}
void NzView::OnRenderTargetRelease(const NzRenderTarget* renderTarget)
{
if (renderTarget == m_target)
m_target = nullptr;
else
NazaraInternalError("Not listening to " + NzString::Pointer(renderTarget));
}
void NzView::OnRenderTargetSizeChange(const NzRenderTarget* renderTarget)
{
if (renderTarget == m_target)
{
m_frustumUpdated = false;
m_projectionMatrixUpdated = false;
m_viewportUpdated = false;
}
else
NazaraInternalError("Not listening to " + NzString::Pointer(renderTarget));
}
void NzView::UpdateFrustum() const
{
if (!m_projectionMatrixUpdated)
UpdateProjectionMatrix();
if (!m_viewMatrixUpdated)
UpdateViewMatrix();
m_frustum.Extract(m_viewMatrix, m_projectionMatrix);
m_frustumUpdated = true;
}
void NzView::UpdateInvViewProjMatrix() const
{
if (!m_viewProjMatrixUpdated)
UpdateViewProjMatrix();
m_viewProjMatrix.GetInverseAffine(&m_invViewProjMatrix);
m_invViewProjMatrixUpdated = true;
}
void NzView::UpdateProjectionMatrix() const
{
if (m_size.x <= 0.f || m_size.y <= 0.f) // Si la taille est nulle, on prendra la taille du viewport
{
if (!m_viewportUpdated)
UpdateViewport();
m_projectionMatrix.MakeOrtho(0.f, static_cast<float>(m_viewport.width), 0.f, static_cast<float>(m_viewport.height), m_zNear, m_zFar);
}
else
m_projectionMatrix.MakeOrtho(0.f, m_size.x, 0.f, m_size.y, m_zNear, m_zFar);
m_projectionMatrixUpdated = true;
}
void NzView::UpdateViewMatrix() const
{
if (!m_derivedUpdated)
UpdateDerived();
m_viewMatrix.MakeViewMatrix(m_derivedPosition, m_derivedRotation);
m_viewMatrixUpdated = true;
}
void NzView::UpdateViewProjMatrix() const
{
if (!m_projectionMatrixUpdated)
UpdateProjectionMatrix();
if (!m_viewMatrixUpdated)
UpdateViewMatrix();
// La matrice de projection orthogonale est affine
m_viewProjMatrix = NzMatrix4f::ConcatenateAffine(m_viewMatrix, m_projectionMatrix);
m_viewProjMatrixUpdated = true;
}
void NzView::UpdateViewport() const
{
unsigned int width = m_target->GetWidth();
unsigned int height = std::max(m_target->GetHeight(), 1U);
m_viewport.x = static_cast<int>(width * m_targetRegion.x);
m_viewport.y = static_cast<int>(height * m_targetRegion.y);
m_viewport.width = static_cast<int>(width * m_targetRegion.width);
m_viewport.height = static_cast<int>(height * m_targetRegion.height);
m_viewportUpdated = true;
}