New Render queues (#161)

* Add new render queues proof of concept + scissoring support (WIP)

* Graphics: Adapt basic sprites rendering to new render queue system

* Graphics: Fix layers when rendering sprites

* Graphics/RenderQueue: Fix sprite default overlay

* Graphics: Enable scissor test by default

* SDK/Widgets: Enable scissoring on widgets

* Graphics: Handle almost everything with the new renderqueues system

Todo:
- Billboard rendering
- Proper model rendering

* Graphics/RenderQueue: Billboard drawing now works (WIP)

At 1/4 of previous code performances due to individually process of billboards

* Add new render queues proof of concept + scissoring support (WIP)

* Graphics: Adapt basic sprites rendering to new render queue system

* Graphics: Fix layers when rendering sprites

* Graphics/RenderQueue: Fix sprite default overlay

* Graphics: Enable scissor test by default

* SDK/Widgets: Enable scissoring on widgets

* Graphics: Handle almost everything with the new renderqueues system

Todo:
- Billboard rendering
- Proper model rendering

* Graphics/RenderQueue: Billboard drawing now works (WIP)

At 1/4 of previous code performances due to individually process of billboards

* Graphics/RenderQueues: Add full support for billboards

* Graphics/RenderQueue: Cleanup and improve billboard rendering

* Graphics/RenderQueue: Fix model drawing

* Examples/Particles: Fix lighting on space station

* Graphics: Cleanup forward render queue/technique

* Fix compilation under Linux

* Graphics/ForwardRenderTechnique: Fix case when scissoring is enabled on material but disabled on element

* Add support for Deferred Shading

* SDK/Widgets: Fix widget rendering

* Graphics: Remove legacy code from render queues

* Graphics: Fix some objects sometimes not showing up due to broken scissor box

* Fix compilation error

* Sdk/GraphicsGraphics: Fix bounding volume

* SDK/World: Fix self-assignation

* Update changelog for render queues
This commit is contained in:
Jérôme Leclercq
2018-04-11 19:36:52 +02:00
committed by GitHub
parent 14248bb6c6
commit 2da086b7df
65 changed files with 3290 additions and 2998 deletions

View File

@@ -33,6 +33,7 @@
#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>
@@ -45,14 +46,13 @@
#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/DeferredRenderQueue.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/ForwardRenderQueue.hpp>
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
#include <Nazara/Graphics/Graphics.hpp>
#include <Nazara/Graphics/GuillotineTextureAtlas.hpp>
@@ -73,6 +73,7 @@
#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>

View File

@@ -37,20 +37,20 @@ namespace Nz
// 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, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) = 0;
virtual void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) = 0;
virtual void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) = 0;
virtual void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) = 0;
virtual void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) = 0;
virtual void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) = 0;
virtual void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) = 0;
virtual void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) = 0;
virtual void 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) = 0;
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 Texture* overlay = nullptr) = 0;
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);

View File

@@ -0,0 +1,142 @@
// Copyright (C) 2017 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

View File

@@ -0,0 +1,38 @@
// Copyright (C) 2017 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);
}
}

View File

@@ -29,7 +29,7 @@ namespace Nz
Billboard(Billboard&&) = delete;
~Billboard() = default;
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override;
inline const Color& GetColor() const;
inline float GetRotation() const;

View File

@@ -8,6 +8,7 @@
#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>
@@ -17,6 +18,8 @@ namespace Nz
{
class NAZARA_GRAPHICS_API DeferredGeometryPass : public DeferredRenderPass
{
friend class DeferredRenderTechnique;
public:
DeferredGeometryPass();
virtual ~DeferredGeometryPass();
@@ -27,9 +30,17 @@ namespace Nz
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);
@@ -41,8 +52,18 @@ namespace Nz
};
mutable std::unordered_map<const Shader*, ShaderUniforms> m_shaderUniforms;
mutable std::vector<std::pair<const VertexStruct_XYZ_Color_UV*, std::size_t>> m_spriteChains;
Buffer m_vertexBuffer;
RenderStates m_clearStates;
ShaderRef m_clearShader;
Texture m_whiteTexture;
VertexBuffer m_billboardPointBuffer;
VertexBuffer m_spriteBuffer;
static IndexBuffer s_quadIndexBuffer;
static VertexBuffer s_quadVertexBuffer;
static VertexDeclaration s_billboardInstanceDeclaration;
static VertexDeclaration s_billboardVertexDeclaration;
};
}

