Revision: 40109
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40109
Author:   campbellbarton
Date:     2011-09-11 04:31:09 +0000 (Sun, 11 Sep 2011)
Log Message:
-----------
simple changes to grid drawing logic.

- make ortho grid drawing use vertex arrays
- make perspective view floor drawing cache result of UI_ThemeColorShade so its 
not called on every line.
- make perspective view floor only loop once on each axis when the grid floor 
isnt being drawn (was looking over all grid lines for no reason).
- add UI_GetColorPtrShade3ubv() to replace UI_GetColorPtrBlendShade3ubv() when 
no blending is needed.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/UI_resources.h
    trunk/blender/source/blender/editors/interface/resources.c
    trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c
    trunk/blender/source/blender/editors/space_view3d/view3d_draw.c

Modified: trunk/blender/source/blender/editors/include/UI_resources.h
===================================================================
--- trunk/blender/source/blender/editors/include/UI_resources.h 2011-09-11 
02:50:01 UTC (rev 40108)
+++ trunk/blender/source/blender/editors/include/UI_resources.h 2011-09-11 
04:31:09 UTC (rev 40109)
@@ -296,6 +296,9 @@
 // blends and shades between two color pointers
 void   UI_ColorPtrBlendShade3ubv(const unsigned char cp1[3], const unsigned 
char cp2[3], float fac, int offset);
 
+// shade a 3 byte color (same as UI_GetColorPtrBlendShade3ubv with 0.0 factor)
+void   UI_GetColorPtrShade3ubv(const unsigned char cp1[3], unsigned char 
col[3], int offset);
+
 // get a 3 byte color, blended and shaded between two other char color pointers
 void   UI_GetColorPtrBlendShade3ubv(const unsigned char cp1[3], const unsigned 
char cp2[3], unsigned char col[3], float fac, int offset);
 

Modified: trunk/blender/source/blender/editors/interface/resources.c
===================================================================
--- trunk/blender/source/blender/editors/interface/resources.c  2011-09-11 
02:50:01 UTC (rev 40108)
+++ trunk/blender/source/blender/editors/interface/resources.c  2011-09-11 
04:31:09 UTC (rev 40109)
@@ -1039,6 +1039,23 @@
        glColor3ub(r, g, b);
 }
 
+void UI_GetColorPtrShade3ubv(const unsigned char cp[3], unsigned char col[3], 
int offset)
+{
+       int r, g, b;
+
+       r= offset+(int)cp[0];
+       g= offset+(int)cp[1];
+       b= offset+(int)cp[2];
+
+       CLAMP(r, 0, 255);
+       CLAMP(g, 0, 255);
+       CLAMP(b, 0, 255);
+
+       col[0] = r;
+       col[1] = g;
+       col[2] = b;
+}
+
 // get a 3 byte color, blended and shaded between two other char color pointers
 void UI_GetColorPtrBlendShade3ubv(const unsigned char cp1[3], const unsigned 
char cp2[3], unsigned char col[3], float fac, int offset)
 {

Modified: trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c       
2011-09-11 02:50:01 UTC (rev 40108)
+++ trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c       
2011-09-11 04:31:09 UTC (rev 40109)
@@ -99,7 +99,7 @@
                UI_GetThemeColor3ubv(TH_SEQ_SCENE, col);
                
                if(seq->scene==curscene) {
-                       UI_GetColorPtrBlendShade3ubv(col, col, col, 1.0, 20);
+                       UI_GetColorPtrShade3ubv(col, col, 20);
                }
                break;
                
@@ -299,7 +299,7 @@
 
                        glRectf(x1_chan,  y1_chan, x2_chan,  y2_chan);
 
-                       UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, -30);
+                       UI_GetColorPtrShade3ubv(col, col, -30);
                        glColor4ubv(col);
                        fdrawbox(x1_chan,  y1_chan, x2_chan,  y2_chan);
 
@@ -473,7 +473,7 @@
                /* feint pinstripes, helps see exactly which is extended and 
which isn't,
                * especially when the extension is very small */ 
                if (seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, 
col, 0.0, 24);
-               else UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, -16);
+               else UI_GetColorPtrShade3ubv(col, col, -16);
                
                glColor3ubv((GLubyte *)col);
                
@@ -490,8 +490,8 @@
                
                /* feint pinstripes, helps see exactly which is extended and 
which isn't,
                * especially when the extension is very small */ 
-               if (seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, 
col, 0.0, 24);
-               else UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, -16);
+               if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, 24);
+               else UI_GetColorPtrShade3ubv(col, col, -16);
                
                glColor3ubv((GLubyte *)col);
                
