@@ -47,9 +47,17 @@ namespace GITechDemoApp
47
47
48
48
HUDPass::HUDPass (const char * const passName, RenderPass* const parentPass)
49
49
: RenderPass(passName, parentPass)
50
- , m_pHUDTexture( nullptr )
51
- , m_nHUDTextureIdx(- 1 )
50
+ , m_nCurrUpdateTexIdx( 0 )
51
+ , m_nCurrRenderTexIdx( 0 )
52
52
{
53
+ assert (HUD_TEXTURE_BUFFER_COUNT > 0 );
54
+
55
+ for (unsigned int idx = 0 ; idx < HUD_TEXTURE_BUFFER_COUNT; idx++)
56
+ {
57
+ m_pHUDTexture[idx] = nullptr ;
58
+ m_nHUDTextureIdx[idx] = -1 ;
59
+ }
60
+
53
61
FT_Library fontLibrary = nullptr ;
54
62
FT_Face face = nullptr ;
55
63
FT_GlyphSlot slot = nullptr ;
@@ -115,25 +123,33 @@ void HUDPass::Update(const float fDeltaTime)
115
123
if (!ResourceMgr)
116
124
return ;
117
125
118
- if (!m_pHUDTexture ||
119
- RenderContext->GetDisplayResolution ()[0 ] * HUD_TEX_WIDTH_RATIO != m_pHUDTexture->GetWidth () ||
120
- RenderContext->GetDisplayResolution ()[1 ] * HUD_TEX_HEIGHT_RATIO != m_pHUDTexture->GetHeight ())
126
+ for (unsigned int idx = 0 ; idx < HUD_TEXTURE_BUFFER_COUNT; idx++)
121
127
{
122
- if (m_pHUDTexture)
128
+ if (!m_pHUDTexture[idx] ||
129
+ RenderContext->GetDisplayResolution ()[0 ] * HUD_TEX_WIDTH_RATIO != m_pHUDTexture[idx]->GetWidth () ||
130
+ RenderContext->GetDisplayResolution ()[1 ] * HUD_TEX_HEIGHT_RATIO != m_pHUDTexture[idx]->GetHeight ())
123
131
{
124
- ResourceMgr->ReleaseTexture (m_nHUDTextureIdx);
125
- m_pHUDTexture = nullptr ;
126
- }
132
+ if (m_pHUDTexture[idx])
133
+ {
134
+ ResourceMgr->ReleaseTexture (m_nHUDTextureIdx[idx]);
135
+ m_pHUDTexture[idx] = nullptr ;
136
+ }
127
137
128
- m_nHUDTextureIdx = ResourceMgr->CreateTexture (PF_L8, TT_2D,
129
- (unsigned int )(RenderContext->GetDisplayResolution ()[0 ] * HUD_TEX_WIDTH_RATIO),
130
- (unsigned int )(RenderContext->GetDisplayResolution ()[1 ] * HUD_TEX_HEIGHT_RATIO),
131
- 1 , 1 , BU_DYNAMIC);
132
- m_pHUDTexture = ResourceMgr->GetTexture (m_nHUDTextureIdx);
138
+ m_nHUDTextureIdx[idx] = ResourceMgr->CreateTexture (PF_L8, TT_2D,
139
+ (unsigned int )(RenderContext->GetDisplayResolution ()[0 ] * HUD_TEX_WIDTH_RATIO),
140
+ (unsigned int )(RenderContext->GetDisplayResolution ()[1 ] * HUD_TEX_HEIGHT_RATIO),
141
+ 1 , 1 , BU_DYNAMIC);
142
+ m_pHUDTexture[idx] = ResourceMgr->GetTexture (m_nHUDTextureIdx[idx]);
143
+ }
133
144
}
134
145
135
- f2HalfTexelOffset = Vec2f (0 .5f / m_pHUDTexture->GetWidth (), 0 .5f / m_pHUDTexture->GetHeight ());
136
- texSource = m_nHUDTextureIdx;
146
+ // Calculate update and render texture indices
147
+ // m_nCurrRenderTexIdx = m_nCurrUpdateTexIdx;
148
+ m_nCurrUpdateTexIdx = (m_nCurrUpdateTexIdx + 1 ) % HUD_TEXTURE_BUFFER_COUNT;
149
+ m_nCurrRenderTexIdx = (m_nCurrUpdateTexIdx + 1 ) % HUD_TEXTURE_BUFFER_COUNT;
150
+
151
+ f2HalfTexelOffset = Vec2f (0 .5f / m_pHUDTexture[m_nCurrRenderTexIdx]->GetWidth (), 0 .5f / m_pHUDTexture[m_nCurrRenderTexIdx]->GetHeight ());
152
+ texSource = m_nHUDTextureIdx[m_nCurrRenderTexIdx];
137
153
}
138
154
139
155
void HUDPass::Draw ()
@@ -149,17 +165,17 @@ void HUDPass::Draw()
149
165
if (m_szTextBuf.length () == 0 )
150
166
return ;
151
167
152
- if (m_pHUDTexture->Lock (0 , BL_WRITE_ONLY))
168
+ if (m_pHUDTexture[m_nCurrUpdateTexIdx] ->Lock (0 , BL_WRITE_ONLY))
153
169
{
154
- memset (m_pHUDTexture->GetMipData (0 ), 0 , m_pHUDTexture->GetMipSizeBytes (0 ));
170
+ memset (m_pHUDTexture[m_nCurrUpdateTexIdx] ->GetMipData (0 ), 0 , m_pHUDTexture[m_nCurrUpdateTexIdx] ->GetMipSizeBytes (0 ));
155
171
156
172
int pen_x = HUD_TEXT_LEFT_MARGIN;
157
173
int pen_y = HUD_TEXT_TOP_MARGIN;
158
174
159
175
for (unsigned int n = 0 ; n < m_szTextBuf.length (); n++)
160
176
{
161
177
char ch = m_szTextBuf[n];
162
- if (ch == ' \n ' || (unsigned int )(pen_x + m_pGlyphCache[ch].left + m_pGlyphCache[ch].width ) > m_pHUDTexture->GetWidth ())
178
+ if (ch == ' \n ' || (unsigned int )(pen_x + m_pGlyphCache[ch].left + m_pGlyphCache[ch].width ) > m_pHUDTexture[m_nCurrUpdateTexIdx] ->GetWidth ())
163
179
{
164
180
pen_x = HUD_TEXT_LEFT_MARGIN;
165
181
pen_y += m_pGlyphCache[ch].advance_y >> 6 ;
@@ -177,12 +193,12 @@ void HUDPass::Draw()
177
193
for (int j = y, q = 0 ; j < y_max; j++, q++)
178
194
{
179
195
if (x < 0 || j < 0 ||
180
- x_max >= (FT_Int)m_pHUDTexture->GetWidth () ||
181
- j >= (FT_Int)m_pHUDTexture->GetHeight ())
196
+ x_max >= (FT_Int)m_pHUDTexture[m_nCurrUpdateTexIdx] ->GetWidth () ||
197
+ j >= (FT_Int)m_pHUDTexture[m_nCurrUpdateTexIdx] ->GetHeight ())
182
198
continue ;
183
199
184
200
memcpy (
185
- m_pHUDTexture->GetMipData (0 ) + j * m_pHUDTexture->GetWidth () + x,
201
+ m_pHUDTexture[m_nCurrUpdateTexIdx] ->GetMipData (0 ) + j * m_pHUDTexture[m_nCurrUpdateTexIdx] ->GetWidth () + x,
186
202
m_pGlyphCache[ch].buffer + q * m_pGlyphCache[ch].width ,
187
203
m_pGlyphCache[ch].width
188
204
);
@@ -192,8 +208,8 @@ void HUDPass::Draw()
192
208
pen_x += m_pGlyphCache[ch].advance_x >> 6 ;
193
209
}
194
210
195
- m_pHUDTexture->Update ();
196
- m_pHUDTexture->Unlock ();
211
+ m_pHUDTexture[m_nCurrUpdateTexIdx] ->Update ();
212
+ m_pHUDTexture[m_nCurrUpdateTexIdx] ->Unlock ();
197
213
}
198
214
199
215
const bool sRGBEnabled = RSMgr->GetSRGBWriteEnabled ();
@@ -208,8 +224,8 @@ void HUDPass::Draw()
208
224
RSMgr->SetZFunc (CMP_ALWAYS);
209
225
RSMgr->SetScissorEnabled (true );
210
226
211
- RenderContext->SetViewport (Vec2i (m_pHUDTexture->GetWidth (), m_pHUDTexture->GetHeight ()));
212
- RSMgr->SetScissor (Vec2i (m_pHUDTexture->GetWidth (), m_pHUDTexture->GetHeight ()));
227
+ RenderContext->SetViewport (Vec2i (m_pHUDTexture[m_nCurrRenderTexIdx] ->GetWidth (), m_pHUDTexture[m_nCurrRenderTexIdx] ->GetHeight ()));
228
+ RSMgr->SetScissor (Vec2i (m_pHUDTexture[m_nCurrRenderTexIdx] ->GetWidth (), m_pHUDTexture[m_nCurrRenderTexIdx] ->GetHeight ()));
213
229
214
230
HUDTextShader.Enable ();
215
231
RenderContext->DrawVertexBuffer (FullScreenTri);
@@ -229,13 +245,17 @@ void HUDPass::Draw()
229
245
void HUDPass::ReleaseHUDTexture ()
230
246
{
231
247
Renderer* RenderContext = Renderer::GetInstance ();
232
- if (RenderContext)
248
+
249
+ for (unsigned int idx = 0 ; idx < HUD_TEXTURE_BUFFER_COUNT; idx++)
233
250
{
234
- ResourceManager* ResourceMgr = RenderContext->GetResourceManager ();
235
- if (ResourceMgr && m_nHUDTextureIdx != ~0u )
236
- ResourceMgr->ReleaseTexture (m_nHUDTextureIdx);
237
- }
251
+ if (RenderContext)
252
+ {
253
+ ResourceManager* ResourceMgr = RenderContext->GetResourceManager ();
254
+ if (ResourceMgr && m_nHUDTextureIdx[idx] != ~0u )
255
+ ResourceMgr->ReleaseTexture (m_nHUDTextureIdx[idx]);
256
+ }
238
257
239
- m_nHUDTextureIdx = ~0u ;
240
- m_pHUDTexture = nullptr ;
258
+ m_nHUDTextureIdx[idx] = ~0u ;
259
+ m_pHUDTexture[idx] = nullptr ;
260
+ }
241
261
}
0 commit comments