Big Graphics update

Separated LightManager
Added Sprite class
Added View class
Camera is no longer a SceneNode
Fixed Material not invalidating programs
Renamed CameraPosition uniform to EyePosition
Renamed VisibilityTest to FrustumCull


Former-commit-id: ff7fbe4d9b31a3c269baab0b48c6faa347a12161
This commit is contained in:
Lynix
2013-08-21 20:05:33 +02:00
parent 09e3027129
commit c8414a39d8
39 changed files with 1772 additions and 556 deletions

View File

@@ -13,6 +13,7 @@
class NzDrawable;
class NzLight;
class NzModel;
class NzSprite;
class NAZARA_API NzAbstractRenderQueue : NzNonCopyable
{
@@ -23,6 +24,7 @@ class NAZARA_API NzAbstractRenderQueue : NzNonCopyable
virtual void AddDrawable(const NzDrawable* drawable) = 0;
virtual void AddLight(const NzLight* light) = 0;
virtual void AddModel(const NzModel* model) = 0;
virtual void AddSprite(const NzSprite* sprite) = 0;
virtual void Clear(bool fully) = 0;
};

View File

@@ -0,0 +1,38 @@
// Copyright (C) 2013 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_ABSTRACTVIEWER_HPP
#define NAZARA_ABSTRACTVIEWER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Rect.hpp>
class NzRenderTarget;
class NzScene;
class NAZARA_API NzAbstractViewer
{
public:
NzAbstractViewer() = default;
virtual ~NzAbstractViewer();
virtual void ApplyView() const = 0;
virtual float GetAspectRatio() const = 0;
virtual NzVector3f GetEyePosition() const = 0;
virtual const NzFrustumf& GetFrustum() const = 0;
virtual const NzMatrix4f& GetProjectionMatrix() const = 0;
virtual const NzRenderTarget* GetTarget() const = 0;
virtual const NzMatrix4f& GetViewMatrix() const = 0;
virtual const NzRectui& GetViewport() const = 0;
virtual float GetZFar() const = 0;
virtual float GetZNear() const = 0;
};
#endif // NAZARA_ABSTRACTVIEWER_HPP

View File

