Merge remote-tracking branch 'origin/Particle-Update'
Conflicts: include/Nazara/Graphics/Enums.hpp include/Nazara/Graphics/ForwardRenderQueue.hpp include/Nazara/Graphics/ForwardRenderTechnique.hpp include/Nazara/Graphics/Sprite.hpp src/Nazara/Graphics/DeferredRenderQueue.cpp src/Nazara/Graphics/ForwardRenderQueue.cpp src/Nazara/Graphics/ForwardRenderTechnique.cpp src/Nazara/Graphics/Material.cpp src/Nazara/Graphics/Resources/Shaders/Basic/core.frag.h src/Nazara/Graphics/Resources/Shaders/Basic/core.vert src/Nazara/Graphics/Resources/Shaders/Basic/core.vert.h src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.frag src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.frag.h src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.vert src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.vert.h src/Nazara/Graphics/Sprite.cpp Former-commit-id: 73139ce47d7721635d87c74b2ca1183c2f67c090
This commit is contained in:
@@ -8,7 +8,9 @@
|
||||
#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>
|
||||
@@ -27,6 +29,8 @@ class NAZARA_API NzAbstractRenderQueue : NzNonCopyable
|
||||
NzAbstractRenderQueue() = default;
|
||||
virtual ~NzAbstractRenderQueue();
|
||||
|
||||
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 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;
|
||||
|
||||
@@ -28,6 +28,8 @@ class NAZARA_API NzDeferredRenderQueue : public NzAbstractRenderQueue, NzResourc
|
||||
NzDeferredRenderQueue(NzForwardRenderQueue* forwardQueue);
|
||||
~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 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;
|
||||
@@ -42,7 +44,7 @@ class NAZARA_API NzDeferredRenderQueue : public NzAbstractRenderQueue, NzResourc
|
||||
|
||||
struct MeshInstanceEntry
|
||||
{
|
||||
MeshInstanceEntry(NzDeferredRenderQueue* listener, int indexBufferValue, int vertexBufferValue) :
|
||||
MeshInstanceEntry(NzResourceListener* listener, int indexBufferValue, int vertexBufferValue) :
|
||||
indexBufferListener(listener, indexBufferValue),
|
||||
vertexBufferListener(listener, vertexBufferValue)
|
||||
{
|
||||
@@ -62,7 +64,7 @@ class NAZARA_API NzDeferredRenderQueue : public NzAbstractRenderQueue, NzResourc
|
||||
|
||||
struct BatchedModelEntry
|
||||
{
|
||||
BatchedModelEntry(NzDeferredRenderQueue* listener, int materialValue) :
|
||||
BatchedModelEntry(NzResourceListener* listener, int materialValue) :
|
||||
materialListener(listener, materialValue)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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,11 +106,12 @@ enum nzRenderTechniqueType
|
||||
|
||||
enum nzSceneNodeType
|
||||
{
|
||||
nzSceneNodeType_Light, // NzLight
|
||||
nzSceneNodeType_Model, // NzModel
|
||||
nzSceneNodeType_Root, // NzSceneRoot
|
||||
nzSceneNodeType_Sprite, // NzSprite
|
||||
nzSceneNodeType_TextSprite, // NzTextSprite
|
||||
nzSceneNodeType_Light, // NzLight
|
||||
nzSceneNodeType_Model, // NzModel
|
||||
nzSceneNodeType_ParticleEmitter, // NzParticleEmitter
|
||||
nzSceneNodeType_Root, // NzSceneRoot
|
||||
nzSceneNodeType_Sprite, // NzSprite
|
||||
nzSceneNodeType_TextSprite, // NzTextSprite
|
||||
nzSceneNodeType_User,
|
||||
|
||||
nzSceneNodeType_Max = nzSceneNodeType_User
|
||||
@@ -86,10 +122,11 @@ enum nzShaderFlags
|
||||
{
|
||||
nzShaderFlags_None = 0,
|
||||
|
||||
nzShaderFlags_Deferred = 0x1,
|
||||
nzShaderFlags_Instancing = 0x2,
|
||||
nzShaderFlags_TextureOverlay = 0x4,
|
||||
nzShaderFlags_VertexColor = 0x8,
|
||||
nzShaderFlags_Billboard = 0x01,
|
||||
nzShaderFlags_Deferred = 0x02,
|
||||
nzShaderFlags_Instancing = 0x04,
|
||||
nzShaderFlags_TextureOverlay = 0x08,
|
||||
nzShaderFlags_VertexColor = 0x10,
|
||||
|
||||
nzShaderFlags_Max = nzShaderFlags_VertexColor*2-1
|
||||
};
|
||||
|
||||
@@ -30,6 +30,8 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
|
||||
NzForwardRenderQueue() = default;
|
||||
~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 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;
|
||||
@@ -43,6 +45,34 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
|
||||
bool OnResourceDestroy(const NzResource* resource, int index) override;
|
||||
void OnResourceReleased(const NzResource* resource, int index) override;
|
||||
|
||||
/// Billboards
|
||||
struct BillboardData
|
||||
{
|
||||
NzColor color;
|
||||
NzVector3f center;
|
||||
NzVector2f size;
|
||||
NzVector2f sinCos;
|
||||
};
|
||||
|
||||
struct BatchedBillboardComparator
|
||||
{
|
||||
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
|
||||
};
|
||||
|
||||
struct BatchedBillboardEntry
|
||||
{
|
||||
BatchedBillboardEntry(NzResourceListener* 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;
|
||||
@@ -51,7 +81,7 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
|
||||
|
||||
struct BatchedSpriteEntry
|
||||
{
|
||||
BatchedSpriteEntry(NzForwardRenderQueue* listener, int textureValue) :
|
||||
BatchedSpriteEntry(NzResourceListener* listener, int textureValue) :
|
||||
textureListener(listener, textureValue)
|
||||
{
|
||||
}
|
||||
@@ -69,7 +99,7 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
|
||||
|
||||
struct BatchedBasicSpriteEntry
|
||||
{
|
||||
BatchedBasicSpriteEntry(NzForwardRenderQueue* listener, int materialValue) :
|
||||
BatchedBasicSpriteEntry(NzResourceListener* listener, int materialValue) :
|
||||
materialListener(listener, materialValue)
|
||||
{
|
||||
}
|
||||
@@ -81,6 +111,7 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
|
||||
|
||||
typedef std::map<const NzMaterial*, BatchedBasicSpriteEntry> BasicSpriteBatches;
|
||||
|
||||
/// Meshes
|
||||
struct MeshDataComparator
|
||||
{
|
||||
bool operator()(const NzMeshData& data1, const NzMeshData& data2);
|
||||
@@ -88,7 +119,7 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
|
||||
|
||||
struct MeshInstanceEntry
|
||||
{
|
||||
MeshInstanceEntry(NzForwardRenderQueue* listener, int indexBufferValue, int vertexBufferValue) :
|
||||
MeshInstanceEntry(NzResourceListener* listener, int indexBufferValue, int vertexBufferValue) :
|
||||
indexBufferListener(listener, indexBufferValue),
|
||||
vertexBufferListener(listener, vertexBufferValue)
|
||||
{
|
||||
@@ -109,7 +140,7 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
|
||||
|
||||
struct BatchedModelEntry
|
||||
{
|
||||
BatchedModelEntry(NzForwardRenderQueue* listener, int materialValue) :
|
||||
BatchedModelEntry(NzResourceListener* listener, int materialValue) :
|
||||
materialListener(listener, materialValue)
|
||||
{
|
||||
}
|
||||
@@ -133,6 +164,7 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
|
||||
typedef std::vector<const NzLight*> LightContainer;
|
||||
typedef std::vector<unsigned int> TransparentModelContainer;
|
||||
|
||||
BatchedBillboardContainer billboards;
|
||||
BasicSpriteBatches basicSprites;
|
||||
ModelBatches opaqueModels;
|
||||
TransparentModelContainer transparentModels;
|
||||
|
||||
@@ -20,7 +20,7 @@ class NAZARA_API NzForwardRenderTechnique : public NzAbstractRenderTechnique, Nz
|
||||
{
|
||||
public:
|
||||
NzForwardRenderTechnique();
|
||||
~NzForwardRenderTechnique();
|
||||
~NzForwardRenderTechnique() = default;
|
||||
|
||||
void Clear(const NzScene* scene) const;
|
||||
bool Draw(const NzScene* scene) const;
|
||||
@@ -31,10 +31,14 @@ class NAZARA_API NzForwardRenderTechnique : public NzAbstractRenderTechnique, Nz
|
||||
|
||||
void SetMaxLightPassPerObject(unsigned int passCount);
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
struct ShaderUniforms;
|
||||
|
||||
void DrawBasicSprites(const NzScene* scene) const;
|
||||
void DrawBillboards(const NzScene* scene) const;
|
||||
void DrawOpaqueModels(const NzScene* scene) const;
|
||||
void DrawTransparentModels(const NzScene* scene) const;
|
||||
const ShaderUniforms* GetShaderUniforms(const NzShader* shader) const;
|
||||
@@ -55,12 +59,18 @@ class NAZARA_API NzForwardRenderTechnique : public NzAbstractRenderTechnique, Nz
|
||||
};
|
||||
|
||||
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
|
||||
|
||||
34
include/Nazara/Graphics/ParticleController.hpp
Normal file
34
include/Nazara/Graphics/ParticleController.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// 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_PARTICLECONTROLLER_HPP
|
||||
#define NAZARA_PARTICLECONTROLLER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||
#include <Nazara/Core/ResourceRef.hpp>
|
||||
|
||||
class NzParticleController;
|
||||
class NzParticleMapper;
|
||||
class NzParticleSystem;
|
||||
|
||||
using NzParticleControllerConstListener = NzResourceListenerWrapper<const NzParticleController>;
|
||||
using NzParticleControllerConstRef = NzResourceRef<const NzParticleController>;
|
||||
using NzParticleControllerListener = NzResourceListenerWrapper<NzParticleController>;
|
||||
using NzParticleControllerRef = NzResourceRef<NzParticleController>;
|
||||
|
||||
class NAZARA_API NzParticleController : public NzResource
|
||||
{
|
||||
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
|
||||
70
include/Nazara/Graphics/ParticleDeclaration.hpp
Normal file
70
include/Nazara/Graphics/ParticleDeclaration.hpp
Normal file
@@ -0,0 +1,70 @@
|
||||
// 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_PARTICLEDECLARATION_HPP
|
||||
#define NAZARA_PARTICLEDECLARATION_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||
#include <Nazara/Core/ResourceRef.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
|
||||
class NzParticleDeclaration;
|
||||
|
||||
using NzParticleDeclarationConstListener = NzResourceListenerWrapper<const NzParticleDeclaration>;
|
||||
using NzParticleDeclarationConstRef = NzResourceRef<const NzParticleDeclaration>;
|
||||
using NzParticleDeclarationListener = NzResourceListenerWrapper<NzParticleDeclaration>;
|
||||
using NzParticleDeclarationRef = NzResourceRef<NzParticleDeclaration>;
|
||||
|
||||
class NAZARA_API NzParticleDeclaration : public NzResource
|
||||
{
|
||||
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
|
||||
43
include/Nazara/Graphics/ParticleEmitter.hpp
Normal file
43
include/Nazara/Graphics/ParticleEmitter.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
// 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_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;
|
||||
|
||||
unsigned int GetEmissionCount() const;
|
||||
float GetEmissionRate() 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;
|
||||
|
||||
mutable float m_emissionAccumulator;
|
||||
float m_emissionRate;
|
||||
unsigned int m_emissionCount;
|
||||
};
|
||||
|
||||
#endif // NAZARA_PARTICLEEMITTER_HPP
|
||||
34
include/Nazara/Graphics/ParticleGenerator.hpp
Normal file
34
include/Nazara/Graphics/ParticleGenerator.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// 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_PARTICLEGENERATOR_HPP
|
||||
#define NAZARA_PARTICLEGENERATOR_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||
#include <Nazara/Core/ResourceRef.hpp>
|
||||
|
||||
class NzParticleGenerator;
|
||||
class NzParticleMapper;
|
||||
class NzParticleSystem;
|
||||
|
||||
using NzParticleGeneratorConstListener = NzResourceListenerWrapper<const NzParticleGenerator>;
|
||||
using NzParticleGeneratorConstRef = NzResourceRef<const NzParticleGenerator>;
|
||||
using NzParticleGeneratorListener = NzResourceListenerWrapper<NzParticleGenerator>;
|
||||
using NzParticleGeneratorRef = NzResourceRef<NzParticleGenerator>;
|
||||
|
||||
class NAZARA_API NzParticleGenerator : public NzResource
|
||||
{
|
||||
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
|
||||
31
include/Nazara/Graphics/ParticleMapper.hpp
Normal file
31
include/Nazara/Graphics/ParticleMapper.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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_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
|
||||
50
include/Nazara/Graphics/ParticleMapper.inl
Normal file
50
include/Nazara/Graphics/ParticleMapper.inl
Normal file
@@ -0,0 +1,50 @@
|
||||
// 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
|
||||
|
||||
#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>
|
||||
35
include/Nazara/Graphics/ParticleRenderer.hpp
Normal file
35
include/Nazara/Graphics/ParticleRenderer.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// 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_PARTICLERENDERER_HPP
|
||||
#define NAZARA_PARTICLERENDERER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||
#include <Nazara/Core/ResourceRef.hpp>
|
||||
|
||||
class NzAbstractRenderQueue;
|
||||
class NzParticleMapper;
|
||||
class NzParticleRenderer;
|
||||
class NzParticleSystem;
|
||||
|
||||
using NzParticleRendererConstListener = NzResourceListenerWrapper<const NzParticleRenderer>;
|
||||
using NzParticleRendererConstRef = NzResourceRef<const NzParticleRenderer>;
|
||||
using NzParticleRendererListener = NzResourceListenerWrapper<NzParticleRenderer>;
|
||||
using NzParticleRendererRef = NzResourceRef<NzParticleRenderer>;
|
||||
|
||||
class NAZARA_API NzParticleRenderer : public NzResource
|
||||
{
|
||||
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
|
||||
42
include/Nazara/Graphics/ParticleStruct.hpp
Normal file
42
include/Nazara/Graphics/ParticleStruct.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// 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_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
|
||||
93
include/Nazara/Graphics/ParticleSystem.hpp
Normal file
93
include/Nazara/Graphics/ParticleSystem.hpp
Normal file
@@ -0,0 +1,93 @@
|
||||
// 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_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* CreateParticle();
|
||||
void* CreateParticles(unsigned int count);
|
||||
|
||||
void EnableFixedStep(bool fixedStep);
|
||||
|
||||
void* GenerateParticle();
|
||||
void* GenerateParticles(unsigned int count);
|
||||
|
||||
const NzBoundingVolumef& GetBoundingVolume() const override;
|
||||
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 GenerateAABB() const;
|
||||
void Register() override;
|
||||
void ResizeBuffer();
|
||||
void Unregister() override;
|
||||
void UpdateBoundingVolume() const;
|
||||
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;
|
||||
mutable NzBoundingVolumef m_boundingVolume;
|
||||
NzParticleDeclarationConstRef m_declaration;
|
||||
NzParticleRendererRef m_renderer;
|
||||
mutable bool m_boundingVolumeUpdated;
|
||||
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
|
||||
Reference in New Issue
Block a user