View3D: avoid matrix multiply using ED_view3d_boundbox_clip

This commit is contained in:
Campbell Barton 2014-03-20 12:17:44 +11:00
parent d4b8f6798d
commit aee30184f3
Notes: blender-bot 2023-02-14 10:59:04 +01:00
Referenced by issue #39297, bpy.selection is not working as expected
Referenced by issue #39275, emission shader value output increased in 2.70
Referenced by issue #39225, Ortho Perspective mode  bug
4 changed files with 36 additions and 21 deletions

View File

@ -3698,7 +3698,7 @@ static bool draw_mesh_object(Scene *scene, ARegion *ar, View3D *v3d, RegionView3
}
else {
/* ob->bb was set by derived mesh system, do NULL check just to be sure */
if (me->totpoly <= 4 || (!ob->bb || ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb))) {
if (me->totpoly <= 4 || (!ob->bb || ED_view3d_boundbox_clip(rv3d, ob->bb))) {
const bool glsl = draw_glsl_material(scene, ob, v3d, dt);
const bool check_alpha = check_alpha_pass(base);
@ -6421,7 +6421,7 @@ static void drawObjectSelect(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
has_faces = BKE_displist_has_faces(&ob->curve_cache->disp);
}
if (has_faces && ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb)) {
if (has_faces && ED_view3d_boundbox_clip(rv3d, ob->bb)) {
draw_index_wire = false;
if (dm) {
draw_mesh_object_outline(v3d, ob, dm);
@ -6462,7 +6462,7 @@ static void draw_wire_extra(Scene *scene, RegionView3D *rv3d, Object *ob, unsign
glDepthMask(0); /* disable write in zbuffer, selected edge wires show better */
if (ELEM3(ob->type, OB_FONT, OB_CURVE, OB_SURF)) {
if (ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb)) {
if (ED_view3d_boundbox_clip(rv3d, ob->bb)) {
if (ob->type == OB_CURVE)
draw_index_wire = false;
@ -6981,7 +6981,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
draw_bounding_volume(ob, ob->boundtype);
}
}
else if (ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb)) {
else if (ED_view3d_boundbox_clip(rv3d, ob->bb)) {
empty_object = drawDispList(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
}
@ -7002,7 +7002,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
draw_bounding_volume(ob, ob->boundtype);
}
}
else if (ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb)) {
else if (ED_view3d_boundbox_clip(rv3d, ob->bb)) {
empty_object = drawDispList(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
//XXX old animsys if (cu->path)

View File

@ -2065,10 +2065,11 @@ static void draw_dupli_objects_color(Scene *scene, ARegion *ar, View3D *v3d, Bas
}
}
if (use_displist) {
glMultMatrixf(dob->mat);
if (ED_view3d_boundbox_clip(rv3d, dob->mat, &bb))
if (ED_view3d_boundbox_clip_ex(rv3d, &bb, dob->mat)) {
glMultMatrixf(dob->mat);
glCallList(displist);
glLoadMatrixf(rv3d->viewmat);
glLoadMatrixf(rv3d->viewmat);
}
}
else {
draw_object(scene, ar, v3d, &tbase, DRAW_CONSTCOLOR);

View File

@ -199,7 +199,8 @@ void VIEW3D_OT_localview(struct wmOperatorType *ot);
void VIEW3D_OT_game_start(struct wmOperatorType *ot);
bool ED_view3d_boundbox_clip(RegionView3D *rv3d, float obmat[4][4], const struct BoundBox *bb);
bool ED_view3d_boundbox_clip_ex(RegionView3D *rv3d, const struct BoundBox *bb, float obmat[4][4]);
bool ED_view3d_boundbox_clip(RegionView3D *rv3d, const struct BoundBox *bb);
void ED_view3d_smooth_view(struct bContext *C, struct View3D *v3d, struct ARegion *ar, struct Object *, struct Object *,
float *ofs, float *quat, float *dist, float *lens,

View File

@ -642,24 +642,15 @@ void ED_view3d_clipping_calc(BoundBox *bb, float planes[4][4], bglMats *mats, co
}
}
bool ED_view3d_boundbox_clip(RegionView3D *rv3d, float obmat[4][4], const BoundBox *bb)
static bool view3d_boundbox_clip_m4(const BoundBox *bb, float persmatob[4][4])
{
/* return 1: draw */
float mat[4][4];
float vec[4], min, max;
int a, flag = -1, fl;
if (bb == NULL) return true;
if (bb->flag & BOUNDBOX_DISABLED) return true;
mul_m4_m4m4(mat, rv3d->persmat, obmat);
for (a = 0; a < 8; a++) {
float vec[4], min, max;
copy_v3_v3(vec, bb->vec[a]);
vec[3] = 1.0;
mul_m4_v4(mat, vec);
mul_m4_v4(persmatob, vec);
max = vec[3];
min = -vec[3];
@ -678,6 +669,28 @@ bool ED_view3d_boundbox_clip(RegionView3D *rv3d, float obmat[4][4], const BoundB
return false;
}
bool ED_view3d_boundbox_clip_ex(RegionView3D *rv3d, const BoundBox *bb, float obmat[4][4])
{
/* return 1: draw */
float persmatob[4][4];
if (bb == NULL) return true;
if (bb->flag & BOUNDBOX_DISABLED) return true;
mul_m4_m4m4(persmatob, rv3d->persmat, obmat);
return view3d_boundbox_clip_m4(bb, persmatob);
}
bool ED_view3d_boundbox_clip(RegionView3D *rv3d, const BoundBox *bb)
{
if (bb == NULL) return true;
if (bb->flag & BOUNDBOX_DISABLED) return true;
return view3d_boundbox_clip_m4(bb, rv3d->persmatob);
}
float ED_view3d_depth_read_cached(ViewContext *vc, int x, int y)
{
ViewDepths *vd = vc->rv3d->depths;