View File

@@ -0,0 +1,58 @@
// Copyright (C) 2017 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

View File

@@ -0,0 +1,30 @@
// Copyright (C) 2017 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;
}
}

View File

@@ -14,10 +14,10 @@
namespace Nz
{
class DeferredRenderTechnique;
class DeferredRenderQueue;
struct SceneData;
class DeferredProxyRenderQueue;
class RenderTexture;
class Texture;
struct SceneData;
class NAZARA_GRAPHICS_API DeferredRenderPass
{
@@ -42,7 +42,7 @@ namespace Nz
protected:
Vector2ui m_dimensions;
DeferredRenderTechnique* m_deferredTechnique;
DeferredRenderQueue* m_renderQueue;
DeferredProxyRenderQueue* m_renderQueue;
RenderTexture* m_GBufferRTT;
RenderTexture* m_workRTT;
Texture* m_depthStencilTexture;

View File

@@ -1,89 +0,0 @@
// Copyright (C) 2017 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/ForwardRenderQueue.hpp>
#include <Nazara/Graphics/Material.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/MeshData.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
#include <map>
namespace Nz
{
class NAZARA_GRAPHICS_API DeferredRenderQueue : public AbstractRenderQueue
{
public:
DeferredRenderQueue(ForwardRenderQueue* forwardQueue);
~DeferredRenderQueue() = default;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) override;
void AddDrawable(int renderOrder, const Drawable* drawable) override;
void AddMesh(int renderOrder, const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix) override;
void AddSprites(int renderOrder, const Material* material, const VertexStruct_XYZ_Color_UV* vertices, std::size_t spriteCount, const Texture* overlay = nullptr) override;
void Clear(bool fully = false) override;
struct MeshInstanceEntry
{
NazaraSlot(IndexBuffer, OnIndexBufferRelease, indexBufferReleaseSlot);
NazaraSlot(VertexBuffer, OnVertexBufferRelease, vertexBufferReleaseSlot);
std::vector<Matrix4f> instances;
};
using MeshInstanceContainer = std::map<MeshData, MeshInstanceEntry, ForwardRenderQueue::MeshDataComparator>;
struct BatchedModelEntry
{
NazaraSlot(Material, OnMaterialRelease, materialReleaseSlot);
MeshInstanceContainer meshMap;
bool enabled = false;
};
using MeshMaterialBatches = std::map<const Material*, BatchedModelEntry, ForwardRenderQueue::MaterialComparator>;
struct BatchedMaterialEntry
{
std::size_t maxInstanceCount = 0;
MeshMaterialBatches materialMap;
};
using MeshPipelineBatches = std::map<const MaterialPipeline*, BatchedMaterialEntry, ForwardRenderQueue::MaterialPipelineComparator>;
struct Layer
{
MeshPipelineBatches opaqueModels;
unsigned int clearCount = 0;
};
std::map<int, Layer> layers;
private:
Layer& GetLayer(unsigned int i); ///TODO: Inline
ForwardRenderQueue* m_forwardQueue;
void OnIndexBufferInvalidation(const IndexBuffer* indexBuffer);
void OnMaterialInvalidation(const Material* material);
void OnVertexBufferInvalidation(const VertexBuffer* vertexBuffer);
};
}
#endif // NAZARA_DEFERREDRENDERQUEUE_HPP

View File

@@ -9,7 +9,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
#include <Nazara/Graphics/DeferredRenderQueue.hpp>
#include <Nazara/Graphics/DeferredProxyRenderQueue.hpp>
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Renderer/RenderTexture.hpp>
@@ -64,8 +64,9 @@ namespace Nz
};
std::map<RenderPassType, std::map<int, std::unique_ptr<DeferredRenderPass>>, RenderPassComparator> m_passes;
ForwardRenderTechnique m_forwardTechnique; // Must be initialized before the RenderQueue
DeferredRenderQueue m_renderQueue;
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;