@@ -8,6 +8,7 @@
#define NAZARA_CAMERA_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Graphics/SceneNode.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Math/Matrix4.hpp>
@@ -15,24 +16,22 @@
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
class NAZARA_API NzCamera : public NzSceneNode, NzRenderTarget::Listener
class NAZARA_API NzCamera : public NzAbstractViewer, public NzNode, NzRenderTarget::Listener
{
public:
NzCamera();
~NzCamera();
void Activate();
void EnsureFrustumUpdate() const;
void EnsureProjectionMatrixUpdate() const;
void EnsureViewMatrixUpdate() const;
void EnsureViewportUpdate() const;
float GetAspectRatio() const;
const NzBoundingVolumef& GetBoundingVolume() const override;
NzVector3f GetEyePosition() const;
float GetFOV() const;
const NzFrustumf& GetFrustum() const;
const NzMatrix4f& GetProjectionMatrix() const;
nzSceneNodeType GetSceneNodeType() const override;
const NzRenderTarget* GetTarget() const;
const NzRectf& GetTargetRegion() const;
const NzMatrix4f& GetViewMatrix() const;
@@ -49,22 +48,17 @@ class NAZARA_API NzCamera : public NzSceneNode, NzRenderTarget::Listener
void SetZNear(float zNear);
private:
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
void Invalidate();
void ApplyView() const override;
void Invalidate() override;
void OnRenderTargetReleased(const NzRenderTarget* renderTarget, void* userdata) override;
bool OnRenderTargetSizeChange(const NzRenderTarget* renderTarget, void* userdata) override;
void Register() override;
void Unregister() override;
void UpdateFrustum() const;
void UpdateProjectionMatrix() const;
void UpdateViewMatrix() const;
void UpdateViewport() const;
bool VisibilityTest(const NzCamera* camera) override;
mutable NzFrustumf m_frustum;
mutable NzMatrix4f m_projectionMatrix;
mutable NzMatrix4f m_viewMatrix;

View File

@@ -28,10 +28,10 @@ enum nzLightType
enum nzSceneNodeType
{
nzSceneNodeType_Camera, // NzCamera
nzSceneNodeType_Light, // NzLight
nzSceneNodeType_Model, // NzModel
nzSceneNodeType_Root, // NzSceneRoot
nzSceneNodeType_Sprite, // NzSprite
nzSceneNodeType_User,
nzSceneNodeType_Max = nzSceneNodeType_User

View File

@@ -32,6 +32,7 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
void AddDrawable(const NzDrawable* drawable);
void AddLight(const NzLight* light);
void AddModel(const NzModel* model);
void AddSprite(const NzSprite* sprite);
void Clear(bool fully);
@@ -40,32 +41,17 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
private:
bool OnResourceDestroy(const NzResource* resource, int index) override;
struct ModelMaterialComparator
{
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
};
struct SkeletalData
{
///TODO
NzMatrix4f transformMatrix;
};
struct SkeletalMeshComparator
{
bool operator()(const NzSkeletalMesh* subMesh1, const NzSkeletalMesh* subMesh2);
};
struct StaticData
{
NzMatrix4f transformMatrix;
};
struct StaticMeshComparator
{
bool operator()(const NzStaticMesh* subMesh1, const NzStaticMesh* subMesh2);
};
struct TransparentModel
{
NzMatrix4f transformMatrix;
@@ -83,17 +69,42 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
NzStaticMesh* mesh;
};
typedef std::map<const NzSkeletalMesh*, std::vector<SkeletalData>, SkeletalMeshComparator> SkeletalMeshContainer;
typedef std::map<const NzStaticMesh*, std::pair<NzSpheref, std::vector<StaticData>>, StaticMeshComparator> StaticMeshContainer;
typedef std::map<const NzMaterial*, std::tuple<bool, SkeletalMeshContainer, StaticMeshContainer>, ModelMaterialComparator> MeshContainer;
MeshContainer opaqueModels;
std::vector<std::pair<unsigned int, bool>> transparentsModels;
struct BatchedModelMaterialComparator
{
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
};
struct BatchedSpriteMaterialComparator
{
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
};
struct BatchedSkeletalMeshComparator
{
bool operator()(const NzSkeletalMesh* subMesh1, const NzSkeletalMesh* subMesh2);
};
struct BatchedStaticMeshComparator
{
bool operator()(const NzStaticMesh* subMesh1, const NzStaticMesh* subMesh2);
};
typedef std::map<const NzSkeletalMesh*, std::vector<SkeletalData>, BatchedSkeletalMeshComparator> BatchedSkeletalMeshContainer;
typedef std::map<const NzStaticMesh*, std::pair<NzSpheref, std::vector<StaticData>>, BatchedStaticMeshComparator> BatchedStaticMeshContainer;
typedef std::map<const NzMaterial*, std::tuple<bool, bool, BatchedSkeletalMeshContainer, BatchedStaticMeshContainer>, BatchedModelMaterialComparator> BatchedModelContainer;
typedef std::map<const NzMaterial*, std::vector<const NzSprite*>> BatchedSpriteContainer;
typedef std::vector<const NzLight*> LightContainer;
typedef std::vector<std::pair<unsigned int, bool>> TransparentModelContainer;
BatchedModelContainer opaqueModels;
BatchedSpriteContainer sprites;
TransparentModelContainer transparentsModels;
std::vector<TransparentSkeletalModel> transparentSkeletalModels;
std::vector<TransparentStaticModel> transparentStaticModels;
std::vector<const NzDrawable*> otherDrawables;
std::vector<const NzLight*> directionnalLights;
std::vector<const NzLight*> lights;
LightContainer directionnalLights;
LightContainer lights;
};
#endif // NAZARA_FORWARDRENDERQUEUE_HPP

View File

@@ -10,12 +10,17 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
#include <Nazara/Graphics/LightManager.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
class NzLightManager;
class NAZARA_API NzForwardRenderTechnique : public NzAbstractRenderTechnique
{
public:
NzForwardRenderTechnique();
~NzForwardRenderTechnique() = default;
~NzForwardRenderTechnique();
void Clear(const NzScene* scene);
void Draw(const NzScene* scene);
@@ -26,7 +31,15 @@ class NAZARA_API NzForwardRenderTechnique : public NzAbstractRenderTechnique
void SetMaxLightsPerObject(unsigned int lightCount);
private:
void DrawOpaqueModels(const NzScene* scene, NzForwardRenderQueue::BatchedModelContainer& opaqueModels);
void DrawSprites(const NzScene* scene, NzForwardRenderQueue::BatchedSpriteContainer& sprites);
void DrawTransparentModels(const NzScene* scene, NzForwardRenderQueue::TransparentModelContainer& transparentModels);
NzForwardRenderQueue m_renderQueue;
NzIndexBufferRef m_indexBuffer;
NzLightManager m_directionnalLights;
NzLightManager m_lights;
NzVertexBuffer m_spriteBuffer;
unsigned int m_maxLightsPerObject;
};

View File

@@ -49,11 +49,11 @@ class NAZARA_API NzLight : public NzSceneNode
static void Disable(const NzShaderProgram* program, unsigned int lightUnit);
private:
void Invalidate();
void Register();
void Unregister();
bool FrustumCull(const NzFrustumf& frustum) override;
void Invalidate() override;
void Register() override;
void Unregister() override;
void UpdateBoundingVolume() const;
bool VisibilityTest(const NzCamera* camera) override;
nzLightType m_type;
mutable NzBoundingVolumef m_boundingVolume;

View File

@@ -0,0 +1,48 @@
// Copyright (C) 2013 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_LIGHTMANAGER_HPP
#define NAZARA_LIGHTMANAGER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Math/Vector3.hpp>
class NzLight;
class NAZARA_API NzLightManager
{
public:
NzLightManager();
NzLightManager(const NzLight** lights, unsigned int lightCount);
~NzLightManager() = default;
void AddLights(const NzLight** lights, unsigned int lightCount);
void Clear();
unsigned int ComputeClosestLights(const NzVector3f& position, float squaredRadius, unsigned int maxResults);
const NzLight* GetLight(unsigned int index) const;
unsigned int GetLightCount() const;
const NzLight* GetResult(unsigned int i) const;
bool IsEmpty() const;
void SetLights(const NzLight** lights, unsigned int lightCount);
private:
struct Light
{
const NzLight* light;
unsigned int score;
};
std::vector<std::pair<const NzLight**, unsigned int>> m_lights;
std::vector<Light> m_results;
unsigned int m_lightCount;
};
#endif // NAZARA_LIGHTMANAGER_HPP

View File

@@ -88,12 +88,12 @@ class NAZARA_API NzModel : public NzSceneNode, public NzUpdatable
NzModel& operator=(NzModel&& node);
private:
bool FrustumCull(const NzFrustumf& frustum) override;
void Invalidate() override;
void Register() override;
void Unregister() override;
void Update() override;
void UpdateBoundingVolume() const;
bool VisibilityTest(const NzCamera* camera) override;
std::vector<NzMaterialRef> m_materials;
NzAnimationRef m_animation;

View File

@@ -15,6 +15,7 @@
#include <Nazara/Math/Frustum.hpp>
class NzAbstractRenderQueue;
class NzAbstractViewer;
class NzCamera;
class NzLight;
class NzModel;
@@ -36,11 +37,11 @@ class NAZARA_API NzScene
void Cull();
void Draw();
NzCamera* GetActiveCamera() const;
NzColor GetAmbientColor() const;
NzAbstractBackground* GetBackground() const;
NzAbstractRenderTechnique* GetRenderTechnique() const;
NzSceneNode& GetRoot() const;
NzAbstractViewer* GetViewer() const;
float GetUpdateTime() const;
unsigned int GetUpdatePerSecond() const;
@@ -49,6 +50,7 @@ class NAZARA_API NzScene
void SetAmbientColor(const NzColor& color);
void SetBackground(NzAbstractBackground* background);
void SetRenderTechnique(NzAbstractRenderTechnique* renderTechnique);
void SetViewer(NzAbstractViewer* viewer);
void SetUpdatePerSecond(unsigned int updatePerSecond);
void UnregisterForUpdate(NzUpdatable* object);
@@ -59,8 +61,7 @@ class NAZARA_API NzScene
operator const NzSceneNode&() const;
private:
void RecursiveCameraCull(NzAbstractRenderQueue* renderQueue, const NzCamera* camera, NzNode* node);
void SetActiveCamera(NzCamera* camera);
void RecursiveFrustumCull(NzAbstractRenderQueue* renderQueue, const NzFrustumf& frustum, NzNode* node);
NzSceneImpl* m_impl;
};

