From 7c31edb385fce1ce3425c88994a333f4e6f6d5bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Thu, 8 Mar 2018 17:54:14 +0100 Subject: DRW: Culling: Expose & Add culling functions to engines. This way engines can do preemptive culling by themselves. --- source/blender/draw/intern/draw_manager_exec.c | 36 +++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'source/blender/draw/intern/draw_manager_exec.c') diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index 1c149330005..27a94ae064b 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -530,11 +530,15 @@ static void draw_clipping_setup_from_view(void) /* Transform to world space. */ mul_m4_v3(viewinv, bsphere->center); } + + DST.clipping.updated = true; } /* Return True if the given BoundSphere intersect the current view frustum */ -static bool draw_culling_sphere_test(BoundSphere *bsphere) +bool DRW_culling_sphere_test(BoundSphere *bsphere) { + draw_clipping_setup_from_view(); + /* Bypass test if radius is negative. */ if (bsphere->radius < 0.0f) return true; @@ -556,6 +560,32 @@ static bool draw_culling_sphere_test(BoundSphere *bsphere) return true; } +/* Return True if the given BoundBox intersect the current view frustum. + * bbox must be in world space. */ +bool DRW_culling_box_test(BoundBox *bbox) +{ + draw_clipping_setup_from_view(); + + /* 6 view frustum planes */ + for (int p = 0; p < 6; p++) { + /* 8 box vertices. */ + for (int v = 0; v < 8 ; v++) { + float dist = plane_point_side_v3(DST.clipping.frustum_planes[p], bbox->vec[v]); + if (dist > 0.0f) { + /* At least one point in front of this plane. + * Go to next plane. */ + break; + } + else if (v == 7) { + /* 8 points behind this plane. */ + return false; + } + } + } + + return true; +} + /** \} */ /* -------------------------------------------------------------------- */ @@ -572,7 +602,7 @@ static void draw_matrices_model_prepare(DRWCallState *st) st->cache_id = DST.state_cache_id; } - if (draw_culling_sphere_test(&st->bsphere)) { + if (DRW_culling_sphere_test(&st->bsphere)) { st->flag &= ~DRW_CALL_CULLED; } else { @@ -934,8 +964,6 @@ static void drw_draw_pass_ex(DRWPass *pass, DRWShadingGroup *start_group, DRWSha } } - DST.clipping.updated = false; - /* TODO dispatch threads to compute matrices/culling */ } -- cgit v1.2.3