1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
#include "tiling_render_policy_st.hpp"
#include "../platform/platform.hpp"
#include "../graphics/opengl/opengl.hpp"
#include "../graphics/skin.hpp"
#include "window_handle.hpp"
#include "queued_renderer.hpp"
#include "tile_renderer.hpp"
#include "coverage_generator.hpp"
TilingRenderPolicyST::TilingRenderPolicyST(Params const & p)
: BasicTilingRenderPolicy(p,
true)
{
int cpuCores = GetPlatform().CpuCores();
graphics::ResourceManager::Params rmp = p.m_rmParams;
rmp.checkDeviceCaps();
rmp.m_primaryTexturesParams = graphics::ResourceManager::TexturePoolParams(512,
256,
1,
rmp.m_texFormat,
true,
true,
true,
1,
"primaryTexture",
true,
true);
rmp.m_fontTexturesParams = graphics::ResourceManager::TexturePoolParams(256,
256,
10,
rmp.m_texFormat,
true,
true,
true,
1,
"fontTexture",
true,
true);
rmp.m_primaryStoragesParams = graphics::ResourceManager::StoragePoolParams(6000 * sizeof(graphics::gl::Vertex),
sizeof(graphics::gl::Vertex),
9000 * sizeof(unsigned short),
sizeof(unsigned short),
10,
true,
true,
2,
"primaryStorage",
true,
true);
rmp.m_smallStoragesParams = graphics::ResourceManager::StoragePoolParams(6000 * sizeof(graphics::gl::Vertex),
sizeof(graphics::gl::Vertex),
9000 * sizeof(unsigned short),
sizeof(unsigned short),
1,
true,
true,
1,
"smallStorage",
true,
true);
rmp.m_multiBlitStoragesParams = graphics::ResourceManager::StoragePoolParams(1500 * sizeof(graphics::gl::Vertex),
sizeof(graphics::gl::Vertex),
2500 * sizeof(unsigned short),
sizeof(unsigned short),
1,
true,
true,
1,
"multiBlitStorage",
true,
true);
rmp.m_renderTargetTexturesParams = graphics::ResourceManager::TexturePoolParams(TileSize(),
TileSize(),
1,
rmp.m_texRtFormat,
true,
true,
true,
4,
"renderTargetTexture",
true,
true);
rmp.m_guiThreadStoragesParams = graphics::ResourceManager::StoragePoolParams(2000 * sizeof(graphics::gl::Vertex),
sizeof(graphics::gl::Vertex),
4000 * sizeof(unsigned short),
sizeof(unsigned short),
5,
true,
true,
1,
"guiThreadStorage",
true,
true);
rmp.m_guiThreadTexturesParams = graphics::ResourceManager::TexturePoolParams(256,
128,
2,
rmp.m_texFormat,
true,
true,
true,
1,
"guiThreadTexture",
true,
true);
rmp.m_glyphCacheParams = graphics::ResourceManager::GlyphCacheParams("unicode_blocks.txt",
"fonts_whitelist.txt",
"fonts_blacklist.txt",
2 * 1024 * 1024);
rmp.m_threadSlotsCount = cpuCores + 2;
rmp.m_renderThreadsCount = cpuCores;
// delete [] debuggingFlags;
rmp.m_useSingleThreadedOGL = true;
rmp.fitIntoLimits();
m_maxTilesCount = rmp.m_renderTargetTexturesParams.m_texCount;
m_resourceManager.reset(new graphics::ResourceManager(rmp));
m_QueuedRenderer->SetSinglePipelineProcessing(m_resourceManager->useReadPixelsToSynchronize());
Platform::FilesList fonts;
GetPlatform().GetFontNames(fonts);
m_resourceManager->addFonts(fonts);
SetSkin(make_shared_ptr(graphics::loadSkin(m_resourceManager, SkinName())));
Drawer::Params dp;
dp.m_frameBuffer = make_shared_ptr(new graphics::gl::FrameBuffer(p.m_useDefaultFB));
dp.m_resourceManager = m_resourceManager;
dp.m_threadSlot = m_resourceManager->guiThreadSlot();
dp.m_skin = GetSkin();
dp.m_visualScale = VisualScale();
dp.m_useGuiResources = true;
dp.m_isSynchronized = false;
dp.m_fastSolidPath = true;
dp.m_renderContext = p.m_primaryRC;
// p.m_isDebugging = true;
m_drawer.reset(new Drawer(dp));
InitCacheScreen();
m_windowHandle.reset(new WindowHandle());
m_windowHandle->setUpdatesEnabled(false);
m_windowHandle->setRenderPolicy(this);
m_windowHandle->setVideoTimer(p.m_videoTimer);
m_windowHandle->setRenderContext(p.m_primaryRC);
}
TilingRenderPolicyST::~TilingRenderPolicyST()
{
LOG(LINFO, ("cancelling ResourceManager"));
m_resourceManager->cancel();
int cpuCores = GetPlatform().CpuCores();
LOG(LINFO, ("deleting TilingRenderPolicyST"));
m_QueuedRenderer->PrepareQueueCancellation(cpuCores);
/// now we should process all commands to collect them into queues
m_CoverageGenerator->SetSequenceID(numeric_limits<int>::max());
m_CoverageGenerator->WaitForEmptyAndFinished();
m_QueuedRenderer->CancelQueuedCommands(cpuCores);
LOG(LINFO, ("reseting coverageGenerator"));
m_CoverageGenerator.reset();
/// firstly stop all rendering commands in progress and collect all commands into queues
for (unsigned i = 0; i < cpuCores; ++i)
m_QueuedRenderer->PrepareQueueCancellation(i);
m_TileRenderer->ClearCommands();
m_TileRenderer->SetSequenceID(numeric_limits<int>::max());
m_TileRenderer->CancelCommands();
m_TileRenderer->WaitForEmptyAndFinished();
/// now we should cancel all collected commands
for (unsigned i = 0; i < cpuCores; ++i)
m_QueuedRenderer->CancelQueuedCommands(i);
LOG(LINFO, ("reseting tileRenderer"));
m_TileRenderer.reset();
LOG(LINFO, ("done reseting tileRenderer"));
}
void TilingRenderPolicyST::SetRenderFn(TRenderFn renderFn)
{
int cpuCores = GetPlatform().CpuCores();
string skinName = SkinName();
graphics::PacketsQueue ** queues = new graphics::PacketsQueue*[cpuCores];
for (unsigned i = 0; i < cpuCores; ++i)
queues[i] = m_QueuedRenderer->GetPacketsQueue(i);
m_TileRenderer.reset(new TileRenderer(TileSize(),
skinName,
cpuCores,
m_bgColor,
renderFn,
m_primaryRC,
m_resourceManager,
VisualScale(),
queues));
delete [] queues;
/// CoverageGenerator rendering queue could execute commands partially
/// as there are no render-to-texture calls.
// m_QueuedRenderer->SetPartialExecution(cpuCores, true);
m_CoverageGenerator.reset(new CoverageGenerator(skinName,
m_TileRenderer.get(),
m_windowHandle,
m_primaryRC,
m_resourceManager,
m_QueuedRenderer->GetPacketsQueue(cpuCores),
m_countryNameFn));
}
|