Merged 2D and 3D modules into Graphics module

Former-commit-id: 33bf0fbe727e50e864bc52680c95a106ada508e9
This commit is contained in:
Lynix
2013-04-03 01:14:55 +02:00
parent e52412577b
commit 34dbd19385
50 changed files with 168 additions and 393 deletions

View File

@@ -0,0 +1,29 @@
// 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_GRAPHICS_HPP
#define NAZARA_GRAPHICS_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Initializer.hpp>
class NAZARA_API NzGraphics
{
public:
NzGraphics() = delete;
~NzGraphics() = delete;
static bool Initialize();
static bool IsInitialized();
static void Uninitialize();
private:
static unsigned int s_moduleReferenceCounter;
};
#endif // NAZARA_GRAPHICS_HPP

View File

@@ -0,0 +1,24 @@
// 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_BACKGROUND_HPP
#define NAZARA_BACKGROUND_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/Enums.hpp>
class NAZARA_API NzBackground
{
public:
NzBackground() = default;
~NzBackground();
virtual void Draw() const = 0;
virtual nzBackgroundType GetBackgroundType() const = 0;
};
#endif // NAZARA_BACKGROUND_HPP

View File

@@ -0,0 +1,77 @@
// 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_CAMERA_HPP
#define NAZARA_CAMERA_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/3D/SceneNode.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector3.hpp>
class NzRenderTarget;
class NAZARA_API NzCamera : public NzSceneNode
{
public:
NzCamera();
~NzCamera();
void Activate() const;
void EnsureFrustumUpdate() const;
void EnsureProjectionMatrixUpdate() const;
void EnsureViewMatrixUpdate() const;
float GetAspectRatio() const;
const NzBoundingBoxf& GetBoundingBox() const override;
float GetFOV() const;
const NzFrustumf& GetFrustum() const;
const NzMatrix4f& GetProjectionMatrix() const;
nzSceneNodeType GetSceneNodeType() const override;
const NzRenderTarget* GetTarget() const;
const NzVector3f& GetUpVector() const;
const NzMatrix4f& GetViewMatrix() const;
const NzRectf& GetViewport() const;
float GetZFar() const;
float GetZNear() const;
void SetFOV(float fov);
void SetTarget(const NzRenderTarget* renderTarget);
void SetTarget(const NzRenderTarget& renderTarget);
void SetUpVector(const NzVector3f& upVector);
void SetViewport(const NzRectf& viewport);
void SetZFar(float zFar);
void SetZNear(float zNear);
private:
void AddToRenderQueue(NzRenderQueue& renderQueue) const;
void Invalidate();
void Register();
void Unregister();
void UpdateFrustum() const;
void UpdateProjectionMatrix() const;
void UpdateViewMatrix() const;
bool VisibilityTest(const NzFrustumf& frustum) override;
mutable NzFrustumf m_frustum;
mutable NzMatrix4f m_projectionMatrix;
mutable NzMatrix4f m_viewMatrix;
NzRectf m_viewport;
NzVector3f m_upVector;
const NzRenderTarget* m_target;
mutable bool m_frustumUpdated;
mutable bool m_projectionMatrixUpdated;
mutable bool m_viewMatrixUpdated;
mutable float m_aspectRatio;
float m_fov;
float m_zFar;
float m_zNear;
};
#endif // NAZARA_CAMERA_HPP

View File

@@ -0,0 +1,30 @@
// 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_COLORBACKGROUND_HPP
#define NAZARA_COLORBACKGROUND_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Graphics/Background.hpp>
class NAZARA_API NzColorBackground : public NzBackground
{
public:
NzColorBackground(const NzColor& color = NzColor::Black);
void Draw() const;
nzBackgroundType GetBackgroundType() const;
NzColor GetColor() const;
void SetColor(const NzColor& color);
private:
NzColor m_color;
};
#endif // NAZARA_COLORBACKGROUND_HPP

View File

