Merge remote-tracking branch 'origin/master' into Resource-Update

Conflicts:
	include/Nazara/Audio/Music.hpp
	include/Nazara/Audio/SoundBuffer.hpp
	include/Nazara/Core/Resource.hpp
	include/Nazara/Core/ResourceListener.hpp
	include/Nazara/Graphics/Material.hpp
	include/Nazara/Renderer/Context.hpp
	include/Nazara/Renderer/RenderBuffer.hpp
	include/Nazara/Renderer/Shader.hpp
	include/Nazara/Renderer/Texture.hpp
	include/Nazara/Renderer/UberShader.hpp
	include/Nazara/Utility/Animation.hpp
	include/Nazara/Utility/Buffer.hpp
	include/Nazara/Utility/Image.hpp
	include/Nazara/Utility/IndexBuffer.hpp
	include/Nazara/Utility/Mesh.hpp
	include/Nazara/Utility/SkeletalMesh.hpp
	include/Nazara/Utility/Skeleton.hpp
	include/Nazara/Utility/StaticMesh.hpp
	include/Nazara/Utility/SubMesh.hpp
	include/Nazara/Utility/VertexBuffer.hpp
	include/Nazara/Utility/VertexDeclaration.hpp
	src/Nazara/Core/Resource.cpp
	src/Nazara/Core/ResourceListener.cpp
	src/Nazara/Graphics/DeferredRenderQueue.cpp
	src/Nazara/Graphics/ForwardRenderQueue.cpp
	src/Nazara/Graphics/SkinningManager.cpp
	src/Nazara/Renderer/RenderTexture.cpp
	src/Nazara/Renderer/Renderer.cpp
	src/Nazara/Utility/Mesh.cpp

