[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47250] branches/soc-2012-swiss_cheese/ source/blender: BLF_draw_font calling gpuEnd too many times in some situations.
Jason Wilkins
Jason.A.Wilkins at gmail.com
Thu May 31 05:57:55 CEST 2012
Revision: 47250
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47250
Author: jwilkins
Date: 2012-05-31 03:57:52 +0000 (Thu, 31 May 2012)
Log Message:
-----------
BLF_draw_font calling gpuEnd too many times in some situations. BLF_draw_font does not always need a color array.
Modified Paths:
--------------
branches/soc-2012-swiss_cheese/source/blender/blenfont/BLF_api.h
branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf.c
branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_font.c
branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_glyph.c
branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_internal.h
branches/soc-2012-swiss_cheese/source/blender/editors/space_text/text_draw.c
Modified: branches/soc-2012-swiss_cheese/source/blender/blenfont/BLF_api.h
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/blenfont/BLF_api.h 2012-05-31 00:54:54 UTC (rev 47249)
+++ branches/soc-2012-swiss_cheese/source/blender/blenfont/BLF_api.h 2012-05-31 03:57:52 UTC (rev 47250)
@@ -78,7 +78,7 @@
/* Draw large blocks of text more efficiently by
explicitely reserving OpenGL for that purpose*/
-void BLF_draw_lock(void);
+void BLF_draw_lock(int fontid);
void BLF_draw_unlock(void);
/* This function return the bounding box of the string
Modified: branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf.c 2012-05-31 00:54:54 UTC (rev 47249)
+++ branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf.c 2012-05-31 03:57:52 UTC (rev 47250)
@@ -481,31 +481,43 @@
}
}
-void BLF_draw_lock(void)
+static void draw_lock(FontBLF *font)
{
if (gpuImmediateLockCount() == 0) {
GLint texCoordSizes[1] = { 2 };
- GLint texUnitMap[1];
+ GLint texUnitMap[1] = { GL_TEXTURE0 };
- glGetIntegerv(GL_ACTIVE_TEXTURE, texUnitMap);
+ if (font->shadow || font->blur) {
+ gpuImmediateElementSizes(2, 0, 4); //-V112
+ }
+ else {
+ gpuImmediateElementSizes(2, 0, 0);
+ }
- gpuImmediateElementSizes(2, 0, 4); //-V112
gpuImmediateTextureUnitCount(1);
gpuImmediateTexCoordSizes(texCoordSizes);
gpuImmediateTextureUnitMap(texUnitMap);
- gpuImmediateFloatAttribCount(0);
- gpuImmediateUbyteAttribCount(0);
/* one time GL setup */
+ glEnable(GL_TEXTURE_2D);
+
glEnable(GL_BLEND);
- glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
gpuImmediateLock();
}
+void BLF_draw_lock(int fontid)
+{
+ FontBLF *font = BLF_get(fontid);
+
+ if (font) {
+ draw_lock(font);
+ }
+}
+
void BLF_draw_unlock(void)
{
gpuImmediateUnlock();
@@ -555,13 +567,11 @@
if (*param != GL_MODULATE)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- BLF_draw_lock();
- /* gpuBegin not called here because texture still needs binding */
+ draw_lock(font);
}
static void blf_draw__end(GLint mode, GLint param)
{
- gpuEnd();
BLF_draw_unlock();
/* and restore the original value. */
Modified: branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_font.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_font.c 2012-05-31 00:54:54 UTC (rev 47249)
+++ branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_font.c 2012-05-31 03:57:52 UTC (rev 47250)
@@ -54,7 +54,9 @@
#include "blf_internal_types.h"
#include "blf_internal.h"
+#include "GPU_compatibility.h"
+
/* freetype2 handle ONLY for this file!. */
static FT_Library ft_lib;
@@ -165,6 +167,7 @@
int pen_x = 0, pen_y = 0;
size_t i = 0;
GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table;
+ int needs_end = FALSE;
BLF_KERNING_VARS(font, has_kerning, kern_mode);
@@ -181,11 +184,16 @@
BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
/* do not return this loop if clipped, we want every character tested */
- blf_glyph_render(font, g, (float)pen_x, (float)pen_y);
+ /* blf_glyph_render calls gpuBegin */
+ blf_glyph_render(font, g, (float)pen_x, (float)pen_y, &needs_end);
pen_x += g->advance;
g_prev = g;
}
+
+ if (needs_end) {
+ gpuEnd();
+ }
}
/* faster version of blf_font_draw, ascii only for view dimensions */
@@ -196,6 +204,7 @@
FT_Vector delta;
int pen_x = 0, pen_y = 0;
GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table;
+ int needs_end = FALSE;
BLF_KERNING_VARS(font, has_kerning, kern_mode);
@@ -208,11 +217,16 @@
BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
/* do not return this loop if clipped, we want every character tested */
- blf_glyph_render(font, g, (float)pen_x, (float)pen_y);
+ /* blf_glyph_render calls gpuBegin */
+ blf_glyph_render(font, g, (float)pen_x, (float)pen_y, &needs_end);
pen_x += g->advance;
g_prev = g;
}
+
+ if (needs_end) {
+ gpuEnd();
+ }
}
/* Sanity checks are done by BLF_draw_buffer() */
Modified: branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_glyph.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_glyph.c 2012-05-31 00:54:54 UTC (rev 47249)
+++ branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_glyph.c 2012-05-31 03:57:52 UTC (rev 47250)
@@ -362,7 +362,12 @@
}
}
-int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
+int blf_glyph_render(
+ FontBLF *font,
+ GlyphBLF *g,
+ float x,
+ float y,
+ int *needs_end)
{
float dx, dx1;
float y1, y2;
@@ -402,7 +407,8 @@
if (!need_begin) {
gpuEnd();
- need_begin = 1;
+ need_begin = TRUE;
+ *needs_end = FALSE;
}
if (font->max_tex_size == -1)
@@ -450,7 +456,7 @@
if (font->tex_bind_state != g->tex) {
if (!need_begin) {
gpuEnd();
- need_begin = 1;
+ need_begin = TRUE;
}
glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state = g->tex));
@@ -458,6 +464,7 @@
if (need_begin) {
gpuBegin(GL_QUADS);
+ *needs_end = TRUE;
}
if (font->flags & BLF_SHADOW) {
@@ -500,5 +507,5 @@
break;
}
- return 1;
+ return TRUE;
}
Modified: branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_internal.h
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_internal.h 2012-05-31 00:54:54 UTC (rev 47249)
+++ branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_internal.h 2012-05-31 03:57:52 UTC (rev 47250)
@@ -70,6 +70,6 @@
struct GlyphBLF *blf_glyph_add(struct FontBLF *font, unsigned int index, unsigned int c);
void blf_glyph_free(struct GlyphBLF *g);
-int blf_glyph_render(struct FontBLF *font, struct GlyphBLF *g, float x, float y);
+int blf_glyph_render(struct FontBLF *font, struct GlyphBLF *g, float x, float y, int *needs_end);
#endif /* __BLF_INTERNAL_H__ */
Modified: branches/soc-2012-swiss_cheese/source/blender/editors/space_text/text_draw.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/editors/space_text/text_draw.c 2012-05-31 00:54:54 UTC (rev 47249)
+++ branches/soc-2012-swiss_cheese/source/blender/editors/space_text/text_draw.c 2012-05-31 03:57:52 UTC (rev 47250)
@@ -1481,7 +1481,7 @@
glEnd();
UI_ThemeColor(TH_TEXT);
- BLF_draw_lock();
+ BLF_draw_lock(mono);
i = 0; br = DOC_WIDTH; lines = 0; // XXX -doc_scroll;
for (p = docs; *p; p++) {
@@ -1558,7 +1558,7 @@
UI_ThemeColor(TH_BACK);
glRecti(x, y, x + boxw, y - boxh);
- BLF_draw_lock();
+ BLF_draw_lock(mono);
/* Set the top 'item' of the visible list */
for (i = 0, item = first; i < *top && item->next; i++, item = item->next) ;
@@ -1920,7 +1920,7 @@
GPU_STRING_MARKER("draw_text_main:begin");
- BLF_draw_lock();
+ BLF_draw_lock(mono);
for (i = 0; y > 0 && i < st->viewlines && tmp; i++, tmp = tmp->next) {
if (st->showsyntax && !tmp->format)
@@ -2024,7 +2024,7 @@
st->left = 0;
}
else {
- BLF_draw_lock();
+ BLF_draw_lock(mono);
x = text_draw(st, text->sell->line, st->left, text->selc, 0, 0, 0, NULL);
BLF_draw_unlock();
More information about the Bf-blender-cvs
mailing list