Merge remote-tracking branch 'origin/NDK' into NDK-ShadowMapping

Conflicts:
	SDK/include/NDK/Systems/RenderSystem.hpp
	SDK/src/NDK/Systems/RenderSystem.cpp

Former-commit-id: f62e9a27427d96893acd2381bb06ae928a1d3741
This commit is contained in:
Lynix
2015-06-29 21:05:09 +02:00
61 changed files with 434 additions and 2573 deletions

View File

@@ -8,12 +8,19 @@
#define NAZARA_ABSTRACTBACKGROUND_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/Enums.hpp>
class NzAbstractBackground;
class NzAbstractViewer;
class NAZARA_GRAPHICS_API NzAbstractBackground
using NzBackgroundConstRef = NzObjectRef<const NzAbstractBackground>;
using NzBackgroundLibrary = NzObjectLibrary<NzAbstractBackground>;
using NzBackgroundRef = NzObjectRef<NzAbstractBackground>;
class NAZARA_GRAPHICS_API NzAbstractBackground : public NzRefCounted
{
public:
NzAbstractBackground() = default;
@@ -22,6 +29,9 @@ class NAZARA_GRAPHICS_API NzAbstractBackground
virtual void Draw(const NzAbstractViewer* viewer) const = 0;
virtual nzBackgroundType GetBackgroundType() const = 0;
private:
static NzBackgroundLibrary::LibraryMap s_library;
};
#endif // NAZARA_ABSTRACTBACKGROUND_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

@@ -12,6 +12,11 @@
#include <Nazara/Graphics/AbstractBackground.hpp>
#include <Nazara/Renderer/UberShader.hpp>
class NzColorBackground;
using NzColorBackgroundConstRef = NzObjectRef<const NzColorBackground>;
using NzColorBackgroundRef = NzObjectRef<NzColorBackground>;
class NAZARA_GRAPHICS_API NzColorBackground : public NzAbstractBackground
{
public:
@@ -24,6 +29,8 @@ class NAZARA_GRAPHICS_API NzColorBackground : public NzAbstractBackground
void SetColor(const NzColor& color);
template<typename... Args> static NzColorBackgroundRef New(Args&&... args);
private:
NzColor m_color;
NzUberShaderConstRef m_uberShader;
@@ -32,4 +39,6 @@ class NAZARA_GRAPHICS_API NzColorBackground : public NzAbstractBackground
int m_vertexDepthUniform;
};
#include <Nazara/Graphics/ColorBackground.inl>
#endif // NAZARA_COLORBACKGROUND_HPP

View File