Former-commit-id: 99b5ad26a19fe9c9f8118da7b5920bffe89f60f8
This commit is contained in:
Lynix
2015-01-25 19:29:55 +01:00
579 changed files with 11958 additions and 3706 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -8,15 +8,19 @@
#define NAZARA_ABSTRACTRENDERQUEUE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/SparsePtr.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/VertexStruct.hpp>
class NzDrawable;
class NzLight;
class NzMaterial;
class NzSprite;
class NzTexture;
struct NzMeshData;
class NAZARA_API NzAbstractRenderQueue : NzNonCopyable
@@ -25,10 +29,21 @@ class NAZARA_API NzAbstractRenderQueue : NzNonCopyable
NzAbstractRenderQueue() = default;
virtual ~NzAbstractRenderQueue();
// Je ne suis vraiment pas fan du nombre de surcharges pour AddBillboards,
// mais je n'ai pas d'autre solution tout aussi performante pour le moment...
virtual void AddBillboard(const NzMaterial* material, const NzVector3f& position, const NzVector2f& size, const NzVector2f& sinCos = NzVector2f(0.f, 1.f), const NzColor& color = NzColor::White) = 0;
virtual void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const NzVector2f> sizePtr, NzSparsePtr<const NzVector2f> sinCosPtr = nullptr, NzSparsePtr<const NzColor> colorPtr = nullptr) = 0;
virtual void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const NzVector2f> sizePtr, NzSparsePtr<const NzVector2f> sinCosPtr, NzSparsePtr<const float> alphaPtr) = 0;
virtual void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const NzVector2f> sizePtr, NzSparsePtr<const float> anglePtr, NzSparsePtr<const NzColor> colorPtr = nullptr) = 0;
virtual void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const NzVector2f> sizePtr, NzSparsePtr<const float> anglePtr, NzSparsePtr<const float> alphaPtr) = 0;
virtual void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const float> sizePtr, NzSparsePtr<const NzVector2f> sinCosPtr = nullptr, NzSparsePtr<const NzColor> colorPtr = nullptr) = 0;
virtual void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const float> sizePtr, NzSparsePtr<const NzVector2f> sinCosPtr, NzSparsePtr<const float> alphaPtr) = 0;
virtual void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const float> sizePtr, NzSparsePtr<const float> anglePtr, NzSparsePtr<const NzColor> colorPtr = nullptr) = 0;
virtual void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const float> sizePtr, NzSparsePtr<const float> anglePtr, NzSparsePtr<const float> alphaPtr) = 0;
virtual void AddDrawable(const NzDrawable* drawable) = 0;
virtual void AddLight(const NzLight* light) = 0;
virtual void AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) = 0;
virtual void AddSprite(const NzSprite* sprite) = 0;
virtual void AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const NzTexture* overlay = nullptr) = 0;
virtual void Clear(bool fully) = 0;
};

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -28,6 +28,9 @@ class NAZARA_API NzAbstractViewer
virtual NzVector3f GetEyePosition() const = 0;
virtual NzVector3f GetForward() const = 0;
virtual const NzFrustumf& GetFrustum() const = 0;
virtual NzVector3f GetGlobalForward() const = 0;
virtual NzVector3f GetGlobalRight() const = 0;
virtual NzVector3f GetGlobalUp() const = 0;
virtual const NzMatrix4f& GetProjectionMatrix() const = 0;
virtual const NzRenderTarget* GetTarget() const = 0;
virtual const NzMatrix4f& GetViewMatrix() const = 0;

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -9,12 +9,12 @@
#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>
#include <Nazara/Utility/Node.hpp>
class NAZARA_API NzCamera : public NzAbstractViewer, public NzNode, NzRenderTarget::Listener
{
@@ -32,6 +32,9 @@ class NAZARA_API NzCamera : public NzAbstractViewer, public NzNode, NzRenderTarg
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;

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -1,7 +1,7 @@
/*
Nazara Engine - Graphics module
Copyright (C) 2014 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Copyright (C) 2015 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

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -1,9 +1,9 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp
#if NAZARA_GRAPHICS_HPP
#if NAZARA_GRAPHICS_MANAGE_MEMORY
#undef delete
#undef new
#endif

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -25,6 +25,7 @@ class NAZARA_API NzDeferredFogPass : public NzDeferredRenderPass
NzRenderStates m_states;
NzShaderRef m_shader;
NzTextureSampler m_pointSampler;
int m_shaderEyePositionLocation;
};
#endif // NAZARA_DEFERREDFOGPASS_HPP

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -22,6 +22,18 @@ class NAZARA_API NzDeferredGeometryPass : public NzDeferredRenderPass
bool Resize(const NzVector2ui& dimensions);
protected:
struct ShaderUniforms;
const ShaderUniforms* GetShaderUniforms(const NzShader* shader) const;
struct ShaderUniforms
{
int eyePosition;
int sceneAmbient;
int textureOverlay;
};
mutable std::unordered_map<const NzShader*, ShaderUniforms> m_shaderUniforms;
NzRenderStates m_clearStates;
NzShaderRef m_clearShader;
};

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -39,7 +39,11 @@ class NAZARA_API NzDeferredPhongLightingPass : public NzDeferredRenderPass
NzStaticMesh* m_coneMesh;
NzStaticMesh* m_sphereMesh;
bool m_lightMeshesDrawing;
int m_directionalLightShaderEyePositionLocation;
int m_directionalLightShaderSceneAmbientLocation;
int m_pointSpotLightShaderDiscardLocation;
int m_pointSpotLightShaderEyePositionLocation;
int m_pointSpotLightShaderSceneAmbientLocation;
};
#endif // NAZARA_DEFERREDPHONGLIGHTINGPASS_HPP

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -11,52 +11,81 @@
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/ObjectListener.hpp>
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
#include <Nazara/Graphics/Material.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/MeshData.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
#include <map>
#include <tuple>
class NzForwardRenderQueue;
class NzMaterial;
class NzSkeletalMesh;
class NzStaticMesh;
class NAZARA_API NzDeferredRenderQueue : public NzAbstractRenderQueue, NzObjectListener
{
public:
NzDeferredRenderQueue(NzForwardRenderQueue* forwardQueue);
~NzDeferredRenderQueue();
~NzDeferredRenderQueue() = default;
void AddBillboard(const NzMaterial* material, const NzVector3f& position, const NzVector2f& size, const NzVector2f& sinCos = NzVector2f(0.f, 1.f), const NzColor& color = NzColor::White) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const NzVector2f> sizePtr, NzSparsePtr<const NzVector2f> sinCosPtr = nullptr, NzSparsePtr<const NzColor> colorPtr = nullptr) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const NzVector2f> sizePtr, NzSparsePtr<const NzVector2f> sinCosPtr, NzSparsePtr<const float> alphaPtr) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const NzVector2f> sizePtr, NzSparsePtr<const float> anglePtr, NzSparsePtr<const NzColor> colorPtr = nullptr) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const NzVector2f> sizePtr, NzSparsePtr<const float> anglePtr, NzSparsePtr<const float> alphaPtr) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const float> sizePtr, NzSparsePtr<const NzVector2f> sinCosPtr = nullptr, NzSparsePtr<const NzColor> colorPtr = nullptr) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const float> sizePtr, NzSparsePtr<const NzVector2f> sinCosPtr, NzSparsePtr<const float> alphaPtr) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const float> sizePtr, NzSparsePtr<const float> anglePtr, NzSparsePtr<const NzColor> colorPtr = nullptr) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const float> sizePtr, NzSparsePtr<const float> anglePtr, NzSparsePtr<const float> alphaPtr) override;
void AddDrawable(const NzDrawable* drawable) override;
void AddLight(const NzLight* light) override;
void AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) override;
void AddSprite(const NzSprite* sprite) override;
void AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const NzTexture* overlay = nullptr) override;
void Clear(bool fully);
struct BatchedModelMaterialComparator
{
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
};
struct BatchedSpriteMaterialComparator
{
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
};
struct MeshDataComparator
{
bool operator()(const NzMeshData& data1, const NzMeshData& data2);
};
typedef std::map<NzMeshData, std::vector<NzMatrix4f>, MeshDataComparator> MeshInstanceContainer;
typedef std::map<const NzMaterial*, std::tuple<bool, bool, MeshInstanceContainer>, BatchedModelMaterialComparator> ModelBatches;
typedef std::map<const NzMaterial*, std::vector<const NzSprite*>> BatchedSpriteContainer;
struct MeshInstanceEntry
{
MeshInstanceEntry(NzObjectListener* listener, int indexBufferValue, int vertexBufferValue) :
indexBufferListener(listener, indexBufferValue),
vertexBufferListener(listener, vertexBufferValue)
{
}
std::vector<NzMatrix4f> instances;
NzIndexBufferConstListener indexBufferListener;
NzVertexBufferConstListener vertexBufferListener;
};
typedef std::map<NzMeshData, MeshInstanceEntry, MeshDataComparator> MeshInstanceContainer;
struct BatchedModelMaterialComparator
{
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
};
struct BatchedModelEntry
{
BatchedModelEntry(NzObjectListener* listener, int materialValue) :
materialListener(listener, materialValue)
{
}
NzMaterialConstListener materialListener;
MeshInstanceContainer meshMap;
bool enabled = false;
bool instancingEnabled = false;
};
typedef std::map<const NzMaterial*, BatchedModelEntry, BatchedModelMaterialComparator> ModelBatches;
typedef std::vector<const NzLight*> LightContainer;
ModelBatches opaqueModels;
BatchedSpriteContainer sprites;
LightContainer directionalLights;
LightContainer pointLights;
LightContainer spotLights;

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -13,7 +13,7 @@ class NAZARA_API NzDrawable
{
public:
NzDrawable() = default;
~NzDrawable();
virtual ~NzDrawable();
virtual void Draw() const = 0;
};

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -43,6 +43,41 @@ enum nzMaterialUniform
nzMaterialUniform_Max = nzMaterialUniform_SpecularMap
};
enum nzParticleComponent
{
nzParticleComponent_Unused = -1,
nzParticleComponent_Color,
nzParticleComponent_Life,
nzParticleComponent_Mass,
nzParticleComponent_Normal,
nzParticleComponent_Position,
nzParticleComponent_Radius,
nzParticleComponent_Rotation,
nzParticleComponent_Size,
nzParticleComponent_Velocity,
nzParticleComponent_Userdata0,
nzParticleComponent_Userdata1,
nzParticleComponent_Userdata2,
nzParticleComponent_Userdata3,
nzParticleComponent_Userdata4,
nzParticleComponent_Userdata5,
nzParticleComponent_Userdata6,
nzParticleComponent_Userdata7,
nzParticleComponent_Userdata8,
nzParticleComponent_Max = nzParticleComponent_Userdata8
};
enum nzParticleLayout
{
nzParticleLayout_Billboard,
nzParticleLayout_Model,
nzParticleLayout_Sprite,
nzParticleLayout_Max = nzParticleLayout_Sprite
};
enum nzRenderPassType
{
nzRenderPassType_AA,
@@ -71,10 +106,12 @@ enum nzRenderTechniqueType
enum nzSceneNodeType
{
nzSceneNodeType_Light, // NzLight
nzSceneNodeType_Model, // NzModel
nzSceneNodeType_Root, // NzSceneRoot
nzSceneNodeType_Sprite, // NzSprite
nzSceneNodeType_Light, // NzLight
nzSceneNodeType_Model, // NzModel
nzSceneNodeType_ParticleEmitter, // NzParticleEmitter
nzSceneNodeType_Root, // NzSceneRoot
nzSceneNodeType_Sprite, // NzSprite
nzSceneNodeType_TextSprite, // NzTextSprite
nzSceneNodeType_User,
nzSceneNodeType_Max = nzSceneNodeType_User
@@ -85,10 +122,13 @@ enum nzShaderFlags
{
nzShaderFlags_None = 0,
nzShaderFlags_Deferred = 0x1,
nzShaderFlags_Instancing = 0x2,
nzShaderFlags_Billboard = 0x01,
nzShaderFlags_Deferred = 0x02,
nzShaderFlags_Instancing = 0x04,
nzShaderFlags_TextureOverlay = 0x08,
nzShaderFlags_VertexColor = 0x10,
nzShaderFlags_Max = nzShaderFlags_Instancing*2-1
nzShaderFlags_Max = nzShaderFlags_VertexColor*2-1
};
#endif // NAZARA_ENUMS_GRAPHICS_HPP

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -11,16 +11,16 @@
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/ObjectListener.hpp>
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
#include <Nazara/Graphics/Material.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/MeshData.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
#include <map>
#include <tuple>
class NzAbstractViewer;
class NzMaterial;
class NzSkeletalMesh;
class NzStaticMesh;
class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzObjectListener
{
@@ -28,12 +28,21 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzObjectLi
public:
NzForwardRenderQueue() = default;
~NzForwardRenderQueue();
~NzForwardRenderQueue() = default;
void AddBillboard(const NzMaterial* material, const NzVector3f& position, const NzVector2f& size, const NzVector2f& sinCos = NzVector2f(0.f, 1.f), const NzColor& color = NzColor::White) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const NzVector2f> sizePtr, NzSparsePtr<const NzVector2f> sinCosPtr = nullptr, NzSparsePtr<const NzColor> colorPtr = nullptr) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const NzVector2f> sizePtr, NzSparsePtr<const NzVector2f> sinCosPtr, NzSparsePtr<const float> alphaPtr) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const NzVector2f> sizePtr, NzSparsePtr<const float> anglePtr, NzSparsePtr<const NzColor> colorPtr = nullptr) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const NzVector2f> sizePtr, NzSparsePtr<const float> anglePtr, NzSparsePtr<const float> alphaPtr) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const float> sizePtr, NzSparsePtr<const NzVector2f> sinCosPtr = nullptr, NzSparsePtr<const NzColor> colorPtr = nullptr) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const float> sizePtr, NzSparsePtr<const NzVector2f> sinCosPtr, NzSparsePtr<const float> alphaPtr) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const float> sizePtr, NzSparsePtr<const float> anglePtr, NzSparsePtr<const NzColor> colorPtr = nullptr) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const float> sizePtr, NzSparsePtr<const float> anglePtr, NzSparsePtr<const float> alphaPtr) override;
void AddDrawable(const NzDrawable* drawable) override;
void AddLight(const NzLight* light) override;
void AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) override;
void AddSprite(const NzSprite* sprite) override;
void AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const NzTexture* overlay = nullptr) override;
void Clear(bool fully);
@@ -43,37 +52,128 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzObjectLi
bool OnObjectDestroy(const NzRefCounted* object, int index) override;
void OnObjectReleased(const NzRefCounted* object, int index) override;
struct TransparentModelData
/// Billboards
struct BillboardData
{
NzMatrix4f transformMatrix;
NzMeshData meshData;
NzSpheref boundingSphere;
const NzMaterial* material;
NzColor color;
NzVector3f center;
NzVector2f size;
NzVector2f sinCos;
};
struct BatchedModelMaterialComparator
struct BatchedBillboardComparator
{
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
};
struct BatchedBillboardEntry
{
BatchedBillboardEntry(NzObjectListener* listener, int materialValue) :
materialListener(listener, materialValue)
{
}
NzMaterialConstListener materialListener;
std::vector<BillboardData> billboards;
};
typedef std::map<const NzMaterial*, BatchedBillboardEntry, BatchedBillboardComparator> BatchedBillboardContainer;
/// Sprites
struct SpriteChain_XYZ_Color_UV
{
const NzVertexStruct_XYZ_Color_UV* vertices;
unsigned int spriteCount;
};
struct BatchedSpriteEntry
{
BatchedSpriteEntry(NzObjectListener* listener, int textureValue) :
textureListener(listener, textureValue)
{
}
std::vector<SpriteChain_XYZ_Color_UV> spriteChains;
NzTextureConstListener textureListener;
};
struct BatchedSpriteMaterialComparator
{
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
};
typedef std::map<const NzTexture*, BatchedSpriteEntry> BasicSpriteOverlayContainer;
struct BatchedBasicSpriteEntry
{
BatchedBasicSpriteEntry(NzObjectListener* listener, int materialValue) :
materialListener(listener, materialValue)
{
}
NzMaterialConstListener materialListener;
BasicSpriteOverlayContainer overlayMap;
bool enabled = false;
};
typedef std::map<const NzMaterial*, BatchedBasicSpriteEntry> BasicSpriteBatches;
/// Meshes
struct MeshDataComparator
{
bool operator()(const NzMeshData& data1, const NzMeshData& data2);
};
typedef std::map<NzMeshData, std::pair<NzSpheref, std::vector<NzMatrix4f>>, MeshDataComparator> MeshInstanceContainer;
typedef std::map<const NzMaterial*, std::tuple<bool, bool, MeshInstanceContainer>, BatchedModelMaterialComparator> ModelBatches;
typedef std::map<const NzMaterial*, std::vector<const NzSprite*>> BatchedSpriteContainer;
struct MeshInstanceEntry
{
MeshInstanceEntry(NzObjectListener* listener, int indexBufferValue, int vertexBufferValue) :
indexBufferListener(listener, indexBufferValue),
vertexBufferListener(listener, vertexBufferValue)
{
}
std::vector<NzMatrix4f> instances;
NzIndexBufferConstListener indexBufferListener;
NzSpheref squaredBoundingSphere;
NzVertexBufferConstListener vertexBufferListener;
};
typedef std::map<NzMeshData, MeshInstanceEntry, MeshDataComparator> MeshInstanceContainer;
struct BatchedModelMaterialComparator
{
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
};
struct BatchedModelEntry
{
BatchedModelEntry(NzObjectListener* listener, int materialValue) :
materialListener(listener, materialValue)
{
}
NzMaterialConstListener materialListener;
MeshInstanceContainer meshMap;
bool enabled = false;
bool instancingEnabled = false;
};
typedef std::map<const NzMaterial*, BatchedModelEntry, BatchedModelMaterialComparator> ModelBatches;
struct TransparentModelData
{
NzMatrix4f transformMatrix;
NzMeshData meshData;
NzSpheref squaredBoundingSphere;
const NzMaterial* material;
};
typedef std::vector<const NzLight*> LightContainer;
typedef std::vector<unsigned int> TransparentModelContainer;
BatchedBillboardContainer billboards;
BasicSpriteBatches basicSprites;
ModelBatches opaqueModels;
BatchedSpriteContainer sprites;
TransparentModelContainer transparentModels;
std::vector<TransparentModelData> transparentModelData;
std::vector<const NzDrawable*> otherDrawables;

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -19,7 +19,7 @@ class NAZARA_API NzForwardRenderTechnique : public NzAbstractRenderTechnique
{
public:
NzForwardRenderTechnique();
~NzForwardRenderTechnique();
~NzForwardRenderTechnique() = default;
void Clear(const NzScene* scene) const;
bool Draw(const NzScene* scene) const;
@@ -30,30 +30,46 @@ class NAZARA_API NzForwardRenderTechnique : public NzAbstractRenderTechnique
void SetMaxLightPassPerObject(unsigned int passCount);
static bool Initialize();
static void Uninitialize();
private:
struct LightUniforms;
struct ShaderUniforms;
void DrawBasicSprites(const NzScene* scene) const;
void DrawBillboards(const NzScene* scene) const;
void DrawOpaqueModels(const NzScene* scene) const;
void DrawSprites(const NzScene* scene) const;
void DrawTransparentModels(const NzScene* scene) const;
const LightUniforms* GetLightUniforms(const NzShader* shader) const;
const ShaderUniforms* GetShaderUniforms(const NzShader* shader) const;
struct LightUniforms
struct ShaderUniforms
{
NzLightUniforms uniforms;
bool exists;
int offset; // "Distance" entre Lights[0].type et Lights[1].type
NzLightUniforms lightUniforms;
bool hasLightUniforms;
/// Moins coûteux en mémoire que de stocker un NzLightUniforms par index de lumière,
/// à voir si ça fonctionne chez tout le monde
int lightOffset; // "Distance" entre Lights[0].type et Lights[1].type
// Autre uniformes
int eyePosition;
int sceneAmbient;
int textureOverlay;
};
mutable std::unordered_map<const NzShader*, LightUniforms> m_lightUniforms;
mutable std::unordered_map<const NzShader*, ShaderUniforms> m_shaderUniforms;
NzBuffer m_vertexBuffer;
mutable NzForwardRenderQueue m_renderQueue;
NzIndexBufferRef m_indexBuffer;
mutable NzLightManager m_directionalLights;
mutable NzLightManager m_lights;
NzVertexBuffer m_billboardPointBuffer;
NzVertexBuffer m_spriteBuffer;
unsigned int m_maxLightPassPerObject;
static NzIndexBuffer s_quadIndexBuffer;
static NzVertexBuffer s_quadVertexBuffer;
static NzVertexDeclaration s_billboardInstanceDeclaration;
static NzVertexDeclaration s_billboardVertexDeclaration;
};
#endif // NAZARA_FORWARDRENDERTECHNIQUE_HPP

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -0,0 +1,25 @@
// 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_GUILLOTINETEXTUREATLAS_HPP
#define NAZARA_GUILLOTINETEXTUREATLAS_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/GuillotineImageAtlas.hpp>
class NAZARA_API NzGuillotineTextureAtlas : public NzGuillotineImageAtlas
{
public:
NzGuillotineTextureAtlas() = default;
~NzGuillotineTextureAtlas() = default;
nzUInt32 GetStorage() const;
private:
NzAbstractImage* ResizeImage(NzAbstractImage* oldImage, const NzVector2ui& size) const override;
};
#endif // NAZARA_GUILLOTINETEXTUREATLAS_HPP

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -18,17 +18,19 @@ struct NzLightUniforms;
class NAZARA_API NzLight : public NzSceneNode
{
public:
NzLight(nzLightType type);
NzLight(nzLightType type = nzLightType_Point);
NzLight(const NzLight& light);
~NzLight() = default;
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
NzLight* Clone() const;
NzLight* Create() const;
void Enable(const NzShader* shader, const NzLightUniforms& uniforms, int offset = 0) const;
float GetAmbientFactor() const;
float GetAttenuation() const;
const NzBoundingVolumef& GetBoundingVolume() const;
NzColor GetColor() const;
float GetDiffuseFactor() const;
float GetInnerAngle() const;
@@ -54,15 +56,13 @@ class NAZARA_API NzLight : public NzSceneNode
private:
bool FrustumCull(const NzFrustumf& frustum) const override;
void InvalidateNode() override;
void MakeBoundingVolume() const override;
void Register() override;
void Unregister() override;
void UpdateBoundingVolume() const;
nzLightType m_type;
mutable NzBoundingVolumef m_boundingVolume;
NzColor m_color;
mutable bool m_boundingVolumeUpdated;
float m_ambientFactor;
float m_attenuation;
float m_diffuseFactor;

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -9,6 +9,7 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/ObjectListenerWrapper.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Resource.hpp>
@@ -35,7 +36,9 @@ struct NAZARA_API NzMaterialParams
class NzMaterial;
using NzMaterialConstListener = NzObjectListenerWrapper<const NzMaterial>;
using NzMaterialConstRef = NzObjectRef<const NzMaterial>;
using NzMaterialListener = NzObjectListenerWrapper<NzMaterial>;
using NzMaterialLoader = NzResourceLoader<NzMaterial, NzMaterialParams>;
using NzMaterialRef = NzObjectRef<NzMaterial>;
@@ -47,13 +50,13 @@ class NAZARA_API NzMaterial : public NzRefCounted, public NzResource
public:
NzMaterial();
NzMaterial(const NzMaterial& material);
NzMaterial(NzMaterial&& material);
~NzMaterial();
const NzShader* Apply(nzUInt32 shaderFlags = 0, nzUInt8 textureUnit = 0, nzUInt8* lastUsedUnit = nullptr) const;
void Enable(nzRendererParameter renderParameter, bool enable);
void EnableAlphaTest(bool alphaTest);
void EnableDepthSorting(bool depthSorting);
void EnableLighting(bool lighting);
void EnableTransform(bool transform);
@@ -89,6 +92,7 @@ class NAZARA_API NzMaterial : public NzRefCounted, public NzResource
bool HasSpecularMap() const;
bool IsAlphaTestEnabled() const;
bool IsDepthSortingEnabled() const;
bool IsEnabled(nzRendererParameter renderParameter) const;
bool IsLightingEnabled() const;
bool IsTransformEnabled() const;
@@ -128,7 +132,6 @@ class NAZARA_API NzMaterial : public NzRefCounted, public NzResource
void SetSrcBlend(nzBlendFunc func);
NzMaterial& operator=(const NzMaterial& material);
NzMaterial& operator=(NzMaterial&& material);
static NzMaterial* GetDefault();
@@ -136,11 +139,12 @@ class NAZARA_API NzMaterial : public NzRefCounted, public NzResource
struct ShaderInstance
{
const NzShader* shader;
NzUberShaderInstance* uberInstance;
NzUberShaderInstance* uberInstance = nullptr;
int uniforms[nzMaterialUniform_Max+1];
};
void Copy(const NzMaterial& material);
void Move(NzMaterial&& material);
void GenerateShader(nzUInt32 flags) const;
void InvalidateShaders();
@@ -162,6 +166,7 @@ class NAZARA_API NzMaterial : public NzRefCounted, public NzResource
NzUberShaderConstRef m_uberShader;
mutable ShaderInstance m_shaders[nzShaderFlags_Max+1];
bool m_alphaTestEnabled;
bool m_depthSortingEnabled;
bool m_lightingEnabled;
bool m_transformEnabled;
float m_alphaThreshold;

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -37,16 +37,17 @@ class NAZARA_API NzModel : public NzResource, public NzSceneNode
public:
NzModel();
NzModel(const NzModel& model);
NzModel(NzModel&& model);
virtual ~NzModel();
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
void AdvanceAnimation(float elapsedTime);
NzModel* Clone() const;
NzModel* Create() const;
void EnableAnimation(bool animation);
NzAnimation* GetAnimation() const;
const NzBoundingVolumef& GetBoundingVolume() const;
NzMaterial* GetMaterial(const NzString& subMeshName) const;
NzMaterial* GetMaterial(unsigned int matIndex) const;
NzMaterial* GetMaterial(unsigned int skinIndex, const NzString& subMeshName) const;
@@ -84,16 +85,12 @@ class NAZARA_API NzModel : public NzResource, public NzSceneNode
void SetSkinCount(unsigned int skinCount);
NzModel& operator=(const NzModel& node);
NzModel& operator=(NzModel&& node);
protected:
void InvalidateNode() override;
virtual void UpdateBoundingVolume() const;
void MakeBoundingVolume() const override;
std::vector<NzMaterialRef> m_materials;
mutable NzBoundingVolumef m_boundingVolume;
NzMeshRef m_mesh;
mutable bool m_boundingVolumeUpdated;
unsigned int m_matCount;
unsigned int m_skin;
unsigned int m_skinCount;

View File

@@ -0,0 +1,34 @@
// 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_PARTICLECONTROLLER_HPP
#define NAZARA_PARTICLECONTROLLER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ObjectListenerWrapper.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
class NzParticleController;
class NzParticleMapper;
class NzParticleSystem;
using NzParticleControllerConstListener = NzObjectListenerWrapper<const NzParticleController>;
using NzParticleControllerConstRef = NzObjectRef<const NzParticleController>;
using NzParticleControllerListener = NzObjectListenerWrapper<NzParticleController>;
using NzParticleControllerRef = NzObjectRef<NzParticleController>;
class NAZARA_API NzParticleController : public NzRefCounted
{
public:
NzParticleController() = default;
NzParticleController(const NzParticleController& controller);
virtual ~NzParticleController();
virtual void Apply(NzParticleSystem& system, NzParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime) = 0;
};
#endif // NAZARA_PARTICLECONTROLLER_HPP

View File

@@ -0,0 +1,70 @@
// 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_PARTICLEDECLARATION_HPP
#define NAZARA_PARTICLEDECLARATION_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ObjectListenerWrapper.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Utility/Enums.hpp>
class NzParticleDeclaration;
using NzParticleDeclarationConstListener = NzObjectListenerWrapper<const NzParticleDeclaration>;
using NzParticleDeclarationConstRef = NzObjectRef<const NzParticleDeclaration>;
using NzParticleDeclarationListener = NzObjectListenerWrapper<NzParticleDeclaration>;
using NzParticleDeclarationRef = NzObjectRef<NzParticleDeclaration>;
class NAZARA_API NzParticleDeclaration : public NzRefCounted
{
friend class NzGraphics;
public:
NzParticleDeclaration();
NzParticleDeclaration(const NzParticleDeclaration& declaration);
~NzParticleDeclaration();
void DisableComponent(nzParticleComponent component);
void EnableComponent(nzParticleComponent component, nzComponentType type, unsigned int offset);
void GetComponent(nzParticleComponent component, bool* enabled, nzComponentType* type, unsigned int* offset) const;
unsigned int GetStride() const;
void SetStride(unsigned int stride);
NzParticleDeclaration& operator=(const NzParticleDeclaration& declaration);
static NzParticleDeclaration* Get(nzParticleLayout layout);
static bool IsTypeSupported(nzComponentType type);
private:
static bool Initialize();
static void Uninitialize();
struct Component
{
nzComponentType type;
bool enabled = false;
unsigned int offset;
/*
** -Lynix:
** Il serait aussi possible de préciser le stride de façon indépendante, ce que je ne permets pas
** pour décomplexifier l'interface en enlevant quelque chose que je juge inutile.
** Si vous pensez que ça peut être utile, n'hésitez pas à me le faire savoir !
*/
};
Component m_components[nzParticleComponent_Max+1];
unsigned int m_stride;
static NzParticleDeclaration s_declarations[nzParticleLayout_Max+1];
};
#endif // NAZARA_PARTICLEDECLARATION_HPP