@@ -584,8 +584,8 @@
        glBegin(GL_QUADS);
        
        if(seq->flag & SEQ_INVALID_EFFECT) { col[0]= 255; col[1]= 0; col[2]= 
255; }
-       else if(seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, col, 
0.0, -50);
-       else UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 0);
+       else if(seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, -50);
+       /* else UI_GetColorPtrShade3ubv(col, col, 0); */ /* DO NOTHING */
        
        glColor3ubv(col);
        
@@ -594,7 +594,7 @@
 
        if(seq->flag & SEQ_INVALID_EFFECT) { col[0]= 255; col[1]= 0; col[2]= 
255; }
        else if(seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, col, 
0.0, 5);
-       else UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, -5);
+       else UI_GetColorPtrShade3ubv(col, col, -5);
 
        glColor3ubv((GLubyte *)col);
        
@@ -610,8 +610,8 @@
        glVertex2f(x1,ymid2);
        glVertex2f(x2,ymid2);
        
-       if(seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 
-15);
-       else UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 25);
+       if(seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, -15);
+       else UI_GetColorPtrShade3ubv(col, col, 25);
        
        glColor3ubv((GLubyte *)col);
        
@@ -697,10 +697,10 @@
                        col[0]= 255; col[1]= col[2]= 40;
                }
                else
-                       UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 
120+outline_tint);
+                       UI_GetColorPtrShade3ubv(col, col, 120+outline_tint);
        }
        else
