Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntony Riakiotakis <kalast@gmail.com>2013-01-06 22:38:16 +0400
committerAntony Riakiotakis <kalast@gmail.com>2013-01-06 22:38:16 +0400
commitaf143b73781a22a6c54ab65bc36a1ee3d06ffe2f (patch)
treed02158b48ad5e0338352a9b154c5c42592022d17
parentbbd95fafefa88390a9bb3fef3664719cf8539d85 (diff)
Small draw optimization: Draw sky with glDrawElements. Calculate
positions and indices once and update only colours each frame.
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c55
1 files changed, 36 insertions, 19 deletions
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 5302f63ebcb..b4b35c6b3ac 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -3001,7 +3001,9 @@ static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const
#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 @@ static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const
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 @@ static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const
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,20 +3084,14 @@ static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const
}
}
- 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();