All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SimpleRenderFilter.h
1 // Copyright (c) 2015 eeGeo. All rights reserved.
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "RenderableFilters.h"
7 #include "IRenderableFilter.h"
8 #include "WorldMeshRenderable.h"
9 #include "RenderQueue.h"
10 
11 #include <algorithm>
12 
13 namespace Eegeo
14 {
15  namespace Rendering
16  {
17  namespace Filters
18  {
19  template <typename TViewType>
21  {
22  public:
23  void EnqueueRenderables(const Rendering::RenderContext& renderContext, Rendering::RenderQueue& renderQueue)
24  {
25  for(typename std::vector<TViewType*>::iterator iter = m_views.begin();
26  iter != m_views.end();
27  ++iter)
28  {
29  TViewType* pView = (*iter);
30 
31  UpdateView(renderContext, *pView);
32 
33  renderQueue.EnqueueRenderable(pView->GetRenderable());
34  }
35  }
36 
37  void AddView(TViewType& view)
38  {
39  Eegeo_ASSERT(
40  std::find(m_views.begin(), m_views.end(), &view) == m_views.end(),
41  "Cannot add view, as it has already been added");
42 
43  m_views.push_back(&view);
44  }
45 
46  void RemoveView(TViewType& view)
47  {
48  Eegeo_ASSERT(
49  std::find(m_views.begin(), m_views.end(), &view) != m_views.end(),
50  "Cannot remove view, as it has not been added");
51 
52  m_views.erase(std::remove(m_views.begin(), m_views.end(), &view));
53  }
54 
55  void Clear()
56  {
57  m_views.clear();
58  }
59 
60  protected:
61  virtual void UpdateView(const Rendering::RenderContext& renderContext, TViewType& view)
62  {
63  view.Update();
64 
65  view.GetRenderable()->UpdateMVP(renderContext, 1.0f);
66  }
67 
68  const std::vector<TViewType*>& GetViews() const
69  {
70  return m_views;
71  }
72  private:
73  std::vector<TViewType*> m_views;
74  };
75  }
76  }
77 }