-               UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, outline_tint);
+               UI_GetColorPtrShade3ubv(col, col, outline_tint);
        
        glColor3ubv((GLubyte *)col);
        

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_draw.c     
2011-09-11 02:50:01 UTC (rev 40108)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_draw.c     
2011-09-11 04:31:09 UTC (rev 40109)
@@ -218,39 +218,40 @@
 
 static void drawgrid_draw(ARegion *ar, float wx, float wy, float x, float y, 
float dx)
 {      
-       float v1[2], v2[2];
+       float verts[2][2];
 
        x+= (wx); 
        y+= (wy);
 
-       v1[1]= 0.0f;
-       v2[1]= (float)ar->winy;
+       /* set fixed 'Y' */
+       verts[0][1]= 0.0f;
+       verts[1][1]= (float)ar->winy;
 
-       v1[0] = v2[0] = x-dx*floorf(x/dx);
-       
-       glBegin(GL_LINES);
-       
-       while(v1[0] < ar->winx) {
-               glVertex2fv(v1);
-               glVertex2fv(v2);
-               v1[0] = v2[0] = v1[0] + dx;
+       /* iter over 'X' */
+       verts[0][0] = verts[1][0] = x-dx*floorf(x/dx);
+       glEnableClientState(GL_VERTEX_ARRAY);
+       glVertexPointer(2, GL_FLOAT, 0, verts);
+
+       while(verts[0][0] < ar->winx) {
+               glDrawArrays(GL_LINES, 0, 2);
+               verts[0][0] = verts[1][0] = verts[0][0] + dx;
        }
 
-       v1[0]= 0.0f;
-       v2[0]= (float)ar->winx;
+       /* set fixed 'X' */
+       verts[0][0]= 0.0f;
+       verts[1][0]= (float)ar->winx;
 
-       v1[1]= v2[1]= y-dx*floorf(y/dx);
-
-       while(v1[1] < ar->winy) {
-               glVertex2fv(v1);
-               glVertex2fv(v2);
-               v1[1] = v2[1] = v1[1] + dx;
+       /* iter over 'Y' */
+       verts[0][1]= verts[1][1]= y-dx*floorf(y/dx);
+       while(verts[0][1] < ar->winy) {
+               glDrawArrays(GL_LINES, 0, 2);
+               verts[0][1] = verts[1][1] = verts[0][1] + dx;
        }
 
-       glEnd();
+       glDisableClientState(GL_VERTEX_ARRAY);
 }
 
-#define GRID_MIN_PX 6.0f
+#define GRID_MIN_PX 1.0f
 
 static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char 
**grid_unit)
 {
@@ -428,9 +429,11 @@
 static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit)
 {
        float vert[3], grid, grid_scale;
-       int a, gridlines, emphasise;
-       unsigned char col[3], col2[3];
-       short draw_line = 0;
+       int a, gridlines;
+       unsigned char col_grid[3], col_bg[3];
+       unsigned char col_grid_emphasise[3], col_grid_light[3]; /* cache */
+       short draw_line= FALSE;
+       const short show_floor= (v3d->gridflag & V3D_SHOW_FLOOR) != 0;
        
        vert[2]= 0.0;
        
@@ -454,45 +457,49 @@
        }
        
        if(v3d->zbuf && scene->obedit) glDepthMask(0);  // for zbuffer-select
-       
+
        gridlines= v3d->gridlines/2;
        grid= gridlines * grid_scale;
 
-       UI_GetThemeColor3ubv(TH_GRID, col);
-       UI_GetThemeColor3ubv(TH_BACK, col2);
-       
+       /* only draw center axis if there are no grid lines, saves loop for no 
reason */
+       if(show_floor == 0) {
+               gridlines= FALSE;
+       }
+
+       UI_GetThemeColor3ubv(TH_GRID, col_grid);
+       UI_GetThemeColor3ubv(TH_BACK, col_bg);
+
        /* emphasise division lines lighter instead of darker, if background is 
darker than grid */
-       if ( ((col[0]+col[1]+col[2])/3+10) > (col2[0]+col2[1]+col2[2])/3 )
-               emphasise = 20;
-       else
-               emphasise = -10;
-       
+       UI_GetColorPtrShade3ubv(col_grid, col_grid_light, 10);
+       UI_GetColorPtrShade3ubv(col_grid, col_grid_emphasise,
+                               (((col_grid[0]+col_grid[1]+col_grid[2])+30) > 
(col_bg[0]+col_bg[1]+col_bg[2])) ? 20 : -10);
+
        /* draw the Y axis and/or grid lines */
        for(a= -gridlines;a<=gridlines;a++) {
                if(a==0) {
                        /* check for the 'show Y axis' preference */
                        if (v3d->gridflag & V3D_SHOW_Y) { 
-                               UI_make_axis_color(col, col2, 'Y');
-                               glColor3ubv(col2);
-                               
-                               draw_line = 1;
-                       } else if (v3d->gridflag & V3D_SHOW_FLOOR) {
-                               UI_ThemeColorShade(TH_GRID, emphasise);
-                       } else {
-                               draw_line = 0;
+                               UI_make_axis_color(col_grid, col_bg, 'Y');
+                               glColor3ubv(col_bg);
+
+                               draw_line = TRUE;
                        }
-               } else {
+                       else if (show_floor) {
+                               glColor3ubv(col_grid_emphasise);
+                       }
+                       else {
+                               draw_line = FALSE;
+                       }
+               }
+               else {
                        /* check for the 'show grid floor' preference */
-                       if (v3d->gridflag & V3D_SHOW_FLOOR) {
-                               if( (a % 10)==0) {
-                                       UI_ThemeColorShade(TH_GRID, emphasise);
-                               }
-                               else UI_ThemeColorShade(TH_GRID, 10);
-                               
-                               draw_line = 1;
-                       } else {
-                               draw_line = 0;
+                       if (show_floor) {
+                               glColor3ubv((a % 10) ? col_grid_light : 
col_grid_emphasise);
+                               draw_line = TRUE;
                        }
+                       else {
+                               draw_line = FALSE;
+                       }
                }
                
                if (draw_line) {
@@ -511,27 +518,27 @@
                if(a==0) {
                        /* check for the 'show X axis' preference */
                        if (v3d->gridflag & V3D_SHOW_X) { 
-                               UI_make_axis_color(col, col2, 'X');
-                               glColor3ubv(col2);
-                               
-                               draw_line = 1;
-                       } else if (v3d->gridflag & V3D_SHOW_FLOOR) {
-                               UI_ThemeColorShade(TH_GRID, emphasise);
-                       } else {
-                               draw_line = 0;
+                               UI_make_axis_color(col_grid, col_bg, 'X');
+                               glColor3ubv(col_bg);
+
+                               draw_line = TRUE;
                        }
-               } else {
+                       else if (show_floor) {
+                               glColor3ubv(col_grid_emphasise);
+                       }
+                       else {
+                               draw_line = FALSE;
+                       }
+               }
+               else {
                        /* check for the 'show grid floor' preference */
-                       if (v3d->gridflag & V3D_SHOW_FLOOR) {
-                               if( (a % 10)==0) {
-                                       UI_ThemeColorShade(TH_GRID, emphasise);
-                               }
-                               else UI_ThemeColorShade(TH_GRID, 10);
-                               
-                               draw_line = 1;
-                       } else {
-                               draw_line = 0;
+                       if (show_floor) {
+                               glColor3ubv((a % 10) ? col_grid_light : 
col_grid_emphasise);
+                               draw_line = TRUE;
                        }
+                       else {
+                               draw_line = FALSE;
+                       }
                }
                
                if (draw_line) {
@@ -548,12 +555,12 @@
        /* draw the Z axis line */      
        /* check for the 'show Z axis' preference */
        if (v3d->gridflag & V3D_SHOW_Z) {
-               UI_make_axis_color(col, col2, 'Z');
-               glColor3ubv(col2);
+               UI_make_axis_color(col_grid, col_bg, 'Z');
+               glColor3ubv(col_bg);
                
                glBegin(GL_LINE_STRIP);
-               vert[0]= 0;
-               vert[1]= 0;

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to