Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
ForwardRenderTechnique.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_FORWARDRENDERTECHNIQUE_HPP
8 #define NAZARA_FORWARDRENDERTECHNIQUE_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Graphics/AbstractRenderTechnique.hpp>
12 #include <Nazara/Graphics/Config.hpp>
13 #include <Nazara/Graphics/ForwardRenderQueue.hpp>
14 #include <Nazara/Graphics/Light.hpp>
15 #include <Nazara/Renderer/Shader.hpp>
16 #include <Nazara/Utility/IndexBuffer.hpp>
17 #include <Nazara/Utility/VertexBuffer.hpp>
18 
19 namespace Nz
20 {
21  class NAZARA_GRAPHICS_API ForwardRenderTechnique : public AbstractRenderTechnique
22  {
23  public:
25  ~ForwardRenderTechnique() = default;
26 
27  void Clear(const SceneData& sceneData) const override;
28  bool Draw(const SceneData& sceneData) const override;
29 
30  unsigned int GetMaxLightPassPerObject() const;
31  AbstractRenderQueue* GetRenderQueue() override;
32  RenderTechniqueType GetType() const override;
33 
34  void SetMaxLightPassPerObject(unsigned int maxLightPassPerObject);
35 
36  static bool Initialize();
37  static void Uninitialize();
38 
39  protected:
40  struct ShaderUniforms;
41 
42  void ChooseLights(const Spheref& object, bool includeDirectionalLights = true) const;
43  void DrawBasicSprites(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const;
44  void DrawBillboards(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const;
45  void DrawOpaqueModels(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const;
46  void DrawOrderedSprites(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const;
47  void DrawTransparentModels(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const;
48  const ShaderUniforms* GetShaderUniforms(const Shader* shader) const;
49  void OnShaderInvalidated(const Shader* shader) const;
50  void SendLightUniforms(const Shader* shader, const LightUniforms& uniforms, unsigned int index, unsigned int lightIndex, unsigned int uniformOffset) const;
51 
52  static float ComputeDirectionalLightScore(const Spheref& object, const AbstractRenderQueue::DirectionalLight& light);
53  static float ComputePointLightScore(const Spheref& object, const AbstractRenderQueue::PointLight& light);
54  static float ComputeSpotLightScore(const Spheref& object, const AbstractRenderQueue::SpotLight& light);
55  static bool IsDirectionalLightSuitable(const Spheref& object, const AbstractRenderQueue::DirectionalLight& light);
56  static bool IsPointLightSuitable(const Spheref& object, const AbstractRenderQueue::PointLight& light);
57  static bool IsSpotLightSuitable(const Spheref& object, const AbstractRenderQueue::SpotLight& light);
58 
59  struct LightIndex
60  {
61  LightType type;
62  float score;
63  unsigned int index;
64  };
65 
66  struct ShaderUniforms
67  {
68  NazaraSlot(Shader, OnShaderUniformInvalidated, shaderUniformInvalidatedSlot);
69  NazaraSlot(Shader, OnShaderRelease, shaderReleaseSlot);
70 
71  LightUniforms lightUniforms;
72  bool hasLightUniforms;
73 
76  int lightOffset; // "Distance" between Lights[0].type and Lights[1].type
77 
78  // Other uniforms
79  int eyePosition;
80  int reflectionMap;
81  int sceneAmbient;
82  int textureOverlay;
83  };
84 
85  mutable std::unordered_map<const Shader*, ShaderUniforms> m_shaderUniforms;
86  mutable std::vector<LightIndex> m_lights;
87  Buffer m_vertexBuffer;
88  mutable ForwardRenderQueue m_renderQueue;
89  Texture m_whiteTexture;
90  VertexBuffer m_billboardPointBuffer;
91  VertexBuffer m_spriteBuffer;
92  unsigned int m_maxLightPassPerObject;
93 
94  static IndexBuffer s_quadIndexBuffer;
95  static Texture s_dummyReflection;
96  static TextureSampler s_reflectionSampler;
97  static TextureSampler s_shadowSampler;
98  static VertexBuffer s_quadVertexBuffer;
99  static VertexDeclaration s_billboardInstanceDeclaration;
100  static VertexDeclaration s_billboardVertexDeclaration;
101  };
102 }
103 
104 #include <Nazara/Graphics/ForwardRenderTechnique.inl>
105 
106 #endif // NAZARA_FORWARDRENDERTECHNIQUE_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Graphics class that represents the rendering queue for our scene.
Definition: AbstractRenderQueue.hpp:26
Graphics class that represents the rendering technique for our scene.
Definition: AbstractRenderTechnique.hpp:20
Graphics class that represents the technique used in forward rendering.
Definition: ForwardRenderTechnique.hpp:21
Graphics class that represents the rendering queue for forward rendering.
Definition: ForwardRenderQueue.hpp:26