View File

@@ -0,0 +1,48 @@
// 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_PARTICLEEMITTER_HPP
#define NAZARA_PARTICLEEMITTER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/Node.hpp>
class NzParticleMapper;
class NzParticleSystem;
class NAZARA_API NzParticleEmitter : public NzNode
{
public:
NzParticleEmitter();
NzParticleEmitter(const NzParticleEmitter& emitter) = default;
NzParticleEmitter(NzParticleEmitter&& emitter) = default;
virtual ~NzParticleEmitter();
virtual void Emit(NzParticleSystem& system, float elapsedTime) const;
void EnableLagCompensation(bool enable);
unsigned int GetEmissionCount() const;
float GetEmissionRate() const;
bool IsLagCompensationEnabled() const;
void SetEmissionCount(unsigned int count);
void SetEmissionRate(float rate);
NzParticleEmitter& operator=(const NzParticleEmitter& emitter) = default;
NzParticleEmitter& operator=(NzParticleEmitter&& emitter) = default;
private:
virtual void SetupParticles(NzParticleMapper& mapper, unsigned int count) const = 0;
bool m_lagCompensationEnabled;
mutable float m_emissionAccumulator;
float m_emissionRate;
unsigned int m_emissionCount;
};
#endif // NAZARA_PARTICLEEMITTER_HPP

