All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
TextRendererStateComponent.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "IScreenTextRenderer.h"
7 #include "DebugRendering.h"
8 #include "IdTypes.h"
9 #include "Fonts.h"
10 #include "BatchedTextAppearanceBuilder.h"
11 #include "Text.h"
12 #include "FontInstance.h"
13 #include "LayerIds.h"
14 #include "FontMaterialSetProperties.h"
15 
16 namespace Eegeo
17 {
18  namespace Text
19  {
21  {
22  public:
24  FontMaterialCache& fontMaterialCache,
25  bool enableSupersampling,
26  bool uniformScale
27  );
28 
29  void SetFontInstance(const Fonts::FontInstance* pFontInstance)
30  {
31  m_fontInstanceChanged = m_pFontInstance != pFontInstance;
32  m_pFontInstance = pFontInstance;
33  }
34 
35  void SetDefaultState();
36 
37  void SetTextSize(float pixelHeight)
38  {
39  m_textAppearanceBuilder.SetSize(pixelHeight);
40  m_textAppearanceChanged = true;
41  if (m_pFontInstance != NULL)
42  {
43  const bool prevMinifying = m_batchedTextAppearance.GetSize() < m_pFontInstance->GetHeight();
44  const bool minifying = pixelHeight < m_pFontInstance->GetHeight();
45  m_minificationChanged = minifying != prevMinifying;
46  }
47  }
48 
49  void SetGlyphColor(const v4& color)
50  {
51  m_textAppearanceBuilder.SetGlyphColor(color);
52  m_textAppearanceChanged = true;
53  }
54 
55  void SetOutlineColor(const v4& color)
56  {
57  m_textAppearanceBuilder.SetOutlineColor(color);
58  m_textAppearanceChanged = true;
59  }
60 
61  void SetHaloStyle(const v4& color, float haloWidth, float haloHardness)
62  {
63  m_textAppearanceBuilder.SetHaloColor(color);
64  m_textAppearanceBuilder.SetHaloWidth(haloWidth);
65  m_textAppearanceBuilder.SetHaloHardness(haloHardness);
66  m_textAppearanceChanged = true;
67  }
68 
69  void SetTransform(const v2& translate, const v2& rotate, const v2& scale)
70  {
71  m_translate = translate;
72  m_rotate = rotate;
73  m_scale = scale;
74  }
75 
76  void SetDepthTest(bool depthTest)
77  {
78  m_textAppearanceBuilder.SetDepthTest(depthTest);
79  m_textAppearanceChanged = true;
80  }
81 
82  void SetStencilTest(bool stencilTest)
83  {
84  m_textAppearanceBuilder.SetStencilTest(stencilTest);
85  m_textAppearanceChanged = true;
86  }
87 
88  void SetStencilFunc(GLenum stencilFunc, int stencilRef, u32 stencilMask)
89  {
90  m_textAppearanceBuilder.SetStencilFunc(stencilFunc, stencilRef, stencilMask);
91  m_textAppearanceChanged = true;
92  }
93 
94  void SetStencilMaskedStyle(bool enable, GLenum stencilFunc, const v4& glyphColor, const v4& haloColor)
95  {
96  m_textAppearanceBuilder.SetStencilMaskedStyle(enable, stencilFunc, glyphColor, haloColor);
97  m_textAppearanceChanged = true;
98  }
99 
100  void SetRenderLayer(Rendering::LayerIds::Values layer, int subLayer)
101  {
102  m_layerChanged = m_layer != layer || m_subLayer != subLayer;
103  m_layer = layer;
104  m_subLayer = subLayer;
105  }
106 
107  void SetAlpha(float alpha)
108  {
109  m_alpha = alpha;
110  }
111 
112  v2 GetTranslate() const { return m_translate; }
113  v2 GetRotate() const { return m_rotate; }
114  v2 GetScale() const { return m_scale; }
115  float GetAlpha() const { return m_alpha; }
116 
117  Rendering::LayerIds::Values GetLayer() const { return m_layer; }
118  int GetSubLayer() const { return m_subLayer; }
119 
120 
121  bool NeedsCachedStateUpdate() const { return m_textAppearanceChanged || m_fontInstanceChanged || m_minificationChanged || m_layerChanged; }
122 
123  bool NeedsRenderableSetup() const { return m_fontInstanceChanged || m_minificationChanged || m_layerChanged; }
124 
125 
126  void UpdateCachedState();
127 
128  const Fonts::FontInstance* GetFontInstance() const { return m_pFontInstance; }
129 
130  const Fonts::FontMaterialSet* GetFontMaterialSetForeground() const { return m_pFontMaterialSetForeground; }
131 
132  const Fonts::FontMaterialSet* GetFontMaterialSetHalo() const { return m_pFontMaterialSetHalo; }
133 
134  const Text::BatchedTextAppearance& GetBatchedTextAppearance() const { return m_batchedTextAppearance; }
135 
136  const Fonts::FontCharacter& GetFontCharacter(u32 codepointUtf32) { return m_pFontInstance->GetCharacter(codepointUtf32); }
137 
138  private:
139  Fonts::FontMaterialSet* GetFontMaterialSetForFontInstance(const Fonts::FontInstance& fontInstance);
140 
141  Fonts::FontMaterialSet* CreateFontMaterialSet(const Fonts::FontInstance& fontInstance);
142 
143  Fonts::IFontMaterialSetFactory& m_fontMaterialSetFactory;
144  FontMaterialCache& m_fontMaterialCache;
145 
146  Text::BatchedTextAppearanceBuilder m_textAppearanceBuilder;
147  Text::BatchedTextAppearance m_batchedTextAppearance;
148 
149  const Fonts::FontInstance* m_pFontInstance;
150  const Fonts::FontMaterialSet* m_pFontMaterialSetForeground;
151  const Fonts::FontMaterialSet* m_pFontMaterialSetHalo;
152 
153  v2 m_translate;
154  v2 m_rotate;
155  v2 m_scale;
156  float m_alpha;
157  Rendering::LayerIds::Values m_layer;
158  int m_subLayer;
159 
160  bool m_textAppearanceChanged;
161  bool m_fontInstanceChanged;
162  bool m_minificationChanged;
163  bool m_layerChanged;
164  const bool m_enableSupersampling;
165  const bool m_uniformScale;
166  };
167  }
168 }