diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-03-08 19:54:14 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-03-10 04:18:25 +0300 |
commit | 7c31edb385fce1ce3425c88994a333f4e6f6d5bc (patch) | |
tree | 9c5d6404c4c888a66fbb56ac6753c67335b7a187 /source/blender/draw/intern/draw_manager_exec.c | |
parent | 4402633e33c9687ad24467f5dc7891ad2b2c1f26 (diff) |
DRW: Culling: Expose & Add culling functions to engines.
This way engines can do preemptive culling by themselves.
Diffstat (limited to 'source/blender/draw/intern/draw_manager_exec.c')
-rw-r--r-- | source/blender/draw/intern/draw_manager_exec.c | 36 |
1 files changed, 32 insertions, 4 deletions
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 */ } |