All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
RenderQueue.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "Rendering.h"
7 #include "RenderableBase.h"
8 #include "IMaterial.h"
9 #include "Shader.h"
10 #include "StencilLayersController.h"
11 #include <vector>
12 #include <functional>
13 
14 #define LOG_SORT_KEYS 0
15 #define LOG_MATERIAL_CHANGES 0
16 #define LOG_MATERIAL_CHANGE_COUNT 0
17 
18 namespace Eegeo
19 {
20  namespace Rendering
21  {
22  namespace
23  {
24  class RenderableLess : public std::binary_function<const RenderableBase*, const RenderableBase*, bool>
25  {
26  public:
27  inline bool operator()(const RenderableBase* pItemA, const RenderableBase* pItemB) const
28  {
29  const SortKey& sortKeyA = pItemA->GetSortKey();
30  const SortKey& sortKeyB = pItemB->GetSortKey();
31  return sortKeyA < sortKeyB;
32  }
33  };
34  }
35 
41  class RenderQueue : protected Eegeo::NonCopyable
42  {
43  public:
44  RenderQueue(StencilLayersController& stencilLayersController);
45 
46  inline void BeginEnqueuing()
47  {
48  Eegeo_ASSERT(m_inEnqueuePhase == false);
49  m_inEnqueuePhase = true;
50  m_renderables.clear();
51  }
52 
53  void EnqueueRenderable(const RenderableBase* pRenderable);
54 
55  void EnqueueRenderable(const RenderableBase& renderable);
56 
57  void EnqueueRenderables(const std::vector<RenderableBase*>& renderablesToAdd);
58 
59  void EndEnqueuing();
60 
61  void Render(Rendering::GLState& glState);
62 
63  int GetNumOfRenders() const
64  {
65  return m_numOfRenders;
66  }
67 
68  int GetNumOfShaderChanges() const
69  {
70  return m_numOfShaderChanges;
71  }
72 
73  int GetNumOfMaterialChanges() const
74  {
75  return m_numOfMaterialChanges;
76  }
77 
78  int GetNumOfStateRestores() const
79  {
80  return m_numOfStateRestores;
81  }
82 
83  private:
84  bool m_inEnqueuePhase;
85  typedef std::vector<const RenderableBase*> TRenderables;
86  TRenderables m_renderables;
87  StencilLayersController& m_stencilLayersController;
88  int m_numOfRenders;
89  int m_numOfShaderChanges;
90  int m_numOfMaterialChanges;
91  int m_numOfStateRestores;
92 
93  void ClearRenderStats()
94  {
95  m_numOfRenders = 0;
96  m_numOfShaderChanges = 0;
97  m_numOfMaterialChanges = 0;
98  m_numOfStateRestores = 0;
99  }
100  };
101  }
102 }