10 #include "VectorMath.h"
11 #include "BatchedTextRenderable.h"
13 #include "IBatchedTextRenderableFactory.h"
14 #include "ITextMaterialFactory.h"
15 #include "FontInstance.h"
16 #include "FontCharacter.h"
17 #include "FontMaterialSetBuilder.h"
18 #include "FontMaterialSet.h"
30 template <
typename TBatchedTextRenderable,
typename TBatchedTextRenderableFactory>
35 typedef TBatchedTextRenderableFactory BatchedTextRenderableFactoryType;
39 typedef std::pair<Rendering::SortKey, Rendering::SortKey> SortKeyPair;
40 typedef std::map<SortKeyPair, BatchedTextRenderableType*> TSortKeyToTextRenderable;
44 typedef typename TSortKeyToTextRenderable::const_iterator TextRenderableIterator;
47 TBatchedTextRenderableFactory& batchedTextRenderableFactory,
49 : m_batchedTextRenderableFactory(batchedTextRenderableFactory)
50 , m_vertexBuffer(vertexBuffer)
55 for (
typename TSortKeyToTextRenderable::const_iterator iter = m_sortKeyToTextRenderable.begin(); iter != m_sortKeyToTextRenderable.end(); ++iter)
58 Eegeo_DELETE pTextRenderable;
64 const Fonts::FontMaterialSet::TMaterialVector& foregroundMaterials = fontMaterialSetNonHalo.GetMaterials();
65 const Fonts::FontMaterialSet::TMaterialVector& haloMaterials = fontMaterialSetHalo.GetMaterials();
66 Eegeo_ASSERT(foregroundMaterials.size() == haloMaterials.size());
68 m_foregroundLayerTextRenderables.clear();
69 m_foregroundLayerTextRenderables.reserve(foregroundMaterials.size());
70 m_haloLayerTextRenderables.clear();
71 m_haloLayerTextRenderables.reserve(haloMaterials.size());
73 const Rendering::SortKey& sortKeyForegroundLayer = BatchedTextRenderable::MakeSortKeyForLayer(layerId, subLayer,
false);
74 const Rendering::SortKey& sortKeyHaloLayer = BatchedTextRenderable::MakeSortKeyForLayer(layerId, subLayer,
true);
76 for (
int i = 0; i < foregroundMaterials.size(); ++i)
79 const Rendering::SortKey& sortKeyForeground = BatchedTextRenderable::MakeSortKey(foregroundMaterial, sortKeyForegroundLayer);
81 if (pForegroundBatchedTextRenderable == NULL)
83 pForegroundBatchedTextRenderable = CreateAndAddRenderable(sortKeyForeground, foregroundMaterial, NULL);
85 m_foregroundLayerTextRenderables.push_back(pForegroundBatchedTextRenderable);
89 const Rendering::SortKey& sortKeyHalo = BatchedTextRenderable::MakeSortKey(haloMaterial, sortKeyHaloLayer);
91 if (pHaloBatchedTextRenderable == NULL)
93 pHaloBatchedTextRenderable = CreateAndAddRenderable(sortKeyHalo, haloMaterial, pForegroundBatchedTextRenderable);
95 m_haloLayerTextRenderables.push_back(pHaloBatchedTextRenderable);
99 void ClearCurrentFont()
101 m_foregroundLayerTextRenderables.clear();
102 m_haloLayerTextRenderables.clear();
105 typename BatchedTextRenderableType::VertexListType& GetTextVertexList(
int texturePage)
const
107 return m_foregroundLayerTextRenderables[texturePage]->GetVertexList();
112 UpdateTextAppearanceOnRenderables(batchedTextAppearance, m_foregroundLayerTextRenderables);
113 UpdateTextAppearanceOnRenderables(batchedTextAppearance, m_haloLayerTextRenderables);
117 TextRenderableIterator TextRenderablesBegin()
const {
return m_sortKeyToTextRenderable.begin(); }
118 TextRenderableIterator TextRenderablesEnd()
const {
return m_sortKeyToTextRenderable.end(); }
122 m_vertexBuffer.Reset();
124 for (TextRenderableIterator iter = TextRenderablesBegin(); iter != TextRenderablesEnd(); ++iter)
127 textRenderable.Reset();
133 m_vertexBuffer.Swap();
134 m_vertexBuffer.Reset();
136 int totalVertexCount = 0;
137 for (TextRenderableIterator iter = TextRenderablesBegin(); iter != TextRenderablesEnd(); ++iter)
140 textRenderable.Finalize();
142 if (textRenderable.IsPrimary())
144 totalVertexCount +=
static_cast<int>(textRenderable.GetVertexList().size());
148 m_vertexBuffer.Reserve(totalVertexCount);
153 m_vertexBuffer.Bind();
155 for (TextRenderableIterator iter = TextRenderablesBegin(); iter != TextRenderablesEnd(); ++iter)
158 textRenderable.Upload();
161 m_vertexBuffer.Unbind();
167 void UpdateTextAppearanceOnRenderables(
const BatchedTextAppearance& batchedTextAppearance,
typename std::vector<TBatchedTextRenderable*>& renderables)
169 for (
typename std::vector<TBatchedTextRenderable*>::const_iterator iter = renderables.begin(); iter != renderables.end(); ++iter)
172 pTextRenderable->SetTextAppearance(batchedTextAppearance);
179 typename TSortKeyToTextRenderable::const_iterator iter = m_sortKeyToTextRenderable.find(std::make_pair(sortKey, sortKeyPrimary));
181 if (iter == m_sortKeyToTextRenderable.end())
191 BatchedTextRenderableType* pBatchedTextRenderableType = m_batchedTextRenderableFactory.Create(material, sortKey, pPrimaryRenderable);
195 const SortKeyPair sortKeyPair(std::make_pair(sortKey, sortKeyPrimary));
197 m_sortKeyToTextRenderable.insert(std::make_pair(sortKeyPair, pBatchedTextRenderableType));
198 return pBatchedTextRenderableType;
202 TBatchedTextRenderableFactory& m_batchedTextRenderableFactory;
205 std::vector<TBatchedTextRenderable*> m_foregroundLayerTextRenderables;
206 std::vector<TBatchedTextRenderable*> m_haloLayerTextRenderables;
208 TSortKeyToTextRenderable m_sortKeyToTextRenderable;