View File

@@ -8,33 +8,33 @@
#define NAZARA_DEPTHRENDERQUEUE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
#include <Nazara/Graphics/BasicRenderQueue.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Matrix4.hpp>
namespace Nz
{
class NAZARA_GRAPHICS_API DepthRenderQueue : public ForwardRenderQueue
class NAZARA_GRAPHICS_API DepthRenderQueue : public BasicRenderQueue
{
public:
DepthRenderQueue();
~DepthRenderQueue() = default;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> 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 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) 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 Texture* overlay = nullptr) 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:
private:
inline bool IsMaterialSuitable(const Material* material) const;
MaterialRef m_baseMaterial;

View File

@@ -35,9 +35,12 @@ namespace Nz
private:
struct ShaderUniforms;
void DrawBasicSprites(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const;
void DrawBillboards(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const;
void DrawOpaqueModels(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) 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;
@@ -59,11 +62,14 @@ namespace Nz
};
mutable std::unordered_map<const Shader*, ShaderUniforms> m_shaderUniforms;
mutable std::vector<std::pair<const VertexStruct_XYZ_Color_UV*, std::size_t>> m_spriteChains;
Buffer m_vertexBuffer;
mutable DepthRenderQueue m_renderQueue;
RenderStates m_clearStates;
ShaderRef m_clearShader;
Texture m_whiteTexture;
VertexBuffer m_billboardPointBuffer;
VertexBuffer m_spriteBuffer;
mutable DepthRenderQueue m_renderQueue;
static IndexBuffer s_quadIndexBuffer;
static VertexBuffer s_quadVertexBuffer;

View File

@@ -1,201 +0,0 @@
// Copyright (C) 2017 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_FORWARDRENDERQUEUE_HPP
#define NAZARA_FORWARDRENDERQUEUE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
#include <Nazara/Graphics/Material.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>
namespace Nz
{
class AbstractViewer;
class NAZARA_GRAPHICS_API ForwardRenderQueue : public AbstractRenderQueue
{
friend class ForwardRenderTechnique;
public:
ForwardRenderQueue() = default;
~ForwardRenderQueue() = default;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const Vector2f> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr = nullptr, SparsePtr<const Color> colorPtr = nullptr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const Vector2f> sinCosPtr, SparsePtr<const float> alphaPtr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const Color> colorPtr = nullptr) override;
void AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) override;
void AddDrawable(int renderOrder, const Drawable* drawable) override;
void AddMesh(int renderOrder, const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix) override;
void AddSprites(int renderOrder, const Material* material, const VertexStruct_XYZ_Color_UV* vertices, std::size_t spriteCount, const Texture* overlay = nullptr) override;
void Clear(bool fully = false) override;
void Sort(const AbstractViewer* viewer);
struct MaterialComparator
{
bool operator()(const Material* mat1, const Material* mat2) const;
};
struct MaterialPipelineComparator
{
bool operator()(const MaterialPipeline* pipeline1, const MaterialPipeline* pipeline2) const;
};
/// Billboards
struct BillboardData
{
Color color;
Vector3f center;
Vector2f size;
Vector2f sinCos;
};
struct BatchedBillboardEntry
{
NazaraSlot(Material, OnMaterialRelease, materialReleaseSlot);
std::vector<BillboardData> billboards;
};
using BatchedBillboardContainer = std::map<const Material*, BatchedBillboardEntry, MaterialComparator>;
struct BatchedBillboardPipelineEntry
{
BatchedBillboardContainer materialMap;
bool enabled = false;
};
using BillboardPipelineBatches = std::map<const MaterialPipeline*, BatchedBillboardPipelineEntry, MaterialPipelineComparator>;
/// Sprites
struct SpriteChain_XYZ_Color_UV
{
const VertexStruct_XYZ_Color_UV* vertices;
std::size_t spriteCount;
};
struct BatchedSpriteEntry
{
NazaraSlot(Texture, OnTextureRelease, textureReleaseSlot);
std::vector<SpriteChain_XYZ_Color_UV> spriteChains;
};
using SpriteOverlayBatches = std::map<const Texture*, BatchedSpriteEntry>;
struct BatchedBasicSpriteEntry
{
NazaraSlot(Material, OnMaterialRelease, materialReleaseSlot);
SpriteOverlayBatches overlayMap;
bool enabled = false;
};
using SpriteMaterialBatches = std::map<const Material*, BatchedBasicSpriteEntry, MaterialComparator>;
struct BatchedSpritePipelineEntry
{
SpriteMaterialBatches materialMap;
bool enabled = false;
};
using SpritePipelineBatches = std::map<const MaterialPipeline*, BatchedSpritePipelineEntry, MaterialPipelineComparator>;
/// Meshes
struct MeshDataComparator
{
bool operator()(const MeshData& data1, const MeshData& data2) const;
};
struct MeshInstanceEntry
{
NazaraSlot(IndexBuffer, OnIndexBufferRelease, indexBufferReleaseSlot);
NazaraSlot(VertexBuffer, OnVertexBufferRelease, vertexBufferReleaseSlot);
std::vector<Matrix4f> instances;
Spheref squaredBoundingSphere;
};
using MeshInstanceContainer = std::map<MeshData, MeshInstanceEntry, MeshDataComparator>;
struct BatchedModelEntry
{
NazaraSlot(Material, OnMaterialRelease, materialReleaseSlot);
MeshInstanceContainer meshMap;
bool enabled = false;
};
using MeshMaterialBatches = std::map<const Material*, BatchedModelEntry, MaterialComparator>;
struct BatchedMaterialEntry
{
std::size_t maxInstanceCount = 0;
MeshMaterialBatches materialMap;
};
using MeshPipelineBatches = std::map<const MaterialPipeline*, BatchedMaterialEntry, MaterialPipelineComparator>;
struct UnbatchedModelData
{
Matrix4f transformMatrix;
MeshData meshData;
Spheref obbSphere;
const Material* material;
};
struct UnbatchedSpriteData
{
std::size_t spriteCount;
const Material* material;
const Texture* overlay;
const VertexStruct_XYZ_Color_UV* vertices;
};
struct Layer
{
BillboardPipelineBatches billboards;
SpritePipelineBatches opaqueSprites;
MeshPipelineBatches opaqueModels;
std::vector<std::size_t> depthSortedMeshes;
std::vector<std::size_t> depthSortedSprites;
std::vector<UnbatchedModelData> depthSortedMeshData;
std::vector<UnbatchedSpriteData> depthSortedSpriteData;
std::vector<const Drawable*> otherDrawables;
unsigned int clearCount = 0;
};
std::map<int, Layer> layers;
private:
BillboardData* GetBillboardData(int renderOrder, const Material* material, unsigned int count);
Layer& GetLayer(int i); ///TODO: Inline
void SortBillboards(Layer& layer, const Planef& nearPlane);
void SortForOrthographic(const AbstractViewer* viewer);
void SortForPerspective(const AbstractViewer* viewer);
void OnIndexBufferInvalidation(const IndexBuffer* indexBuffer);
void OnMaterialInvalidation(const Material* material);
void OnTextureInvalidation(const Texture* texture);
void OnVertexBufferInvalidation(const VertexBuffer* vertexBuffer);
};
}
#endif // NAZARA_FORWARDRENDERQUEUE_HPP