View File

@@ -0,0 +1,34 @@
// Copyright (C) 2013 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_SCENELAYER_HPP
#define NAZARA_SCENELAYER_HPP
#include <Nazara/Prerequesites.hpp>
class NzAbstractRenderTechnique;
class NzAbstractViewer;
class NAZARA_API NzSceneLayer
{
public:
NzSceneLayer();
~NzSceneLayer();
void Draw();
nzUInt32 GetBufferClearFlags() const;
NzAbstractRenderQueue* GetRenderQueue() const;
NzAbstractRenderTechnique* GetRenderTechnique() const;
NzScene* GetScene() const;
NzAbstractViewer* GetViewer() const;
void SetBufferClearFlags(nzUInt32 flags);
void SetRenderTechnique(NzAbstractRenderTechnique* renderTechnique);
void SetViewer(NzAbstractViewer* viewer);
};
#endif // NAZARA_SCENELAYER_HPP

View File

@@ -35,18 +35,18 @@ class NAZARA_API NzSceneNode : public NzNode
protected:
virtual void OnParenting(const NzNode* parent) override;
virtual void OnVisibilityChange(bool visibility);
virtual bool FrustumCull(const NzFrustumf& frustum) = 0;
void RecursiveSetScene(NzScene* scene, NzNode* node);
virtual void Register();
void SetScene(NzScene* scene);
virtual void Unregister();
virtual void Update();
virtual bool VisibilityTest(const NzCamera* camera) = 0;
NzScene* m_scene;
bool m_visible;
private:
void UpdateVisibility(const NzCamera* camera);
void UpdateVisibility(const NzFrustumf& frustum);
};
#endif // NAZARA_SCENENODE_HPP

