diff options
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_draw.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 153 |
1 files changed, 101 insertions, 52 deletions
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 67c2a4f1c56..30880db0c90 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -571,93 +571,74 @@ static void drawcursor(Scene *scene, ARegion *ar, View3D *v3d) } } -/* Draw a live substitute of the view icon, which is always shown */ +/* Draw a live substitute of the view icon, which is always shown + * colors copied from transform_manipulator.c, we should keep these matching. */ static void draw_view_axis(RegionView3D *rv3d) { const float k = U.rvisize; /* axis size */ const float toll = 0.5; /* used to see when view is quasi-orthogonal */ const float start = k + 1.0; /* axis center in screen coordinates, x=y */ float ydisp = 0.0; /* vertical displacement to allow obj info text */ - - /* rvibright ranges approx. from original axis icon color to gizmo color */ - float bright = U.rvibright / 15.0f; - - unsigned char col[3]; - unsigned char gridcol[3]; - float colf[3]; - - float vec[4]; + + float vec[3]; float dx, dy; - float h, s, v; /* thickness of lines is proportional to k */ - /* (log(k)-1) gives a more suitable thickness, but fps decreased by about 3 fps */ - glLineWidth(k / 10); - //glLineWidth(log(k)-1); // a bit slow - - UI_GetThemeColor3ubv(TH_GRID, (char *)gridcol); - + glLineWidth(2); + /* X */ - vec[0] = vec[3] = 1; + vec[0] = 1; vec[1] = vec[2] = 0; mul_qt_v3(rv3d->viewquat, vec); - - UI_make_axis_color((char *)gridcol, (char *)col, 'x'); - rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v); - s = s<0.5 ? s+0.5 : 1.0; - v = 0.3; - v = (v<1.0-(bright) ? v+bright : 1.0); - hsv_to_rgb(h, s, v, colf, colf+1, colf+2); - glColor3fv(colf); - dx = vec[0] * k; dy = vec[1] * k; - fdrawline(start, start + ydisp, start + dx, start + dy + ydisp); + + glColor3ub(220, 0, 0); + glBegin(GL_LINES); + glVertex2f(start, start + ydisp); + glVertex2f(start + dx, start + dy + ydisp); + glEnd(); + if (fabs(dx) > toll || fabs(dy) > toll) { BLF_draw_default(start + dx + 2, start + dy + ydisp + 2, 0.0f, "x"); } /* Y */ - vec[1] = vec[3] = 1; + vec[1] = 1; vec[0] = vec[2] = 0; mul_qt_v3(rv3d->viewquat, vec); - - UI_make_axis_color((char *)gridcol, (char *)col, 'y'); - rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v); - s = s<0.5 ? s+0.5 : 1.0; - v = 0.3; - v = (v<1.0-(bright) ? v+bright : 1.0); - hsv_to_rgb(h, s, v, colf, colf+1, colf+2); - glColor3fv(colf); - dx = vec[0] * k; dy = vec[1] * k; - fdrawline(start, start + ydisp, start + dx, start + dy + ydisp); + + glColor3ub(0, 220, 0); + glBegin(GL_LINES); + glVertex2f(start, start + ydisp); + glVertex2f(start + dx, start + dy + ydisp); + glEnd(); + if (fabs(dx) > toll || fabs(dy) > toll) { BLF_draw_default(start + dx + 2, start + dy + ydisp + 2, 0.0f, "y"); } /* Z */ - vec[2] = vec[3] = 1; + vec[2] = 1; vec[1] = vec[0] = 0; mul_qt_v3(rv3d->viewquat, vec); - - UI_make_axis_color((char *)gridcol, (char *)col, 'z'); - rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v); - s = s<0.5 ? s+0.5 : 1.0; - v = 0.5; - v = (v<1.0-(bright) ? v+bright : 1.0); - hsv_to_rgb(h, s, v, colf, colf+1, colf+2); - glColor3fv(colf); - dx = vec[0] * k; dy = vec[1] * k; - fdrawline(start, start + ydisp, start + dx, start + dy + ydisp); + + glColor3ub(30, 30, 220); + glBegin(GL_LINES); + glVertex2f(start, start + ydisp); + glVertex2f(start + dx, start + dy + ydisp); + glEnd(); + if (fabs(dx) > toll || fabs(dy) > toll) { BLF_draw_default(start + dx + 2, start + dy + ydisp + 2, 0.0f, "z"); } - + /* restore line-width */ + glLineWidth(1.0); } @@ -1478,7 +1459,7 @@ static void draw_dupli_objects_color(Scene *scene, ARegion *ar, View3D *v3d, Bas { RegionView3D *rv3d= ar->regiondata; ListBase *lb; - DupliObject *dob_prev= NULL, *dob, *dob_next; + DupliObject *dob_prev= NULL, *dob, *dob_next= NULL; Base tbase; BoundBox bb, *bb_tmp; /* use a copy because draw_object, calls clear_mesh_caches */ GLuint displist=0; @@ -1588,7 +1569,51 @@ static void draw_dupli_objects(Scene *scene, ARegion *ar, View3D *v3d, Base *bas draw_dupli_objects_color(scene, ar, v3d, base, color); } +void view3d_update_depths_rect(ARegion *ar, ViewDepths *d, rcti *rect) +{ + int x, y, w, h; + /* clamp rect by area */ + + /* Constrain rect to depth bounds */ + if (rect->xmin < 0) rect->xmin = 0; + if (rect->ymin < 0) rect->ymin = 0; + if (rect->xmax >= ar->winx) rect->xmax = ar->winx-1; + if (rect->ymax >= ar->winy) rect->ymax = ar->winy-1; + + /* assign values to compare with the ViewDepths */ + x= ar->winrct.xmin + rect->xmin; + y= ar->winrct.ymin + rect->ymin; + + w= rect->xmax - rect->xmin; + h= rect->ymax - rect->ymin; + + if( d->w != w || + d->h != h || + d->x != x || + d->y != y || + d->depths==NULL + ) { + d->x= x; + d->y= y; + d->w= w; + d->h= h; + + if(d->depths) + MEM_freeN(d->depths); + d->depths= MEM_mallocN(sizeof(float)*d->w*d->h,"View depths Subset"); + + d->damaged= 1; + } + + if(d->damaged) { + glReadPixels(ar->winrct.xmin+d->x,ar->winrct.ymin+d->y, d->w,d->h, GL_DEPTH_COMPONENT,GL_FLOAT, d->depths); + glGetDoublev(GL_DEPTH_RANGE,d->depth_range); + d->damaged= 0; + } +} + +/* note, with nouveau drivers the glReadPixels() is very slow. [#24339] */ void view3d_update_depths(ARegion *ar) { RegionView3D *rv3d= ar->regiondata; @@ -1619,6 +1644,30 @@ void view3d_update_depths(ARegion *ar) } } +/* utility function to find the closest Z value, use for autodepth */ +float view3d_depth_near(ViewDepths *d) +{ + /* convert to float for comparisons */ + const float near= (float)d->depth_range[0]; + const float far_real= (float)d->depth_range[1]; + float far= far_real; + + const float *depths= d->depths; + float depth= FLT_MAX; + int i= d->w * d->h; + + /* far is both the starting 'far' value + * and the closest value found. */ + while(i--) { + depth= *depths++; + if((depth < far) && (depth > near)) { + far= depth; + } + } + + return far == far_real ? FLT_MAX : far; +} + void draw_depth_gpencil(Scene *scene, ARegion *ar, View3D *v3d) { short zbuf= v3d->zbuf; |