diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-12-09 13:59:29 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-12-09 14:20:08 +0400 |
commit | 90e7be47101fedea8ca1b35e0118cdfdda1291a1 (patch) | |
tree | 71857a24b397759cfc12872f688d24a37562141f /source | |
parent | c46463eb3f66022533f4741e1dc4fb3d47475bfd (diff) |
Fix T37727: z-offset problems with camera view
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/include/ED_view3d.h | 3 | ||||
-rw-r--r-- | source/blender/editors/screen/glutil.c | 4 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawarmature.c | 8 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawmesh.c | 10 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawobject.c | 28 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 19 |
6 files changed, 48 insertions, 24 deletions
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index ae8aeab7835..f155247f851 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -218,6 +218,9 @@ bool ED_view3d_clip_range_get(struct View3D *v3d, struct RegionView3D *rv3d, float *r_clipsta, float *r_clipend, const bool use_ortho_factor); bool ED_view3d_viewplane_get(struct View3D *v3d, struct RegionView3D *rv3d, int winxi, int winyi, struct rctf *r_viewplane, float *r_clipsta, float *r_clipend, float *r_pixsize); + +void ED_view3d_polygon_offset(const struct RegionView3D *rv3d, const float dist); + void ED_view3d_calc_camera_border(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, struct rctf *r_viewborder, const bool no_shift); diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index f02cb4aa1a4..57d97178be5 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -981,7 +981,9 @@ void bgl_get_mats(bglMats *mats) /* *************** glPolygonOffset hack ************* */ -/* dist is only for ortho now... */ +/** + * \note \a viewdist is only for ortho at the moment. + */ void bglPolygonOffset(float viewdist, float dist) { static float winmat[16], offset = 0.0; diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c index de6fafb2cd8..8aced487160 100644 --- a/source/blender/editors/space_view3d/drawarmature.c +++ b/source/blender/editors/space_view3d/drawarmature.c @@ -1878,7 +1878,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, } /* if solid && posemode, we draw again with polygonoffset */ else if ((dt > OB_WIRE) && (arm->flag & ARM_POSEMODE)) { - bglPolygonOffset(rv3d->dist, 1.0); + ED_view3d_polygon_offset(rv3d, 1.0); } else { /* and we use selection indices if not done yet */ @@ -1986,7 +1986,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, } /* restore things */ if (!ELEM(arm->drawtype, ARM_WIRE, ARM_LINE) && (dt > OB_WIRE) && (arm->flag & ARM_POSEMODE)) - bglPolygonOffset(rv3d->dist, 0.0); + ED_view3d_polygon_offset(rv3d, 0.0); } /* restore */ @@ -2154,7 +2154,7 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, const short dt) index = 0; } else if (dt > OB_WIRE) - bglPolygonOffset(rv3d->dist, 1.0f); + ED_view3d_polygon_offset(rv3d, 1.0); else if (arm->flag & ARM_EDITMODE) index = 0; /* do selection codes */ @@ -2221,7 +2221,7 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, const short dt) /* pass */ } else if (dt > OB_WIRE) { - bglPolygonOffset(rv3d->dist, 0.0f); + ED_view3d_polygon_offset(rv3d, 0.0); } /* finally names and axes */ diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index a08a6cc1478..52897aa023e 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -170,7 +170,7 @@ void draw_mesh_face_select(RegionView3D *rv3d, Mesh *me, DerivedMesh *dm) glEnable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); - bglPolygonOffset(rv3d->dist, 1.0); + ED_view3d_polygon_offset(rv3d, 1.0); /* Draw (Hidden) Edges */ setlinestyle(1); @@ -188,7 +188,7 @@ void draw_mesh_face_select(RegionView3D *rv3d, Mesh *me, DerivedMesh *dm) glDisable(GL_BLEND); } - bglPolygonOffset(rv3d->dist, 1.0); + ED_view3d_polygon_offset(rv3d, 1.0); /* Draw Stippled Outline for selected faces */ glColor3ub(255, 255, 255); @@ -196,7 +196,7 @@ void draw_mesh_face_select(RegionView3D *rv3d, Mesh *me, DerivedMesh *dm) dm->drawMappedEdges(dm, draw_mesh_face_select__setSelectOpts, &data); setlinestyle(0); - bglPolygonOffset(rv3d->dist, 0.0); /* resets correctly now, even after calling accumulated offsets */ + ED_view3d_polygon_offset(rv3d, 0.0); /* resets correctly now, even after calling accumulated offsets */ MEM_freeN(data.edge_flags); } @@ -1055,7 +1055,7 @@ void draw_mesh_paint_weight_edges(RegionView3D *rv3d, DerivedMesh *dm, const boo * rather than the shading, this is also forced in wire view */ if (use_depth) { - bglPolygonOffset(rv3d->dist, 1.0); + ED_view3d_polygon_offset(rv3d, 1.0); glDepthMask(0); /* disable write in zbuffer, selected edge wires show better */ } else { @@ -1070,7 +1070,7 @@ void draw_mesh_paint_weight_edges(RegionView3D *rv3d, DerivedMesh *dm, const boo dm->drawMappedEdges(dm, (DMSetDrawOptions)edgemask_cb, user_data); if (use_depth) { - bglPolygonOffset(rv3d->dist, 0.0); + ED_view3d_polygon_offset(rv3d, 0.0); glDepthMask(1); } else { diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index b4b8bd24703..225c58207e7 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -3123,7 +3123,7 @@ static void draw_em_fancy(Scene *scene, ARegion *ar, View3D *v3d, if (dt > OB_WIRE) { draw_mesh_paint_weight_faces(finalDM, true, draw_em_fancy__setFaceOpts, me->edit_btmesh); - bglPolygonOffset(rv3d->dist, 1.0); + ED_view3d_polygon_offset(rv3d, 1.0); glDepthMask(0); } else { @@ -3173,7 +3173,7 @@ static void draw_em_fancy(Scene *scene, ARegion *ar, View3D *v3d, * write to show selected edge wires better */ UI_ThemeColor(TH_WIRE_EDIT); - bglPolygonOffset(rv3d->dist, 1.0); + ED_view3d_polygon_offset(rv3d, 1.0); glDepthMask(0); } else { @@ -3319,12 +3319,12 @@ static void draw_em_fancy(Scene *scene, ARegion *ar, View3D *v3d, if (dt > OB_WIRE) { glDepthMask(1); - bglPolygonOffset(rv3d->dist, 0.0); + ED_view3d_polygon_offset(rv3d, 0.0); GPU_disable_material(); } #if 0 /* currently not needed */ else if (use_occlude_wire) { - bglPolygonOffset(rv3d->dist, 0.0); + ED_view3d_polygon_offset(rv3d, 0.0); } #endif } @@ -3565,7 +3565,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D * otherwise this wire is to overlay solid mode faces so do some depth buffer tricks. */ if (dt != OB_WIRE && (draw_wire == OBDRAW_WIRE_ON_DEPTH)) { - bglPolygonOffset(rv3d->dist, 1.0); + ED_view3d_polygon_offset(rv3d, 1.0); glDepthMask(0); /* disable write in zbuffer, selected edge wires show better */ } @@ -3573,7 +3573,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D if (dt != OB_WIRE && (draw_wire == OBDRAW_WIRE_ON_DEPTH)) { glDepthMask(1); - bglPolygonOffset(rv3d->dist, 0.0); + ED_view3d_polygon_offset(rv3d, 0.0); } } @@ -3583,10 +3583,10 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE)); if (!use_depth) glDisable(GL_DEPTH_TEST); - else bglPolygonOffset(rv3d->dist, 1.0); + else ED_view3d_polygon_offset(rv3d, 1.0); drawSelectedVertices(dm, ob->data); if (!use_depth) glEnable(GL_DEPTH_TEST); - else bglPolygonOffset(rv3d->dist, 0.0); + else ED_view3d_polygon_offset(rv3d, 0.0); glPointSize(1.0f); } @@ -5756,7 +5756,7 @@ static void draw_empty_cone(float size) static void draw_textcurs(RegionView3D *rv3d, float textcurs[4][2]) { cpack(0); - bglPolygonOffset(rv3d->dist, -1.0); + ED_view3d_polygon_offset(rv3d, -1.0); set_inverted_drawing(1); glBegin(GL_QUADS); glVertex2fv(textcurs[0]); @@ -5765,7 +5765,7 @@ static void draw_textcurs(RegionView3D *rv3d, float textcurs[4][2]) glVertex2fv(textcurs[3]); glEnd(); set_inverted_drawing(0); - bglPolygonOffset(rv3d->dist, 0.0); + ED_view3d_polygon_offset(rv3d, 0.0); } static void drawspiral(const float cent[3], float rad, float tmat[4][4], int start) @@ -6377,7 +6377,7 @@ static void draw_wire_extra(Scene *scene, RegionView3D *rv3d, Object *ob, unsign glColor3ubv(ob_wire_col); } - bglPolygonOffset(rv3d->dist, 1.0); + ED_view3d_polygon_offset(rv3d, 1.0); glDepthMask(0); /* disable write in zbuffer, selected edge wires show better */ if (ELEM3(ob->type, OB_FONT, OB_CURVE, OB_SURF)) { @@ -6403,7 +6403,7 @@ static void draw_wire_extra(Scene *scene, RegionView3D *rv3d, Object *ob, unsign } glDepthMask(1); - bglPolygonOffset(rv3d->dist, 0.0); + ED_view3d_polygon_offset(rv3d, 0.0); } } @@ -7556,7 +7556,7 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec else bm_solidoffs = 1; - bglPolygonOffset(rv3d->dist, 1.0); + ED_view3d_polygon_offset(rv3d, 1.0); /* we draw edges always, for loop (select) tools */ bbs_mesh_wire(em, dm, bm_solidoffs); @@ -7571,7 +7571,7 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec bm_vertoffs = bm_wireoffs; } - bglPolygonOffset(rv3d->dist, 0.0); + ED_view3d_polygon_offset(rv3d, 0.0); dm->release(dm); } diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 475f466c17b..d81ab0319e6 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -721,6 +721,25 @@ bool ED_view3d_viewplane_get(View3D *v3d, RegionView3D *rv3d, int winx, int winy return params.is_ortho; } +/** + * Use instead of: ``bglPolygonOffset(rv3d->dist, ...)`` see bug [#37727] + */ +void ED_view3d_polygon_offset(const RegionView3D *rv3d, float dist) +{ + float viewdist = rv3d->dist; + + /* special exception for ortho camera (viewdist isnt used for perspective cameras) */ + if (dist != 0.0f) { + if (rv3d->persp == RV3D_CAMOB) { + if (rv3d->is_persp == false) { + viewdist = 1.0f / max_ff(fabsf(rv3d->winmat[0][0]), fabsf(rv3d->winmat[1][1])); + } + } + } + + bglPolygonOffset(viewdist, dist); +} + /*! * \param rect for picking, NULL not to use. */ |