View File

@@ -0,0 +1,34 @@
// 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_PARTICLEGENERATOR_HPP
#define NAZARA_PARTICLEGENERATOR_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ObjectListenerWrapper.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
class NzParticleGenerator;
class NzParticleMapper;
class NzParticleSystem;
using NzParticleGeneratorConstListener = NzObjectListenerWrapper<const NzParticleGenerator>;
using NzParticleGeneratorConstRef = NzObjectRef<const NzParticleGenerator>;
using NzParticleGeneratorListener = NzObjectListenerWrapper<NzParticleGenerator>;
using NzParticleGeneratorRef = NzObjectRef<NzParticleGenerator>;
class NAZARA_API NzParticleGenerator : public NzRefCounted
{
public:
NzParticleGenerator() = default;
NzParticleGenerator(const NzParticleGenerator& generator);
virtual ~NzParticleGenerator();
virtual void Generate(NzParticleSystem& system, NzParticleMapper& mapper, unsigned int startId, unsigned int endId) = 0;
};
#endif // NAZARA_PARTICLEGENERATOR_HPP

View File

@@ -0,0 +1,31 @@
// 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_PARTICLEMAPPER_HPP
#define NAZARA_PARTICLEMAPPER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/SparsePtr.hpp>
#include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Graphics/ParticleDeclaration.hpp>
class NAZARA_API NzParticleMapper
{
public:
NzParticleMapper(void* buffer, const NzParticleDeclaration* declaration);
~NzParticleMapper();
template<typename T> NzSparsePtr<T> GetComponentPtr(nzParticleComponent component);
template<typename T> NzSparsePtr<const T> GetComponentPtr(nzParticleComponent component) const;
private:
const NzParticleDeclaration* m_declaration;
nzUInt8* m_ptr;
};
#include <Nazara/Graphics/ParticleMapper.inl>
#endif // NAZARA_PARTICLEMAPPER_HPP

