Remove Graphics module and fix compilation
This commit is contained in:
parent
bc92d030ed
commit
2a875c8bdc
|
|
@ -1,8 +0,0 @@
|
|||
MODULE.Name = "Graphics"
|
||||
|
||||
MODULE.Libraries = {
|
||||
"NazaraCore",
|
||||
"NazaraUtility",
|
||||
"NazaraPlatform",
|
||||
"NazaraRenderer"
|
||||
}
|
||||
|
|
@ -10,7 +10,6 @@
|
|||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Core/HardwareInfo.hpp>
|
||||
#include <Nazara/Core/Initializer.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
|
@ -58,37 +57,6 @@ int main()
|
|||
else
|
||||
oss << "Impossible de retrouver les informations du processeur" << std::endl;
|
||||
|
||||
oss << std::endl << "--Carte graphique--" << std::endl;
|
||||
// La classe OpenGL nous donne accès à des informations sur la carte graphique
|
||||
// Cependant celle-ci n'est accessible que si le projet est compilé avec NAZARA_RENDERER_OPENGL
|
||||
// et que les répertoires d'inclusions donnent accès aux includes d'OpenGL (Cette démo utilisent ceux de Nazara)
|
||||
Nz::Initializer<Nz::OpenGL> openGL;
|
||||
if (openGL)
|
||||
{
|
||||
// Nous récupérons ensuite la version d'OpenGL sous forme d'entier (ex: OpenGL 3.3 donnera 330)
|
||||
unsigned int openglVersion = Nz::OpenGL::GetVersion();
|
||||
|
||||
// OpenGL nous donne accès à trois informations principales:
|
||||
// 1) La chaîne d'identification du driver ("Renderer name")
|
||||
// 2) La chaîne d'identification du concepteur ("Vendor name")
|
||||
// 3) La version d'OpenGL
|
||||
oss << "Identification: " << Nz::OpenGL::GetRendererName() << std::endl;
|
||||
oss << "Concepteur: " << Nz::OpenGL::GetVendorName() << std::endl;
|
||||
oss << "Version d'OpenGL: " << openglVersion/100 << '.' << openglVersion%100 << std::endl;
|
||||
oss << std::endl;
|
||||
|
||||
// Ainsi qu'un report des capacités de la carte graphique (avec le driver actuel)
|
||||
oss << "Rapport des capacites: " << std::endl; // Pas d'accent car écriture dans un fichier (et on ne va pas s'embêter avec ça)
|
||||
printCap(oss, "-Calculs 64bits", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_FP64));
|
||||
printCap(oss, "-Compression de textures (s3tc)", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_TextureCompression_s3tc));
|
||||
printCap(oss, "-Filtrage anisotrope", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_AnisotropicFilter));
|
||||
printCap(oss, "-Mode debug", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_DebugOutput));
|
||||
printCap(oss, "-Separate shader objects", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_SeparateShaderObjects));
|
||||
printCap(oss, "-Texture storage", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_TextureStorage));
|
||||
}
|
||||
else
|
||||
oss << "Impossible de retrouver les informations de la carte graphique" << std::endl;
|
||||
|
||||
std::cout << "\r "; // On efface le message d'initialisation
|
||||
std::cout << '\r'; // Et on place déjà le caractère pour revenir sur la même ligne (Pour ne pas avoir un saut inutile)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,87 +0,0 @@
|
|||
// This file was automatically generated
|
||||
|
||||
/*
|
||||
Nazara Engine - Graphics module
|
||||
|
||||
Copyright (C) 2015 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GLOBAL_GRAPHICS_HPP
|
||||
#define NAZARA_GLOBAL_GRAPHICS_HPP
|
||||
|
||||
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
|
||||
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
|
||||
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||
#include <Nazara/Graphics/BasicRenderQueue.hpp>
|
||||
#include <Nazara/Graphics/Billboard.hpp>
|
||||
#include <Nazara/Graphics/ColorBackground.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/CullingList.hpp>
|
||||
#include <Nazara/Graphics/DeferredBloomPass.hpp>
|
||||
#include <Nazara/Graphics/DeferredDOFPass.hpp>
|
||||
#include <Nazara/Graphics/DeferredFinalPass.hpp>
|
||||
#include <Nazara/Graphics/DeferredFogPass.hpp>
|
||||
#include <Nazara/Graphics/DeferredForwardPass.hpp>
|
||||
#include <Nazara/Graphics/DeferredFXAAPass.hpp>
|
||||
#include <Nazara/Graphics/DeferredGeometryPass.hpp>
|
||||
#include <Nazara/Graphics/DeferredPhongLightingPass.hpp>
|
||||
#include <Nazara/Graphics/DeferredProxyRenderQueue.hpp>
|
||||
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
||||
#include <Nazara/Graphics/DeferredRenderTechnique.hpp>
|
||||
#include <Nazara/Graphics/DepthRenderQueue.hpp>
|
||||
#include <Nazara/Graphics/DepthRenderTechnique.hpp>
|
||||
#include <Nazara/Graphics/Drawable.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
|
||||
#include <Nazara/Graphics/Graphics.hpp>
|
||||
#include <Nazara/Graphics/GuillotineTextureAtlas.hpp>
|
||||
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||
#include <Nazara/Graphics/Light.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Graphics/MaterialPipeline.hpp>
|
||||
#include <Nazara/Graphics/Model.hpp>
|
||||
#include <Nazara/Graphics/ParticleController.hpp>
|
||||
#include <Nazara/Graphics/ParticleDeclaration.hpp>
|
||||
#include <Nazara/Graphics/ParticleEmitter.hpp>
|
||||
#include <Nazara/Graphics/ParticleFunctionController.hpp>
|
||||
#include <Nazara/Graphics/ParticleFunctionGenerator.hpp>
|
||||
#include <Nazara/Graphics/ParticleFunctionRenderer.hpp>
|
||||
#include <Nazara/Graphics/ParticleGenerator.hpp>
|
||||
#include <Nazara/Graphics/ParticleGroup.hpp>
|
||||
#include <Nazara/Graphics/ParticleMapper.hpp>
|
||||
#include <Nazara/Graphics/ParticleRenderer.hpp>
|
||||
#include <Nazara/Graphics/ParticleStruct.hpp>
|
||||
#include <Nazara/Graphics/Renderable.hpp>
|
||||
#include <Nazara/Graphics/RenderQueue.hpp>
|
||||
#include <Nazara/Graphics/RenderTechniques.hpp>
|
||||
#include <Nazara/Graphics/SceneData.hpp>
|
||||
#include <Nazara/Graphics/SkeletalModel.hpp>
|
||||
#include <Nazara/Graphics/SkinningManager.hpp>
|
||||
#include <Nazara/Graphics/SkyboxBackground.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Graphics/TextureBackground.hpp>
|
||||
#include <Nazara/Graphics/TileMap.hpp>
|
||||
|
||||
#endif // NAZARA_GLOBAL_GRAPHICS_HPP
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ABSTRACTBACKGROUND_HPP
|
||||
#define NAZARA_ABSTRACTBACKGROUND_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractBackground;
|
||||
class AbstractViewer;
|
||||
|
||||
using BackgroundConstRef = ObjectRef<const AbstractBackground>;
|
||||
using BackgroundLibrary = ObjectLibrary<AbstractBackground>;
|
||||
using BackgroundRef = ObjectRef<AbstractBackground>;
|
||||
|
||||
class NAZARA_GRAPHICS_API AbstractBackground : public RefCounted
|
||||
{
|
||||
public:
|
||||
AbstractBackground() = default;
|
||||
AbstractBackground(const AbstractBackground&) = default;
|
||||
AbstractBackground(AbstractBackground&&) = delete;
|
||||
virtual ~AbstractBackground();
|
||||
|
||||
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
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ABSTRACTRENDERQUEUE_HPP
|
||||
#define NAZARA_ABSTRACTRENDERQUEUE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/SparsePtr.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Drawable;
|
||||
class Material;
|
||||
class Texture;
|
||||
struct MeshData;
|
||||
struct VertexStruct_XYZ_Color_UV;
|
||||
|
||||
class NAZARA_GRAPHICS_API AbstractRenderQueue
|
||||
{
|
||||
public:
|
||||
struct DirectionalLight;
|
||||
struct PointLight;
|
||||
struct SpotLight;
|
||||
|
||||
AbstractRenderQueue() = default;
|
||||
AbstractRenderQueue(const AbstractRenderQueue&) = delete;
|
||||
AbstractRenderQueue(AbstractRenderQueue&&) noexcept = default;
|
||||
virtual ~AbstractRenderQueue();
|
||||
|
||||
// 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 AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) = 0;
|
||||
virtual void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) = 0;
|
||||
virtual void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) = 0;
|
||||
virtual void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) = 0;
|
||||
virtual void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) = 0;
|
||||
virtual void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) = 0;
|
||||
virtual void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) = 0;
|
||||
virtual void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) = 0;
|
||||
virtual void AddDrawable(int renderOrder, const Drawable* drawable) = 0;
|
||||
virtual void AddDirectionalLight(const DirectionalLight& light);
|
||||
virtual void AddMesh(int renderOrder, const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix, const Recti& scissorRect) = 0;
|
||||
virtual void AddPointLight(const PointLight& light);
|
||||
virtual void AddSpotLight(const SpotLight& light);
|
||||
virtual void AddSprites(int renderOrder, const Material* material, const VertexStruct_XYZ_Color_UV* vertices, std::size_t spriteCount, const Recti& scissorRect, const Texture* overlay = nullptr) = 0;
|
||||
|
||||
virtual void Clear(bool fully = false);
|
||||
|
||||
AbstractRenderQueue& operator=(const AbstractRenderQueue&) = delete;
|
||||
AbstractRenderQueue& operator=(AbstractRenderQueue&&) noexcept = default;
|
||||
|
||||
struct DirectionalLight
|
||||
{
|
||||
Color color;
|
||||
Matrix4f transformMatrix;
|
||||
Vector3f direction;
|
||||
Texture* shadowMap;
|
||||
float ambientFactor;
|
||||
float diffuseFactor;
|
||||
};
|
||||
|
||||
struct PointLight
|
||||
{
|
||||
Color color;
|
||||
Vector3f position;
|
||||
Texture* shadowMap;
|
||||
float ambientFactor;
|
||||
float attenuation;
|
||||
float diffuseFactor;
|
||||
float invRadius;
|
||||
float radius;
|
||||
};
|
||||
|
||||
struct SpotLight
|
||||
{
|
||||
Color color;
|
||||
Matrix4f transformMatrix;
|
||||
Vector3f direction;
|
||||
Vector3f position;
|
||||
Texture* shadowMap;
|
||||
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
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ABSTRACTRENDERTECHNIQUE_HPP
|
||||
#define NAZARA_ABSTRACTRENDERTECHNIQUE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractRenderQueue;
|
||||
struct SceneData;
|
||||
|
||||
class NAZARA_GRAPHICS_API AbstractRenderTechnique
|
||||
{
|
||||
public:
|
||||
AbstractRenderTechnique();
|
||||
AbstractRenderTechnique(const AbstractRenderTechnique&) = delete;
|
||||
AbstractRenderTechnique(AbstractRenderTechnique&&) noexcept = default;
|
||||
virtual ~AbstractRenderTechnique();
|
||||
|
||||
virtual void Clear(const SceneData& sceneData) const = 0;
|
||||
virtual bool Draw(const SceneData& sceneData) const = 0;
|
||||
|
||||
virtual void EnableInstancing(bool instancing);
|
||||
|
||||
virtual String GetName() const;
|
||||
virtual AbstractRenderQueue* GetRenderQueue() = 0;
|
||||
virtual RenderTechniqueType GetType() const = 0;
|
||||
|
||||
virtual bool IsInstancingEnabled() const;
|
||||
|
||||
AbstractRenderTechnique& operator=(const AbstractRenderTechnique&) = delete;
|
||||
AbstractRenderTechnique& operator=(AbstractRenderTechnique&&) noexcept = default;
|
||||
|
||||
protected:
|
||||
bool m_instancingEnabled;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_ABSTRACTRENDERTECHNIQUE_HPP
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ABSTRACTVIEWER_HPP
|
||||
#define NAZARA_ABSTRACTVIEWER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
#include <Nazara/Math/Frustum.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class RenderTarget;
|
||||
|
||||
class NAZARA_GRAPHICS_API AbstractViewer
|
||||
{
|
||||
public:
|
||||
AbstractViewer() = default;
|
||||
AbstractViewer(const AbstractViewer&) = default;
|
||||
AbstractViewer(AbstractViewer&&) noexcept = default;
|
||||
virtual ~AbstractViewer();
|
||||
|
||||
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 Nz::ProjectionType GetProjectionType() 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;
|
||||
|
||||
Nz::Vector3f Project(const Nz::Vector3f& worldPosition) const;
|
||||
float ProjectDepth(float depth);
|
||||
|
||||
Nz::Vector3f Unproject(const Nz::Vector3f& screenPos) const;
|
||||
|
||||
AbstractViewer& operator=(const AbstractViewer&) = default;
|
||||
AbstractViewer& operator=(AbstractViewer&&) noexcept = default;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_ABSTRACTVIEWER_HPP
|
||||
|
|
@ -1,142 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_BASICRENDERQUEUE_HPP
|
||||
#define NAZARA_BASICRENDERQUEUE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Graphics/RenderQueue.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Plane.hpp>
|
||||
#include <Nazara/Utility/IndexBuffer.hpp>
|
||||
#include <Nazara/Utility/MeshData.hpp>
|
||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractViewer;
|
||||
|
||||
class NAZARA_GRAPHICS_API BasicRenderQueue : public AbstractRenderQueue
|
||||
{
|
||||
friend class ForwardRenderTechnique;
|
||||
|
||||
public:
|
||||
struct BillboardData;
|
||||
|
||||
BasicRenderQueue() = default;
|
||||
~BasicRenderQueue() = default;
|
||||
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddDrawable(int renderOrder, const Drawable* drawable) override;
|
||||
void AddMesh(int renderOrder, const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix, const Recti& scissorRect) override;
|
||||
void AddSprites(int renderOrder, const Material* material, const VertexStruct_XYZ_Color_UV* vertices, std::size_t spriteCount, const Recti& scissorRect, const Texture* overlay = nullptr) override;
|
||||
|
||||
void Clear(bool fully = false) override;
|
||||
|
||||
inline const BillboardData* GetBillboardData(std::size_t billboardIndex) const;
|
||||
|
||||
void Sort(const AbstractViewer* viewer);
|
||||
|
||||
struct BillboardData
|
||||
{
|
||||
Color color;
|
||||
Vector3f center;
|
||||
Vector2f size;
|
||||
Vector2f sinCos;
|
||||
};
|
||||
|
||||
struct Billboard
|
||||
{
|
||||
int layerIndex;
|
||||
MovablePtr<const Nz::Material> material;
|
||||
Nz::Recti scissorRect;
|
||||
BillboardData data;
|
||||
};
|
||||
|
||||
struct BillboardChain
|
||||
{
|
||||
int layerIndex;
|
||||
MovablePtr<const Nz::Material> material;
|
||||
Nz::Recti scissorRect;
|
||||
std::size_t billboardCount;
|
||||
std::size_t billboardIndex;
|
||||
};
|
||||
|
||||
RenderQueue<BillboardChain> billboards;
|
||||
RenderQueue<Billboard> depthSortedBillboards;
|
||||
|
||||
struct CustomDrawable
|
||||
{
|
||||
int layerIndex;
|
||||
MovablePtr<const Drawable> drawable;
|
||||
};
|
||||
|
||||
RenderQueue<CustomDrawable> customDrawables;
|
||||
|
||||
struct Model
|
||||
{
|
||||
int layerIndex;
|
||||
MeshData meshData;
|
||||
MovablePtr<const Nz::Material> material;
|
||||
Nz::Matrix4f matrix;
|
||||
Nz::Recti scissorRect;
|
||||
Nz::Spheref obbSphere;
|
||||
};
|
||||
|
||||
RenderQueue<Model> models;
|
||||
RenderQueue<Model> depthSortedModels;
|
||||
|
||||
struct SpriteChain
|
||||
{
|
||||
int layerIndex;
|
||||
std::size_t spriteCount;
|
||||
MovablePtr<const Material> material;
|
||||
MovablePtr<const Texture> overlay;
|
||||
MovablePtr<const VertexStruct_XYZ_Color_UV> vertices;
|
||||
Nz::Recti scissorRect;
|
||||
};
|
||||
|
||||
RenderQueue<SpriteChain> basicSprites;
|
||||
RenderQueue<SpriteChain> depthSortedSprites;
|
||||
|
||||
private:
|
||||
inline Color ComputeColor(float alpha);
|
||||
inline Vector2f ComputeSinCos(float angle);
|
||||
inline Vector2f ComputeSize(float size);
|
||||
|
||||
inline void RegisterLayer(int layerIndex);
|
||||
|
||||
std::unordered_map<const MaterialPipeline*, std::size_t> m_pipelineCache;
|
||||
std::unordered_map<const Material*, std::size_t> m_materialCache;
|
||||
std::unordered_map<const Texture*, std::size_t> m_overlayCache;
|
||||
std::unordered_map<const UberShader*, std::size_t> m_shaderCache;
|
||||
std::unordered_map<const Texture*, std::size_t> m_textureCache;
|
||||
std::unordered_map<const VertexBuffer*, std::size_t> m_vertexBufferCache;
|
||||
std::unordered_map<int, std::size_t> m_layerCache;
|
||||
|
||||
std::vector<BillboardData> m_billboards;
|
||||
std::vector<int> m_renderLayers;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/BasicRenderQueue.inl>
|
||||
|
||||
#endif // NAZARA_BASICRENDERQUEUE_HPP
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/BasicRenderQueue.hpp>
|
||||
#include <cassert>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline const BasicRenderQueue::BillboardData* BasicRenderQueue::GetBillboardData(std::size_t billboardIndex) const
|
||||
{
|
||||
assert(billboardIndex < m_billboards.size());
|
||||
return &m_billboards[billboardIndex];
|
||||
}
|
||||
|
||||
inline Color BasicRenderQueue::ComputeColor(float alpha)
|
||||
{
|
||||
return Color(255, 255, 255, static_cast<UInt8>(255.f * alpha));
|
||||
}
|
||||
|
||||
inline Vector2f BasicRenderQueue::ComputeSinCos(float angle)
|
||||
{
|
||||
float radians = ToRadians(angle);
|
||||
return { std::sin(radians), std::cos(radians) };
|
||||
}
|
||||
|
||||
inline Vector2f BasicRenderQueue::ComputeSize(float size)
|
||||
{
|
||||
return Vector2f(size, size);
|
||||
}
|
||||
|
||||
inline void BasicRenderQueue::RegisterLayer(int layerIndex)
|
||||
{
|
||||
auto it = std::lower_bound(m_renderLayers.begin(), m_renderLayers.end(), layerIndex);
|
||||
if (it == m_renderLayers.end() || *it != layerIndex)
|
||||
m_renderLayers.insert(it, layerIndex);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_BILLBOARD_HPP
|
||||
#define NAZARA_BILLBOARD_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Billboard;
|
||||
|
||||
using BillboardConstRef = ObjectRef<const Billboard>;
|
||||
using BillboardLibrary = ObjectLibrary<Billboard>;
|
||||
using BillboardRef = ObjectRef<Billboard>;
|
||||
|
||||
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;
|
||||
|
||||
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override;
|
||||
|
||||
std::unique_ptr<InstancedRenderable> Clone() const override;
|
||||
|
||||
inline const Color& GetColor() const;
|
||||
inline const RadianAnglef& GetRotation() const;
|
||||
inline const Vector2f& GetSize() const;
|
||||
|
||||
inline void SetColor(const Color& color);
|
||||
inline void SetDefaultMaterial();
|
||||
inline void SetMaterial(MaterialRef material, bool resizeBillboard = true);
|
||||
inline void SetMaterial(std::size_t skinIndex, MaterialRef material, bool resizeBillboard = true);
|
||||
inline void SetRotation(const RadianAnglef& rotation);
|
||||
inline void SetSize(const Vector2f& size);
|
||||
inline void SetSize(float sizeX, float sizeY);
|
||||
inline void SetTexture(TextureRef texture, bool resizeBillboard = true);
|
||||
inline void SetTexture(std::size_t skinIndex, TextureRef texture, bool resizeBillboard = true);
|
||||
|
||||
inline Billboard& operator=(const Billboard& billboard);
|
||||
Billboard& operator=(Billboard&&) = delete;
|
||||
|
||||
template<typename... Args> static BillboardRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
void MakeBoundingVolume() const override;
|
||||
|
||||
Color m_color;
|
||||
Vector2f m_sinCos;
|
||||
Vector2f m_size;
|
||||
RadianAnglef m_rotation;
|
||||
|
||||
static BillboardLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/Billboard.inl>
|
||||
|
||||
#endif // NAZARA_BILLBOARD_HPP
|
||||
|
|
@ -1,272 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/Billboard.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a Billboard object by default
|
||||
*/
|
||||
|
||||
inline Billboard::Billboard()
|
||||
{
|
||||
ResetMaterials(1);
|
||||
|
||||
SetColor(Color::White);
|
||||
SetDefaultMaterial();
|
||||
SetRotation(0.f);
|
||||
SetSize(64.f, 64.f);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Billboard object with a reference to a material
|
||||
*
|
||||
* \param material Reference to a material
|
||||
*/
|
||||
|
||||
inline Billboard::Billboard(MaterialRef material)
|
||||
{
|
||||
ResetMaterials(1);
|
||||
|
||||
SetColor(Color::White);
|
||||
SetMaterial(std::move(material), true);
|
||||
SetRotation(0.f);
|
||||
SetSize(64.f, 64.f);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Billboard object with a pointer to a texture
|
||||
*
|
||||
* \param texture Pointer to a texture
|
||||
*/
|
||||
|
||||
inline Billboard::Billboard(Texture* texture)
|
||||
{
|
||||
ResetMaterials(1);
|
||||
|
||||
SetColor(Color::White);
|
||||
SetRotation(0.f);
|
||||
SetSize(64.f, 64.f);
|
||||
SetTexture(texture, true);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Billboard object by assignation
|
||||
*
|
||||
* \param billboard Billboard to copy into this
|
||||
*/
|
||||
|
||||
inline Billboard::Billboard(const Billboard& billboard) :
|
||||
InstancedRenderable(billboard),
|
||||
m_color(billboard.m_color),
|
||||
m_sinCos(billboard.m_sinCos),
|
||||
m_size(billboard.m_size),
|
||||
m_rotation(billboard.m_rotation)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the color of the billboard
|
||||
* \return Current color
|
||||
*/
|
||||
|
||||
inline const Color& Billboard::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the rotation of the billboard
|
||||
* \return Current rotation
|
||||
*/
|
||||
|
||||
inline const RadianAnglef& Billboard::GetRotation() const
|
||||
{
|
||||
return m_rotation;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the size of the billboard
|
||||
* \return Current size
|
||||
*/
|
||||
|
||||
inline const Vector2f& Billboard::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the color of the billboard
|
||||
*
|
||||
* \param color Color for the billboard
|
||||
*/
|
||||
|
||||
inline void Billboard::SetColor(const Color& color)
|
||||
{
|
||||
m_color = color;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the default material of the billboard (just default material)
|
||||
*/
|
||||
|
||||
inline void Billboard::SetDefaultMaterial()
|
||||
{
|
||||
MaterialRef material = Material::New();
|
||||
material->EnableFaceCulling(true);
|
||||
|
||||
SetMaterial(std::move(material));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the material of the billboard
|
||||
*
|
||||
* \param material Material for the billboard
|
||||
* \param resizeBillboard Should billboard be resized to the material size (diffuse map)
|
||||
*/
|
||||
inline void Billboard::SetMaterial(MaterialRef material, bool resizeBillboard)
|
||||
{
|
||||
SetMaterial(GetSkin(), std::move(material), resizeBillboard);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the material of the billboard
|
||||
*
|
||||
* \param skinIndex Skin index to change
|
||||
* \param material Material for the billboard
|
||||
* \param resizeBillboard Should billboard be resized to the material size (diffuse map)
|
||||
*/
|
||||
inline void Billboard::SetMaterial(std::size_t skinIndex, MaterialRef material, bool resizeBillboard)
|
||||
{
|
||||
InstancedRenderable::SetMaterial(skinIndex, 0, std::move(material));
|
||||
|
||||
if (resizeBillboard)
|
||||
{
|
||||
if (const MaterialRef& newMat = GetMaterial())
|
||||
{
|
||||
const TextureRef& diffuseMap = newMat->GetDiffuseMap();
|
||||
if (diffuseMap && diffuseMap->IsValid())
|
||||
SetSize(Vector2f(Vector2ui(diffuseMap->GetSize())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the rotation of the billboard
|
||||
*
|
||||
* \param rotation Rotation for the billboard
|
||||
*/
|
||||
|
||||
inline void Billboard::SetRotation(const RadianAnglef& rotation)
|
||||
{
|
||||
m_rotation = rotation;
|
||||
|
||||
auto sincos = rotation.GetSinCos();
|
||||
m_sinCos.Set(sincos.first, sincos.second);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the size of the billboard
|
||||
*
|
||||
* \param size Size for the billboard
|
||||
*/
|
||||
|
||||
inline void Billboard::SetSize(const Vector2f& size)
|
||||
{
|
||||
m_size = size;
|
||||
|
||||
// We invalidate the bounding volume
|
||||
InvalidateBoundingVolume();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the size of the billboard
|
||||
*
|
||||
* \param sizeX Size in X for the billboard
|
||||
* \param sizeY Size in Y for the billboard
|
||||
*/
|
||||
|
||||
inline void Billboard::SetSize(float sizeX, float sizeY)
|
||||
{
|
||||
SetSize(Vector2f(sizeX, sizeY));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the texture of the billboard
|
||||
*
|
||||
* \param texture Texture for the billboard
|
||||
* \param resizeBillboard Should billboard be resized to the texture size
|
||||
*/
|
||||
inline void Billboard::SetTexture(TextureRef texture, bool resizeBillboard)
|
||||
{
|
||||
SetTexture(GetSkin(), std::move(texture), resizeBillboard);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the texture of the billboard for a specific index
|
||||
*
|
||||
* This function changes the diffuse map of the material associated with the specified skin index
|
||||
*
|
||||
* \param skinIndex Skin index to change
|
||||
* \param texture Texture for the billboard
|
||||
* \param resizeBillboard Should billboard be resized to the texture size
|
||||
*/
|
||||
inline void Billboard::SetTexture(std::size_t skinIndex, TextureRef texture, bool resizeBillboard)
|
||||
{
|
||||
if (resizeBillboard && texture && texture->IsValid())
|
||||
SetSize(Vector2f(Vector2ui(texture->GetSize())));
|
||||
|
||||
const MaterialRef& material = GetMaterial(skinIndex);
|
||||
|
||||
if (material->GetReferenceCount() > 1)
|
||||
{
|
||||
MaterialRef newMat = Material::New(*material); // Copy
|
||||
newMat->SetDiffuseMap(std::move(texture));
|
||||
|
||||
SetMaterial(skinIndex, std::move(newMat));
|
||||
}
|
||||
else
|
||||
material->SetDiffuseMap(std::move(texture));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the current billboard with the content of the other one
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param billboard The other Billboard
|
||||
*/
|
||||
|
||||
inline Billboard& Billboard::operator=(const Billboard& billboard)
|
||||
{
|
||||
InstancedRenderable::operator=(billboard);
|
||||
|
||||
m_color = billboard.m_color;
|
||||
m_size = billboard.m_size;
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a new billboard from the arguments
|
||||
* \return A reference to the newly created billboard
|
||||
*
|
||||
* \param args Arguments for the billboard
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_COLORBACKGROUND_HPP
|
||||
#define NAZARA_COLORBACKGROUND_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||
#include <Nazara/Renderer/UberShader.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ColorBackground;
|
||||
|
||||
using ColorBackgroundConstRef = ObjectRef<const ColorBackground>;
|
||||
using ColorBackgroundRef = ObjectRef<ColorBackground>;
|
||||
|
||||
class NAZARA_GRAPHICS_API ColorBackground : public AbstractBackground
|
||||
{
|
||||
public:
|
||||
ColorBackground(const Color& color = Color::Black);
|
||||
ColorBackground(const ColorBackground&) = default;
|
||||
ColorBackground(ColorBackground&&) = delete;
|
||||
|
||||
void Draw(const AbstractViewer* viewer) const override;
|
||||
|
||||
BackgroundType GetBackgroundType() const override;
|
||||
Color GetColor() const;
|
||||
|
||||
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>
|
||||
|
||||
#endif // NAZARA_COLORBACKGROUND_HPP
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Creates a new color background from the arguments
|
||||
* \return A reference to the newly created color background
|
||||
*
|
||||
* \param args Arguments for the color background
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
Nazara Engine - Graphics module
|
||||
|
||||
Copyright (C) 2015 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CONFIG_GRAPHICS_HPP
|
||||
#define NAZARA_CONFIG_GRAPHICS_HPP
|
||||
|
||||
/*!
|
||||
* \defgroup graphics (NazaraGraphics) Graphics module
|
||||
* Graphics/System module including classes to handle graphical elements...
|
||||
*/
|
||||
|
||||
/// Each modification of a paramater of the module needs a recompilation of the unit
|
||||
|
||||
// How much instances are need of a same mesh/material to enable instancing ?
|
||||
#define NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT 10
|
||||
|
||||
// Use the MemoryManager to manage dynamic allocations (can detect memory leak but allocations/frees are slower)
|
||||
#define NAZARA_GRAPHICS_MANAGE_MEMORY 0
|
||||
|
||||
// Activate the security tests based on the code (Advised for development)
|
||||
#define NAZARA_GRAPHICS_SAFE 1
|
||||
|
||||
/// Each modification of a parameter following implies a modification (often minor) of the code
|
||||
|
||||
// The maximum number of lights in a standard shader
|
||||
#define NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS 3
|
||||
|
||||
/// Checking the values and types of certain constants
|
||||
#include <Nazara/Graphics/ConfigCheck.hpp>
|
||||
|
||||
#if defined(NAZARA_STATIC)
|
||||
#define NAZARA_GRAPHICS_API
|
||||
#else
|
||||
#ifdef NAZARA_GRAPHICS_BUILD
|
||||
#define NAZARA_GRAPHICS_API NAZARA_EXPORT
|
||||
#else
|
||||
#define NAZARA_GRAPHICS_API NAZARA_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_CONFIG_GRAPHICS_HPP
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CONFIG_CHECK_GRAPHICS_HPP
|
||||
#define NAZARA_CONFIG_CHECK_GRAPHICS_HPP
|
||||
|
||||
/// This file is used to check the constant values defined in Config.hpp
|
||||
|
||||
#include <type_traits>
|
||||
#define NazaraCheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err)
|
||||
|
||||
// We force the value of MANAGE_MEMORY in debug
|
||||
#if defined(NAZARA_DEBUG) && !NAZARA_GRAPHICS_MANAGE_MEMORY
|
||||
#undef NAZARA_GRAPHICS_MANAGE_MEMORY
|
||||
#define NAZARA_GRAPHICS_MANAGE_MEMORY 0
|
||||
#endif
|
||||
|
||||
NazaraCheckTypeAndVal(NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT, integral, >, 0, " shall be a strictly positive integer");
|
||||
NazaraCheckTypeAndVal(NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS, integral, >, 0, " shall be a strictly positive integer");
|
||||
|
||||
#undef NazaraCheckTypeAndVal
|
||||
|
||||
#endif // NAZARA_CONFIG_CHECK_GRAPHICS_HPP
|
||||
|
|
@ -1,215 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CULLINGLIST_HPP
|
||||
#define NAZARA_CULLINGLIST_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
#include <Nazara/Math/BoundingVolume.hpp>
|
||||
#include <Nazara/Math/Frustum.hpp>
|
||||
#include <Nazara/Math/Sphere.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename T>
|
||||
class CullingList
|
||||
{
|
||||
public:
|
||||
template<CullTest> class Entry;
|
||||
class BoxEntry;
|
||||
class NoTestEntry;
|
||||
class SphereEntry;
|
||||
class VolumeEntry;
|
||||
|
||||
template<CullTest> friend class Entry;
|
||||
friend BoxEntry;
|
||||
friend NoTestEntry;
|
||||
friend SphereEntry;
|
||||
friend VolumeEntry;
|
||||
|
||||
using ResultContainer = std::vector<const T*>;
|
||||
|
||||
CullingList() = default;
|
||||
CullingList(const CullingList& renderable) = delete;
|
||||
CullingList(CullingList&& renderable) = delete;
|
||||
~CullingList();
|
||||
|
||||
std::size_t Cull(const Frustumf& frustum, bool* forceInvalidation = nullptr);
|
||||
|
||||
std::size_t FillWithAllEntries(bool* forceInvalidation = nullptr);
|
||||
|
||||
const ResultContainer& GetFullyVisibleResults() const;
|
||||
const ResultContainer& GetPartiallyVisibleResults() const;
|
||||
|
||||
BoxEntry RegisterBoxTest(const T* renderable);
|
||||
NoTestEntry RegisterNoTest(const T* renderable);
|
||||
SphereEntry RegisterSphereTest(const T* renderable);
|
||||
VolumeEntry RegisterVolumeTest(const T* renderable);
|
||||
|
||||
CullingList& operator=(const CullingList& renderable) = delete;
|
||||
CullingList& operator=(CullingList&& renderable) = delete;
|
||||
|
||||
NazaraSignal(OnCullingListRelease, CullingList* /*cullingList*/);
|
||||
|
||||
private:
|
||||
inline void NotifyBoxUpdate(std::size_t index, const Boxf& boundingVolume);
|
||||
inline void NotifyForceInvalidation(CullTest type, std::size_t index);
|
||||
inline void NotifyMovement(CullTest type, std::size_t index, void* oldPtr, void* newPtr);
|
||||
inline void NotifyRelease(CullTest type, std::size_t index);
|
||||
inline void NotifySphereUpdate(std::size_t index, const Spheref& sphere);
|
||||
inline void NotifyVolumeUpdate(std::size_t index, const BoundingVolumef& boundingVolume);
|
||||
|
||||
struct BoxVisibilityEntry
|
||||
{
|
||||
Boxf box;
|
||||
BoxEntry* entry;
|
||||
const T* renderable;
|
||||
bool forceInvalidation;
|
||||
};
|
||||
|
||||
struct NoTestVisibilityEntry
|
||||
{
|
||||
NoTestEntry* entry;
|
||||
const T* renderable;
|
||||
bool forceInvalidation;
|
||||
};
|
||||
|
||||
struct SphereVisibilityEntry
|
||||
{
|
||||
Spheref sphere;
|
||||
SphereEntry* entry;
|
||||
const T* renderable;
|
||||
bool forceInvalidation;
|
||||
};
|
||||
|
||||
struct VolumeVisibilityEntry
|
||||
{
|
||||
BoundingVolumef volume;
|
||||
VolumeEntry* entry;
|
||||
const T* renderable;
|
||||
bool forceInvalidation;
|
||||
};
|
||||
|
||||
std::vector<BoxVisibilityEntry> m_boxTestList;
|
||||
std::vector<NoTestVisibilityEntry> m_noTestList;
|
||||
std::vector<SphereVisibilityEntry> m_sphereTestList;
|
||||
std::vector<VolumeVisibilityEntry> m_volumeTestList;
|
||||
ResultContainer m_fullyVisibleResults;
|
||||
ResultContainer m_partiallyVisibleResults;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
template<CullTest Type>
|
||||
class CullingList<T>::Entry
|
||||
{
|
||||
public:
|
||||
Entry();
|
||||
Entry(const Entry&) = delete;
|
||||
Entry(Entry&& entry);
|
||||
~Entry();
|
||||
|
||||
void ForceInvalidation();
|
||||
|
||||
CullingList* GetParent() const;
|
||||
|
||||
void UpdateIndex(std::size_t index);
|
||||
|
||||
Entry& operator=(const Entry&) = delete;
|
||||
Entry& operator=(Entry&& entry);
|
||||
|
||||
protected:
|
||||
Entry(CullingList* parent, std::size_t index);
|
||||
|
||||
std::size_t m_index;
|
||||
CullingList* m_parent;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class CullingList<T>::BoxEntry : public CullingList<T>::template Entry<CullTest::Box>
|
||||
{
|
||||
friend CullingList;
|
||||
|
||||
using ParentType = Entry<CullTest::Box>;
|
||||
|
||||
public:
|
||||
BoxEntry();
|
||||
BoxEntry(BoxEntry&&) = default;
|
||||
~BoxEntry() = default;
|
||||
|
||||
void UpdateBox(const Boxf& box);
|
||||
|
||||
BoxEntry& operator=(BoxEntry&&) = default;
|
||||
|
||||
private:
|
||||
BoxEntry(CullingList* parent, std::size_t index);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class CullingList<T>::NoTestEntry : public CullingList<T>::template Entry<CullTest::NoTest>
|
||||
{
|
||||
friend CullingList;
|
||||
|
||||
using ParentType = Entry<CullTest::NoTest>;
|
||||
|
||||
public:
|
||||
NoTestEntry();
|
||||
NoTestEntry(NoTestEntry&&) = default;
|
||||
~NoTestEntry() = default;
|
||||
|
||||
NoTestEntry& operator=(NoTestEntry&&) = default;
|
||||
|
||||
private:
|
||||
NoTestEntry(CullingList* parent, std::size_t index);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class CullingList<T>::SphereEntry : public CullingList<T>::template Entry<CullTest::Sphere>
|
||||
{
|
||||
friend CullingList;
|
||||
|
||||
using ParentType = Entry<CullTest::Sphere>;
|
||||
|
||||
public:
|
||||
SphereEntry();
|
||||
SphereEntry(SphereEntry&&) = default;
|
||||
~SphereEntry() = default;
|
||||
|
||||
void UpdateSphere(const Spheref& sphere);
|
||||
|
||||
SphereEntry& operator=(SphereEntry&&) = default;
|
||||
|
||||
private:
|
||||
SphereEntry(CullingList* parent, std::size_t index);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class CullingList<T>::VolumeEntry : public CullingList<T>::template Entry<CullTest::Volume>
|
||||
{
|
||||
friend CullingList;
|
||||
|
||||
using ParentType = Entry<CullTest::Volume>;
|
||||
|
||||
public:
|
||||
VolumeEntry();
|
||||
VolumeEntry(VolumeEntry&&) = default;
|
||||
~VolumeEntry() = default;
|
||||
|
||||
void UpdateVolume(const BoundingVolumef& sphere);
|
||||
|
||||
VolumeEntry& operator=(VolumeEntry&&) = default;
|
||||
|
||||
private:
|
||||
VolumeEntry(CullingList* parent, std::size_t index);
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/CullingList.inl>
|
||||
|
||||
#endif // NAZARA_CULLINGLIST_HPP
|
||||
|
|
@ -1,498 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/CullingList.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename T>
|
||||
CullingList<T>::~CullingList()
|
||||
{
|
||||
OnCullingListRelease(this);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::size_t CullingList<T>::Cull(const Frustumf& frustum, bool* forceInvalidation)
|
||||
{
|
||||
m_fullyVisibleResults.clear();
|
||||
m_partiallyVisibleResults.clear();
|
||||
|
||||
bool forcedInvalidation = false;
|
||||
|
||||
std::size_t fullyVisibleHash = 5U;
|
||||
std::size_t partiallyVisibleHash = 5U;
|
||||
|
||||
auto CombineHash = [](std::size_t currentHash, std::size_t newHash)
|
||||
{
|
||||
return currentHash * 23 + newHash;
|
||||
};
|
||||
|
||||
for (BoxVisibilityEntry& entry : m_boxTestList)
|
||||
{
|
||||
switch (frustum.Intersect(entry.box))
|
||||
{
|
||||
case IntersectionSide_Inside:
|
||||
m_fullyVisibleResults.push_back(entry.renderable);
|
||||
fullyVisibleHash = CombineHash(fullyVisibleHash, std::hash<const T*>()(entry.renderable));
|
||||
|
||||
forcedInvalidation = forcedInvalidation | entry.forceInvalidation;
|
||||
entry.forceInvalidation = false;
|
||||
break;
|
||||
|
||||
case IntersectionSide_Intersecting:
|
||||
m_partiallyVisibleResults.push_back(entry.renderable);
|
||||
partiallyVisibleHash = CombineHash(partiallyVisibleHash, std::hash<const T*>()(entry.renderable));
|
||||
|
||||
forcedInvalidation = forcedInvalidation | entry.forceInvalidation;
|
||||
entry.forceInvalidation = false;
|
||||
break;
|
||||
|
||||
case IntersectionSide_Outside:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (NoTestVisibilityEntry& entry : m_noTestList)
|
||||
{
|
||||
m_fullyVisibleResults.push_back(entry.renderable);
|
||||
CombineHash(fullyVisibleHash, std::hash<const T*>()(entry.renderable));
|
||||
|
||||
if (entry.forceInvalidation)
|
||||
{
|
||||
forcedInvalidation = true;
|
||||
entry.forceInvalidation = false;
|
||||
}
|
||||
}
|
||||
|
||||
for (SphereVisibilityEntry& entry : m_sphereTestList)
|
||||
{
|
||||
switch (frustum.Intersect(entry.sphere))
|
||||
{
|
||||
case IntersectionSide_Inside:
|
||||
m_fullyVisibleResults.push_back(entry.renderable);
|
||||
fullyVisibleHash = CombineHash(fullyVisibleHash, std::hash<const T*>()(entry.renderable));
|
||||
|
||||
forcedInvalidation = forcedInvalidation | entry.forceInvalidation;
|
||||
entry.forceInvalidation = false;
|
||||
break;
|
||||
|
||||
case IntersectionSide_Intersecting:
|
||||
m_partiallyVisibleResults.push_back(entry.renderable);
|
||||
partiallyVisibleHash = CombineHash(partiallyVisibleHash, std::hash<const T*>()(entry.renderable));
|
||||
|
||||
forcedInvalidation = forcedInvalidation | entry.forceInvalidation;
|
||||
entry.forceInvalidation = false;
|
||||
break;
|
||||
|
||||
case IntersectionSide_Outside:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (VolumeVisibilityEntry& entry : m_volumeTestList)
|
||||
{
|
||||
switch (frustum.Intersect(entry.volume))
|
||||
{
|
||||
case IntersectionSide_Inside:
|
||||
m_fullyVisibleResults.push_back(entry.renderable);
|
||||
fullyVisibleHash = CombineHash(fullyVisibleHash, std::hash<const T*>()(entry.renderable));
|
||||
|
||||
forcedInvalidation = forcedInvalidation | entry.forceInvalidation;
|
||||
entry.forceInvalidation = false;
|
||||
break;
|
||||
|
||||
case IntersectionSide_Intersecting:
|
||||
m_partiallyVisibleResults.push_back(entry.renderable);
|
||||
partiallyVisibleHash = CombineHash(partiallyVisibleHash, std::hash<const T*>()(entry.renderable));
|
||||
|
||||
forcedInvalidation = forcedInvalidation | entry.forceInvalidation;
|
||||
entry.forceInvalidation = false;
|
||||
break;
|
||||
|
||||
case IntersectionSide_Outside:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (forceInvalidation)
|
||||
*forceInvalidation = forcedInvalidation;
|
||||
|
||||
return 5 + partiallyVisibleHash * 17 + fullyVisibleHash;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::size_t CullingList<T>::FillWithAllEntries(bool* forceInvalidation)
|
||||
{
|
||||
m_fullyVisibleResults.clear();
|
||||
m_partiallyVisibleResults.clear();
|
||||
|
||||
bool forcedInvalidation = false;
|
||||
|
||||
std::size_t visibleHash = 5U;
|
||||
|
||||
auto FillWithList = [&](auto& testList)
|
||||
{
|
||||
for (auto& entry : testList)
|
||||
{
|
||||
m_fullyVisibleResults.push_back(entry.renderable);
|
||||
visibleHash = visibleHash * 23 + std::hash<const T*>()(entry.renderable);
|
||||
|
||||
forcedInvalidation = forcedInvalidation | entry.forceInvalidation;
|
||||
entry.forceInvalidation = false;
|
||||
}
|
||||
};
|
||||
|
||||
FillWithList(m_boxTestList);
|
||||
FillWithList(m_noTestList);
|
||||
FillWithList(m_sphereTestList);
|
||||
FillWithList(m_volumeTestList);
|
||||
|
||||
if (forceInvalidation)
|
||||
*forceInvalidation = forcedInvalidation;
|
||||
|
||||
return visibleHash;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto CullingList<T>::GetFullyVisibleResults() const -> const ResultContainer&
|
||||
{
|
||||
return m_fullyVisibleResults;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto CullingList<T>::GetPartiallyVisibleResults() const -> const ResultContainer&
|
||||
{
|
||||
return m_partiallyVisibleResults;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto CullingList<T>::RegisterBoxTest(const T* renderable) -> BoxEntry
|
||||
{
|
||||
BoxEntry newEntry(this, m_boxTestList.size());
|
||||
m_boxTestList.emplace_back(BoxVisibilityEntry{ Nz::Boxf(), &newEntry, renderable, false }); //< Address of entry will be updated when moving
|
||||
|
||||
return newEntry;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto CullingList<T>::RegisterNoTest(const T* renderable) -> NoTestEntry
|
||||
{
|
||||
NoTestEntry newEntry(this, m_volumeTestList.size());
|
||||
m_noTestList.emplace_back(NoTestVisibilityEntry{&newEntry, renderable, false}); //< Address of entry will be updated when moving
|
||||
|
||||
return newEntry;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto CullingList<T>::RegisterSphereTest(const T* renderable) -> SphereEntry
|
||||
{
|
||||
SphereEntry newEntry(this, m_sphereTestList.size());
|
||||
m_sphereTestList.emplace_back(SphereVisibilityEntry{Nz::Spheref(), &newEntry, renderable, false}); //< Address of entry will be updated when moving
|
||||
|
||||
return newEntry;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto CullingList<T>::RegisterVolumeTest(const T* renderable) -> VolumeEntry
|
||||
{
|
||||
VolumeEntry newEntry(this, m_volumeTestList.size());
|
||||
m_volumeTestList.emplace_back(VolumeVisibilityEntry{Nz::BoundingVolumef(), &newEntry, renderable, false}); //< Address of entry will be updated when moving
|
||||
|
||||
return newEntry;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void CullingList<T>::NotifyBoxUpdate(std::size_t index, const Boxf& box)
|
||||
{
|
||||
m_boxTestList[index].box = box;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CullingList<T>::NotifyForceInvalidation(CullTest type, std::size_t index)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case CullTest::Box:
|
||||
{
|
||||
m_boxTestList[index].forceInvalidation = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case CullTest::NoTest:
|
||||
{
|
||||
m_noTestList[index].forceInvalidation = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case CullTest::Sphere:
|
||||
{
|
||||
m_sphereTestList[index].forceInvalidation = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case CullTest::Volume:
|
||||
{
|
||||
m_volumeTestList[index].forceInvalidation = true;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
NazaraInternalError("Unhandled culltype");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CullingList<T>::NotifyMovement(CullTest type, std::size_t index, void* oldPtr, void* newPtr)
|
||||
{
|
||||
NazaraUnused(oldPtr);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case CullTest::Box:
|
||||
{
|
||||
BoxVisibilityEntry& entry = m_boxTestList[index];
|
||||
NazaraAssert(entry.entry == oldPtr, "Invalid box entry");
|
||||
|
||||
entry.entry = static_cast<BoxEntry*>(newPtr);
|
||||
break;
|
||||
}
|
||||
|
||||
case CullTest::NoTest:
|
||||
{
|
||||
NoTestVisibilityEntry& entry = m_noTestList[index];
|
||||
NazaraAssert(entry.entry == oldPtr, "Invalid entry");
|
||||
|
||||
entry.entry = static_cast<NoTestEntry*>(newPtr);
|
||||
break;
|
||||
}
|
||||
|
||||
case CullTest::Sphere:
|
||||
{
|
||||
SphereVisibilityEntry& entry = m_sphereTestList[index];
|
||||
NazaraAssert(entry.entry == oldPtr, "Invalid sphere entry");
|
||||
|
||||
entry.entry = static_cast<SphereEntry*>(newPtr);
|
||||
break;
|
||||
}
|
||||
|
||||
case CullTest::Volume:
|
||||
{
|
||||
VolumeVisibilityEntry& entry = m_volumeTestList[index];
|
||||
NazaraAssert(entry.entry == oldPtr, "Invalid volume entry");
|
||||
|
||||
entry.entry = static_cast<VolumeEntry*>(newPtr);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
NazaraInternalError("Unhandled culltype");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CullingList<T>::NotifyRelease(CullTest type, std::size_t index)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case CullTest::Box:
|
||||
{
|
||||
m_boxTestList[index] = std::move(m_boxTestList.back());
|
||||
m_boxTestList[index].entry->UpdateIndex(index);
|
||||
m_boxTestList.pop_back();
|
||||
break;
|
||||
}
|
||||
|
||||
case CullTest::NoTest:
|
||||
{
|
||||
m_noTestList[index] = std::move(m_noTestList.back());
|
||||
m_noTestList[index].entry->UpdateIndex(index);
|
||||
m_noTestList.pop_back();
|
||||
break;
|
||||
}
|
||||
|
||||
case CullTest::Sphere:
|
||||
{
|
||||
m_sphereTestList[index] = std::move(m_sphereTestList.back());
|
||||
m_sphereTestList[index].entry->UpdateIndex(index);
|
||||
m_sphereTestList.pop_back();
|
||||
break;
|
||||
}
|
||||
|
||||
case CullTest::Volume:
|
||||
{
|
||||
m_volumeTestList[index] = std::move(m_volumeTestList.back());
|
||||
m_volumeTestList[index].entry->UpdateIndex(index);
|
||||
m_volumeTestList.pop_back();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
NazaraInternalError("Unhandled culltype");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CullingList<T>::NotifySphereUpdate(std::size_t index, const Spheref& sphere)
|
||||
{
|
||||
m_sphereTestList[index].sphere = sphere;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CullingList<T>::NotifyVolumeUpdate(std::size_t index, const BoundingVolumef& boundingVolume)
|
||||
{
|
||||
m_volumeTestList[index].volume = boundingVolume;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename T>
|
||||
template<CullTest Type>
|
||||
CullingList<T>::Entry<Type>::Entry() :
|
||||
m_parent(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<CullTest Type>
|
||||
CullingList<T>::Entry<Type>::Entry(CullingList* parent, std::size_t index) :
|
||||
m_index(index),
|
||||
m_parent(parent)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<CullTest Type>
|
||||
CullingList<T>::Entry<Type>::Entry(Entry&& entry) :
|
||||
m_index(entry.m_index),
|
||||
m_parent(entry.m_parent)
|
||||
{
|
||||
if (m_parent)
|
||||
m_parent->NotifyMovement(Type, m_index, &entry, this);
|
||||
|
||||
entry.m_parent = nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<CullTest Type>
|
||||
CullingList<T>::Entry<Type>::~Entry()
|
||||
{
|
||||
if (m_parent)
|
||||
m_parent->NotifyRelease(Type, m_index);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<CullTest Type>
|
||||
void CullingList<T>::Entry<Type>::ForceInvalidation()
|
||||
{
|
||||
m_parent->NotifyForceInvalidation(Type, m_index);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<CullTest Type>
|
||||
CullingList<T>* CullingList<T>::Entry<Type>::GetParent() const
|
||||
{
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<CullTest Type>
|
||||
void CullingList<T>::Entry<Type>::UpdateIndex(std::size_t index)
|
||||
{
|
||||
m_index = index;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<CullTest Type>
|
||||
typename CullingList<T>::template Entry<Type>& CullingList<T>::Entry<Type>::operator=(Entry&& entry)
|
||||
{
|
||||
m_index = entry.m_index;
|
||||
m_parent = entry.m_parent;
|
||||
if (m_parent)
|
||||
m_parent->NotifyMovement(Type, m_index, &entry, this);
|
||||
|
||||
entry.m_parent = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename T>
|
||||
CullingList<T>::BoxEntry::BoxEntry() :
|
||||
ParentType()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
CullingList<T>::BoxEntry::BoxEntry(CullingList* parent, std::size_t index) :
|
||||
ParentType(parent, index)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CullingList<T>::BoxEntry::UpdateBox(const Boxf& box)
|
||||
{
|
||||
this->m_parent->NotifyBoxUpdate(this->m_index, box);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename T>
|
||||
CullingList<T>::NoTestEntry::NoTestEntry() :
|
||||
ParentType()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
CullingList<T>::NoTestEntry::NoTestEntry(CullingList* parent, std::size_t index) :
|
||||
ParentType(parent, index)
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename T>
|
||||
CullingList<T>::SphereEntry::SphereEntry() :
|
||||
ParentType()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
CullingList<T>::SphereEntry::SphereEntry(CullingList* parent, std::size_t index) :
|
||||
ParentType(parent, index)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CullingList<T>::SphereEntry::UpdateSphere(const Spheref& sphere)
|
||||
{
|
||||
this->m_parent->NotifySphereUpdate(this->m_index, sphere);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename T>
|
||||
CullingList<T>::VolumeEntry::VolumeEntry() :
|
||||
ParentType()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
CullingList<T>::VolumeEntry::VolumeEntry(CullingList* parent, std::size_t index) :
|
||||
ParentType(parent, index)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CullingList<T>::VolumeEntry::UpdateVolume(const BoundingVolumef& volume)
|
||||
{
|
||||
this->m_parent->NotifyVolumeUpdate(this->m_index, volume);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#if NAZARA_GRAPHICS_MANAGE_MEMORY
|
||||
#include <Nazara/Core/Debug/NewRedefinition.hpp>
|
||||
#endif
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// We suppose that Debug.hpp is already included, same goes for Config.hpp
|
||||
#if NAZARA_GRAPHICS_MANAGE_MEMORY
|
||||
#undef delete
|
||||
#undef new
|
||||
#endif
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DEFERREDBLOOMPASS_HPP
|
||||
#define NAZARA_DEFERREDBLOOMPASS_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
||||
#include <Nazara/Renderer/RenderStates.hpp>
|
||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_GRAPHICS_API DeferredBloomPass : public DeferredRenderPass
|
||||
{
|
||||
public:
|
||||
DeferredBloomPass();
|
||||
virtual ~DeferredBloomPass();
|
||||
|
||||
unsigned int GetBlurPassCount() const;
|
||||
float GetBrightLuminance() const;
|
||||
float GetBrightMiddleGrey() const;
|
||||
float GetBrightThreshold() const;
|
||||
Texture* GetTexture(unsigned int i) const;
|
||||
|
||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override;
|
||||
bool Resize(const Vector2ui& dimensions) override;
|
||||
|
||||
void SetBlurPassCount(unsigned int passCount);
|
||||
void SetBrightLuminance(float luminance);
|
||||
void SetBrightMiddleGrey(float middleGrey);
|
||||
void SetBrightThreshold(float threshold);
|
||||
|
||||
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
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DEFERREDDOFPASS_HPP
|
||||
#define NAZARA_DEFERREDDOFPASS_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
||||
#include <Nazara/Renderer/RenderStates.hpp>
|
||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_GRAPHICS_API DeferredDOFPass : public DeferredRenderPass
|
||||
{
|
||||
public:
|
||||
DeferredDOFPass();
|
||||
virtual ~DeferredDOFPass();
|
||||
|
||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override;
|
||||
bool Resize(const Vector2ui& dimensions) override;
|
||||
|
||||
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
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DEFERREDFXAAPASS_HPP
|
||||
#define NAZARA_DEFERREDFXAAPASS_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
||||
#include <Nazara/Renderer/RenderStates.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_GRAPHICS_API DeferredFXAAPass : public DeferredRenderPass
|
||||
{
|
||||
public:
|
||||
DeferredFXAAPass();
|
||||
virtual ~DeferredFXAAPass();
|
||||
|
||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override;
|
||||
|
||||
protected:
|
||||
RenderStates m_states;
|
||||
ShaderRef m_fxaaShader;
|
||||
TextureSampler m_pointSampler;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DEFERREDFXAAPASS_HPP
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DEFERREDFINALPASS_HPP
|
||||
#define NAZARA_DEFERREDFINALPASS_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
||||
#include <Nazara/Renderer/RenderStates.hpp>
|
||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||
#include <Nazara/Renderer/UberShader.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_GRAPHICS_API DeferredFinalPass : public DeferredRenderPass
|
||||
{
|
||||
public:
|
||||
DeferredFinalPass();
|
||||
virtual ~DeferredFinalPass();
|
||||
|
||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override;
|
||||
|
||||
protected:
|
||||
RenderStates m_states;
|
||||
TextureSampler m_pointSampler;
|
||||
UberShaderConstRef m_uberShader;
|
||||
const UberShaderInstance* m_uberShaderInstance;
|
||||
int m_materialDiffuseUniform;
|
||||
int m_materialDiffuseMapUniform;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DEFERREDFINALPASS_HPP
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DEFERREDFOGPASS_HPP
|
||||
#define NAZARA_DEFERREDFOGPASS_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
||||
#include <Nazara/Renderer/RenderStates.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_GRAPHICS_API DeferredFogPass : public DeferredRenderPass
|
||||
{
|
||||
public:
|
||||
DeferredFogPass();
|
||||
virtual ~DeferredFogPass();
|
||||
|
||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override;
|
||||
|
||||
protected:
|
||||
RenderStates m_states;
|
||||
ShaderRef m_shader;
|
||||
TextureSampler m_pointSampler;
|
||||
int m_shaderEyePositionLocation;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DEFERREDFOGPASS_HPP
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DEFERREDFORWARDPASS_HPP
|
||||
#define NAZARA_DEFERREDFORWARDPASS_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ForwardRenderTechnique;
|
||||
|
||||
class NAZARA_GRAPHICS_API DeferredForwardPass : public DeferredRenderPass
|
||||
{
|
||||
public:
|
||||
DeferredForwardPass();
|
||||
virtual ~DeferredForwardPass();
|
||||
|
||||
void Initialize(DeferredRenderTechnique* technique) override;
|
||||
bool Process(const SceneData& sceneData, unsigned int workTexture, unsigned int sceneTexture) const override;
|
||||
|
||||
protected:
|
||||
const ForwardRenderTechnique* m_forwardTechnique;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DEFERREDFORWARDPASS_HPP
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DEFERREDGEOMETRYPASS_HPP
|
||||
#define NAZARA_DEFERREDGEOMETRYPASS_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/BasicRenderQueue.hpp>
|
||||
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
||||
#include <Nazara/Renderer/RenderStates.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_GRAPHICS_API DeferredGeometryPass : public DeferredRenderPass
|
||||
{
|
||||
friend class DeferredRenderTechnique;
|
||||
|
||||
public:
|
||||
DeferredGeometryPass();
|
||||
virtual ~DeferredGeometryPass();
|
||||
|
||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override;
|
||||
bool Resize(const Vector2ui& dimensions) override;
|
||||
|
||||
protected:
|
||||
struct ShaderUniforms;
|
||||
|
||||
void DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue<BasicRenderQueue::Billboard>& billboards) const;
|
||||
void DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue<BasicRenderQueue::BillboardChain>& billboards) const;
|
||||
void DrawModels(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue<BasicRenderQueue::Model>& models) const;
|
||||
void DrawSprites(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue<BasicRenderQueue::SpriteChain>& sprites) const;
|
||||
|
||||
const ShaderUniforms* GetShaderUniforms(const Shader* shader) const;
|
||||
void OnShaderInvalidated(const Shader* shader) const;
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
struct ShaderUniforms
|
||||
{
|
||||
NazaraSlot(Shader, OnShaderUniformInvalidated, shaderUniformInvalidatedSlot);
|
||||
NazaraSlot(Shader, OnShaderRelease, shaderReleaseSlot);
|
||||
|
||||
int eyePosition;
|
||||
int sceneAmbient;
|
||||
int textureOverlay;
|
||||
};
|
||||
|
||||
struct SpriteBatch
|
||||
{
|
||||
std::size_t spriteCount;
|
||||
const Material* material;
|
||||
const Texture* overlayTexture;
|
||||
Recti scissorRect;
|
||||
};
|
||||
|
||||
mutable std::unordered_map<const Shader*, ShaderUniforms> m_shaderUniforms;
|
||||
mutable std::vector<SpriteBatch> m_spriteBatches;
|
||||
Buffer m_vertexBuffer;
|
||||
RenderStates m_clearStates;
|
||||
ShaderRef m_clearShader;
|
||||
TextureRef m_whiteTexture;
|
||||
VertexBuffer m_billboardPointBuffer;
|
||||
VertexBuffer m_spriteBuffer;
|
||||
|
||||
static IndexBuffer s_quadIndexBuffer;
|
||||
static VertexBuffer s_quadVertexBuffer;
|
||||
static VertexDeclaration s_billboardInstanceDeclaration;
|
||||
static VertexDeclaration s_billboardVertexDeclaration;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DEFERREDGEOMETRYPASS_HPP
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DEFERREDPHONGLIGHTINGPASS_HPP
|
||||
#define NAZARA_DEFERREDPHONGLIGHTINGPASS_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
||||
#include <Nazara/Graphics/Light.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class StaticMesh;
|
||||
|
||||
class NAZARA_GRAPHICS_API DeferredPhongLightingPass : public DeferredRenderPass
|
||||
{
|
||||
public:
|
||||
DeferredPhongLightingPass();
|
||||
virtual ~DeferredPhongLightingPass();
|
||||
|
||||
void EnableLightMeshesDrawing(bool enable);
|
||||
|
||||
bool IsLightMeshesDrawingEnabled() const;
|
||||
|
||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override;
|
||||
|
||||
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
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DEFERREDRENDERQUEUE_HPP
|
||||
#define NAZARA_DEFERREDRENDERQUEUE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/BasicRenderQueue.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Utility/IndexBuffer.hpp>
|
||||
#include <Nazara/Utility/MeshData.hpp>
|
||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class BasicRenderQueue;
|
||||
|
||||
class NAZARA_GRAPHICS_API DeferredProxyRenderQueue final : public AbstractRenderQueue
|
||||
{
|
||||
public:
|
||||
struct BillboardData;
|
||||
|
||||
inline DeferredProxyRenderQueue(BasicRenderQueue* deferredQueue, BasicRenderQueue* forwardQueue);
|
||||
~DeferredProxyRenderQueue() = default;
|
||||
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddDrawable(int renderOrder, const Drawable* drawable) override;
|
||||
void AddMesh(int renderOrder, const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix, const Recti& scissorRect) override;
|
||||
void AddSprites(int renderOrder, const Material* material, const VertexStruct_XYZ_Color_UV* vertices, std::size_t spriteCount, const Recti& scissorRect, const Texture* overlay = nullptr) override;
|
||||
|
||||
void Clear(bool fully = false) override;
|
||||
|
||||
inline BasicRenderQueue* GetDeferredRenderQueue();
|
||||
inline BasicRenderQueue* GetForwardRenderQueue();
|
||||
|
||||
private:
|
||||
BasicRenderQueue * m_deferredRenderQueue;
|
||||
BasicRenderQueue* m_forwardRenderQueue;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DeferredProxyRenderQueue.inl>
|
||||
|
||||
#endif // NAZARA_DEFERREDRENDERQUEUE_HPP
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/DeferredProxyRenderQueue.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a DeferredProxyRenderQueue using a deferred and a forward queues
|
||||
*
|
||||
* \param deferredQueue Deferred queue which will be used for non-blended objects
|
||||
* \param forwardQueue Forward queue which will be used for blended objects
|
||||
*/
|
||||
inline DeferredProxyRenderQueue::DeferredProxyRenderQueue(BasicRenderQueue* deferredQueue, BasicRenderQueue* forwardQueue) :
|
||||
m_deferredRenderQueue(deferredQueue),
|
||||
m_forwardRenderQueue(forwardQueue)
|
||||
{
|
||||
}
|
||||
|
||||
inline BasicRenderQueue* DeferredProxyRenderQueue::GetDeferredRenderQueue()
|
||||
{
|
||||
return m_deferredRenderQueue;
|
||||
}
|
||||
|
||||
inline BasicRenderQueue* DeferredProxyRenderQueue::GetForwardRenderQueue()
|
||||
{
|
||||
return m_forwardRenderQueue;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DEFERREDRENDERPASS_HPP
|
||||
#define NAZARA_DEFERREDRENDERPASS_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class DeferredRenderTechnique;
|
||||
class DeferredProxyRenderQueue;
|
||||
class RenderTexture;
|
||||
class Texture;
|
||||
struct SceneData;
|
||||
|
||||
class NAZARA_GRAPHICS_API DeferredRenderPass
|
||||
{
|
||||
friend DeferredRenderTechnique;
|
||||
|
||||
public:
|
||||
DeferredRenderPass();
|
||||
DeferredRenderPass(const DeferredRenderPass&) = delete;
|
||||
virtual ~DeferredRenderPass();
|
||||
|
||||
void Enable(bool enable);
|
||||
|
||||
virtual void Initialize(DeferredRenderTechnique* technique);
|
||||
|
||||
bool IsEnabled() const;
|
||||
|
||||
virtual bool Process(const SceneData& sceneData, unsigned int workTexture, unsigned int sceneTexture) const = 0;
|
||||
virtual bool Resize(const Vector2ui& GBufferSize);
|
||||
|
||||
DeferredRenderPass& operator=(const DeferredRenderPass&) = delete;
|
||||
|
||||
protected:
|
||||
Vector2ui m_dimensions;
|
||||
DeferredRenderTechnique* m_deferredTechnique;
|
||||
DeferredProxyRenderQueue* m_renderQueue;
|
||||
RenderTexture* m_GBufferRTT;
|
||||
RenderTexture* m_workRTT;
|
||||
Texture* m_depthStencilTexture;
|
||||
Texture* m_GBuffer[4];
|
||||
Texture* m_workTextures[2];
|
||||
|
||||
private:
|
||||
bool m_enabled;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DEFERREDRENDERPASS_HPP
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DEFERREDRENDERTECHNIQUE_HPP
|
||||
#define NAZARA_DEFERREDRENDERTECHNIQUE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
|
||||
#include <Nazara/Graphics/DeferredProxyRenderQueue.hpp>
|
||||
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class DeferredRenderPass;
|
||||
|
||||
class NAZARA_GRAPHICS_API DeferredRenderTechnique : public AbstractRenderTechnique
|
||||
{
|
||||
friend class Graphics;
|
||||
|
||||
public:
|
||||
DeferredRenderTechnique();
|
||||
~DeferredRenderTechnique();
|
||||
|
||||
void Clear(const SceneData& sceneData) const override;
|
||||
bool Draw(const SceneData& sceneData) const override;
|
||||
|
||||
void EnablePass(RenderPassType renderPass, int position, bool enable);
|
||||
|
||||
Texture* GetDepthStencilTexture() 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(RenderPassType renderPass, int position);
|
||||
|
||||
DeferredRenderPass* ResetPass(RenderPassType renderPass, int position);
|
||||
|
||||
void SetPass(RenderPassType relativeTo, int position, DeferredRenderPass* pass);
|
||||
|
||||
static bool IsSupported();
|
||||
|
||||
private:
|
||||
bool Resize(const Vector2ui& dimensions) const;
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
struct RenderPassComparator
|
||||
{
|
||||
bool operator()(RenderPassType pass1, RenderPassType pass2) const;
|
||||
};
|
||||
|
||||
std::map<RenderPassType, std::map<int, std::unique_ptr<DeferredRenderPass>>, RenderPassComparator> m_passes;
|
||||
BasicRenderQueue m_deferredRenderQueue; // Must be initialized before the ProxyRenderQueue
|
||||
ForwardRenderTechnique m_forwardTechnique; // Must be initialized before the ProxyRenderQueue
|
||||
DeferredProxyRenderQueue m_renderQueue;
|
||||
mutable TextureRef m_depthStencilTexture;
|
||||
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
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DEPTHRENDERQUEUE_HPP
|
||||
#define NAZARA_DEPTHRENDERQUEUE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/BasicRenderQueue.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_GRAPHICS_API DepthRenderQueue : public BasicRenderQueue
|
||||
{
|
||||
public:
|
||||
DepthRenderQueue();
|
||||
~DepthRenderQueue() = default;
|
||||
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t count, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t count, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t count, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t count, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t count, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t count, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t count, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
|
||||
void AddBillboards(int renderOrder, const Material* material, std::size_t count, const Recti& scissorRect, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) override;
|
||||
void AddDirectionalLight(const DirectionalLight& light) override;
|
||||
void AddMesh(int renderOrder, const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix, const Recti& scissorRect) override;
|
||||
void AddPointLight(const PointLight& light) override;
|
||||
void AddSpotLight(const SpotLight& light) override;
|
||||
void AddSprites(int renderOrder, const Material* material, const VertexStruct_XYZ_Color_UV* vertices, std::size_t spriteCount, const Recti& scissorRect, const Texture* overlay = nullptr) override;
|
||||
|
||||
private:
|
||||
inline bool IsMaterialSuitable(const Material* material) const;
|
||||
|
||||
MaterialRef m_baseMaterial;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DepthRenderQueue.inl>
|
||||
|
||||
#endif // NAZARA_DEPTHRENDERQUEUE_HPP
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the material is suitable to fit in the render queue
|
||||
* \return true If it is the case
|
||||
*
|
||||
* \param material Material to verify
|
||||
*/
|
||||
|
||||
bool DepthRenderQueue::IsMaterialSuitable(const Material* material) const
|
||||
{
|
||||
NazaraAssert(material, "Invalid material");
|
||||
|
||||
return material->HasDepthMaterial() || (material->IsDepthBufferEnabled() && material->IsDepthWriteEnabled() && material->IsShadowCastingEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DEPTHRENDERTECHNIQUE_HPP
|
||||
#define NAZARA_DEPTHRENDERTECHNIQUE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/DepthRenderQueue.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Utility/IndexBuffer.hpp>
|
||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_GRAPHICS_API DepthRenderTechnique : public AbstractRenderTechnique
|
||||
{
|
||||
public:
|
||||
DepthRenderTechnique();
|
||||
~DepthRenderTechnique() = default;
|
||||
|
||||
void Clear(const SceneData& sceneData) const override;
|
||||
bool Draw(const SceneData& sceneData) const override;
|
||||
|
||||
AbstractRenderQueue* GetRenderQueue() override;
|
||||
RenderTechniqueType GetType() const override;
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
struct ShaderUniforms;
|
||||
|
||||
void DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue<BasicRenderQueue::Billboard>& billboards) const;
|
||||
void DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue<BasicRenderQueue::BillboardChain>& billboards) const;
|
||||
void DrawCustomDrawables(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue<BasicRenderQueue::CustomDrawable>& customDrawables) const;
|
||||
void DrawModels(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue<BasicRenderQueue::Model>& models) const;
|
||||
void DrawSprites(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue<BasicRenderQueue::SpriteChain>& sprites) const;
|
||||
|
||||
const ShaderUniforms* GetShaderUniforms(const Shader* shader) const;
|
||||
void OnShaderInvalidated(const Shader* shader) const;
|
||||
|
||||
struct LightIndex
|
||||
{
|
||||
LightType type;
|
||||
float score;
|
||||
unsigned int index;
|
||||
};
|
||||
|
||||
struct ShaderUniforms
|
||||
{
|
||||
NazaraSlot(Shader, OnShaderUniformInvalidated, shaderUniformInvalidatedSlot);
|
||||
NazaraSlot(Shader, OnShaderRelease, shaderReleaseSlot);
|
||||
|
||||
// Autre uniformes
|
||||
int sceneAmbient;
|
||||
int textureOverlay;
|
||||
};
|
||||
|
||||
struct SpriteBatch
|
||||
{
|
||||
std::size_t spriteCount;
|
||||
const Material* material;
|
||||
const Texture* overlayTexture;
|
||||
Recti scissorRect;
|
||||
};
|
||||
|
||||
mutable std::unordered_map<const Shader*, ShaderUniforms> m_shaderUniforms;
|
||||
mutable std::vector<SpriteBatch> m_spriteBatches;
|
||||
Buffer m_vertexBuffer;
|
||||
RenderStates m_clearStates;
|
||||
ShaderRef m_clearShader;
|
||||
TextureRef m_whiteTexture;
|
||||
VertexBuffer m_billboardPointBuffer;
|
||||
VertexBuffer m_spriteBuffer;
|
||||
mutable DepthRenderQueue m_renderQueue;
|
||||
|
||||
static IndexBuffer s_quadIndexBuffer;
|
||||
static VertexBuffer s_quadVertexBuffer;
|
||||
static VertexDeclaration s_billboardInstanceDeclaration;
|
||||
static VertexDeclaration s_billboardVertexDeclaration;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#include <Nazara/Graphics/DepthRenderTechnique.inl>
|
||||
|
||||
#endif // NAZARA_DEPTHRENDERTECHNIQUE_HPP
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DRAWABLE_HPP
|
||||
#define NAZARA_DRAWABLE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_GRAPHICS_API Drawable
|
||||
{
|
||||
public:
|
||||
Drawable() = default;
|
||||
virtual ~Drawable();
|
||||
|
||||
virtual void Draw() const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DRAWABLE_HPP
|
||||
|
|
@ -1,183 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ENUMS_GRAPHICS_HPP
|
||||
#define NAZARA_ENUMS_GRAPHICS_HPP
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
enum BackgroundType
|
||||
{
|
||||
BackgroundType_Color, // ColorBackground
|
||||
BackgroundType_Skybox, // SkyboxBackground
|
||||
BackgroundType_Texture, // TextureBackground
|
||||
BackgroundType_User,
|
||||
|
||||
BackgroundType_Max = BackgroundType_User
|
||||
};
|
||||
|
||||
enum class CullTest
|
||||
{
|
||||
Box,
|
||||
NoTest,
|
||||
Sphere,
|
||||
Volume
|
||||
};
|
||||
|
||||
enum ProjectionType
|
||||
{
|
||||
ProjectionType_Orthogonal,
|
||||
ProjectionType_Perspective,
|
||||
|
||||
ProjectionType_Max = ProjectionType_Perspective
|
||||
};
|
||||
|
||||
enum LightType
|
||||
{
|
||||
LightType_Directional,
|
||||
LightType_Point,
|
||||
LightType_Spot,
|
||||
|
||||
LightType_Max = LightType_Spot
|
||||
};
|
||||
|
||||
enum MaterialUniform
|
||||
{
|
||||
MaterialUniform_AlphaMap,
|
||||
MaterialUniform_AlphaThreshold,
|
||||
MaterialUniform_Ambient,
|
||||
MaterialUniform_Diffuse,
|
||||
MaterialUniform_DiffuseMap,
|
||||
MaterialUniform_EmissiveMap,
|
||||
MaterialUniform_HeightMap,
|
||||
MaterialUniform_NormalMap,
|
||||
MaterialUniform_Shininess,
|
||||
MaterialUniform_Specular,
|
||||
MaterialUniform_SpecularMap,
|
||||
|
||||
MaterialUniform_Max = MaterialUniform_SpecularMap
|
||||
};
|
||||
|
||||
enum ParticleComponent
|
||||
{
|
||||
ParticleComponent_Unused = -1,
|
||||
|
||||
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,
|
||||
|
||||
ParticleComponent_Max = ParticleComponent_Userdata8
|
||||
};
|
||||
|
||||
enum ParticleLayout
|
||||
{
|
||||
ParticleLayout_Billboard,
|
||||
ParticleLayout_Model,
|
||||
ParticleLayout_Sprite,
|
||||
|
||||
ParticleLayout_Max = ParticleLayout_Sprite
|
||||
};
|
||||
|
||||
enum RenderPassType
|
||||
{
|
||||
RenderPassType_AA,
|
||||
RenderPassType_Bloom,
|
||||
RenderPassType_DOF,
|
||||
RenderPassType_Final,
|
||||
RenderPassType_Fog,
|
||||
RenderPassType_Forward,
|
||||
RenderPassType_Lighting,
|
||||
RenderPassType_Geometry,
|
||||
RenderPassType_SSAO,
|
||||
|
||||
RenderPassType_Max = RenderPassType_SSAO
|
||||
};
|
||||
|
||||
enum RenderTechniqueType
|
||||
{
|
||||
RenderTechniqueType_AdvancedForward, // AdvancedForwardRenderTechnique
|
||||
RenderTechniqueType_BasicForward, // BasicForwardRenderTechnique
|
||||
RenderTechniqueType_DeferredShading, // DeferredRenderTechnique
|
||||
RenderTechniqueType_Depth, // DepthRenderTechnique
|
||||
RenderTechniqueType_LightPrePass, // LightPrePassRenderTechnique
|
||||
RenderTechniqueType_User,
|
||||
|
||||
RenderTechniqueType_Max = RenderTechniqueType_User
|
||||
};
|
||||
|
||||
enum ReflectionMode
|
||||
{
|
||||
ReflectionMode_RealTime,
|
||||
ReflectionMode_Probe,
|
||||
ReflectionMode_Skybox,
|
||||
|
||||
ReflectionMode_Max = ReflectionMode_Skybox
|
||||
};
|
||||
|
||||
enum SceneNodeType
|
||||
{
|
||||
SceneNodeType_Light, // Light
|
||||
SceneNodeType_Model, // Model
|
||||
SceneNodeType_ParticleEmitter, // ParticleEmitter
|
||||
SceneNodeType_Root, // SceneRoot
|
||||
SceneNodeType_Sprite, // Sprite
|
||||
SceneNodeType_TextSprite, // TextSprite
|
||||
SceneNodeType_User,
|
||||
|
||||
SceneNodeType_Max = SceneNodeType_User
|
||||
};
|
||||
|
||||
// These parameters are independant of the material: they can not be asked for the moment
|
||||
enum ShaderFlags
|
||||
{
|
||||
ShaderFlags_None = 0,
|
||||
|
||||
ShaderFlags_Billboard = 0x01,
|
||||
ShaderFlags_Deferred = 0x02,
|
||||
ShaderFlags_Instancing = 0x04,
|
||||
ShaderFlags_TextureOverlay = 0x08,
|
||||
ShaderFlags_VertexColor = 0x10,
|
||||
|
||||
ShaderFlags_Max = ShaderFlags_VertexColor * 2 - 1
|
||||
};
|
||||
|
||||
enum TextureMap
|
||||
{
|
||||
TextureMap_Alpha,
|
||||
TextureMap_Diffuse,
|
||||
TextureMap_Emissive,
|
||||
TextureMap_Height,
|
||||
TextureMap_ReflectionCube,
|
||||
TextureMap_Normal,
|
||||
TextureMap_Overlay,
|
||||
TextureMap_Shadow2D_1,
|
||||
TextureMap_Shadow2D_2,
|
||||
TextureMap_Shadow2D_3,
|
||||
TextureMap_ShadowCube_1,
|
||||
TextureMap_ShadowCube_2,
|
||||
TextureMap_ShadowCube_3,
|
||||
TextureMap_Specular,
|
||||
|
||||
TextureMap_Max = TextureMap_Specular
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_ENUMS_GRAPHICS_HPP
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_FORWARDRENDERTECHNIQUE_HPP
|
||||
#define NAZARA_FORWARDRENDERTECHNIQUE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/BasicRenderQueue.hpp>
|
||||
#include <Nazara/Graphics/Light.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Utility/IndexBuffer.hpp>
|
||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_GRAPHICS_API ForwardRenderTechnique : public AbstractRenderTechnique
|
||||
{
|
||||
public:
|
||||
ForwardRenderTechnique();
|
||||
~ForwardRenderTechnique() = default;
|
||||
|
||||
void Clear(const SceneData& sceneData) const override;
|
||||
bool Draw(const SceneData& sceneData) const override;
|
||||
|
||||
unsigned int GetMaxLightPassPerObject() const;
|
||||
AbstractRenderQueue* GetRenderQueue() override;
|
||||
RenderTechniqueType GetType() const override;
|
||||
|
||||
void SetMaxLightPassPerObject(unsigned int maxLightPassPerObject);
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
protected:
|
||||
struct ShaderUniforms;
|
||||
|
||||
void ChooseLights(const Spheref& object, bool includeDirectionalLights = true) const;
|
||||
void DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue<BasicRenderQueue::Billboard>& billboards) const;
|
||||
void DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue<BasicRenderQueue::BillboardChain>& billboards) const;
|
||||
void DrawCustomDrawables(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue<BasicRenderQueue::CustomDrawable>& customDrawables) const;
|
||||
void DrawModels(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue<BasicRenderQueue::Model>& models) const;
|
||||
void DrawSprites(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue<BasicRenderQueue::SpriteChain>& sprites) 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 lightIndex, unsigned int uniformOffset) const;
|
||||
|
||||
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
|
||||
{
|
||||
LightType type;
|
||||
float score;
|
||||
unsigned int index;
|
||||
};
|
||||
|
||||
struct ShaderUniforms
|
||||
{
|
||||
NazaraSlot(Shader, OnShaderUniformInvalidated, shaderUniformInvalidatedSlot);
|
||||
NazaraSlot(Shader, OnShaderRelease, shaderReleaseSlot);
|
||||
|
||||
LightUniforms lightUniforms;
|
||||
bool hasLightUniforms;
|
||||
|
||||
/// Less costly in memory than storing a LightUniforms by index of light,
|
||||
/// this may not work everywhere
|
||||
int lightOffset; // "Distance" between Lights[0].type and Lights[1].type
|
||||
|
||||
// Other uniforms
|
||||
int eyePosition;
|
||||
int reflectionMap;
|
||||
int sceneAmbient;
|
||||
int textureOverlay;
|
||||
};
|
||||
|
||||
struct SpriteBatch
|
||||
{
|
||||
std::size_t spriteCount;
|
||||
const Material* material;
|
||||
const Texture* overlayTexture;
|
||||
Recti scissorRect;
|
||||
};
|
||||
|
||||
mutable std::unordered_map<const Shader*, ShaderUniforms> m_shaderUniforms;
|
||||
mutable std::vector<LightIndex> m_lights;
|
||||
mutable std::vector<SpriteBatch> m_spriteBatches;
|
||||
Buffer m_vertexBuffer;
|
||||
mutable BasicRenderQueue m_renderQueue;
|
||||
TextureRef m_whiteCubemap;
|
||||
TextureRef m_whiteTexture;
|
||||
VertexBuffer m_billboardPointBuffer;
|
||||
VertexBuffer m_spriteBuffer;
|
||||
unsigned int m_maxLightPassPerObject;
|
||||
|
||||
static IndexBuffer s_quadIndexBuffer;
|
||||
static TextureSampler s_reflectionSampler;
|
||||
static TextureSampler s_shadowSampler;
|
||||
static VertexBuffer s_quadVertexBuffer;
|
||||
static VertexDeclaration s_billboardInstanceDeclaration;
|
||||
static VertexDeclaration s_billboardVertexDeclaration;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/ForwardRenderTechnique.inl>
|
||||
|
||||
#endif // NAZARA_FORWARDRENDERTECHNIQUE_HPP
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Computes the score for directional light
|
||||
* \return 0.f
|
||||
*
|
||||
* \param object Sphere symbolising the object
|
||||
* \param light Light to compute
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Computes the score for point light
|
||||
* \return Distance to the light
|
||||
*
|
||||
* \param object Sphere symbolising the object
|
||||
* \param light Light to compute
|
||||
*/
|
||||
|
||||
inline float ForwardRenderTechnique::ComputePointLightScore(const Spheref& object, const AbstractRenderQueue::PointLight& light)
|
||||
{
|
||||
///TODO: Compute a score depending on the light luminosity
|
||||
return object.GetPosition().SquaredDistance(light.position);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Computes the score for spot light
|
||||
* \return Distance to the light
|
||||
*
|
||||
* \param object Sphere symbolising the object
|
||||
* \param light Light to compute
|
||||
*/
|
||||
|
||||
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.GetPosition().SquaredDistance(light.position);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the directional light is suitable for the computations
|
||||
* \return true if light is enoughly close
|
||||
*
|
||||
* \param object Sphere symbolising the object
|
||||
* \param light Light to compute
|
||||
*/
|
||||
|
||||
inline bool ForwardRenderTechnique::IsDirectionalLightSuitable(const Spheref& object, const AbstractRenderQueue::DirectionalLight& light)
|
||||
{
|
||||
NazaraUnused(object);
|
||||
NazaraUnused(light);
|
||||
|
||||
// Directional light are always suitable
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the point light is suitable for the computations
|
||||
* \return true if light is close enough
|
||||
*
|
||||
* \param object Sphere symbolizing the object
|
||||
* \param light Light to compute
|
||||
*/
|
||||
|
||||
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.Intersect(Spheref(light.position, light.radius));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the spot light is suitable for the computations
|
||||
* \return true if light is close enough
|
||||
*
|
||||
* \param object Sphere symbolizing the object
|
||||
* \param light Light to compute
|
||||
*/
|
||||
|
||||
inline bool ForwardRenderTechnique::IsSpotLightSuitable(const Spheref& object, const AbstractRenderQueue::SpotLight& light)
|
||||
{
|
||||
///TODO: Exclude spot lights based on their direction and outer angle?
|
||||
return object.Intersect(Spheref(light.position, light.radius));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GRAPHICS_HPP
|
||||
#define NAZARA_GRAPHICS_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_GRAPHICS_API Graphics
|
||||
{
|
||||
public:
|
||||
Graphics() = delete;
|
||||
~Graphics() = delete;
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_GRAPHICS_HPP
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GUILLOTINETEXTUREATLAS_HPP
|
||||
#define NAZARA_GUILLOTINETEXTUREATLAS_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Utility/GuillotineImageAtlas.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_GRAPHICS_API GuillotineTextureAtlas : public GuillotineImageAtlas
|
||||
{
|
||||
public:
|
||||
GuillotineTextureAtlas() = default;
|
||||
~GuillotineTextureAtlas() = default;
|
||||
|
||||
UInt32 GetStorage() const override;
|
||||
|
||||
private:
|
||||
AbstractImage* ResizeImage(AbstractImage* oldImage, const Vector2ui& size) const override;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_GUILLOTINETEXTUREATLAS_HPP
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_INSTANCEDRENDERABLE_HPP
|
||||
#define NAZARA_INSTANCEDRENDERABLE_HPP
|
||||
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/CullingList.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Math/BoundingVolume.hpp>
|
||||
#include <Nazara/Math/Frustum.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractRenderQueue;
|
||||
class InstancedRenderable;
|
||||
|
||||
using InstancedRenderableConstRef = ObjectRef<const InstancedRenderable>;
|
||||
using InstancedRenderableLibrary = ObjectLibrary<InstancedRenderable>;
|
||||
using InstancedRenderableRef = ObjectRef<InstancedRenderable>;
|
||||
|
||||
class NAZARA_GRAPHICS_API InstancedRenderable : public RefCounted
|
||||
{
|
||||
public:
|
||||
struct InstanceData;
|
||||
|
||||
inline InstancedRenderable();
|
||||
inline InstancedRenderable(const InstancedRenderable& renderable);
|
||||
InstancedRenderable(InstancedRenderable&& renderable) = delete;
|
||||
virtual ~InstancedRenderable();
|
||||
|
||||
virtual void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const = 0;
|
||||
|
||||
virtual std::unique_ptr<InstancedRenderable> Clone() const = 0;
|
||||
|
||||
virtual bool Cull(const Frustumf& frustum, const InstanceData& instanceData) const;
|
||||
|
||||
inline void EnsureBoundingVolumeUpdated() const;
|
||||
|
||||
virtual const BoundingVolumef& GetBoundingVolume() const;
|
||||
|
||||
inline const MaterialRef& GetMaterial(std::size_t matIndex = 0) const;
|
||||
inline const MaterialRef& GetMaterial(std::size_t skinIndex, std::size_t matIndex) const;
|
||||
inline std::size_t GetMaterialCount() const;
|
||||
inline std::size_t GetSkin() const;
|
||||
inline std::size_t GetSkinCount() const;
|
||||
|
||||
virtual void InvalidateData(InstanceData* instanceData, UInt32 flags) const;
|
||||
|
||||
inline void SetMaterial(std::size_t matIndex, MaterialRef material);
|
||||
inline void SetMaterial(std::size_t skinIndex, std::size_t matIndex, MaterialRef material);
|
||||
inline void SetSkin(std::size_t skinIndex);
|
||||
inline void SetSkinCount(std::size_t skinCount);
|
||||
|
||||
virtual void UpdateBoundingVolume(InstanceData* instanceData) const;
|
||||
virtual void UpdateData(InstanceData* instanceData) const;
|
||||
|
||||
inline InstancedRenderable& operator=(const InstancedRenderable& renderable);
|
||||
InstancedRenderable& operator=(InstancedRenderable&& renderable) = delete;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnInstancedRenderableInvalidateBoundingVolume, const InstancedRenderable* /*instancedRenderable*/);
|
||||
NazaraSignal(OnInstancedRenderableInvalidateData, const InstancedRenderable* /*instancedRenderable*/, UInt32 /*flags*/);
|
||||
NazaraSignal(OnInstancedRenderableInvalidateMaterial, const InstancedRenderable* /*instancedRenderable*/, std::size_t /*skinIndex*/, std::size_t /*matIndex*/, const MaterialRef& /*newMat*/);
|
||||
NazaraSignal(OnInstancedRenderableRelease, const InstancedRenderable* /*instancedRenderable*/);
|
||||
NazaraSignal(OnInstancedRenderableResetMaterials, const InstancedRenderable* /*instancedRenderable*/, std::size_t /*newMaterialCount*/);
|
||||
NazaraSignal(OnInstancedRenderableSkinChange, const InstancedRenderable* /*instancedRenderable*/, std::size_t /*newSkinIndex*/);
|
||||
|
||||
struct InstanceData
|
||||
{
|
||||
InstanceData(const Matrix4f& transformationMatrix) :
|
||||
localMatrix(transformationMatrix),
|
||||
flags(0)
|
||||
{
|
||||
}
|
||||
|
||||
InstanceData(InstanceData&& instanceData) noexcept = default;
|
||||
|
||||
InstanceData& operator=(InstanceData&& instanceData) noexcept
|
||||
{
|
||||
data = std::move(instanceData.data);
|
||||
flags = instanceData.flags;
|
||||
renderOrder = instanceData.renderOrder;
|
||||
localMatrix = instanceData.localMatrix;
|
||||
transformMatrix = instanceData.transformMatrix;
|
||||
volume = instanceData.volume;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::vector<UInt8> data;
|
||||
BoundingVolumef volume;
|
||||
Matrix4f localMatrix;
|
||||
mutable Matrix4f transformMatrix;
|
||||
UInt32 flags;
|
||||
int renderOrder;
|
||||
};
|
||||
|
||||
protected:
|
||||
inline void InvalidateBoundingVolume();
|
||||
inline void InvalidateInstanceData(UInt32 flags);
|
||||
|
||||
virtual void MakeBoundingVolume() const = 0;
|
||||
|
||||
inline void ResetMaterials(std::size_t matCount, std::size_t skinCount = 1);
|
||||
|
||||
mutable BoundingVolumef m_boundingVolume;
|
||||
|
||||
private:
|
||||
inline void UpdateBoundingVolume() const;
|
||||
|
||||
std::size_t m_matCount;
|
||||
std::size_t m_skin;
|
||||
std::size_t m_skinCount;
|
||||
std::vector<MaterialRef> m_materials;
|
||||
mutable bool m_boundingVolumeUpdated;
|
||||
|
||||
static InstancedRenderableLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/InstancedRenderable.inl>
|
||||
|
||||
#endif // NAZARA_INSTANCEDRENDERABLE_HPP
|
||||
|
|
@ -1,280 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a InstancedRenderable object by default
|
||||
*/
|
||||
inline InstancedRenderable::InstancedRenderable() :
|
||||
m_boundingVolumeUpdated(false)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a InstancedRenderable object by assignation
|
||||
*
|
||||
* \param renderable InstancedRenderable to copy into this
|
||||
*/
|
||||
inline InstancedRenderable::InstancedRenderable(const InstancedRenderable& renderable) :
|
||||
RefCounted(),
|
||||
m_boundingVolume(renderable.m_boundingVolume),
|
||||
m_matCount(renderable.m_matCount),
|
||||
m_skin(renderable.m_skin),
|
||||
m_skinCount(renderable.m_skinCount),
|
||||
m_materials(renderable.m_materials),
|
||||
m_boundingVolumeUpdated(renderable.m_boundingVolumeUpdated)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Ensures that the bounding volume is up to date
|
||||
*/
|
||||
|
||||
inline void InstancedRenderable::EnsureBoundingVolumeUpdated() const
|
||||
{
|
||||
if (!m_boundingVolumeUpdated)
|
||||
UpdateBoundingVolume();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets one of the material used by the object.
|
||||
* \return A reference to the material.
|
||||
*
|
||||
* This function returns the active material at the specified index, depending on the current active skin.
|
||||
*
|
||||
* \param matIndex Material index to query
|
||||
*
|
||||
* \see GetSkin, GetMaterialCount, SetSkin
|
||||
*/
|
||||
inline const MaterialRef& InstancedRenderable::GetMaterial(std::size_t matIndex) const
|
||||
{
|
||||
return GetMaterial(m_skin, matIndex);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets one of the material used by the object, independently from the active skin.
|
||||
* \return A reference to the material.
|
||||
*
|
||||
* This function returns the active material at the specified index and the specified skin index.
|
||||
* This function is the only way to query a material independently from the active skin.
|
||||
*
|
||||
* \param skinIndex Skin index to query
|
||||
* \param matIndex Material index to query
|
||||
*
|
||||
* \see GetSkinCount, GetMaterialCount, SetSkin
|
||||
*/
|
||||
inline const MaterialRef& InstancedRenderable::GetMaterial(std::size_t skinIndex, std::size_t matIndex) const
|
||||
{
|
||||
NazaraAssert(skinIndex < m_skinCount, "Skin index out of bounds");
|
||||
NazaraAssert(matIndex < m_materials.size(), "Material index out of bounds");
|
||||
|
||||
return m_materials[m_matCount * skinIndex + matIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the number of material per skin.
|
||||
* \return The current material count per skin
|
||||
*
|
||||
* This function returns how many different materials entries exists per skin
|
||||
* and is independent from the number of skin.
|
||||
*/
|
||||
inline std::size_t InstancedRenderable::GetMaterialCount() const
|
||||
{
|
||||
return m_matCount;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the current active skin index
|
||||
* \return Current skin index
|
||||
*
|
||||
* \see SetSkin
|
||||
*/
|
||||
inline std::size_t InstancedRenderable::GetSkin() const
|
||||
{
|
||||
return m_skin;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the number of skins this object has
|
||||
* \return Skin count
|
||||
*
|
||||
* \see GetSkin, SetSkinCount
|
||||
*/
|
||||
inline std::size_t InstancedRenderable::GetSkinCount() const
|
||||
{
|
||||
return m_skinCount;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Changes the material used at the specified index by another one
|
||||
*
|
||||
* This function changes the active material at the specified index, depending on the current active skin, to the one passed as parameter.
|
||||
*
|
||||
* \param matIndex Material index
|
||||
* \param material New material, cannot be null
|
||||
*
|
||||
* \remark If you wish to reset the material to the default one, use the default material (see Material::GetDefault)
|
||||
*
|
||||
* \see SetMaterial
|
||||
*/
|
||||
inline void InstancedRenderable::SetMaterial(std::size_t matIndex, MaterialRef material)
|
||||
{
|
||||
SetMaterial(m_skin, matIndex, std::move(material));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Changes the material used at the specified index by another one, independently from the active skin.
|
||||
*
|
||||
* This function changes the active material at the specified index and for the specified skin index, to the one passed as parameter.
|
||||
*
|
||||
* \param skinIndex Skin index
|
||||
* \param matIndex Material index
|
||||
* \param material New material, cannot be null
|
||||
*
|
||||
* \remark If you wish to reset the material to the default one, use the default material (see Material::GetDefault)
|
||||
*
|
||||
* \see SetMaterial
|
||||
*/
|
||||
inline void InstancedRenderable::SetMaterial(std::size_t skinIndex, std::size_t matIndex, MaterialRef material)
|
||||
{
|
||||
NazaraAssert(skinIndex < m_skinCount, "Skin index out of bounds");
|
||||
NazaraAssert(matIndex < m_materials.size(), "Material index out of bounds");
|
||||
NazaraAssert(material.IsValid(), "Material must be valid");
|
||||
|
||||
MaterialRef& matEntry = m_materials[m_matCount * skinIndex + matIndex];
|
||||
if (matEntry != material)
|
||||
{
|
||||
OnInstancedRenderableInvalidateMaterial(this, skinIndex, matIndex, material);
|
||||
|
||||
matEntry = std::move(material);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Changes the active skin
|
||||
*
|
||||
* Each InstancedRenderable has the possibility to have multiples skins, which are sets of materials.
|
||||
* Using this function allows you to have an object reference multiple materials, while using only some of thems (depending on the type of the object, see GetMaterialCount).
|
||||
*
|
||||
* \param skinIndex Skin index to change to
|
||||
*
|
||||
* \see SetSkinCount
|
||||
*/
|
||||
inline void InstancedRenderable::SetSkin(std::size_t skinIndex)
|
||||
{
|
||||
NazaraAssert(skinIndex < m_skinCount, "Skin index out of bounds");
|
||||
|
||||
if (m_skin != skinIndex)
|
||||
{
|
||||
OnInstancedRenderableSkinChange(this, skinIndex);
|
||||
|
||||
m_skin = skinIndex;
|
||||
|
||||
// Force render queue invalidation
|
||||
InvalidateInstanceData(0);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Changes the maximum skin count of the object
|
||||
*
|
||||
* This functions allows the object to store up to skinCount skins, which can then be switched to using SetSkin.
|
||||
* Please note that the possibly new skins will be set to the default material, which should not be changed.
|
||||
*
|
||||
* \param skinCount Skin index to change to
|
||||
*
|
||||
* \see SetSkin
|
||||
*/
|
||||
inline void InstancedRenderable::SetSkinCount(std::size_t skinCount)
|
||||
{
|
||||
m_materials.resize(m_matCount * skinCount, Material::GetDefault());
|
||||
m_skinCount = skinCount;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invalidates the bounding volume
|
||||
*/
|
||||
|
||||
inline void InstancedRenderable::InvalidateBoundingVolume()
|
||||
{
|
||||
m_boundingVolumeUpdated = false;
|
||||
|
||||
OnInstancedRenderableInvalidateBoundingVolume(this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invalidates the instance data based on flags
|
||||
*
|
||||
* \param flags Flags to invalidate
|
||||
*/
|
||||
|
||||
inline void InstancedRenderable::InvalidateInstanceData(UInt32 flags)
|
||||
{
|
||||
OnInstancedRenderableInvalidateData(this, flags);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resets the materials, material count and skin count
|
||||
*
|
||||
* This function clears the materials in use by the InstancedRenderable and resets its material count per skin along with its skin count.
|
||||
* This is the only way of setting the material count per skin and should be called at least by the constructor of the derived class.
|
||||
* Please note that all materials will be set to the default material, which should not be changed.
|
||||
*
|
||||
* This function also resets the current skin to the first one.
|
||||
*
|
||||
* \param matCount The new material count per skin value, must be at least 1
|
||||
* \param skinCount The new skin count value
|
||||
*
|
||||
* \see GetMaterial, GetMaterialCount, GetSkinCount, SetSkinCount
|
||||
*/
|
||||
inline void InstancedRenderable::ResetMaterials(std::size_t matCount, std::size_t skinCount)
|
||||
{
|
||||
NazaraAssert(skinCount != 0, "Invalid skin count (cannot be zero)");
|
||||
|
||||
OnInstancedRenderableResetMaterials(this, matCount);
|
||||
|
||||
m_materials.clear();
|
||||
m_materials.resize(matCount * skinCount, Material::GetDefault());
|
||||
|
||||
m_matCount = matCount;
|
||||
m_skinCount = skinCount;
|
||||
m_skin = 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the current instanced renderable with the content of the other one
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param renderable The other InstancedRenderable
|
||||
*/
|
||||
|
||||
inline InstancedRenderable& InstancedRenderable::operator=(const InstancedRenderable& renderable)
|
||||
{
|
||||
m_boundingVolume = renderable.m_boundingVolume;
|
||||
m_boundingVolumeUpdated = renderable.m_boundingVolumeUpdated;
|
||||
m_matCount = renderable.m_matCount;
|
||||
m_materials = renderable.m_materials;
|
||||
m_skin = renderable.m_skin;
|
||||
m_skinCount = renderable.m_skinCount;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Updates the bounding volume
|
||||
*/
|
||||
|
||||
inline void InstancedRenderable::UpdateBoundingVolume() const
|
||||
{
|
||||
MakeBoundingVolume();
|
||||
|
||||
m_boundingVolumeUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -1,121 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_LIGHT_HPP
|
||||
#define NAZARA_LIGHT_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
#include <Nazara/Graphics/Renderable.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_GRAPHICS_API Light : public Renderable
|
||||
{
|
||||
public:
|
||||
Light(LightType type = LightType_Point);
|
||||
inline Light(const Light& light);
|
||||
Light(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;
|
||||
|
||||
inline void EnableShadowCasting(bool castShadows);
|
||||
|
||||
inline void EnsureShadowMapUpdate() const;
|
||||
|
||||
inline float GetAmbientFactor() const;
|
||||
inline float GetAttenuation() const;
|
||||
inline Color GetColor() const;
|
||||
inline float GetDiffuseFactor() const;
|
||||
inline float GetInnerAngle() const;
|
||||
inline float GetInnerAngleCosine() const;
|
||||
inline float GetInvRadius() const;
|
||||
inline LightType GetLightType() const;
|
||||
inline float GetOuterAngle() const;
|
||||
inline float GetOuterAngleCosine() const;
|
||||
inline float GetOuterAngleTangent() const;
|
||||
inline float GetRadius() const;
|
||||
inline TextureRef GetShadowMap() const;
|
||||
inline PixelFormat GetShadowMapFormat() const;
|
||||
inline const Vector2ui& GetShadowMapSize() const;
|
||||
|
||||
inline bool IsShadowCastingEnabled() const;
|
||||
|
||||
inline void SetAmbientFactor(float factor);
|
||||
inline void SetAttenuation(float attenuation);
|
||||
inline void SetColor(const Color& color);
|
||||
inline void SetDiffuseFactor(float factor);
|
||||
inline void SetInnerAngle(float innerAngle);
|
||||
inline void SetLightType(LightType type);
|
||||
inline void SetOuterAngle(float outerAngle);
|
||||
inline void SetRadius(float radius);
|
||||
inline void SetShadowMapFormat(PixelFormat shadowFormat);
|
||||
inline void SetShadowMapSize(const Vector2ui& size);
|
||||
|
||||
void UpdateBoundingVolume(const Matrix4f& transformMatrix) override;
|
||||
|
||||
Light& operator=(const Light& light);
|
||||
Light& operator=(Light&& light) = default;
|
||||
|
||||
private:
|
||||
void MakeBoundingVolume() const override;
|
||||
inline void InvalidateShadowMap();
|
||||
void UpdateShadowMap() const;
|
||||
|
||||
Color m_color;
|
||||
LightType m_type;
|
||||
PixelFormat m_shadowMapFormat;
|
||||
Vector2ui m_shadowMapSize;
|
||||
mutable TextureRef m_shadowMap;
|
||||
bool m_shadowCastingEnabled;
|
||||
mutable bool m_shadowMapUpdated;
|
||||
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 LightUniforms
|
||||
{
|
||||
struct UniformLocations
|
||||
{
|
||||
int type;
|
||||
int color;
|
||||
int factors;
|
||||
int lightViewProjMatrix;
|
||||
int parameters1;
|
||||
int parameters2;
|
||||
int parameters3;
|
||||
int shadowMapping;
|
||||
};
|
||||
|
||||
bool ubo;
|
||||
|
||||
union
|
||||
{
|
||||
UniformLocations locations;
|
||||
int blockLocation;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/Light.inl>
|
||||
|
||||
#endif // NAZARA_LIGHT_HPP
|
||||
|
|
@ -1,404 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Utility/PixelFormat.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a Light object by default
|
||||
*/
|
||||
|
||||
inline Light::Light(const Light& light) :
|
||||
Renderable(light),
|
||||
m_color(light.m_color),
|
||||
m_type(light.m_type),
|
||||
m_shadowMapFormat(light.m_shadowMapFormat),
|
||||
m_shadowMapSize(light.m_shadowMapSize),
|
||||
m_shadowCastingEnabled(light.m_shadowCastingEnabled),
|
||||
m_shadowMapUpdated(false),
|
||||
m_ambientFactor(light.m_ambientFactor),
|
||||
m_attenuation(light.m_attenuation),
|
||||
m_diffuseFactor(light.m_diffuseFactor),
|
||||
m_innerAngle(light.m_innerAngle),
|
||||
m_innerAngleCosine(light.m_innerAngleCosine),
|
||||
m_invRadius(light.m_invRadius),
|
||||
m_outerAngle(light.m_outerAngle),
|
||||
m_outerAngleCosine(light.m_outerAngleCosine),
|
||||
m_outerAngleTangent(light.m_outerAngleTangent),
|
||||
m_radius(light.m_radius)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enables shadow casting
|
||||
*
|
||||
* \param castShadows Should shadows be cast
|
||||
*/
|
||||
|
||||
inline void Light::EnableShadowCasting(bool castShadows)
|
||||
{
|
||||
if (m_shadowCastingEnabled != castShadows)
|
||||
{
|
||||
m_shadowCastingEnabled = castShadows;
|
||||
m_shadowMapUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Ensures that the shadow map is up to date
|
||||
*/
|
||||
|
||||
inline void Light::EnsureShadowMapUpdate() const
|
||||
{
|
||||
if (!m_shadowMapUpdated)
|
||||
UpdateShadowMap();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the ambient factor
|
||||
* \return Current ambient factor
|
||||
*/
|
||||
|
||||
inline float Light::GetAmbientFactor() const
|
||||
{
|
||||
return m_ambientFactor;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the light attenuation (in 1 / R^2)
|
||||
* \return Attenuation
|
||||
*/
|
||||
|
||||
inline float Light::GetAttenuation() const
|
||||
{
|
||||
return m_attenuation;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the color of the light
|
||||
* \return Light color
|
||||
*/
|
||||
|
||||
inline Color Light::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the diffuse factor
|
||||
* \return Current diffuse factor
|
||||
*/
|
||||
|
||||
inline float Light::GetDiffuseFactor() const
|
||||
{
|
||||
return m_diffuseFactor;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the inner angle in spot light
|
||||
* \return Inner angle
|
||||
*/
|
||||
|
||||
inline float Light::GetInnerAngle() const
|
||||
{
|
||||
return m_innerAngle;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the cosine inner angle in spot light
|
||||
* \return Cosine inner angle
|
||||
*/
|
||||
|
||||
inline float Light::GetInnerAngleCosine() const
|
||||
{
|
||||
return m_innerAngleCosine;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the inverse of the radius
|
||||
* \return Inverse of the radius
|
||||
*/
|
||||
|
||||
inline float Light::GetInvRadius() const
|
||||
{
|
||||
return m_invRadius;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the type of the light
|
||||
* \return Light type
|
||||
*/
|
||||
|
||||
inline LightType Light::GetLightType() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the outer angle in spot light
|
||||
* \return Outer angle
|
||||
*/
|
||||
|
||||
inline float Light::GetOuterAngle() const
|
||||
{
|
||||
return m_outerAngle;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the cosine outer angle in spot light
|
||||
* \return Cosine outer angle
|
||||
*/
|
||||
|
||||
inline float Light::GetOuterAngleCosine() const
|
||||
{
|
||||
return m_outerAngleCosine;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the tangent outer angle in spot light
|
||||
* \return Tangent outer angle
|
||||
*/
|
||||
|
||||
inline float Light::GetOuterAngleTangent() const
|
||||
{
|
||||
return m_outerAngleTangent;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the radius of the light
|
||||
* \return Light radius
|
||||
*/
|
||||
|
||||
inline float Light::GetRadius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the shadow map
|
||||
* \return Reference to the shadow map texture
|
||||
*/
|
||||
|
||||
inline TextureRef Light::GetShadowMap() const
|
||||
{
|
||||
EnsureShadowMapUpdate();
|
||||
|
||||
return m_shadowMap;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the format of the shadow map
|
||||
* \return Shadow map format
|
||||
*/
|
||||
|
||||
inline PixelFormat Light::GetShadowMapFormat() const
|
||||
{
|
||||
return m_shadowMapFormat;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the size of the shadow map
|
||||
* \return Shadow map size
|
||||
*/
|
||||
|
||||
inline const Vector2ui& Light::GetShadowMapSize() const
|
||||
{
|
||||
return m_shadowMapSize;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the shadow casting is enabled
|
||||
* \return true If it is the case
|
||||
*/
|
||||
|
||||
inline bool Light::IsShadowCastingEnabled() const
|
||||
{
|
||||
return m_shadowCastingEnabled;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the ambient factor
|
||||
*
|
||||
* \param factor Ambient factor
|
||||
*/
|
||||
|
||||
inline void Light::SetAmbientFactor(float factor)
|
||||
{
|
||||
m_ambientFactor = factor;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the light attenuation (in 1 / R^2)
|
||||
*
|
||||
* \param attenuation Light attenuation
|
||||
*/
|
||||
|
||||
inline void Light::SetAttenuation(float attenuation)
|
||||
{
|
||||
m_attenuation = attenuation;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the color of the light
|
||||
*
|
||||
* \param color Light color
|
||||
*/
|
||||
|
||||
inline void Light::SetColor(const Color& color)
|
||||
{
|
||||
m_color = color;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the diffuse factor
|
||||
*
|
||||
* \param factor Diffuse factor
|
||||
*/
|
||||
|
||||
inline void Light::SetDiffuseFactor(float factor)
|
||||
{
|
||||
m_diffuseFactor = factor;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the inner angle in spot light
|
||||
*
|
||||
* \param innerAngle Inner angle
|
||||
*/
|
||||
|
||||
inline void Light::SetInnerAngle(float innerAngle)
|
||||
{
|
||||
m_innerAngle = innerAngle;
|
||||
m_innerAngleCosine = std::cos(DegreeToRadian(m_innerAngle));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the type of light
|
||||
*
|
||||
* \param type Light type
|
||||
*/
|
||||
|
||||
inline void Light::SetLightType(LightType type)
|
||||
{
|
||||
m_type = type;
|
||||
|
||||
InvalidateShadowMap();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the outer angle in spot light
|
||||
*
|
||||
* \param outerAngle Outer angle
|
||||
*
|
||||
* \remark Invalidates the bounding volume
|
||||
*/
|
||||
|
||||
inline void Light::SetOuterAngle(float outerAngle)
|
||||
{
|
||||
m_outerAngle = outerAngle;
|
||||
m_outerAngleCosine = std::cos(DegreeToRadian(m_outerAngle));
|
||||
m_outerAngleTangent = std::tan(DegreeToRadian(m_outerAngle));
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the radius of the light
|
||||
*
|
||||
* \param radius Light radius
|
||||
*
|
||||
* \remark Invalidates the bounding volume
|
||||
*/
|
||||
|
||||
inline void Light::SetRadius(float radius)
|
||||
{
|
||||
m_radius = radius;
|
||||
|
||||
m_invRadius = 1.f / m_radius;
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the shadow map format
|
||||
*
|
||||
* \param shadowFormat Shadow map format
|
||||
*
|
||||
* \remark Invalidates the shadow map
|
||||
* \remark Produces a NazaraAssert if format is not a depth type
|
||||
*/
|
||||
|
||||
inline void Light::SetShadowMapFormat(PixelFormat shadowFormat)
|
||||
{
|
||||
NazaraAssert(PixelFormatInfo::GetContent(shadowFormat) == PixelFormatContent_DepthStencil, "Shadow format type is not a depth format");
|
||||
|
||||
m_shadowMapFormat = shadowFormat;
|
||||
|
||||
InvalidateShadowMap();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the size of the shadow map
|
||||
*
|
||||
* \param size Shadow map size
|
||||
*
|
||||
* \remark Invalidates the shadow map
|
||||
* \remark Produces a NazaraAssert if size is zero
|
||||
*/
|
||||
|
||||
inline void Light::SetShadowMapSize(const Vector2ui& size)
|
||||
{
|
||||
NazaraAssert(size.x > 0 && size.y > 0, "Shadow map size must have a positive size");
|
||||
|
||||
m_shadowMapSize = size;
|
||||
|
||||
InvalidateShadowMap();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the current light with the content of the other one
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param light The other Light
|
||||
*
|
||||
* \remark Invalidates the shadow map
|
||||
*/
|
||||
|
||||
inline Light& Light::operator=(const Light& light)
|
||||
{
|
||||
Renderable::operator=(light);
|
||||
|
||||
m_ambientFactor = light.m_ambientFactor;
|
||||
m_attenuation = light.m_attenuation;
|
||||
m_color = light.m_color;
|
||||
m_diffuseFactor = light.m_diffuseFactor;
|
||||
m_innerAngle = light.m_innerAngle;
|
||||
m_innerAngleCosine = light.m_innerAngleCosine;
|
||||
m_invRadius = light.m_invRadius;
|
||||
m_outerAngle = light.m_outerAngle;
|
||||
m_outerAngleCosine = light.m_outerAngleCosine;
|
||||
m_outerAngleTangent = light.m_outerAngleTangent;
|
||||
m_radius = light.m_radius;
|
||||
m_shadowCastingEnabled = light.m_shadowCastingEnabled;
|
||||
m_shadowMapFormat = light.m_shadowMapFormat;
|
||||
m_shadowMapSize = light.m_shadowMapSize;
|
||||
m_type = light.m_type;
|
||||
|
||||
InvalidateShadowMap();
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invalidates the shadow map
|
||||
*/
|
||||
|
||||
inline void Light::InvalidateShadowMap()
|
||||
{
|
||||
m_shadowMapUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/DebugOff.hpp>
|
||||
|
|
@ -1,230 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_MATERIAL_HPP
|
||||
#define NAZARA_MATERIAL_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
#include <Nazara/Graphics/MaterialPipeline.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||
#include <Nazara/Renderer/UberShader.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct NAZARA_GRAPHICS_API MaterialParams : ResourceParameters
|
||||
{
|
||||
bool loadAlphaMap = true;
|
||||
bool loadDiffuseMap = true;
|
||||
bool loadEmissiveMap = true;
|
||||
bool loadHeightMap = true;
|
||||
bool loadNormalMap = true;
|
||||
bool loadSpecularMap = true;
|
||||
std::string shaderName = "Basic";
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
class Material;
|
||||
|
||||
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 Material : public RefCounted, public Resource
|
||||
{
|
||||
friend MaterialLibrary;
|
||||
friend MaterialLoader;
|
||||
friend MaterialManager;
|
||||
friend class Graphics;
|
||||
|
||||
public:
|
||||
inline Material();
|
||||
inline Material(const MaterialPipeline* pipeline);
|
||||
inline Material(const MaterialPipelineInfo& pipelineInfo);
|
||||
inline Material(const std::string& pipelineName);
|
||||
inline Material(const Material& material);
|
||||
inline ~Material();
|
||||
|
||||
void Apply(const MaterialPipeline::Instance& instance) const;
|
||||
|
||||
void BuildFromParameters(const ParameterList& matData, const MaterialParams& matParams = MaterialParams());
|
||||
|
||||
inline void Configure(const MaterialPipeline* pipeline);
|
||||
inline void Configure(const MaterialPipelineInfo& pipelineInfo);
|
||||
inline bool Configure(const std::string& pipelineName);
|
||||
|
||||
inline void EnableAlphaTest(bool alphaTest);
|
||||
inline void EnableBlending(bool blending);
|
||||
inline void EnableColorWrite(bool colorWrite);
|
||||
inline void EnableDepthBuffer(bool depthBuffer);
|
||||
inline void EnableDepthSorting(bool depthSorting);
|
||||
inline void EnableDepthWrite(bool depthWrite);
|
||||
inline void EnableFaceCulling(bool faceCulling);
|
||||
inline void EnableReflectionMapping(bool reflection);
|
||||
inline void EnableScissorTest(bool scissorTest);
|
||||
inline void EnableShadowCasting(bool castShadows);
|
||||
inline void EnableShadowReceive(bool receiveShadows);
|
||||
inline void EnableStencilTest(bool stencilTest);
|
||||
inline void EnableVertexColor(bool vertexColor);
|
||||
|
||||
inline void EnsurePipelineUpdate() const;
|
||||
|
||||
inline const TextureRef& GetAlphaMap() const;
|
||||
inline float GetAlphaThreshold() const;
|
||||
inline Color GetAmbientColor() const;
|
||||
inline RendererComparison GetDepthFunc() const;
|
||||
inline const MaterialRef& GetDepthMaterial() const;
|
||||
inline Color GetDiffuseColor() const;
|
||||
inline const TextureRef& GetDiffuseMap() const;
|
||||
inline TextureSampler& GetDiffuseSampler();
|
||||
inline const TextureSampler& GetDiffuseSampler() const;
|
||||
inline BlendFunc GetDstBlend() const;
|
||||
inline const TextureRef& GetEmissiveMap() const;
|
||||
inline FaceSide GetFaceCulling() const;
|
||||
inline FaceFilling GetFaceFilling() const;
|
||||
inline const TextureRef& GetHeightMap() const;
|
||||
inline float GetLineWidth() const;
|
||||
inline const TextureRef& GetNormalMap() const;
|
||||
inline const MaterialPipeline* GetPipeline() const;
|
||||
inline const MaterialPipelineInfo& GetPipelineInfo() const;
|
||||
inline float GetPointSize() const;
|
||||
inline ReflectionMode GetReflectionMode() const;
|
||||
inline const UberShader* GetShader() const;
|
||||
inline float GetShininess() const;
|
||||
inline Color GetSpecularColor() const;
|
||||
inline const TextureRef& GetSpecularMap() const;
|
||||
inline TextureSampler& GetSpecularSampler();
|
||||
inline const TextureSampler& GetSpecularSampler() const;
|
||||
inline BlendFunc GetSrcBlend() const;
|
||||
|
||||
inline bool HasAlphaMap() const;
|
||||
inline bool HasDepthMaterial() const;
|
||||
inline bool HasDiffuseMap() const;
|
||||
inline bool HasEmissiveMap() const;
|
||||
inline bool HasHeightMap() const;
|
||||
inline bool HasNormalMap() const;
|
||||
inline bool HasSpecularMap() const;
|
||||
inline bool HasVertexColor() const;
|
||||
|
||||
inline bool IsAlphaTestEnabled() const;
|
||||
inline bool IsBlendingEnabled() const;
|
||||
inline bool IsColorWriteEnabled() const;
|
||||
inline bool IsDepthBufferEnabled() const;
|
||||
inline bool IsDepthSortingEnabled() const;
|
||||
inline bool IsDepthWriteEnabled() const;
|
||||
inline bool IsFaceCullingEnabled() const;
|
||||
inline bool IsReflectionMappingEnabled() const;
|
||||
inline bool IsScissorTestEnabled() const;
|
||||
inline bool IsStencilTestEnabled() const;
|
||||
inline bool IsShadowCastingEnabled() const;
|
||||
inline bool IsShadowReceiveEnabled() const;
|
||||
|
||||
void Reset();
|
||||
|
||||
void SaveToParameters(ParameterList* matData);
|
||||
|
||||
inline bool SetAlphaMap(const std::string& textureName);
|
||||
inline void SetAlphaMap(TextureRef alphaMap);
|
||||
inline void SetAlphaThreshold(float alphaThreshold);
|
||||
inline void SetAmbientColor(const Color& ambient);
|
||||
inline void SetDepthFunc(RendererComparison depthFunc);
|
||||
inline void SetDepthMaterial(MaterialRef depthMaterial);
|
||||
inline void SetDiffuseColor(const Color& diffuse);
|
||||
inline bool SetDiffuseMap(const std::string& textureName);
|
||||
inline void SetDiffuseMap(TextureRef diffuseMap);
|
||||
inline void SetDiffuseSampler(const TextureSampler& sampler);
|
||||
inline void SetDstBlend(BlendFunc func);
|
||||
inline bool SetEmissiveMap(const std::string& textureName);
|
||||
inline void SetEmissiveMap(TextureRef textureName);
|
||||
inline void SetFaceCulling(FaceSide faceSide);
|
||||
inline void SetFaceFilling(FaceFilling filling);
|
||||
inline bool SetHeightMap(const std::string& textureName);
|
||||
inline void SetHeightMap(TextureRef textureName);
|
||||
inline void SetLineWidth(float lineWidth);
|
||||
inline bool SetNormalMap(const std::string& textureName);
|
||||
inline void SetNormalMap(TextureRef textureName);
|
||||
inline void SetPointSize(float pointSize);
|
||||
inline void SetReflectionMode(ReflectionMode reflectionMode);
|
||||
inline void SetShader(UberShaderConstRef uberShader);
|
||||
inline bool SetShader(const std::string& uberShaderName);
|
||||
inline void SetShininess(float shininess);
|
||||
inline void SetSpecularColor(const Color& specular);
|
||||
inline bool SetSpecularMap(const std::string& textureName);
|
||||
inline void SetSpecularMap(TextureRef specularMap);
|
||||
inline void SetSpecularSampler(const TextureSampler& sampler);
|
||||
inline void SetSrcBlend(BlendFunc func);
|
||||
|
||||
inline Material& operator=(const Material& material);
|
||||
|
||||
inline static MaterialRef GetDefault();
|
||||
inline static int GetTextureUnit(TextureMap textureMap);
|
||||
|
||||
static inline MaterialRef LoadFromFile(const std::filesystem::path& filePath, const MaterialParams& params = MaterialParams());
|
||||
static inline MaterialRef LoadFromMemory(const void* data, std::size_t size, const MaterialParams& params = MaterialParams());
|
||||
static inline MaterialRef LoadFromStream(Stream& stream, const MaterialParams& params = MaterialParams());
|
||||
|
||||
template<typename... Args> static MaterialRef New(Args&&... args);
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnMaterialReflectionModeChange, const Material* /*material*/, ReflectionMode /*newReflectionMode*/);
|
||||
NazaraSignal(OnMaterialRelease, const Material* /*material*/);
|
||||
NazaraSignal(OnMaterialReset, const Material* /*material*/);
|
||||
|
||||
private:
|
||||
void Copy(const Material& material);
|
||||
inline void InvalidatePipeline();
|
||||
inline void UpdatePipeline() const;
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
Color m_ambientColor;
|
||||
Color m_diffuseColor;
|
||||
Color m_specularColor;
|
||||
MaterialRef m_depthMaterial; //< Materialception
|
||||
mutable const MaterialPipeline* m_pipeline;
|
||||
MaterialPipelineInfo m_pipelineInfo;
|
||||
ReflectionMode m_reflectionMode;
|
||||
TextureSampler m_diffuseSampler;
|
||||
TextureSampler m_specularSampler;
|
||||
TextureRef m_alphaMap;
|
||||
TextureRef m_diffuseMap;
|
||||
TextureRef m_emissiveMap;
|
||||
TextureRef m_heightMap;
|
||||
TextureRef m_normalMap;
|
||||
TextureRef m_specularMap;
|
||||
mutable bool m_pipelineUpdated;
|
||||
bool m_shadowCastingEnabled;
|
||||
float m_alphaThreshold;
|
||||
float m_shininess;
|
||||
unsigned int m_reflectionSize;
|
||||
|
||||
static std::array<int, TextureMap_Max + 1> s_textureUnits;
|
||||
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>
|
||||
|
||||
#endif // NAZARA_MATERIAL_HPP
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,95 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_MATERIALPIPELINE_HPP
|
||||
#define NAZARA_MATERIALPIPELINE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
#include <Nazara/Renderer/RenderPipeline.hpp>
|
||||
#include <Nazara/Renderer/UberShader.hpp>
|
||||
#include <array>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct MaterialPipelineInfo : RenderStates
|
||||
{
|
||||
bool alphaTest = false;
|
||||
bool depthSorting = false;
|
||||
bool hasAlphaMap = false;
|
||||
bool hasDiffuseMap = false;
|
||||
bool hasEmissiveMap = false;
|
||||
bool hasHeightMap = false;
|
||||
bool hasNormalMap = false;
|
||||
bool hasSpecularMap = false;
|
||||
bool hasVertexColor = false;
|
||||
bool reflectionMapping = false;
|
||||
bool shadowReceive = true;
|
||||
|
||||
UberShaderConstRef uberShader;
|
||||
};
|
||||
|
||||
inline bool operator==(const MaterialPipelineInfo& lhs, const MaterialPipelineInfo& rhs);
|
||||
inline bool operator!=(const MaterialPipelineInfo& lhs, const MaterialPipelineInfo& rhs);
|
||||
|
||||
class MaterialPipeline;
|
||||
|
||||
using MaterialPipelineConstRef = ObjectRef<const MaterialPipeline>;
|
||||
using MaterialPipelineLibrary = ObjectLibrary<MaterialPipeline>;
|
||||
using MaterialPipelineRef = ObjectRef<MaterialPipeline>;
|
||||
|
||||
class NAZARA_GRAPHICS_API MaterialPipeline : public RefCounted
|
||||
{
|
||||
friend class Graphics;
|
||||
friend MaterialPipelineLibrary;
|
||||
|
||||
public:
|
||||
struct Instance;
|
||||
|
||||
MaterialPipeline(const MaterialPipeline&) = delete;
|
||||
MaterialPipeline(MaterialPipeline&&) = delete;
|
||||
~MaterialPipeline() = default;
|
||||
|
||||
inline const Instance& Apply(UInt32 flags = ShaderFlags_None) const;
|
||||
|
||||
MaterialPipeline& operator=(const MaterialPipeline&) = delete;
|
||||
MaterialPipeline& operator=(MaterialPipeline&&) = delete;
|
||||
|
||||
inline const MaterialPipelineInfo& GetInfo() const;
|
||||
inline const Instance& GetInstance(UInt32 flags = ShaderFlags_None) const;
|
||||
|
||||
static MaterialPipelineRef GetPipeline(const MaterialPipelineInfo& pipelineInfo);
|
||||
|
||||
struct Instance
|
||||
{
|
||||
RenderPipeline renderPipeline;
|
||||
UberShaderInstance* uberInstance = nullptr;
|
||||
std::array<int, MaterialUniform_Max + 1> uniforms;
|
||||
};
|
||||
|
||||
private:
|
||||
inline MaterialPipeline(const MaterialPipelineInfo& pipelineInfo);
|
||||
|
||||
void GenerateRenderPipeline(UInt32 flags) const;
|
||||
|
||||
static bool Initialize();
|
||||
template<typename... Args> static MaterialPipelineRef New(Args&&... args);
|
||||
static void Uninitialize();
|
||||
|
||||
MaterialPipelineInfo m_pipelineInfo;
|
||||
mutable std::array<Instance, ShaderFlags_Max + 1> m_instances;
|
||||
|
||||
using PipelineCache = std::unordered_map<MaterialPipelineInfo, MaterialPipelineRef>;
|
||||
static PipelineCache s_pipelineCache;
|
||||
|
||||
static MaterialPipelineLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/MaterialPipeline.inl>
|
||||
|
||||
#endif // NAZARA_MATERIALPIPELINE_HPP
|
||||
|
|
@ -1,147 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/UberShaderInstance.hpp>
|
||||
#include <functional>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline MaterialPipeline::MaterialPipeline(const MaterialPipelineInfo& pipelineInfo) :
|
||||
m_pipelineInfo(pipelineInfo)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enable pipeline states for rendering
|
||||
*
|
||||
* \param flags Shader flags
|
||||
*/
|
||||
inline const MaterialPipeline::Instance& MaterialPipeline::Apply(UInt32 flags) const
|
||||
{
|
||||
const Instance& instance = GetInstance(flags);
|
||||
instance.uberInstance->Activate();
|
||||
|
||||
Renderer::SetRenderStates(m_pipelineInfo);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Retrieve a MaterialPipelineInfo object describing this pipeline
|
||||
*
|
||||
* \return Pipeline informations
|
||||
*/
|
||||
const MaterialPipelineInfo& MaterialPipeline::GetInfo() const
|
||||
{
|
||||
return m_pipelineInfo;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Retrieve (and generate if required) a pipeline instance using shader flags without applying it
|
||||
*
|
||||
* \param flags Shader flags
|
||||
*
|
||||
* \return Pipeline instance
|
||||
*/
|
||||
inline const MaterialPipeline::Instance& MaterialPipeline::GetInstance(UInt32 flags) const
|
||||
{
|
||||
const Instance& instance = m_instances[flags];
|
||||
if (!instance.uberInstance)
|
||||
GenerateRenderPipeline(flags);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool operator==(const MaterialPipelineInfo& lhs, const MaterialPipelineInfo& rhs)
|
||||
{
|
||||
if (!operator==(static_cast<const RenderStates&>(lhs), static_cast<const RenderStates&>(rhs)))
|
||||
return false;
|
||||
|
||||
#define NazaraPipelineMember(field) if (lhs.field != rhs.field) return false
|
||||
#define NazaraPipelineBoolMember NazaraPipelineMember
|
||||
|
||||
NazaraPipelineBoolMember(alphaTest);
|
||||
NazaraPipelineBoolMember(depthSorting);
|
||||
NazaraPipelineBoolMember(hasAlphaMap);
|
||||
NazaraPipelineBoolMember(hasDiffuseMap);
|
||||
NazaraPipelineBoolMember(hasEmissiveMap);
|
||||
NazaraPipelineBoolMember(hasHeightMap);
|
||||
NazaraPipelineBoolMember(hasNormalMap);
|
||||
NazaraPipelineBoolMember(hasSpecularMap);
|
||||
NazaraPipelineBoolMember(hasVertexColor);
|
||||
NazaraPipelineBoolMember(reflectionMapping);
|
||||
NazaraPipelineBoolMember(shadowReceive);
|
||||
|
||||
NazaraPipelineMember(uberShader);
|
||||
|
||||
#undef NazaraPipelineMember
|
||||
#undef NazaraPipelineBoolMember
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator!=(const MaterialPipelineInfo& lhs, const MaterialPipelineInfo& rhs)
|
||||
{
|
||||
return !operator==(lhs, rhs);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a new MaterialPipeline from the arguments
|
||||
* \return A reference to the newly created material pipeline
|
||||
*
|
||||
* \param args Arguments for the material pipeline
|
||||
*/
|
||||
template<typename... Args>
|
||||
MaterialPipelineRef MaterialPipeline::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<MaterialPipeline> object(new MaterialPipeline(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<Nz::MaterialPipelineInfo>
|
||||
{
|
||||
size_t operator()(const Nz::MaterialPipelineInfo& pipelineInfo) const
|
||||
{
|
||||
hash<Nz::RenderStates> parentHash;
|
||||
|
||||
std::size_t seed = parentHash(pipelineInfo);
|
||||
|
||||
Nz::UInt16 parameterHash = 0;
|
||||
Nz::UInt16 parameterIndex = 0;
|
||||
|
||||
#define NazaraPipelineMember(member) Nz::HashCombine(seed, pipelineInfo.member)
|
||||
#define NazaraPipelineBoolMember(member) parameterHash |= ((pipelineInfo.member) ? 1U : 0U) << (parameterIndex++)
|
||||
|
||||
NazaraPipelineBoolMember(alphaTest);
|
||||
NazaraPipelineBoolMember(depthSorting);
|
||||
NazaraPipelineBoolMember(hasAlphaMap);
|
||||
NazaraPipelineBoolMember(hasDiffuseMap);
|
||||
NazaraPipelineBoolMember(hasEmissiveMap);
|
||||
NazaraPipelineBoolMember(hasHeightMap);
|
||||
NazaraPipelineBoolMember(hasNormalMap);
|
||||
NazaraPipelineBoolMember(hasSpecularMap);
|
||||
NazaraPipelineBoolMember(hasVertexColor);
|
||||
NazaraPipelineBoolMember(reflectionMapping);
|
||||
NazaraPipelineBoolMember(shadowReceive);
|
||||
|
||||
NazaraPipelineMember(uberShader);
|
||||
|
||||
#undef NazaraPipelineMember
|
||||
#undef NazaraPipelineBoolMember
|
||||
|
||||
Nz::HashCombine(seed, parameterHash);
|
||||
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_MODEL_HPP
|
||||
#define NAZARA_MODEL_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Core/ResourceSaver.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct NAZARA_GRAPHICS_API ModelParameters : ResourceParameters
|
||||
{
|
||||
ModelParameters();
|
||||
|
||||
bool loadMaterials = true;
|
||||
MaterialParams material;
|
||||
MeshParams mesh;
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
class Model;
|
||||
|
||||
using ModelConstRef = ObjectRef<const Model>;
|
||||
using ModelLibrary = ObjectLibrary<Model>;
|
||||
using ModelLoader = ResourceLoader<Model, ModelParameters>;
|
||||
using ModelManager = ResourceManager<Model, ModelParameters>;
|
||||
using ModelRef = ObjectRef<Model>;
|
||||
using ModelSaver = ResourceSaver<Model, ModelParameters>;
|
||||
|
||||
class NAZARA_GRAPHICS_API Model : public InstancedRenderable, public Resource
|
||||
{
|
||||
friend ModelLibrary;
|
||||
friend ModelLoader;
|
||||
friend ModelManager;
|
||||
friend ModelSaver;
|
||||
|
||||
public:
|
||||
inline Model();
|
||||
Model(const Model& model);
|
||||
Model(Model&& model) = delete;
|
||||
virtual ~Model();
|
||||
|
||||
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override;
|
||||
inline void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix, int renderOrder = 0, const Recti& scissorRect = Recti(-1, -1, -1, -1)) const;
|
||||
|
||||
std::unique_ptr<InstancedRenderable> Clone() const override;
|
||||
|
||||
using InstancedRenderable::GetMaterial;
|
||||
const MaterialRef& GetMaterial(const std::string& subMeshName) const;
|
||||
const MaterialRef& GetMaterial(std::size_t skinIndex, const std::string& subMeshName) const;
|
||||
Mesh* GetMesh() const;
|
||||
|
||||
virtual bool IsAnimated() const;
|
||||
|
||||
using InstancedRenderable::SetMaterial;
|
||||
bool SetMaterial(const std::string& subMeshName, MaterialRef material);
|
||||
bool SetMaterial(std::size_t skinIndex, const std::string& subMeshName, MaterialRef material);
|
||||
|
||||
virtual void SetMesh(Mesh* mesh);
|
||||
|
||||
Model& operator=(const Model& node) = default;
|
||||
Model& operator=(Model&& node) = delete;
|
||||
|
||||
static ModelRef LoadFromFile(const std::filesystem::path& filePath, const ModelParameters& params = ModelParameters());
|
||||
static ModelRef LoadFromMemory(const void* data, std::size_t size, const ModelParameters& params = ModelParameters());
|
||||
static ModelRef LoadFromStream(Stream& stream, const ModelParameters& params = ModelParameters());
|
||||
|
||||
template<typename... Args> static ModelRef New(Args&&... args);
|
||||
|
||||
protected:
|
||||
void MakeBoundingVolume() const override;
|
||||
|
||||
MeshRef m_mesh;
|
||||
|
||||
NazaraSlot(Mesh, OnMeshInvalidateAABB, m_meshAABBInvalidationSlot);
|
||||
|
||||
static ModelLibrary::LibraryMap s_library;
|
||||
static ModelLoader::LoaderList s_loaders;
|
||||
static ModelManager::ManagerMap s_managerMap;
|
||||
static ModelManager::ManagerParams s_managerParameters;
|
||||
static ModelSaver::SaverList s_savers;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/Model.inl>
|
||||
|
||||
#endif // NAZARA_MODEL_HPP
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/Model.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a Model object by default
|
||||
*/
|
||||
inline Model::Model()
|
||||
{
|
||||
ResetMaterials(0);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Model object by copying another
|
||||
*
|
||||
* \param model Model to copy
|
||||
*/
|
||||
inline Model::Model(const Model& model) :
|
||||
InstancedRenderable(model)
|
||||
{
|
||||
SetMesh(model.m_mesh);
|
||||
|
||||
// Since SetMesh does reset materials, we need reapply them
|
||||
SetSkinCount(model.GetSkinCount());
|
||||
for (std::size_t skin = 0; skin < model.GetSkinCount(); ++skin)
|
||||
{
|
||||
for (std::size_t matIndex = 0; matIndex < model.GetMaterialCount(); ++matIndex)
|
||||
SetMaterial(skin, matIndex, model.GetMaterial(skin, matIndex));
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds this model to a render queue, using user-specified transform matrix and render order
|
||||
*
|
||||
* This can be useful when drawing particles
|
||||
*
|
||||
* \param renderQueue Queue to be added
|
||||
* \param transformMatrix Transform matrix to be used for rendering the model
|
||||
* \param renderOrder Specify the render queue layer to be used
|
||||
* \param scissorRect The Scissor rect to uses for rendering
|
||||
*/
|
||||
inline void Model::AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix, int renderOrder, const Recti& scissorRect) const
|
||||
{
|
||||
InstanceData instanceData(Nz::Matrix4f::Identity());
|
||||
instanceData.renderOrder = renderOrder;
|
||||
instanceData.transformMatrix = transformMatrix;
|
||||
return AddToRenderQueue(renderQueue, instanceData, scissorRect);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a new Model from the arguments
|
||||
* \return A reference to the newly created model
|
||||
*
|
||||
* \param args Arguments for the model
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PARTICLECONTROLLER_HPP
|
||||
#define NAZARA_PARTICLECONTROLLER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ParticleController;
|
||||
class ParticleMapper;
|
||||
class ParticleGroup;
|
||||
|
||||
using ParticleControllerConstRef = ObjectRef<const ParticleController>;
|
||||
using ParticleControllerLibrary = ObjectLibrary<ParticleController>;
|
||||
using ParticleControllerRef = ObjectRef<ParticleController>;
|
||||
|
||||
class NAZARA_GRAPHICS_API ParticleController : public RefCounted
|
||||
{
|
||||
friend ParticleControllerLibrary;
|
||||
friend class Graphics;
|
||||
|
||||
public:
|
||||
ParticleController() = default;
|
||||
ParticleController(const ParticleController& controller);
|
||||
virtual ~ParticleController();
|
||||
|
||||
virtual void Apply(ParticleGroup& system, ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime) = 0;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnParticleControllerRelease, const ParticleController* /*particleController*/);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
static ParticleControllerLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PARTICLECONTROLLER_HPP
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PARTICLEDECLARATION_HPP
|
||||
#define NAZARA_PARTICLEDECLARATION_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <array>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ParticleDeclaration;
|
||||
|
||||
using ParticleDeclarationConstRef = ObjectRef<const ParticleDeclaration>;
|
||||
using ParticleDeclarationLibrary = ObjectLibrary<ParticleDeclaration>;
|
||||
using ParticleDeclarationRef = ObjectRef<ParticleDeclaration>;
|
||||
|
||||
class NAZARA_GRAPHICS_API ParticleDeclaration : public RefCounted
|
||||
{
|
||||
friend ParticleDeclarationLibrary;
|
||||
friend class Graphics;
|
||||
|
||||
public:
|
||||
ParticleDeclaration();
|
||||
ParticleDeclaration(const ParticleDeclaration& declaration);
|
||||
~ParticleDeclaration();
|
||||
|
||||
void DisableComponent(ParticleComponent component);
|
||||
void EnableComponent(ParticleComponent component, ComponentType type, std::size_t offset);
|
||||
|
||||
void GetComponent(ParticleComponent component, bool* enabled, ComponentType* type, std::size_t* offset) const;
|
||||
std::size_t GetStride() const;
|
||||
|
||||
void SetStride(unsigned int stride);
|
||||
|
||||
ParticleDeclaration& operator=(const ParticleDeclaration& declaration);
|
||||
|
||||
static ParticleDeclaration* Get(ParticleLayout layout);
|
||||
static bool IsTypeSupported(ComponentType type);
|
||||
template<typename... Args> static ParticleDeclarationRef New(Args&&... args);
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnParticleDeclarationRelease, const ParticleDeclaration* /*particleDeclaration*/);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
struct Component
|
||||
{
|
||||
ComponentType type;
|
||||
bool enabled = false;
|
||||
std::size_t offset;
|
||||
|
||||
/*
|
||||
** -Lynix:
|
||||
** It would be also possible to precise the stride by an independant way, what I don't allow
|
||||
** to decomplexify the interface of something I consider useless.
|
||||
** If you think that could be useful, don't hesitate to make me aware !
|
||||
*/
|
||||
};
|
||||
|
||||
std::array<Component, ParticleComponent_Max + 1> m_components;
|
||||
std::size_t m_stride;
|
||||
|
||||
static std::array<ParticleDeclaration, ParticleLayout_Max + 1> s_declarations;
|
||||
static ParticleDeclarationLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/ParticleDeclaration.inl>
|
||||
|
||||
#endif // NAZARA_PARTICLEDECLARATION_HPP
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename... Args>
|
||||
ParticleDeclarationRef ParticleDeclaration::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<ParticleDeclaration> object(new ParticleDeclaration(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Utility/DebugOff.hpp>
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PARTICLEEMITTER_HPP
|
||||
#define NAZARA_PARTICLEEMITTER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ParticleMapper;
|
||||
class ParticleGroup;
|
||||
|
||||
class NAZARA_GRAPHICS_API ParticleEmitter
|
||||
{
|
||||
public:
|
||||
ParticleEmitter();
|
||||
ParticleEmitter(const ParticleEmitter& emitter);
|
||||
ParticleEmitter(ParticleEmitter&& emitter);
|
||||
virtual ~ParticleEmitter();
|
||||
|
||||
virtual void Emit(ParticleGroup& system, float elapsedTime) const;
|
||||
|
||||
void EnableLagCompensation(bool enable);
|
||||
|
||||
std::size_t GetEmissionCount() const;
|
||||
float GetEmissionRate() const;
|
||||
|
||||
bool IsLagCompensationEnabled() const;
|
||||
|
||||
void SetEmissionCount(std::size_t count);
|
||||
void SetEmissionRate(float rate);
|
||||
|
||||
ParticleEmitter& operator=(const ParticleEmitter& emitter) = default;
|
||||
ParticleEmitter& operator=(ParticleEmitter&& emitter);
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnParticleEmitterMove, ParticleEmitter* /*oldParticleEmitter*/, ParticleEmitter* /*newParticleEmitter*/);
|
||||
NazaraSignal(OnParticleEmitterRelease, const ParticleEmitter* /*particleEmitter*/);
|
||||
|
||||
private:
|
||||
virtual void SetupParticles(ParticleMapper& mapper, unsigned int count) const = 0;
|
||||
|
||||
bool m_lagCompensationEnabled;
|
||||
mutable float m_emissionAccumulator;
|
||||
float m_emissionRate;
|
||||
std::size_t m_emissionCount;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PARTICLEEMITTER_HPP
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PARTICLEFUNCTIONCONTROLLER_HPP
|
||||
#define NAZARA_PARTICLEFUNCTIONCONTROLLER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/ParticleController.hpp>
|
||||
#include <functional>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ParticleFunctionController;
|
||||
|
||||
using ParticleFunctionControllerConstRef = ObjectRef<const ParticleFunctionController>;
|
||||
using ParticleFunctionControllerRef = ObjectRef<ParticleFunctionController>;
|
||||
|
||||
class NAZARA_GRAPHICS_API ParticleFunctionController : public ParticleController
|
||||
{
|
||||
public:
|
||||
using Controller = std::function<void(ParticleGroup& /*group*/, ParticleMapper& /*mapper*/, unsigned int /*startId*/, unsigned int /*endId*/, float /*elapsedTime*/)>;
|
||||
|
||||
inline ParticleFunctionController(Controller controller);
|
||||
ParticleFunctionController(const ParticleFunctionController&) = default;
|
||||
~ParticleFunctionController() = default;
|
||||
|
||||
void Apply(ParticleGroup& group, ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime) override final;
|
||||
|
||||
inline const Controller& GetController() const;
|
||||
|
||||
inline void SetController(Controller controller);
|
||||
|
||||
template<typename... Args> static ParticleFunctionControllerRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
Controller m_controller;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/ParticleFunctionController.inl>
|
||||
|
||||
#endif // NAZARA_PARTICLEFUNCTIONCONTROLLER_HPP
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline ParticleFunctionController::ParticleFunctionController(Controller controller) :
|
||||
m_controller(std::move(controller))
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the controller function
|
||||
*
|
||||
* \return Controller function responsible for particle update
|
||||
*/
|
||||
inline const ParticleFunctionController::Controller& ParticleFunctionController::GetController() const
|
||||
{
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the controller function
|
||||
*
|
||||
* \remark The controller function must be valid
|
||||
*/
|
||||
inline void ParticleFunctionController::SetController(Controller controller)
|
||||
{
|
||||
m_controller = std::move(controller);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
ParticleFunctionControllerRef ParticleFunctionController::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<ParticleFunctionController> object(new ParticleFunctionController(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PARTICLEFUNCTIONGENERATOR_HPP
|
||||
#define NAZARA_PARTICLEFUNCTIONGENERATOR_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/ParticleGenerator.hpp>
|
||||
#include <functional>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ParticleFunctionGenerator;
|
||||
|
||||
using ParticleFunctionGeneratorConstRef = ObjectRef<const ParticleFunctionGenerator>;
|
||||
using ParticleFunctionGeneratorRef = ObjectRef<ParticleFunctionGenerator>;
|
||||
|
||||
class NAZARA_GRAPHICS_API ParticleFunctionGenerator : public ParticleGenerator
|
||||
{
|
||||
public:
|
||||
using Generator = std::function<void(ParticleGroup& /*group*/, ParticleMapper& /*mapper*/, unsigned int /*startId*/, unsigned int /*endId*/)>;
|
||||
|
||||
inline ParticleFunctionGenerator(Generator controller);
|
||||
ParticleFunctionGenerator(const ParticleFunctionGenerator&) = default;
|
||||
~ParticleFunctionGenerator() = default;
|
||||
|
||||
void Generate(ParticleGroup& group, ParticleMapper& mapper, unsigned int startId, unsigned int endId) override final;
|
||||
|
||||
inline const Generator& GetGenerator() const;
|
||||
|
||||
inline void SetGenerator(Generator generator);
|
||||
|
||||
template<typename... Args> static ParticleFunctionGeneratorRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
Generator m_generator;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/ParticleFunctionGenerator.inl>
|
||||
|
||||
#endif // NAZARA_PARTICLEFUNCTIONGENERATOR_HPP
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline ParticleFunctionGenerator::ParticleFunctionGenerator(Generator generator) :
|
||||
m_generator(std::move(generator))
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the generator function
|
||||
*
|
||||
* \return Generator function responsible for particle creation
|
||||
*/
|
||||
inline const ParticleFunctionGenerator::Generator& ParticleFunctionGenerator::GetGenerator() const
|
||||
{
|
||||
return m_generator;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the generator function
|
||||
*
|
||||
* \remark The generator function must be valid
|
||||
*/
|
||||
inline void ParticleFunctionGenerator::SetGenerator(Generator generator)
|
||||
{
|
||||
m_generator = std::move(generator);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
ParticleFunctionGeneratorRef ParticleFunctionGenerator::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<ParticleFunctionGenerator> object(new ParticleFunctionGenerator(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PARTICLEFUNCTIONRENDERER_HPP
|
||||
#define NAZARA_PARTICLEFUNCTIONRENDERER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/ParticleRenderer.hpp>
|
||||
#include <functional>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ParticleFunctionRenderer;
|
||||
|
||||
using ParticleFunctionRendererConstRef = ObjectRef<const ParticleFunctionRenderer>;
|
||||
using ParticleFunctionRendererRef = ObjectRef<ParticleFunctionRenderer>;
|
||||
|
||||
class NAZARA_GRAPHICS_API ParticleFunctionRenderer : public ParticleRenderer
|
||||
{
|
||||
public:
|
||||
using Renderer = std::function<void(const ParticleGroup& /*group*/, const ParticleMapper& /*mapper*/, unsigned int /*startId*/, unsigned int /*endId*/, AbstractRenderQueue* /*renderQueue*/)>;
|
||||
|
||||
inline ParticleFunctionRenderer(Renderer renderer);
|
||||
ParticleFunctionRenderer(const ParticleFunctionRenderer&) = default;
|
||||
~ParticleFunctionRenderer() = default;
|
||||
|
||||
void Render(const ParticleGroup& group, const ParticleMapper& mapper, unsigned int startId, unsigned int endId, AbstractRenderQueue* renderQueue) override final;
|
||||
|
||||
inline const Renderer& GetRenderer() const;
|
||||
|
||||
inline void SetRenderer(Renderer renderer);
|
||||
|
||||
template<typename... Args> static ParticleFunctionRendererRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
Renderer m_renderer;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/ParticleFunctionRenderer.inl>
|
||||
|
||||
#endif // NAZARA_PARTICLEFUNCTIONRENDERER_HPP
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline ParticleFunctionRenderer::ParticleFunctionRenderer(Renderer renderer) :
|
||||
m_renderer(std::move(renderer))
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the renderer function
|
||||
*
|
||||
* \return Renderer function responsible for particle rendering
|
||||
*/
|
||||
inline const ParticleFunctionRenderer::Renderer& ParticleFunctionRenderer::GetRenderer() const
|
||||
{
|
||||
return m_renderer;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the renderer function
|
||||
*
|
||||
* \remark The renderer function must be valid
|
||||
*/
|
||||
inline void ParticleFunctionRenderer::SetRenderer(Renderer renderer)
|
||||
{
|
||||
m_renderer = std::move(renderer);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
ParticleFunctionRendererRef ParticleFunctionRenderer::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<ParticleFunctionRenderer> object(new ParticleFunctionRenderer(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PARTICLEGENERATOR_HPP
|
||||
#define NAZARA_PARTICLEGENERATOR_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ParticleGenerator;
|
||||
class ParticleMapper;
|
||||
class ParticleGroup;
|
||||
|
||||
using ParticleGeneratorConstRef = ObjectRef<const ParticleGenerator>;
|
||||
using ParticleGeneratorLibrary = ObjectLibrary<ParticleGenerator>;
|
||||
using ParticleGeneratorRef = ObjectRef<ParticleGenerator>;
|
||||
|
||||
class NAZARA_GRAPHICS_API ParticleGenerator : public RefCounted
|
||||
{
|
||||
friend ParticleGeneratorLibrary;
|
||||
friend class Graphics;
|
||||
|
||||
public:
|
||||
ParticleGenerator() = default;
|
||||
ParticleGenerator(const ParticleGenerator& generator);
|
||||
virtual ~ParticleGenerator();
|
||||
|
||||
virtual void Generate(ParticleGroup& system, ParticleMapper& mapper, unsigned int startId, unsigned int endId) = 0;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnParticleGeneratorRelease, const ParticleGenerator* /*particleGenerator*/);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
static ParticleGeneratorLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PARTICLEGENERATOR_HPP
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PARTICLEGROUP_HPP
|
||||
#define NAZARA_PARTICLEGROUP_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Graphics/ParticleController.hpp>
|
||||
#include <Nazara/Graphics/ParticleDeclaration.hpp>
|
||||
#include <Nazara/Graphics/ParticleEmitter.hpp>
|
||||
#include <Nazara/Graphics/ParticleGenerator.hpp>
|
||||
#include <Nazara/Graphics/ParticleRenderer.hpp>
|
||||
#include <Nazara/Graphics/Renderable.hpp>
|
||||
#include <functional>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_GRAPHICS_API ParticleGroup : public Renderable
|
||||
{
|
||||
public:
|
||||
ParticleGroup(unsigned int maxParticleCount, ParticleLayout layout);
|
||||
ParticleGroup(unsigned int maxParticleCount, ParticleDeclarationConstRef declaration);
|
||||
ParticleGroup(const ParticleGroup& emitter);
|
||||
~ParticleGroup();
|
||||
|
||||
void AddController(ParticleControllerRef controller);
|
||||
void AddEmitter(ParticleEmitter* emitter);
|
||||
void AddGenerator(ParticleGeneratorRef generator);
|
||||
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix) const override;
|
||||
|
||||
void ApplyControllers(ParticleMapper& mapper, unsigned int particleCount, float elapsedTime);
|
||||
|
||||
void* CreateParticle();
|
||||
void* CreateParticles(unsigned int count);
|
||||
|
||||
void* GenerateParticle();
|
||||
void* GenerateParticles(unsigned int count);
|
||||
|
||||
inline void* GetBuffer();
|
||||
inline const void* GetBuffer() const;
|
||||
const ParticleDeclarationConstRef& GetDeclaration() const;
|
||||
std::size_t GetMaxParticleCount() const;
|
||||
std::size_t GetParticleCount() const;
|
||||
std::size_t GetParticleSize() const;
|
||||
|
||||
void KillParticle(std::size_t index);
|
||||
void KillParticles();
|
||||
|
||||
void RemoveController(ParticleController* controller);
|
||||
void RemoveEmitter(ParticleEmitter* emitter);
|
||||
void RemoveGenerator(ParticleGenerator* generator);
|
||||
|
||||
void SetRenderer(ParticleRenderer* renderer);
|
||||
|
||||
void Update(float elapsedTime);
|
||||
void UpdateBoundingVolume(const Matrix4f& transformMatrix) override;
|
||||
|
||||
ParticleGroup& operator=(const ParticleGroup& emitter);
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnParticleGroupRelease, const ParticleGroup* /*particleGroup*/);
|
||||
|
||||
private:
|
||||
void MakeBoundingVolume() const override;
|
||||
void OnEmitterMove(ParticleEmitter* oldEmitter, ParticleEmitter* newEmitter);
|
||||
void OnEmitterRelease(const ParticleEmitter* emitter);
|
||||
void ResizeBuffer();
|
||||
|
||||
struct EmitterEntry
|
||||
{
|
||||
NazaraSlot(ParticleEmitter, OnParticleEmitterMove, moveSlot);
|
||||
NazaraSlot(ParticleEmitter, OnParticleEmitterRelease, releaseSlot);
|
||||
|
||||
ParticleEmitter* emitter;
|
||||
};
|
||||
|
||||
std::set<unsigned int, std::greater<unsigned int>> m_dyingParticles;
|
||||
std::size_t m_maxParticleCount;
|
||||
std::size_t m_particleCount;
|
||||
std::size_t m_particleSize;
|
||||
mutable std::vector<UInt8> m_buffer;
|
||||
std::vector<ParticleControllerRef> m_controllers;
|
||||
std::vector<EmitterEntry> m_emitters;
|
||||
std::vector<ParticleGeneratorRef> m_generators;
|
||||
ParticleDeclarationConstRef m_declaration;
|
||||
ParticleRendererRef m_renderer;
|
||||
bool m_processing;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/ParticleGroup.inl>
|
||||
|
||||
#endif // NAZARA_PARTICLEGROUP_HPP
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Gets a raw pointer to the particle buffer
|
||||
*
|
||||
* This can be useful when working directly with a struct, or needing to iterate over all particles.
|
||||
*
|
||||
* \return Pointer to the buffer
|
||||
*
|
||||
* \see GetParticleCount
|
||||
*/
|
||||
inline void* ParticleGroup::GetBuffer()
|
||||
{
|
||||
return m_buffer.data();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a raw pointer to the particle buffer
|
||||
*
|
||||
* This can be useful when working directly with a struct, or needing to iterate over all particles.
|
||||
*
|
||||
* \return Pointer to the buffer
|
||||
*
|
||||
* \see GetParticleCount
|
||||
*/
|
||||
inline const void* ParticleGroup::GetBuffer() const
|
||||
{
|
||||
return m_buffer.data();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PARTICLEMAPPER_HPP
|
||||
#define NAZARA_PARTICLEMAPPER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/SparsePtr.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
#include <Nazara/Graphics/ParticleDeclaration.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_GRAPHICS_API ParticleMapper
|
||||
{
|
||||
public:
|
||||
ParticleMapper(void* buffer, const ParticleDeclaration* declaration);
|
||||
~ParticleMapper();
|
||||
|
||||
template<typename T> SparsePtr<T> GetComponentPtr(ParticleComponent component);
|
||||
template<typename T> SparsePtr<const T> GetComponentPtr(ParticleComponent component) const;
|
||||
inline void* GetPointer();
|
||||
|
||||
private:
|
||||
const ParticleDeclaration* m_declaration;
|
||||
UInt8* m_ptr;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/ParticleMapper.inl>
|
||||
|
||||
#endif // NAZARA_PARTICLEMAPPER_HPP
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
#include <Nazara/Utility/Algorithm.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Gets a pointer to iterate through same components
|
||||
* \return SparsePtr pointing to same components
|
||||
*
|
||||
* \param component Component to get in the declaration
|
||||
*
|
||||
* \remark The same components are not continguous but separated by sizeof(ParticleSize)
|
||||
* \remark Produces a NazaraError if component is disabled
|
||||
*/
|
||||
|
||||
template <typename T>
|
||||
SparsePtr<T> ParticleMapper::GetComponentPtr(ParticleComponent component)
|
||||
{
|
||||
// Then the component that are interesting
|
||||
bool enabled;
|
||||
ComponentType type;
|
||||
std::size_t offset;
|
||||
m_declaration->GetComponent(component, &enabled, &type, &offset);
|
||||
|
||||
if (enabled && GetComponentTypeOf<T>() == type)
|
||||
{
|
||||
///TODO: Check the ratio between the type of the attribute and the template type ?
|
||||
return SparsePtr<T>(m_ptr + offset, m_declaration->GetStride());
|
||||
}
|
||||
else
|
||||
{
|
||||
NazaraError("Attribute 0x" + String::Number(component, 16) + " is not enabled");
|
||||
return SparsePtr<T>();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a pointer to iterate through same components
|
||||
* \return SparsePtr pointing to same components
|
||||
*
|
||||
* \param component Component to get in the declaration
|
||||
*
|
||||
* \remark The same components are not continguous but separated by sizeof(ParticleSize)
|
||||
* \remark Produces a NazaraError if component is disabled
|
||||
*/
|
||||
|
||||
template <typename T>
|
||||
SparsePtr<const T> ParticleMapper::GetComponentPtr(ParticleComponent component) const
|
||||
{
|
||||
// Then the component that are interesting
|
||||
bool enabled;
|
||||
ComponentType type;
|
||||
std::size_t offset;
|
||||
m_declaration->GetComponent(component, &enabled, &type, &offset);
|
||||
|
||||
if (enabled && GetComponentTypeOf<T>() == type)
|
||||
{
|
||||
///TODO: Check the ratio between the type of the attribute and the template type ?
|
||||
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>();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a raw pointer to the particle buffer
|
||||
*
|
||||
* This can be useful when working directly with a struct
|
||||
*
|
||||
* \return Pointer to the buffer
|
||||
*/
|
||||
inline void* ParticleMapper::GetPointer()
|
||||
{
|
||||
return m_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PARTICLERENDERER_HPP
|
||||
#define NAZARA_PARTICLERENDERER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractRenderQueue;
|
||||
class ParticleMapper;
|
||||
class ParticleRenderer;
|
||||
class ParticleGroup;
|
||||
|
||||
using ParticleRendererConstRef = ObjectRef<const ParticleRenderer>;
|
||||
using ParticleRendererLibrary = ObjectLibrary<ParticleRenderer>;
|
||||
using ParticleRendererRef = ObjectRef<ParticleRenderer>;
|
||||
|
||||
class NAZARA_GRAPHICS_API ParticleRenderer : public RefCounted
|
||||
{
|
||||
friend ParticleRendererLibrary;
|
||||
friend class Graphics;
|
||||
|
||||
public:
|
||||
ParticleRenderer() = default;
|
||||
ParticleRenderer(const ParticleRenderer& renderer);
|
||||
virtual ~ParticleRenderer();
|
||||
|
||||
virtual void Render(const ParticleGroup& system, const ParticleMapper& mapper, unsigned int startId, unsigned int endId, AbstractRenderQueue* renderQueue) = 0;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnParticleRendererRelease, const ParticleRenderer* /*particleRenderer*/);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
static ParticleRendererLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PARTICLERENDERER_HPP
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PARTICLESTRUCT_HPP
|
||||
#define NAZARA_PARTICLESTRUCT_HPP
|
||||
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct ParticleStruct_Billboard
|
||||
{
|
||||
Color color;
|
||||
Vector2f size;
|
||||
Vector3f normal;
|
||||
Vector3f position;
|
||||
Vector3f velocity;
|
||||
float life;
|
||||
float rotation;
|
||||
};
|
||||
|
||||
struct ParticleStruct_Model
|
||||
{
|
||||
Quaternionf rotation;
|
||||
Vector3f position;
|
||||
Vector3f velocity;
|
||||
float life;
|
||||
};
|
||||
|
||||
struct ParticleStruct_Sprite
|
||||
{
|
||||
Color color;
|
||||
Vector3f position;
|
||||
Vector3f velocity;
|
||||
float life;
|
||||
float rotation;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PARTICLESTRUCT_HPP
|
||||
|
|
@ -1,101 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_RENDERQUEUE_HPP
|
||||
#define NAZARA_RENDERQUEUE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class RenderQueueInternal
|
||||
{
|
||||
public:
|
||||
using Index = Nz::UInt64;
|
||||
|
||||
RenderQueueInternal() = default;
|
||||
RenderQueueInternal(const RenderQueueInternal&) = default;
|
||||
RenderQueueInternal(RenderQueueInternal&&) = default;
|
||||
~RenderQueueInternal() = default;
|
||||
|
||||
RenderQueueInternal& operator=(const RenderQueueInternal&) = default;
|
||||
RenderQueueInternal& operator=(RenderQueueInternal&&) = default;
|
||||
|
||||
protected:
|
||||
using RenderDataPair = std::pair<Index, std::size_t>;
|
||||
|
||||
void Sort();
|
||||
|
||||
std::vector<RenderDataPair> m_orderedRenderQueue;
|
||||
};
|
||||
|
||||
template<typename RenderData>
|
||||
class RenderQueue : public RenderQueueInternal
|
||||
{
|
||||
public:
|
||||
class const_iterator;
|
||||
friend const_iterator;
|
||||
using size_type = std::size_t;
|
||||
|
||||
RenderQueue() = default;
|
||||
RenderQueue(const RenderQueue&) = default;
|
||||
RenderQueue(RenderQueue&&) noexcept = default;
|
||||
~RenderQueue() = default;
|
||||
|
||||
void Clear();
|
||||
|
||||
void Insert(RenderData&& data);
|
||||
|
||||
template<typename IndexFunc> void Sort(IndexFunc&& func);
|
||||
|
||||
// STL API
|
||||
inline const_iterator begin() const;
|
||||
inline bool empty() const;
|
||||
inline const_iterator end() const;
|
||||
inline size_type size() const;
|
||||
|
||||
RenderQueue& operator=(const RenderQueue&) = default;
|
||||
RenderQueue& operator=(RenderQueue&&) noexcept = default;
|
||||
|
||||
private:
|
||||
const RenderData& GetData(std::size_t i) const;
|
||||
|
||||
std::vector<RenderData> m_data;
|
||||
};
|
||||
|
||||
template<typename RenderData>
|
||||
class RenderQueue<RenderData>::const_iterator : public std::iterator<std::forward_iterator_tag, const RenderData>
|
||||
{
|
||||
friend RenderQueue;
|
||||
|
||||
public:
|
||||
const_iterator(const const_iterator& it);
|
||||
|
||||
const RenderData& operator*() const;
|
||||
|
||||
const_iterator& operator=(const const_iterator& it);
|
||||
const_iterator& operator++();
|
||||
const_iterator operator++(int);
|
||||
|
||||
bool operator==(const const_iterator& rhs) const;
|
||||
bool operator!=(const const_iterator& rhs) const;
|
||||
|
||||
void swap(const_iterator& rhs);
|
||||
|
||||
private:
|
||||
const_iterator(const RenderQueue* queue, std::size_t nextId);
|
||||
|
||||
std::size_t m_nextDataId;
|
||||
const RenderQueue* m_queue;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/RenderQueue.inl>
|
||||
|
||||
#endif // NAZARA_RENDERQUEUE_HPP
|
||||
|
|
@ -1,136 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/RenderQueue.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename RenderData>
|
||||
void RenderQueue<RenderData>::Clear()
|
||||
{
|
||||
m_orderedRenderQueue.clear();
|
||||
m_data.clear();
|
||||
}
|
||||
|
||||
template<typename RenderData>
|
||||
void RenderQueue<RenderData>::Insert(RenderData&& data)
|
||||
{
|
||||
m_data.emplace_back(std::move(data));
|
||||
}
|
||||
|
||||
template<typename RenderData>
|
||||
template<typename IndexFunc>
|
||||
void RenderQueue<RenderData>::Sort(IndexFunc&& func)
|
||||
{
|
||||
m_orderedRenderQueue.clear();
|
||||
m_orderedRenderQueue.reserve(m_data.size());
|
||||
|
||||
std::size_t dataIndex = 0;
|
||||
for (const RenderData& renderData : m_data)
|
||||
m_orderedRenderQueue.emplace_back(func(renderData), dataIndex++);
|
||||
|
||||
RenderQueueInternal::Sort();
|
||||
}
|
||||
|
||||
template<typename RenderData>
|
||||
typename RenderQueue<RenderData>::const_iterator RenderQueue<RenderData>::begin() const
|
||||
{
|
||||
return const_iterator(this, 0);
|
||||
}
|
||||
|
||||
template<typename RenderData>
|
||||
bool RenderQueue<RenderData>::empty() const
|
||||
{
|
||||
return m_orderedRenderQueue.empty();
|
||||
}
|
||||
|
||||
template<typename RenderData>
|
||||
typename RenderQueue<RenderData>::const_iterator RenderQueue<RenderData>::end() const
|
||||
{
|
||||
return const_iterator(this, m_orderedRenderQueue.size());
|
||||
}
|
||||
|
||||
template<typename RenderData>
|
||||
typename RenderQueue<RenderData>::size_type RenderQueue<RenderData>::size() const
|
||||
{
|
||||
return m_orderedRenderQueue.size();
|
||||
}
|
||||
|
||||
template<typename RenderData>
|
||||
const RenderData& RenderQueue<RenderData>::GetData(std::size_t i) const
|
||||
{
|
||||
NazaraAssert(i < m_orderedRenderQueue.size(), "Cannot dereference post-end iterator");
|
||||
|
||||
return m_data[m_orderedRenderQueue[i].second];
|
||||
}
|
||||
|
||||
|
||||
template<typename RenderData>
|
||||
RenderQueue<RenderData>::const_iterator::const_iterator(const RenderQueue* queue, std::size_t nextId) :
|
||||
m_nextDataId(nextId),
|
||||
m_queue(queue)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename RenderData>
|
||||
RenderQueue<RenderData>::const_iterator::const_iterator(const const_iterator& it) :
|
||||
m_nextDataId(it.m_nextDataId),
|
||||
m_queue(it.m_queue)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename RenderData>
|
||||
const RenderData& RenderQueue<RenderData>::const_iterator::operator*() const
|
||||
{
|
||||
return m_queue->GetData(m_nextDataId);
|
||||
}
|
||||
|
||||
template<typename RenderData>
|
||||
typename RenderQueue<RenderData>::const_iterator& RenderQueue<RenderData>::const_iterator::operator=(const const_iterator& it)
|
||||
{
|
||||
m_nextDataId = it.m_nextDataId;
|
||||
m_queue = it.m_queue;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename RenderData>
|
||||
typename RenderQueue<RenderData>::const_iterator& RenderQueue<RenderData>::const_iterator::operator++()
|
||||
{
|
||||
++m_nextDataId;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename RenderData>
|
||||
typename RenderQueue<RenderData>::const_iterator RenderQueue<RenderData>::const_iterator::operator++(int)
|
||||
{
|
||||
return iterator(m_queue, m_nextDataId++);
|
||||
}
|
||||
|
||||
template<typename RenderData>
|
||||
bool RenderQueue<RenderData>::const_iterator::operator==(const typename RenderQueue<RenderData>::const_iterator& rhs) const
|
||||
{
|
||||
NazaraAssert(m_queue == rhs.m_queue, "Cannot compare iterator coming from different queues");
|
||||
|
||||
return m_nextDataId == rhs.m_nextDataId;
|
||||
}
|
||||
|
||||
template<typename RenderData>
|
||||
bool RenderQueue<RenderData>::const_iterator::operator!=(const typename RenderQueue<RenderData>::const_iterator& rhs) const
|
||||
{
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
template<typename RenderData>
|
||||
void RenderQueue<RenderData>::const_iterator::swap(typename RenderQueue<RenderData>::const_iterator& rhs)
|
||||
{
|
||||
NazaraAssert(m_queue == rhs.m_queue, "Cannot swap iterator coming from different queues");
|
||||
|
||||
using std::swap;
|
||||
|
||||
swap(m_nextDataId, rhs.m_nextDataId);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_RENDERTECHNIQUES_HPP
|
||||
#define NAZARA_RENDERTECHNIQUES_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractRenderTechnique;
|
||||
|
||||
class NAZARA_GRAPHICS_API RenderTechniques
|
||||
{
|
||||
public:
|
||||
using RenderTechniqueFactory = AbstractRenderTechnique* (*)();
|
||||
|
||||
RenderTechniques() = delete;
|
||||
~RenderTechniques() = delete;
|
||||
|
||||
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 std::size_t GetCount();
|
||||
|
||||
static void Register(const String& name, int ranking, RenderTechniqueFactory factory);
|
||||
|
||||
static String ToString(RenderTechniqueType renderTechnique);
|
||||
|
||||
static void Unregister(const String& name);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_RENDERTECHNIQUES_HPP
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_RENDERABLE_HPP
|
||||
#define NAZARA_RENDERABLE_HPP
|
||||
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Math/BoundingVolume.hpp>
|
||||
#include <Nazara/Math/Frustum.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractRenderQueue;
|
||||
|
||||
class NAZARA_GRAPHICS_API Renderable
|
||||
{
|
||||
public:
|
||||
Renderable() = default;
|
||||
Renderable(const Renderable& renderable) = default;
|
||||
Renderable(Renderable&&) noexcept = default;
|
||||
virtual ~Renderable();
|
||||
|
||||
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);
|
||||
|
||||
Renderable& operator=(const Renderable& renderable) = default;
|
||||
Renderable& operator=(Renderable&& renderable) noexcept = default;
|
||||
|
||||
protected:
|
||||
virtual void MakeBoundingVolume() const = 0;
|
||||
inline void InvalidateBoundingVolume();
|
||||
|
||||
mutable BoundingVolumef m_boundingVolume;
|
||||
|
||||
private:
|
||||
inline void UpdateBoundingVolume() const;
|
||||
|
||||
mutable bool m_boundingVolumeUpdated;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/Renderable.inl>
|
||||
|
||||
#endif // NAZARA_RENDERABLE_HPP
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Ensures that the bounding volume is up to date
|
||||
*/
|
||||
|
||||
inline void Renderable::EnsureBoundingVolumeUpdated() const
|
||||
{
|
||||
if (!m_boundingVolumeUpdated)
|
||||
UpdateBoundingVolume();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invalidates the bounding volume
|
||||
*/
|
||||
|
||||
inline void Renderable::InvalidateBoundingVolume()
|
||||
{
|
||||
m_boundingVolumeUpdated = false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Updates the bounding volume
|
||||
*/
|
||||
|
||||
inline void Renderable::UpdateBoundingVolume() const
|
||||
{
|
||||
MakeBoundingVolume();
|
||||
m_boundingVolumeUpdated = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SCENEDATA_HPP
|
||||
#define NAZARA_SCENEDATA_HPP
|
||||
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractBackground;
|
||||
class AbstractViewer;
|
||||
class Texture;
|
||||
|
||||
struct SceneData
|
||||
{
|
||||
Color ambientColor;
|
||||
const AbstractBackground* background;
|
||||
const AbstractViewer* viewer;
|
||||
Texture* globalReflectionTexture;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_SCENEDATA_HPP
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SKELETALMODEL_HPP
|
||||
#define NAZARA_SKELETALMODEL_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/Updatable.hpp>
|
||||
#include <Nazara/Graphics/Model.hpp>
|
||||
#include <Nazara/Utility/Animation.hpp>
|
||||
#include <Nazara/Utility/Skeleton.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct NAZARA_GRAPHICS_API SkeletalModelParameters : ModelParameters
|
||||
{
|
||||
bool loadAnimation = true;
|
||||
AnimationParams animation;
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
class SkeletalModel;
|
||||
|
||||
using SkeletalModelRef = ObjectRef<SkeletalModel>;
|
||||
|
||||
class NAZARA_GRAPHICS_API SkeletalModel : public Model, Updatable
|
||||
{
|
||||
public:
|
||||
SkeletalModel();
|
||||
SkeletalModel(const SkeletalModel& model) = default;
|
||||
SkeletalModel(SkeletalModel&& model) = default;
|
||||
~SkeletalModel() = default;
|
||||
|
||||
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override;
|
||||
void AdvanceAnimation(float elapsedTime);
|
||||
|
||||
std::unique_ptr<InstancedRenderable> Clone() const override;
|
||||
SkeletalModel* Create() const;
|
||||
|
||||
void EnableAnimation(bool animation);
|
||||
|
||||
Animation* GetAnimation() const;
|
||||
Skeleton* GetSkeleton();
|
||||
const Skeleton* GetSkeleton() const;
|
||||
|
||||
bool HasAnimation() const;
|
||||
|
||||
bool IsAnimated() const override;
|
||||
bool IsAnimationEnabled() const;
|
||||
|
||||
bool SetAnimation(Animation* animation);
|
||||
void SetMesh(Mesh* mesh) override;
|
||||
bool SetSequence(const String& sequenceName);
|
||||
void SetSequence(unsigned int sequenceIndex);
|
||||
|
||||
SkeletalModel& operator=(const SkeletalModel& node) = default;
|
||||
SkeletalModel& operator=(SkeletalModel&& node) = default;
|
||||
|
||||
template<typename... Args> static SkeletalModelRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
void MakeBoundingVolume() const override;
|
||||
/*void Register() override;
|
||||
void Unregister() override;*/
|
||||
void Update() override;
|
||||
|
||||
AnimationRef m_animation;
|
||||
Skeleton m_skeleton;
|
||||
const Sequence* m_currentSequence;
|
||||
bool m_animationEnabled;
|
||||
float m_interpolation;
|
||||
unsigned int m_currentFrame;
|
||||
unsigned int m_nextFrame;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/SkeletalModel.inl>
|
||||
|
||||
#endif // NAZARA_SKELETALMODEL_HPP
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/SkeletalModel.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Creates a new SkeletalModel from the arguments
|
||||
* \return A reference to the newly created SkeletalModel
|
||||
*
|
||||
* \param args Arguments for the skeletal model
|
||||
*/
|
||||
template<typename... Args>
|
||||
SkeletalModelRef SkeletalModel::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<SkeletalModel> object(new SkeletalModel(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SKINNINGMANAGER_HPP
|
||||
#define NAZARA_SKINNINGMANAGER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Skeleton;
|
||||
class SkeletalMesh;
|
||||
class VertexBuffer;
|
||||
|
||||
class NAZARA_GRAPHICS_API SkinningManager
|
||||
{
|
||||
friend class Graphics;
|
||||
|
||||
public:
|
||||
using SkinFunction = void (*)(const SkeletalMesh* mesh, const Skeleton* skeleton, VertexBuffer* buffer);
|
||||
|
||||
SkinningManager() = delete;
|
||||
~SkinningManager() = delete;
|
||||
|
||||
static VertexBuffer* GetBuffer(const SkeletalMesh* mesh, const Skeleton* skeleton);
|
||||
static void Skin();
|
||||
|
||||
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
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SKYBOXBACKGROUND_HPP
|
||||
#define NAZARA_SKYBOXBACKGROUND_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractViewer;
|
||||
class SkyboxBackground;
|
||||
|
||||
using SkyboxBackgroundConstRef = ObjectRef<const SkyboxBackground>;
|
||||
using SkyboxBackgroundRef = ObjectRef<SkyboxBackground>;
|
||||
|
||||
class NAZARA_GRAPHICS_API SkyboxBackground : public AbstractBackground
|
||||
{
|
||||
friend class Graphics;
|
||||
|
||||
public:
|
||||
SkyboxBackground(TextureRef cubemapTexture = TextureRef());
|
||||
~SkyboxBackground() = default;
|
||||
|
||||
void Draw(const AbstractViewer* viewer) const override;
|
||||
|
||||
BackgroundType GetBackgroundType() const override;
|
||||
inline const Vector3f& GetMovementOffset() const;
|
||||
inline float GetMovementScale() const;
|
||||
inline const TextureRef& GetTexture() const;
|
||||
inline TextureSampler& GetTextureSampler();
|
||||
inline const TextureSampler& GetTextureSampler() const;
|
||||
|
||||
inline void SetMovementOffset(const Vector3f& offset);
|
||||
inline void SetMovementScale(float scale);
|
||||
inline void SetTexture(TextureRef cubemapTexture);
|
||||
inline void SetTextureSampler(const TextureSampler& sampler);
|
||||
|
||||
template<typename... Args> static SkyboxBackgroundRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
TextureRef m_texture;
|
||||
TextureSampler m_sampler;
|
||||
Vector3f m_movementOffset;
|
||||
float m_movementScale;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/SkyboxBackground.inl>
|
||||
|
||||
#endif // NAZARA_SKYBOXBACKGROUND_HPP
|
||||
|
|
@ -1,128 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Gets the movement offset
|
||||
* \return Offset of the movement
|
||||
*/
|
||||
|
||||
inline const Vector3f& Nz::SkyboxBackground::GetMovementOffset() const
|
||||
{
|
||||
return m_movementOffset;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the movement scale
|
||||
* \return Scale of the movement
|
||||
*/
|
||||
|
||||
inline float SkyboxBackground::GetMovementScale() const
|
||||
{
|
||||
return m_movementScale;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the texture of the background
|
||||
* \return Texture of the background
|
||||
*/
|
||||
|
||||
inline const TextureRef& SkyboxBackground::GetTexture() const
|
||||
{
|
||||
return m_texture;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the texture sampler of the background
|
||||
* \return A reference to the texture sampler of the background
|
||||
*/
|
||||
|
||||
inline TextureSampler& SkyboxBackground::GetTextureSampler()
|
||||
{
|
||||
return m_sampler;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the texture sampler of the background
|
||||
* \return A constant reference to the texture sampler of the background
|
||||
*/
|
||||
|
||||
inline const TextureSampler& SkyboxBackground::GetTextureSampler() const
|
||||
{
|
||||
return m_sampler;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the movement offset
|
||||
*
|
||||
* \param offset Offset of the movement
|
||||
*/
|
||||
|
||||
inline void SkyboxBackground::SetMovementOffset(const Vector3f& offset)
|
||||
{
|
||||
NazaraAssert(std::isfinite(offset.x) && std::isfinite(offset.y) && std::isfinite(offset.z), "Offset must be a finite vector");
|
||||
|
||||
m_movementOffset = offset;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the movement scale
|
||||
*
|
||||
* \param scale Scale of the movement
|
||||
*/
|
||||
|
||||
inline void SkyboxBackground::SetMovementScale(float scale)
|
||||
{
|
||||
NazaraAssert(std::isfinite(scale), "Scale must be a finite value");
|
||||
|
||||
m_movementScale = scale;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the texture of the background
|
||||
*
|
||||
* \param cubemapTexture Texture of the background
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the texture sampler of the background
|
||||
*
|
||||
* \param sampler Texture sampler of the background
|
||||
*/
|
||||
|
||||
void SkyboxBackground::SetTextureSampler(const TextureSampler& sampler)
|
||||
{
|
||||
m_sampler = sampler;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a new skybox background from the arguments
|
||||
* \return A reference to the newly created skybox background
|
||||
*
|
||||
* \param args Arguments for the skybox background
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SPRITE_HPP
|
||||
#define NAZARA_SPRITE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <array>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Sprite;
|
||||
|
||||
using SpriteConstRef = ObjectRef<const Sprite>;
|
||||
using SpriteLibrary = ObjectLibrary<Sprite>;
|
||||
using SpriteRef = ObjectRef<Sprite>;
|
||||
|
||||
class NAZARA_GRAPHICS_API Sprite : public InstancedRenderable
|
||||
{
|
||||
friend SpriteLibrary;
|
||||
friend class Graphics;
|
||||
|
||||
public:
|
||||
inline Sprite();
|
||||
inline Sprite(MaterialRef material);
|
||||
inline Sprite(Texture* texture);
|
||||
Sprite(const Sprite&) = default;
|
||||
Sprite(Sprite&&) = delete;
|
||||
~Sprite() = default;
|
||||
|
||||
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override;
|
||||
|
||||
std::unique_ptr<InstancedRenderable> Clone() const override;
|
||||
|
||||
inline const Color& GetColor() const;
|
||||
inline const Color& GetCornerColor(RectCorner corner) const;
|
||||
inline const Vector3f& GetOrigin() const;
|
||||
inline const Vector2f& GetSize() const;
|
||||
inline const Rectf& GetTextureCoords() const;
|
||||
|
||||
inline void SetColor(const Color& color);
|
||||
inline void SetCornerColor(RectCorner corner, const Color& color);
|
||||
inline void SetDefaultMaterial();
|
||||
inline void SetMaterial(MaterialRef material, bool resizeSprite = true);
|
||||
bool SetMaterial(std::string materialName, bool resizeSprite = true);
|
||||
inline void SetMaterial(std::size_t skinIndex, MaterialRef material, bool resizeSprite = true);
|
||||
bool SetMaterial(std::size_t skinIndex, std::string materialName, bool resizeSprite = true);
|
||||
inline void SetOrigin(const Vector3f& origin);
|
||||
inline void SetSize(const Vector2f& size);
|
||||
inline void SetSize(float sizeX, float sizeY);
|
||||
bool SetTexture(std::string textureName, bool resizeSprite = true);
|
||||
inline void SetTexture(TextureRef texture, bool resizeSprite = true);
|
||||
bool SetTexture(std::size_t skinIndex, std::string textureName, bool resizeSprite = true);
|
||||
inline void SetTexture(std::size_t skinIndex, TextureRef texture, bool resizeSprite = true);
|
||||
inline void SetTextureCoords(const Rectf& coords);
|
||||
inline void SetTextureRect(const Rectui& rect);
|
||||
|
||||
inline Sprite& operator=(const Sprite& sprite);
|
||||
Sprite& operator=(Sprite&& sprite) = delete;
|
||||
|
||||
template<typename... Args> static SpriteRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
inline void InvalidateVertices();
|
||||
void MakeBoundingVolume() const override;
|
||||
void UpdateData(InstanceData* instanceData) const override;
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
std::array<Color, 4> m_cornerColor;
|
||||
Color m_color;
|
||||
Rectf m_textureCoords;
|
||||
Vector2f m_size;
|
||||
Vector3f m_origin;
|
||||
|
||||
static SpriteLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/Sprite.inl>
|
||||
|
||||
#endif // NAZARA_SPRITE_HPP
|
||||
|
|
@ -1,374 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a Sprite object by default
|
||||
*/
|
||||
|
||||
inline Sprite::Sprite() :
|
||||
m_color(Color::White),
|
||||
m_textureCoords(0.f, 0.f, 1.f, 1.f),
|
||||
m_size(64.f, 64.f),
|
||||
m_origin(Nz::Vector3f::Zero())
|
||||
{
|
||||
ResetMaterials(1);
|
||||
|
||||
for (Color& color : m_cornerColor)
|
||||
color = Color::White;
|
||||
|
||||
SetDefaultMaterial();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Sprite object with a reference to a material
|
||||
*
|
||||
* \param material Reference to a material
|
||||
*/
|
||||
inline Sprite::Sprite(MaterialRef material) :
|
||||
Sprite()
|
||||
{
|
||||
SetMaterial(std::move(material), true);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Sprite object with a pointer to a texture
|
||||
*
|
||||
* \param texture Pointer to a texture
|
||||
*/
|
||||
|
||||
inline Sprite::Sprite(Texture* texture) :
|
||||
Sprite()
|
||||
{
|
||||
SetTexture(texture, true);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the color of the sprite
|
||||
*
|
||||
* This is the global color of the sprite, independent from corner colors
|
||||
*
|
||||
* \return Current color
|
||||
*
|
||||
* \see GetCornerColor
|
||||
* \see SetColor
|
||||
*/
|
||||
inline const Color& Sprite::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the color setup on a corner of the sprite
|
||||
*
|
||||
* \return Current color
|
||||
*
|
||||
* \param corner Corner of the sprite to query
|
||||
*
|
||||
* \see SetCornerColor
|
||||
*/
|
||||
inline const Color& Sprite::GetCornerColor(RectCorner corner) const
|
||||
{
|
||||
NazaraAssert(static_cast<std::size_t>(corner) < m_cornerColor.size(), "Invalid corner");
|
||||
|
||||
return m_cornerColor[corner];
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the origin of the sprite
|
||||
*
|
||||
* \return Current material
|
||||
*
|
||||
* \see SetOrigin
|
||||
*/
|
||||
inline const Vector3f& Sprite::GetOrigin() const
|
||||
{
|
||||
return m_origin;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the size of the sprite
|
||||
* \return Current size
|
||||
*/
|
||||
|
||||
inline const Vector2f& Sprite::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the texture coordinates of the sprite
|
||||
* \return Current texture coordinates
|
||||
*/
|
||||
inline const Rectf& Sprite::GetTextureCoords() const
|
||||
{
|
||||
return m_textureCoords;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the global color of the sprite
|
||||
*
|
||||
* This is independent from the corner color of the sprite
|
||||
*
|
||||
* \param color Color for the sprite
|
||||
*
|
||||
* \see GetColor
|
||||
* \see SetCornerColor
|
||||
*/
|
||||
inline void Sprite::SetColor(const Color& color)
|
||||
{
|
||||
m_color = color;
|
||||
|
||||
InvalidateVertices();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets a color for a corner of the sprite
|
||||
*
|
||||
* This is independent from the sprite global color, which gets multiplied by the corner color when rendering the sprite.
|
||||
*
|
||||
* \param corner Corner of the sprite to set
|
||||
* \param color Color for the sprite
|
||||
*
|
||||
* \see GetCornerColor
|
||||
* \see SetColor
|
||||
*/
|
||||
inline void Sprite::SetCornerColor(RectCorner corner, const Color& color)
|
||||
{
|
||||
NazaraAssert(static_cast<std::size_t>(corner) < m_cornerColor.size(), "Invalid corner");
|
||||
|
||||
m_cornerColor[corner] = color;
|
||||
|
||||
InvalidateVertices();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the default material of the sprite (just default material)
|
||||
*/
|
||||
|
||||
inline void Sprite::SetDefaultMaterial()
|
||||
{
|
||||
MaterialRef material = Material::New();
|
||||
material->EnableFaceCulling(false);
|
||||
material->EnableScissorTest(true);
|
||||
|
||||
SetMaterial(std::move(material));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Changes the material of the sprite
|
||||
*
|
||||
* \param material Material for the sprite
|
||||
* \param resizeSprite Should billboard be resized to the material size (diffuse map)
|
||||
*/
|
||||
inline void Sprite::SetMaterial(MaterialRef material, bool resizeSprite)
|
||||
{
|
||||
SetMaterial(GetSkin(), std::move(material), resizeSprite);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the material of the sprite
|
||||
*
|
||||
* \param skinIndex Skin index to change
|
||||
* \param material Material for the sprite
|
||||
* \param resizeBillboard Should billboard be resized to the material size (diffuse map)
|
||||
*/
|
||||
inline void Sprite::SetMaterial(std::size_t skinIndex, MaterialRef material, bool resizeSprite)
|
||||
{
|
||||
InstancedRenderable::SetMaterial(skinIndex, 0, std::move(material));
|
||||
|
||||
if (resizeSprite)
|
||||
{
|
||||
if (const MaterialRef& newMat = GetMaterial())
|
||||
{
|
||||
const TextureRef& diffuseMap = newMat->GetDiffuseMap();
|
||||
if (diffuseMap && diffuseMap->IsValid())
|
||||
SetSize(Vector2f(Vector2ui(diffuseMap->GetSize())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the origin of the sprite
|
||||
*
|
||||
* The origin is the center of translation/rotation/scaling of the sprite.
|
||||
*
|
||||
* \param origin New origin for the sprite
|
||||
*
|
||||
* \see GetOrigin
|
||||
*/
|
||||
inline void Sprite::SetOrigin(const Vector3f& origin)
|
||||
{
|
||||
m_origin = origin;
|
||||
|
||||
// On invalide la bounding box
|
||||
InvalidateBoundingVolume();
|
||||
InvalidateVertices();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the size of the sprite
|
||||
*
|
||||
* \param size Size for the sprite
|
||||
*/
|
||||
|
||||
inline void Sprite::SetSize(const Vector2f& size)
|
||||
{
|
||||
m_size = size;
|
||||
|
||||
// On invalide la bounding box
|
||||
InvalidateBoundingVolume();
|
||||
InvalidateVertices();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the size of the sprite
|
||||
*
|
||||
* \param sizeX Size in X for the sprite
|
||||
* \param sizeY Size in Y for the sprite
|
||||
*/
|
||||
|
||||
inline void Sprite::SetSize(float sizeX, float sizeY)
|
||||
{
|
||||
SetSize(Vector2f(sizeX, sizeY));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the texture of the sprite for the current skin
|
||||
*
|
||||
* This function changes the diffuse map of the material associated with the current skin
|
||||
*
|
||||
* \param texture Texture for the sprite
|
||||
* \param resizeSprite Should the sprite be resized to the texture size?
|
||||
*
|
||||
* \remark The sprite material gets copied to prevent accidentally changing other drawable materials
|
||||
*/
|
||||
inline void Sprite::SetTexture(TextureRef texture, bool resizeSprite)
|
||||
{
|
||||
SetTexture(GetSkin(), std::move(texture), resizeSprite);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the texture of the sprite for a specific skin
|
||||
*
|
||||
* This function changes the diffuse map of the material associated with the specified skin
|
||||
*
|
||||
* \param skinIndex Skin index to change
|
||||
* \param texture Texture for the sprite
|
||||
* \param resizeSprite Should the sprite be resized to the texture size?
|
||||
*
|
||||
* \remark The sprite material gets copied to prevent accidentally changing other drawable materials
|
||||
*/
|
||||
inline void Sprite::SetTexture(std::size_t skinIndex, TextureRef texture, bool resizeSprite)
|
||||
{
|
||||
const MaterialRef& material = GetMaterial(skinIndex);
|
||||
|
||||
if (material->GetReferenceCount() > 1)
|
||||
{
|
||||
MaterialRef newMat = Material::New(*material); // Copy
|
||||
newMat->SetDiffuseMap(std::move(texture));
|
||||
|
||||
SetMaterial(skinIndex, std::move(newMat), resizeSprite);
|
||||
}
|
||||
else
|
||||
{
|
||||
material->SetDiffuseMap(std::move(texture));
|
||||
const TextureRef& newTexture = material->GetDiffuseMap();
|
||||
|
||||
if (resizeSprite && newTexture && newTexture->IsValid())
|
||||
SetSize(Vector2f(Vector2ui(newTexture->GetSize())));
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the texture coordinates of the sprite
|
||||
*
|
||||
* \param coords Texture coordinates
|
||||
*/
|
||||
|
||||
inline void Sprite::SetTextureCoords(const Rectf& coords)
|
||||
{
|
||||
m_textureCoords = coords;
|
||||
|
||||
InvalidateVertices();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the texture rectangle of the sprite
|
||||
*
|
||||
* \param rect Rectangles symbolizing the size of the texture
|
||||
*
|
||||
* \remark Produces a NazaraAssert if material is invalid
|
||||
* \remark Produces a NazaraAssert if material has no diffuse map
|
||||
*/
|
||||
|
||||
inline void Sprite::SetTextureRect(const Rectui& rect)
|
||||
{
|
||||
const MaterialRef& material = GetMaterial();
|
||||
NazaraAssert(material->HasDiffuseMap(), "Sprite material has no diffuse map");
|
||||
|
||||
Texture* diffuseMap = 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));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the current sprite with the content of the other one
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param sprite The other Sprite
|
||||
*/
|
||||
|
||||
inline Sprite& Sprite::operator=(const Sprite& sprite)
|
||||
{
|
||||
InstancedRenderable::operator=(sprite);
|
||||
|
||||
m_color = sprite.m_color;
|
||||
m_origin = sprite.m_origin;
|
||||
m_textureCoords = sprite.m_textureCoords;
|
||||
m_size = sprite.m_size;
|
||||
|
||||
// We do not copy final vertices because it's highly probable that our parameters are modified and they must be regenerated
|
||||
InvalidateBoundingVolume();
|
||||
InvalidateVertices();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invalidates the vertices
|
||||
*/
|
||||
|
||||
inline void Sprite::InvalidateVertices()
|
||||
{
|
||||
InvalidateInstanceData(0);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a new sprite from the arguments
|
||||
* \return A reference to the newly created sprite
|
||||
*
|
||||
* \param args Arguments for the sprite
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_TEXTSPRITE_HPP
|
||||
#define NAZARA_TEXTSPRITE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||
#include <Nazara/Utility/AbstractAtlas.hpp>
|
||||
#include <Nazara/Utility/VertexStruct.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractTextDrawer;
|
||||
class TextSprite;
|
||||
|
||||
using TextSpriteConstRef = ObjectRef<const TextSprite>;
|
||||
using TextSpriteLibrary = ObjectLibrary<TextSprite>;
|
||||
using TextSpriteRef = ObjectRef<TextSprite>;
|
||||
|
||||
class NAZARA_GRAPHICS_API TextSprite : public InstancedRenderable
|
||||
{
|
||||
public:
|
||||
inline TextSprite();
|
||||
inline TextSprite(const AbstractTextDrawer& drawer);
|
||||
inline TextSprite(const TextSprite& sprite);
|
||||
~TextSprite() = default;
|
||||
|
||||
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override;
|
||||
|
||||
inline void Clear();
|
||||
|
||||
std::unique_ptr<InstancedRenderable> Clone() const override;
|
||||
|
||||
inline const Color& GetColor() const;
|
||||
inline float GetScale() const;
|
||||
|
||||
inline void SetColor(const Color& color);
|
||||
inline void SetDefaultMaterial();
|
||||
using InstancedRenderable::SetMaterial;
|
||||
inline void SetMaterial(MaterialRef material);
|
||||
inline void SetMaterial(std::size_t skinIndex, MaterialRef material);
|
||||
inline void SetScale(float scale);
|
||||
|
||||
void Update(const AbstractTextDrawer& drawer);
|
||||
|
||||
inline TextSprite& operator=(const TextSprite& text);
|
||||
|
||||
template<typename... Args> static TextSpriteRef New(Args&&... args);
|
||||
|
||||
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;
|
||||
|
||||
struct RenderKey
|
||||
{
|
||||
Texture* texture;
|
||||
int renderOrder;
|
||||
|
||||
bool operator==(const RenderKey& rhs) const
|
||||
{
|
||||
return texture == rhs.texture && renderOrder == rhs.renderOrder;
|
||||
}
|
||||
|
||||
bool operator!=(const RenderKey& rhs) const
|
||||
{
|
||||
return !operator==(rhs);
|
||||
}
|
||||
};
|
||||
|
||||
struct HashRenderKey
|
||||
{
|
||||
std::size_t operator()(const RenderKey& key) const
|
||||
{
|
||||
// Since renderOrder will be very small, this will be enough
|
||||
return std::hash<Texture*>()(key.texture) + key.renderOrder;
|
||||
}
|
||||
};
|
||||
|
||||
struct RenderIndices
|
||||
{
|
||||
unsigned int first;
|
||||
unsigned int count;
|
||||
};
|
||||
|
||||
struct AtlasSlots
|
||||
{
|
||||
bool used;
|
||||
NazaraSlot(AbstractAtlas, OnAtlasCleared, clearSlot);
|
||||
NazaraSlot(AbstractAtlas, OnAtlasLayerChange, layerChangeSlot);
|
||||
NazaraSlot(AbstractAtlas, OnAtlasRelease, releaseSlot);
|
||||
};
|
||||
|
||||
std::unordered_map<const AbstractAtlas*, AtlasSlots> m_atlases;
|
||||
mutable std::unordered_map<RenderKey, RenderIndices, HashRenderKey> m_renderInfos;
|
||||
mutable std::vector<VertexStruct_XY_Color_UV> m_localVertices;
|
||||
Color m_color;
|
||||
Rectf m_localBounds;
|
||||
float m_scale;
|
||||
|
||||
static TextSpriteLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/TextSprite.inl>
|
||||
|
||||
#endif // NAZARA_TEXTSPRITE_HPP
|
||||
|
|
@ -1,209 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a TextSprite object by default
|
||||
*/
|
||||
|
||||
inline TextSprite::TextSprite() :
|
||||
m_color(Color::White),
|
||||
m_localBounds(Nz::Rectf::Zero()),
|
||||
m_scale(1.f)
|
||||
{
|
||||
ResetMaterials(1U);
|
||||
|
||||
SetDefaultMaterial();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a TextSprite object with a drawer
|
||||
*
|
||||
* \param drawer Drawer used to compose text on the sprite
|
||||
*/
|
||||
|
||||
inline TextSprite::TextSprite(const AbstractTextDrawer& drawer) :
|
||||
TextSprite()
|
||||
{
|
||||
Update(drawer);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a TextSprite object by assignation
|
||||
*
|
||||
* \param sprite TextSprite to copy into this
|
||||
*/
|
||||
|
||||
inline TextSprite::TextSprite(const TextSprite& sprite) :
|
||||
InstancedRenderable(sprite),
|
||||
m_renderInfos(sprite.m_renderInfos),
|
||||
m_localVertices(sprite.m_localVertices),
|
||||
m_color(sprite.m_color),
|
||||
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& atlasSlots = m_atlases[atlas];
|
||||
|
||||
atlasSlots.clearSlot.Connect(atlas->OnAtlasCleared, this, &TextSprite::OnAtlasInvalidated);
|
||||
atlasSlots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, &TextSprite::OnAtlasLayerChange);
|
||||
atlasSlots.releaseSlot.Connect(atlas->OnAtlasRelease, this, &TextSprite::OnAtlasInvalidated);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Clears the data
|
||||
*/
|
||||
|
||||
inline void TextSprite::Clear()
|
||||
{
|
||||
m_atlases.clear();
|
||||
m_boundingVolume.MakeNull();
|
||||
m_localVertices.clear();
|
||||
m_renderInfos.clear();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the color of the text sprite
|
||||
* \return Current color
|
||||
*/
|
||||
|
||||
inline const Color& TextSprite::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the current scale of the text sprite
|
||||
* \return Current scale
|
||||
*/
|
||||
|
||||
inline float TextSprite::GetScale() const
|
||||
{
|
||||
return m_scale;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the color of the text sprite
|
||||
*
|
||||
* \param color Color for the text sprite
|
||||
*/
|
||||
|
||||
inline void TextSprite::SetColor(const Color& color)
|
||||
{
|
||||
m_color = color;
|
||||
|
||||
InvalidateVertices();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the default material of the text sprite (just default material)
|
||||
*/
|
||||
|
||||
|
||||
inline void TextSprite::SetDefaultMaterial()
|
||||
{
|
||||
SetMaterial(Material::New("Translucent2D"));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the material of the text sprite
|
||||
*
|
||||
* \param material Material for the text sprite
|
||||
*/
|
||||
|
||||
inline void TextSprite::SetMaterial(MaterialRef material)
|
||||
{
|
||||
InstancedRenderable::SetMaterial(0, std::move(material));
|
||||
}
|
||||
|
||||
inline void TextSprite::SetMaterial(std::size_t skinIndex, MaterialRef material)
|
||||
{
|
||||
InstancedRenderable::SetMaterial(skinIndex, 0, std::move(material));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the current scale of the text sprite
|
||||
*
|
||||
* \param scale Scale of the text sprite
|
||||
*/
|
||||
|
||||
inline void TextSprite::SetScale(float scale)
|
||||
{
|
||||
m_scale = scale;
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
InvalidateVertices();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the current text sprite with the content of the other one
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param text sprite The other TextSprite
|
||||
*/
|
||||
|
||||
inline TextSprite& TextSprite::operator=(const TextSprite& text)
|
||||
{
|
||||
InstancedRenderable::operator=(text);
|
||||
|
||||
m_atlases.clear();
|
||||
|
||||
m_color = text.m_color;
|
||||
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& atlasSlots = m_atlases[atlas];
|
||||
|
||||
atlasSlots.clearSlot.Connect(atlas->OnAtlasCleared, this, &TextSprite::OnAtlasInvalidated);
|
||||
atlasSlots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, &TextSprite::OnAtlasLayerChange);
|
||||
atlasSlots.releaseSlot.Connect(atlas->OnAtlasRelease, this, &TextSprite::OnAtlasInvalidated);
|
||||
}
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
InvalidateVertices();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invalidates the vertices
|
||||
*/
|
||||
|
||||
inline void TextSprite::InvalidateVertices()
|
||||
{
|
||||
InvalidateInstanceData(0);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a new text sprite from the arguments
|
||||
* \return A reference to the newly created text sprite
|
||||
*
|
||||
* \param args Arguments for the text sprite
|
||||
*/
|
||||
|
||||
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/Graphics/DebugOff.hpp>
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_TEXTUREBACKGROUND_HPP
|
||||
#define NAZARA_TEXTUREBACKGROUND_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||
#include <Nazara/Renderer/UberShader.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class TextureBackground;
|
||||
|
||||
using TextureBackgroundConstRef = ObjectRef<const TextureBackground>;
|
||||
using TextureBackgroundRef = ObjectRef<TextureBackground>;
|
||||
|
||||
class NAZARA_GRAPHICS_API TextureBackground : public AbstractBackground
|
||||
{
|
||||
public:
|
||||
TextureBackground(TextureRef texture = TextureRef());
|
||||
|
||||
void Draw(const AbstractViewer* viewer) const override;
|
||||
|
||||
BackgroundType GetBackgroundType() const override;
|
||||
inline const TextureRef& GetTexture() const;
|
||||
|
||||
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>
|
||||
|
||||
#endif // NAZARA_TEXTUREBACKGROUND_HPP
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Gets the texture of the background
|
||||
* \return Texture of the background
|
||||
*/
|
||||
|
||||
inline const TextureRef& TextureBackground::GetTexture() const
|
||||
{
|
||||
return m_texture;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the texture of the background
|
||||
*
|
||||
* \param texture Texture of the background
|
||||
*/
|
||||
|
||||
inline void TextureBackground::SetTexture(TextureRef texture)
|
||||
{
|
||||
NazaraAssert(!texture || texture->IsValid(), "Invalid texture");
|
||||
|
||||
m_texture = std::move(texture);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a new texture background from the arguments
|
||||
* \return A reference to the newly created texture background
|
||||
*
|
||||
* \param args Arguments for the texture background
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_TILEMAP_HPP
|
||||
#define NAZARA_TILEMAP_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <set>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class TileMap;
|
||||
|
||||
using TileMapConstRef = ObjectRef<const TileMap>;
|
||||
using TileMapLibrary = ObjectLibrary<TileMap>;
|
||||
using TileMapRef = ObjectRef<TileMap>;
|
||||
|
||||
class NAZARA_GRAPHICS_API TileMap : public InstancedRenderable
|
||||
{
|
||||
friend TileMapLibrary;
|
||||
friend class Graphics;
|
||||
|
||||
public:
|
||||
struct Tile;
|
||||
|
||||
inline TileMap(const Nz::Vector2ui& mapSize, const Nz::Vector2f& tileSize, std::size_t materialCount = 1);
|
||||
TileMap(const TileMap&) = default;
|
||||
TileMap(TileMap&&) = delete;
|
||||
~TileMap() = default;
|
||||
|
||||
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override;
|
||||
|
||||
std::unique_ptr<InstancedRenderable> Clone() const override;
|
||||
|
||||
inline void DisableTile(const Vector2ui& tilePos);
|
||||
inline void DisableTiles();
|
||||
inline void DisableTiles(const Vector2ui* tilesPos, std::size_t tileCount);
|
||||
|
||||
inline void EnableIsometricMode(bool isometric);
|
||||
|
||||
inline void EnableTile(const Vector2ui& tilePos, const Rectf& coords, const Color& color = Color::White, std::size_t materialIndex = 0U);
|
||||
inline void EnableTile(const Vector2ui& tilePos, const Rectui& rect, const Color& color = Color::White, std::size_t materialIndex = 0U);
|
||||
inline void EnableTiles(const Rectf& coords, const Color& color = Color::White, std::size_t materialIndex = 0U);
|
||||
inline void EnableTiles(const Rectui& rect, const Color& color = Color::White, std::size_t materialIndex = 0U);
|
||||
inline void EnableTiles(const Vector2ui* tilesPos, std::size_t tileCount, const Rectf& coords, const Color& color = Color::White, std::size_t materialIndex = 0U);
|
||||
inline void EnableTiles(const Vector2ui* tilesPos, std::size_t tileCount, const Rectui& rect, const Color& color = Color::White, std::size_t materialIndex = 0U);
|
||||
|
||||
inline const Vector2ui& GetMapSize() const;
|
||||
inline Vector2f GetSize() const;
|
||||
inline const Tile& GetTile(const Vector2ui& tilePos) const;
|
||||
inline const Vector2f& GetTileSize() const;
|
||||
|
||||
inline bool IsIsometricModeEnabled() const;
|
||||
|
||||
using InstancedRenderable::SetMaterial;
|
||||
|
||||
inline TileMap& operator=(const TileMap& TileMap);
|
||||
TileMap& operator=(TileMap&& TileMap) = delete;
|
||||
|
||||
template<typename... Args> static TileMapRef New(Args&&... args);
|
||||
|
||||
struct Tile
|
||||
{
|
||||
std::size_t layerIndex = 0U;
|
||||
Color color = Color::White;
|
||||
Rectf textureCoords = Rectf::Zero();
|
||||
bool enabled = false;
|
||||
};
|
||||
|
||||
private:
|
||||
void MakeBoundingVolume() const override;
|
||||
void UpdateData(InstanceData* instanceData) const override;
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
struct Layer
|
||||
{
|
||||
std::set<std::size_t> tiles;
|
||||
};
|
||||
|
||||
std::vector<Tile> m_tiles;
|
||||
std::vector<Layer> m_layers;
|
||||
Vector2ui m_mapSize;
|
||||
Vector2f m_tileSize;
|
||||
bool m_isometricModeEnabled;
|
||||
|
||||
static TileMapLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/TileMap.inl>
|
||||
|
||||
#endif // NAZARA_TILEMAP_HPP
|
||||
|
|
@ -1,435 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a TileMap object, containing mapSize tileSize-sized tiles
|
||||
*
|
||||
* \param mapSize Number of tiles in each dimension, must be
|
||||
* \param tileSize Size of each tile of the TileMap
|
||||
* \param materialCount The maximum number of differents Material this TileMap will use
|
||||
*
|
||||
* \remark When constructed, a TileMap has no tile active and will not be rendered
|
||||
* To use it, you have to enable some tiles.
|
||||
*
|
||||
* \remark The default material is used for every material requested
|
||||
*/
|
||||
inline TileMap::TileMap(const Nz::Vector2ui& mapSize, const Nz::Vector2f& tileSize, std::size_t materialCount) :
|
||||
m_tiles(mapSize.x * mapSize.y),
|
||||
m_layers(materialCount),
|
||||
m_mapSize(mapSize),
|
||||
m_tileSize(tileSize),
|
||||
m_isometricModeEnabled(false)
|
||||
{
|
||||
NazaraAssert(m_tiles.size() != 0U, "Invalid map size");
|
||||
NazaraAssert(m_tileSize.x > 0 && m_tileSize.y > 0, "Invalid tile size");
|
||||
NazaraAssert(m_layers.size() != 0U, "Invalid material count");
|
||||
|
||||
ResetMaterials(materialCount);
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Disable the tile at position tilePos, disabling rendering at this location
|
||||
*
|
||||
* \param tilePos Position of the tile to disable
|
||||
*
|
||||
* \see DisableTiles
|
||||
*/
|
||||
inline void TileMap::DisableTile(const Vector2ui& tilePos)
|
||||
{
|
||||
NazaraAssert(tilePos.x < m_mapSize.x && tilePos.y < m_mapSize.y, "Tile position is out of bounds");
|
||||
|
||||
std::size_t tileIndex = tilePos.y * m_mapSize.x + tilePos.x;
|
||||
Tile& tile = m_tiles[tileIndex];
|
||||
tile.enabled = false;
|
||||
|
||||
m_layers[tile.layerIndex].tiles.erase(tileIndex);
|
||||
|
||||
InvalidateInstanceData(1U << tile.layerIndex);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Disable all tiles
|
||||
*/
|
||||
inline void TileMap::DisableTiles()
|
||||
{
|
||||
for (Tile& tile : m_tiles)
|
||||
tile.enabled = false;
|
||||
|
||||
for (Layer& layer : m_layers)
|
||||
layer.tiles.clear();
|
||||
|
||||
InvalidateInstanceData(0xFFFFFFFF);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Disable tileCount tiles at positions contained at tilesPos location, disabling rendering at those locations
|
||||
*
|
||||
* This is equivalent to calling tileCount times DisableTile with the positions contained at tilesPos
|
||||
*
|
||||
* \param tilesPos Pointer to a valid array of at least tileCount positions
|
||||
* \param tileCount Number of tiles to disable
|
||||
*
|
||||
* \remark if tileCount is zero, this is a no-op and the value of tilesPos is not used
|
||||
*
|
||||
* \see DisableTile
|
||||
*/
|
||||
inline void TileMap::DisableTiles(const Vector2ui* tilesPos, std::size_t tileCount)
|
||||
{
|
||||
NazaraAssert(tilesPos || tileCount == 0, "Invalid tile position array with a non-zero tileCount");
|
||||
|
||||
UInt32 invalidatedLayers = 0;
|
||||
|
||||
for (std::size_t i = 0; i < tileCount; ++i)
|
||||
{
|
||||
NazaraAssert(tilesPos->x < m_mapSize.x && tilesPos->y < m_mapSize.y, "Tile position is out of bounds");
|
||||
|
||||
std::size_t tileIndex = tilesPos->y * m_mapSize.x + tilesPos->x;
|
||||
Tile& tile = m_tiles[tileIndex];
|
||||
tile.enabled = false;
|
||||
|
||||
m_layers[tile.layerIndex].tiles.erase(tileIndex);
|
||||
|
||||
invalidatedLayers |= 1U << tile.layerIndex;
|
||||
|
||||
tilesPos++;
|
||||
}
|
||||
|
||||
if (tileCount > 0)
|
||||
InvalidateInstanceData(invalidatedLayers);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enable/Disable isometric mode
|
||||
*
|
||||
* If enabled, every odd line will overlap by half the tile size with the upper line
|
||||
*
|
||||
* \param isometric Should the isometric mode be enabled for this TileMap
|
||||
*
|
||||
* \see IsIsometricModeEnabled
|
||||
*/
|
||||
inline void TileMap::EnableIsometricMode(bool isometric)
|
||||
{
|
||||
m_isometricModeEnabled = isometric;
|
||||
|
||||
InvalidateInstanceData(0xFFFFFFFF);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enable and sets the tile at position tilePos
|
||||
*
|
||||
* Setup the tile at position tilePos using color, normalized coordinates coords and materialIndex
|
||||
*
|
||||
* \param tilePos Position of the tile to enable
|
||||
* \param coords Normalized coordinates ([0..1]) used to specify which region of the material textures will be used
|
||||
* \param color The multiplicative color applied to the tile
|
||||
* \param materialIndex The material which will be used for rendering this tile
|
||||
*
|
||||
* \see EnableTiles
|
||||
*/
|
||||
inline void TileMap::EnableTile(const Vector2ui& tilePos, const Rectf& coords, const Color& color, std::size_t materialIndex)
|
||||
{
|
||||
NazaraAssert(tilePos.x < m_mapSize.x && tilePos.y < m_mapSize.y, "Tile position is out of bounds");
|
||||
NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds");
|
||||
|
||||
UInt32 invalidatedLayers = 1U << materialIndex;
|
||||
|
||||
std::size_t tileIndex = tilePos.y * m_mapSize.x + tilePos.x;
|
||||
Tile& tile = m_tiles[tilePos.y * m_mapSize.x + tilePos.x];
|
||||
|
||||
if (!tile.enabled)
|
||||
m_layers[materialIndex].tiles.insert(tileIndex);
|
||||
else if (materialIndex != tile.layerIndex)
|
||||
{
|
||||
m_layers[tile.layerIndex].tiles.erase(tileIndex);
|
||||
m_layers[materialIndex].tiles.insert(tileIndex);
|
||||
|
||||
invalidatedLayers |= 1U << tile.layerIndex;
|
||||
}
|
||||
|
||||
tile.enabled = true;
|
||||
tile.color = color;
|
||||
tile.textureCoords = coords;
|
||||
tile.layerIndex = materialIndex;
|
||||
|
||||
InvalidateInstanceData(invalidatedLayers);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enable and sets the tile at position tilePos
|
||||
*
|
||||
* Setup the tile at position tilePos using color, unnormalized coordinates rect and materialIndex
|
||||
*
|
||||
* \param tilePos Position of the tile to enable
|
||||
* \param coords Unnormalized coordinates ([0..size]) used to specify which region of the material textures will be used
|
||||
* \param color The multiplicative color applied to the tile
|
||||
* \param materialIndex The material which will be used for rendering this tile
|
||||
*
|
||||
* \remark The material at [materialIndex] must have a valid diffuse map before using this function,
|
||||
* as the size of the material diffuse map is used to compute normalized texture coordinates before returning.
|
||||
*
|
||||
* \see EnableTiles
|
||||
*/
|
||||
inline void TileMap::EnableTile(const Vector2ui& tilePos, const Rectui& rect, const Color& color, std::size_t materialIndex)
|
||||
{
|
||||
NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds");
|
||||
|
||||
const MaterialRef& material = GetMaterial(materialIndex);
|
||||
NazaraAssert(material->HasDiffuseMap(), "Material has no diffuse map");
|
||||
|
||||
Texture* diffuseMap = material->GetDiffuseMap();
|
||||
float invWidth = 1.f / diffuseMap->GetWidth();
|
||||
float invHeight = 1.f / diffuseMap->GetHeight();
|
||||
|
||||
Rectf unnormalizedCoords(invWidth * rect.x, invHeight * rect.y, invWidth * rect.width, invHeight * rect.height);
|
||||
EnableTile(tilePos, unnormalizedCoords, color, materialIndex);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enable and sets all the tiles
|
||||
*
|
||||
* Setup all tiles using color, normalized coordinates coords and materialIndex
|
||||
*
|
||||
* \param coords Normalized coordinates ([0..1]) used to specify which region of the material textures will be used
|
||||
* \param color The multiplicative color applied to the tile
|
||||
* \param materialIndex The material which will be used for rendering this tile
|
||||
*
|
||||
* \remark The material at [materialIndex] must have a valid diffuse map before using this function,
|
||||
* as the size of the material diffuse map is used to compute normalized texture coordinates before returning.
|
||||
*
|
||||
* \see EnableTile
|
||||
*/
|
||||
inline void TileMap::EnableTiles(const Rectf& coords, const Color& color, std::size_t materialIndex)
|
||||
{
|
||||
NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds");
|
||||
|
||||
for (Layer& layer : m_layers)
|
||||
layer.tiles.clear();
|
||||
|
||||
std::size_t tileIndex = 0;
|
||||
for (Tile& tile : m_tiles)
|
||||
{
|
||||
tile.enabled = true;
|
||||
tile.color = color;
|
||||
tile.textureCoords = coords;
|
||||
tile.layerIndex = materialIndex;
|
||||
|
||||
m_layers[materialIndex].tiles.insert(tileIndex++);
|
||||
}
|
||||
|
||||
InvalidateInstanceData(0xFFFFFFFF);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enable and sets all the tiles
|
||||
*
|
||||
* Setup all tiles using color, unnormalized coordinates coords and materialIndex
|
||||
*
|
||||
* \param coords Unnormalized coordinates ([0..size]) used to specify which region of the material textures will be used
|
||||
* \param color The multiplicative color applied to the tile
|
||||
* \param materialIndex The material which will be used for rendering this tile
|
||||
*
|
||||
* \remark The material at [materialIndex] must have a valid diffuse map before using this function,
|
||||
* as the size of the material diffuse map is used to compute normalized texture coordinates before returning.
|
||||
*
|
||||
* \see EnableTile
|
||||
*/
|
||||
inline void TileMap::EnableTiles(const Rectui& rect, const Color& color, std::size_t materialIndex)
|
||||
{
|
||||
NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds");
|
||||
|
||||
Texture* diffuseMap = GetMaterial(materialIndex)->GetDiffuseMap();
|
||||
float invWidth = 1.f / diffuseMap->GetWidth();
|
||||
float invHeight = 1.f / diffuseMap->GetHeight();
|
||||
|
||||
Rectf unnormalizedCoords(invWidth * rect.x, invHeight * rect.y, invWidth * rect.width, invHeight * rect.height);
|
||||
EnableTiles(unnormalizedCoords, color, materialIndex);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enable and sets tileCount tiles at positions contained at tilesPos location, enabling rendering at those locations
|
||||
*
|
||||
* Setup all tiles using color, normalized coordinates coords and materialIndex
|
||||
*
|
||||
* \param tilesPos Pointer to a valid array of at least tileCount positions
|
||||
* \param tileCount Number of tiles to enable
|
||||
* \param coords Normalized coordinates ([0..1]) used to specify which region of the material textures will be used
|
||||
* \param color The multiplicative color applied to the tile
|
||||
* \param materialIndex The material which will be used for rendering this tile
|
||||
*
|
||||
* \see EnableTile
|
||||
*/
|
||||
inline void TileMap::EnableTiles(const Vector2ui* tilesPos, std::size_t tileCount, const Rectf& coords, const Color& color, std::size_t materialIndex)
|
||||
{
|
||||
NazaraAssert(tilesPos || tileCount == 0, "Invalid tile position array with a non-zero tileCount");
|
||||
NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds");
|
||||
|
||||
UInt32 invalidatedLayers = 1U << materialIndex;
|
||||
|
||||
for (std::size_t i = 0; i < tileCount; ++i)
|
||||
{
|
||||
NazaraAssert(tilesPos->x < m_mapSize.x && tilesPos->y < m_mapSize.y, "Tile position is out of bounds");
|
||||
|
||||
std::size_t tileIndex = tilesPos->y * m_mapSize.x + tilesPos->x;
|
||||
Tile& tile = m_tiles[tileIndex];
|
||||
|
||||
if (!tile.enabled)
|
||||
m_layers[materialIndex].tiles.insert(tileIndex);
|
||||
else if (materialIndex != tile.layerIndex)
|
||||
{
|
||||
m_layers[tile.layerIndex].tiles.erase(tileIndex);
|
||||
m_layers[materialIndex].tiles.insert(tileIndex);
|
||||
|
||||
invalidatedLayers |= 1U << tile.layerIndex;
|
||||
}
|
||||
|
||||
tile.enabled = true;
|
||||
tile.color = color;
|
||||
tile.textureCoords = coords;
|
||||
tile.layerIndex = materialIndex;
|
||||
tilesPos++;
|
||||
}
|
||||
|
||||
if (tileCount > 0)
|
||||
InvalidateInstanceData(invalidatedLayers);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enable and sets tileCount tiles at positions contained at tilesPos location, enabling rendering at those locations
|
||||
*
|
||||
* Setup all tiles using color, unnormalized coordinates coords and materialIndex
|
||||
*
|
||||
* \param tilesPos Pointer to a valid array of at least tileCount positions
|
||||
* \param tileCount Number of tiles to enable
|
||||
* \param coords Unnormalized coordinates ([0..size]) used to specify which region of the material textures will be used
|
||||
* \param color The multiplicative color applied to the tile
|
||||
* \param materialIndex The material which will be used for rendering this tile
|
||||
*
|
||||
* \remark The material at [materialIndex] must have a valid diffuse map before using this function,
|
||||
* as the size of the material diffuse map is used to compute normalized texture coordinates before returning.
|
||||
*
|
||||
* \see EnableTile
|
||||
*/
|
||||
inline void TileMap::EnableTiles(const Vector2ui* tilesPos, std::size_t tileCount, const Rectui& rect, const Color& color, std::size_t materialIndex)
|
||||
{
|
||||
NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds");
|
||||
|
||||
const MaterialRef& material = GetMaterial(materialIndex);
|
||||
NazaraAssert(material->HasDiffuseMap(), "Material has no diffuse map");
|
||||
|
||||
Texture* diffuseMap = material->GetDiffuseMap();
|
||||
float invWidth = 1.f / diffuseMap->GetWidth();
|
||||
float invHeight = 1.f / diffuseMap->GetHeight();
|
||||
|
||||
Rectf unnormalizedCoords(invWidth * rect.x, invHeight * rect.y, invWidth * rect.width, invHeight * rect.height);
|
||||
EnableTiles(tilesPos, tileCount, unnormalizedCoords, color, materialIndex);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the tilemap size (i.e. number of tiles in each dimension)
|
||||
* \return Number of tiles in each dimension
|
||||
*
|
||||
* \see GetSize
|
||||
* \see GetTileSize
|
||||
*/
|
||||
inline const Vector2ui& TileMap::GetMapSize() const
|
||||
{
|
||||
return m_mapSize;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the size of the tilemap in units (which is equivalent to GetMapSize() * GetTileSize())
|
||||
* \return Maximum size in units occupied by this tilemap
|
||||
*
|
||||
* \see GetMapSize
|
||||
* \see GetTileSize
|
||||
*/
|
||||
inline Vector2f TileMap::GetSize() const
|
||||
{
|
||||
return Vector2f(m_mapSize) * m_tileSize;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns informations about a particular tile
|
||||
*
|
||||
* \param tilePos Position of the tile to get (enabled or not)
|
||||
*
|
||||
* \return Maximum size in units occupied by this tilemap
|
||||
*/
|
||||
inline const TileMap::Tile& TileMap::GetTile(const Vector2ui& tilePos) const
|
||||
{
|
||||
NazaraAssert(tilePos.x < m_mapSize.x && tilePos.y < m_mapSize.y, "Tile position is out of bounds");
|
||||
|
||||
return m_tiles[tilePos.y * m_mapSize.x + tilePos.x];
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the tile size (i.e. number of units occupied by a tile in each dimension)
|
||||
* \return Tile size in each dimension
|
||||
*
|
||||
* \see GetMapSize
|
||||
* \see GetSize
|
||||
*/
|
||||
inline const Vector2f& TileMap::GetTileSize() const
|
||||
{
|
||||
return m_tileSize;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the actual state of the isometric mode
|
||||
* \return True if the isometric mode is enabled
|
||||
*
|
||||
* \see EnableIsometricMode
|
||||
*/
|
||||
inline bool TileMap::IsIsometricModeEnabled() const
|
||||
{
|
||||
return m_isometricModeEnabled;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the current TileMap with the content of the other one
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param TileMap The other TileMap
|
||||
*/
|
||||
inline TileMap& TileMap::operator=(const TileMap& tileMap)
|
||||
{
|
||||
InstancedRenderable::operator=(tileMap);
|
||||
|
||||
m_layers = tileMap.m_layers;
|
||||
m_mapSize = tileMap.m_mapSize;
|
||||
m_tiles = tileMap.m_tiles;
|
||||
m_tileSize = tileMap.m_tileSize;
|
||||
|
||||
// We do not copy final vertices because it's highly probable that our parameters are modified and they must be regenerated
|
||||
InvalidateBoundingVolume();
|
||||
InvalidateInstanceData(0xFFFFFFFF);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a new TileMap from the arguments
|
||||
* \return A reference to the newly created TileMap
|
||||
*
|
||||
* \param args Arguments for the TileMap
|
||||
*/
|
||||
template<typename... Args>
|
||||
TileMapRef TileMap::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<TileMap> object(new TileMap(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -15,11 +15,7 @@
|
|||
#include <set>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NazaraSDK/Canvas.hpp>
|
||||
#include <NazaraSDK/Console.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Platform/Window.hpp>
|
||||
#endif
|
||||
|
||||
|
|
@ -28,11 +24,6 @@ namespace Ndk
|
|||
class NDK_API Application
|
||||
{
|
||||
public:
|
||||
#ifndef NDK_SERVER
|
||||
struct ConsoleOverlay;
|
||||
struct FPSCounterOverlay;
|
||||
#endif
|
||||
|
||||
inline Application();
|
||||
Application(int argc, char* argv[]);
|
||||
Application(const Application&) = delete;
|
||||
|
|
@ -44,14 +35,6 @@ namespace Ndk
|
|||
#endif
|
||||
template<typename... Args> World& AddWorld(Args&&... args);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
inline void EnableConsole(bool enable);
|
||||
inline void EnableFPSCounter(bool enable);
|
||||
|
||||
inline ConsoleOverlay& GetConsoleOverlay(std::size_t windowIndex = 0U);
|
||||
inline FPSCounterOverlay& GetFPSCounterOverlay(std::size_t windowIndex = 0U);
|
||||
#endif
|
||||
|
||||
inline const std::set<Nz::String>& GetOptions() const;
|
||||
inline const std::map<Nz::String, Nz::String>& GetParameters() const;
|
||||
|
||||
|
|
@ -78,53 +61,15 @@ namespace Ndk
|
|||
|
||||
inline static Application* Instance();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
struct ConsoleOverlay
|
||||
{
|
||||
Console* console;
|
||||
|
||||
NazaraSlot(Nz::EventHandler, OnEvent, eventSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnKeyPressed, keyPressedSlot);
|
||||
NazaraSlot(Nz::RenderTarget, OnRenderTargetSizeChange, resizedSlot);
|
||||
NazaraSlot(Nz::Log, OnLogWrite, logSlot);
|
||||
};
|
||||
|
||||
struct FPSCounterOverlay
|
||||
{
|
||||
Nz::TextSpriteRef sprite;
|
||||
EntityOwner entity;
|
||||
float elapsedTime = 0.f;
|
||||
unsigned int frameCount = 0;
|
||||
};
|
||||
#endif
|
||||
|
||||
private:
|
||||
#ifndef NDK_SERVER
|
||||
enum OverlayFlags
|
||||
{
|
||||
OverlayFlags_Console = 0x1,
|
||||
OverlayFlags_FPSCounter = 0x2
|
||||
};
|
||||
|
||||
struct WindowInfo
|
||||
{
|
||||
inline WindowInfo(std::unique_ptr<Nz::Window>&& window);
|
||||
|
||||
Nz::RenderTarget* renderTarget;
|
||||
std::unique_ptr<Nz::Window> window;
|
||||
std::unique_ptr<ConsoleOverlay> console;
|
||||
std::unique_ptr<Canvas> canvas;
|
||||
std::unique_ptr<FPSCounterOverlay> fpsCounter;
|
||||
std::unique_ptr<World> overlayWorld;
|
||||
};
|
||||
|
||||
void SetupConsole(WindowInfo& info);
|
||||
void SetupFPSCounter(WindowInfo& info);
|
||||
void SetupOverlay(WindowInfo& info);
|
||||
|
||||
template<typename T> void SetupWindow(WindowInfo& info, T* renderTarget, std::true_type /*isRenderTarget*/);
|
||||
template<typename T> void SetupWindow(WindowInfo& /*info*/, T* /*renderTarget*/, std::false_type /*isNotRenderTarget*/);
|
||||
|
||||
std::vector<WindowInfo> m_windows;
|
||||
#endif
|
||||
|
||||
|
|
@ -134,7 +79,6 @@ namespace Ndk
|
|||
Nz::Clock m_updateClock;
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
Nz::UInt32 m_overlayFlags;
|
||||
bool m_exitOnClosedWindows;
|
||||
#endif
|
||||
bool m_shouldQuit;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ namespace Ndk
|
|||
*/
|
||||
inline Application::Application() :
|
||||
#ifndef NDK_SERVER
|
||||
m_overlayFlags(0U),
|
||||
m_exitOnClosedWindows(true),
|
||||
#endif
|
||||
m_shouldQuit(false),
|
||||
|
|
@ -65,11 +64,7 @@ namespace Ndk
|
|||
m_windows.emplace_back(std::make_unique<T>(std::forward<Args>(args)...));
|
||||
WindowInfo& info = m_windows.back();
|
||||
|
||||
T& window = static_cast<T&>(*info.window.get()); //< Warning: ugly
|
||||
|
||||
SetupWindow(info, &window, std::is_base_of<Nz::RenderTarget, T>());
|
||||
|
||||
return window;
|
||||
return static_cast<T&>(*info.window.get()); //< Warning: ugly
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -87,133 +82,6 @@ namespace Ndk
|
|||
return m_worlds.back();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enable/disable debug console
|
||||
*
|
||||
* \param enable Should the console overlay be enabled
|
||||
*/
|
||||
#ifndef NDK_SERVER
|
||||
inline void Application::EnableConsole(bool enable)
|
||||
{
|
||||
if (enable != ((m_overlayFlags & OverlayFlags_Console) != 0))
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
if (m_overlayFlags == 0)
|
||||
{
|
||||
for (WindowInfo& info : m_windows)
|
||||
SetupOverlay(info);
|
||||
}
|
||||
|
||||
for (WindowInfo& info : m_windows)
|
||||
{
|
||||
if (info.renderTarget)
|
||||
SetupConsole(info);
|
||||
}
|
||||
|
||||
m_overlayFlags |= OverlayFlags_Console;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (WindowInfo& info : m_windows)
|
||||
info.console.reset();
|
||||
|
||||
m_overlayFlags &= ~OverlayFlags_Console;
|
||||
if (m_overlayFlags == 0)
|
||||
{
|
||||
for (WindowInfo& info : m_windows)
|
||||
info.overlayWorld.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Enable/disable debug FPS counter
|
||||
*
|
||||
* \param enable Should the FPS counter be displayed
|
||||
*/
|
||||
#ifndef NDK_SERVER
|
||||
inline void Application::EnableFPSCounter(bool enable)
|
||||
{
|
||||
if (enable != ((m_overlayFlags & OverlayFlags_FPSCounter) != 0))
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
if (m_overlayFlags == 0)
|
||||
{
|
||||
for (WindowInfo& info : m_windows)
|
||||
SetupOverlay(info);
|
||||
}
|
||||
|
||||
for (WindowInfo& info : m_windows)
|
||||
{
|
||||
if (info.renderTarget)
|
||||
SetupFPSCounter(info);
|
||||
}
|
||||
|
||||
m_overlayFlags |= OverlayFlags_FPSCounter;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
for (WindowInfo& info : m_windows)
|
||||
info.fpsCounter.reset();
|
||||
|
||||
m_overlayFlags &= ~OverlayFlags_FPSCounter;
|
||||
if (m_overlayFlags == 0)
|
||||
{
|
||||
for (WindowInfo& info : m_windows)
|
||||
info.overlayWorld.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Gets the console overlay for a specific window
|
||||
*
|
||||
* \param windowIndex Index of the window to get
|
||||
*
|
||||
* \remark The console overlay must be enabled
|
||||
*
|
||||
* \return A reference to the console overlay of the window
|
||||
*
|
||||
* \see IsConsoleOverlayEnabled
|
||||
*/
|
||||
#ifndef NDK_SERVER
|
||||
inline Application::ConsoleOverlay& Application::GetConsoleOverlay(std::size_t windowIndex)
|
||||
{
|
||||
NazaraAssert(m_overlayFlags & OverlayFlags_Console, "Console overlay is not enabled");
|
||||
NazaraAssert(windowIndex <= m_windows.size(), "Window index is out of range");
|
||||
|
||||
return *m_windows[windowIndex].console;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Gets the console overlay for a specific window
|
||||
*
|
||||
* \param windowIndex Index of the window to get
|
||||
*
|
||||
* \remark The console overlay must be enabled
|
||||
*
|
||||
* \return A reference to the console overlay of the window
|
||||
*
|
||||
* \see IsFPSCounterEnabled
|
||||
*/
|
||||
#ifndef NDK_SERVER
|
||||
inline Application::FPSCounterOverlay& Application::GetFPSCounterOverlay(std::size_t windowIndex)
|
||||
{
|
||||
NazaraAssert(m_overlayFlags & OverlayFlags_FPSCounter, "FPS counter overlay is not enabled");
|
||||
NazaraAssert(windowIndex <= m_windows.size(), "Window index is out of range");
|
||||
|
||||
return *m_windows[windowIndex].fpsCounter;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Gets the options used to start the application
|
||||
*
|
||||
|
|
@ -287,35 +155,6 @@ namespace Ndk
|
|||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks if the console overlay is enabled
|
||||
*
|
||||
* \remark This has nothing to do with the visibility state of the console
|
||||
*
|
||||
* \return True if the console overlay is enabled
|
||||
*
|
||||
* \see GetConsoleOverlay
|
||||
*/
|
||||
#ifndef NDK_SERVER
|
||||
inline bool Application::IsConsoleEnabled() const
|
||||
{
|
||||
return (m_overlayFlags & OverlayFlags_Console) != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Checks if the FPS counter overlay is enabled
|
||||
* \return True if the FPS counter overlay is enabled
|
||||
*
|
||||
* \see GetFPSCounterOverlay
|
||||
*/
|
||||
#ifndef NDK_SERVER
|
||||
inline bool Application::IsFPSCounterEnabled() const
|
||||
{
|
||||
return (m_overlayFlags & OverlayFlags_FPSCounter) != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Makes the application exit when there's no more open window
|
||||
*
|
||||
|
|
@ -348,30 +187,7 @@ namespace Ndk
|
|||
}
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
template<typename T>
|
||||
inline void Application::SetupWindow(WindowInfo& info, T* renderTarget, std::true_type)
|
||||
{
|
||||
info.renderTarget = renderTarget;
|
||||
|
||||
if (m_overlayFlags)
|
||||
{
|
||||
SetupOverlay(info);
|
||||
|
||||
if (m_overlayFlags & OverlayFlags_Console)
|
||||
SetupConsole(info);
|
||||
|
||||
if (m_overlayFlags & OverlayFlags_FPSCounter)
|
||||
SetupFPSCounter(info);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void Application::SetupWindow(WindowInfo&, T*, std::false_type)
|
||||
{
|
||||
}
|
||||
|
||||
inline Application::WindowInfo::WindowInfo(std::unique_ptr<Nz::Window>&& windowPtr) :
|
||||
renderTarget(nullptr),
|
||||
window(std::move(windowPtr))
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,179 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_BASEWIDGET_HPP
|
||||
#define NDK_BASEWIDGET_HPP
|
||||
|
||||
#include <NazaraSDK/Prerequisites.hpp>
|
||||
#include <NazaraSDK/Entity.hpp>
|
||||
#include <NazaraSDK/EntityOwner.hpp>
|
||||
#include <NazaraSDK/World.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Platform/Event.hpp>
|
||||
#include <Nazara/Platform/Mouse.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
#include <limits>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class Canvas;
|
||||
|
||||
class NDK_API BaseWidget : public Nz::Node
|
||||
{
|
||||
friend Canvas;
|
||||
|
||||
public:
|
||||
BaseWidget(BaseWidget* parent);
|
||||
BaseWidget(const BaseWidget&) = delete;
|
||||
BaseWidget(BaseWidget&&) = delete;
|
||||
virtual ~BaseWidget();
|
||||
|
||||
template<typename T, typename... Args> T* Add(Args&&... args);
|
||||
inline void AddChild(std::unique_ptr<BaseWidget>&& widget);
|
||||
|
||||
inline void Center();
|
||||
inline void CenterHorizontal();
|
||||
inline void CenterVertical();
|
||||
|
||||
void ClearFocus();
|
||||
inline void ClearRenderingRect();
|
||||
|
||||
void Destroy();
|
||||
|
||||
void EnableBackground(bool enable);
|
||||
|
||||
template<typename F> void ForEachWidgetChild(F iterator);
|
||||
template<typename F> void ForEachWidgetChild(F iterator) const;
|
||||
|
||||
//virtual BaseWidget* Clone() const = 0;
|
||||
|
||||
inline const Nz::Color& GetBackgroundColor() const;
|
||||
inline Canvas* GetCanvas();
|
||||
inline Nz::SystemCursor GetCursor() const;
|
||||
inline float GetHeight() const;
|
||||
|
||||
inline float GetMaximumHeight() const;
|
||||
inline Nz::Vector2f GetMaximumSize() const;
|
||||
inline float GetMaximumWidth() const;
|
||||
|
||||
inline float GetMinimumHeight() const;
|
||||
inline Nz::Vector2f GetMinimumSize() const;
|
||||
inline float GetMinimumWidth() const;
|
||||
|
||||
inline float GetPreferredHeight() const;
|
||||
inline Nz::Vector2f GetPreferredSize() const;
|
||||
inline float GetPreferredWidth() const;
|
||||
|
||||
inline const Nz::Rectf& GetRenderingRect() const;
|
||||
|
||||
inline Nz::Vector2f GetSize() const;
|
||||
inline float GetWidth() const;
|
||||
inline std::size_t GetWidgetChildCount() const;
|
||||
|
||||
bool HasFocus() const;
|
||||
|
||||
inline void Hide();
|
||||
inline bool IsVisible() const;
|
||||
|
||||
void Resize(const Nz::Vector2f& size);
|
||||
|
||||
void SetBackgroundColor(const Nz::Color& color);
|
||||
void SetCursor(Nz::SystemCursor systemCursor);
|
||||
void SetFocus();
|
||||
void SetParent(BaseWidget* widget);
|
||||
|
||||
inline void SetFixedHeight(float fixedHeight);
|
||||
inline void SetFixedSize(const Nz::Vector2f& fixedSize);
|
||||
inline void SetFixedWidth(float fixedWidth);
|
||||
|
||||
inline void SetMaximumHeight(float maximumHeight);
|
||||
inline void SetMaximumSize(const Nz::Vector2f& maximumSize);
|
||||
inline void SetMaximumWidth(float maximumWidth);
|
||||
|
||||
inline void SetMinimumHeight(float minimumHeight);
|
||||
inline void SetMinimumSize(const Nz::Vector2f& minimumSize);
|
||||
inline void SetMinimumWidth(float minimumWidth);
|
||||
|
||||
virtual void SetRenderingRect(const Nz::Rectf& renderingRect);
|
||||
|
||||
void Show(bool show = true);
|
||||
|
||||
BaseWidget& operator=(const BaseWidget&) = delete;
|
||||
BaseWidget& operator=(BaseWidget&&) = delete;
|
||||
|
||||
protected:
|
||||
const EntityHandle& CreateEntity();
|
||||
void DestroyEntity(Entity* entity);
|
||||
virtual void Layout();
|
||||
|
||||
void InvalidateNode() override;
|
||||
|
||||
Nz::Rectf GetScissorRect() const;
|
||||
|
||||
virtual bool IsFocusable() const;
|
||||
virtual void OnFocusLost();
|
||||
virtual void OnFocusReceived();
|
||||
virtual bool OnKeyPressed(const Nz::WindowEvent::KeyEvent& key);
|
||||
virtual void OnKeyReleased(const Nz::WindowEvent::KeyEvent& key);
|
||||
virtual void OnMouseEnter();
|
||||
virtual void OnMouseMoved(int x, int y, int deltaX, int deltaY);
|
||||
virtual void OnMouseButtonPress(int x, int y, Nz::Mouse::Button button);
|
||||
virtual void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button);
|
||||
virtual void OnMouseWheelMoved(int x, int y, float delta);
|
||||
virtual void OnMouseExit();
|
||||
virtual void OnParentResized(const Nz::Vector2f& newSize);
|
||||
virtual void OnTextEntered(char32_t character, bool repeated);
|
||||
virtual void OnTextEdited(const std::array<char, 32>& characters, int length);
|
||||
|
||||
inline void SetPreferredSize(const Nz::Vector2f& preferredSize);
|
||||
|
||||
virtual void ShowChildren(bool show);
|
||||
|
||||
private:
|
||||
inline BaseWidget();
|
||||
|
||||
void DestroyChild(BaseWidget* widget);
|
||||
void DestroyChildren();
|
||||
inline bool IsRegisteredToCanvas() const;
|
||||
inline void NotifyParentResized(const Nz::Vector2f& newSize);
|
||||
void RegisterToCanvas();
|
||||
inline void UpdateCanvasIndex(std::size_t index);
|
||||
void UnregisterFromCanvas();
|
||||
void UpdatePositionAndSize();
|
||||
|
||||
struct WidgetEntity
|
||||
{
|
||||
EntityOwner handle;
|
||||
bool isEnabled = true;
|
||||
|
||||
NazaraSlot(Ndk::Entity, OnEntityDisabled, onDisabledSlot);
|
||||
NazaraSlot(Ndk::Entity, OnEntityEnabled, onEnabledSlot);
|
||||
};
|
||||
|
||||
static constexpr std::size_t InvalidCanvasIndex = std::numeric_limits<std::size_t>::max();
|
||||
|
||||
std::size_t m_canvasIndex;
|
||||
std::vector<WidgetEntity> m_entities;
|
||||
std::vector<std::unique_ptr<BaseWidget>> m_children;
|
||||
Canvas* m_canvas;
|
||||
EntityOwner m_backgroundEntity;
|
||||
WorldHandle m_world;
|
||||
Nz::Color m_backgroundColor;
|
||||
Nz::Rectf m_renderingRect;
|
||||
Nz::SpriteRef m_backgroundSprite;
|
||||
Nz::SystemCursor m_cursor;
|
||||
Nz::Vector2f m_maximumSize;
|
||||
Nz::Vector2f m_minimumSize;
|
||||
Nz::Vector2f m_preferredSize;
|
||||
Nz::Vector2f m_size;
|
||||
BaseWidget* m_widgetParent;
|
||||
bool m_visible;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/BaseWidget.inl>
|
||||
|
||||
#endif // NDK_BASEWIDGET_HPP
|
||||
|
|
@ -1,275 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NazaraSDK/BaseWidget.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <limits>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline BaseWidget::BaseWidget() :
|
||||
m_canvasIndex(InvalidCanvasIndex),
|
||||
m_canvas(nullptr),
|
||||
m_backgroundColor(Nz::Color(230, 230, 230, 255)),
|
||||
m_renderingRect(-std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()),
|
||||
m_cursor(Nz::SystemCursor_Default),
|
||||
m_maximumSize(std::numeric_limits<float>::infinity()),
|
||||
m_minimumSize(0.f),
|
||||
m_preferredSize(-1),
|
||||
m_size(50.f, 50.f),
|
||||
m_widgetParent(nullptr),
|
||||
m_visible(true)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
inline T* BaseWidget::Add(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<T> widget = std::make_unique<T>(this, std::forward<Args>(args)...);
|
||||
T* widgetPtr = widget.get();
|
||||
AddChild(std::move(widget));
|
||||
|
||||
return widgetPtr;
|
||||
}
|
||||
|
||||
inline void BaseWidget::AddChild(std::unique_ptr<BaseWidget>&& widget)
|
||||
{
|
||||
widget->Show(m_visible);
|
||||
widget->SetParent(this);
|
||||
m_children.emplace_back(std::move(widget));
|
||||
}
|
||||
|
||||
inline void BaseWidget::Center()
|
||||
{
|
||||
NazaraAssert(m_widgetParent, "Widget has no parent");
|
||||
|
||||
Nz::Vector2f parentSize = m_widgetParent->GetSize();
|
||||
Nz::Vector2f mySize = GetSize();
|
||||
SetPosition((parentSize.x - mySize.x) / 2.f, (parentSize.y - mySize.y) / 2.f);
|
||||
}
|
||||
|
||||
inline void BaseWidget::CenterHorizontal()
|
||||
{
|
||||
NazaraAssert(m_widgetParent, "Widget has no parent");
|
||||
|
||||
Nz::Vector2f parentSize = m_widgetParent->GetSize();
|
||||
Nz::Vector2f mySize = GetSize();
|
||||
SetPosition((parentSize.x - mySize.x) / 2.f, GetPosition(Nz::CoordSys_Local).y);
|
||||
}
|
||||
|
||||
inline void BaseWidget::CenterVertical()
|
||||
{
|
||||
NazaraAssert(m_widgetParent, "Widget has no parent");
|
||||
|
||||
Nz::Vector2f parentSize = m_widgetParent->GetSize();
|
||||
Nz::Vector2f mySize = GetSize();
|
||||
SetPosition(GetPosition(Nz::CoordSys_Local).x, (parentSize.y - mySize.y) / 2.f);
|
||||
}
|
||||
|
||||
inline void BaseWidget::ClearRenderingRect()
|
||||
{
|
||||
SetRenderingRect(Nz::Rectf(-std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()));
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
inline void BaseWidget::ForEachWidgetChild(F iterator)
|
||||
{
|
||||
for (const auto& child : m_children)
|
||||
iterator(child.get());
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
inline void BaseWidget::ForEachWidgetChild(F iterator) const
|
||||
{
|
||||
for (const auto& child : m_children)
|
||||
iterator(static_cast<const BaseWidget*>(child.get()));
|
||||
}
|
||||
|
||||
inline const Nz::Color& BaseWidget::GetBackgroundColor() const
|
||||
{
|
||||
return m_backgroundColor;
|
||||
}
|
||||
|
||||
inline Canvas* BaseWidget::GetCanvas()
|
||||
{
|
||||
return m_canvas;
|
||||
}
|
||||
|
||||
inline Nz::SystemCursor BaseWidget::GetCursor() const
|
||||
{
|
||||
return m_cursor;
|
||||
}
|
||||
|
||||
inline float BaseWidget::GetHeight() const
|
||||
{
|
||||
return m_size.y;
|
||||
}
|
||||
|
||||
inline float BaseWidget::GetMaximumHeight() const
|
||||
{
|
||||
return m_maximumSize.y;
|
||||
}
|
||||
|
||||
inline Nz::Vector2f BaseWidget::GetMaximumSize() const
|
||||
{
|
||||
return m_maximumSize;
|
||||
}
|
||||
|
||||
inline float BaseWidget::GetMaximumWidth() const
|
||||
{
|
||||
return m_maximumSize.x;
|
||||
}
|
||||
|
||||
inline float BaseWidget::GetMinimumHeight() const
|
||||
{
|
||||
return m_minimumSize.y;
|
||||
}
|
||||
|
||||
inline Nz::Vector2f BaseWidget::GetMinimumSize() const
|
||||
{
|
||||
return m_minimumSize;
|
||||
}
|
||||
|
||||
inline float BaseWidget::GetMinimumWidth() const
|
||||
{
|
||||
return m_minimumSize.x;
|
||||
}
|
||||
|
||||
inline float BaseWidget::GetPreferredHeight() const
|
||||
{
|
||||
return m_preferredSize.y;
|
||||
}
|
||||
|
||||
inline Nz::Vector2f BaseWidget::GetPreferredSize() const
|
||||
{
|
||||
return m_preferredSize;
|
||||
}
|
||||
|
||||
inline float BaseWidget::GetPreferredWidth() const
|
||||
{
|
||||
return m_preferredSize.x;
|
||||
}
|
||||
|
||||
inline const Nz::Rectf& BaseWidget::GetRenderingRect() const
|
||||
{
|
||||
return m_renderingRect;
|
||||
}
|
||||
|
||||
inline Nz::Vector2f BaseWidget::GetSize() const
|
||||
{
|
||||
return Nz::Vector2f(GetWidth(), GetHeight());
|
||||
}
|
||||
|
||||
inline float BaseWidget::GetWidth() const
|
||||
{
|
||||
return m_size.x;
|
||||
}
|
||||
|
||||
inline std::size_t BaseWidget::GetWidgetChildCount() const
|
||||
{
|
||||
return m_children.size();
|
||||
}
|
||||
|
||||
inline void BaseWidget::Hide()
|
||||
{
|
||||
return Show(false);
|
||||
}
|
||||
|
||||
inline bool BaseWidget::IsVisible() const
|
||||
{
|
||||
return m_visible;
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetFixedHeight(float fixedHeight)
|
||||
{
|
||||
SetMaximumHeight(fixedHeight);
|
||||
SetMinimumHeight(fixedHeight);
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetFixedSize(const Nz::Vector2f& fixedSize)
|
||||
{
|
||||
SetMaximumSize(fixedSize);
|
||||
SetMinimumSize(fixedSize);
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetFixedWidth(float fixedWidth)
|
||||
{
|
||||
SetMaximumWidth(fixedWidth);
|
||||
SetMinimumWidth(fixedWidth);
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetMaximumHeight(float maximumHeight)
|
||||
{
|
||||
Nz::Vector2f maximumSize = GetMaximumSize();
|
||||
maximumSize.y = maximumHeight;
|
||||
|
||||
SetMaximumSize(maximumSize);
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetMaximumSize(const Nz::Vector2f& maximumSize)
|
||||
{
|
||||
m_maximumSize = maximumSize;
|
||||
|
||||
Nz::Vector2f size = GetSize();
|
||||
if (size.x > m_maximumSize.x || size.y > m_maximumSize.y)
|
||||
Resize(size); //< Will clamp automatically
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetMaximumWidth(float maximumWidth)
|
||||
{
|
||||
Nz::Vector2f maximumSize = GetMaximumSize();
|
||||
maximumSize.x = maximumWidth;
|
||||
|
||||
SetMaximumSize(maximumSize);
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetMinimumHeight(float minimumHeight)
|
||||
{
|
||||
Nz::Vector2f minimumSize = GetMinimumSize();
|
||||
minimumSize.y = minimumHeight;
|
||||
|
||||
SetMinimumSize(minimumSize);
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetMinimumSize(const Nz::Vector2f& minimumSize)
|
||||
{
|
||||
m_minimumSize = minimumSize;
|
||||
|
||||
Nz::Vector2f size = GetSize();
|
||||
if (size.x < m_minimumSize.x || size.y < m_minimumSize.y)
|
||||
Resize(size); //< Will clamp automatically
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetMinimumWidth(float minimumWidth)
|
||||
{
|
||||
Nz::Vector2f minimumSize = GetMinimumSize();
|
||||
minimumSize.x = minimumWidth;
|
||||
|
||||
SetMinimumSize(minimumSize);
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetPreferredSize(const Nz::Vector2f& preferredSize)
|
||||
{
|
||||
m_preferredSize = preferredSize;
|
||||
|
||||
//Resize(m_preferredSize);
|
||||
}
|
||||
|
||||
inline bool BaseWidget::IsRegisteredToCanvas() const
|
||||
{
|
||||
return m_canvas && m_canvasIndex != InvalidCanvasIndex;
|
||||
}
|
||||
|
||||
inline void BaseWidget::NotifyParentResized(const Nz::Vector2f& newSize)
|
||||
{
|
||||
for (const auto& widgetPtr : m_children)
|
||||
widgetPtr->OnParentResized(newSize);
|
||||
}
|
||||
|
||||
inline void BaseWidget::UpdateCanvasIndex(std::size_t index)
|
||||
{
|
||||
m_canvasIndex = index;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_CANVAS_HPP
|
||||
#define NDK_CANVAS_HPP
|
||||
|
||||
#include <NazaraSDK/Prerequisites.hpp>
|
||||
#include <NazaraSDK/BaseWidget.hpp>
|
||||
#include <Nazara/Platform/CursorController.hpp>
|
||||
#include <Nazara/Platform/EventHandler.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API Canvas : public BaseWidget
|
||||
{
|
||||
friend BaseWidget;
|
||||
|
||||
public:
|
||||
struct Padding;
|
||||
|
||||
inline Canvas(WorldHandle world, Nz::EventHandler& eventHandler, Nz::CursorControllerHandle cursorController);
|
||||
Canvas(const Canvas&) = delete;
|
||||
Canvas(Canvas&&) = delete;
|
||||
inline ~Canvas();
|
||||
|
||||
inline const WorldHandle& GetWorld() const;
|
||||
|
||||
Canvas& operator=(const Canvas&) = delete;
|
||||
Canvas& operator=(Canvas&&) = delete;
|
||||
|
||||
NazaraSignal(OnUnhandledKeyPressed, const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& /*event*/);
|
||||
NazaraSignal(OnUnhandledKeyReleased, const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& /*event*/);
|
||||
|
||||
protected:
|
||||
inline void ClearKeyboardOwner(std::size_t canvasIndex);
|
||||
|
||||
inline bool IsKeyboardOwner(std::size_t canvasIndex) const;
|
||||
|
||||
inline void NotifyWidgetBoxUpdate(std::size_t index);
|
||||
inline void NotifyWidgetCursorUpdate(std::size_t index);
|
||||
|
||||
std::size_t RegisterWidget(BaseWidget* widget);
|
||||
|
||||
inline void SetKeyboardOwner(std::size_t canvasIndex);
|
||||
|
||||
void UnregisterWidget(std::size_t index);
|
||||
|
||||
private:
|
||||
void OnEventMouseButtonPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event);
|
||||
void OnEventMouseButtonRelease(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event);
|
||||
void OnEventMouseLeft(const Nz::EventHandler* eventHandler);
|
||||
void OnEventMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event);
|
||||
void OnEventMouseWheelMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseWheelEvent& event);
|
||||
void OnEventKeyPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
|
||||
void OnEventKeyReleased(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
|
||||
void OnEventTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event);
|
||||
void OnEventTextEdited(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::EditEvent& event);
|
||||
|
||||
struct WidgetEntry
|
||||
{
|
||||
BaseWidget* widget;
|
||||
Nz::Boxf box;
|
||||
Nz::SystemCursor cursor;
|
||||
};
|
||||
|
||||
NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnKeyReleased, m_keyReleasedSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnMouseButtonPressed, m_mouseButtonPressedSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnMouseButtonReleased, m_mouseButtonReleasedSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnMouseLeft, m_mouseLeftSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnMouseMoved, m_mouseMovedSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnMouseWheelMoved, m_mouseWheelMovedSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnTextEdited, m_textEditedSlot);
|
||||
|
||||
std::size_t m_keyboardOwner;
|
||||
std::size_t m_hoveredWidget;
|
||||
std::vector<WidgetEntry> m_widgetEntries;
|
||||
Nz::CursorControllerHandle m_cursorController;
|
||||
WorldHandle m_world;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Canvas.inl>
|
||||
|
||||
#endif // NDK_CANVAS_HPP
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NazaraSDK/Canvas.hpp>
|
||||
#include <Nazara/Platform/Cursor.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline Canvas::Canvas(WorldHandle world, Nz::EventHandler& eventHandler, Nz::CursorControllerHandle cursorController) :
|
||||
m_keyboardOwner(InvalidCanvasIndex),
|
||||
m_hoveredWidget(InvalidCanvasIndex),
|
||||
m_cursorController(cursorController),
|
||||
m_world(std::move(world))
|
||||
{
|
||||
m_canvas = this;
|
||||
m_widgetParent = nullptr;
|
||||
|
||||
// Register ourselves as a widget to handle cursor change
|
||||
RegisterToCanvas();
|
||||
|
||||
// Connect to every meaningful event
|
||||
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, this, &Canvas::OnEventKeyPressed);
|
||||
m_keyReleasedSlot.Connect(eventHandler.OnKeyReleased, this, &Canvas::OnEventKeyReleased);
|
||||
m_mouseButtonPressedSlot.Connect(eventHandler.OnMouseButtonPressed, this, &Canvas::OnEventMouseButtonPressed);
|
||||
m_mouseButtonReleasedSlot.Connect(eventHandler.OnMouseButtonReleased, this, &Canvas::OnEventMouseButtonRelease);
|
||||
m_mouseLeftSlot.Connect(eventHandler.OnMouseLeft, this, &Canvas::OnEventMouseLeft);
|
||||
m_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, this, &Canvas::OnEventMouseMoved);
|
||||
m_mouseWheelMovedSlot.Connect(eventHandler.OnMouseWheelMoved, this, &Canvas::OnEventMouseWheelMoved);
|
||||
m_textEnteredSlot.Connect(eventHandler.OnTextEntered, this, &Canvas::OnEventTextEntered);
|
||||
m_textEditedSlot.Connect(eventHandler.OnTextEdited, this, &Canvas::OnEventTextEdited);
|
||||
}
|
||||
|
||||
inline Canvas::~Canvas()
|
||||
{
|
||||
// Destroy children explicitly because they signal us when getting destroyed, and that can't happen after our own destruction
|
||||
DestroyChildren();
|
||||
|
||||
// Prevent our parent from trying to call us
|
||||
m_canvasIndex = InvalidCanvasIndex;
|
||||
}
|
||||
|
||||
inline const WorldHandle& Canvas::GetWorld() const
|
||||
{
|
||||
return m_world;
|
||||
}
|
||||
|
||||
inline void Canvas::ClearKeyboardOwner(std::size_t canvasIndex)
|
||||
{
|
||||
if (m_keyboardOwner == canvasIndex)
|
||||
SetKeyboardOwner(InvalidCanvasIndex);
|
||||
}
|
||||
|
||||
inline bool Canvas::IsKeyboardOwner(std::size_t canvasIndex) const
|
||||
{
|
||||
return m_keyboardOwner == canvasIndex;
|
||||
}
|
||||
|
||||
inline void Canvas::NotifyWidgetBoxUpdate(std::size_t index)
|
||||
{
|
||||
WidgetEntry& entry = m_widgetEntries[index];
|
||||
|
||||
Nz::Vector3f pos = entry.widget->GetPosition(Nz::CoordSys_Global);
|
||||
Nz::Vector2f size = entry.widget->GetSize();
|
||||
|
||||
entry.box.Set(pos.x, pos.y, pos.z, size.x, size.y, 1.f);
|
||||
}
|
||||
|
||||
inline void Canvas::NotifyWidgetCursorUpdate(std::size_t index)
|
||||
{
|
||||
WidgetEntry& entry = m_widgetEntries[index];
|
||||
|
||||
entry.cursor = entry.widget->GetCursor();
|
||||
if (m_cursorController && m_hoveredWidget == index)
|
||||
m_cursorController->UpdateCursor(Nz::Cursor::Get(entry.cursor));
|
||||
}
|
||||
|
||||
inline void Canvas::SetKeyboardOwner(std::size_t canvasIndex)
|
||||
{
|
||||
if (m_keyboardOwner != canvasIndex)
|
||||
{
|
||||
if (m_keyboardOwner != InvalidCanvasIndex)
|
||||
m_widgetEntries[m_keyboardOwner].widget->OnFocusLost();
|
||||
|
||||
m_keyboardOwner = canvasIndex;
|
||||
|
||||
if (m_keyboardOwner != InvalidCanvasIndex)
|
||||
m_widgetEntries[m_keyboardOwner].widget->OnFocusReceived();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_COMPONENTS_CAMERACOMPONENT_HPP
|
||||
#define NDK_COMPONENTS_CAMERACOMPONENT_HPP
|
||||
|
||||
#include <Nazara/Math/Frustum.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
#include <NazaraSDK/Component.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class CameraComponent;
|
||||
|
||||
using CameraComponentHandle = Nz::ObjectHandle<CameraComponent>;
|
||||
|
||||
class NDK_API CameraComponent : public Component<CameraComponent>, public Nz::AbstractViewer
|
||||
{
|
||||
public:
|
||||
inline CameraComponent();
|
||||
inline CameraComponent(const CameraComponent& camera);
|
||||
~CameraComponent() = default;
|
||||
|
||||
void ApplyView() const override;
|
||||
|
||||
inline void EnsureFrustumUpdate() const;
|
||||
inline void EnsureProjectionMatrixUpdate() const;
|
||||
inline void EnsureViewMatrixUpdate() const;
|
||||
inline void EnsureViewportUpdate() const;
|
||||
|
||||
float GetAspectRatio() const override;
|
||||
Nz::Vector3f GetEyePosition() const override;
|
||||
Nz::Vector3f GetForward() const override;
|
||||
inline float GetFOV() const;
|
||||
const Nz::Frustumf& GetFrustum() const override;
|
||||
inline unsigned int GetLayer() const;
|
||||
const Nz::Matrix4f& GetProjectionMatrix() const override;
|
||||
inline const Nz::Vector3f& GetProjectionScale() const;
|
||||
Nz::ProjectionType GetProjectionType() const override;
|
||||
inline const Nz::Vector2f& GetSize() const;
|
||||
const Nz::RenderTarget* GetTarget() const override;
|
||||
inline const Nz::Rectf& GetTargetRegion() const;
|
||||
const Nz::Matrix4f& GetViewMatrix() const override;
|
||||
const Nz::Recti& GetViewport() const override;
|
||||
float GetZFar() const override;
|
||||
float GetZNear() const override;
|
||||
|
||||
inline void SetFOV(float fov);
|
||||
void SetLayer(unsigned int layer);
|
||||
inline void SetProjectionScale(const Nz::Vector3f& scale);
|
||||
inline void SetProjectionType(Nz::ProjectionType projection);
|
||||
inline void SetSize(const Nz::Vector2f& size);
|
||||
inline void SetSize(float width, float height);
|
||||
inline void SetTarget(const Nz::RenderTarget* renderTarget);
|
||||
inline void SetTargetRegion(const Nz::Rectf& region);
|
||||
inline void SetViewport(const Nz::Recti& viewport);
|
||||
inline void SetZFar(float zFar);
|
||||
inline void SetZNear(float zNear);
|
||||
|
||||
inline bool UpdateVisibility(std::size_t visibilityHash);
|
||||
|
||||
static ComponentIndex componentIndex;
|
||||
|
||||
private:
|
||||
inline void InvalidateFrustum() const;
|
||||
inline void InvalidateProjectionMatrix() const;
|
||||
inline void InvalidateViewMatrix() const;
|
||||
inline void InvalidateViewport() const;
|
||||
|
||||
void OnAttached() override;
|
||||
void OnComponentAttached(BaseComponent& component) override;
|
||||
void OnComponentDetached(BaseComponent& component) override;
|
||||
void OnDetached() override;
|
||||
void OnNodeInvalidated(const Nz::Node* node);
|
||||
void OnRenderTargetRelease(const Nz::RenderTarget* renderTarget);
|
||||
void OnRenderTargetSizeChange(const Nz::RenderTarget* renderTarget);
|
||||
|
||||
void UpdateFrustum() const;
|
||||
void UpdateProjectionMatrix() const;
|
||||
void UpdateViewMatrix() const;
|
||||
void UpdateViewport() const;
|
||||
|
||||
NazaraSlot(Nz::Node, OnNodeInvalidation, m_nodeInvalidationSlot);
|
||||
NazaraSlot(Nz::RenderTarget, OnRenderTargetRelease, m_targetReleaseSlot);
|
||||
NazaraSlot(Nz::RenderTarget, OnRenderTargetSizeChange, m_targetResizeSlot);
|
||||
|
||||
std::size_t m_visibilityHash;
|
||||
Nz::ProjectionType m_projectionType;
|
||||
mutable Nz::Frustumf m_frustum;
|
||||
mutable Nz::Matrix4f m_projectionMatrix;
|
||||
mutable Nz::Matrix4f m_viewMatrix;
|
||||
Nz::Rectf m_targetRegion;
|
||||
mutable Nz::Recti m_viewport;
|
||||
const Nz::RenderTarget* m_target;
|
||||
Nz::Vector2f m_size;
|
||||
Nz::Vector3f m_projectionScale;
|
||||
mutable bool m_frustumUpdated;
|
||||
mutable bool m_projectionMatrixUpdated;
|
||||
mutable bool m_viewMatrixUpdated;
|
||||
mutable bool m_viewportUpdated;
|
||||
mutable float m_aspectRatio;
|
||||
float m_fov;
|
||||
float m_zFar;
|
||||
float m_zNear;
|
||||
unsigned int m_layer;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Components/CameraComponent.inl>
|
||||
|
||||
#endif // NDK_COMPONENTS_CAMERACOMPONENT_HPP
|
||||
#endif // NDK_SERVER
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue