include/Spectre/Graphics/Font.h: move texture variable into it's own struct.
When implementing rendering of glyphs with different properties: size, stroke width, bold etc. We will need to store them in different textures.
This commit is contained in:
parent
1e5d448fa1
commit
c74dda1200
2 changed files with 32 additions and 27 deletions
|
|
@ -29,8 +29,8 @@ bool Font::loadFromFile(const std::string& filename, unsigned int size)
|
|||
}
|
||||
|
||||
m_size = size;
|
||||
m_shelf = 0;
|
||||
m_texpos = vec2u(0, 0);
|
||||
m_cacheTextureA.shelf = 0;
|
||||
m_cacheTextureA.texpos = vec2u(0, 0);
|
||||
|
||||
createTexture();
|
||||
|
||||
|
|
@ -66,10 +66,10 @@ void Font::loadChar(unsigned char code) const
|
|||
|
||||
Vector2u pos = findTextureRegion(img);
|
||||
|
||||
m_texture.enable();
|
||||
m_texture.update(pos, img);
|
||||
m_cacheTextureA.texture.enable();
|
||||
m_cacheTextureA.texture.update(pos, img);
|
||||
|
||||
glyph.texture = &m_texture;
|
||||
glyph.texture = &m_cacheTextureA.texture;
|
||||
glyph.texture_origin = vec2u(pos.x, pos.y);
|
||||
} else {
|
||||
glyph.texture = NULL;
|
||||
|
|
@ -80,48 +80,49 @@ void Font::loadChar(unsigned char code) const
|
|||
|
||||
void Font::createTexture()
|
||||
{
|
||||
m_texture.create(128, 32, PixelFormat::PF_Alpha);
|
||||
m_texture.enable();
|
||||
m_texture.setSmooth(true);
|
||||
m_texture.disable();
|
||||
m_cacheTextureA.texture.create(128, 32, PixelFormat::PF_Alpha);
|
||||
m_cacheTextureA.texture.enable();
|
||||
m_cacheTextureA.texture.setSmooth(true);
|
||||
m_cacheTextureA.texture.disable();
|
||||
}
|
||||
|
||||
void Font::resizeTexture() const
|
||||
{
|
||||
unsigned int nextSize = math::nextPowerOfTwo(m_texture.getSize().y + 1);
|
||||
Texture& tex = m_cacheTextureA.texture;
|
||||
unsigned int nextSize = math::nextPowerOfTwo(tex.getSize().y + 1);
|
||||
|
||||
Image tmpImg = m_texture.copyToImage();
|
||||
Image tmpImg = tex.copyToImage();
|
||||
|
||||
// recreate texture.
|
||||
m_texture.create(m_texture.getSize().x, nextSize, tmpImg.getFormat());
|
||||
m_texture.update(vec2u(0, 0), tmpImg);
|
||||
tex.create(tex.getSize().x, nextSize, tmpImg.getFormat());
|
||||
tex.update(vec2u(0, 0), tmpImg);
|
||||
}
|
||||
|
||||
Vector2u Font::findTextureRegion(const Image& img) const
|
||||
{
|
||||
Vector2u pos;
|
||||
|
||||
if (m_texpos.x + img.getWidth() + 1 > m_texture.getSize().x) {
|
||||
m_texpos.y += m_shelf;
|
||||
m_texpos.x = 0;
|
||||
m_shelf = 0;
|
||||
if (m_cacheTextureA.texpos.x + img.getWidth() + 1 > m_cacheTextureA.texture.getSize().x) {
|
||||
m_cacheTextureA.texpos.y += m_cacheTextureA.shelf;
|
||||
m_cacheTextureA.texpos.x = 0;
|
||||
m_cacheTextureA.shelf = 0;
|
||||
}
|
||||
|
||||
if (img.getHeight() + 1 > m_shelf) {
|
||||
m_shelf = img.getHeight() + 1;
|
||||
if (m_texpos.y + m_shelf > m_texture.getSize().y) {
|
||||
if (img.getHeight() + 1 > m_cacheTextureA.shelf) {
|
||||
m_cacheTextureA.shelf = img.getHeight() + 1;
|
||||
if (m_cacheTextureA.texpos.y + m_cacheTextureA.shelf > m_cacheTextureA.texture.getSize().y) {
|
||||
resizeTexture();
|
||||
}
|
||||
}
|
||||
|
||||
pos = m_texpos;
|
||||
pos = m_cacheTextureA.texpos;
|
||||
|
||||
m_texpos.x += img.getWidth() + 1;
|
||||
m_cacheTextureA.texpos.x += img.getWidth() + 1;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
const Texture* Font::getTexture() const
|
||||
{
|
||||
return &m_texture;
|
||||
return &m_cacheTextureA.texture;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue