[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46812] branches/soc-2012-swiss_cheese/ source/blender/blenfont/intern/blf_glyph.c: minor optimization of font rendering
Jason Wilkins
Jason.A.Wilkins at gmail.com
Sun May 20 18:53:34 CEST 2012
Revision: 46812
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46812
Author: jwilkins
Date: 2012-05-20 16:53:34 +0000 (Sun, 20 May 2012)
Log Message:
-----------
minor optimization of font rendering
Made some large local arrays static and used array instead of pointers to help compiler with aliasing issues.
Made glBegin/glEnd only called once.
I plan to replace the glBegin/glEnd paradigm with a set of inline functions for filling in VBO, so this isn't just shuffling around deprecated functionality.
Modified Paths:
--------------
branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_glyph.c
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-20 16:47:11 UTC (rev 46811)
+++ branches/soc-2012-swiss_cheese/source/blender/blenfont/intern/blf_glyph.c 2012-05-20 16:53:34 UTC (rev 46812)
@@ -297,7 +297,6 @@
static void blf_texture_draw(float uv[2][2], float dx, float y1, float dx1, float y2)
{
- glBegin(GL_QUADS);
glTexCoord2f(uv[0][0], uv[0][1]);
glVertex2f(dx, y1);
@@ -309,42 +308,46 @@
glTexCoord2f(uv[1][0], uv[0][1]);
glVertex2f(dx1, y1);
- glEnd();
}
static void blf_texture5_draw(const float shadow_col[4], float uv[2][2], float x1, float y1, float x2, float y2)
{
- float soft[25] = {1 / 60.0f, 1 / 60.0f, 2 / 60.0f, 1 / 60.0f, 1 / 60.0f,
- 1 / 60.0f, 3 / 60.0f, 5 / 60.0f, 3 / 60.0f, 1 / 60.0f,
- 2 / 60.0f, 5 / 60.0f, 8 / 60.0f, 5 / 60.0f, 2 / 60.0f,
- 1 / 60.0f, 3 / 60.0f, 5 / 60.0f, 3 / 60.0f, 1 / 60.0f,
- 1 / 60.0f, 1 / 60.0f, 2 / 60.0f, 1 / 60.0f, 1 / 60.0f};
-
- float color[4], *fp = soft;
+ static const float soft[25] =
+ {1 / 60.0f, 1 / 60.0f, 2 / 60.0f, 1 / 60.0f, 1 / 60.0f,
+ 1 / 60.0f, 3 / 60.0f, 5 / 60.0f, 3 / 60.0f, 1 / 60.0f,
+ 2 / 60.0f, 5 / 60.0f, 8 / 60.0f, 5 / 60.0f, 2 / 60.0f,
+ 1 / 60.0f, 3 / 60.0f, 5 / 60.0f, 3 / 60.0f, 1 / 60.0f,
+ 1 / 60.0f, 1 / 60.0f, 2 / 60.0f, 1 / 60.0f, 1 / 60.0f};
+
+ int i = 0;
+ float color[4];
int dx, dy;
color[0] = shadow_col[0];
color[1] = shadow_col[1];
color[2] = shadow_col[2];
-
+
for (dx = -2; dx < 3; dx++) {
- for (dy = -2; dy < 3; dy++, fp++) {
- color[3] = *(fp) * shadow_col[3];
+ for (dy = -2; dy < 3; dy++) {
+ color[3] = soft[i++] * shadow_col[3];
glColor4fv(color);
+
blf_texture_draw(uv, x1 + dx, y1 + dy, x2 + dx, y2 + dy);
}
}
-
+
glColor4fv(color);
}
static void blf_texture3_draw(const float shadow_col[4], float uv[2][2], float x1, float y1, float x2, float y2)
{
- float soft[9] = {1 / 16.0f, 2 / 16.0f, 1 / 16.0f,
- 2 / 16.0f, 4 / 16.0f, 2 / 16.0f,
- 1 / 16.0f, 2 / 16.0f, 1 / 16.0f};
+ static const float soft[9] =
+ {1 / 16.0f, 2 / 16.0f, 1 / 16.0f,
+ 2 / 16.0f, 4 / 16.0f, 2 / 16.0f,
+ 1 / 16.0f, 2 / 16.0f, 1 / 16.0f};
- float color[4], *fp = soft;
+ int i = 0;
+ float color[4];
int dx, dy;
color[0] = shadow_col[0];
@@ -352,8 +355,8 @@
color[2] = shadow_col[2];
for (dx = -1; dx < 2; dx++) {
- for (dy = -1; dy < 2; dy++, fp++) {
- color[3] = *(fp) * shadow_col[3];
+ for (dy = -1; dy < 2; dy++) {
+ color[3] = soft[i++] * shadow_col[3];
glColor4fv(color);
blf_texture_draw(uv, x1 + dx, y1 + dy, x2 + dx, y2 + dy);
}
@@ -448,6 +451,8 @@
glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state = g->tex));
}
+ glBegin(GL_QUADS);
+
if (font->flags & BLF_SHADOW) {
switch (font->shadow) {
@@ -486,5 +491,7 @@
break;
}
+ glEnd();
+
return 1;
}
More information about the Bf-blender-cvs
mailing list