View File

@@ -10,8 +10,6 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/SceneNode.hpp>
struct NzSceneImpl;
class NAZARA_API NzSceneRoot : public NzSceneNode
{
friend struct NzSceneImpl;
@@ -26,9 +24,9 @@ class NAZARA_API NzSceneRoot : public NzSceneNode
NzSceneRoot(NzScene* scene);
virtual ~NzSceneRoot();
bool FrustumCull(const NzFrustumf& frustum) override;
void Register();
void Unregister();
bool VisibilityTest(const NzCamera* camera) override;
};
#endif // NAZARA_SCENEROOT_HPP

View File

@@ -0,0 +1,52 @@
// Copyright (C) 2013 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/Enums.hpp>
#include <Nazara/Graphics/Scene.hpp>
#include <Nazara/Math/BoundingVolume.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Utility/Node.hpp>
class NAZARA_API NzSceneNode : public NzNode
{
friend class NzScene;
public:
NzSceneNode();
NzSceneNode(const NzSceneNode& node);
virtual ~NzSceneNode();
virtual void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const = 0;
virtual const NzBoundingVolumef& GetBoundingVolume() const = 0;
nzNodeType GetNodeType() const final;
NzScene* GetScene() const;
virtual nzSceneNodeType GetSceneNodeType() const = 0;
bool IsVisible() const;
protected:
virtual void OnParenting(const NzNode* parent) override;
virtual void OnVisibilityChange(bool visibility);
void RecursiveSetScene(NzScene* scene, NzNode* node);
virtual void Register();
void SetScene(NzScene* scene);
virtual void Unregister();
virtual void Update();
virtual bool VisibilityTest(const NzCamera* camera) = 0;
NzScene* m_scene;
bool m_visible;
private:
void UpdateVisibility(const NzCamera& camera);
};
#endif // NAZARA_SCENENODE_HPP

