@@ -47,9 +47,17 @@ namespace GITechDemoApp
4747
4848HUDPass::HUDPass (const char * const passName, RenderPass* const parentPass)
4949 : RenderPass(passName, parentPass)
50- , m_pHUDTexture( nullptr )
51- , m_nHUDTextureIdx(- 1 )
50+ , m_nCurrUpdateTexIdx( 0 )
51+ , m_nCurrRenderTexIdx( 0 )
5252{
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+
5361 FT_Library fontLibrary = nullptr ;
5462 FT_Face face = nullptr ;
5563 FT_GlyphSlot slot = nullptr ;
@@ -115,25 +123,33 @@ void HUDPass::Update(const float fDeltaTime)
115123 if (!ResourceMgr)
116124 return ;
117125
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++)
121127 {
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 ())
123131 {
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+ }
127137
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+ }
133144 }
134145
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];
137153}
138154
139155void HUDPass::Draw ()
@@ -149,17 +165,17 @@ void HUDPass::Draw()
149165 if (m_szTextBuf.length () == 0 )
150166 return ;
151167
152- if (m_pHUDTexture->Lock (0 , BL_WRITE_ONLY))
168+ if (m_pHUDTexture[m_nCurrUpdateTexIdx] ->Lock (0 , BL_WRITE_ONLY))
153169 {
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 ));
155171
156172 int pen_x = HUD_TEXT_LEFT_MARGIN;
157173 int pen_y = HUD_TEXT_TOP_MARGIN;
158174
159175 for (unsigned int n = 0 ; n < m_szTextBuf.length (); n++)
160176 {
161177 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 ())
163179 {
164180 pen_x = HUD_TEXT_LEFT_MARGIN;
165181 pen_y += m_pGlyphCache[ch].advance_y >> 6 ;
@@ -177,12 +193,12 @@ void HUDPass::Draw()
177193 for (int j = y, q = 0 ; j < y_max; j++, q++)
178194 {
179195 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 ())
182198 continue ;
183199
184200 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,
186202 m_pGlyphCache[ch].buffer + q * m_pGlyphCache[ch].width ,
187203 m_pGlyphCache[ch].width
188204 );
@@ -192,8 +208,8 @@ void HUDPass::Draw()
192208 pen_x += m_pGlyphCache[ch].advance_x >> 6 ;
193209 }
194210
195- m_pHUDTexture->Update ();
196- m_pHUDTexture->Unlock ();
211+ m_pHUDTexture[m_nCurrUpdateTexIdx] ->Update ();
212+ m_pHUDTexture[m_nCurrUpdateTexIdx] ->Unlock ();
197213 }
198214
199215 const bool sRGBEnabled = RSMgr->GetSRGBWriteEnabled ();
@@ -208,8 +224,8 @@ void HUDPass::Draw()
208224 RSMgr->SetZFunc (CMP_ALWAYS);
209225 RSMgr->SetScissorEnabled (true );
210226
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 ()));
213229
214230 HUDTextShader.Enable ();
215231 RenderContext->DrawVertexBuffer (FullScreenTri);
@@ -229,13 +245,17 @@ void HUDPass::Draw()
229245void HUDPass::ReleaseHUDTexture ()
230246{
231247 Renderer* RenderContext = Renderer::GetInstance ();
232- if (RenderContext)
248+
249+ for (unsigned int idx = 0 ; idx < HUD_TEXTURE_BUFFER_COUNT; idx++)
233250 {
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+ }
238257
239- m_nHUDTextureIdx = ~0u ;
240- m_pHUDTexture = nullptr ;
258+ m_nHUDTextureIdx[idx] = ~0u ;
259+ m_pHUDTexture[idx] = nullptr ;
260+ }
241261}
0 commit comments