Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
Removed generating new texture repeatedly during character cache. (op…
Browse files Browse the repository at this point in the history
…t_ttf_gl xbmc#4884)
  • Loading branch information
epoke committed Jun 16, 2014
1 parent d303e1a commit fc212a4
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 13 deletions.
72 changes: 60 additions & 12 deletions xbmc/guilib/GUIFontTTFGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ using namespace std;
CGUIFontTTFGL::CGUIFontTTFGL(const CStdString& strFileName)
: CGUIFontTTFBase(strFileName)
{
m_updateY1 = 0;
m_updateY2 = 0;
m_textureStatus = TEXTURE_VOID;
}

CGUIFontTTFGL::~CGUIFontTTFGL(void)
Expand All @@ -54,6 +57,14 @@ void CGUIFontTTFGL::Begin()
{
if (m_nestedBeginCount == 0 && m_texture != NULL)
{
if (m_textureStatus == TEXTURE_REALLOCATED)
{
if (glIsTexture(m_nTexture))
g_TextureManager.ReleaseHwTexture(m_nTexture);
m_bTextureLoaded = false;
m_textureStatus = TEXTURE_VOID;
}

if (!m_bTextureLoaded)
{
// Have OpenGL generate a texture object handle for us
Expand All @@ -70,12 +81,24 @@ void CGUIFontTTFGL::Begin()

// Set the texture image -- THIS WORKS, so the pixels must be wrong.
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, m_texture->GetWidth(), m_texture->GetHeight(), 0,
GL_ALPHA, GL_UNSIGNED_BYTE, m_texture->GetPixels());

GL_ALPHA, GL_UNSIGNED_BYTE, 0);
VerifyGLState();
m_textureStatus = TEXTURE_UPDATED;
m_bTextureLoaded = true;
}

if (m_textureStatus == TEXTURE_UPDATED)
{
glBindTexture(GL_TEXTURE_2D, m_nTexture);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, m_updateY1, m_texture->GetWidth(), m_updateY2 - m_updateY1, GL_ALPHA, GL_UNSIGNED_BYTE,
m_texture->GetPixels() + m_updateY1 * m_texture->GetPitch());
glDisable(GL_TEXTURE_2D);

m_updateY1 = m_updateY2 = 0;
m_textureStatus = TEXTURE_READY;
}

// Turn Blending On
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_ONE);
glEnable(GL_BLEND);
Expand Down Expand Up @@ -216,6 +239,9 @@ CBaseTexture* CGUIFontTTFGL::ReallocTexture(unsigned int& newHeight)
memset(newTexture->GetPixels(), 0, m_textureHeight * newTexture->GetPitch());
if (m_texture)
{
m_updateY1 = 0;
m_updateY2 = m_texture->GetHeight();

unsigned char* src = (unsigned char*) m_texture->GetPixels();
unsigned char* dst = (unsigned char*) newTexture->GetPixels();
for (unsigned int y = 0; y < m_texture->GetHeight(); y++)
Expand All @@ -227,6 +253,8 @@ CBaseTexture* CGUIFontTTFGL::ReallocTexture(unsigned int& newHeight)
delete m_texture;
}

m_textureStatus = TEXTURE_REALLOCATED;

return newTexture;
}

Expand All @@ -243,18 +271,35 @@ bool CGUIFontTTFGL::CopyCharToTexture(FT_BitmapGlyph bitGlyph, unsigned int x1,
source += bitmap.width;
target += m_texture->GetPitch();
}
// THE SOURCE VALUES ARE THE SAME IN BOTH SITUATIONS.

// Since we have a new texture, we need to delete the old one
// the Begin(); End(); stuff is handled by whoever called us
if (m_bTextureLoaded)

switch (m_textureStatus)
{
g_graphicsContext.BeginPaint(); //FIXME
DeleteHardwareTexture();
g_graphicsContext.EndPaint();
m_bTextureLoaded = false;
}
case TEXTURE_UPDATED:
{
m_updateY1 = std:min(m_updateY1, y1);
m_updateY2 = std:max(m_updateY2, y2);
}
break;

case TEXTURE_READY:
{
m_updateY1 = y1;
m_updateY2 = y2;
m_textureStatus = TEXTURE_UPDATED;
}
break;

case TEXTURE_REALLOCATED:
{
m_updateY2 = std::max(m_updateY2, y2);
}
break;

case TEXTURE_VOID:
default:
break;
}

return TRUE;
}

Expand All @@ -267,6 +312,9 @@ void CGUIFontTTFGL::DeleteHardwareTexture()
g_TextureManager.ReleaseHwTexture(m_nTexture);
m_bTextureLoaded = false;
}

m_textureStatus = TEXTURE_VOID;
m_updateY1 = m_updateY2 = 0;
}

#endif
15 changes: 14 additions & 1 deletion xbmc/guilib/GUIFontTTFGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,20 @@ class CGUIFontTTFGL : public CGUIFontTTFBase
virtual CBaseTexture* ReallocTexture(unsigned int& newHeight);
virtual bool CopyCharToTexture(FT_BitmapGlyph bitGlyph, unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2);
virtual void DeleteHardwareTexture();


private:
unsigned int m_updateY1;
unsigned int m_updateY2;

enum TextureStatus
{
TEXTURE_VOID = 0,
TEXTURE_READY,
TEXTURE_REALLOCATED,
TEXTURE_UPDATED,
};

TextureStatus m_textureStatus;
};

#endif

0 comments on commit fc212a4

Please sign in to comment.