All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
IconRendererStateComponent.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "IScreenIconRenderer.h"
7 #include "IdTypes.h"
8 #include "BatchedIconAppearanceBuilder.h"
9 #include "BatchedIconAppearance.h"
10 #include "Icons.h"
11 #include "LayerIds.h"
12 #include "VectorMathDecl.h"
13 #include "IconSet.h"
14 #include "IconDefinition.h"
15 
16 namespace Eegeo
17 {
18  namespace Icons
19  {
21  {
22  public:
23  IconRendererStateComponent(IconMaterialSetFactory& iconMaterialSetFactory,
24  IconMaterialSetCache& iconMaterialSetCache
25  );
26 
27  void SetIconSet(const IconSet* pIconSet)
28  {
29  m_pIconSet = pIconSet;
30  m_iconSetChanged = true;
31  }
32 
33  void SetDefaultState();
34 
35  void SetIconColor(const v4& iconColor)
36  {
37  m_appearanceBuilder.SetIconColor(iconColor);
38  m_appearanceChanged = true;
39  }
40 
41  void SetScale(float scale)
42  {
43  m_appearanceBuilder.SetScale(scale);
44  m_appearanceChanged = true;
45  }
46 
47  void SetTransform(const v2& translate, const v2& rotate, const v2& scale)
48  {
49  m_translate = translate;
50  m_rotate = rotate;
51  m_scale = scale;
52  }
53 
54  void SetDepthTest(bool depthTest)
55  {
56  m_appearanceBuilder.SetDepthTest(depthTest);
57  m_appearanceChanged = true;
58  }
59 
60  void SetStencilTest(bool stencilTest)
61  {
62  m_appearanceBuilder.SetStencilTest(stencilTest);
63  m_appearanceChanged = true;
64  }
65 
66  void SetStencilFunc(GLenum stencilFunc, int stencilRef, u32 stencilMask)
67  {
68  m_appearanceBuilder.SetStencilFunc(stencilFunc, stencilRef, stencilMask);
69  m_appearanceChanged = true;
70  }
71 
72  void SetStencilMaskedStyle(bool enable, GLenum stencilFunc, const v4& maskedIconColor)
73  {
74  m_appearanceBuilder.SetStencilMaskedStyle(enable, stencilFunc, maskedIconColor);
75  m_appearanceChanged = true;
76  }
77 
78  void SetRenderLayer(Rendering::LayerIds::Values layer, int subLayer)
79  {
80  m_layer = layer;
81  m_subLayer = subLayer;
82  m_layerChanged = true;
83  }
84 
85  void SetAlpha(float alpha)
86  {
87  m_alpha = alpha;
88  }
89 
90  v2 GetTranslate() const { return m_translate; }
91  v2 GetRotate() const { return m_rotate; }
92  v2 GetScale() const { return m_scale; }
93  float GetAlpha() const { return m_alpha; }
94 
95  Rendering::LayerIds::Values GetLayer() const { return m_layer; }
96  int GetSubLayer() const { return m_subLayer; }
97 
98 
99  bool NeedsCachedStateUpdate() const { return m_appearanceChanged || m_iconSetChanged || m_layerChanged; }
100 
101  void UpdateCachedState();
102 
103  const IconSet* GetIconSet() const { return m_pIconSet; }
104 
105  const IconDefinition& GetIconDefinition(const IconDefinition::IdType& iconKey) const { return m_pIconSet->GetIconDefinition(iconKey); }
106 
107  const MaterialSet* GetIconMaterialSet() const { return m_pIconMaterialSet; }
108 
109  const BatchedIconAppearance& GetBatchedAppearance() const { return m_batchedAppearance; }
110 
111  private:
112 
113  MaterialSet* GetIconMaterialSetForIconSet(const IconSet& iconSet);
114 
115  MaterialSet* CreateIconMaterialSet(const IconSet& iconSet);
116 
117  IconMaterialSetFactory& m_iconMaterialSetFactory;
118  IconMaterialSetCache& m_iconMaterialSetCache;
119 
120  BatchedIconAppearanceBuilder m_appearanceBuilder;
121  BatchedIconAppearance m_batchedAppearance;
122 
123  const MaterialSet* m_pIconMaterialSet;
124  const IconSet* m_pIconSet;
125 
126  v2 m_translate;
127  v2 m_rotate;
128  v2 m_scale;
129  float m_alpha;
130  Rendering::LayerIds::Values m_layer;
131  int m_subLayer;
132 
133  bool m_appearanceChanged;
134  bool m_iconSetChanged;
135  bool m_layerChanged;
136  };
137  }
138 }