diff options
author | Enne Walker <enne.walker@gmail.com> | 2010-05-09 20:59:50 -0400 |
---|---|---|
committer | Enne Walker <enne.walker@gmail.com> | 2010-05-14 18:18:52 -0400 |
commit | b65c556801c177b541d55697a97ff0f58ae4c781 (patch) | |
tree | 821d3eb39e35c4541c0353f67cdaa31a70ab2384 /crawl-ref/source/fontwrapper-ft.cc | |
parent | 63fe4a8f506ffe4462193235182582d66f50ef37 (diff) | |
download | crawl-ref-b65c556801c177b541d55697a97ff0f58ae4c781.tar.gz crawl-ref-b65c556801c177b541d55697a97ff0f58ae4c781.zip |
Reuse the same buffer when drawing fonts.
Don't alloc/delete every time a string is drawn.
Diffstat (limited to 'crawl-ref/source/fontwrapper-ft.cc')
-rw-r--r-- | crawl-ref/source/fontwrapper-ft.cc | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/crawl-ref/source/fontwrapper-ft.cc b/crawl-ref/source/fontwrapper-ft.cc index 63f39cdb29..9be7186315 100644 --- a/crawl-ref/source/fontwrapper-ft.cc +++ b/crawl-ref/source/fontwrapper-ft.cc @@ -24,11 +24,13 @@ FTFontWrapper::FTFontWrapper() : m_max_advance(0, 0), m_min_offset(0) { + m_buf = GLShapeBuffer::create(true, true); } FTFontWrapper::~FTFontWrapper() { delete[] m_glyphs; + delete m_buf; } bool FTFontWrapper::load_font(const char *font_name, unsigned int font_size, @@ -252,11 +254,8 @@ void FTFontWrapper::render_textblock(unsigned int x_pos, unsigned int y_pos, coord_def adv(std::max(-m_min_offset, 0), 0); unsigned int i = 0; - GLShapeBuffer *buf = GLShapeBuffer::create(true, true); - // TODO enne - make this better - // This is bad for the CRT. Maybe we should just reserve some fixed limit? - // Maybe we should just cache this in FTFontWrapper? - // TODO ixtli - facilitate the above TODO buy using the buffer better + ASSERT(m_buf); + m_buf->clear(); float texcoord_dy = (float)m_max_advance.y / (float)m_tex.height(); @@ -276,7 +275,7 @@ void FTFontWrapper::render_textblock(unsigned int x_pos, unsigned int y_pos, VColour col(term_colours[col_bg].r, term_colours[col_bg].g, term_colours[col_bg].b); rect.set_col(&col, &col, &col, &col); - buf->push(rect); + m_buf->push(rect); } adv.x += m_glyphs[c].offset; @@ -297,7 +296,7 @@ void FTFontWrapper::render_textblock(unsigned int x_pos, unsigned int y_pos, rect.set_col(&col, &col, &col, &col); rect.set_tex(tex_x, tex_y, tex_x2, tex_y2); - buf->push(rect); + m_buf->push(rect); } i++; @@ -308,7 +307,7 @@ void FTFontWrapper::render_textblock(unsigned int x_pos, unsigned int y_pos, adv.y += m_max_advance.y; } - if (!buf->size()) + if (!m_buf->size()) return; GLState state; @@ -330,7 +329,7 @@ void FTFontWrapper::render_textblock(unsigned int x_pos, unsigned int y_pos, trans.x++; trans.y++; glmanager->set_transform(&trans); - buf->draw(); + m_buf->draw(); trans.x--; trans.y--; @@ -343,11 +342,9 @@ void FTFontWrapper::render_textblock(unsigned int x_pos, unsigned int y_pos, state.array_colour = true; glmanager->set(state); glmanager->set_transform(&trans); - buf->draw(); + m_buf->draw(); state.array_colour = false; glmanager->set(state); - - delete buf; } struct box_vert |