View File

@@ -0,0 +1,45 @@
// Copyright (C) 2013 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_SPRITE_HPP
#define NAZARA_SPRITE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/SceneNode.hpp>
#include <Nazara/Renderer/Material.hpp>
class NAZARA_API NzSprite : public NzSceneNode
{
public:
NzSprite();
NzSprite(const NzSprite& sprite);
NzSprite(NzSprite&& sprite);
~NzSprite();
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
const NzBoundingVolumef& GetBoundingVolume() const override;
NzMaterial* GetMaterial() const;
nzSceneNodeType GetSceneNodeType() const override;
const NzVector2f& GetSize() const;
const NzRectf& GetTextureCoords() const;
void SetMaterial(NzMaterial* material);
void SetSize(const NzVector2f& size);
void SetTextureCoords(const NzRectf& coords);
void SetTextureRect(const NzRectui& rect);
private:
bool FrustumCull(const NzFrustumf& frustum) override;
void Register() override;
void Unregister() override;
NzRectf m_textureCoords;
NzVector2f m_size;
NzMaterialRef m_material;
};
#endif // NAZARA_SPRITE_HPP

View File

@@ -0,0 +1,74 @@
// Copyright (C) 2013 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/Graphics/SceneNode.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>
class NAZARA_API NzView : public NzAbstractViewer, public NzNode, NzRenderTarget::Listener
{
public:
NzView();
~NzView();
void EnsureFrustumUpdate() const;
void EnsureProjectionMatrixUpdate() const;
void EnsureViewMatrixUpdate() const;
void EnsureViewportUpdate() const;
float GetAspectRatio() const;
NzVector3f GetEyePosition() const;
const NzFrustumf& GetFrustum() const;
const NzMatrix4f& GetProjectionMatrix() const;
const NzRenderTarget* GetTarget() const;
const NzRectf& GetTargetRegion() const;
const NzMatrix4f& GetViewMatrix() const;
const NzRectui& GetViewport() const;
float GetZFar() const;
float GetZNear() const;
void SetTarget(const NzRenderTarget* renderTarget);
void SetTarget(const NzRenderTarget& renderTarget);
void SetTargetRegion(const NzRectf& region);
void SetViewport(const NzRectui& viewport);
void SetZFar(float zFar);
void SetZNear(float zNear);
private:
void ApplyView() const override;
void Invalidate() override;
void OnRenderTargetReleased(const NzRenderTarget* renderTarget, void* userdata) override;
bool OnRenderTargetSizeChange(const NzRenderTarget* renderTarget, void* userdata) override;
void UpdateFrustum() const;
void UpdateProjectionMatrix() const;
void UpdateViewMatrix() const;
void UpdateViewport() const;
mutable NzFrustumf m_frustum;
mutable NzMatrix4f m_projectionMatrix;
mutable NzMatrix4f m_viewMatrix;
NzRectf m_targetRegion;
mutable NzRectui m_viewport;
const NzRenderTarget* m_target;
mutable bool m_frustumUpdated;
mutable bool m_projectionMatrixUpdated;
mutable bool m_viewMatrixUpdated;
mutable bool m_viewportUpdated;
float m_zFar;
float m_zNear;
};
#endif // NAZARA_VIEW_HPP