[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46991] branches/soc-2012-swiss_cheese/ source/blender/blenfont: Modified blenfont to use gpuImmediateLock/ gpuImmediateUnlock
Jason Wilkins
Jason.A.Wilkins at gmail.com
Fri May 25 03:28:43 CEST 2012
Revision: 46991
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46991
Author: jwilkins
Date: 2012-05-25 01:28:42 +0000 (Fri, 25 May 2012)
Log Message:
-----------
Modified blenfont to use gpuImmediateLock/gpuImmediateUnlock
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
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-25 01:26:20 UTC (rev 46990)
+++ branches/soc-2012-swiss_cheese/source/blender/blenfont/BLF_api.h 2012-05-25 01:28:42 UTC (rev 46991)
@@ -76,6 +76,11 @@
void BLF_draw(int fontid, const char *str, size_t len);
void BLF_draw_ascii(int fontid, const char *str, size_t len);
+/* Draw large blocks of text more efficiently by
+ explicitely reserving OpenGL for that purpose*/
+void BLF_draw_lock();
+void BLF_draw_unlock();
+
/* This function return the bounding box of the string
* and are not multiplied by the aspect.
*/
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-25 01:26:20 UTC (rev 46990)
+++ branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf.c 2012-05-25 01:28:42 UTC (rev 46991)
@@ -481,6 +481,32 @@
}
}
+void BLF_draw_lock(void)
+{
+ if (!gpuImmediateIsLocked()) {
+ GLint texCoordSizes[1] = { 2 };
+ GLenum texUnitMap[1];
+
+ glGetIntegerv(GL_ACTIVE_TEXTURE, texUnitMap);
+
+ gpuImmediateElementSizes(2, 0, 4); //-V112
+ gpuImmediateTextureUnitCount(1);
+ gpuImmediateTexCoordSizes(texCoordSizes);
+ gpuImmediateTextureUnitMap(texUnitMap);
+ gpuImmediateFloatAttribCount(0);
+ gpuImmediateUbyteAttribCount(0);
+
+ gpuImmediateLock();
+ }
+}
+
+void BLF_draw_unlock()
+{
+ if (gpuImmediateIsLocked()) {
+ gpuImmediateUnlock();
+ }
+}
+
static void blf_draw__start(FontBLF *font, GLint *mode, GLint *param)
{
/*
@@ -524,26 +550,14 @@
if (*param != GL_MODULATE)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- { // XXX: setup immediate, common setups could be refactored into utilities
- GLint texCoordSizes[1] = { 2 };
- GLenum texUnitMap[1];
-
- glGetIntegerv(GL_ACTIVE_TEXTURE, texUnitMap);
-
- gpuImmediateElementSizes(2, 0, 4);
- gpuImmediateTextureUnitCount(1);
- gpuImmediateTexCoordSizes(texCoordSizes);
- gpuImmediateTextureUnitMap(texUnitMap);
- gpuImmediateFloatAttribCount(0);
- gpuImmediateUbyteAttribCount(0);
- }
-
+ BLF_draw_lock();
gpuBegin(GL_QUADS);
}
static void blf_draw__end(GLint mode, GLint param)
{
gpuEnd(GL_QUADS);
+ BLF_draw_unlock();
/* and restore the original value. */
if (param != GL_MODULATE)
@@ -564,25 +578,29 @@
void BLF_draw(int fontid, const char *str, size_t len)
{
- FontBLF *font = BLF_get(fontid);
- GLint mode, param;
+ if (len > 0) {
+ FontBLF *font = BLF_get(fontid);
+ GLint mode, param;
- if (font && font->glyph_cache) {
- blf_draw__start(font, &mode, ¶m);
- blf_font_draw(font, str, len);
- blf_draw__end(mode, param);
+ if (font && font->glyph_cache) {
+ blf_draw__start(font, &mode, ¶m);
+ blf_font_draw(font, str, len);
+ blf_draw__end(mode, param);
+ }
}
}
void BLF_draw_ascii(int fontid, const char *str, size_t len)
{
- FontBLF *font = BLF_get(fontid);
- GLint mode, param;
+ if (len > 0) {
+ FontBLF *font = BLF_get(fontid);
+ GLint mode, param;
- if (font && font->glyph_cache) {
- blf_draw__start(font, &mode, ¶m);
- blf_font_draw_ascii(font, str, len);
- blf_draw__end(mode, param);
+ if (font && font->glyph_cache) {
+ blf_draw__start(font, &mode, ¶m);
+ blf_font_draw_ascii(font, str, len);
+ blf_draw__end(mode, param);
+ }
}
}
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-25 01:26:20 UTC (rev 46990)
+++ branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_font.c 2012-05-25 01:28:42 UTC (rev 46991)
@@ -157,7 +157,7 @@
} \
} \
-void blf_font_draw(FontBLF *font, const char *str, unsigned int len)
+void blf_font_draw(FontBLF *font, const char *str, size_t len)
{
unsigned int c;
GlyphBLF *g, *g_prev = NULL;
@@ -189,7 +189,7 @@
}
/* faster version of blf_font_draw, ascii only for view dimensions */
-void blf_font_draw_ascii(FontBLF *font, const char *str, unsigned int len)
+void blf_font_draw_ascii(FontBLF *font, const char *str, size_t len)
{
unsigned char c;
GlyphBLF *g, *g_prev = NULL;
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-25 01:26:20 UTC (rev 46990)
+++ branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_glyph.c 2012-05-25 01:28:42 UTC (rev 46991)
@@ -433,7 +433,7 @@
glBindTexture(GL_TEXTURE_2D, g->tex);
glTexSubImage2D(GL_TEXTURE_2D, 0, g->xoff, g->yoff, g->width, g->height, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 4); /* restore default value */
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 4); /* restore default value */ //-V112
g->uv[0][0] = ((float)g->xoff) / ((float)gc->p2_width);
g->uv[0][1] = ((float)g->yoff) / ((float)gc->p2_height);
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-25 01:26:20 UTC (rev 46990)
+++ branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_internal.h 2012-05-25 01:28:42 UTC (rev 46991)
@@ -51,8 +51,8 @@
void blf_font_attach_from_mem(struct FontBLF *font, const unsigned char *mem, int mem_size);
void blf_font_size(struct FontBLF *font, int size, int dpi);
-void blf_font_draw(struct FontBLF *font, const char *str, unsigned int len);
-void blf_font_draw_ascii(struct FontBLF *font, const char *str, unsigned int len);
+void blf_font_draw(struct FontBLF *font, const char *str, size_t len);
+void blf_font_draw_ascii(struct FontBLF *font, const char *str, size_t len);
void blf_font_buffer(struct FontBLF *font, const char *str);
void blf_font_boundbox(struct FontBLF *font, const char *str, struct rctf *box);
void blf_font_width_and_height(struct FontBLF *font, const char *str, float *width, float *height);
More information about the Bf-blender-cvs
mailing list