Merge branch 'NDK-Refactor' into NDK
Conflicts: examples/HardwareInfo/main.cpp include/Nazara/Renderer/Enums.hpp include/Nazara/Renderer/GpuQuery.hpp include/Nazara/Renderer/OpenGL.hpp include/Nazara/Renderer/RenderBuffer.hpp include/Nazara/Renderer/RenderTexture.hpp include/Nazara/Renderer/Texture.hpp src/Nazara/Graphics/AbstractRenderTechnique.cpp src/Nazara/Graphics/DeferredRenderTechnique.cpp src/Nazara/Graphics/Material.cpp src/Nazara/Graphics/SkyboxBackground.cpp src/Nazara/Renderer/GpuQuery.cpp src/Nazara/Renderer/OpenGL.cpp src/Nazara/Renderer/RenderBuffer.cpp src/Nazara/Renderer/RenderTexture.cpp src/Nazara/Renderer/Renderer.cpp src/Nazara/Renderer/Shader.cpp src/Nazara/Renderer/ShaderStage.cpp src/Nazara/Renderer/Texture.cpp Former-commit-id: 2f1c7e9f9766f59ab83d9405856a1898ac4ab48f
This commit is contained in:
@@ -13,25 +13,33 @@
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
|
||||
class NzAbstractBackground;
|
||||
class NzAbstractViewer;
|
||||
|
||||
using NzBackgroundConstRef = NzObjectRef<const NzAbstractBackground>;
|
||||
using NzBackgroundLibrary = NzObjectLibrary<NzAbstractBackground>;
|
||||
using NzBackgroundRef = NzObjectRef<NzAbstractBackground>;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzAbstractBackground : public NzRefCounted
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzAbstractBackground() = default;
|
||||
virtual ~NzAbstractBackground();
|
||||
class AbstractBackground;
|
||||
class AbstractViewer;
|
||||
|
||||
virtual void Draw(const NzAbstractViewer* viewer) const = 0;
|
||||
using BackgroundConstRef = ObjectRef<const AbstractBackground>;
|
||||
using BackgroundLibrary = ObjectLibrary<AbstractBackground>;
|
||||
using BackgroundRef = ObjectRef<AbstractBackground>;
|
||||
|
||||
virtual nzBackgroundType GetBackgroundType() const = 0;
|
||||
class NAZARA_GRAPHICS_API AbstractBackground : public RefCounted
|
||||
{
|
||||
public:
|
||||
AbstractBackground() = default;
|
||||
AbstractBackground(const AbstractBackground&) = default;
|
||||
AbstractBackground(AbstractBackground&&) = delete;
|
||||
virtual ~AbstractBackground();
|
||||
|
||||
private:
|
||||
static NzBackgroundLibrary::LibraryMap s_library;
|
||||
};
|
||||
virtual void Draw(const AbstractViewer* viewer) const = 0;
|
||||
|
||||
virtual BackgroundType GetBackgroundType() const = 0;
|
||||
|
||||
AbstractBackground& operator=(const AbstractBackground&) = default;
|
||||
AbstractBackground& operator=(AbstractBackground&&) = delete;
|
||||
|
||||
private:
|
||||
static BackgroundLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_ABSTRACTBACKGROUND_HPP
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Core/SparsePtr.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
@@ -18,81 +17,86 @@
|
||||
#include <Nazara/Utility/VertexStruct.hpp>
|
||||
#include <vector>
|
||||
|
||||
class NzDrawable;
|
||||
class NzMaterial;
|
||||
class NzTexture;
|
||||
struct NzMeshData;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzAbstractRenderQueue
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
struct DirectionalLight;
|
||||
struct PointLight;
|
||||
struct SpotLight;
|
||||
class Drawable;
|
||||
class Material;
|
||||
class Texture;
|
||||
struct MeshData;
|
||||
|
||||
NzAbstractRenderQueue() = default;
|
||||
NzAbstractRenderQueue(const NzAbstractRenderQueue&) = delete;
|
||||
virtual ~NzAbstractRenderQueue();
|
||||
class NAZARA_GRAPHICS_API AbstractRenderQueue
|
||||
{
|
||||
public:
|
||||
struct DirectionalLight;
|
||||
struct PointLight;
|
||||
struct SpotLight;
|
||||
|
||||
// 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 AddDirectionalLight(const DirectionalLight& light);
|
||||
virtual void AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) = 0;
|
||||
virtual void AddPointLight(const PointLight& light);
|
||||
virtual void AddSpotLight(const SpotLight& light);
|
||||
virtual void AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const NzTexture* overlay = nullptr) = 0;
|
||||
AbstractRenderQueue() = default;
|
||||
AbstractRenderQueue(const AbstractRenderQueue&) = delete;
|
||||
AbstractRenderQueue(AbstractRenderQueue&&) = default;
|
||||
virtual ~AbstractRenderQueue();
|
||||
|
||||
virtual void Clear(bool fully = false);
|
||||
// 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 Material* material, const Vector3f& position, const Vector2f& size, const Vector2f& sinCos = Vector2f(0.f, 1.f), const Color& color = Color::White) = 0;
|
||||
virtual void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) = 0;
|
||||
virtual void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) = 0;
|
||||
virtual void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) = 0;
|
||||
virtual void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) = 0;
|
||||
virtual void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) = 0;
|
||||
virtual void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) = 0;
|
||||
virtual void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) = 0;
|
||||
virtual void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) = 0;
|
||||
virtual void AddDrawable(const Drawable* drawable) = 0;
|
||||
virtual void AddDirectionalLight(const DirectionalLight& light);
|
||||
virtual void AddMesh(const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix) = 0;
|
||||
virtual void AddPointLight(const PointLight& light);
|
||||
virtual void AddSpotLight(const SpotLight& light);
|
||||
virtual void AddSprites(const Material* material, const VertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const Texture* overlay = nullptr) = 0;
|
||||
|
||||
NzAbstractRenderQueue& operator=(const NzAbstractRenderQueue&) = delete;
|
||||
virtual void Clear(bool fully = false);
|
||||
|
||||
struct DirectionalLight
|
||||
{
|
||||
NzColor color;
|
||||
NzVector3f direction;
|
||||
float ambientFactor;
|
||||
float diffuseFactor;
|
||||
};
|
||||
AbstractRenderQueue& operator=(const AbstractRenderQueue&) = delete;
|
||||
AbstractRenderQueue& operator=(AbstractRenderQueue&&) = default;
|
||||
|
||||
struct PointLight
|
||||
{
|
||||
NzColor color;
|
||||
NzVector3f position;
|
||||
float ambientFactor;
|
||||
float attenuation;
|
||||
float diffuseFactor;
|
||||
float invRadius;
|
||||
float radius;
|
||||
};
|
||||
struct DirectionalLight
|
||||
{
|
||||
Color color;
|
||||
Vector3f direction;
|
||||
float ambientFactor;
|
||||
float diffuseFactor;
|
||||
};
|
||||
|
||||
struct SpotLight
|
||||
{
|
||||
NzColor color;
|
||||
NzVector3f direction;
|
||||
NzVector3f position;
|
||||
float ambientFactor;
|
||||
float attenuation;
|
||||
float diffuseFactor;
|
||||
float innerAngleCosine;
|
||||
float invRadius;
|
||||
float outerAngleCosine;
|
||||
float outerAngleTangent;
|
||||
float radius;
|
||||
};
|
||||
struct PointLight
|
||||
{
|
||||
Color color;
|
||||
Vector3f position;
|
||||
float ambientFactor;
|
||||
float attenuation;
|
||||
float diffuseFactor;
|
||||
float invRadius;
|
||||
float radius;
|
||||
};
|
||||
|
||||
std::vector<DirectionalLight> directionalLights;
|
||||
std::vector<PointLight> pointLights;
|
||||
std::vector<SpotLight> spotLights;
|
||||
};
|
||||
struct SpotLight
|
||||
{
|
||||
Color color;
|
||||
Vector3f direction;
|
||||
Vector3f position;
|
||||
float ambientFactor;
|
||||
float attenuation;
|
||||
float diffuseFactor;
|
||||
float innerAngleCosine;
|
||||
float invRadius;
|
||||
float outerAngleCosine;
|
||||
float outerAngleTangent;
|
||||
float radius;
|
||||
};
|
||||
|
||||
std::vector<DirectionalLight> directionalLights;
|
||||
std::vector<PointLight> pointLights;
|
||||
std::vector<SpotLight> spotLights;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_ABSTRACTRENDERQUEUE_HPP
|
||||
|
||||
@@ -9,37 +9,41 @@
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
#include <Nazara/Graphics/SceneData.hpp>
|
||||
|
||||
class NzAbstractViewer;
|
||||
class NzBackground;
|
||||
struct SceneData;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzAbstractRenderTechnique
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzAbstractRenderTechnique();
|
||||
NzAbstractRenderTechnique(const NzAbstractRenderTechnique&) = delete;
|
||||
virtual ~NzAbstractRenderTechnique();
|
||||
class AbstractViewer;
|
||||
class Background;
|
||||
struct SceneData;
|
||||
|
||||
virtual bool Draw(const NzSceneData& sceneData) const = 0;
|
||||
class NAZARA_GRAPHICS_API AbstractRenderTechnique
|
||||
{
|
||||
public:
|
||||
AbstractRenderTechnique();
|
||||
AbstractRenderTechnique(const AbstractRenderTechnique&) = delete;
|
||||
AbstractRenderTechnique(AbstractRenderTechnique&&) = default;
|
||||
virtual ~AbstractRenderTechnique();
|
||||
|
||||
virtual void EnableInstancing(bool instancing);
|
||||
virtual bool Draw(const SceneData& sceneData) const = 0;
|
||||
|
||||
virtual NzString GetName() const;
|
||||
virtual NzAbstractRenderQueue* GetRenderQueue() = 0;
|
||||
virtual nzRenderTechniqueType GetType() const = 0;
|
||||
virtual void EnableInstancing(bool instancing);
|
||||
|
||||
virtual bool IsInstancingEnabled() const;
|
||||
virtual String GetName() const;
|
||||
virtual AbstractRenderQueue* GetRenderQueue() = 0;
|
||||
virtual RenderTechniqueType GetType() const = 0;
|
||||
|
||||
NzAbstractRenderTechnique& operator=(const NzAbstractRenderTechnique&) = delete;
|
||||
virtual bool IsInstancingEnabled() const;
|
||||
|
||||
protected:
|
||||
bool m_instancingEnabled;
|
||||
};
|
||||
AbstractRenderTechnique& operator=(const AbstractRenderTechnique&) = delete;
|
||||
AbstractRenderTechnique& operator=(AbstractRenderTechnique&&) = default;
|
||||
|
||||
protected:
|
||||
bool m_instancingEnabled;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_ABSTRACTRENDERTECHNIQUE_HPP
|
||||
|
||||
@@ -14,27 +14,34 @@
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
|
||||
class NzRenderTarget;
|
||||
class NzScene;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzAbstractViewer
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzAbstractViewer() = default;
|
||||
virtual ~NzAbstractViewer();
|
||||
class RenderTarget;
|
||||
|
||||
virtual void ApplyView() const = 0;
|
||||
class NAZARA_GRAPHICS_API AbstractViewer
|
||||
{
|
||||
public:
|
||||
AbstractViewer() = default;
|
||||
AbstractViewer(const AbstractViewer&) = default;
|
||||
AbstractViewer(AbstractViewer&&) noexcept = default;
|
||||
virtual ~AbstractViewer();
|
||||
|
||||
virtual float GetAspectRatio() const = 0;
|
||||
virtual NzVector3f GetEyePosition() const = 0;
|
||||
virtual NzVector3f GetForward() const = 0;
|
||||
virtual const NzFrustumf& GetFrustum() const = 0;
|
||||
virtual const NzMatrix4f& GetProjectionMatrix() const = 0;
|
||||
virtual const NzRenderTarget* GetTarget() const = 0;
|
||||
virtual const NzMatrix4f& GetViewMatrix() const = 0;
|
||||
virtual const NzRecti& GetViewport() const = 0;
|
||||
virtual float GetZFar() const = 0;
|
||||
virtual float GetZNear() const = 0;
|
||||
};
|
||||
virtual void ApplyView() const = 0;
|
||||
|
||||
virtual float GetAspectRatio() const = 0;
|
||||
virtual Vector3f GetEyePosition() const = 0;
|
||||
virtual Vector3f GetForward() const = 0;
|
||||
virtual const Frustumf& GetFrustum() const = 0;
|
||||
virtual const Matrix4f& GetProjectionMatrix() const = 0;
|
||||
virtual const RenderTarget* GetTarget() const = 0;
|
||||
virtual const Matrix4f& GetViewMatrix() const = 0;
|
||||
virtual const Recti& GetViewport() const = 0;
|
||||
virtual float GetZFar() const = 0;
|
||||
virtual float GetZNear() const = 0;
|
||||
|
||||
AbstractViewer& operator=(const AbstractViewer&) = default;
|
||||
AbstractViewer& operator=(AbstractViewer&&) noexcept = default;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_ABSTRACTVIEWER_HPP
|
||||
|
||||
@@ -11,51 +11,56 @@
|
||||
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
|
||||
class NzBillboard;
|
||||
|
||||
using NzBillboardConstRef = NzObjectRef<const NzBillboard>;
|
||||
using NzBillboardLibrary = NzObjectLibrary<NzBillboard>;
|
||||
using NzBillboardRef = NzObjectRef<NzBillboard>;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzBillboard : public NzInstancedRenderable
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
inline NzBillboard();
|
||||
inline NzBillboard(NzMaterialRef material);
|
||||
inline NzBillboard(NzTexture* texture);
|
||||
inline NzBillboard(const NzBillboard& billboard);
|
||||
~NzBillboard() = default;
|
||||
class Billboard;
|
||||
|
||||
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
|
||||
using BillboardConstRef = ObjectRef<const Billboard>;
|
||||
using BillboardLibrary = ObjectLibrary<Billboard>;
|
||||
using BillboardRef = ObjectRef<Billboard>;
|
||||
|
||||
inline const NzColor& GetColor() const;
|
||||
inline const NzMaterialRef& GetMaterial() const;
|
||||
inline float GetRotation() const;
|
||||
inline const NzVector2f& GetSize() const;
|
||||
class NAZARA_GRAPHICS_API Billboard : public InstancedRenderable
|
||||
{
|
||||
public:
|
||||
inline Billboard();
|
||||
inline Billboard(MaterialRef material);
|
||||
inline Billboard(Texture* texture);
|
||||
inline Billboard(const Billboard& billboard);
|
||||
Billboard(Billboard&&) = delete;
|
||||
~Billboard() = default;
|
||||
|
||||
inline void SetColor(const NzColor& color);
|
||||
inline void SetDefaultMaterial();
|
||||
inline void SetMaterial(NzMaterialRef material, bool resizeBillboard = true);
|
||||
inline void SetRotation(float rotation);
|
||||
inline void SetSize(const NzVector2f& size);
|
||||
inline void SetSize(float sizeX, float sizeY);
|
||||
inline void SetTexture(NzTextureRef texture, bool resizeBillboard = true);
|
||||
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
|
||||
|
||||
inline NzBillboard& operator=(const NzBillboard& billboard);
|
||||
inline const Color& GetColor() const;
|
||||
inline const MaterialRef& GetMaterial() const;
|
||||
inline float GetRotation() const;
|
||||
inline const Vector2f& GetSize() const;
|
||||
|
||||
template<typename... Args> static NzBillboardRef New(Args&&... args);
|
||||
inline void SetColor(const Color& color);
|
||||
inline void SetDefaultMaterial();
|
||||
inline void SetMaterial(MaterialRef material, bool resizeBillboard = true);
|
||||
inline void SetRotation(float rotation);
|
||||
inline void SetSize(const Vector2f& size);
|
||||
inline void SetSize(float sizeX, float sizeY);
|
||||
inline void SetTexture(TextureRef texture, bool resizeBillboard = true);
|
||||
|
||||
private:
|
||||
void MakeBoundingVolume() const override;
|
||||
inline Billboard& operator=(const Billboard& billboard);
|
||||
Billboard& operator=(Billboard&&) = delete;
|
||||
|
||||
NzColor m_color;
|
||||
NzMaterialRef m_material;
|
||||
NzVector2f m_sinCos;
|
||||
NzVector2f m_size;
|
||||
float m_rotation;
|
||||
template<typename... Args> static BillboardRef New(Args&&... args);
|
||||
|
||||
static NzBillboardLibrary::LibraryMap s_library;
|
||||
};
|
||||
private:
|
||||
void MakeBoundingVolume() const override;
|
||||
|
||||
Color m_color;
|
||||
MaterialRef m_material;
|
||||
Vector2f m_sinCos;
|
||||
Vector2f m_size;
|
||||
float m_rotation;
|
||||
|
||||
static BillboardLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/Billboard.inl>
|
||||
|
||||
|
||||
@@ -5,137 +5,140 @@
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
inline NzBillboard::NzBillboard()
|
||||
namespace Nz
|
||||
{
|
||||
SetColor(NzColor::White);
|
||||
SetDefaultMaterial();
|
||||
SetRotation(0.f);
|
||||
SetSize(64.f, 64.f);
|
||||
}
|
||||
|
||||
inline NzBillboard::NzBillboard(NzMaterialRef material)
|
||||
{
|
||||
SetColor(NzColor::White);
|
||||
SetMaterial(std::move(material), true);
|
||||
SetRotation(0.f);
|
||||
SetSize(64.f, 64.f);
|
||||
}
|
||||
|
||||
inline NzBillboard::NzBillboard(NzTexture* texture)
|
||||
{
|
||||
SetColor(NzColor::White);
|
||||
SetRotation(0.f);
|
||||
SetSize(64.f, 64.f);
|
||||
SetTexture(texture, true);
|
||||
}
|
||||
|
||||
inline NzBillboard::NzBillboard(const NzBillboard& billboard) :
|
||||
NzInstancedRenderable(billboard),
|
||||
m_color(billboard.m_color),
|
||||
m_material(billboard.m_material),
|
||||
m_rotation(billboard.m_rotation),
|
||||
m_sinCos(billboard.m_sinCos),
|
||||
m_size(billboard.m_size)
|
||||
{
|
||||
}
|
||||
|
||||
inline const NzColor& NzBillboard::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
inline const NzMaterialRef& NzBillboard::GetMaterial() const
|
||||
{
|
||||
return m_material;
|
||||
}
|
||||
|
||||
inline float NzBillboard::GetRotation() const
|
||||
{
|
||||
return m_rotation;
|
||||
}
|
||||
|
||||
inline const NzVector2f& NzBillboard::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
inline void NzBillboard::SetColor(const NzColor& color)
|
||||
{
|
||||
m_color = color;
|
||||
}
|
||||
|
||||
inline void NzBillboard::SetDefaultMaterial()
|
||||
{
|
||||
NzMaterialRef material = NzMaterial::New();
|
||||
material->Enable(nzRendererParameter_FaceCulling, true);
|
||||
material->EnableLighting(false);
|
||||
|
||||
SetMaterial(std::move(material));
|
||||
}
|
||||
|
||||
inline void NzBillboard::SetMaterial(NzMaterialRef material, bool resizeBillboard)
|
||||
{
|
||||
m_material = std::move(material);
|
||||
if (m_material && resizeBillboard)
|
||||
inline Billboard::Billboard()
|
||||
{
|
||||
NzTexture* diffuseMap = m_material->GetDiffuseMap();
|
||||
if (diffuseMap && diffuseMap->IsValid())
|
||||
SetSize(NzVector2f(NzVector2ui(diffuseMap->GetSize())));
|
||||
SetColor(Color::White);
|
||||
SetDefaultMaterial();
|
||||
SetRotation(0.f);
|
||||
SetSize(64.f, 64.f);
|
||||
}
|
||||
|
||||
inline Billboard::Billboard(MaterialRef material)
|
||||
{
|
||||
SetColor(Color::White);
|
||||
SetMaterial(std::move(material), true);
|
||||
SetRotation(0.f);
|
||||
SetSize(64.f, 64.f);
|
||||
}
|
||||
|
||||
inline Billboard::Billboard(Texture* texture)
|
||||
{
|
||||
SetColor(Color::White);
|
||||
SetRotation(0.f);
|
||||
SetSize(64.f, 64.f);
|
||||
SetTexture(texture, true);
|
||||
}
|
||||
|
||||
inline Billboard::Billboard(const Billboard& billboard) :
|
||||
InstancedRenderable(billboard),
|
||||
m_color(billboard.m_color),
|
||||
m_material(billboard.m_material),
|
||||
m_rotation(billboard.m_rotation),
|
||||
m_sinCos(billboard.m_sinCos),
|
||||
m_size(billboard.m_size)
|
||||
{
|
||||
}
|
||||
|
||||
inline const Color& Billboard::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
inline const MaterialRef& Billboard::GetMaterial() const
|
||||
{
|
||||
return m_material;
|
||||
}
|
||||
|
||||
inline float Billboard::GetRotation() const
|
||||
{
|
||||
return m_rotation;
|
||||
}
|
||||
|
||||
inline const Vector2f& Billboard::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
inline void Billboard::SetColor(const Color& color)
|
||||
{
|
||||
m_color = color;
|
||||
}
|
||||
|
||||
inline void Billboard::SetDefaultMaterial()
|
||||
{
|
||||
MaterialRef material = Material::New();
|
||||
material->Enable(RendererParameter_FaceCulling, true);
|
||||
material->EnableLighting(false);
|
||||
|
||||
SetMaterial(std::move(material));
|
||||
}
|
||||
|
||||
inline void Billboard::SetMaterial(MaterialRef material, bool resizeBillboard)
|
||||
{
|
||||
m_material = std::move(material);
|
||||
if (m_material && resizeBillboard)
|
||||
{
|
||||
Texture* diffuseMap = m_material->GetDiffuseMap();
|
||||
if (diffuseMap && diffuseMap->IsValid())
|
||||
SetSize(Vector2f(Vector2ui(diffuseMap->GetSize())));
|
||||
}
|
||||
}
|
||||
|
||||
inline void Billboard::SetRotation(float rotation)
|
||||
{
|
||||
m_rotation = rotation;
|
||||
m_sinCos.Set(std::sin(m_rotation), std::cos(m_rotation));
|
||||
}
|
||||
|
||||
inline void Billboard::SetSize(const Vector2f& size)
|
||||
{
|
||||
m_size = size;
|
||||
|
||||
// On invalide la bounding box
|
||||
InvalidateBoundingVolume();
|
||||
}
|
||||
|
||||
inline void Billboard::SetSize(float sizeX, float sizeY)
|
||||
{
|
||||
SetSize(Vector2f(sizeX, sizeY));
|
||||
}
|
||||
|
||||
inline void Billboard::SetTexture(TextureRef texture, bool resizeBillboard)
|
||||
{
|
||||
if (!m_material)
|
||||
SetDefaultMaterial();
|
||||
else if (m_material->GetReferenceCount() > 1)
|
||||
m_material = Material::New(*m_material); // Copie
|
||||
|
||||
if (resizeBillboard && texture && texture->IsValid())
|
||||
SetSize(Vector2f(Vector2ui(texture->GetSize())));
|
||||
|
||||
m_material->SetDiffuseMap(std::move(texture));
|
||||
}
|
||||
|
||||
inline Billboard& Billboard::operator=(const Billboard& billboard)
|
||||
{
|
||||
InstancedRenderable::operator=(billboard);
|
||||
|
||||
m_color = billboard.m_color;
|
||||
m_material = billboard.m_material;
|
||||
m_size = billboard.m_size;
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
BillboardRef Billboard::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<Billboard> object(new Billboard(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
inline void NzBillboard::SetRotation(float rotation)
|
||||
{
|
||||
m_rotation = rotation;
|
||||
m_sinCos.Set(std::sin(m_rotation), std::cos(m_rotation));
|
||||
}
|
||||
|
||||
inline void NzBillboard::SetSize(const NzVector2f& size)
|
||||
{
|
||||
m_size = size;
|
||||
|
||||
// On invalide la bounding box
|
||||
InvalidateBoundingVolume();
|
||||
}
|
||||
|
||||
inline void NzBillboard::SetSize(float sizeX, float sizeY)
|
||||
{
|
||||
SetSize(NzVector2f(sizeX, sizeY));
|
||||
}
|
||||
|
||||
inline void NzBillboard::SetTexture(NzTextureRef texture, bool resizeBillboard)
|
||||
{
|
||||
if (!m_material)
|
||||
SetDefaultMaterial();
|
||||
else if (m_material->GetReferenceCount() > 1)
|
||||
m_material = NzMaterial::New(*m_material); // Copie
|
||||
|
||||
if (resizeBillboard && texture && texture->IsValid())
|
||||
SetSize(NzVector2f(NzVector2ui(texture->GetSize())));
|
||||
|
||||
m_material->SetDiffuseMap(std::move(texture));
|
||||
}
|
||||
|
||||
inline NzBillboard& NzBillboard::operator=(const NzBillboard& billboard)
|
||||
{
|
||||
NzInstancedRenderable::operator=(billboard);
|
||||
|
||||
m_color = billboard.m_color;
|
||||
m_material = billboard.m_material;
|
||||
m_size = billboard.m_size;
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
NzBillboardRef NzBillboard::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<NzBillboard> object(new NzBillboard(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
||||
@@ -12,32 +12,39 @@
|
||||
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||
#include <Nazara/Renderer/UberShader.hpp>
|
||||
|
||||
class NzColorBackground;
|
||||
|
||||
using NzColorBackgroundConstRef = NzObjectRef<const NzColorBackground>;
|
||||
using NzColorBackgroundRef = NzObjectRef<NzColorBackground>;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzColorBackground : public NzAbstractBackground
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzColorBackground(const NzColor& color = NzColor::Black);
|
||||
class ColorBackground;
|
||||
|
||||
void Draw(const NzAbstractViewer* viewer) const;
|
||||
using ColorBackgroundConstRef = ObjectRef<const ColorBackground>;
|
||||
using ColorBackgroundRef = ObjectRef<ColorBackground>;
|
||||
|
||||
nzBackgroundType GetBackgroundType() const;
|
||||
NzColor GetColor() const;
|
||||
class NAZARA_GRAPHICS_API ColorBackground : public AbstractBackground
|
||||
{
|
||||
public:
|
||||
ColorBackground(const Color& color = Color::Black);
|
||||
ColorBackground(const ColorBackground&) = default;
|
||||
ColorBackground(ColorBackground&&) = delete;
|
||||
|
||||
void SetColor(const NzColor& color);
|
||||
void Draw(const AbstractViewer* viewer) const;
|
||||
|
||||
template<typename... Args> static NzColorBackgroundRef New(Args&&... args);
|
||||
BackgroundType GetBackgroundType() const;
|
||||
Color GetColor() const;
|
||||
|
||||
private:
|
||||
NzColor m_color;
|
||||
NzUberShaderConstRef m_uberShader;
|
||||
const NzUberShaderInstance* m_uberShaderInstance;
|
||||
int m_materialDiffuseUniform;
|
||||
int m_vertexDepthUniform;
|
||||
};
|
||||
void SetColor(const Color& color);
|
||||
|
||||
ColorBackground& operator=(ColorBackground&&) = delete;
|
||||
|
||||
template<typename... Args> static ColorBackgroundRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
Color m_color;
|
||||
UberShaderConstRef m_uberShader;
|
||||
const UberShaderInstance* m_uberShaderInstance;
|
||||
int m_materialDiffuseUniform;
|
||||
int m_vertexDepthUniform;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/ColorBackground.inl>
|
||||
|
||||
|
||||
@@ -5,13 +5,16 @@
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
template<typename... Args>
|
||||
NzColorBackgroundRef NzColorBackground::New(Args&&... args)
|
||||
namespace Nz
|
||||
{
|
||||
std::unique_ptr<NzColorBackground> object(new NzColorBackground(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
template<typename... Args>
|
||||
ColorBackgroundRef ColorBackground::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<ColorBackground> object(new ColorBackground(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
||||
@@ -15,40 +15,43 @@
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||
|
||||
class NAZARA_GRAPHICS_API NzDeferredBloomPass : public NzDeferredRenderPass
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzDeferredBloomPass();
|
||||
virtual ~NzDeferredBloomPass();
|
||||
class NAZARA_GRAPHICS_API DeferredBloomPass : public DeferredRenderPass
|
||||
{
|
||||
public:
|
||||
DeferredBloomPass();
|
||||
virtual ~DeferredBloomPass();
|
||||
|
||||
unsigned int GetBlurPassCount() const;
|
||||
float GetBrightLuminance() const;
|
||||
float GetBrightMiddleGrey() const;
|
||||
float GetBrightThreshold() const;
|
||||
NzTexture* GetTexture(unsigned int i) const;
|
||||
unsigned int GetBlurPassCount() const;
|
||||
float GetBrightLuminance() const;
|
||||
float GetBrightMiddleGrey() const;
|
||||
float GetBrightThreshold() const;
|
||||
Texture* GetTexture(unsigned int i) const;
|
||||
|
||||
bool Process(const NzSceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
|
||||
bool Resize(const NzVector2ui& dimensions);
|
||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
|
||||
bool Resize(const Vector2ui& dimensions);
|
||||
|
||||
void SetBlurPassCount(unsigned int passCount);
|
||||
void SetBrightLuminance(float luminance);
|
||||
void SetBrightMiddleGrey(float middleGrey);
|
||||
void SetBrightThreshold(float threshold);
|
||||
void SetBlurPassCount(unsigned int passCount);
|
||||
void SetBrightLuminance(float luminance);
|
||||
void SetBrightMiddleGrey(float middleGrey);
|
||||
void SetBrightThreshold(float threshold);
|
||||
|
||||
protected:
|
||||
NzRenderStates m_bloomStates;
|
||||
NzRenderTexture m_bloomRTT;
|
||||
NzShaderRef m_bloomBrightShader;
|
||||
NzShaderRef m_bloomFinalShader;
|
||||
NzShaderRef m_gaussianBlurShader;
|
||||
NzTextureRef m_bloomTextures[2];
|
||||
NzTextureSampler m_bilinearSampler;
|
||||
mutable bool m_uniformUpdated;
|
||||
float m_brightLuminance;
|
||||
float m_brightMiddleGrey;
|
||||
float m_brightThreshold;
|
||||
int m_gaussianBlurShaderFilterLocation;
|
||||
unsigned int m_blurPassCount;
|
||||
};
|
||||
protected:
|
||||
RenderStates m_bloomStates;
|
||||
RenderTexture m_bloomRTT;
|
||||
ShaderRef m_bloomBrightShader;
|
||||
ShaderRef m_bloomFinalShader;
|
||||
ShaderRef m_gaussianBlurShader;
|
||||
TextureRef m_bloomTextures[2];
|
||||
TextureSampler m_bilinearSampler;
|
||||
mutable bool m_uniformUpdated;
|
||||
float m_brightLuminance;
|
||||
float m_brightMiddleGrey;
|
||||
float m_brightThreshold;
|
||||
int m_gaussianBlurShaderFilterLocation;
|
||||
unsigned int m_blurPassCount;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DEFERREDBLOOMPASS_HPP
|
||||
|
||||
@@ -15,24 +15,27 @@
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||
|
||||
class NAZARA_GRAPHICS_API NzDeferredDOFPass : public NzDeferredRenderPass
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzDeferredDOFPass();
|
||||
virtual ~NzDeferredDOFPass();
|
||||
class NAZARA_GRAPHICS_API DeferredDOFPass : public DeferredRenderPass
|
||||
{
|
||||
public:
|
||||
DeferredDOFPass();
|
||||
virtual ~DeferredDOFPass();
|
||||
|
||||
bool Process(const NzSceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
|
||||
bool Resize(const NzVector2ui& dimensions);
|
||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
|
||||
bool Resize(const Vector2ui& dimensions);
|
||||
|
||||
protected:
|
||||
NzRenderTexture m_dofRTT;
|
||||
NzRenderStates m_states;
|
||||
NzShaderConstRef m_dofShader;
|
||||
NzShaderConstRef m_gaussianBlurShader;
|
||||
NzTextureRef m_dofTextures[2];
|
||||
NzTextureSampler m_bilinearSampler;
|
||||
NzTextureSampler m_pointSampler;
|
||||
int m_gaussianBlurShaderFilterLocation;
|
||||
};
|
||||
protected:
|
||||
RenderTexture m_dofRTT;
|
||||
RenderStates m_states;
|
||||
ShaderConstRef m_dofShader;
|
||||
ShaderConstRef m_gaussianBlurShader;
|
||||
TextureRef m_dofTextures[2];
|
||||
TextureSampler m_bilinearSampler;
|
||||
TextureSampler m_pointSampler;
|
||||
int m_gaussianBlurShaderFilterLocation;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DEFERREDDOFPASS_HPP
|
||||
|
||||
@@ -13,18 +13,21 @@
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||
|
||||
class NAZARA_GRAPHICS_API NzDeferredFXAAPass : public NzDeferredRenderPass
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzDeferredFXAAPass();
|
||||
virtual ~NzDeferredFXAAPass();
|
||||
class NAZARA_GRAPHICS_API DeferredFXAAPass : public DeferredRenderPass
|
||||
{
|
||||
public:
|
||||
DeferredFXAAPass();
|
||||
virtual ~DeferredFXAAPass();
|
||||
|
||||
bool Process(const NzSceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
|
||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
|
||||
|
||||
protected:
|
||||
NzRenderStates m_states;
|
||||
NzShaderRef m_fxaaShader;
|
||||
NzTextureSampler m_pointSampler;
|
||||
};
|
||||
protected:
|
||||
RenderStates m_states;
|
||||
ShaderRef m_fxaaShader;
|
||||
TextureSampler m_pointSampler;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DEFERREDFXAAPASS_HPP
|
||||
|
||||
@@ -13,21 +13,24 @@
|
||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||
#include <Nazara/Renderer/UberShader.hpp>
|
||||
|
||||
class NAZARA_GRAPHICS_API NzDeferredFinalPass : public NzDeferredRenderPass
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzDeferredFinalPass();
|
||||
virtual ~NzDeferredFinalPass();
|
||||
class NAZARA_GRAPHICS_API DeferredFinalPass : public DeferredRenderPass
|
||||
{
|
||||
public:
|
||||
DeferredFinalPass();
|
||||
virtual ~DeferredFinalPass();
|
||||
|
||||
bool Process(const NzSceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
|
||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
|
||||
|
||||
protected:
|
||||
NzRenderStates m_states;
|
||||
NzTextureSampler m_pointSampler;
|
||||
NzUberShaderConstRef m_uberShader;
|
||||
const NzUberShaderInstance* m_uberShaderInstance;
|
||||
int m_materialDiffuseUniform;
|
||||
int m_materialDiffuseMapUniform;
|
||||
};
|
||||
protected:
|
||||
RenderStates m_states;
|
||||
TextureSampler m_pointSampler;
|
||||
UberShaderConstRef m_uberShader;
|
||||
const UberShaderInstance* m_uberShaderInstance;
|
||||
int m_materialDiffuseUniform;
|
||||
int m_materialDiffuseMapUniform;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DEFERREDFINALPASS_HPP
|
||||
|
||||
@@ -13,19 +13,22 @@
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||
|
||||
class NAZARA_GRAPHICS_API NzDeferredFogPass : public NzDeferredRenderPass
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzDeferredFogPass();
|
||||
virtual ~NzDeferredFogPass();
|
||||
class NAZARA_GRAPHICS_API DeferredFogPass : public DeferredRenderPass
|
||||
{
|
||||
public:
|
||||
DeferredFogPass();
|
||||
virtual ~DeferredFogPass();
|
||||
|
||||
bool Process(const NzSceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
|
||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
|
||||
|
||||
protected:
|
||||
NzRenderStates m_states;
|
||||
NzShaderRef m_shader;
|
||||
NzTextureSampler m_pointSampler;
|
||||
int m_shaderEyePositionLocation;
|
||||
};
|
||||
protected:
|
||||
RenderStates m_states;
|
||||
ShaderRef m_shader;
|
||||
TextureSampler m_pointSampler;
|
||||
int m_shaderEyePositionLocation;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DEFERREDFOGPASS_HPP
|
||||
|
||||
@@ -10,19 +10,22 @@
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
||||
|
||||
class NzForwardRenderTechnique;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzDeferredForwardPass : public NzDeferredRenderPass
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzDeferredForwardPass();
|
||||
virtual ~NzDeferredForwardPass();
|
||||
class ForwardRenderTechnique;
|
||||
|
||||
void Initialize(NzDeferredRenderTechnique* technique);
|
||||
bool Process(const NzSceneData& sceneData, unsigned int workTexture, unsigned sceneTexture) const;
|
||||
class NAZARA_GRAPHICS_API DeferredForwardPass : public DeferredRenderPass
|
||||
{
|
||||
public:
|
||||
DeferredForwardPass();
|
||||
virtual ~DeferredForwardPass();
|
||||
|
||||
protected:
|
||||
const NzForwardRenderTechnique* m_forwardTechnique;
|
||||
};
|
||||
void Initialize(DeferredRenderTechnique* technique);
|
||||
bool Process(const SceneData& sceneData, unsigned int workTexture, unsigned sceneTexture) const;
|
||||
|
||||
protected:
|
||||
const ForwardRenderTechnique* m_forwardTechnique;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DEFERREDFORWARDPASS_HPP
|
||||
|
||||
@@ -13,34 +13,37 @@
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
class NAZARA_GRAPHICS_API NzDeferredGeometryPass : public NzDeferredRenderPass
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzDeferredGeometryPass();
|
||||
virtual ~NzDeferredGeometryPass();
|
||||
class NAZARA_GRAPHICS_API DeferredGeometryPass : public DeferredRenderPass
|
||||
{
|
||||
public:
|
||||
DeferredGeometryPass();
|
||||
virtual ~DeferredGeometryPass();
|
||||
|
||||
bool Process(const NzSceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
|
||||
bool Resize(const NzVector2ui& dimensions);
|
||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
|
||||
bool Resize(const Vector2ui& dimensions);
|
||||
|
||||
protected:
|
||||
struct ShaderUniforms;
|
||||
protected:
|
||||
struct ShaderUniforms;
|
||||
|
||||
const ShaderUniforms* GetShaderUniforms(const NzShader* shader) const;
|
||||
void OnShaderInvalidated(const NzShader* shader) const;
|
||||
const ShaderUniforms* GetShaderUniforms(const Shader* shader) const;
|
||||
void OnShaderInvalidated(const Shader* shader) const;
|
||||
|
||||
struct ShaderUniforms
|
||||
{
|
||||
NazaraSlot(NzShader, OnShaderUniformInvalidated, shaderUniformInvalidatedSlot);
|
||||
NazaraSlot(NzShader, OnShaderRelease, shaderReleaseSlot);
|
||||
struct ShaderUniforms
|
||||
{
|
||||
NazaraSlot(Shader, OnShaderUniformInvalidated, shaderUniformInvalidatedSlot);
|
||||
NazaraSlot(Shader, OnShaderRelease, shaderReleaseSlot);
|
||||
|
||||
int eyePosition;
|
||||
int sceneAmbient;
|
||||
int textureOverlay;
|
||||
};
|
||||
int eyePosition;
|
||||
int sceneAmbient;
|
||||
int textureOverlay;
|
||||
};
|
||||
|
||||
mutable std::unordered_map<const NzShader*, ShaderUniforms> m_shaderUniforms;
|
||||
NzRenderStates m_clearStates;
|
||||
NzShaderRef m_clearShader;
|
||||
};
|
||||
mutable std::unordered_map<const Shader*, ShaderUniforms> m_shaderUniforms;
|
||||
RenderStates m_clearStates;
|
||||
ShaderRef m_clearShader;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DEFERREDGEOMETRYPASS_HPP
|
||||
|
||||
@@ -14,36 +14,39 @@
|
||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
|
||||
class NzStaticMesh;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzDeferredPhongLightingPass : public NzDeferredRenderPass
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzDeferredPhongLightingPass();
|
||||
virtual ~NzDeferredPhongLightingPass();
|
||||
class StaticMesh;
|
||||
|
||||
void EnableLightMeshesDrawing(bool enable);
|
||||
class NAZARA_GRAPHICS_API DeferredPhongLightingPass : public DeferredRenderPass
|
||||
{
|
||||
public:
|
||||
DeferredPhongLightingPass();
|
||||
virtual ~DeferredPhongLightingPass();
|
||||
|
||||
bool IsLightMeshesDrawingEnabled() const;
|
||||
void EnableLightMeshesDrawing(bool enable);
|
||||
|
||||
bool Process(const NzSceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
|
||||
bool IsLightMeshesDrawingEnabled() const;
|
||||
|
||||
protected:
|
||||
NzLightUniforms m_directionalLightUniforms;
|
||||
NzLightUniforms m_pointSpotLightUniforms;
|
||||
NzMeshRef m_cone;
|
||||
NzMeshRef m_sphere;
|
||||
NzShaderRef m_directionalLightShader;
|
||||
NzShaderRef m_pointSpotLightShader;
|
||||
NzTextureSampler m_pointSampler;
|
||||
NzStaticMesh* m_coneMesh;
|
||||
NzStaticMesh* m_sphereMesh;
|
||||
bool m_lightMeshesDrawing;
|
||||
int m_directionalLightShaderEyePositionLocation;
|
||||
int m_directionalLightShaderSceneAmbientLocation;
|
||||
int m_pointSpotLightShaderDiscardLocation;
|
||||
int m_pointSpotLightShaderEyePositionLocation;
|
||||
int m_pointSpotLightShaderSceneAmbientLocation;
|
||||
};
|
||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
|
||||
|
||||
protected:
|
||||
LightUniforms m_directionalLightUniforms;
|
||||
LightUniforms m_pointSpotLightUniforms;
|
||||
MeshRef m_cone;
|
||||
MeshRef m_sphere;
|
||||
ShaderRef m_directionalLightShader;
|
||||
ShaderRef m_pointSpotLightShader;
|
||||
TextureSampler m_pointSampler;
|
||||
StaticMesh* m_coneMesh;
|
||||
StaticMesh* m_sphereMesh;
|
||||
bool m_lightMeshesDrawing;
|
||||
int m_directionalLightShaderEyePositionLocation;
|
||||
int m_directionalLightShaderSceneAmbientLocation;
|
||||
int m_pointSpotLightShaderDiscardLocation;
|
||||
int m_pointSpotLightShaderEyePositionLocation;
|
||||
int m_pointSpotLightShaderSceneAmbientLocation;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DEFERREDPHONGLIGHTINGPASS_HPP
|
||||
|
||||
@@ -13,46 +13,49 @@
|
||||
#include <Nazara/Graphics/SceneData.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
||||
class NzAbstractViewer;
|
||||
class NzDeferredRenderTechnique;
|
||||
class NzDeferredRenderQueue;
|
||||
class NzRenderBuffer;
|
||||
class NzRenderTexture;
|
||||
class NzScene;
|
||||
class NzTexture;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzDeferredRenderPass
|
||||
namespace Nz
|
||||
{
|
||||
friend NzDeferredRenderTechnique;
|
||||
class AbstractViewer;
|
||||
class DeferredRenderTechnique;
|
||||
class DeferredRenderQueue;
|
||||
class RenderBuffer;
|
||||
class RenderTexture;
|
||||
class Scene;
|
||||
class Texture;
|
||||
|
||||
public:
|
||||
NzDeferredRenderPass();
|
||||
NzDeferredRenderPass(const NzDeferredRenderPass&) = delete;
|
||||
virtual ~NzDeferredRenderPass();
|
||||
class NAZARA_GRAPHICS_API DeferredRenderPass
|
||||
{
|
||||
friend DeferredRenderTechnique;
|
||||
|
||||
void Enable(bool enable);
|
||||
public:
|
||||
DeferredRenderPass();
|
||||
DeferredRenderPass(const DeferredRenderPass&) = delete;
|
||||
virtual ~DeferredRenderPass();
|
||||
|
||||
virtual void Initialize(NzDeferredRenderTechnique* technique);
|
||||
void Enable(bool enable);
|
||||
|
||||
bool IsEnabled() const;
|
||||
virtual void Initialize(DeferredRenderTechnique* technique);
|
||||
|
||||
virtual bool Process(const NzSceneData& sceneData, unsigned int workTexture, unsigned sceneTexture) const = 0;
|
||||
virtual bool Resize(const NzVector2ui& GBufferSize);
|
||||
bool IsEnabled() const;
|
||||
|
||||
NzDeferredRenderPass& operator=(const NzDeferredRenderPass&) = delete;
|
||||
virtual bool Process(const SceneData& sceneData, unsigned int workTexture, unsigned sceneTexture) const = 0;
|
||||
virtual bool Resize(const Vector2ui& GBufferSize);
|
||||
|
||||
protected:
|
||||
NzVector2ui m_dimensions;
|
||||
NzDeferredRenderTechnique* m_deferredTechnique;
|
||||
NzDeferredRenderQueue* m_renderQueue;
|
||||
NzRenderBuffer* m_depthStencilBuffer;
|
||||
NzRenderTexture* m_GBufferRTT;
|
||||
NzRenderTexture* m_workRTT;
|
||||
NzTexture* m_GBuffer[4];
|
||||
NzTexture* m_workTextures[2];
|
||||
DeferredRenderPass& operator=(const DeferredRenderPass&) = delete;
|
||||
|
||||
private:
|
||||
bool m_enabled;
|
||||
};
|
||||
protected:
|
||||
Vector2ui m_dimensions;
|
||||
DeferredRenderTechnique* m_deferredTechnique;
|
||||
DeferredRenderQueue* m_renderQueue;
|
||||
RenderBuffer* m_depthStencilBuffer;
|
||||
RenderTexture* m_GBufferRTT;
|
||||
RenderTexture* m_workRTT;
|
||||
Texture* m_GBuffer[4];
|
||||
Texture* m_workTextures[2];
|
||||
|
||||
private:
|
||||
bool m_enabled;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DEFERREDRENDERPASS_HPP
|
||||
|
||||
@@ -19,66 +19,69 @@
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
|
||||
class NzForwardRenderQueue;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzDeferredRenderQueue : public NzAbstractRenderQueue
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzDeferredRenderQueue(NzForwardRenderQueue* forwardQueue);
|
||||
~NzDeferredRenderQueue() = default;
|
||||
class ForwardRenderQueue;
|
||||
|
||||
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 AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) override;
|
||||
void AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const NzTexture* overlay = nullptr) override;
|
||||
class NAZARA_GRAPHICS_API DeferredRenderQueue : public AbstractRenderQueue
|
||||
{
|
||||
public:
|
||||
DeferredRenderQueue(ForwardRenderQueue* forwardQueue);
|
||||
~DeferredRenderQueue() = default;
|
||||
|
||||
void Clear(bool fully = false);
|
||||
void AddBillboard(const Material* material, const Vector3f& position, const Vector2f& size, const Vector2f& sinCos = Vector2f(0.f, 1.f), const Color& color = Color::White) override;
|
||||
void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddDrawable(const Drawable* drawable) override;
|
||||
void AddMesh(const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix) override;
|
||||
void AddSprites(const Material* material, const VertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const Texture* overlay = nullptr) override;
|
||||
|
||||
struct MeshDataComparator
|
||||
{
|
||||
bool operator()(const NzMeshData& data1, const NzMeshData& data2) const;
|
||||
};
|
||||
void Clear(bool fully = false);
|
||||
|
||||
struct MeshInstanceEntry
|
||||
{
|
||||
NazaraSlot(NzIndexBuffer, OnIndexBufferRelease, indexBufferReleaseSlot);
|
||||
NazaraSlot(NzVertexBuffer, OnVertexBufferRelease, vertexBufferReleaseSlot);
|
||||
struct MeshDataComparator
|
||||
{
|
||||
bool operator()(const MeshData& data1, const MeshData& data2) const;
|
||||
};
|
||||
|
||||
std::vector<NzMatrix4f> instances;
|
||||
};
|
||||
struct MeshInstanceEntry
|
||||
{
|
||||
NazaraSlot(IndexBuffer, OnIndexBufferRelease, indexBufferReleaseSlot);
|
||||
NazaraSlot(VertexBuffer, OnVertexBufferRelease, vertexBufferReleaseSlot);
|
||||
|
||||
typedef std::map<NzMeshData, MeshInstanceEntry, MeshDataComparator> MeshInstanceContainer;
|
||||
std::vector<Matrix4f> instances;
|
||||
};
|
||||
|
||||
struct BatchedModelMaterialComparator
|
||||
{
|
||||
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2) const;
|
||||
};
|
||||
typedef std::map<MeshData, MeshInstanceEntry, MeshDataComparator> MeshInstanceContainer;
|
||||
|
||||
struct BatchedModelEntry
|
||||
{
|
||||
NazaraSlot(NzMaterial, OnMaterialRelease, materialReleaseSlot);
|
||||
struct BatchedModelMaterialComparator
|
||||
{
|
||||
bool operator()(const Material* mat1, const Material* mat2) const;
|
||||
};
|
||||
|
||||
MeshInstanceContainer meshMap;
|
||||
bool enabled = false;
|
||||
bool instancingEnabled = false;
|
||||
};
|
||||
struct BatchedModelEntry
|
||||
{
|
||||
NazaraSlot(Material, OnMaterialRelease, materialReleaseSlot);
|
||||
|
||||
typedef std::map<const NzMaterial*, BatchedModelEntry, BatchedModelMaterialComparator> ModelBatches;
|
||||
MeshInstanceContainer meshMap;
|
||||
bool enabled = false;
|
||||
bool instancingEnabled = false;
|
||||
};
|
||||
|
||||
ModelBatches opaqueModels;
|
||||
NzForwardRenderQueue* m_forwardQueue;
|
||||
typedef std::map<const Material*, BatchedModelEntry, BatchedModelMaterialComparator> ModelBatches;
|
||||
|
||||
void OnIndexBufferInvalidation(const NzIndexBuffer* indexBuffer);
|
||||
void OnMaterialInvalidation(const NzMaterial* material);
|
||||
void OnVertexBufferInvalidation(const NzVertexBuffer* vertexBuffer);
|
||||
};
|
||||
ModelBatches opaqueModels;
|
||||
ForwardRenderQueue* m_forwardQueue;
|
||||
|
||||
void OnIndexBufferInvalidation(const IndexBuffer* indexBuffer);
|
||||
void OnMaterialInvalidation(const Material* material);
|
||||
void OnVertexBufferInvalidation(const VertexBuffer* vertexBuffer);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DEFERREDRENDERQUEUE_HPP
|
||||
|
||||
@@ -22,57 +22,60 @@
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
class NAZARA_GRAPHICS_API NzDeferredRenderTechnique : public NzAbstractRenderTechnique
|
||||
namespace Nz
|
||||
{
|
||||
friend class NzGraphics;
|
||||
class NAZARA_GRAPHICS_API DeferredRenderTechnique : public AbstractRenderTechnique
|
||||
{
|
||||
friend class Graphics;
|
||||
|
||||
public:
|
||||
NzDeferredRenderTechnique();
|
||||
~NzDeferredRenderTechnique();
|
||||
public:
|
||||
DeferredRenderTechnique();
|
||||
~DeferredRenderTechnique();
|
||||
|
||||
bool Draw(const NzSceneData& sceneData) const override;
|
||||
bool Draw(const SceneData& sceneData) const override;
|
||||
|
||||
void EnablePass(nzRenderPassType renderPass, int position, bool enable);
|
||||
void EnablePass(RenderPassType renderPass, int position, bool enable);
|
||||
|
||||
NzRenderBuffer* GetDepthStencilBuffer() const;
|
||||
NzTexture* GetGBuffer(unsigned int i) const;
|
||||
NzRenderTexture* GetGBufferRTT() const;
|
||||
const NzForwardRenderTechnique* GetForwardTechnique() const;
|
||||
NzDeferredRenderPass* GetPass(nzRenderPassType renderPass, int position = 0);
|
||||
NzAbstractRenderQueue* GetRenderQueue() override;
|
||||
nzRenderTechniqueType GetType() const override;
|
||||
NzRenderTexture* GetWorkRTT() const;
|
||||
NzTexture* GetWorkTexture(unsigned int i) const;
|
||||
RenderBuffer* GetDepthStencilBuffer() const;
|
||||
Texture* GetGBuffer(unsigned int i) const;
|
||||
RenderTexture* GetGBufferRTT() const;
|
||||
const ForwardRenderTechnique* GetForwardTechnique() const;
|
||||
DeferredRenderPass* GetPass(RenderPassType renderPass, int position = 0);
|
||||
AbstractRenderQueue* GetRenderQueue() override;
|
||||
RenderTechniqueType GetType() const override;
|
||||
RenderTexture* GetWorkRTT() const;
|
||||
Texture* GetWorkTexture(unsigned int i) const;
|
||||
|
||||
bool IsPassEnabled(nzRenderPassType renderPass, int position);
|
||||
bool IsPassEnabled(RenderPassType renderPass, int position);
|
||||
|
||||
NzDeferredRenderPass* ResetPass(nzRenderPassType renderPass, int position);
|
||||
DeferredRenderPass* ResetPass(RenderPassType renderPass, int position);
|
||||
|
||||
void SetPass(nzRenderPassType relativeTo, int position, NzDeferredRenderPass* pass);
|
||||
void SetPass(RenderPassType relativeTo, int position, DeferredRenderPass* pass);
|
||||
|
||||
static bool IsSupported();
|
||||
static bool IsSupported();
|
||||
|
||||
private:
|
||||
bool Resize(const NzVector2ui& dimensions) const;
|
||||
private:
|
||||
bool Resize(const Vector2ui& dimensions) const;
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
struct RenderPassComparator
|
||||
{
|
||||
bool operator()(nzRenderPassType pass1, nzRenderPassType pass2) const;
|
||||
};
|
||||
struct RenderPassComparator
|
||||
{
|
||||
bool operator()(RenderPassType pass1, RenderPassType pass2) const;
|
||||
};
|
||||
|
||||
std::map<nzRenderPassType, std::map<int, std::unique_ptr<NzDeferredRenderPass>>, RenderPassComparator> m_passes;
|
||||
NzForwardRenderTechnique m_forwardTechnique; // Doit être initialisé avant la RenderQueue
|
||||
NzDeferredRenderQueue m_renderQueue;
|
||||
mutable NzRenderBufferRef m_depthStencilBuffer;
|
||||
mutable NzRenderTexture m_GBufferRTT;
|
||||
mutable NzRenderTexture m_workRTT;
|
||||
mutable NzTextureRef m_GBuffer[4];
|
||||
mutable NzTextureRef m_workTextures[2];
|
||||
mutable NzVector2ui m_GBufferSize;
|
||||
const NzRenderTarget* m_viewerTarget;
|
||||
std::map<RenderPassType, std::map<int, std::unique_ptr<DeferredRenderPass>>, RenderPassComparator> m_passes;
|
||||
ForwardRenderTechnique m_forwardTechnique; // Doit être initialisé avant la RenderQueue
|
||||
DeferredRenderQueue m_renderQueue;
|
||||
mutable RenderBufferRef m_depthStencilBuffer;
|
||||
mutable RenderTexture m_GBufferRTT;
|
||||
mutable RenderTexture m_workRTT;
|
||||
mutable TextureRef m_GBuffer[4];
|
||||
mutable TextureRef m_workTextures[2];
|
||||
mutable Vector2ui m_GBufferSize;
|
||||
const RenderTarget* m_viewerTarget;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_FORWARDRENDERTECHNIQUE_HPP
|
||||
|
||||
@@ -10,13 +10,16 @@
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
|
||||
class NAZARA_GRAPHICS_API NzDrawable
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzDrawable() = default;
|
||||
virtual ~NzDrawable();
|
||||
class NAZARA_GRAPHICS_API Drawable
|
||||
{
|
||||
public:
|
||||
Drawable() = default;
|
||||
virtual ~Drawable();
|
||||
|
||||
virtual void Draw() const = 0;
|
||||
};
|
||||
virtual void Draw() const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DRAWABLE_HPP
|
||||
|
||||
@@ -7,136 +7,139 @@
|
||||
#ifndef NAZARA_ENUMS_GRAPHICS_HPP
|
||||
#define NAZARA_ENUMS_GRAPHICS_HPP
|
||||
|
||||
enum nzBackgroundType
|
||||
namespace Nz
|
||||
{
|
||||
nzBackgroundType_Color, // NzColorBackground
|
||||
nzBackgroundType_Skybox, // NzSkyboxBackground
|
||||
nzBackgroundType_Texture, // NzTextureBackground
|
||||
nzBackgroundType_User,
|
||||
enum BackgroundType
|
||||
{
|
||||
BackgroundType_Color, // ColorBackground
|
||||
BackgroundType_Skybox, // SkyboxBackground
|
||||
BackgroundType_Texture, // TextureBackground
|
||||
BackgroundType_User,
|
||||
|
||||
nzBackgroundType_Max = nzBackgroundType_User
|
||||
};
|
||||
BackgroundType_Max = BackgroundType_User
|
||||
};
|
||||
|
||||
enum nzProjectionType
|
||||
{
|
||||
nzProjectionType_Orthogonal,
|
||||
nzProjectionType_Perspective,
|
||||
enum ProjectionType
|
||||
{
|
||||
ProjectionType_Orthogonal,
|
||||
ProjectionType_Perspective,
|
||||
|
||||
nzProjectionType_Max = nzProjectionType_Perspective
|
||||
};
|
||||
ProjectionType_Max = ProjectionType_Perspective
|
||||
};
|
||||
|
||||
enum nzLightType
|
||||
{
|
||||
nzLightType_Directional,
|
||||
nzLightType_Point,
|
||||
nzLightType_Spot,
|
||||
enum LightType
|
||||
{
|
||||
LightType_Directional,
|
||||
LightType_Point,
|
||||
LightType_Spot,
|
||||
|
||||
nzLightType_Max = nzLightType_Spot
|
||||
};
|
||||
LightType_Max = LightType_Spot
|
||||
};
|
||||
|
||||
enum nzMaterialUniform
|
||||
{
|
||||
nzMaterialUniform_AlphaMap,
|
||||
nzMaterialUniform_AlphaThreshold,
|
||||
nzMaterialUniform_Ambient,
|
||||
nzMaterialUniform_Diffuse,
|
||||
nzMaterialUniform_DiffuseMap,
|
||||
nzMaterialUniform_EmissiveMap,
|
||||
nzMaterialUniform_HeightMap,
|
||||
nzMaterialUniform_NormalMap,
|
||||
nzMaterialUniform_Shininess,
|
||||
nzMaterialUniform_Specular,
|
||||
nzMaterialUniform_SpecularMap,
|
||||
enum MaterialUniform
|
||||
{
|
||||
MaterialUniform_AlphaMap,
|
||||
MaterialUniform_AlphaThreshold,
|
||||
MaterialUniform_Ambient,
|
||||
MaterialUniform_Diffuse,
|
||||
MaterialUniform_DiffuseMap,
|
||||
MaterialUniform_EmissiveMap,
|
||||
MaterialUniform_HeightMap,
|
||||
MaterialUniform_NormalMap,
|
||||
MaterialUniform_Shininess,
|
||||
MaterialUniform_Specular,
|
||||
MaterialUniform_SpecularMap,
|
||||
|
||||
nzMaterialUniform_Max = nzMaterialUniform_SpecularMap
|
||||
};
|
||||
MaterialUniform_Max = MaterialUniform_SpecularMap
|
||||
};
|
||||
|
||||
enum nzParticleComponent
|
||||
{
|
||||
nzParticleComponent_Unused = -1,
|
||||
enum ParticleComponent
|
||||
{
|
||||
ParticleComponent_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,
|
||||
ParticleComponent_Color,
|
||||
ParticleComponent_Life,
|
||||
ParticleComponent_Mass,
|
||||
ParticleComponent_Normal,
|
||||
ParticleComponent_Position,
|
||||
ParticleComponent_Radius,
|
||||
ParticleComponent_Rotation,
|
||||
ParticleComponent_Size,
|
||||
ParticleComponent_Velocity,
|
||||
ParticleComponent_Userdata0,
|
||||
ParticleComponent_Userdata1,
|
||||
ParticleComponent_Userdata2,
|
||||
ParticleComponent_Userdata3,
|
||||
ParticleComponent_Userdata4,
|
||||
ParticleComponent_Userdata5,
|
||||
ParticleComponent_Userdata6,
|
||||
ParticleComponent_Userdata7,
|
||||
ParticleComponent_Userdata8,
|
||||
|
||||
nzParticleComponent_Max = nzParticleComponent_Userdata8
|
||||
};
|
||||
ParticleComponent_Max = ParticleComponent_Userdata8
|
||||
};
|
||||
|
||||
enum nzParticleLayout
|
||||
{
|
||||
nzParticleLayout_Billboard,
|
||||
nzParticleLayout_Model,
|
||||
nzParticleLayout_Sprite,
|
||||
enum ParticleLayout
|
||||
{
|
||||
ParticleLayout_Billboard,
|
||||
ParticleLayout_Model,
|
||||
ParticleLayout_Sprite,
|
||||
|
||||
nzParticleLayout_Max = nzParticleLayout_Sprite
|
||||
};
|
||||
ParticleLayout_Max = ParticleLayout_Sprite
|
||||
};
|
||||
|
||||
enum nzRenderPassType
|
||||
{
|
||||
nzRenderPassType_AA,
|
||||
nzRenderPassType_Bloom,
|
||||
nzRenderPassType_DOF,
|
||||
nzRenderPassType_Final,
|
||||
nzRenderPassType_Fog,
|
||||
nzRenderPassType_Forward,
|
||||
nzRenderPassType_Lighting,
|
||||
nzRenderPassType_Geometry,
|
||||
nzRenderPassType_SSAO,
|
||||
enum RenderPassType
|
||||
{
|
||||
RenderPassType_AA,
|
||||
RenderPassType_Bloom,
|
||||
RenderPassType_DOF,
|
||||
RenderPassType_Final,
|
||||
RenderPassType_Fog,
|
||||
RenderPassType_Forward,
|
||||
RenderPassType_Lighting,
|
||||
RenderPassType_Geometry,
|
||||
RenderPassType_SSAO,
|
||||
|
||||
nzRenderPassType_Max = nzRenderPassType_SSAO
|
||||
};
|
||||
RenderPassType_Max = RenderPassType_SSAO
|
||||
};
|
||||
|
||||
enum nzRenderTechniqueType
|
||||
{
|
||||
nzRenderTechniqueType_AdvancedForward, // NzAdvancedForwardRenderTechnique
|
||||
nzRenderTechniqueType_BasicForward, // NzBasicForwardRenderTechnique
|
||||
nzRenderTechniqueType_DeferredShading, // NzDeferredRenderTechnique
|
||||
nzRenderTechniqueType_LightPrePass, // NzLightPrePassRenderTechnique
|
||||
nzRenderTechniqueType_User,
|
||||
enum RenderTechniqueType
|
||||
{
|
||||
RenderTechniqueType_AdvancedForward, // AdvancedForwardRenderTechnique
|
||||
RenderTechniqueType_BasicForward, // BasicForwardRenderTechnique
|
||||
RenderTechniqueType_DeferredShading, // DeferredRenderTechnique
|
||||
RenderTechniqueType_LightPrePass, // LightPrePassRenderTechnique
|
||||
RenderTechniqueType_User,
|
||||
|
||||
nzRenderTechniqueType_Max = nzRenderTechniqueType_User
|
||||
};
|
||||
RenderTechniqueType_Max = RenderTechniqueType_User
|
||||
};
|
||||
|
||||
enum nzSceneNodeType
|
||||
{
|
||||
nzSceneNodeType_Light, // NzLight
|
||||
nzSceneNodeType_Model, // NzModel
|
||||
nzSceneNodeType_ParticleEmitter, // NzParticleEmitter
|
||||
nzSceneNodeType_Root, // NzSceneRoot
|
||||
nzSceneNodeType_Sprite, // NzSprite
|
||||
nzSceneNodeType_TextSprite, // NzTextSprite
|
||||
nzSceneNodeType_User,
|
||||
enum SceneNodeType
|
||||
{
|
||||
SceneNodeType_Light, // Light
|
||||
SceneNodeType_Model, // Model
|
||||
SceneNodeType_ParticleEmitter, // ParticleEmitter
|
||||
SceneNodeType_Root, // SceneRoot
|
||||
SceneNodeType_Sprite, // Sprite
|
||||
SceneNodeType_TextSprite, // TextSprite
|
||||
SceneNodeType_User,
|
||||
|
||||
nzSceneNodeType_Max = nzSceneNodeType_User
|
||||
};
|
||||
SceneNodeType_Max = SceneNodeType_User
|
||||
};
|
||||
|
||||
// Ces paramètres sont indépendants du matériau: ils peuvent être demandés à tout moment
|
||||
enum nzShaderFlags
|
||||
{
|
||||
nzShaderFlags_None = 0,
|
||||
// Ces paramètres sont indépendants du matériau: ils peuvent être demandés à tout moment
|
||||
enum ShaderFlags
|
||||
{
|
||||
ShaderFlags_None = 0,
|
||||
|
||||
nzShaderFlags_Billboard = 0x01,
|
||||
nzShaderFlags_Deferred = 0x02,
|
||||
nzShaderFlags_Instancing = 0x04,
|
||||
nzShaderFlags_TextureOverlay = 0x08,
|
||||
nzShaderFlags_VertexColor = 0x10,
|
||||
ShaderFlags_Billboard = 0x01,
|
||||
ShaderFlags_Deferred = 0x02,
|
||||
ShaderFlags_Instancing = 0x04,
|
||||
ShaderFlags_TextureOverlay = 0x08,
|
||||
ShaderFlags_VertexColor = 0x10,
|
||||
|
||||
nzShaderFlags_Max = nzShaderFlags_VertexColor*2-1
|
||||
};
|
||||
ShaderFlags_Max = ShaderFlags_VertexColor*2-1
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_ENUMS_GRAPHICS_HPP
|
||||
|
||||
@@ -19,142 +19,145 @@
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
|
||||
class NzAbstractViewer;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzForwardRenderQueue : public NzAbstractRenderQueue
|
||||
namespace Nz
|
||||
{
|
||||
friend class NzForwardRenderTechnique;
|
||||
class AbstractViewer;
|
||||
|
||||
public:
|
||||
NzForwardRenderQueue() = default;
|
||||
~NzForwardRenderQueue() = default;
|
||||
class NAZARA_GRAPHICS_API ForwardRenderQueue : public AbstractRenderQueue
|
||||
{
|
||||
friend class ForwardRenderTechnique;
|
||||
|
||||
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 AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) override;
|
||||
void AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const NzTexture* overlay = nullptr) override;
|
||||
public:
|
||||
ForwardRenderQueue() = default;
|
||||
~ForwardRenderQueue() = default;
|
||||
|
||||
void Clear(bool fully = false);
|
||||
void AddBillboard(const Material* material, const Vector3f& position, const Vector2f& size, const Vector2f& sinCos = Vector2f(0.f, 1.f), const Color& color = Color::White) override;
|
||||
void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddDrawable(const Drawable* drawable) override;
|
||||
void AddMesh(const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix) override;
|
||||
void AddSprites(const Material* material, const VertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const Texture* overlay = nullptr) override;
|
||||
|
||||
void Sort(const NzAbstractViewer* viewer);
|
||||
void Clear(bool fully = false);
|
||||
|
||||
/// Billboards
|
||||
struct BillboardData
|
||||
{
|
||||
NzColor color;
|
||||
NzVector3f center;
|
||||
NzVector2f size;
|
||||
NzVector2f sinCos;
|
||||
};
|
||||
void Sort(const AbstractViewer* viewer);
|
||||
|
||||
struct BatchedBillboardComparator
|
||||
{
|
||||
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2) const;
|
||||
};
|
||||
/// Billboards
|
||||
struct BillboardData
|
||||
{
|
||||
Color color;
|
||||
Vector3f center;
|
||||
Vector2f size;
|
||||
Vector2f sinCos;
|
||||
};
|
||||
|
||||
struct BatchedBillboardEntry
|
||||
{
|
||||
NazaraSlot(NzMaterial, OnMaterialRelease, materialReleaseSlot);
|
||||
struct BatchedBillboardComparator
|
||||
{
|
||||
bool operator()(const Material* mat1, const Material* mat2) const;
|
||||
};
|
||||
|
||||
std::vector<BillboardData> billboards;
|
||||
};
|
||||
struct BatchedBillboardEntry
|
||||
{
|
||||
NazaraSlot(Material, OnMaterialRelease, materialReleaseSlot);
|
||||
|
||||
typedef std::map<const NzMaterial*, BatchedBillboardEntry, BatchedBillboardComparator> BatchedBillboardContainer;
|
||||
std::vector<BillboardData> billboards;
|
||||
};
|
||||
|
||||
/// Sprites
|
||||
struct SpriteChain_XYZ_Color_UV
|
||||
{
|
||||
const NzVertexStruct_XYZ_Color_UV* vertices;
|
||||
unsigned int spriteCount;
|
||||
};
|
||||
typedef std::map<const Material*, BatchedBillboardEntry, BatchedBillboardComparator> BatchedBillboardContainer;
|
||||
|
||||
struct BatchedSpriteEntry
|
||||
{
|
||||
NazaraSlot(NzTexture, OnTextureRelease, textureReleaseSlot);
|
||||
/// Sprites
|
||||
struct SpriteChain_XYZ_Color_UV
|
||||
{
|
||||
const VertexStruct_XYZ_Color_UV* vertices;
|
||||
unsigned int spriteCount;
|
||||
};
|
||||
|
||||
std::vector<SpriteChain_XYZ_Color_UV> spriteChains;
|
||||
};
|
||||
struct BatchedSpriteEntry
|
||||
{
|
||||
NazaraSlot(Texture, OnTextureRelease, textureReleaseSlot);
|
||||
|
||||
struct BatchedSpriteMaterialComparator
|
||||
{
|
||||
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
|
||||
};
|
||||
std::vector<SpriteChain_XYZ_Color_UV> spriteChains;
|
||||
};
|
||||
|
||||
typedef std::map<const NzTexture*, BatchedSpriteEntry> BasicSpriteOverlayContainer;
|
||||
struct BatchedSpriteMaterialComparator
|
||||
{
|
||||
bool operator()(const Material* mat1, const Material* mat2);
|
||||
};
|
||||
|
||||
struct BatchedBasicSpriteEntry
|
||||
{
|
||||
NazaraSlot(NzMaterial, OnMaterialRelease, materialReleaseSlot);
|
||||
typedef std::map<const Texture*, BatchedSpriteEntry> BasicSpriteOverlayContainer;
|
||||
|
||||
BasicSpriteOverlayContainer overlayMap;
|
||||
bool enabled = false;
|
||||
};
|
||||
struct BatchedBasicSpriteEntry
|
||||
{
|
||||
NazaraSlot(Material, OnMaterialRelease, materialReleaseSlot);
|
||||
|
||||
typedef std::map<const NzMaterial*, BatchedBasicSpriteEntry> BasicSpriteBatches;
|
||||
BasicSpriteOverlayContainer overlayMap;
|
||||
bool enabled = false;
|
||||
};
|
||||
|
||||
/// Meshes
|
||||
struct MeshDataComparator
|
||||
{
|
||||
bool operator()(const NzMeshData& data1, const NzMeshData& data2) const;
|
||||
};
|
||||
typedef std::map<const Material*, BatchedBasicSpriteEntry> BasicSpriteBatches;
|
||||
|
||||
struct MeshInstanceEntry
|
||||
{
|
||||
NazaraSlot(NzIndexBuffer, OnIndexBufferRelease, indexBufferReleaseSlot);
|
||||
NazaraSlot(NzVertexBuffer, OnVertexBufferRelease, vertexBufferReleaseSlot);
|
||||
/// Meshes
|
||||
struct MeshDataComparator
|
||||
{
|
||||
bool operator()(const MeshData& data1, const MeshData& data2) const;
|
||||
};
|
||||
|
||||
std::vector<NzMatrix4f> instances;
|
||||
NzSpheref squaredBoundingSphere;
|
||||
};
|
||||
struct MeshInstanceEntry
|
||||
{
|
||||
NazaraSlot(IndexBuffer, OnIndexBufferRelease, indexBufferReleaseSlot);
|
||||
NazaraSlot(VertexBuffer, OnVertexBufferRelease, vertexBufferReleaseSlot);
|
||||
|
||||
typedef std::map<NzMeshData, MeshInstanceEntry, MeshDataComparator> MeshInstanceContainer;
|
||||
std::vector<Matrix4f> instances;
|
||||
Spheref squaredBoundingSphere;
|
||||
};
|
||||
|
||||
struct BatchedModelMaterialComparator
|
||||
{
|
||||
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2) const;
|
||||
};
|
||||
typedef std::map<MeshData, MeshInstanceEntry, MeshDataComparator> MeshInstanceContainer;
|
||||
|
||||
struct BatchedModelEntry
|
||||
{
|
||||
NazaraSlot(NzMaterial, OnMaterialRelease, materialReleaseSlot);
|
||||
struct BatchedModelMaterialComparator
|
||||
{
|
||||
bool operator()(const Material* mat1, const Material* mat2) const;
|
||||
};
|
||||
|
||||
MeshInstanceContainer meshMap;
|
||||
bool enabled = false;
|
||||
bool instancingEnabled = false;
|
||||
};
|
||||
struct BatchedModelEntry
|
||||
{
|
||||
NazaraSlot(Material, OnMaterialRelease, materialReleaseSlot);
|
||||
|
||||
typedef std::map<const NzMaterial*, BatchedModelEntry, BatchedModelMaterialComparator> ModelBatches;
|
||||
MeshInstanceContainer meshMap;
|
||||
bool enabled = false;
|
||||
bool instancingEnabled = false;
|
||||
};
|
||||
|
||||
struct TransparentModelData
|
||||
{
|
||||
NzMatrix4f transformMatrix;
|
||||
NzMeshData meshData;
|
||||
NzSpheref squaredBoundingSphere;
|
||||
const NzMaterial* material;
|
||||
};
|
||||
typedef std::map<const Material*, BatchedModelEntry, BatchedModelMaterialComparator> ModelBatches;
|
||||
|
||||
typedef std::vector<unsigned int> TransparentModelContainer;
|
||||
struct TransparentModelData
|
||||
{
|
||||
Matrix4f transformMatrix;
|
||||
MeshData meshData;
|
||||
Spheref squaredBoundingSphere;
|
||||
const Material* material;
|
||||
};
|
||||
|
||||
BatchedBillboardContainer billboards;
|
||||
BasicSpriteBatches basicSprites;
|
||||
ModelBatches opaqueModels;
|
||||
TransparentModelContainer transparentModels;
|
||||
std::vector<TransparentModelData> transparentModelData;
|
||||
std::vector<const NzDrawable*> otherDrawables;
|
||||
typedef std::vector<unsigned int> TransparentModelContainer;
|
||||
|
||||
private:
|
||||
void OnIndexBufferInvalidation(const NzIndexBuffer* indexBuffer);
|
||||
void OnMaterialInvalidation(const NzMaterial* material);
|
||||
void OnTextureInvalidation(const NzTexture* texture);
|
||||
void OnVertexBufferInvalidation(const NzVertexBuffer* vertexBuffer);
|
||||
};
|
||||
BatchedBillboardContainer billboards;
|
||||
BasicSpriteBatches basicSprites;
|
||||
ModelBatches opaqueModels;
|
||||
TransparentModelContainer transparentModels;
|
||||
std::vector<TransparentModelData> transparentModelData;
|
||||
std::vector<const Drawable*> otherDrawables;
|
||||
|
||||
private:
|
||||
void OnIndexBufferInvalidation(const IndexBuffer* indexBuffer);
|
||||
void OnMaterialInvalidation(const Material* material);
|
||||
void OnTextureInvalidation(const Texture* texture);
|
||||
void OnVertexBufferInvalidation(const VertexBuffer* vertexBuffer);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_FORWARDRENDERQUEUE_HPP
|
||||
|
||||
@@ -16,80 +16,83 @@
|
||||
#include <Nazara/Utility/IndexBuffer.hpp>
|
||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||
|
||||
class NAZARA_GRAPHICS_API NzForwardRenderTechnique : public NzAbstractRenderTechnique
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzForwardRenderTechnique();
|
||||
~NzForwardRenderTechnique() = default;
|
||||
class NAZARA_GRAPHICS_API ForwardRenderTechnique : public AbstractRenderTechnique
|
||||
{
|
||||
public:
|
||||
ForwardRenderTechnique();
|
||||
~ForwardRenderTechnique() = default;
|
||||
|
||||
bool Draw(const NzSceneData& sceneData) const override;
|
||||
bool Draw(const SceneData& sceneData) const override;
|
||||
|
||||
unsigned int GetMaxLightPassPerObject() const;
|
||||
NzAbstractRenderQueue* GetRenderQueue() override;
|
||||
nzRenderTechniqueType GetType() const override;
|
||||
unsigned int GetMaxLightPassPerObject() const;
|
||||
AbstractRenderQueue* GetRenderQueue() override;
|
||||
RenderTechniqueType GetType() const override;
|
||||
|
||||
void SetMaxLightPassPerObject(unsigned int passCount);
|
||||
void SetMaxLightPassPerObject(unsigned int passCount);
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
struct ShaderUniforms;
|
||||
private:
|
||||
struct ShaderUniforms;
|
||||
|
||||
void ChooseLights(const NzSpheref& object, bool includeDirectionalLights = true) const;
|
||||
void DrawBasicSprites(const NzSceneData& sceneData) const;
|
||||
void DrawBillboards(const NzSceneData& sceneData) const;
|
||||
void DrawOpaqueModels(const NzSceneData& sceneData) const;
|
||||
void DrawTransparentModels(const NzSceneData& sceneData) const;
|
||||
const ShaderUniforms* GetShaderUniforms(const NzShader* shader) const;
|
||||
void OnShaderInvalidated(const NzShader* shader) const;
|
||||
void SendLightUniforms(const NzShader* shader, const NzLightUniforms& uniforms, unsigned int index, unsigned int uniformOffset) const;
|
||||
void ChooseLights(const Spheref& object, bool includeDirectionalLights = true) const;
|
||||
void DrawBasicSprites(const SceneData& sceneData) const;
|
||||
void DrawBillboards(const SceneData& sceneData) const;
|
||||
void DrawOpaqueModels(const SceneData& sceneData) const;
|
||||
void DrawTransparentModels(const SceneData& sceneData) const;
|
||||
const ShaderUniforms* GetShaderUniforms(const Shader* shader) const;
|
||||
void OnShaderInvalidated(const Shader* shader) const;
|
||||
void SendLightUniforms(const Shader* shader, const LightUniforms& uniforms, unsigned int index, unsigned int uniformOffset) const;
|
||||
|
||||
static float ComputeDirectionalLightScore(const NzSpheref& object, const NzAbstractRenderQueue::DirectionalLight& light);
|
||||
static float ComputePointLightScore(const NzSpheref& object, const NzAbstractRenderQueue::PointLight& light);
|
||||
static float ComputeSpotLightScore(const NzSpheref& object, const NzAbstractRenderQueue::SpotLight& light);
|
||||
static bool IsDirectionalLightSuitable(const NzSpheref& object, const NzAbstractRenderQueue::DirectionalLight& light);
|
||||
static bool IsPointLightSuitable(const NzSpheref& object, const NzAbstractRenderQueue::PointLight& light);
|
||||
static bool IsSpotLightSuitable(const NzSpheref& object, const NzAbstractRenderQueue::SpotLight& light);
|
||||
static float ComputeDirectionalLightScore(const Spheref& object, const AbstractRenderQueue::DirectionalLight& light);
|
||||
static float ComputePointLightScore(const Spheref& object, const AbstractRenderQueue::PointLight& light);
|
||||
static float ComputeSpotLightScore(const Spheref& object, const AbstractRenderQueue::SpotLight& light);
|
||||
static bool IsDirectionalLightSuitable(const Spheref& object, const AbstractRenderQueue::DirectionalLight& light);
|
||||
static bool IsPointLightSuitable(const Spheref& object, const AbstractRenderQueue::PointLight& light);
|
||||
static bool IsSpotLightSuitable(const Spheref& object, const AbstractRenderQueue::SpotLight& light);
|
||||
|
||||
struct LightIndex
|
||||
{
|
||||
nzLightType type;
|
||||
float score;
|
||||
unsigned int index;
|
||||
};
|
||||
struct LightIndex
|
||||
{
|
||||
LightType type;
|
||||
float score;
|
||||
unsigned int index;
|
||||
};
|
||||
|
||||
struct ShaderUniforms
|
||||
{
|
||||
NazaraSlot(NzShader, OnShaderUniformInvalidated, shaderUniformInvalidatedSlot);
|
||||
NazaraSlot(NzShader, OnShaderRelease, shaderReleaseSlot);
|
||||
struct ShaderUniforms
|
||||
{
|
||||
NazaraSlot(Shader, OnShaderUniformInvalidated, shaderUniformInvalidatedSlot);
|
||||
NazaraSlot(Shader, OnShaderRelease, shaderReleaseSlot);
|
||||
|
||||
NzLightUniforms lightUniforms;
|
||||
bool hasLightUniforms;
|
||||
LightUniforms 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
|
||||
/// Moins coûteux en mémoire que de stocker un LightUniforms 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;
|
||||
};
|
||||
// Autre uniformes
|
||||
int eyePosition;
|
||||
int sceneAmbient;
|
||||
int textureOverlay;
|
||||
};
|
||||
|
||||
mutable std::unordered_map<const NzShader*, ShaderUniforms> m_shaderUniforms;
|
||||
mutable std::vector<LightIndex> m_lights;
|
||||
NzBuffer m_vertexBuffer;
|
||||
mutable NzForwardRenderQueue m_renderQueue;
|
||||
NzVertexBuffer m_billboardPointBuffer;
|
||||
NzVertexBuffer m_spriteBuffer;
|
||||
unsigned int m_maxLightPassPerObject;
|
||||
mutable std::unordered_map<const Shader*, ShaderUniforms> m_shaderUniforms;
|
||||
mutable std::vector<LightIndex> m_lights;
|
||||
Buffer m_vertexBuffer;
|
||||
mutable ForwardRenderQueue m_renderQueue;
|
||||
VertexBuffer m_billboardPointBuffer;
|
||||
VertexBuffer m_spriteBuffer;
|
||||
unsigned int m_maxLightPassPerObject;
|
||||
|
||||
static NzIndexBuffer s_quadIndexBuffer;
|
||||
static NzVertexBuffer s_quadVertexBuffer;
|
||||
static NzVertexDeclaration s_billboardInstanceDeclaration;
|
||||
static NzVertexDeclaration s_billboardVertexDeclaration;
|
||||
};
|
||||
static IndexBuffer s_quadIndexBuffer;
|
||||
static VertexBuffer s_quadVertexBuffer;
|
||||
static VertexDeclaration s_billboardInstanceDeclaration;
|
||||
static VertexDeclaration s_billboardVertexDeclaration;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/ForwardRenderTechnique.inl>
|
||||
|
||||
|
||||
@@ -2,92 +2,95 @@
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
inline void NzForwardRenderTechnique::SendLightUniforms(const NzShader* shader, const NzLightUniforms& uniforms, unsigned int index, unsigned int uniformOffset) const
|
||||
namespace Nz
|
||||
{
|
||||
if (index < m_lights.size())
|
||||
inline void ForwardRenderTechnique::SendLightUniforms(const Shader* shader, const LightUniforms& uniforms, unsigned int index, unsigned int uniformOffset) const
|
||||
{
|
||||
const LightIndex& lightIndex = m_lights[index];
|
||||
|
||||
shader->SendInteger(uniforms.locations.type + uniformOffset, lightIndex.type); //< Sends the light type
|
||||
|
||||
switch (lightIndex.type)
|
||||
if (index < m_lights.size())
|
||||
{
|
||||
case nzLightType_Directional:
|
||||
const LightIndex& lightIndex = m_lights[index];
|
||||
|
||||
shader->SendInteger(uniforms.locations.type + uniformOffset, lightIndex.type); //< Sends the light type
|
||||
|
||||
switch (lightIndex.type)
|
||||
{
|
||||
const auto& light = m_renderQueue.directionalLights[lightIndex.index];
|
||||
case LightType_Directional:
|
||||
{
|
||||
const auto& light = m_renderQueue.directionalLights[lightIndex.index];
|
||||
|
||||
shader->SendColor(uniforms.locations.color + uniformOffset, light.color);
|
||||
shader->SendVector(uniforms.locations.factors + uniformOffset, NzVector2f(light.ambientFactor, light.diffuseFactor));
|
||||
shader->SendVector(uniforms.locations.parameters1 + uniformOffset, NzVector4f(light.direction));
|
||||
break;
|
||||
}
|
||||
shader->SendColor(uniforms.locations.color + uniformOffset, light.color);
|
||||
shader->SendVector(uniforms.locations.factors + uniformOffset, Vector2f(light.ambientFactor, light.diffuseFactor));
|
||||
shader->SendVector(uniforms.locations.parameters1 + uniformOffset, Vector4f(light.direction));
|
||||
break;
|
||||
}
|
||||
|
||||
case nzLightType_Point:
|
||||
{
|
||||
const auto& light = m_renderQueue.pointLights[lightIndex.index];
|
||||
case LightType_Point:
|
||||
{
|
||||
const auto& light = m_renderQueue.pointLights[lightIndex.index];
|
||||
|
||||
shader->SendColor(uniforms.locations.color + uniformOffset, light.color);
|
||||
shader->SendVector(uniforms.locations.factors + uniformOffset, NzVector2f(light.ambientFactor, light.diffuseFactor));
|
||||
shader->SendVector(uniforms.locations.parameters1 + uniformOffset, NzVector4f(light.position, light.attenuation));
|
||||
shader->SendVector(uniforms.locations.parameters2 + uniformOffset, NzVector4f(0.f, 0.f, 0.f, light.invRadius));
|
||||
break;
|
||||
}
|
||||
shader->SendColor(uniforms.locations.color + uniformOffset, light.color);
|
||||
shader->SendVector(uniforms.locations.factors + uniformOffset, Vector2f(light.ambientFactor, light.diffuseFactor));
|
||||
shader->SendVector(uniforms.locations.parameters1 + uniformOffset, Vector4f(light.position, light.attenuation));
|
||||
shader->SendVector(uniforms.locations.parameters2 + uniformOffset, Vector4f(0.f, 0.f, 0.f, light.invRadius));
|
||||
break;
|
||||
}
|
||||
|
||||
case nzLightType_Spot:
|
||||
{
|
||||
const auto& light = m_renderQueue.spotLights[lightIndex.index];
|
||||
case LightType_Spot:
|
||||
{
|
||||
const auto& light = m_renderQueue.spotLights[lightIndex.index];
|
||||
|
||||
shader->SendColor(uniforms.locations.color + uniformOffset, light.color);
|
||||
shader->SendVector(uniforms.locations.factors + uniformOffset, NzVector2f(light.ambientFactor, light.diffuseFactor));
|
||||
shader->SendVector(uniforms.locations.parameters1 + uniformOffset, NzVector4f(light.position, light.attenuation));
|
||||
shader->SendVector(uniforms.locations.parameters2 + uniformOffset, NzVector4f(light.direction, light.invRadius));
|
||||
shader->SendVector(uniforms.locations.parameters3 + uniformOffset, NzVector2f(light.innerAngleCosine, light.outerAngleCosine));
|
||||
break;
|
||||
shader->SendColor(uniforms.locations.color + uniformOffset, light.color);
|
||||
shader->SendVector(uniforms.locations.factors + uniformOffset, Vector2f(light.ambientFactor, light.diffuseFactor));
|
||||
shader->SendVector(uniforms.locations.parameters1 + uniformOffset, Vector4f(light.position, light.attenuation));
|
||||
shader->SendVector(uniforms.locations.parameters2 + uniformOffset, Vector4f(light.direction, light.invRadius));
|
||||
shader->SendVector(uniforms.locations.parameters3 + uniformOffset, Vector2f(light.innerAngleCosine, light.outerAngleCosine));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
shader->SendInteger(uniforms.locations.type + uniformOffset, -1); //< Disable the light in the shader
|
||||
}
|
||||
|
||||
inline float ForwardRenderTechnique::ComputeDirectionalLightScore(const Spheref& object, const AbstractRenderQueue::DirectionalLight& light)
|
||||
{
|
||||
NazaraUnused(object);
|
||||
NazaraUnused(light);
|
||||
|
||||
///TODO: Compute a score depending on the light luminosity
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
inline float ForwardRenderTechnique::ComputePointLightScore(const Spheref& object, const AbstractRenderQueue::PointLight& light)
|
||||
{
|
||||
///TODO: Compute a score depending on the light luminosity
|
||||
return object.SquaredDistance(light.position);
|
||||
}
|
||||
|
||||
inline float ForwardRenderTechnique::ComputeSpotLightScore(const Spheref& object, const AbstractRenderQueue::SpotLight& light)
|
||||
{
|
||||
///TODO: Compute a score depending on the light luminosity and spot direction
|
||||
return object.SquaredDistance(light.position);
|
||||
}
|
||||
|
||||
inline bool ForwardRenderTechnique::IsDirectionalLightSuitable(const Spheref& object, const AbstractRenderQueue::DirectionalLight& light)
|
||||
{
|
||||
NazaraUnused(object);
|
||||
NazaraUnused(light);
|
||||
|
||||
// Directional light are always suitables
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool ForwardRenderTechnique::IsPointLightSuitable(const Spheref& object, const AbstractRenderQueue::PointLight& light)
|
||||
{
|
||||
// If the object is too far away from this point light, there is not way it could light it
|
||||
return object.SquaredDistance(light.position) <= light.radius * light.radius;
|
||||
}
|
||||
|
||||
inline bool ForwardRenderTechnique::IsSpotLightSuitable(const Spheref& object, const AbstractRenderQueue::SpotLight& light)
|
||||
{
|
||||
///TODO: Exclude spot lights based on their direction and outer angle?
|
||||
return object.SquaredDistance(light.position) <= light.radius * light.radius;
|
||||
}
|
||||
else
|
||||
shader->SendInteger(uniforms.locations.type + uniformOffset, -1); //< Disable the light in the shader
|
||||
}
|
||||
|
||||
inline float NzForwardRenderTechnique::ComputeDirectionalLightScore(const NzSpheref& object, const NzAbstractRenderQueue::DirectionalLight& light)
|
||||
{
|
||||
NazaraUnused(object);
|
||||
NazaraUnused(light);
|
||||
|
||||
///TODO: Compute a score depending on the light luminosity
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
inline float NzForwardRenderTechnique::ComputePointLightScore(const NzSpheref& object, const NzAbstractRenderQueue::PointLight& light)
|
||||
{
|
||||
///TODO: Compute a score depending on the light luminosity
|
||||
return object.SquaredDistance(light.position);
|
||||
}
|
||||
|
||||
inline float NzForwardRenderTechnique::ComputeSpotLightScore(const NzSpheref& object, const NzAbstractRenderQueue::SpotLight& light)
|
||||
{
|
||||
///TODO: Compute a score depending on the light luminosity and spot direction
|
||||
return object.SquaredDistance(light.position);
|
||||
}
|
||||
|
||||
inline bool NzForwardRenderTechnique::IsDirectionalLightSuitable(const NzSpheref& object, const NzAbstractRenderQueue::DirectionalLight& light)
|
||||
{
|
||||
NazaraUnused(object);
|
||||
NazaraUnused(light);
|
||||
|
||||
// Directional light are always suitables
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool NzForwardRenderTechnique::IsPointLightSuitable(const NzSpheref& object, const NzAbstractRenderQueue::PointLight& light)
|
||||
{
|
||||
// If the object is too far away from this point light, there is not way it could light it
|
||||
return object.SquaredDistance(light.position) <= light.radius * light.radius;
|
||||
}
|
||||
|
||||
inline bool NzForwardRenderTechnique::IsSpotLightSuitable(const NzSpheref& object, const NzAbstractRenderQueue::SpotLight& light)
|
||||
{
|
||||
///TODO: Exclude spot lights based on their direction and outer angle?
|
||||
return object.SquaredDistance(light.position) <= light.radius * light.radius;
|
||||
}
|
||||
|
||||
@@ -11,20 +11,23 @@
|
||||
#include <Nazara/Core/Initializer.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
|
||||
class NAZARA_GRAPHICS_API NzGraphics
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzGraphics() = delete;
|
||||
~NzGraphics() = delete;
|
||||
class NAZARA_GRAPHICS_API Graphics
|
||||
{
|
||||
public:
|
||||
Graphics() = delete;
|
||||
~Graphics() = delete;
|
||||
|
||||
static bool Initialize();
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
static bool IsInitialized();
|
||||
|
||||
static void Uninitialize();
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
};
|
||||
private:
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_GRAPHICS_HPP
|
||||
|
||||
@@ -11,16 +11,19 @@
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Utility/GuillotineImageAtlas.hpp>
|
||||
|
||||
class NAZARA_GRAPHICS_API NzGuillotineTextureAtlas : public NzGuillotineImageAtlas
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzGuillotineTextureAtlas() = default;
|
||||
~NzGuillotineTextureAtlas() = default;
|
||||
class NAZARA_GRAPHICS_API GuillotineTextureAtlas : public GuillotineImageAtlas
|
||||
{
|
||||
public:
|
||||
GuillotineTextureAtlas() = default;
|
||||
~GuillotineTextureAtlas() = default;
|
||||
|
||||
nzUInt32 GetStorage() const;
|
||||
UInt32 GetStorage() const;
|
||||
|
||||
private:
|
||||
NzAbstractImage* ResizeImage(NzAbstractImage* oldImage, const NzVector2ui& size) const override;
|
||||
};
|
||||
private:
|
||||
AbstractImage* ResizeImage(AbstractImage* oldImage, const Vector2ui& size) const override;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_GUILLOTINETEXTUREATLAS_HPP
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#ifndef NAZARA_INSTANCEDRENDERABLE_HPP
|
||||
#define NAZARA_INSTANCEDRENDERABLE_HPP
|
||||
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Core/PrimitiveList.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
@@ -18,64 +17,69 @@
|
||||
#include <Nazara/Math/Frustum.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
|
||||
class NzAbstractRenderQueue;
|
||||
class NzInstancedRenderable;
|
||||
|
||||
using NzInstancedRenderableConstRef = NzObjectRef<const NzInstancedRenderable>;
|
||||
using NzInstancedRenderableLibrary = NzObjectLibrary<NzInstancedRenderable>;
|
||||
using NzInstancedRenderableRef = NzObjectRef<NzInstancedRenderable>;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzInstancedRenderable : public NzRefCounted
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
struct InstanceData;
|
||||
class AbstractRenderQueue;
|
||||
class InstancedRenderable;
|
||||
|
||||
NzInstancedRenderable() = default;
|
||||
inline NzInstancedRenderable(const NzInstancedRenderable& renderable);
|
||||
virtual ~NzInstancedRenderable();
|
||||
using InstancedRenderableConstRef = ObjectRef<const InstancedRenderable>;
|
||||
using InstancedRenderableLibrary = ObjectLibrary<InstancedRenderable>;
|
||||
using InstancedRenderableRef = ObjectRef<InstancedRenderable>;
|
||||
|
||||
inline void EnsureBoundingVolumeUpdated() const;
|
||||
class NAZARA_GRAPHICS_API InstancedRenderable : public RefCounted
|
||||
{
|
||||
public:
|
||||
struct InstanceData;
|
||||
|
||||
virtual void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const InstanceData& instanceData) const = 0;
|
||||
virtual bool Cull(const NzFrustumf& frustum, const InstanceData& instanceData) const;
|
||||
virtual const NzBoundingVolumef& GetBoundingVolume() const;
|
||||
virtual void InvalidateData(InstanceData* instanceData, nzUInt32 flags) const;
|
||||
virtual void UpdateBoundingVolume(InstanceData* instanceData) const;
|
||||
virtual void UpdateData(InstanceData* instanceData) const;
|
||||
InstancedRenderable() = default;
|
||||
inline InstancedRenderable(const InstancedRenderable& renderable);
|
||||
InstancedRenderable(InstancedRenderable&& renderable) = delete;
|
||||
virtual ~InstancedRenderable();
|
||||
|
||||
inline NzInstancedRenderable& operator=(const NzInstancedRenderable& renderable);
|
||||
inline void EnsureBoundingVolumeUpdated() const;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnInstancedRenderableInvalidateData, const NzInstancedRenderable* /*instancedRenderable*/, nzUInt32 /*flags*/);
|
||||
NazaraSignal(OnInstancedRenderableRelease, const NzInstancedRenderable* /*instancedRenderable*/);
|
||||
virtual void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const = 0;
|
||||
virtual bool Cull(const Frustumf& frustum, const InstanceData& instanceData) const;
|
||||
virtual const BoundingVolumef& GetBoundingVolume() const;
|
||||
virtual void InvalidateData(InstanceData* instanceData, UInt32 flags) const;
|
||||
virtual void UpdateBoundingVolume(InstanceData* instanceData) const;
|
||||
virtual void UpdateData(InstanceData* instanceData) const;
|
||||
|
||||
struct InstanceData
|
||||
{
|
||||
InstanceData(NzMatrix4f& referenceMatrix) :
|
||||
transformMatrix(referenceMatrix),
|
||||
flags(0)
|
||||
inline InstancedRenderable& operator=(const InstancedRenderable& renderable);
|
||||
InstancedRenderable& operator=(InstancedRenderable&& renderable) = delete;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnInstancedRenderableInvalidateData, const InstancedRenderable* /*instancedRenderable*/, UInt32 /*flags*/);
|
||||
NazaraSignal(OnInstancedRenderableRelease, const InstancedRenderable* /*instancedRenderable*/);
|
||||
|
||||
struct InstanceData
|
||||
{
|
||||
}
|
||||
InstanceData(Matrix4f& referenceMatrix) :
|
||||
transformMatrix(referenceMatrix),
|
||||
flags(0)
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<nzUInt8> data;
|
||||
NzBoundingVolumef volume;
|
||||
NzMatrix4f& transformMatrix;
|
||||
nzUInt32 flags;
|
||||
};
|
||||
std::vector<UInt8> data;
|
||||
BoundingVolumef volume;
|
||||
Matrix4f& transformMatrix;
|
||||
UInt32 flags;
|
||||
};
|
||||
|
||||
protected:
|
||||
virtual void MakeBoundingVolume() const = 0;
|
||||
void InvalidateBoundingVolume();
|
||||
inline void InvalidateInstanceData(nzUInt32 flags);
|
||||
inline void UpdateBoundingVolume() const;
|
||||
protected:
|
||||
virtual void MakeBoundingVolume() const = 0;
|
||||
void InvalidateBoundingVolume();
|
||||
inline void InvalidateInstanceData(UInt32 flags);
|
||||
inline void UpdateBoundingVolume() const;
|
||||
|
||||
mutable NzBoundingVolumef m_boundingVolume;
|
||||
mutable BoundingVolumef m_boundingVolume;
|
||||
|
||||
private:
|
||||
mutable bool m_boundingVolumeUpdated;
|
||||
private:
|
||||
mutable bool m_boundingVolumeUpdated;
|
||||
|
||||
static NzInstancedRenderableLibrary::LibraryMap s_library;
|
||||
};
|
||||
static InstancedRenderableLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/InstancedRenderable.inl>
|
||||
|
||||
|
||||
@@ -2,39 +2,42 @@
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
inline NzInstancedRenderable::NzInstancedRenderable(const NzInstancedRenderable& renderable) :
|
||||
NzRefCounted(),
|
||||
m_boundingVolume(renderable.m_boundingVolume),
|
||||
m_boundingVolumeUpdated(renderable.m_boundingVolumeUpdated)
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
inline InstancedRenderable::InstancedRenderable(const InstancedRenderable& renderable) :
|
||||
RefCounted(),
|
||||
m_boundingVolume(renderable.m_boundingVolume),
|
||||
m_boundingVolumeUpdated(renderable.m_boundingVolumeUpdated)
|
||||
{
|
||||
}
|
||||
|
||||
inline void NzInstancedRenderable::EnsureBoundingVolumeUpdated() const
|
||||
{
|
||||
if (!m_boundingVolumeUpdated)
|
||||
UpdateBoundingVolume();
|
||||
}
|
||||
inline void InstancedRenderable::EnsureBoundingVolumeUpdated() const
|
||||
{
|
||||
if (!m_boundingVolumeUpdated)
|
||||
UpdateBoundingVolume();
|
||||
}
|
||||
|
||||
inline void NzInstancedRenderable::InvalidateBoundingVolume()
|
||||
{
|
||||
m_boundingVolumeUpdated = false;
|
||||
}
|
||||
inline void InstancedRenderable::InvalidateBoundingVolume()
|
||||
{
|
||||
m_boundingVolumeUpdated = false;
|
||||
}
|
||||
|
||||
inline void NzInstancedRenderable::InvalidateInstanceData(nzUInt32 flags)
|
||||
{
|
||||
OnInstancedRenderableInvalidateData(this, flags);
|
||||
}
|
||||
inline void InstancedRenderable::InvalidateInstanceData(UInt32 flags)
|
||||
{
|
||||
OnInstancedRenderableInvalidateData(this, flags);
|
||||
}
|
||||
|
||||
inline NzInstancedRenderable& NzInstancedRenderable::operator=(const NzInstancedRenderable& renderable)
|
||||
{
|
||||
m_boundingVolume = renderable.m_boundingVolume;
|
||||
m_boundingVolumeUpdated = renderable.m_boundingVolumeUpdated;
|
||||
inline InstancedRenderable& InstancedRenderable::operator=(const InstancedRenderable& renderable)
|
||||
{
|
||||
m_boundingVolume = renderable.m_boundingVolume;
|
||||
m_boundingVolumeUpdated = renderable.m_boundingVolumeUpdated;
|
||||
|
||||
return *this;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void NzInstancedRenderable::UpdateBoundingVolume() const
|
||||
{
|
||||
MakeBoundingVolume();
|
||||
m_boundingVolumeUpdated = true;
|
||||
inline void InstancedRenderable::UpdateBoundingVolume() const
|
||||
{
|
||||
MakeBoundingVolume();
|
||||
m_boundingVolumeUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,86 +12,89 @@
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
#include <Nazara/Graphics/Renderable.hpp>
|
||||
|
||||
class NzLight;
|
||||
struct NzLightUniforms;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzLight : public NzRenderable
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzLight(nzLightType type = nzLightType_Point);
|
||||
NzLight(const NzLight& light) = default;
|
||||
~NzLight() = default;
|
||||
class Light;
|
||||
struct LightUniforms;
|
||||
|
||||
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const NzMatrix4f& transformMatrix) const override;
|
||||
|
||||
NzLight* Clone() const;
|
||||
NzLight* Create() const;
|
||||
|
||||
bool Cull(const NzFrustumf& frustum, const NzMatrix4f& transformMatrix) const override;
|
||||
|
||||
float GetAmbientFactor() const;
|
||||
float GetAttenuation() const;
|
||||
NzColor GetColor() const;
|
||||
float GetDiffuseFactor() const;
|
||||
float GetInnerAngle() const;
|
||||
float GetInnerAngleCosine() const;
|
||||
float GetInvRadius() const;
|
||||
nzLightType GetLightType() const;
|
||||
float GetOuterAngle() const;
|
||||
float GetOuterAngleCosine() const;
|
||||
float GetOuterAngleTangent() const;
|
||||
float GetRadius() const;
|
||||
|
||||
void SetAmbientFactor(float factor);
|
||||
void SetAttenuation(float attenuation);
|
||||
void SetColor(const NzColor& color);
|
||||
void SetDiffuseFactor(float factor);
|
||||
void SetInnerAngle(float innerAngle);
|
||||
void SetLightType(nzLightType type);
|
||||
void SetOuterAngle(float outerAngle);
|
||||
void SetRadius(float radius);
|
||||
|
||||
void UpdateBoundingVolume(const NzMatrix4f& transformMatrix) override;
|
||||
|
||||
NzLight& operator=(const NzLight& light) = default;
|
||||
|
||||
private:
|
||||
void MakeBoundingVolume() const override;
|
||||
|
||||
nzLightType m_type;
|
||||
NzColor m_color;
|
||||
float m_ambientFactor;
|
||||
float m_attenuation;
|
||||
float m_diffuseFactor;
|
||||
float m_innerAngle;
|
||||
float m_innerAngleCosine;
|
||||
float m_invRadius;
|
||||
float m_outerAngle;
|
||||
float m_outerAngleCosine;
|
||||
float m_outerAngleTangent;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
struct NzLightUniforms
|
||||
{
|
||||
struct UniformLocations
|
||||
class NAZARA_GRAPHICS_API Light : public Renderable
|
||||
{
|
||||
int type;
|
||||
int color;
|
||||
int factors;
|
||||
int parameters1;
|
||||
int parameters2;
|
||||
int parameters3;
|
||||
public:
|
||||
Light(LightType type = LightType_Point);
|
||||
Light(const Light& light) = default;
|
||||
~Light() = default;
|
||||
|
||||
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix) const override;
|
||||
|
||||
Light* Clone() const;
|
||||
Light* Create() const;
|
||||
|
||||
bool Cull(const Frustumf& frustum, const Matrix4f& transformMatrix) const override;
|
||||
|
||||
float GetAmbientFactor() const;
|
||||
float GetAttenuation() const;
|
||||
Color GetColor() const;
|
||||
float GetDiffuseFactor() const;
|
||||
float GetInnerAngle() const;
|
||||
float GetInnerAngleCosine() const;
|
||||
float GetInvRadius() const;
|
||||
LightType GetLightType() const;
|
||||
float GetOuterAngle() const;
|
||||
float GetOuterAngleCosine() const;
|
||||
float GetOuterAngleTangent() const;
|
||||
float GetRadius() const;
|
||||
|
||||
void SetAmbientFactor(float factor);
|
||||
void SetAttenuation(float attenuation);
|
||||
void SetColor(const Color& color);
|
||||
void SetDiffuseFactor(float factor);
|
||||
void SetInnerAngle(float innerAngle);
|
||||
void SetLightType(LightType type);
|
||||
void SetOuterAngle(float outerAngle);
|
||||
void SetRadius(float radius);
|
||||
|
||||
void UpdateBoundingVolume(const Matrix4f& transformMatrix) override;
|
||||
|
||||
Light& operator=(const Light& light) = default;
|
||||
|
||||
private:
|
||||
void MakeBoundingVolume() const override;
|
||||
|
||||
LightType m_type;
|
||||
Color m_color;
|
||||
float m_ambientFactor;
|
||||
float m_attenuation;
|
||||
float m_diffuseFactor;
|
||||
float m_innerAngle;
|
||||
float m_innerAngleCosine;
|
||||
float m_invRadius;
|
||||
float m_outerAngle;
|
||||
float m_outerAngleCosine;
|
||||
float m_outerAngleTangent;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
bool ubo;
|
||||
|
||||
union
|
||||
struct LightUniforms
|
||||
{
|
||||
UniformLocations locations;
|
||||
int blockLocation;
|
||||
struct UniformLocations
|
||||
{
|
||||
int type;
|
||||
int color;
|
||||
int factors;
|
||||
int parameters1;
|
||||
int parameters2;
|
||||
int parameters3;
|
||||
};
|
||||
|
||||
bool ubo;
|
||||
|
||||
union
|
||||
{
|
||||
UniformLocations locations;
|
||||
int blockLocation;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/Light.inl>
|
||||
|
||||
|
||||
@@ -5,103 +5,106 @@
|
||||
#include <memory>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
inline float NzLight::GetAmbientFactor() const
|
||||
namespace Nz
|
||||
{
|
||||
return m_ambientFactor;
|
||||
}
|
||||
inline float Light::GetAmbientFactor() const
|
||||
{
|
||||
return m_ambientFactor;
|
||||
}
|
||||
|
||||
inline float NzLight::GetAttenuation() const
|
||||
{
|
||||
return m_attenuation;
|
||||
}
|
||||
inline float Light::GetAttenuation() const
|
||||
{
|
||||
return m_attenuation;
|
||||
}
|
||||
|
||||
inline NzColor NzLight::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
inline Color Light::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
inline float NzLight::GetDiffuseFactor() const
|
||||
{
|
||||
return m_diffuseFactor;
|
||||
}
|
||||
inline float Light::GetDiffuseFactor() const
|
||||
{
|
||||
return m_diffuseFactor;
|
||||
}
|
||||
|
||||
inline float NzLight::GetInnerAngle() const
|
||||
{
|
||||
return m_innerAngle;
|
||||
}
|
||||
inline float Light::GetInnerAngle() const
|
||||
{
|
||||
return m_innerAngle;
|
||||
}
|
||||
|
||||
inline nzLightType NzLight::GetLightType() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
inline LightType Light::GetLightType() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
inline float NzLight::GetOuterAngle() const
|
||||
{
|
||||
return m_outerAngle;
|
||||
}
|
||||
inline float Light::GetOuterAngle() const
|
||||
{
|
||||
return m_outerAngle;
|
||||
}
|
||||
|
||||
inline float NzLight::GetOuterAngleCosine() const
|
||||
{
|
||||
return m_outerAngleCosine;
|
||||
}
|
||||
inline float Light::GetOuterAngleCosine() const
|
||||
{
|
||||
return m_outerAngleCosine;
|
||||
}
|
||||
|
||||
inline float NzLight::GetOuterAngleTangent() const
|
||||
{
|
||||
return m_outerAngleTangent;
|
||||
}
|
||||
inline float Light::GetOuterAngleTangent() const
|
||||
{
|
||||
return m_outerAngleTangent;
|
||||
}
|
||||
|
||||
inline float NzLight::GetRadius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
inline float Light::GetRadius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
inline void NzLight::SetAmbientFactor(float factor)
|
||||
{
|
||||
m_ambientFactor = factor;
|
||||
}
|
||||
inline void Light::SetAmbientFactor(float factor)
|
||||
{
|
||||
m_ambientFactor = factor;
|
||||
}
|
||||
|
||||
inline void NzLight::SetAttenuation(float attenuation)
|
||||
{
|
||||
m_attenuation = attenuation;
|
||||
}
|
||||
inline void Light::SetAttenuation(float attenuation)
|
||||
{
|
||||
m_attenuation = attenuation;
|
||||
}
|
||||
|
||||
inline void NzLight::SetColor(const NzColor& color)
|
||||
{
|
||||
m_color = color;
|
||||
}
|
||||
inline void Light::SetColor(const Color& color)
|
||||
{
|
||||
m_color = color;
|
||||
}
|
||||
|
||||
inline void NzLight::SetDiffuseFactor(float factor)
|
||||
{
|
||||
m_diffuseFactor = factor;
|
||||
}
|
||||
inline void Light::SetDiffuseFactor(float factor)
|
||||
{
|
||||
m_diffuseFactor = factor;
|
||||
}
|
||||
|
||||
inline void NzLight::SetInnerAngle(float innerAngle)
|
||||
{
|
||||
m_innerAngle = innerAngle;
|
||||
m_innerAngleCosine = std::cos(NzDegreeToRadian(m_innerAngle));
|
||||
}
|
||||
inline void Light::SetInnerAngle(float innerAngle)
|
||||
{
|
||||
m_innerAngle = innerAngle;
|
||||
m_innerAngleCosine = std::cos(DegreeToRadian(m_innerAngle));
|
||||
}
|
||||
|
||||
inline void NzLight::SetLightType(nzLightType type)
|
||||
{
|
||||
m_type = type;
|
||||
}
|
||||
inline void Light::SetLightType(LightType type)
|
||||
{
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
inline void NzLight::SetOuterAngle(float outerAngle)
|
||||
{
|
||||
m_outerAngle = outerAngle;
|
||||
m_outerAngleCosine = std::cos(NzDegreeToRadian(m_outerAngle));
|
||||
m_outerAngleTangent = std::tan(NzDegreeToRadian(m_outerAngle));
|
||||
inline void Light::SetOuterAngle(float outerAngle)
|
||||
{
|
||||
m_outerAngle = outerAngle;
|
||||
m_outerAngleCosine = std::cos(DegreeToRadian(m_outerAngle));
|
||||
m_outerAngleTangent = std::tan(DegreeToRadian(m_outerAngle));
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
}
|
||||
InvalidateBoundingVolume();
|
||||
}
|
||||
|
||||
inline void NzLight::SetRadius(float radius)
|
||||
{
|
||||
m_radius = radius;
|
||||
inline void Light::SetRadius(float radius)
|
||||
{
|
||||
m_radius = radius;
|
||||
|
||||
m_invRadius = 1.f / m_radius;
|
||||
m_invRadius = 1.f / m_radius;
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
InvalidateBoundingVolume();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/DebugOff.hpp>
|
||||
|
||||
@@ -24,169 +24,172 @@
|
||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||
#include <Nazara/Renderer/UberShader.hpp>
|
||||
|
||||
struct NAZARA_GRAPHICS_API NzMaterialParams
|
||||
namespace Nz
|
||||
{
|
||||
bool loadAlphaMap = true;
|
||||
bool loadDiffuseMap = true;
|
||||
bool loadEmissiveMap = true;
|
||||
bool loadHeightMap = true;
|
||||
bool loadNormalMap = true;
|
||||
bool loadSpecularMap = true;
|
||||
NzString shaderName = "Basic";
|
||||
struct NAZARA_GRAPHICS_API MaterialParams
|
||||
{
|
||||
bool loadAlphaMap = true;
|
||||
bool loadDiffuseMap = true;
|
||||
bool loadEmissiveMap = true;
|
||||
bool loadHeightMap = true;
|
||||
bool loadNormalMap = true;
|
||||
bool loadSpecularMap = true;
|
||||
String shaderName = "Basic";
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
class NzMaterial;
|
||||
class Material;
|
||||
|
||||
using NzMaterialConstRef = NzObjectRef<const NzMaterial>;
|
||||
using NzMaterialLibrary = NzObjectLibrary<NzMaterial>;
|
||||
using NzMaterialLoader = NzResourceLoader<NzMaterial, NzMaterialParams>;
|
||||
using NzMaterialManager = NzResourceManager<NzMaterial, NzMaterialParams>;
|
||||
using NzMaterialRef = NzObjectRef<NzMaterial>;
|
||||
using MaterialConstRef = ObjectRef<const Material>;
|
||||
using MaterialLibrary = ObjectLibrary<Material>;
|
||||
using MaterialLoader = ResourceLoader<Material, MaterialParams>;
|
||||
using MaterialManager = ResourceManager<Material, MaterialParams>;
|
||||
using MaterialRef = ObjectRef<Material>;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzMaterial : public NzRefCounted, public NzResource
|
||||
{
|
||||
friend NzMaterialLibrary;
|
||||
friend NzMaterialLoader;
|
||||
friend NzMaterialManager;
|
||||
friend class NzGraphics;
|
||||
class NAZARA_GRAPHICS_API Material : public RefCounted, public Resource
|
||||
{
|
||||
friend MaterialLibrary;
|
||||
friend MaterialLoader;
|
||||
friend MaterialManager;
|
||||
friend class Graphics;
|
||||
|
||||
public:
|
||||
NzMaterial();
|
||||
NzMaterial(const NzMaterial& material);
|
||||
~NzMaterial();
|
||||
public:
|
||||
Material();
|
||||
Material(const Material& material);
|
||||
~Material();
|
||||
|
||||
const NzShader* Apply(nzUInt32 shaderFlags = 0, nzUInt8 textureUnit = 0, nzUInt8* lastUsedUnit = nullptr) const;
|
||||
const Shader* Apply(UInt32 shaderFlags = 0, UInt8 textureUnit = 0, UInt8* 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);
|
||||
void Enable(RendererParameter renderParameter, bool enable);
|
||||
void EnableAlphaTest(bool alphaTest);
|
||||
void EnableDepthSorting(bool depthSorting);
|
||||
void EnableLighting(bool lighting);
|
||||
void EnableTransform(bool transform);
|
||||
|
||||
NzTexture* GetAlphaMap() const;
|
||||
float GetAlphaThreshold() const;
|
||||
NzColor GetAmbientColor() const;
|
||||
nzRendererComparison GetDepthFunc() const;
|
||||
NzColor GetDiffuseColor() const;
|
||||
NzTexture* GetDiffuseMap() const;
|
||||
NzTextureSampler& GetDiffuseSampler();
|
||||
const NzTextureSampler& GetDiffuseSampler() const;
|
||||
nzBlendFunc GetDstBlend() const;
|
||||
NzTexture* GetEmissiveMap() const;
|
||||
nzFaceSide GetFaceCulling() const;
|
||||
nzFaceFilling GetFaceFilling() const;
|
||||
NzTexture* GetHeightMap() const;
|
||||
NzTexture* GetNormalMap() const;
|
||||
const NzRenderStates& GetRenderStates() const;
|
||||
const NzUberShader* GetShader() const;
|
||||
const NzUberShaderInstance* GetShaderInstance(nzUInt32 flags = nzShaderFlags_None) const;
|
||||
float GetShininess() const;
|
||||
NzColor GetSpecularColor() const;
|
||||
NzTexture* GetSpecularMap() const;
|
||||
NzTextureSampler& GetSpecularSampler();
|
||||
const NzTextureSampler& GetSpecularSampler() const;
|
||||
nzBlendFunc GetSrcBlend() const;
|
||||
Texture* GetAlphaMap() const;
|
||||
float GetAlphaThreshold() const;
|
||||
Color GetAmbientColor() const;
|
||||
RendererComparison GetDepthFunc() const;
|
||||
Color GetDiffuseColor() const;
|
||||
Texture* GetDiffuseMap() const;
|
||||
TextureSampler& GetDiffuseSampler();
|
||||
const TextureSampler& GetDiffuseSampler() const;
|
||||
BlendFunc GetDstBlend() const;
|
||||
Texture* GetEmissiveMap() const;
|
||||
FaceSide GetFaceCulling() const;
|
||||
FaceFilling GetFaceFilling() const;
|
||||
Texture* GetHeightMap() const;
|
||||
Texture* GetNormalMap() const;
|
||||
const RenderStates& GetRenderStates() const;
|
||||
const UberShader* GetShader() const;
|
||||
const UberShaderInstance* GetShaderInstance(UInt32 flags = ShaderFlags_None) const;
|
||||
float GetShininess() const;
|
||||
Color GetSpecularColor() const;
|
||||
Texture* GetSpecularMap() const;
|
||||
TextureSampler& GetSpecularSampler();
|
||||
const TextureSampler& GetSpecularSampler() const;
|
||||
BlendFunc GetSrcBlend() const;
|
||||
|
||||
bool HasAlphaMap() const;
|
||||
bool HasDiffuseMap() const;
|
||||
bool HasEmissiveMap() const;
|
||||
bool HasHeightMap() const;
|
||||
bool HasNormalMap() const;
|
||||
bool HasSpecularMap() const;
|
||||
bool HasAlphaMap() const;
|
||||
bool HasDiffuseMap() const;
|
||||
bool HasEmissiveMap() const;
|
||||
bool HasHeightMap() const;
|
||||
bool HasNormalMap() const;
|
||||
bool HasSpecularMap() const;
|
||||
|
||||
bool IsAlphaTestEnabled() const;
|
||||
bool IsDepthSortingEnabled() const;
|
||||
bool IsEnabled(nzRendererParameter renderParameter) const;
|
||||
bool IsLightingEnabled() const;
|
||||
bool IsTransformEnabled() const;
|
||||
bool IsAlphaTestEnabled() const;
|
||||
bool IsDepthSortingEnabled() const;
|
||||
bool IsEnabled(RendererParameter renderParameter) const;
|
||||
bool IsLightingEnabled() const;
|
||||
bool IsTransformEnabled() const;
|
||||
|
||||
bool LoadFromFile(const NzString& filePath, const NzMaterialParams& params = NzMaterialParams());
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const NzMaterialParams& params = NzMaterialParams());
|
||||
bool LoadFromStream(NzInputStream& stream, const NzMaterialParams& params = NzMaterialParams());
|
||||
bool LoadFromFile(const String& filePath, const MaterialParams& params = MaterialParams());
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const MaterialParams& params = MaterialParams());
|
||||
bool LoadFromStream(InputStream& stream, const MaterialParams& params = MaterialParams());
|
||||
|
||||
void Reset();
|
||||
void Reset();
|
||||
|
||||
bool SetAlphaMap(const NzString& textureName);
|
||||
void SetAlphaMap(NzTextureRef alphaMap);
|
||||
void SetAlphaThreshold(float alphaThreshold);
|
||||
void SetAmbientColor(const NzColor& ambient);
|
||||
void SetDepthFunc(nzRendererComparison depthFunc);
|
||||
void SetDiffuseColor(const NzColor& diffuse);
|
||||
bool SetDiffuseMap(const NzString& textureName);
|
||||
void SetDiffuseMap(NzTextureRef diffuseMap);
|
||||
void SetDiffuseSampler(const NzTextureSampler& sampler);
|
||||
void SetDstBlend(nzBlendFunc func);
|
||||
bool SetEmissiveMap(const NzString& textureName);
|
||||
void SetEmissiveMap(NzTextureRef textureName);
|
||||
void SetFaceCulling(nzFaceSide faceSide);
|
||||
void SetFaceFilling(nzFaceFilling filling);
|
||||
bool SetHeightMap(const NzString& textureName);
|
||||
void SetHeightMap(NzTextureRef textureName);
|
||||
bool SetNormalMap(const NzString& textureName);
|
||||
void SetNormalMap(NzTextureRef textureName);
|
||||
void SetRenderStates(const NzRenderStates& states);
|
||||
void SetShader(NzUberShaderConstRef uberShader);
|
||||
bool SetShader(const NzString& uberShaderName);
|
||||
void SetShininess(float shininess);
|
||||
void SetSpecularColor(const NzColor& specular);
|
||||
bool SetSpecularMap(const NzString& textureName);
|
||||
void SetSpecularMap(NzTextureRef specularMap);
|
||||
void SetSpecularSampler(const NzTextureSampler& sampler);
|
||||
void SetSrcBlend(nzBlendFunc func);
|
||||
bool SetAlphaMap(const String& textureName);
|
||||
void SetAlphaMap(TextureRef alphaMap);
|
||||
void SetAlphaThreshold(float alphaThreshold);
|
||||
void SetAmbientColor(const Color& ambient);
|
||||
void SetDepthFunc(RendererComparison depthFunc);
|
||||
void SetDiffuseColor(const Color& diffuse);
|
||||
bool SetDiffuseMap(const String& textureName);
|
||||
void SetDiffuseMap(TextureRef diffuseMap);
|
||||
void SetDiffuseSampler(const TextureSampler& sampler);
|
||||
void SetDstBlend(BlendFunc func);
|
||||
bool SetEmissiveMap(const String& textureName);
|
||||
void SetEmissiveMap(TextureRef textureName);
|
||||
void SetFaceCulling(FaceSide faceSide);
|
||||
void SetFaceFilling(FaceFilling filling);
|
||||
bool SetHeightMap(const String& textureName);
|
||||
void SetHeightMap(TextureRef textureName);
|
||||
bool SetNormalMap(const String& textureName);
|
||||
void SetNormalMap(TextureRef textureName);
|
||||
void SetRenderStates(const RenderStates& states);
|
||||
void SetShader(UberShaderConstRef uberShader);
|
||||
bool SetShader(const String& uberShaderName);
|
||||
void SetShininess(float shininess);
|
||||
void SetSpecularColor(const Color& specular);
|
||||
bool SetSpecularMap(const String& textureName);
|
||||
void SetSpecularMap(TextureRef specularMap);
|
||||
void SetSpecularSampler(const TextureSampler& sampler);
|
||||
void SetSrcBlend(BlendFunc func);
|
||||
|
||||
NzMaterial& operator=(const NzMaterial& material);
|
||||
Material& operator=(const Material& material);
|
||||
|
||||
static NzMaterialRef GetDefault();
|
||||
template<typename... Args> static NzMaterialRef New(Args&&... args);
|
||||
static MaterialRef GetDefault();
|
||||
template<typename... Args> static MaterialRef New(Args&&... args);
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnMaterialRelease, const NzMaterial* /*material*/);
|
||||
NazaraSignal(OnMaterialReset, const NzMaterial* /*material*/);
|
||||
// Signals:
|
||||
NazaraSignal(OnMaterialRelease, const Material* /*material*/);
|
||||
NazaraSignal(OnMaterialReset, const Material* /*material*/);
|
||||
|
||||
private:
|
||||
struct ShaderInstance
|
||||
{
|
||||
const NzShader* shader;
|
||||
NzUberShaderInstance* uberInstance = nullptr;
|
||||
int uniforms[nzMaterialUniform_Max+1];
|
||||
};
|
||||
private:
|
||||
struct ShaderInstance
|
||||
{
|
||||
const Shader* shader;
|
||||
UberShaderInstance* uberInstance = nullptr;
|
||||
int uniforms[MaterialUniform_Max+1];
|
||||
};
|
||||
|
||||
void Copy(const NzMaterial& material);
|
||||
void GenerateShader(nzUInt32 flags) const;
|
||||
void InvalidateShaders();
|
||||
void Copy(const Material& material);
|
||||
void GenerateShader(UInt32 flags) const;
|
||||
void InvalidateShaders();
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
NzColor m_ambientColor;
|
||||
NzColor m_diffuseColor;
|
||||
NzColor m_specularColor;
|
||||
NzRenderStates m_states;
|
||||
NzTextureSampler m_diffuseSampler;
|
||||
NzTextureSampler m_specularSampler;
|
||||
NzTextureRef m_alphaMap;
|
||||
NzTextureRef m_diffuseMap;
|
||||
NzTextureRef m_emissiveMap;
|
||||
NzTextureRef m_heightMap;
|
||||
NzTextureRef m_normalMap;
|
||||
NzTextureRef m_specularMap;
|
||||
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;
|
||||
float m_shininess;
|
||||
Color m_ambientColor;
|
||||
Color m_diffuseColor;
|
||||
Color m_specularColor;
|
||||
RenderStates m_states;
|
||||
TextureSampler m_diffuseSampler;
|
||||
TextureSampler m_specularSampler;
|
||||
TextureRef m_alphaMap;
|
||||
TextureRef m_diffuseMap;
|
||||
TextureRef m_emissiveMap;
|
||||
TextureRef m_heightMap;
|
||||
TextureRef m_normalMap;
|
||||
TextureRef m_specularMap;
|
||||
UberShaderConstRef m_uberShader;
|
||||
mutable ShaderInstance m_shaders[ShaderFlags_Max+1];
|
||||
bool m_alphaTestEnabled;
|
||||
bool m_depthSortingEnabled;
|
||||
bool m_lightingEnabled;
|
||||
bool m_transformEnabled;
|
||||
float m_alphaThreshold;
|
||||
float m_shininess;
|
||||
|
||||
static NzMaterialLibrary::LibraryMap s_library;
|
||||
static NzMaterialLoader::LoaderList s_loaders;
|
||||
static NzMaterialManager::ManagerMap s_managerMap;
|
||||
static NzMaterialManager::ManagerParams s_managerParameters;
|
||||
static NzMaterialRef s_defaultMaterial;
|
||||
};
|
||||
static MaterialLibrary::LibraryMap s_library;
|
||||
static MaterialLoader::LoaderList s_loaders;
|
||||
static MaterialManager::ManagerMap s_managerMap;
|
||||
static MaterialManager::ManagerParams s_managerParameters;
|
||||
static MaterialRef s_defaultMaterial;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/Material.inl>
|
||||
|
||||
|
||||
@@ -5,13 +5,16 @@
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
template<typename... Args>
|
||||
NzMaterialRef NzMaterial::New(Args&&... args)
|
||||
namespace Nz
|
||||
{
|
||||
std::unique_ptr<NzMaterial> object(new NzMaterial(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
template<typename... Args>
|
||||
MaterialRef Material::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<Material> object(new Material(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
||||
@@ -14,78 +14,81 @@
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
|
||||
struct NAZARA_GRAPHICS_API NzModelParameters
|
||||
namespace Nz
|
||||
{
|
||||
NzModelParameters();
|
||||
struct NAZARA_GRAPHICS_API ModelParameters
|
||||
{
|
||||
ModelParameters();
|
||||
|
||||
bool loadMaterials = true;
|
||||
NzMaterialParams material;
|
||||
NzMeshParams mesh;
|
||||
bool loadMaterials = true;
|
||||
MaterialParams material;
|
||||
MeshParams mesh;
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
class NzModel;
|
||||
class Model;
|
||||
|
||||
using NzModelConstRef = NzObjectRef<const NzModel>;
|
||||
using NzModelLoader = NzResourceLoader<NzModel, NzModelParameters>;
|
||||
using NzModelRef = NzObjectRef<NzModel>;
|
||||
using ModelConstRef = ObjectRef<const Model>;
|
||||
using ModelLoader = ResourceLoader<Model, ModelParameters>;
|
||||
using ModelRef = ObjectRef<Model>;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzModel : public NzInstancedRenderable, public NzResource
|
||||
{
|
||||
friend NzModelLoader;
|
||||
class NAZARA_GRAPHICS_API Model : public InstancedRenderable, public Resource
|
||||
{
|
||||
friend ModelLoader;
|
||||
|
||||
public:
|
||||
NzModel();
|
||||
NzModel(const NzModel& model) = default;
|
||||
NzModel(NzModel&& model) = default;
|
||||
virtual ~NzModel();
|
||||
public:
|
||||
Model();
|
||||
Model(const Model& model) = default;
|
||||
Model(Model&& model) = default;
|
||||
virtual ~Model();
|
||||
|
||||
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
|
||||
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
|
||||
|
||||
NzMaterial* GetMaterial(const NzString& subMeshName) const;
|
||||
NzMaterial* GetMaterial(unsigned int matIndex) const;
|
||||
NzMaterial* GetMaterial(unsigned int skinIndex, const NzString& subMeshName) const;
|
||||
NzMaterial* GetMaterial(unsigned int skinIndex, unsigned int matIndex) const;
|
||||
unsigned int GetMaterialCount() const;
|
||||
unsigned int GetSkin() const;
|
||||
unsigned int GetSkinCount() const;
|
||||
NzMesh* GetMesh() const;
|
||||
Material* GetMaterial(const String& subMeshName) const;
|
||||
Material* GetMaterial(unsigned int matIndex) const;
|
||||
Material* GetMaterial(unsigned int skinIndex, const String& subMeshName) const;
|
||||
Material* GetMaterial(unsigned int skinIndex, unsigned int matIndex) const;
|
||||
unsigned int GetMaterialCount() const;
|
||||
unsigned int GetSkin() const;
|
||||
unsigned int GetSkinCount() const;
|
||||
Mesh* GetMesh() const;
|
||||
|
||||
virtual bool IsAnimated() const;
|
||||
virtual bool IsAnimated() const;
|
||||
|
||||
bool LoadFromFile(const NzString& filePath, const NzModelParameters& params = NzModelParameters());
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const NzModelParameters& params = NzModelParameters());
|
||||
bool LoadFromStream(NzInputStream& stream, const NzModelParameters& params = NzModelParameters());
|
||||
bool LoadFromFile(const String& filePath, const ModelParameters& params = ModelParameters());
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const ModelParameters& params = ModelParameters());
|
||||
bool LoadFromStream(InputStream& stream, const ModelParameters& params = ModelParameters());
|
||||
|
||||
void Reset();
|
||||
void Reset();
|
||||
|
||||
bool SetMaterial(const NzString& subMeshName, NzMaterial* material);
|
||||
void SetMaterial(unsigned int matIndex, NzMaterial* material);
|
||||
bool SetMaterial(unsigned int skinIndex, const NzString& subMeshName, NzMaterial* material);
|
||||
void SetMaterial(unsigned int skinIndex, unsigned int matIndex, NzMaterial* material);
|
||||
virtual void SetMesh(NzMesh* mesh);
|
||||
bool SetSequence(const NzString& sequenceName);
|
||||
void SetSequence(unsigned int sequenceIndex);
|
||||
void SetSkin(unsigned int skin);
|
||||
void SetSkinCount(unsigned int skinCount);
|
||||
bool SetMaterial(const String& subMeshName, Material* material);
|
||||
void SetMaterial(unsigned int matIndex, Material* material);
|
||||
bool SetMaterial(unsigned int skinIndex, const String& subMeshName, Material* material);
|
||||
void SetMaterial(unsigned int skinIndex, unsigned int matIndex, Material* material);
|
||||
virtual void SetMesh(Mesh* mesh);
|
||||
bool SetSequence(const String& sequenceName);
|
||||
void SetSequence(unsigned int sequenceIndex);
|
||||
void SetSkin(unsigned int skin);
|
||||
void SetSkinCount(unsigned int skinCount);
|
||||
|
||||
NzModel& operator=(const NzModel& node) = default;
|
||||
NzModel& operator=(NzModel&& node) = default;
|
||||
Model& operator=(const Model& node) = default;
|
||||
Model& operator=(Model&& node) = default;
|
||||
|
||||
template<typename... Args> static NzModelRef New(Args&&... args);
|
||||
template<typename... Args> static ModelRef New(Args&&... args);
|
||||
|
||||
protected:
|
||||
void MakeBoundingVolume() const override;
|
||||
protected:
|
||||
void MakeBoundingVolume() const override;
|
||||
|
||||
std::vector<NzMaterialRef> m_materials;
|
||||
NzMeshRef m_mesh;
|
||||
unsigned int m_matCount;
|
||||
unsigned int m_skin;
|
||||
unsigned int m_skinCount;
|
||||
std::vector<MaterialRef> m_materials;
|
||||
MeshRef m_mesh;
|
||||
unsigned int m_matCount;
|
||||
unsigned int m_skin;
|
||||
unsigned int m_skinCount;
|
||||
|
||||
static NzModelLoader::LoaderList s_loaders;
|
||||
};
|
||||
static ModelLoader::LoaderList s_loaders;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/Model.inl>
|
||||
|
||||
|
||||
@@ -5,13 +5,16 @@
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
template<typename... Args>
|
||||
NzModelRef NzModel::New(Args&&... args)
|
||||
namespace Nz
|
||||
{
|
||||
std::unique_ptr<NzModel> object(new NzModel(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
template<typename... Args>
|
||||
ModelRef Model::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<Model> object(new Model(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
||||
@@ -14,34 +14,37 @@
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
|
||||
class NzParticleController;
|
||||
class NzParticleMapper;
|
||||
class NzParticleSystem;
|
||||
|
||||
using NzParticleControllerConstRef = NzObjectRef<const NzParticleController>;
|
||||
using NzParticleControllerLibrary = NzObjectLibrary<NzParticleController>;
|
||||
using NzParticleControllerRef = NzObjectRef<NzParticleController>;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzParticleController : public NzRefCounted
|
||||
namespace Nz
|
||||
{
|
||||
friend NzParticleControllerLibrary;
|
||||
friend class NzGraphics;
|
||||
class ParticleController;
|
||||
class ParticleMapper;
|
||||
class ParticleSystem;
|
||||
|
||||
public:
|
||||
NzParticleController() = default;
|
||||
NzParticleController(const NzParticleController& controller);
|
||||
virtual ~NzParticleController();
|
||||
using ParticleControllerConstRef = ObjectRef<const ParticleController>;
|
||||
using ParticleControllerLibrary = ObjectLibrary<ParticleController>;
|
||||
using ParticleControllerRef = ObjectRef<ParticleController>;
|
||||
|
||||
virtual void Apply(NzParticleSystem& system, NzParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime) = 0;
|
||||
class NAZARA_GRAPHICS_API ParticleController : public RefCounted
|
||||
{
|
||||
friend ParticleControllerLibrary;
|
||||
friend class Graphics;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnParticleControllerRelease, const NzParticleController* /*particleController*/);
|
||||
public:
|
||||
ParticleController() = default;
|
||||
ParticleController(const ParticleController& controller);
|
||||
virtual ~ParticleController();
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
virtual void Apply(ParticleSystem& system, ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime) = 0;
|
||||
|
||||
static NzParticleControllerLibrary::LibraryMap s_library;
|
||||
};
|
||||
// Signals:
|
||||
NazaraSignal(OnParticleControllerRelease, const ParticleController* /*particleController*/);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
static ParticleControllerLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PARTICLECONTROLLER_HPP
|
||||
|
||||
@@ -16,61 +16,64 @@
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
|
||||
class NzParticleDeclaration;
|
||||
|
||||
using NzParticleDeclarationConstRef = NzObjectRef<const NzParticleDeclaration>;
|
||||
using NzParticleDeclarationLibrary = NzObjectLibrary<NzParticleDeclaration>;
|
||||
using NzParticleDeclarationRef = NzObjectRef<NzParticleDeclaration>;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzParticleDeclaration : public NzRefCounted
|
||||
namespace Nz
|
||||
{
|
||||
friend NzParticleDeclarationLibrary;
|
||||
friend class NzGraphics;
|
||||
class ParticleDeclaration;
|
||||
|
||||
public:
|
||||
NzParticleDeclaration();
|
||||
NzParticleDeclaration(const NzParticleDeclaration& declaration);
|
||||
~NzParticleDeclaration();
|
||||
using ParticleDeclarationConstRef = ObjectRef<const ParticleDeclaration>;
|
||||
using ParticleDeclarationLibrary = ObjectLibrary<ParticleDeclaration>;
|
||||
using ParticleDeclarationRef = ObjectRef<ParticleDeclaration>;
|
||||
|
||||
void DisableComponent(nzParticleComponent component);
|
||||
void EnableComponent(nzParticleComponent component, nzComponentType type, unsigned int offset);
|
||||
class NAZARA_GRAPHICS_API ParticleDeclaration : public RefCounted
|
||||
{
|
||||
friend ParticleDeclarationLibrary;
|
||||
friend class Graphics;
|
||||
|
||||
void GetComponent(nzParticleComponent component, bool* enabled, nzComponentType* type, unsigned int* offset) const;
|
||||
unsigned int GetStride() const;
|
||||
public:
|
||||
ParticleDeclaration();
|
||||
ParticleDeclaration(const ParticleDeclaration& declaration);
|
||||
~ParticleDeclaration();
|
||||
|
||||
void SetStride(unsigned int stride);
|
||||
void DisableComponent(ParticleComponent component);
|
||||
void EnableComponent(ParticleComponent component, ComponentType type, unsigned int offset);
|
||||
|
||||
NzParticleDeclaration& operator=(const NzParticleDeclaration& declaration);
|
||||
void GetComponent(ParticleComponent component, bool* enabled, ComponentType* type, unsigned int* offset) const;
|
||||
unsigned int GetStride() const;
|
||||
|
||||
static NzParticleDeclaration* Get(nzParticleLayout layout);
|
||||
static bool IsTypeSupported(nzComponentType type);
|
||||
void SetStride(unsigned int stride);
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnParticleDeclarationRelease, const NzParticleDeclaration* /*particleDeclaration*/);
|
||||
ParticleDeclaration& operator=(const ParticleDeclaration& declaration);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
static ParticleDeclaration* Get(ParticleLayout layout);
|
||||
static bool IsTypeSupported(ComponentType type);
|
||||
|
||||
struct Component
|
||||
{
|
||||
nzComponentType type;
|
||||
bool enabled = false;
|
||||
unsigned int offset;
|
||||
// Signals:
|
||||
NazaraSignal(OnParticleDeclarationRelease, const ParticleDeclaration* /*particleDeclaration*/);
|
||||
|
||||
/*
|
||||
** -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 !
|
||||
*/
|
||||
};
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
Component m_components[nzParticleComponent_Max+1];
|
||||
unsigned int m_stride;
|
||||
struct Component
|
||||
{
|
||||
ComponentType type;
|
||||
bool enabled = false;
|
||||
unsigned int offset;
|
||||
|
||||
static NzParticleDeclaration s_declarations[nzParticleLayout_Max+1];
|
||||
static NzParticleDeclarationLibrary::LibraryMap s_library;
|
||||
};
|
||||
/*
|
||||
** -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[ParticleComponent_Max+1];
|
||||
unsigned int m_stride;
|
||||
|
||||
static ParticleDeclaration s_declarations[ParticleLayout_Max+1];
|
||||
static ParticleDeclarationLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PARTICLEDECLARATION_HPP
|
||||
|
||||
@@ -11,39 +11,42 @@
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
|
||||
class NzParticleMapper;
|
||||
class NzParticleSystem;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzParticleEmitter : public NzNode
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzParticleEmitter();
|
||||
NzParticleEmitter(const NzParticleEmitter& emitter) = default;
|
||||
NzParticleEmitter(NzParticleEmitter&& emitter) = default;
|
||||
virtual ~NzParticleEmitter();
|
||||
class ParticleMapper;
|
||||
class ParticleSystem;
|
||||
|
||||
virtual void Emit(NzParticleSystem& system, float elapsedTime) const;
|
||||
class NAZARA_GRAPHICS_API ParticleEmitter : public Node
|
||||
{
|
||||
public:
|
||||
ParticleEmitter();
|
||||
ParticleEmitter(const ParticleEmitter& emitter) = default;
|
||||
ParticleEmitter(ParticleEmitter&& emitter) = default;
|
||||
virtual ~ParticleEmitter();
|
||||
|
||||
void EnableLagCompensation(bool enable);
|
||||
virtual void Emit(ParticleSystem& system, float elapsedTime) const;
|
||||
|
||||
unsigned int GetEmissionCount() const;
|
||||
float GetEmissionRate() const;
|
||||
void EnableLagCompensation(bool enable);
|
||||
|
||||
bool IsLagCompensationEnabled() const;
|
||||
unsigned int GetEmissionCount() const;
|
||||
float GetEmissionRate() const;
|
||||
|
||||
void SetEmissionCount(unsigned int count);
|
||||
void SetEmissionRate(float rate);
|
||||
bool IsLagCompensationEnabled() const;
|
||||
|
||||
NzParticleEmitter& operator=(const NzParticleEmitter& emitter) = default;
|
||||
NzParticleEmitter& operator=(NzParticleEmitter&& emitter) = default;
|
||||
void SetEmissionCount(unsigned int count);
|
||||
void SetEmissionRate(float rate);
|
||||
|
||||
private:
|
||||
virtual void SetupParticles(NzParticleMapper& mapper, unsigned int count) const = 0;
|
||||
ParticleEmitter& operator=(const ParticleEmitter& emitter) = default;
|
||||
ParticleEmitter& operator=(ParticleEmitter&& emitter) = default;
|
||||
|
||||
bool m_lagCompensationEnabled;
|
||||
mutable float m_emissionAccumulator;
|
||||
float m_emissionRate;
|
||||
unsigned int m_emissionCount;
|
||||
};
|
||||
private:
|
||||
virtual void SetupParticles(ParticleMapper& mapper, unsigned int count) const = 0;
|
||||
|
||||
bool m_lagCompensationEnabled;
|
||||
mutable float m_emissionAccumulator;
|
||||
float m_emissionRate;
|
||||
unsigned int m_emissionCount;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PARTICLEEMITTER_HPP
|
||||
|
||||
@@ -14,34 +14,37 @@
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
|
||||
class NzParticleGenerator;
|
||||
class NzParticleMapper;
|
||||
class NzParticleSystem;
|
||||
|
||||
using NzParticleGeneratorConstRef = NzObjectRef<const NzParticleGenerator>;
|
||||
using NzParticleGeneratorLibrary = NzObjectLibrary<NzParticleGenerator>;
|
||||
using NzParticleGeneratorRef = NzObjectRef<NzParticleGenerator>;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzParticleGenerator : public NzRefCounted
|
||||
namespace Nz
|
||||
{
|
||||
friend NzParticleGeneratorLibrary;
|
||||
friend class NzGraphics;
|
||||
class ParticleGenerator;
|
||||
class ParticleMapper;
|
||||
class ParticleSystem;
|
||||
|
||||
public:
|
||||
NzParticleGenerator() = default;
|
||||
NzParticleGenerator(const NzParticleGenerator& generator);
|
||||
virtual ~NzParticleGenerator();
|
||||
using ParticleGeneratorConstRef = ObjectRef<const ParticleGenerator>;
|
||||
using ParticleGeneratorLibrary = ObjectLibrary<ParticleGenerator>;
|
||||
using ParticleGeneratorRef = ObjectRef<ParticleGenerator>;
|
||||
|
||||
virtual void Generate(NzParticleSystem& system, NzParticleMapper& mapper, unsigned int startId, unsigned int endId) = 0;
|
||||
class NAZARA_GRAPHICS_API ParticleGenerator : public RefCounted
|
||||
{
|
||||
friend ParticleGeneratorLibrary;
|
||||
friend class Graphics;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnParticleGeneratorRelease, const NzParticleGenerator* /*particleGenerator*/);
|
||||
public:
|
||||
ParticleGenerator() = default;
|
||||
ParticleGenerator(const ParticleGenerator& generator);
|
||||
virtual ~ParticleGenerator();
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
virtual void Generate(ParticleSystem& system, ParticleMapper& mapper, unsigned int startId, unsigned int endId) = 0;
|
||||
|
||||
static NzParticleGeneratorLibrary::LibraryMap s_library;
|
||||
};
|
||||
// Signals:
|
||||
NazaraSignal(OnParticleGeneratorRelease, const ParticleGenerator* /*particleGenerator*/);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
static ParticleGeneratorLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PARTICLEGENERATOR_HPP
|
||||
|
||||
@@ -12,19 +12,22 @@
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
#include <Nazara/Graphics/ParticleDeclaration.hpp>
|
||||
|
||||
class NAZARA_GRAPHICS_API NzParticleMapper
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzParticleMapper(void* buffer, const NzParticleDeclaration* declaration);
|
||||
~NzParticleMapper();
|
||||
class NAZARA_GRAPHICS_API ParticleMapper
|
||||
{
|
||||
public:
|
||||
ParticleMapper(void* buffer, const ParticleDeclaration* declaration);
|
||||
~ParticleMapper();
|
||||
|
||||
template<typename T> NzSparsePtr<T> GetComponentPtr(nzParticleComponent component);
|
||||
template<typename T> NzSparsePtr<const T> GetComponentPtr(nzParticleComponent component) const;
|
||||
template<typename T> SparsePtr<T> GetComponentPtr(ParticleComponent component);
|
||||
template<typename T> SparsePtr<const T> GetComponentPtr(ParticleComponent component) const;
|
||||
|
||||
private:
|
||||
const NzParticleDeclaration* m_declaration;
|
||||
nzUInt8* m_ptr;
|
||||
};
|
||||
private:
|
||||
const ParticleDeclaration* m_declaration;
|
||||
UInt8* m_ptr;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/ParticleMapper.inl>
|
||||
|
||||
|
||||
@@ -5,45 +5,48 @@
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
template <typename T>
|
||||
NzSparsePtr<T> NzParticleMapper::GetComponentPtr(nzParticleComponent component)
|
||||
namespace Nz
|
||||
{
|
||||
// Ensuite le composant qui nous intéresse
|
||||
bool enabled;
|
||||
nzComponentType type;
|
||||
unsigned int offset;
|
||||
m_declaration->GetComponent(component, &enabled, &type, &offset);
|
||||
template <typename T>
|
||||
SparsePtr<T> ParticleMapper::GetComponentPtr(ParticleComponent component)
|
||||
{
|
||||
// Ensuite le composant qui nous intéresse
|
||||
bool enabled;
|
||||
ComponentType 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());
|
||||
if (enabled)
|
||||
{
|
||||
///TODO: Vérifier le rapport entre le type de l'attribut et le type template ?
|
||||
return SparsePtr<T>(m_ptr + offset, m_declaration->GetStride());
|
||||
}
|
||||
else
|
||||
{
|
||||
NazaraError("Attribute 0x" + String::Number(component, 16) + " is not enabled");
|
||||
return SparsePtr<T>();
|
||||
}
|
||||
}
|
||||
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);
|
||||
template <typename T>
|
||||
SparsePtr<const T> ParticleMapper::GetComponentPtr(ParticleComponent component) const
|
||||
{
|
||||
// Ensuite le composant qui nous intéresse
|
||||
bool enabled;
|
||||
ComponentType 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>();
|
||||
if (enabled)
|
||||
{
|
||||
///TODO: Vérifier le rapport entre le type de l'attribut et le type template ?
|
||||
return SparsePtr<const T>(m_ptr + offset, m_declaration->GetStride());
|
||||
}
|
||||
else
|
||||
{
|
||||
NazaraError("Attribute 0x" + String::Number(component, 16) + " is not enabled");
|
||||
return SparsePtr<const T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,35 +14,38 @@
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
|
||||
class NzAbstractRenderQueue;
|
||||
class NzParticleMapper;
|
||||
class NzParticleRenderer;
|
||||
class NzParticleSystem;
|
||||
|
||||
using NzParticleRendererConstRef = NzObjectRef<const NzParticleRenderer>;
|
||||
using NzParticleRendererLibrary = NzObjectLibrary<NzParticleRenderer>;
|
||||
using NzParticleRendererRef = NzObjectRef<NzParticleRenderer>;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzParticleRenderer : public NzRefCounted
|
||||
namespace Nz
|
||||
{
|
||||
friend NzParticleRendererLibrary;
|
||||
friend class NzGraphics;
|
||||
class AbstractRenderQueue;
|
||||
class ParticleMapper;
|
||||
class ParticleRenderer;
|
||||
class ParticleSystem;
|
||||
|
||||
public:
|
||||
NzParticleRenderer() = default;
|
||||
NzParticleRenderer(const NzParticleRenderer& renderer);
|
||||
virtual ~NzParticleRenderer();
|
||||
using ParticleRendererConstRef = ObjectRef<const ParticleRenderer>;
|
||||
using ParticleRendererLibrary = ObjectLibrary<ParticleRenderer>;
|
||||
using ParticleRendererRef = ObjectRef<ParticleRenderer>;
|
||||
|
||||
virtual void Render(const NzParticleSystem& system, const NzParticleMapper& mapper, unsigned int startId, unsigned int endId, NzAbstractRenderQueue* renderQueue) = 0;
|
||||
class NAZARA_GRAPHICS_API ParticleRenderer : public RefCounted
|
||||
{
|
||||
friend ParticleRendererLibrary;
|
||||
friend class Graphics;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnParticleRendererRelease, const NzParticleRenderer* /*particleRenderer*/);
|
||||
public:
|
||||
ParticleRenderer() = default;
|
||||
ParticleRenderer(const ParticleRenderer& renderer);
|
||||
virtual ~ParticleRenderer();
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
virtual void Render(const ParticleSystem& system, const ParticleMapper& mapper, unsigned int startId, unsigned int endId, AbstractRenderQueue* renderQueue) = 0;
|
||||
|
||||
static NzParticleRendererLibrary::LibraryMap s_library;
|
||||
};
|
||||
// Signals:
|
||||
NazaraSignal(OnParticleRendererRelease, const ParticleRenderer* /*particleRenderer*/);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
static ParticleRendererLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PARTICLERENDERER_HPP
|
||||
|
||||
@@ -12,31 +12,34 @@
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
struct NzParticleStruct_Billboard
|
||||
namespace Nz
|
||||
{
|
||||
NzColor color;
|
||||
NzVector3f normal;
|
||||
NzVector3f position;
|
||||
NzVector3f velocity;
|
||||
nzUInt32 life;
|
||||
float rotation;
|
||||
};
|
||||
struct ParticleStruct_Billboard
|
||||
{
|
||||
Color color;
|
||||
Vector3f normal;
|
||||
Vector3f position;
|
||||
Vector3f velocity;
|
||||
UInt32 life;
|
||||
float rotation;
|
||||
};
|
||||
|
||||
struct NzParticleStruct_Model
|
||||
{
|
||||
NzVector3f position;
|
||||
NzVector3f velocity;
|
||||
nzUInt32 life;
|
||||
NzQuaternionf rotation;
|
||||
};
|
||||
struct ParticleStruct_Model
|
||||
{
|
||||
Vector3f position;
|
||||
Vector3f velocity;
|
||||
UInt32 life;
|
||||
Quaternionf rotation;
|
||||
};
|
||||
|
||||
struct NzParticleStruct_Sprite
|
||||
{
|
||||
NzColor color;
|
||||
NzVector2f position;
|
||||
NzVector2f velocity;
|
||||
nzUInt32 life;
|
||||
float rotation;
|
||||
};
|
||||
struct ParticleStruct_Sprite
|
||||
{
|
||||
Color color;
|
||||
Vector2f position;
|
||||
Vector2f velocity;
|
||||
UInt32 life;
|
||||
float rotation;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PARTICLESTRUCT_HPP
|
||||
|
||||
@@ -20,70 +20,73 @@
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
class NAZARA_GRAPHICS_API NzParticleSystem : public NzRenderable
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzParticleSystem(unsigned int maxParticleCount, nzParticleLayout layout);
|
||||
NzParticleSystem(unsigned int maxParticleCount, NzParticleDeclarationConstRef declaration);
|
||||
NzParticleSystem(const NzParticleSystem& emitter);
|
||||
~NzParticleSystem();
|
||||
class NAZARA_GRAPHICS_API ParticleSystem : public Renderable
|
||||
{
|
||||
public:
|
||||
ParticleSystem(unsigned int maxParticleCount, ParticleLayout layout);
|
||||
ParticleSystem(unsigned int maxParticleCount, ParticleDeclarationConstRef declaration);
|
||||
ParticleSystem(const ParticleSystem& emitter);
|
||||
~ParticleSystem();
|
||||
|
||||
void AddController(NzParticleControllerRef controller);
|
||||
void AddEmitter(NzParticleEmitter* emitter);
|
||||
void AddGenerator(NzParticleGeneratorRef generator);
|
||||
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const NzMatrix4f& transformMatrix) const;
|
||||
void AddController(ParticleControllerRef controller);
|
||||
void AddEmitter(ParticleEmitter* emitter);
|
||||
void AddGenerator(ParticleGeneratorRef generator);
|
||||
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix) const;
|
||||
|
||||
void ApplyControllers(NzParticleMapper& mapper, unsigned int particleCount, float elapsedTime);
|
||||
void ApplyControllers(ParticleMapper& mapper, unsigned int particleCount, float elapsedTime);
|
||||
|
||||
void* CreateParticle();
|
||||
void* CreateParticles(unsigned int count);
|
||||
void* CreateParticle();
|
||||
void* CreateParticles(unsigned int count);
|
||||
|
||||
void EnableFixedStep(bool fixedStep);
|
||||
void EnableFixedStep(bool fixedStep);
|
||||
|
||||
void* GenerateParticle();
|
||||
void* GenerateParticles(unsigned int count);
|
||||
void* GenerateParticle();
|
||||
void* GenerateParticles(unsigned int count);
|
||||
|
||||
const NzParticleDeclarationConstRef& GetDeclaration() const;
|
||||
float GetFixedStepSize() const;
|
||||
unsigned int GetMaxParticleCount() const;
|
||||
unsigned int GetParticleCount() const;
|
||||
unsigned int GetParticleSize() const;
|
||||
const ParticleDeclarationConstRef& GetDeclaration() const;
|
||||
float GetFixedStepSize() const;
|
||||
unsigned int GetMaxParticleCount() const;
|
||||
unsigned int GetParticleCount() const;
|
||||
unsigned int GetParticleSize() const;
|
||||
|
||||
bool IsFixedStepEnabled() const;
|
||||
bool IsFixedStepEnabled() const;
|
||||
|
||||
void KillParticle(unsigned int index);
|
||||
void KillParticles();
|
||||
void KillParticle(unsigned int index);
|
||||
void KillParticles();
|
||||
|
||||
void RemoveController(NzParticleController* controller);
|
||||
void RemoveEmitter(NzParticleEmitter* emitter);
|
||||
void RemoveGenerator(NzParticleGenerator* generator);
|
||||
void RemoveController(ParticleController* controller);
|
||||
void RemoveEmitter(ParticleEmitter* emitter);
|
||||
void RemoveGenerator(ParticleGenerator* generator);
|
||||
|
||||
void SetFixedStepSize(float stepSize);
|
||||
void SetRenderer(NzParticleRenderer* renderer);
|
||||
void SetFixedStepSize(float stepSize);
|
||||
void SetRenderer(ParticleRenderer* renderer);
|
||||
|
||||
void Update(float elapsedTime);
|
||||
void UpdateBoundingVolume(const NzMatrix4f& transformMatrix) override;
|
||||
void Update(float elapsedTime);
|
||||
void UpdateBoundingVolume(const Matrix4f& transformMatrix) override;
|
||||
|
||||
NzParticleSystem& operator=(const NzParticleSystem& emitter);
|
||||
ParticleSystem& operator=(const ParticleSystem& emitter);
|
||||
|
||||
private:
|
||||
void MakeBoundingVolume() const override;
|
||||
void ResizeBuffer();
|
||||
private:
|
||||
void MakeBoundingVolume() const override;
|
||||
void ResizeBuffer();
|
||||
|
||||
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;
|
||||
};
|
||||
std::set<unsigned int, std::greater<unsigned int>> m_dyingParticles;
|
||||
mutable std::vector<UInt8> m_buffer;
|
||||
std::vector<ParticleControllerRef> m_controllers;
|
||||
std::vector<ParticleEmitter*> m_emitters;
|
||||
std::vector<ParticleGeneratorRef> m_generators;
|
||||
ParticleDeclarationConstRef m_declaration;
|
||||
ParticleRendererRef 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
|
||||
|
||||
@@ -12,28 +12,31 @@
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
|
||||
class NzAbstractRenderTechnique;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzRenderTechniques
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
using RenderTechniqueFactory = NzAbstractRenderTechnique* (*)();
|
||||
class AbstractRenderTechnique;
|
||||
|
||||
NzRenderTechniques() = delete;
|
||||
~NzRenderTechniques() = delete;
|
||||
class NAZARA_GRAPHICS_API RenderTechniques
|
||||
{
|
||||
public:
|
||||
using RenderTechniqueFactory = AbstractRenderTechnique* (*)();
|
||||
|
||||
static NzAbstractRenderTechnique* GetByEnum(nzRenderTechniqueType renderTechnique, int* techniqueRanking = nullptr);
|
||||
static NzAbstractRenderTechnique* GetByIndex(unsigned int index, int* techniqueRanking = nullptr);
|
||||
static NzAbstractRenderTechnique* GetByName(const NzString& name, int* techniqueRanking = nullptr);
|
||||
static NzAbstractRenderTechnique* GetByRanking(int maxRanking, int* techniqueRanking = nullptr);
|
||||
RenderTechniques() = delete;
|
||||
~RenderTechniques() = delete;
|
||||
|
||||
static unsigned int GetCount();
|
||||
static AbstractRenderTechnique* GetByEnum(RenderTechniqueType renderTechnique, int* techniqueRanking = nullptr);
|
||||
static AbstractRenderTechnique* GetByIndex(unsigned int index, int* techniqueRanking = nullptr);
|
||||
static AbstractRenderTechnique* GetByName(const String& name, int* techniqueRanking = nullptr);
|
||||
static AbstractRenderTechnique* GetByRanking(int maxRanking, int* techniqueRanking = nullptr);
|
||||
|
||||
static void Register(const NzString& name, int ranking, RenderTechniqueFactory factory);
|
||||
static unsigned int GetCount();
|
||||
|
||||
static NzString ToString(nzRenderTechniqueType renderTechnique);
|
||||
static void Register(const String& name, int ranking, RenderTechniqueFactory factory);
|
||||
|
||||
static void Unregister(const NzString& name);
|
||||
};
|
||||
static String ToString(RenderTechniqueType renderTechnique);
|
||||
|
||||
static void Unregister(const String& name);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_RENDERTECHNIQUES_HPP
|
||||
|
||||
@@ -7,42 +7,43 @@
|
||||
#ifndef NAZARA_RENDERABLE_HPP
|
||||
#define NAZARA_RENDERABLE_HPP
|
||||
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Core/PrimitiveList.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Math/BoundingVolume.hpp>
|
||||
#include <Nazara/Math/Frustum.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
|
||||
class NzAbstractRenderQueue;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzRenderable
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzRenderable() = default;
|
||||
NzRenderable(const NzRenderable& renderable) = default;
|
||||
virtual ~NzRenderable();
|
||||
class AbstractRenderQueue;
|
||||
|
||||
inline void EnsureBoundingVolumeUpdated() const;
|
||||
class NAZARA_GRAPHICS_API Renderable
|
||||
{
|
||||
public:
|
||||
Renderable() = default;
|
||||
Renderable(const Renderable& renderable) = default;
|
||||
Renderable(Renderable&&) = default;
|
||||
virtual ~Renderable();
|
||||
|
||||
virtual void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const NzMatrix4f& transformMatrix) const = 0;
|
||||
virtual bool Cull(const NzFrustumf& frustum, const NzMatrix4f& transformMatrix) const;
|
||||
virtual const NzBoundingVolumef& GetBoundingVolume() const;
|
||||
virtual void UpdateBoundingVolume(const NzMatrix4f& transformMatrix);
|
||||
virtual void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix) const = 0;
|
||||
virtual bool Cull(const Frustumf& frustum, const Matrix4f& transformMatrix) const;
|
||||
inline void EnsureBoundingVolumeUpdated() const;
|
||||
virtual const BoundingVolumef& GetBoundingVolume() const;
|
||||
virtual void UpdateBoundingVolume(const Matrix4f& transformMatrix);
|
||||
|
||||
NzRenderable& operator=(const NzRenderable& renderable) = default;
|
||||
Renderable& operator=(const Renderable& renderable) = default;
|
||||
Renderable& operator=(Renderable&& renderable) = default;
|
||||
|
||||
protected:
|
||||
virtual void MakeBoundingVolume() const = 0;
|
||||
inline void InvalidateBoundingVolume();
|
||||
inline void UpdateBoundingVolume() const;
|
||||
protected:
|
||||
virtual void MakeBoundingVolume() const = 0;
|
||||
inline void InvalidateBoundingVolume();
|
||||
inline void UpdateBoundingVolume() const;
|
||||
|
||||
mutable NzBoundingVolumef m_boundingVolume;
|
||||
mutable BoundingVolumef m_boundingVolume;
|
||||
|
||||
private:
|
||||
mutable bool m_boundingVolumeUpdated;
|
||||
};
|
||||
private:
|
||||
mutable bool m_boundingVolumeUpdated;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/Renderable.inl>
|
||||
|
||||
|
||||
@@ -2,19 +2,22 @@
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
inline void NzRenderable::EnsureBoundingVolumeUpdated() const
|
||||
namespace Nz
|
||||
{
|
||||
if (!m_boundingVolumeUpdated)
|
||||
UpdateBoundingVolume();
|
||||
}
|
||||
inline void Renderable::EnsureBoundingVolumeUpdated() const
|
||||
{
|
||||
if (!m_boundingVolumeUpdated)
|
||||
UpdateBoundingVolume();
|
||||
}
|
||||
|
||||
inline void NzRenderable::InvalidateBoundingVolume()
|
||||
{
|
||||
m_boundingVolumeUpdated = false;
|
||||
}
|
||||
inline void Renderable::InvalidateBoundingVolume()
|
||||
{
|
||||
m_boundingVolumeUpdated = false;
|
||||
}
|
||||
|
||||
inline void NzRenderable::UpdateBoundingVolume() const
|
||||
{
|
||||
MakeBoundingVolume();
|
||||
m_boundingVolumeUpdated = true;
|
||||
inline void Renderable::UpdateBoundingVolume() const
|
||||
{
|
||||
MakeBoundingVolume();
|
||||
m_boundingVolumeUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,14 +9,17 @@
|
||||
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
|
||||
class NzAbstractBackground;
|
||||
class NzAbstractViewer;
|
||||
|
||||
struct NzSceneData
|
||||
namespace Nz
|
||||
{
|
||||
NzColor ambientColor;
|
||||
const NzAbstractBackground* background;
|
||||
const NzAbstractViewer* viewer;
|
||||
};
|
||||
class AbstractBackground;
|
||||
class AbstractViewer;
|
||||
|
||||
struct SceneData
|
||||
{
|
||||
Color ambientColor;
|
||||
const AbstractBackground* background;
|
||||
const AbstractViewer* viewer;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_SCENEDATA_HPP
|
||||
|
||||
@@ -16,74 +16,77 @@
|
||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||
#include <vector>
|
||||
|
||||
struct NAZARA_GRAPHICS_API NzSkeletalModelParameters : public NzModelParameters
|
||||
namespace Nz
|
||||
{
|
||||
bool loadAnimation = true;
|
||||
NzAnimationParams animation;
|
||||
struct NAZARA_GRAPHICS_API SkeletalModelParameters : public ModelParameters
|
||||
{
|
||||
bool loadAnimation = true;
|
||||
AnimationParams animation;
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
class NzSkeletalModel;
|
||||
class SkeletalModel;
|
||||
|
||||
using NzSkeletalModelLoader = NzResourceLoader<NzSkeletalModel, NzSkeletalModelParameters>;
|
||||
using SkeletalModelLoader = ResourceLoader<SkeletalModel, SkeletalModelParameters>;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzSkeletalModel : public NzModel, NzUpdatable
|
||||
{
|
||||
friend NzSkeletalModelLoader;
|
||||
class NAZARA_GRAPHICS_API SkeletalModel : public Model, Updatable
|
||||
{
|
||||
friend SkeletalModelLoader;
|
||||
|
||||
public:
|
||||
NzSkeletalModel();
|
||||
NzSkeletalModel(const NzSkeletalModel& model) = default;
|
||||
NzSkeletalModel(NzSkeletalModel&& model) = default;
|
||||
~NzSkeletalModel() = default;
|
||||
public:
|
||||
SkeletalModel();
|
||||
SkeletalModel(const SkeletalModel& model) = default;
|
||||
SkeletalModel(SkeletalModel&& model) = default;
|
||||
~SkeletalModel() = default;
|
||||
|
||||
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
|
||||
void AdvanceAnimation(float elapsedTime);
|
||||
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
|
||||
void AdvanceAnimation(float elapsedTime);
|
||||
|
||||
NzSkeletalModel* Clone() const;
|
||||
NzSkeletalModel* Create() const;
|
||||
SkeletalModel* Clone() const;
|
||||
SkeletalModel* Create() const;
|
||||
|
||||
void EnableAnimation(bool animation);
|
||||
void EnableAnimation(bool animation);
|
||||
|
||||
NzAnimation* GetAnimation() const;
|
||||
NzSkeleton* GetSkeleton();
|
||||
const NzSkeleton* GetSkeleton() const;
|
||||
Animation* GetAnimation() const;
|
||||
Skeleton* GetSkeleton();
|
||||
const Skeleton* GetSkeleton() const;
|
||||
|
||||
bool HasAnimation() const;
|
||||
bool HasAnimation() const;
|
||||
|
||||
bool IsAnimated() const;
|
||||
bool IsAnimationEnabled() const;
|
||||
bool IsAnimated() const;
|
||||
bool IsAnimationEnabled() 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());
|
||||
bool LoadFromFile(const String& filePath, const SkeletalModelParameters& params = SkeletalModelParameters());
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const SkeletalModelParameters& params = SkeletalModelParameters());
|
||||
bool LoadFromStream(InputStream& stream, const SkeletalModelParameters& params = SkeletalModelParameters());
|
||||
|
||||
void Reset();
|
||||
void Reset();
|
||||
|
||||
bool SetAnimation(NzAnimation* animation);
|
||||
void SetMesh(NzMesh* mesh) override;
|
||||
bool SetSequence(const NzString& sequenceName);
|
||||
void SetSequence(unsigned int sequenceIndex);
|
||||
bool SetAnimation(Animation* animation);
|
||||
void SetMesh(Mesh* mesh) override;
|
||||
bool SetSequence(const String& sequenceName);
|
||||
void SetSequence(unsigned int sequenceIndex);
|
||||
|
||||
NzSkeletalModel& operator=(const NzSkeletalModel& node) = default;
|
||||
NzSkeletalModel& operator=(NzSkeletalModel&& node) = default;
|
||||
SkeletalModel& operator=(const SkeletalModel& node) = default;
|
||||
SkeletalModel& operator=(SkeletalModel&& node) = default;
|
||||
|
||||
private:
|
||||
void MakeBoundingVolume() const override;
|
||||
/*void Register() override;
|
||||
void Unregister() override;*/
|
||||
void Update() override;
|
||||
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;
|
||||
AnimationRef m_animation;
|
||||
Skeleton m_skeleton;
|
||||
const Sequence* m_currentSequence;
|
||||
bool m_animationEnabled;
|
||||
float m_interpolation;
|
||||
unsigned int m_currentFrame;
|
||||
unsigned int m_nextFrame;
|
||||
|
||||
static NzSkeletalModelLoader::LoaderList s_loaders;
|
||||
};
|
||||
static SkeletalModelLoader::LoaderList s_loaders;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_SKELETALMODEL_HPP
|
||||
|
||||
@@ -10,31 +10,34 @@
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
|
||||
class NzSkeleton;
|
||||
class NzSkeletalMesh;
|
||||
class NzVertexBuffer;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzSkinningManager
|
||||
namespace Nz
|
||||
{
|
||||
friend class NzGraphics;
|
||||
class Skeleton;
|
||||
class SkeletalMesh;
|
||||
class VertexBuffer;
|
||||
|
||||
public:
|
||||
using SkinFunction = void (*)(const NzSkeletalMesh* mesh, const NzSkeleton* skeleton, NzVertexBuffer* buffer);
|
||||
class NAZARA_GRAPHICS_API SkinningManager
|
||||
{
|
||||
friend class Graphics;
|
||||
|
||||
NzSkinningManager() = delete;
|
||||
~NzSkinningManager() = delete;
|
||||
public:
|
||||
using SkinFunction = void (*)(const SkeletalMesh* mesh, const Skeleton* skeleton, VertexBuffer* buffer);
|
||||
|
||||
static NzVertexBuffer* GetBuffer(const NzSkeletalMesh* mesh, const NzSkeleton* skeleton);
|
||||
static void Skin();
|
||||
SkinningManager() = delete;
|
||||
~SkinningManager() = delete;
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void OnSkeletalMeshDestroy(const NzSkeletalMesh* mesh);
|
||||
static void OnSkeletonInvalidated(const NzSkeleton* skeleton);
|
||||
static void OnSkeletonRelease(const NzSkeleton* skeleton);
|
||||
static void Uninitialize();
|
||||
static VertexBuffer* GetBuffer(const SkeletalMesh* mesh, const Skeleton* skeleton);
|
||||
static void Skin();
|
||||
|
||||
static SkinFunction s_skinFunc;
|
||||
};
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void OnSkeletalMeshDestroy(const SkeletalMesh* mesh);
|
||||
static void OnSkeletonInvalidated(const Skeleton* skeleton);
|
||||
static void OnSkeletonRelease(const Skeleton* skeleton);
|
||||
static void Uninitialize();
|
||||
|
||||
static SkinFunction s_skinFunc;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_SKINNINGMANAGER_HPP
|
||||
|
||||
@@ -15,38 +15,41 @@
|
||||
#include <Nazara/Utility/IndexBuffer.hpp>
|
||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||
|
||||
class NzSkyboxBackground;
|
||||
|
||||
using NzSkyboxBackgroundConstRef = NzObjectRef<const NzSkyboxBackground>;
|
||||
using NzSkyboxBackgroundRef = NzObjectRef<NzSkyboxBackground>;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzSkyboxBackground : public NzAbstractBackground
|
||||
namespace Nz
|
||||
{
|
||||
friend class NzGraphics;
|
||||
class SkyboxBackground;
|
||||
|
||||
public:
|
||||
NzSkyboxBackground(NzTextureRef cubemapTexture = NzTextureRef());
|
||||
~NzSkyboxBackground() = default;
|
||||
using SkyboxBackgroundConstRef = ObjectRef<const SkyboxBackground>;
|
||||
using SkyboxBackgroundRef = ObjectRef<SkyboxBackground>;
|
||||
|
||||
void Draw(const NzAbstractViewer* viewer) const;
|
||||
class NAZARA_GRAPHICS_API SkyboxBackground : public AbstractBackground
|
||||
{
|
||||
friend class Graphics;
|
||||
|
||||
nzBackgroundType GetBackgroundType() const;
|
||||
inline const NzTextureRef& GetTexture() const;
|
||||
inline NzTextureSampler& GetTextureSampler();
|
||||
inline const NzTextureSampler& GetTextureSampler() const;
|
||||
public:
|
||||
SkyboxBackground(TextureRef cubemapTexture = TextureRef());
|
||||
~SkyboxBackground() = default;
|
||||
|
||||
inline void SetTexture(NzTextureRef cubemapTexture);
|
||||
inline void SetTextureSampler(const NzTextureSampler& sampler);
|
||||
void Draw(const AbstractViewer* viewer) const;
|
||||
|
||||
template<typename... Args> static NzSkyboxBackgroundRef New(Args&&... args);
|
||||
BackgroundType GetBackgroundType() const;
|
||||
inline const TextureRef& GetTexture() const;
|
||||
inline TextureSampler& GetTextureSampler();
|
||||
inline const TextureSampler& GetTextureSampler() const;
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
inline void SetTexture(TextureRef cubemapTexture);
|
||||
inline void SetTextureSampler(const TextureSampler& sampler);
|
||||
|
||||
NzTextureRef m_texture;
|
||||
NzTextureSampler m_sampler;
|
||||
};
|
||||
template<typename... Args> static SkyboxBackgroundRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
TextureRef m_texture;
|
||||
TextureSampler m_sampler;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/SkyboxBackground.inl>
|
||||
|
||||
|
||||
@@ -5,41 +5,44 @@
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
inline const NzTextureRef& NzSkyboxBackground::GetTexture() const
|
||||
namespace Nz
|
||||
{
|
||||
return m_texture;
|
||||
}
|
||||
inline const TextureRef& SkyboxBackground::GetTexture() const
|
||||
{
|
||||
return m_texture;
|
||||
}
|
||||
|
||||
inline NzTextureSampler& NzSkyboxBackground::GetTextureSampler()
|
||||
{
|
||||
return m_sampler;
|
||||
}
|
||||
inline TextureSampler& SkyboxBackground::GetTextureSampler()
|
||||
{
|
||||
return m_sampler;
|
||||
}
|
||||
|
||||
inline const NzTextureSampler& NzSkyboxBackground::GetTextureSampler() const
|
||||
{
|
||||
return m_sampler;
|
||||
}
|
||||
inline const TextureSampler& SkyboxBackground::GetTextureSampler() const
|
||||
{
|
||||
return m_sampler;
|
||||
}
|
||||
|
||||
inline void NzSkyboxBackground::SetTexture(NzTextureRef cubemapTexture)
|
||||
{
|
||||
NazaraAssert(!cubemapTexture || cubemapTexture->IsValid(), "Invalid texture");
|
||||
NazaraAssert(!cubemapTexture || cubemapTexture->IsCubemap(), "Texture must be a cubemap");
|
||||
inline void SkyboxBackground::SetTexture(TextureRef cubemapTexture)
|
||||
{
|
||||
NazaraAssert(!cubemapTexture || cubemapTexture->IsValid(), "Invalid texture");
|
||||
NazaraAssert(!cubemapTexture || cubemapTexture->IsCubemap(), "Texture must be a cubemap");
|
||||
|
||||
m_texture = std::move(cubemapTexture);
|
||||
}
|
||||
m_texture = std::move(cubemapTexture);
|
||||
}
|
||||
|
||||
void NzSkyboxBackground::SetTextureSampler(const NzTextureSampler& sampler)
|
||||
{
|
||||
m_sampler = sampler;
|
||||
}
|
||||
void SkyboxBackground::SetTextureSampler(const TextureSampler& sampler)
|
||||
{
|
||||
m_sampler = sampler;
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
NzSkyboxBackgroundRef NzSkyboxBackground::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<NzSkyboxBackground> object(new NzSkyboxBackground(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
template<typename... Args>
|
||||
SkyboxBackgroundRef SkyboxBackground::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<SkyboxBackground> object(new SkyboxBackground(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
||||
@@ -13,53 +13,58 @@
|
||||
#include <Nazara/Utility/VertexStruct.hpp>
|
||||
#include <array>
|
||||
|
||||
class NzSprite;
|
||||
|
||||
using NzSpriteConstRef = NzObjectRef<const NzSprite>;
|
||||
using NzSpriteLibrary = NzObjectLibrary<NzSprite>;
|
||||
using NzSpriteRef = NzObjectRef<NzSprite>;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzSprite : public NzInstancedRenderable
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
inline NzSprite();
|
||||
inline NzSprite(NzMaterialRef material);
|
||||
inline NzSprite(NzTexture* texture);
|
||||
inline NzSprite(const NzSprite& sprite);
|
||||
~NzSprite() = default;
|
||||
class Sprite;
|
||||
|
||||
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
|
||||
using SpriteConstRef = ObjectRef<const Sprite>;
|
||||
using SpriteLibrary = ObjectLibrary<Sprite>;
|
||||
using SpriteRef = ObjectRef<Sprite>;
|
||||
|
||||
inline const NzColor& GetColor() const;
|
||||
inline const NzMaterialRef& GetMaterial() const;
|
||||
inline const NzVector2f& GetSize() const;
|
||||
inline const NzRectf& GetTextureCoords() const;
|
||||
class NAZARA_GRAPHICS_API Sprite : public InstancedRenderable
|
||||
{
|
||||
public:
|
||||
inline Sprite();
|
||||
inline Sprite(MaterialRef material);
|
||||
inline Sprite(Texture* texture);
|
||||
inline Sprite(const Sprite& sprite);
|
||||
Sprite(Sprite&&) = delete;
|
||||
~Sprite() = default;
|
||||
|
||||
inline void SetColor(const NzColor& color);
|
||||
inline void SetDefaultMaterial();
|
||||
inline void SetMaterial(NzMaterialRef material, bool resizeSprite = true);
|
||||
inline void SetSize(const NzVector2f& size);
|
||||
inline void SetSize(float sizeX, float sizeY);
|
||||
inline void SetTexture(NzTextureRef texture, bool resizeSprite = true);
|
||||
inline void SetTextureCoords(const NzRectf& coords);
|
||||
inline void SetTextureRect(const NzRectui& rect);
|
||||
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
|
||||
|
||||
inline NzSprite& operator=(const NzSprite& sprite);
|
||||
inline const Color& GetColor() const;
|
||||
inline const MaterialRef& GetMaterial() const;
|
||||
inline const Vector2f& GetSize() const;
|
||||
inline const Rectf& GetTextureCoords() const;
|
||||
|
||||
template<typename... Args> static NzSpriteRef New(Args&&... args);
|
||||
inline void SetColor(const Color& color);
|
||||
inline void SetDefaultMaterial();
|
||||
inline void SetMaterial(MaterialRef material, bool resizeSprite = true);
|
||||
inline void SetSize(const Vector2f& size);
|
||||
inline void SetSize(float sizeX, float sizeY);
|
||||
inline void SetTexture(TextureRef texture, bool resizeSprite = true);
|
||||
inline void SetTextureCoords(const Rectf& coords);
|
||||
inline void SetTextureRect(const Rectui& rect);
|
||||
|
||||
private:
|
||||
inline void InvalidateVertices();
|
||||
void MakeBoundingVolume() const override;
|
||||
void UpdateData(InstanceData* instanceData) const override;
|
||||
inline Sprite& operator=(const Sprite& sprite);
|
||||
Sprite& operator=(Sprite&& sprite) = delete;
|
||||
|
||||
NzColor m_color;
|
||||
NzMaterialRef m_material;
|
||||
NzRectf m_textureCoords;
|
||||
NzVector2f m_size;
|
||||
template<typename... Args> static SpriteRef New(Args&&... args);
|
||||
|
||||
static NzSpriteLibrary::LibraryMap s_library;
|
||||
};
|
||||
private:
|
||||
inline void InvalidateVertices();
|
||||
void MakeBoundingVolume() const override;
|
||||
void UpdateData(InstanceData* instanceData) const override;
|
||||
|
||||
Color m_color;
|
||||
MaterialRef m_material;
|
||||
Rectf m_textureCoords;
|
||||
Vector2f m_size;
|
||||
|
||||
static SpriteLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/Sprite.inl>
|
||||
|
||||
|
||||
@@ -6,160 +6,163 @@
|
||||
#include <memory>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
inline NzSprite::NzSprite() :
|
||||
m_color(NzColor::White),
|
||||
m_textureCoords(0.f, 0.f, 1.f, 1.f),
|
||||
m_size(64.f, 64.f)
|
||||
namespace Nz
|
||||
{
|
||||
SetDefaultMaterial();
|
||||
}
|
||||
|
||||
inline NzSprite::NzSprite(NzMaterialRef material) :
|
||||
m_color(NzColor::White),
|
||||
m_textureCoords(0.f, 0.f, 1.f, 1.f),
|
||||
m_size(64.f, 64.f)
|
||||
{
|
||||
SetMaterial(std::move(material), true);
|
||||
}
|
||||
|
||||
inline NzSprite::NzSprite(NzTexture* texture) :
|
||||
m_color(NzColor::White),
|
||||
m_textureCoords(0.f, 0.f, 1.f, 1.f),
|
||||
m_size(64.f, 64.f)
|
||||
{
|
||||
SetTexture(texture, true);
|
||||
}
|
||||
|
||||
inline NzSprite::NzSprite(const NzSprite& sprite) :
|
||||
NzInstancedRenderable(sprite),
|
||||
m_color(sprite.m_color),
|
||||
m_material(sprite.m_material),
|
||||
m_textureCoords(sprite.m_textureCoords),
|
||||
m_size(sprite.m_size)
|
||||
{
|
||||
}
|
||||
|
||||
inline const NzColor& NzSprite::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
inline const NzMaterialRef& NzSprite::GetMaterial() const
|
||||
{
|
||||
return m_material;
|
||||
}
|
||||
|
||||
inline const NzVector2f& NzSprite::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
inline const NzRectf& NzSprite::GetTextureCoords() const
|
||||
{
|
||||
return m_textureCoords;
|
||||
}
|
||||
|
||||
inline void NzSprite::SetColor(const NzColor& color)
|
||||
{
|
||||
m_color = color;
|
||||
|
||||
InvalidateVertices();
|
||||
}
|
||||
|
||||
inline void NzSprite::SetDefaultMaterial()
|
||||
{
|
||||
NzMaterialRef material = NzMaterial::New();
|
||||
material->Enable(nzRendererParameter_FaceCulling, false);
|
||||
material->EnableLighting(false);
|
||||
|
||||
SetMaterial(std::move(material));
|
||||
}
|
||||
|
||||
inline void NzSprite::SetMaterial(NzMaterialRef material, bool resizeSprite)
|
||||
{
|
||||
m_material = std::move(material);
|
||||
if (m_material && resizeSprite)
|
||||
inline Sprite::Sprite() :
|
||||
m_color(Color::White),
|
||||
m_textureCoords(0.f, 0.f, 1.f, 1.f),
|
||||
m_size(64.f, 64.f)
|
||||
{
|
||||
NzTexture* diffuseMap = m_material->GetDiffuseMap();
|
||||
if (diffuseMap && diffuseMap->IsValid())
|
||||
SetSize(NzVector2f(NzVector2ui(diffuseMap->GetSize())));
|
||||
SetDefaultMaterial();
|
||||
}
|
||||
|
||||
inline Sprite::Sprite(MaterialRef material) :
|
||||
m_color(Color::White),
|
||||
m_textureCoords(0.f, 0.f, 1.f, 1.f),
|
||||
m_size(64.f, 64.f)
|
||||
{
|
||||
SetMaterial(std::move(material), true);
|
||||
}
|
||||
|
||||
inline Sprite::Sprite(Texture* texture) :
|
||||
m_color(Color::White),
|
||||
m_textureCoords(0.f, 0.f, 1.f, 1.f),
|
||||
m_size(64.f, 64.f)
|
||||
{
|
||||
SetTexture(texture, true);
|
||||
}
|
||||
|
||||
inline Sprite::Sprite(const Sprite& sprite) :
|
||||
InstancedRenderable(sprite),
|
||||
m_color(sprite.m_color),
|
||||
m_material(sprite.m_material),
|
||||
m_textureCoords(sprite.m_textureCoords),
|
||||
m_size(sprite.m_size)
|
||||
{
|
||||
}
|
||||
|
||||
inline const Color& Sprite::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
inline const MaterialRef& Sprite::GetMaterial() const
|
||||
{
|
||||
return m_material;
|
||||
}
|
||||
|
||||
inline const Vector2f& Sprite::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
inline const Rectf& Sprite::GetTextureCoords() const
|
||||
{
|
||||
return m_textureCoords;
|
||||
}
|
||||
|
||||
inline void Sprite::SetColor(const Color& color)
|
||||
{
|
||||
m_color = color;
|
||||
|
||||
InvalidateVertices();
|
||||
}
|
||||
|
||||
inline void Sprite::SetDefaultMaterial()
|
||||
{
|
||||
MaterialRef material = Material::New();
|
||||
material->Enable(RendererParameter_FaceCulling, false);
|
||||
material->EnableLighting(false);
|
||||
|
||||
SetMaterial(std::move(material));
|
||||
}
|
||||
|
||||
inline void Sprite::SetMaterial(MaterialRef material, bool resizeSprite)
|
||||
{
|
||||
m_material = std::move(material);
|
||||
if (m_material && resizeSprite)
|
||||
{
|
||||
Texture* diffuseMap = m_material->GetDiffuseMap();
|
||||
if (diffuseMap && diffuseMap->IsValid())
|
||||
SetSize(Vector2f(Vector2ui(diffuseMap->GetSize())));
|
||||
}
|
||||
}
|
||||
|
||||
inline void Sprite::SetSize(const Vector2f& size)
|
||||
{
|
||||
m_size = size;
|
||||
|
||||
// On invalide la bounding box
|
||||
InvalidateBoundingVolume();
|
||||
InvalidateVertices();
|
||||
}
|
||||
|
||||
inline void Sprite::SetSize(float sizeX, float sizeY)
|
||||
{
|
||||
SetSize(Vector2f(sizeX, sizeY));
|
||||
}
|
||||
|
||||
inline void Sprite::SetTexture(TextureRef texture, bool resizeSprite)
|
||||
{
|
||||
if (!m_material)
|
||||
SetDefaultMaterial();
|
||||
else if (m_material->GetReferenceCount() > 1)
|
||||
m_material = Material::New(*m_material); // Copie
|
||||
|
||||
if (resizeSprite && texture && texture->IsValid())
|
||||
SetSize(Vector2f(Vector2ui(texture->GetSize())));
|
||||
|
||||
m_material->SetDiffuseMap(std::move(texture));
|
||||
}
|
||||
|
||||
inline void Sprite::SetTextureCoords(const Rectf& coords)
|
||||
{
|
||||
m_textureCoords = coords;
|
||||
InvalidateVertices();
|
||||
}
|
||||
|
||||
inline void Sprite::SetTextureRect(const Rectui& rect)
|
||||
{
|
||||
NazaraAssert(m_material, "Sprite has no material");
|
||||
NazaraAssert(m_material->HasDiffuseMap(), "Sprite material has no diffuse map");
|
||||
|
||||
Texture* diffuseMap = m_material->GetDiffuseMap();
|
||||
|
||||
float invWidth = 1.f/diffuseMap->GetWidth();
|
||||
float invHeight = 1.f/diffuseMap->GetHeight();
|
||||
|
||||
SetTextureCoords(Rectf(invWidth*rect.x, invHeight*rect.y, invWidth*rect.width, invHeight*rect.height));
|
||||
}
|
||||
|
||||
inline Sprite& Sprite::operator=(const Sprite& sprite)
|
||||
{
|
||||
InstancedRenderable::operator=(sprite);
|
||||
|
||||
m_color = sprite.m_color;
|
||||
m_material = sprite.m_material;
|
||||
m_textureCoords = sprite.m_textureCoords;
|
||||
m_size = sprite.m_size;
|
||||
|
||||
// On ne copie pas les sommets finaux car il est très probable que nos paramètres soient modifiés et qu'ils doivent être régénérés de toute façon
|
||||
InvalidateBoundingVolume();
|
||||
InvalidateVertices();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void Sprite::InvalidateVertices()
|
||||
{
|
||||
InvalidateInstanceData(0);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
SpriteRef Sprite::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<Sprite> object(new Sprite(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
inline void NzSprite::SetSize(const NzVector2f& size)
|
||||
{
|
||||
m_size = size;
|
||||
|
||||
// On invalide la bounding box
|
||||
InvalidateBoundingVolume();
|
||||
InvalidateVertices();
|
||||
}
|
||||
|
||||
inline void NzSprite::SetSize(float sizeX, float sizeY)
|
||||
{
|
||||
SetSize(NzVector2f(sizeX, sizeY));
|
||||
}
|
||||
|
||||
inline void NzSprite::SetTexture(NzTextureRef texture, bool resizeSprite)
|
||||
{
|
||||
if (!m_material)
|
||||
SetDefaultMaterial();
|
||||
else if (m_material->GetReferenceCount() > 1)
|
||||
m_material = NzMaterial::New(*m_material); // Copie
|
||||
|
||||
if (resizeSprite && texture && texture->IsValid())
|
||||
SetSize(NzVector2f(NzVector2ui(texture->GetSize())));
|
||||
|
||||
m_material->SetDiffuseMap(std::move(texture));
|
||||
}
|
||||
|
||||
inline void NzSprite::SetTextureCoords(const NzRectf& coords)
|
||||
{
|
||||
m_textureCoords = coords;
|
||||
InvalidateVertices();
|
||||
}
|
||||
|
||||
inline void NzSprite::SetTextureRect(const NzRectui& rect)
|
||||
{
|
||||
NazaraAssert(m_material, "Sprite has no material");
|
||||
NazaraAssert(m_material->HasDiffuseMap(), "Sprite material has no diffuse map");
|
||||
|
||||
NzTexture* diffuseMap = m_material->GetDiffuseMap();
|
||||
|
||||
float invWidth = 1.f/diffuseMap->GetWidth();
|
||||
float invHeight = 1.f/diffuseMap->GetHeight();
|
||||
|
||||
SetTextureCoords(NzRectf(invWidth*rect.x, invHeight*rect.y, invWidth*rect.width, invHeight*rect.height));
|
||||
}
|
||||
|
||||
inline NzSprite& NzSprite::operator=(const NzSprite& sprite)
|
||||
{
|
||||
NzInstancedRenderable::operator=(sprite);
|
||||
|
||||
m_color = sprite.m_color;
|
||||
m_material = sprite.m_material;
|
||||
m_textureCoords = sprite.m_textureCoords;
|
||||
m_size = sprite.m_size;
|
||||
|
||||
// On ne copie pas les sommets finaux car il est très probable que nos paramètres soient modifiés et qu'ils doivent être régénérés de toute façon
|
||||
InvalidateBoundingVolume();
|
||||
InvalidateVertices();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void NzSprite::InvalidateVertices()
|
||||
{
|
||||
InvalidateInstanceData(0);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
NzSpriteRef NzSprite::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<NzSprite> object(new NzSprite(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/DebugOff.hpp>
|
||||
|
||||
@@ -16,69 +16,72 @@
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
class NzTextSprite;
|
||||
|
||||
using NzTextSpriteConstRef = NzObjectRef<const NzTextSprite>;
|
||||
using NzTextSpriteLibrary = NzObjectLibrary<NzTextSprite>;
|
||||
using NzTextSpriteRef = NzObjectRef<NzTextSprite>;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzTextSprite : public NzInstancedRenderable
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
inline NzTextSprite();
|
||||
inline NzTextSprite(const NzTextSprite& sprite);
|
||||
~NzTextSprite() = default;
|
||||
class TextSprite;
|
||||
|
||||
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
|
||||
using TextSpriteConstRef = ObjectRef<const TextSprite>;
|
||||
using TextSpriteLibrary = ObjectLibrary<TextSprite>;
|
||||
using TextSpriteRef = ObjectRef<TextSprite>;
|
||||
|
||||
inline void Clear();
|
||||
class NAZARA_GRAPHICS_API TextSprite : public InstancedRenderable
|
||||
{
|
||||
public:
|
||||
inline TextSprite();
|
||||
inline TextSprite(const TextSprite& sprite);
|
||||
~TextSprite() = default;
|
||||
|
||||
inline const NzColor& GetColor() const;
|
||||
inline const NzMaterialRef& GetMaterial() const;
|
||||
inline float GetScale() const;
|
||||
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
|
||||
|
||||
inline void SetColor(const NzColor& color);
|
||||
inline void SetDefaultMaterial();
|
||||
inline void SetMaterial(NzMaterialRef material);
|
||||
inline void SetScale(float scale);
|
||||
inline void Clear();
|
||||
|
||||
void Update(const NzAbstractTextDrawer& drawer);
|
||||
inline const Color& GetColor() const;
|
||||
inline const MaterialRef& GetMaterial() const;
|
||||
inline float GetScale() const;
|
||||
|
||||
inline NzTextSprite& operator=(const NzTextSprite& text);
|
||||
inline void SetColor(const Color& color);
|
||||
inline void SetDefaultMaterial();
|
||||
inline void SetMaterial(MaterialRef material);
|
||||
inline void SetScale(float scale);
|
||||
|
||||
template<typename... Args> static NzTextSpriteRef New(Args&&... args);
|
||||
void Update(const AbstractTextDrawer& drawer);
|
||||
|
||||
private:
|
||||
inline void InvalidateVertices();
|
||||
void MakeBoundingVolume() const override;
|
||||
void OnAtlasInvalidated(const NzAbstractAtlas* atlas);
|
||||
void OnAtlasLayerChange(const NzAbstractAtlas* atlas, NzAbstractImage* oldLayer, NzAbstractImage* newLayer);
|
||||
void UpdateData(InstanceData* instanceData) const override;
|
||||
inline TextSprite& operator=(const TextSprite& text);
|
||||
|
||||
struct RenderIndices
|
||||
{
|
||||
unsigned int first;
|
||||
unsigned int count;
|
||||
};
|
||||
template<typename... Args> static TextSpriteRef New(Args&&... args);
|
||||
|
||||
struct AtlasSlots
|
||||
{
|
||||
NazaraSlot(NzAbstractAtlas, OnAtlasCleared, clearSlot);
|
||||
NazaraSlot(NzAbstractAtlas, OnAtlasLayerChange, layerChangeSlot);
|
||||
NazaraSlot(NzAbstractAtlas, OnAtlasRelease, releaseSlot);
|
||||
};
|
||||
private:
|
||||
inline void InvalidateVertices();
|
||||
void MakeBoundingVolume() const override;
|
||||
void OnAtlasInvalidated(const AbstractAtlas* atlas);
|
||||
void OnAtlasLayerChange(const AbstractAtlas* atlas, AbstractImage* oldLayer, AbstractImage* newLayer);
|
||||
void UpdateData(InstanceData* instanceData) const override;
|
||||
|
||||
std::unordered_map<const NzAbstractAtlas*, AtlasSlots> m_atlases;
|
||||
mutable std::unordered_map<NzTexture*, RenderIndices> m_renderInfos;
|
||||
mutable std::vector<NzVertexStruct_XY_Color_UV> m_localVertices;
|
||||
NzColor m_color;
|
||||
NzMaterialRef m_material;
|
||||
NzRectui m_localBounds;
|
||||
mutable bool m_verticesUpdated;
|
||||
float m_scale;
|
||||
struct RenderIndices
|
||||
{
|
||||
unsigned int first;
|
||||
unsigned int count;
|
||||
};
|
||||
|
||||
static NzTextSpriteLibrary::LibraryMap s_library;
|
||||
};
|
||||
struct AtlasSlots
|
||||
{
|
||||
NazaraSlot(AbstractAtlas, OnAtlasCleared, clearSlot);
|
||||
NazaraSlot(AbstractAtlas, OnAtlasLayerChange, layerChangeSlot);
|
||||
NazaraSlot(AbstractAtlas, OnAtlasRelease, releaseSlot);
|
||||
};
|
||||
|
||||
std::unordered_map<const AbstractAtlas*, AtlasSlots> m_atlases;
|
||||
mutable std::unordered_map<Texture*, RenderIndices> m_renderInfos;
|
||||
mutable std::vector<VertexStruct_XY_Color_UV> m_localVertices;
|
||||
Color m_color;
|
||||
MaterialRef m_material;
|
||||
Rectui m_localBounds;
|
||||
mutable bool m_verticesUpdated;
|
||||
float m_scale;
|
||||
|
||||
static TextSpriteLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/TextSprite.inl>
|
||||
|
||||
|
||||
@@ -5,130 +5,133 @@
|
||||
#include <memory>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
inline NzTextSprite::NzTextSprite() :
|
||||
m_color(NzColor::White),
|
||||
m_scale(1.f)
|
||||
namespace Nz
|
||||
{
|
||||
SetDefaultMaterial();
|
||||
}
|
||||
|
||||
inline NzTextSprite::NzTextSprite(const NzTextSprite& sprite) :
|
||||
NzInstancedRenderable(sprite),
|
||||
m_renderInfos(sprite.m_renderInfos),
|
||||
m_localVertices(sprite.m_localVertices),
|
||||
m_color(sprite.m_color),
|
||||
m_material(sprite.m_material),
|
||||
m_localBounds(sprite.m_localBounds),
|
||||
m_scale(sprite.m_scale)
|
||||
{
|
||||
for (auto it = sprite.m_atlases.begin(); it != sprite.m_atlases.end(); ++it)
|
||||
inline TextSprite::TextSprite() :
|
||||
m_color(Color::White),
|
||||
m_scale(1.f)
|
||||
{
|
||||
const NzAbstractAtlas* atlas = it->first;
|
||||
AtlasSlots& slots = m_atlases[atlas];
|
||||
|
||||
slots.clearSlot.Connect(atlas->OnAtlasCleared, this, &NzTextSprite::OnAtlasInvalidated);
|
||||
slots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, &NzTextSprite::OnAtlasLayerChange);
|
||||
slots.releaseSlot.Connect(atlas->OnAtlasRelease, this, &NzTextSprite::OnAtlasInvalidated);
|
||||
}
|
||||
}
|
||||
|
||||
inline void NzTextSprite::Clear()
|
||||
{
|
||||
m_atlases.clear();
|
||||
m_boundingVolume.MakeNull();
|
||||
m_localVertices.clear();
|
||||
m_renderInfos.clear();
|
||||
}
|
||||
|
||||
inline const NzColor& NzTextSprite::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
inline const NzMaterialRef& NzTextSprite::GetMaterial() const
|
||||
{
|
||||
return m_material;
|
||||
}
|
||||
|
||||
inline float NzTextSprite::GetScale() const
|
||||
{
|
||||
return m_scale;
|
||||
}
|
||||
|
||||
inline void NzTextSprite::SetColor(const NzColor& color)
|
||||
{
|
||||
m_color = color;
|
||||
|
||||
InvalidateVertices();
|
||||
}
|
||||
|
||||
inline void NzTextSprite::SetDefaultMaterial()
|
||||
{
|
||||
NzMaterialRef material = NzMaterial::New();
|
||||
material->Enable(nzRendererParameter_Blend, true);
|
||||
material->Enable(nzRendererParameter_DepthWrite, false);
|
||||
material->Enable(nzRendererParameter_FaceCulling, false);
|
||||
material->EnableLighting(false);
|
||||
material->SetDstBlend(nzBlendFunc_InvSrcAlpha);
|
||||
material->SetSrcBlend(nzBlendFunc_SrcAlpha);
|
||||
|
||||
SetMaterial(material);
|
||||
}
|
||||
|
||||
inline void NzTextSprite::SetMaterial(NzMaterialRef material)
|
||||
{
|
||||
m_material = std::move(material);
|
||||
}
|
||||
|
||||
inline void NzTextSprite::SetScale(float scale)
|
||||
{
|
||||
m_scale = scale;
|
||||
|
||||
InvalidateVertices();
|
||||
}
|
||||
|
||||
inline void NzTextSprite::InvalidateVertices()
|
||||
{
|
||||
InvalidateInstanceData(0);
|
||||
}
|
||||
|
||||
inline NzTextSprite& NzTextSprite::operator=(const NzTextSprite& text)
|
||||
{
|
||||
NzInstancedRenderable::operator=(text);
|
||||
|
||||
m_atlases.clear();
|
||||
|
||||
m_color = text.m_color;
|
||||
m_material = text.m_material;
|
||||
m_renderInfos = text.m_renderInfos;
|
||||
m_localBounds = text.m_localBounds;
|
||||
m_localVertices = text.m_localVertices;
|
||||
m_scale = text.m_scale;
|
||||
|
||||
// Connect to the slots of the new atlases
|
||||
for (auto it = text.m_atlases.begin(); it != text.m_atlases.end(); ++it)
|
||||
{
|
||||
const NzAbstractAtlas* atlas = it->first;
|
||||
AtlasSlots& slots = m_atlases[atlas];
|
||||
|
||||
slots.clearSlot.Connect(atlas->OnAtlasCleared, this, &NzTextSprite::OnAtlasInvalidated);
|
||||
slots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, &NzTextSprite::OnAtlasLayerChange);
|
||||
slots.releaseSlot.Connect(atlas->OnAtlasRelease, this, &NzTextSprite::OnAtlasInvalidated);
|
||||
SetDefaultMaterial();
|
||||
}
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
InvalidateVertices();
|
||||
inline TextSprite::TextSprite(const TextSprite& sprite) :
|
||||
InstancedRenderable(sprite),
|
||||
m_renderInfos(sprite.m_renderInfos),
|
||||
m_localVertices(sprite.m_localVertices),
|
||||
m_color(sprite.m_color),
|
||||
m_material(sprite.m_material),
|
||||
m_localBounds(sprite.m_localBounds),
|
||||
m_scale(sprite.m_scale)
|
||||
{
|
||||
for (auto it = sprite.m_atlases.begin(); it != sprite.m_atlases.end(); ++it)
|
||||
{
|
||||
const AbstractAtlas* atlas = it->first;
|
||||
AtlasSlots& slots = m_atlases[atlas];
|
||||
|
||||
return *this;
|
||||
}
|
||||
slots.clearSlot.Connect(atlas->OnAtlasCleared, this, &TextSprite::OnAtlasInvalidated);
|
||||
slots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, &TextSprite::OnAtlasLayerChange);
|
||||
slots.releaseSlot.Connect(atlas->OnAtlasRelease, this, &TextSprite::OnAtlasInvalidated);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
NzTextSpriteRef NzTextSprite::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<NzTextSprite> object(new NzTextSprite(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
inline void TextSprite::Clear()
|
||||
{
|
||||
m_atlases.clear();
|
||||
m_boundingVolume.MakeNull();
|
||||
m_localVertices.clear();
|
||||
m_renderInfos.clear();
|
||||
}
|
||||
|
||||
return object.release();
|
||||
inline const Color& TextSprite::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
inline const MaterialRef& TextSprite::GetMaterial() const
|
||||
{
|
||||
return m_material;
|
||||
}
|
||||
|
||||
inline float TextSprite::GetScale() const
|
||||
{
|
||||
return m_scale;
|
||||
}
|
||||
|
||||
inline void TextSprite::SetColor(const Color& color)
|
||||
{
|
||||
m_color = color;
|
||||
|
||||
InvalidateVertices();
|
||||
}
|
||||
|
||||
inline void TextSprite::SetDefaultMaterial()
|
||||
{
|
||||
MaterialRef material = Material::New();
|
||||
material->Enable(RendererParameter_Blend, true);
|
||||
material->Enable(RendererParameter_DepthWrite, false);
|
||||
material->Enable(RendererParameter_FaceCulling, false);
|
||||
material->EnableLighting(false);
|
||||
material->SetDstBlend(BlendFunc_InvSrcAlpha);
|
||||
material->SetSrcBlend(BlendFunc_SrcAlpha);
|
||||
|
||||
SetMaterial(material);
|
||||
}
|
||||
|
||||
inline void TextSprite::SetMaterial(MaterialRef material)
|
||||
{
|
||||
m_material = std::move(material);
|
||||
}
|
||||
|
||||
inline void TextSprite::SetScale(float scale)
|
||||
{
|
||||
m_scale = scale;
|
||||
|
||||
InvalidateVertices();
|
||||
}
|
||||
|
||||
inline void TextSprite::InvalidateVertices()
|
||||
{
|
||||
InvalidateInstanceData(0);
|
||||
}
|
||||
|
||||
inline TextSprite& TextSprite::operator=(const TextSprite& text)
|
||||
{
|
||||
InstancedRenderable::operator=(text);
|
||||
|
||||
m_atlases.clear();
|
||||
|
||||
m_color = text.m_color;
|
||||
m_material = text.m_material;
|
||||
m_renderInfos = text.m_renderInfos;
|
||||
m_localBounds = text.m_localBounds;
|
||||
m_localVertices = text.m_localVertices;
|
||||
m_scale = text.m_scale;
|
||||
|
||||
// Connect to the slots of the new atlases
|
||||
for (auto it = text.m_atlases.begin(); it != text.m_atlases.end(); ++it)
|
||||
{
|
||||
const AbstractAtlas* atlas = it->first;
|
||||
AtlasSlots& slots = m_atlases[atlas];
|
||||
|
||||
slots.clearSlot.Connect(atlas->OnAtlasCleared, this, &TextSprite::OnAtlasInvalidated);
|
||||
slots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, &TextSprite::OnAtlasLayerChange);
|
||||
slots.releaseSlot.Connect(atlas->OnAtlasRelease, this, &TextSprite::OnAtlasInvalidated);
|
||||
}
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
InvalidateVertices();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
TextSpriteRef TextSprite::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<TextSprite> object(new TextSprite(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/DebugOff.hpp>
|
||||
|
||||
@@ -12,33 +12,36 @@
|
||||
#include <Nazara/Renderer/UberShader.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
|
||||
class NzTextureBackground;
|
||||
|
||||
using NzTextureBackgroundConstRef = NzObjectRef<const NzTextureBackground>;
|
||||
using NzTextureBackgroundRef = NzObjectRef<NzTextureBackground>;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzTextureBackground : public NzAbstractBackground
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
NzTextureBackground(NzTextureRef texture = NzTextureRef());
|
||||
class TextureBackground;
|
||||
|
||||
void Draw(const NzAbstractViewer* viewer) const;
|
||||
using TextureBackgroundConstRef = ObjectRef<const TextureBackground>;
|
||||
using TextureBackgroundRef = ObjectRef<TextureBackground>;
|
||||
|
||||
nzBackgroundType GetBackgroundType() const;
|
||||
inline const NzTextureRef& GetTexture() const;
|
||||
class NAZARA_GRAPHICS_API TextureBackground : public AbstractBackground
|
||||
{
|
||||
public:
|
||||
TextureBackground(TextureRef texture = TextureRef());
|
||||
|
||||
inline void SetTexture(NzTextureRef texture);
|
||||
void Draw(const AbstractViewer* viewer) const;
|
||||
|
||||
template<typename... Args> static NzTextureBackgroundRef New(Args&&... args);
|
||||
BackgroundType GetBackgroundType() const;
|
||||
inline const TextureRef& GetTexture() const;
|
||||
|
||||
private:
|
||||
NzTextureRef m_texture;
|
||||
NzUberShaderConstRef m_uberShader;
|
||||
const NzUberShaderInstance* m_uberShaderInstance;
|
||||
int m_materialDiffuseUniform;
|
||||
int m_materialDiffuseMapUniform;
|
||||
int m_vertexDepthUniform;
|
||||
};
|
||||
inline void SetTexture(TextureRef texture);
|
||||
|
||||
template<typename... Args> static TextureBackgroundRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
TextureRef m_texture;
|
||||
UberShaderConstRef m_uberShader;
|
||||
const UberShaderInstance* m_uberShaderInstance;
|
||||
int m_materialDiffuseUniform;
|
||||
int m_materialDiffuseMapUniform;
|
||||
int m_vertexDepthUniform;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/TextureBackground.inl>
|
||||
|
||||
|
||||
@@ -5,25 +5,28 @@
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
inline const NzTextureRef& NzTextureBackground::GetTexture() const
|
||||
namespace Nz
|
||||
{
|
||||
return m_texture;
|
||||
}
|
||||
inline const TextureRef& TextureBackground::GetTexture() const
|
||||
{
|
||||
return m_texture;
|
||||
}
|
||||
|
||||
inline void NzTextureBackground::SetTexture(NzTextureRef texture)
|
||||
{
|
||||
NazaraAssert(!texture || texture->IsValid(), "Invalid texture");
|
||||
inline void TextureBackground::SetTexture(TextureRef texture)
|
||||
{
|
||||
NazaraAssert(!texture || texture->IsValid(), "Invalid texture");
|
||||
|
||||
m_texture = std::move(texture);
|
||||
}
|
||||
m_texture = std::move(texture);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
NzTextureBackgroundRef NzTextureBackground::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<NzTextureBackground> object(new NzTextureBackground(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
template<typename... Args>
|
||||
TextureBackgroundRef TextureBackground::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<TextureBackground> object(new TextureBackground(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
||||
Reference in New Issue
Block a user