[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53613] trunk/blender/source/blender/ editors/space_view3d/view3d_draw.c: Small draw optimization: Draw sky with glDrawElements.
Antony Riakiotakis
kalast at gmail.com
Sun Jan 6 19:38:16 CET 2013
Revision: 53613
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53613
Author: psy-fi
Date: 2013-01-06 18:38:16 +0000 (Sun, 06 Jan 2013)
Log Message:
-----------
Small draw optimization: Draw sky with glDrawElements. Calculate
positions and indices once and update only colours each frame.
Modified Paths:
--------------
trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
Modified: trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_draw.c 2013-01-06 18:28:39 UTC (rev 53612)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_draw.c 2013-01-06 18:38:16 UTC (rev 53613)
@@ -3001,7 +3001,9 @@
#define YTOT 16
GLubyte grid_col[XTOT][YTOT][4];
- float grid_pos[XTOT][YTOT][2];
+ static float grid_pos[XTOT][YTOT][2];
+ static GLushort indices[XTOT-1][XTOT-1][4];
+ static char buf_calculated = FALSE;
IMB_colormanagement_pixel_to_display_space_v3(col_hor, &scene->world->horr, &scene->view_settings,
&scene->display_settings);
@@ -3019,6 +3021,31 @@
glShadeModel(GL_SMOOTH);
+ /* calculate buffers the first time only */
+ if (!buf_calculated) {
+ for (x = 0; x < XTOT; x++) {
+ for (y = 0; y < YTOT; y++) {
+ const float xf = (float)x / (float)(XTOT - 1);
+ const float yf = (float)y / (float)(YTOT - 1);
+
+ /* -1..1 range */
+ grid_pos[x][y][0] = (xf - 0.5f) * 2.0f;
+ grid_pos[x][y][1] = (yf - 0.5f) * 2.0f;
+ }
+ }
+
+ for (x = 0; x < XTOT - 1; x++) {
+ for (y = 0; y < YTOT - 1; y++) {
+ indices[x][y][0] = x*XTOT + y;
+ indices[x][y][1] = x*XTOT + y + 1;
+ indices[x][y][2] = (x + 1)*XTOT + y + 1;
+ indices[x][y][3] = (x + 1)*XTOT + y;
+ }
+ }
+
+ buf_calculated = TRUE;
+ }
+
for (x = 0; x < XTOT; x++) {
for (y = 0; y < YTOT; y++) {
const float xf = (float)x / (float)(XTOT - 1);
@@ -3031,10 +3058,6 @@
float col_fac;
float col_fl[3];
- /* -1..1 range */
- grid_pos[x][y][0] = (xf - 0.5f) * 2.0f;
- grid_pos[x][y][1] = (yf - 0.5f) * 2.0f;
-
ED_view3d_win_to_vector(ar, mval, out);
if (scene->world->skytype & WO_SKYPAPER) {
@@ -3061,21 +3084,15 @@
}
}
- glBegin(GL_QUADS);
- for (x = 0; x < XTOT - 1; x++) {
- for (y = 0; y < YTOT - 1; y++) {
- glColor4ubv(grid_col[x][y]);
- glVertex2fv(grid_pos[x][y]);
- glColor4ubv(grid_col[x][y + 1]);
- glVertex2fv(grid_pos[x][y + 1]);
- glColor4ubv(grid_col[x + 1][y + 1]);
- glVertex2fv(grid_pos[x + 1][y + 1]);
- glColor4ubv(grid_col[x + 1][y]);
- glVertex2fv(grid_pos[x + 1][y]);
- }
- }
- glEnd();
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+ glVertexPointer(2, GL_FLOAT, 0, grid_pos);
+ glColorPointer(4, GL_UNSIGNED_BYTE, 0, grid_col);
+ glDrawElements(GL_QUADS, (XTOT - 1)*(YTOT - 1)*4, GL_UNSIGNED_SHORT, indices);
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
More information about the Bf-blender-cvs
mailing list