View File

@@ -10,7 +10,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
#include <Nazara/Graphics/BasicRenderQueue.hpp>
#include <Nazara/Graphics/Light.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
@@ -40,11 +40,12 @@ namespace Nz
struct ShaderUniforms;
void ChooseLights(const Spheref& object, bool includeDirectionalLights = true) const;
void DrawBasicSprites(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const;
void DrawBillboards(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const;
void DrawOpaqueModels(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const;
void DrawOrderedSprites(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const;
void DrawTransparentModels(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) 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;
@@ -84,8 +85,9 @@ namespace Nz
mutable std::unordered_map<const Shader*, ShaderUniforms> m_shaderUniforms;
mutable std::vector<LightIndex> m_lights;
mutable std::vector<std::pair<const VertexStruct_XYZ_Color_UV*, std::size_t>> m_spriteChains;
Buffer m_vertexBuffer;
mutable ForwardRenderQueue m_renderQueue;
mutable BasicRenderQueue m_renderQueue;
Texture m_whiteTexture;
VertexBuffer m_billboardPointBuffer;
VertexBuffer m_spriteBuffer;

View File

@@ -2,7 +2,7 @@
// 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/Graphics/ForwardRenderTechnique.hpp>
namespace Nz
{

View File

@@ -37,7 +37,7 @@ namespace Nz
InstancedRenderable(InstancedRenderable&& renderable) = delete;
virtual ~InstancedRenderable();
virtual void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const = 0;
virtual void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const = 0;
virtual bool Cull(const Frustumf& frustum, const InstanceData& instanceData) const;

View File

@@ -11,6 +11,7 @@
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceParameters.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Graphics/InstancedRenderable.hpp>
#include <Nazara/Graphics/Material.hpp>
#include <Nazara/Utility/Mesh.hpp>
@@ -44,8 +45,8 @@ namespace Nz
Model(Model&& model) = default;
virtual ~Model();
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
inline void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix, unsigned int renderOrder = 0);
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;
using InstancedRenderable::GetMaterial;
const MaterialRef& GetMaterial(const String& subMeshName) const;

View File

@@ -22,14 +22,15 @@ namespace Nz
*
* \param renderQueue Queue to be added
* \param transformMatrix Transform matrix to be used for rendering the model
* \param renderOrder Specify the renderqueue layer to be used
* \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, unsigned int renderOrder)
{
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);
return AddToRenderQueue(renderQueue, instanceData, scissorRect);
}
/*!

View File

@@ -0,0 +1,96 @@
// Copyright (C) 2017 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() = 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&&) = 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&&) = 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

View File

@@ -0,0 +1,136 @@
// Copyright (C) 2017 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);
}
}

View File

@@ -38,7 +38,7 @@ namespace Nz
SkeletalModel(SkeletalModel&& model) = default;
~SkeletalModel() = default;
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override;
void AdvanceAnimation(float elapsedTime);
SkeletalModel* Clone() const;

View File

@@ -33,7 +33,7 @@ namespace Nz
Sprite(Sprite&&) = delete;
~Sprite() = default;
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override;
inline const Color& GetColor() const;
inline const Color& GetCornerColor(RectCorner corner) const;

View File

@@ -172,6 +172,7 @@ namespace Nz
{
MaterialRef material = Material::New();
material->EnableFaceCulling(false);
material->EnableScissorTest(true);
SetMaterial(std::move(material));
}

View File

@@ -30,7 +30,7 @@ namespace Nz
inline TextSprite(const TextSprite& sprite);
~TextSprite() = default;
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override;
inline void Clear();

View File

@@ -110,14 +110,7 @@ namespace Nz
inline void TextSprite::SetDefaultMaterial()
{
MaterialRef material = Material::New();
material->EnableBlending(true);
material->EnableDepthWrite(false);
material->EnableFaceCulling(false);
material->SetDstBlend(BlendFunc_InvSrcAlpha);
material->SetSrcBlend(BlendFunc_SrcAlpha);
SetMaterial(material);
SetMaterial(Material::New("Translucent2D"));
}
/*!

View File

@@ -33,7 +33,7 @@ namespace Nz
TileMap(TileMap&&) = delete;
~TileMap() = default;
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override;
inline void DisableTile(const Vector2ui& tilePos);
inline void DisableTiles();