@@ -0,0 +1,17 @@
// 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 <memory>
#include <Nazara/Graphics/Debug.hpp>
template<typename... Args>
NzColorBackgroundRef NzColorBackground::New(Args&&... args)
{
std::unique_ptr<NzColorBackground> object(new NzColorBackground(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -52,6 +52,9 @@ inline void NzForwardRenderTechnique::SendLightUniforms(const NzShader* shader,
inline float NzForwardRenderTechnique::ComputeDirectionalLightScore(const NzSpheref& object, const NzAbstractRenderQueue::DirectionalLight& light)
{
NazaraUnused(object);
NazaraUnused(light);
///TODO: Compute a score depending on the light luminosity
return 0.f;
}
@@ -70,6 +73,9 @@ inline float NzForwardRenderTechnique::ComputeSpotLightScore(const NzSpheref& ob
inline bool NzForwardRenderTechnique::IsDirectionalLightSuitable(const NzSpheref& object, const NzAbstractRenderQueue::DirectionalLight& light)
{
NazaraUnused(object);
NazaraUnused(light);
// Directional light are always suitables
return true;
}

View File

@@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
inline NzInstancedRenderable::NzInstancedRenderable(const NzInstancedRenderable& renderable) :
NzRefCounted(),
m_boundingVolume(renderable.m_boundingVolume),
m_boundingVolumeUpdated(renderable.m_boundingVolumeUpdated)
{

View File

@@ -3,7 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Renderer/Debug.hpp>
#include <Nazara/Graphics/Debug.hpp>
template<typename... Args>
NzModelRef NzModel::New(Args&&... args)
@@ -14,4 +14,4 @@ NzModelRef NzModel::New(Args&&... args)
return object.release();
}
#include <Nazara/Renderer/DebugOff.hpp>
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -8,33 +8,32 @@
#define NAZARA_PARTICLESYSTEM_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Updatable.hpp>
#include <Nazara/Graphics/ParticleController.hpp>
#include <Nazara/Graphics/ParticleDeclaration.hpp>
#include <Nazara/Graphics/ParticleEmitter.hpp>
#include <Nazara/Graphics/ParticleGenerator.hpp>
#include <Nazara/Graphics/ParticleRenderer.hpp>
#include <Nazara/Graphics/SceneNode.hpp>
#include <Nazara/Graphics/Renderable.hpp>
#include <Nazara/Math/BoundingVolume.hpp>
#include <functional>
#include <memory>
#include <set>
#include <vector>
class NAZARA_GRAPHICS_API NzParticleSystem : public NzSceneNode, NzUpdatable
class NAZARA_GRAPHICS_API NzParticleSystem : public NzRenderable
{
public:
NzParticleSystem(unsigned int maxParticleCount, nzParticleLayout layout);
NzParticleSystem(unsigned int maxParticleCount, const NzParticleDeclaration* declaration);
NzParticleSystem(unsigned int maxParticleCount, NzParticleDeclarationConstRef declaration);
NzParticleSystem(const NzParticleSystem& emitter);
~NzParticleSystem();
void AddController(NzParticleController* controller);
void AddController(NzParticleControllerRef controller);
void AddEmitter(NzParticleEmitter* emitter);
void AddGenerator(NzParticleGenerator* generator);
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const;
void AddGenerator(NzParticleGeneratorRef generator);
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const NzMatrix4f& transformMatrix) const;
void ApplyControllers(NzParticleMapper& mapper, unsigned int particleCount, float elapsedTime, float& stepAccumulator);
void ApplyControllers(NzParticleMapper& mapper, unsigned int particleCount, float elapsedTime);
void* CreateParticle();
void* CreateParticles(unsigned int count);
@@ -44,14 +43,12 @@ class NAZARA_GRAPHICS_API NzParticleSystem : public NzSceneNode, NzUpdatable
void* GenerateParticle();
void* GenerateParticles(unsigned int count);
const NzParticleDeclaration* GetDeclaration() const;
const NzParticleDeclarationConstRef& GetDeclaration() const;
float GetFixedStepSize() const;
unsigned int GetMaxParticleCount() const;
unsigned int GetParticleCount() const;
unsigned int GetParticleSize() const;
nzSceneNodeType GetSceneNodeType() const override;
bool IsDrawable() const;
bool IsFixedStepEnabled() const;
void KillParticle(unsigned int index);
@@ -64,14 +61,14 @@ class NAZARA_GRAPHICS_API NzParticleSystem : public NzSceneNode, NzUpdatable
void SetFixedStepSize(float stepSize);
void SetRenderer(NzParticleRenderer* renderer);
void Update(float elapsedTime);
void UpdateBoundingVolume(const NzMatrix4f& transformMatrix) override;
NzParticleSystem& operator=(const NzParticleSystem& emitter);
private:
void MakeBoundingVolume() const override;
void Register() override;
void ResizeBuffer();
void Unregister() override;
void Update() override;
std::set<unsigned int, std::greater<unsigned int>> m_dyingParticles;
mutable std::vector<nzUInt8> m_buffer;

View File

@@ -27,7 +27,7 @@ class NAZARA_GRAPHICS_API NzRenderable
inline void EnsureBoundingVolumeUpdated() const;
virtual void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const NzMatrix4f& transformMatrix) const = 0;
virtual bool Cull(const NzFrustumf& frustum, const NzMatrix4f& transformMatrix) const = 0;
virtual bool Cull(const NzFrustumf& frustum, const NzMatrix4f& transformMatrix) const;
virtual const NzBoundingVolumef& GetBoundingVolume() const;
virtual void UpdateBoundingVolume(const NzMatrix4f& transformMatrix);

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

@@ -15,28 +15,39 @@
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
class NzSkyboxBackground;
using NzSkyboxBackgroundConstRef = NzObjectRef<const NzSkyboxBackground>;
using NzSkyboxBackgroundRef = NzObjectRef<NzSkyboxBackground>;
class NAZARA_GRAPHICS_API NzSkyboxBackground : public NzAbstractBackground
{
friend class NzGraphics;
public:
NzSkyboxBackground();
NzSkyboxBackground(NzTexture* cubemapTexture);
~NzSkyboxBackground();
NzSkyboxBackground(NzTextureRef cubemapTexture = NzTextureRef());
~NzSkyboxBackground() = default;
void Draw(const NzAbstractViewer* viewer) const;
nzBackgroundType GetBackgroundType() const;
NzTexture* GetTexture() const;
const NzTextureSampler& GetTextureSampler();
inline const NzTextureRef& GetTexture() const;
inline NzTextureSampler& GetTextureSampler();
inline const NzTextureSampler& GetTextureSampler() const;
void SetTexture(NzTexture* cubemapTexture);
void SetTextureSampler(const NzTextureSampler& sampler);
inline void SetTexture(NzTextureRef cubemapTexture);
inline void SetTextureSampler(const NzTextureSampler& sampler);
template<typename... Args> static NzSkyboxBackgroundRef New(Args&&... args);
private:
static bool Initialize();
static void Uninitialize();
NzTextureRef m_texture;
NzTextureSampler m_sampler;
NzIndexBufferRef m_indexBuffer;
NzShaderRef m_shader;
NzVertexBufferRef m_vertexBuffer;
};
#include <Nazara/Graphics/SkyboxBackground.inl>
#endif // NAZARA_SKYBOXBACKGROUND_HPP

View File

@@ -0,0 +1,45 @@
// 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 <memory>
#include <Nazara/Graphics/Debug.hpp>
inline const NzTextureRef& NzSkyboxBackground::GetTexture() const
{
return m_texture;
}
inline NzTextureSampler& NzSkyboxBackground::GetTextureSampler()
{
return m_sampler;
}
inline const NzTextureSampler& NzSkyboxBackground::GetTextureSampler() const
{
return m_sampler;
}
inline void NzSkyboxBackground::SetTexture(NzTextureRef cubemapTexture)
{
NazaraAssert(!cubemapTexture || cubemapTexture->IsValid(), "Invalid texture");
NazaraAssert(!cubemapTexture || cubemapTexture->IsCubemap(), "Texture must be a cubemap");
m_texture = std::move(cubemapTexture);
}
void NzSkyboxBackground::SetTextureSampler(const NzTextureSampler& sampler)
{
m_sampler = sampler;
}
template<typename... Args>
NzSkyboxBackgroundRef NzSkyboxBackground::New(Args&&... args)
{
std::unique_ptr<NzSkyboxBackground> object(new NzSkyboxBackground(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

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

View File

@@ -12,18 +12,24 @@
#include <Nazara/Renderer/UberShader.hpp>
#include <Nazara/Renderer/Texture.hpp>
class NzTextureBackground;
using NzTextureBackgroundConstRef = NzObjectRef<const NzTextureBackground>;
using NzTextureBackgroundRef = NzObjectRef<NzTextureBackground>;
class NAZARA_GRAPHICS_API NzTextureBackground : public NzAbstractBackground
{
public:
NzTextureBackground();
NzTextureBackground(NzTexture* texture);
NzTextureBackground(NzTextureRef texture = NzTextureRef());
void Draw(const NzAbstractViewer* viewer) const;
nzBackgroundType GetBackgroundType() const;
NzTexture* GetTexture() const;
inline const NzTextureRef& GetTexture() const;
void SetTexture(NzTexture* texture);
inline void SetTexture(NzTextureRef texture);
template<typename... Args> static NzTextureBackgroundRef New(Args&&... args);
private:
NzTextureRef m_texture;
@@ -34,4 +40,6 @@ class NAZARA_GRAPHICS_API NzTextureBackground : public NzAbstractBackground
int m_vertexDepthUniform;
};
#include <Nazara/Graphics/TextureBackground.inl>
#endif // NAZARA_TEXTUREBACKGROUND_HPP

View File

@@ -0,0 +1,29 @@
// 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 <memory>
#include <Nazara/Graphics/Debug.hpp>
inline const NzTextureRef& NzTextureBackground::GetTexture() const
{
return m_texture;
}
inline void NzTextureBackground::SetTexture(NzTextureRef texture)
{
NazaraAssert(!texture || texture->IsValid(), "Invalid texture");
m_texture = std::move(texture);
}
template<typename... Args>
NzTextureBackgroundRef NzTextureBackground::New(Args&&... args)
{
std::unique_ptr<NzTextureBackground> object(new NzTextureBackground(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Graphics/DebugOff.hpp>

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