@@ -0,0 +1,38 @@
/*
Nazara Engine - Graphics module
Copyright (C) 2013 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_CONFIG_GRAPHICS_HPP
#define NAZARA_CONFIG_GRAPHICS_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_GRAPHICS_MEMORYLEAKTRACKER 0
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
#define NAZARA_GRAPHICS_SAFE 1
#endif // NAZARA_CONFIG_GRAPHICS_HPP

View File

@@ -0,0 +1,11 @@
// 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
#include <Nazara/Graphics/Config.hpp>
#if NAZARA_GRAPHICS_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
#define new new(__FILE__, __LINE__)
#endif

View File

@@ -0,0 +1,8 @@
// 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
#if NAZARA_GRAPHICS_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#undef delete
#undef new
#endif

View File

@@ -0,0 +1,21 @@
// 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_DRAWABLE_HPP
#define NAZARA_DRAWABLE_HPP
#include <Nazara/Prerequesites.hpp>
class NAZARA_API NzDrawable
{
public:
NzDrawable() = default;
~NzDrawable();
virtual void Draw() const = 0;
};
#endif // NAZARA_DRAWABLE_HPP

View File

@@ -0,0 +1,40 @@
// 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_ENUMS_GRAPHICS_HPP
#define NAZARA_ENUMS_GRAPHICS_HPP
enum nzBackgroundType
{
nzBackgroundType_Color, // NzColorBackground
nzBackgroundType_Skybox, // NzSkyboxBackground
nzBackgroundType_Texture, // NzTextureBackground
nzBackgroundType_User,
nzBackgroundType_Max = nzBackgroundType_User
};
enum nzLightType
{
nzLightType_Directional,
nzLightType_Point,
nzLightType_Spot,
nzLightType_Max = nzLightType_Spot
};
enum nzSceneNodeType
{
nzSceneNodeType_Camera, // NzCamera
nzSceneNodeType_Light, // NzLight
nzSceneNodeType_Model, // NzModel
nzSceneNodeType_Root, // NzSceneRoot
nzSceneNodeType_User,
nzSceneNodeType_Max = nzSceneNodeType_User
};
#endif // NAZARA_ENUMS_GRAPHICS_HPP

View File

@@ -0,0 +1,68 @@
// 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_LIGHT_HPP
#define NAZARA_LIGHT_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Graphics/SceneNode.hpp>
class NzShader;
class NAZARA_API NzLight : public NzSceneNode
{
public:
NzLight(nzLightType type);
NzLight(const NzLight& light);
~NzLight();
void AddToRenderQueue(NzRenderQueue& renderQueue) const;
void Apply(const NzShader* shader, unsigned int lightUnit) const;
const NzBoundingBoxf& GetBoundingBox() const;
NzColor GetAmbientColor() const;
float GetAttenuation() const;
NzColor GetDiffuseColor() const;
float GetInnerAngle() const;
nzLightType GetLightType() const;
float GetOuterAngle() const;
float GetRadius() const;
nzSceneNodeType GetSceneNodeType() const;
NzColor GetSpecularColor() const;
void SetAmbientColor(const NzColor& ambient);
void SetAttenuation(float attenuation);
void SetDiffuseColor(const NzColor& diffuse);
void SetInnerAngle(float innerAngle);
void SetOuterAngle(float outerAngle);
void SetRadius(float radius);
void SetSpecularColor(const NzColor& specular);
NzLight& operator=(const NzLight& light);
private:
void Invalidate();
void Register();
void Unregister();
void UpdateBoundingBox() const;
bool VisibilityTest(const NzFrustumf& frustum);
nzLightType m_type;
mutable NzBoundingBoxf m_boundingBox;
NzColor m_ambientColor;
NzColor m_diffuseColor;
NzColor m_specularColor;
mutable bool m_boundingBoxUpdated;
float m_attenuation;
float m_innerAngle;
float m_outerAngle;
float m_radius;
};
#endif // NAZARA_LIGHT_HPP

View File

@@ -0,0 +1,112 @@
// 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_MODEL_HPP
#define NAZARA_MODEL_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/Updatable.hpp>
#include <Nazara/Graphics/SceneNode.hpp>
#include <Nazara/Renderer/Material.hpp>
#include <Nazara/Utility/Animation.hpp>
#include <Nazara/Utility/Mesh.hpp>
struct NAZARA_API NzModelParameters
{
bool loadAnimation = true;
bool loadMaterials = true;
NzAnimationParams animation;
NzMaterialParams material;
NzMeshParams mesh;
bool IsValid() const;
};
class NzModel;
using NzModelLoader = NzResourceLoader<NzModel, NzModelParameters>;
class NAZARA_API NzModel : public NzSceneNode, public NzUpdatable
{
friend NzModelLoader;
friend class NzScene;
public:
NzModel();
NzModel(const NzModel& model);
NzModel(NzModel&& model);
~NzModel();
void AddToRenderQueue(NzRenderQueue& renderQueue) const;
void AdvanceAnimation(float elapsedTime);
void EnableAnimation(bool animation);
void EnableDraw(bool draw);
NzAnimation* GetAnimation() const;
const NzBoundingBoxf& GetBoundingBox() const;
NzMaterial* GetMaterial(unsigned int matIndex) const;
NzMaterial* GetMaterial(unsigned int skinIndex, unsigned int matIndex) const;
unsigned int GetMaterialCount() const;
unsigned int GetSkin() const;
unsigned int GetSkinCount() const;
NzMesh* GetMesh() const;
nzSceneNodeType GetSceneNodeType() const override;
NzSkeleton* GetSkeleton();
const NzSkeleton* GetSkeleton() const;
bool HasAnimation() const;
bool IsAnimationEnabled() const;
bool IsDrawEnabled() const;
bool LoadFromFile(const NzString& filePath, const NzModelParameters& params = NzModelParameters());
bool LoadFromMemory(const void* data, std::size_t size, const NzModelParameters& params = NzModelParameters());
bool LoadFromStream(NzInputStream& stream, const NzModelParameters& params = NzModelParameters());
void Reset();
bool SetAnimation(NzAnimation* animation);
void SetMaterial(unsigned int matIndex, NzMaterial* material);
void SetMaterial(unsigned int skinIndex, unsigned int matIndex, NzMaterial* material);
void SetMesh(NzMesh* mesh);
bool SetSequence(const NzString& sequenceName);
void SetSequence(unsigned int sequenceIndex);
void SetSkin(unsigned int skin);
void SetSkinCount(unsigned int skinCount);
NzModel& operator=(const NzModel& node);
NzModel& operator=(NzModel&& node);
private:
void Invalidate() override;
void Register() override;
void Unregister() override;
void Update() override;
void UpdateBoundingBox() const;
bool VisibilityTest(const NzFrustumf& frustum) override;
std::vector<NzMaterialRef> m_materials;
mutable NzBoundingBoxf m_boundingBox;
NzSkeleton m_skeleton; // Uniquement pour les animations squelettiques
NzAnimationRef m_animation;
NzMeshRef m_mesh;
const NzSequence* m_currentSequence;
bool m_animationEnabled;
mutable bool m_boundingBoxUpdated;
bool m_drawEnabled;
float m_interpolation;
unsigned int m_currentFrame;
unsigned int m_matCount;
unsigned int m_nextFrame;
unsigned int m_skin;
unsigned int m_skinCount;
static NzModelLoader::LoaderList s_loaders;
};
#endif // NAZARA_MODEL_HPP

View File

@@ -0,0 +1,62 @@
// 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
#ifndef NAZARA_RENDERQUEUE_HPP
#define NAZARA_RENDERQUEUE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Utility/Mesh.hpp>
#include <map>
#include <vector>
class NzDrawable;
class NzLight;
class NzMaterial;
class NzModel;
class NzSkeletalMesh;
class NzStaticMesh;
class NAZARA_API NzRenderQueue
{
public:
struct MaterialComparator
{
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
};
struct SkeletalMeshComparator
{
bool operator()(const NzSkeletalMesh* subMesh1, const NzSkeletalMesh* subMesh2);
};
struct StaticMeshComparator
{
bool operator()(const NzStaticMesh* subMesh1, const NzStaticMesh* subMesh2);
};
NzRenderQueue() = default;
~NzRenderQueue() = default;
void Clear();
struct SkeletalData
{
NzMatrix4f transformMatrix;
///TODO: Déplacer vers un container séparé qui ne serait pas sujer à Clear();
std::vector<NzMeshVertex> skinnedVertices;
};
typedef std::map<NzSkeletalMesh*, std::vector<SkeletalData>, SkeletalMeshComparator> SkeletalMeshContainer;
typedef std::map<NzStaticMesh*, std::vector<NzMatrix4f>, StaticMeshComparator> StaticMeshContainer;
std::map<NzMaterial*, SkeletalMeshContainer, MaterialComparator> visibleSkeletalModels;
std::map<NzMaterial*, StaticMeshContainer, MaterialComparator> visibleStaticModels;
std::vector<const NzDrawable*> otherDrawables;
std::vector<const NzLight*> directionnalLights;
std::vector<const NzLight*> visibleLights;
};
#endif // NAZARA_RENDERQUEUE_HPP

View File

@@ -0,0 +1,63 @@
// 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_SCENE_HPP
#define NAZARA_SCENE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/Updatable.hpp>
#include <Nazara/Graphics/Background.hpp>
#include <Nazara/Math/Frustum.hpp>
class NzCamera;
class NzLight;
class NzModel;
class NzNode;
class NzRenderQueue;
class NzSceneNode;
struct NzSceneImpl;
class NAZARA_API NzScene
{
friend NzCamera;
public:
NzScene();
~NzScene();
void AddToVisibilityList(NzUpdatable* object);
void Cull();
void Draw();
const NzCamera* GetActiveCamera() const;
NzBackground* GetBackground() const;
NzSceneNode& GetRoot() const;
float GetUpdateTime() const;
unsigned int GetUpdatePerSecond() const;
void RegisterForUpdate(NzUpdatable* object);
void SetAmbientColor(const NzColor& color);
void SetBackground(NzBackground* background);
void SetUpdatePerSecond(unsigned int updatePerSecond);
void UnregisterForUpdate(NzUpdatable* object);
void Update();
void UpdateVisible();
operator const NzSceneNode&() const;
private:
void RecursiveFrustumCull(NzRenderQueue& renderQueue, const NzFrustumf& frustum, NzNode* node);
void SetActiveCamera(const NzCamera* camera);
NzSceneImpl* m_impl;
};
#endif // NAZARA_SCENE_HPP

View File

@@ -0,0 +1,53 @@
// 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/RenderQueue.hpp>
#include <Nazara/Graphics/Scene.hpp>
#include <Nazara/Math/BoundingBox.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(NzRenderQueue& renderQueue) const = 0;
virtual const NzBoundingBoxf& GetBoundingBox() 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 NzFrustumf& frustum) = 0;
NzScene* m_scene;
bool m_visible;
private:
void UpdateVisibility(const NzFrustumf& frustum);
};
#endif // NAZARA_SCENENODE_HPP

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_SCENEROOT_HPP
#define NAZARA_SCENEROOT_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/SceneNode.hpp>
struct NzSceneImpl;
class NAZARA_API NzSceneRoot : public NzSceneNode
{
friend struct NzSceneImpl;
public:
void AddToRenderQueue(NzRenderQueue& renderQueue) const override;
const NzBoundingBoxf& GetBoundingBox() const override;
nzSceneNodeType GetSceneNodeType() const override;
private:
NzSceneRoot(NzScene* scene);
virtual ~NzSceneRoot();
void Register();
void Unregister();
bool VisibilityTest(const NzFrustumf& frustum) override;
};
#endif // NAZARA_SCENEROOT_HPP

View File

@@ -0,0 +1,30 @@
// 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_TEXTUREBACKGROUND_HPP
#define NAZARA_TEXTUREBACKGROUND_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/Background.hpp>
#include <Nazara/Renderer/Texture.hpp>
class NAZARA_API NzTextureBackground : public NzBackground
{
public:
NzTextureBackground(NzTexture* texture);
void Draw() const;
nzBackgroundType GetBackgroundType() const;
NzTexture* GetTexture() const;
void SetTexture(NzTexture* texture);
private:
NzTextureRef m_texture;
};
#endif // NAZARA_TEXTUREBACKGROUND_HPP