View File

@@ -0,0 +1,50 @@
// 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/Core/Error.hpp>
#include <Nazara/Graphics/Debug.hpp>
template <typename T>
NzSparsePtr<T> NzParticleMapper::GetComponentPtr(nzParticleComponent component)
{
// Ensuite le composant qui nous intéresse
bool enabled;
nzComponentType type;
unsigned int offset;
m_declaration->GetComponent(component, &enabled, &type, &offset);
if (enabled)
{
///TODO: Vérifier le rapport entre le type de l'attribut et le type template ?
return NzSparsePtr<T>(m_ptr + offset, m_declaration->GetStride());
}
else
{
NazaraError("Attribute 0x" + NzString::Number(component, 16) + " is not enabled");
return NzSparsePtr<T>();
}
}
template <typename T>
NzSparsePtr<const T> NzParticleMapper::GetComponentPtr(nzParticleComponent component) const
{
// Ensuite le composant qui nous intéresse
bool enabled;
nzComponentType type;
unsigned int offset;
m_declaration->GetComponent(component, &enabled, &type, &offset);
if (enabled)
{
///TODO: Vérifier le rapport entre le type de l'attribut et le type template ?
return NzSparsePtr<const T>(m_ptr + offset, m_declaration->GetStride());
}
else
{
NazaraError("Attribute 0x" + NzString::Number(component, 16) + " is not enabled");
return NzSparsePtr<const T>();
}
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -0,0 +1,35 @@
// 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_PARTICLERENDERER_HPP
#define NAZARA_PARTICLERENDERER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ObjectListenerWrapper.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
class NzAbstractRenderQueue;
class NzParticleMapper;
class NzParticleRenderer;
class NzParticleSystem;
using NzParticleRendererConstListener = NzObjectListenerWrapper<const NzParticleRenderer>;
using NzParticleRendererConstRef = NzObjectRef<const NzParticleRenderer>;
using NzParticleRendererListener = NzObjectListenerWrapper<NzParticleRenderer>;
using NzParticleRendererRef = NzObjectRef<NzParticleRenderer>;
class NAZARA_API NzParticleRenderer : public NzRefCounted
{
public:
NzParticleRenderer() = default;
NzParticleRenderer(const NzParticleRenderer& renderer);
virtual ~NzParticleRenderer();
virtual void Render(const NzParticleSystem& system, const NzParticleMapper& mapper, unsigned int startId, unsigned int endId, NzAbstractRenderQueue* renderQueue) = 0;
};
#endif // NAZARA_PARTICLERENDERER_HPP

View File

@@ -0,0 +1,42 @@
// 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_PARTICLESTRUCT_HPP
#define NAZARA_PARTICLESTRUCT_HPP
#include <Nazara/Core/Color.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp>
struct NzParticleStruct_Billboard
{
NzColor color;
NzVector3f normal;
NzVector3f position;
NzVector3f velocity;
nzUInt32 life;
float rotation;
};
struct NzParticleStruct_Model
{
NzVector3f position;
NzVector3f velocity;
nzUInt32 life;
NzQuaternionf rotation;
};
struct NzParticleStruct_Sprite
{
NzColor color;
NzVector2f position;
NzVector2f velocity;
nzUInt32 life;
float rotation;
};
#endif // NAZARA_PARTICLESTRUCT_HPP

View File

@@ -0,0 +1,91 @@
// 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_PARTICLESYSTEM_HPP
#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/Math/BoundingVolume.hpp>
#include <memory>
#include <set>
#include <vector>
class NAZARA_API NzParticleSystem : public NzSceneNode, NzUpdatable
{
public:
NzParticleSystem(unsigned int maxParticleCount, nzParticleLayout layout);
NzParticleSystem(unsigned int maxParticleCount, const NzParticleDeclaration* declaration);
NzParticleSystem(const NzParticleSystem& emitter);
~NzParticleSystem();
void AddController(NzParticleController* controller);
void AddEmitter(NzParticleEmitter* emitter);
void AddGenerator(NzParticleGenerator* generator);
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const;
void ApplyControllers(NzParticleMapper& mapper, unsigned int particleCount, float elapsedTime, float& stepAccumulator);
void* CreateParticle();
void* CreateParticles(unsigned int count);
void EnableFixedStep(bool fixedStep);
void* GenerateParticle();
void* GenerateParticles(unsigned int count);
const NzParticleDeclaration* 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);
void KillParticles();
void RemoveController(NzParticleController* controller);
void RemoveEmitter(NzParticleEmitter* emitter);
void RemoveGenerator(NzParticleGenerator* generator);
void SetFixedStepSize(float stepSize);
void SetRenderer(NzParticleRenderer* renderer);
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;
std::vector<NzParticleControllerRef> m_controllers;
std::vector<NzParticleEmitter*> m_emitters;
std::vector<NzParticleGeneratorRef> m_generators;
NzParticleDeclarationConstRef m_declaration;
NzParticleRendererRef m_renderer;
bool m_fixedStepEnabled;
bool m_processing;
float m_stepAccumulator;
float m_stepSize;
unsigned int m_maxParticleCount;
unsigned int m_particleCount;
unsigned int m_particleSize;
};
#endif // NAZARA_PARTICLESYSTEM_HPP

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -8,42 +8,61 @@
#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 NzCamera;
class NzLight;
class NzModel;
class NzNode;
class NzRenderQueue;
class NzSceneNode;
struct NzSceneImpl;
class NAZARA_API NzScene
{
friend NzCamera;
friend NzSceneNode;
public:
NzScene();
~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;
NzSceneNode& GetRoot() const;
NzVector3f GetRight() const;
NzSceneNode& GetRoot();
const NzSceneNode& GetRoot() const;
NzAbstractViewer* GetViewer() const;
NzVector3f GetUp() const;
float GetUpdateTime() const;
unsigned int GetUpdatePerSecond() const;
@@ -51,6 +70,11 @@ class NAZARA_API NzScene
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);
@@ -66,9 +90,28 @@ class NAZARA_API NzScene
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);
NzSceneImpl* m_impl;
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

