Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
DeferredRenderQueue.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Engine - Graphics module"
3 // For conditions of distribution and use, see copyright notice in Config.hpp
4 
5 #pragma once
6 
7 #ifndef NAZARA_DEFERREDRENDERQUEUE_HPP
8 #define NAZARA_DEFERREDRENDERQUEUE_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Graphics/ForwardRenderQueue.hpp>
12 #include <Nazara/Graphics/Material.hpp>
13 #include <Nazara/Math/Box.hpp>
14 #include <Nazara/Math/Matrix4.hpp>
15 #include <Nazara/Utility/IndexBuffer.hpp>
16 #include <Nazara/Utility/MeshData.hpp>
17 #include <Nazara/Utility/VertexBuffer.hpp>
18 #include <map>
19 
20 namespace Nz
21 {
22  class NAZARA_GRAPHICS_API DeferredRenderQueue : public AbstractRenderQueue
23  {
24  public:
26  ~DeferredRenderQueue() = default;
27 
28  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;
29  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;
30  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;
31  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;
32  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;
33  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;
34  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;
35  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;
36  void AddDrawable(int renderOrder, const Drawable* drawable) override;
37  void AddMesh(int renderOrder, const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix) override;
38  void AddSprites(int renderOrder, const Material* material, const VertexStruct_XYZ_Color_UV* vertices, std::size_t spriteCount, const Texture* overlay = nullptr) override;
39 
40  void Clear(bool fully = false) override;
41 
42  struct MeshInstanceEntry
43  {
44  NazaraSlot(IndexBuffer, OnIndexBufferRelease, indexBufferReleaseSlot);
45  NazaraSlot(VertexBuffer, OnVertexBufferRelease, vertexBufferReleaseSlot);
46 
47  std::vector<Matrix4f> instances;
48  };
49 
50  typedef std::map<MeshData, MeshInstanceEntry, ForwardRenderQueue::MeshDataComparator> MeshInstanceContainer;
51 
52  struct BatchedModelEntry
53  {
54  NazaraSlot(Material, OnMaterialRelease, materialReleaseSlot);
55 
56  MeshInstanceContainer meshMap;
57  bool enabled = false;
58  };
59 
60  typedef std::map<const Material*, BatchedModelEntry, ForwardRenderQueue::MaterialComparator> MeshMaterialBatches;
61 
62  struct BatchedMaterialEntry
63  {
64  std::size_t maxInstanceCount = 0;
65  MeshMaterialBatches materialMap;
66  };
67 
68  typedef std::map<const MaterialPipeline*, BatchedMaterialEntry, ForwardRenderQueue::MaterialPipelineComparator> MeshPipelineBatches;
69 
70  struct Layer
71  {
72  MeshPipelineBatches opaqueModels;
73  unsigned int clearCount = 0;
74  };
75 
76  std::map<int, Layer> layers;
77 
78  private:
79  Layer& GetLayer(unsigned int i);
80 
81  ForwardRenderQueue* m_forwardQueue;
82 
83  void OnIndexBufferInvalidation(const IndexBuffer* indexBuffer);
84  void OnMaterialInvalidation(const Material* material);
85  void OnVertexBufferInvalidation(const VertexBuffer* vertexBuffer);
86  };
87 }
88 
89 #endif // NAZARA_DEFERREDRENDERQUEUE_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Graphics class that represents the rendering queue for our scene.
Definition: AbstractRenderQueue.hpp:26
Core class that represents a pointer and the step between two elements.
Definition: SparsePtr.hpp:19
Graphics class that represents a material.
Definition: Material.hpp:51
Graphics class that represents the rendering queue for forward rendering.
Definition: ForwardRenderQueue.hpp:26
Graphics class that represents the rendering queue for deferred rendering.
Definition: DeferredRenderQueue.hpp:22
Graphics class that represents something drawable for our scene.
Definition: Drawable.hpp:15