@@ -0,0 +1,139 @@
// 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,34 +0,0 @@
// Copyright (C) 2014 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

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -9,52 +9,78 @@
#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 NzAbstractRenderQueue;
class NzScene;
class NAZARA_API NzSceneNode : public NzNode
{
friend class NzScene;
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);
virtual const NzBoundingVolumef& GetBoundingVolume() const = 0;
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;
bool SetName(const NzString& name);
NzSceneNode& operator=(const NzSceneNode& sceneNode);
NzSceneNode& operator=(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,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -10,14 +10,15 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/SceneNode.hpp>
class NzScene;
class NAZARA_API NzSceneRoot : public NzSceneNode
{
friend struct NzSceneImpl;
friend NzScene;
public:
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
const NzBoundingVolumef& GetBoundingVolume() const override;
nzSceneNodeType GetSceneNodeType() const override;
bool IsDrawable() const;
@@ -26,6 +27,10 @@ class NAZARA_API NzSceneRoot : public NzSceneNode
NzSceneRoot(NzScene* scene);
virtual ~NzSceneRoot();
NzSceneRoot* Clone() const;
NzSceneRoot* Create() const;
void MakeBoundingVolume() const override;
void Register();
void Unregister();
};

View File

@@ -1,52 +0,0 @@
// Copyright (C) 2014 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,90 @@
// 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_SKELETALMODEL_HPP
#define NAZARA_SKELETALMODEL_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/Updatable.hpp>
#include <Nazara/Graphics/Model.hpp>
#include <Nazara/Utility/Animation.hpp>
#include <Nazara/Utility/Buffer.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
#include <vector>
struct NAZARA_API NzSkeletalModelParameters : public NzModelParameters
{
bool loadAnimation = true;
NzAnimationParams animation;
bool IsValid() const;
};
class NzSkeletalModel;
using NzSkeletalModelLoader = NzResourceLoader<NzSkeletalModel, NzSkeletalModelParameters>;
class NAZARA_API NzSkeletalModel : public NzModel, NzUpdatable
{
friend NzSkeletalModelLoader;
public:
NzSkeletalModel();
NzSkeletalModel(const NzSkeletalModel& model);
NzSkeletalModel(NzSkeletalModel&& model);
~NzSkeletalModel();
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
void AdvanceAnimation(float elapsedTime);
NzSkeletalModel* Clone() const;
NzSkeletalModel* Create() const;
void EnableAnimation(bool animation);
NzAnimation* GetAnimation() const;
NzSkeleton* GetSkeleton();
const NzSkeleton* GetSkeleton() const;
bool HasAnimation() const;
bool IsAnimated() const;
bool IsAnimationEnabled() const;
bool IsDrawable() const;
bool LoadFromFile(const NzString& filePath, const NzSkeletalModelParameters& params = NzSkeletalModelParameters());
bool LoadFromMemory(const void* data, std::size_t size, const NzSkeletalModelParameters& params = NzSkeletalModelParameters());
bool LoadFromStream(NzInputStream& stream, const NzSkeletalModelParameters& params = NzSkeletalModelParameters());
void Reset();
bool SetAnimation(NzAnimation* animation);
void SetMesh(NzMesh* mesh) override;
bool SetSequence(const NzString& sequenceName);
void SetSequence(unsigned int sequenceIndex);
NzSkeletalModel& operator=(const NzSkeletalModel& node);
NzSkeletalModel& operator=(NzSkeletalModel&& node);
private:
void MakeBoundingVolume() const override;
void Register() override;
void Unregister() override;
void Update() override;
NzAnimationRef m_animation;
NzSkeleton m_skeleton;
const NzSequence* m_currentSequence;
bool m_animationEnabled;
float m_interpolation;
unsigned int m_currentFrame;
unsigned int m_nextFrame;
static NzSkeletalModelLoader::LoaderList s_loaders;
};
#endif // NAZARA_SKELETALMODEL_HPP

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -10,6 +10,7 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/Material.hpp>
#include <Nazara/Graphics/SceneNode.hpp>
#include <Nazara/Utility/VertexStruct.hpp>
class NAZARA_API NzSprite : public NzSceneNode
{
@@ -17,12 +18,14 @@ class NAZARA_API NzSprite : public NzSceneNode
NzSprite();
NzSprite(NzTexture* texture);
NzSprite(const NzSprite& sprite);
NzSprite(NzSprite&& sprite);
~NzSprite();
~NzSprite() = default;
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
const NzBoundingVolumef& GetBoundingVolume() const override;
NzSprite* Clone() const;
NzSprite* Create() const;
const NzColor& GetColor() const;
NzMaterial* GetMaterial() const;
nzSceneNodeType GetSceneNodeType() const override;
const NzVector2f& GetSize() const;
@@ -30,23 +33,30 @@ class NAZARA_API NzSprite : public NzSceneNode
bool IsDrawable() const;
void SetColor(const NzColor& color);
void SetDefaultMaterial();
void SetMaterial(NzMaterial* material, bool resizeSprite = true);
void SetSize(const NzVector2f& size);
void SetSize(float sizeX, float sizeY);
void SetTexture(NzTexture* texture, bool resizeSprite = true);
void SetTextureCoords(const NzRectf& coords);
void SetTextureRect(const NzRectui& rect);
NzSprite& operator=(const NzSprite& sprite);
private:
void InvalidateNode() override;
void MakeBoundingVolume() const override;
void Register() override;
void Unregister() override;
void UpdateBoundingVolume() const;
void UpdateVertices() const;
mutable NzBoundingVolumef m_boundingVolume;
NzColor m_color;
NzMaterialRef m_material;
NzRectf m_textureCoords;
NzVector2f m_size;
mutable bool m_boundingVolumeUpdated;
mutable NzVertexStruct_XYZ_Color_UV m_vertices[4];
mutable bool m_verticesUpdated;
};
#endif // NAZARA_SPRITE_HPP

View File

@@ -0,0 +1,75 @@
// 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_TEXTSPRITE_HPP
#define NAZARA_TEXTSPRITE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/Material.hpp>
#include <Nazara/Graphics/SceneNode.hpp>
#include <Nazara/Utility/AbstractAtlas.hpp>
#include <Nazara/Utility/AbstractTextDrawer.hpp>
#include <Nazara/Utility/VertexStruct.hpp>
#include <memory>
#include <set>
class NAZARA_API NzTextSprite : public NzSceneNode, NzAbstractAtlas::Listener
{
public:
NzTextSprite();
NzTextSprite(const NzTextSprite& sprite);
~NzTextSprite();
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
void Clear();
NzTextSprite* Clone() const;
NzTextSprite* Create() const;
const NzColor& GetColor() const;
NzMaterial* GetMaterial() const;
nzSceneNodeType GetSceneNodeType() const override;
void InvalidateVertices();
bool IsDrawable() const;
void SetColor(const NzColor& color);
void SetDefaultMaterial();
void SetMaterial(NzMaterial* material);
void Update(const NzAbstractTextDrawer& drawer);
NzTextSprite& operator=(const NzTextSprite& text);
private:
void ClearAtlases();
void InvalidateNode() override;
void MakeBoundingVolume() const override;
bool OnAtlasCleared(const NzAbstractAtlas* atlas, void* userdata) override;
bool OnAtlasLayerChange(const NzAbstractAtlas* atlas, NzAbstractImage* oldLayer, NzAbstractImage* newLayer, void* userdata) override;
void OnAtlasReleased(const NzAbstractAtlas* atlas, void* userdata) override;
void Register() override;
void Unregister() override;
void UpdateVertices() const;
struct RenderIndices
{
unsigned int first;
unsigned int count;
};
std::set<const NzAbstractAtlas*> m_atlases;
mutable std::unordered_map<NzTexture*, RenderIndices> m_renderInfos;
mutable std::vector<NzVertexStruct_XY_Color> m_localVertices;
mutable std::vector<NzVertexStruct_XYZ_Color_UV> m_vertices;
NzColor m_color;
NzMaterialRef m_material;
NzRectui m_localBounds;
mutable bool m_verticesUpdated;
};
#endif // NAZARA_TEXTSPRITE_HPP

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Jérôme Leclercq
// 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
@@ -9,17 +9,18 @@
#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>
#include <Nazara/Utility/Node.hpp>
class NAZARA_API NzView : public NzAbstractViewer, public NzNode, NzRenderTarget::Listener
{
public:
NzView();
NzView(const NzVector2f& size);
~NzView();
void EnsureFrustumUpdate() const;
@@ -31,7 +32,11 @@ class NAZARA_API NzView : public NzAbstractViewer, public NzNode, NzRenderTarget
NzVector3f GetEyePosition() const;
NzVector3f GetForward() const;
const NzFrustumf& GetFrustum() const;
NzVector3f GetGlobalForward() const;
NzVector3f GetGlobalRight() const;
NzVector3f GetGlobalUp() const;
const NzMatrix4f& GetProjectionMatrix() const;
const NzVector2f& GetSize() const;
const NzRenderTarget* GetTarget() const;
const NzRectf& GetTargetRegion() const;
const NzMatrix4f& GetViewMatrix() const;
@@ -39,6 +44,8 @@ class NAZARA_API NzView : public NzAbstractViewer, public NzNode, NzRenderTarget
float GetZFar() const;
float GetZNear() const;
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);
@@ -63,6 +70,7 @@ class NAZARA_API NzView : public NzAbstractViewer, public NzNode, NzRenderTarget
mutable NzMatrix4f m_viewMatrix;
NzRectf m_targetRegion;
mutable NzRecti m_viewport;
NzVector2f m_size;
const NzRenderTarget* m_target;
mutable bool m_frustumUpdated;
mutable bool m_projectionMatrixUpdated;