diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-01-23 15:30:30 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-01-23 15:37:25 +0300 |
commit | 48eed058b170e3def90fbc420933638d3986ca2c (patch) | |
tree | 5e2ddb5fae907ae921b26f027b77437c1cd2ccbe /source/blender/draw/intern/draw_view.c | |
parent | 44e9fe024bba014aa49b3a106fe89aa0b6e610cd (diff) |
3D View: draw clipping region
Only for workbench solid/wire modes.
Diffstat (limited to 'source/blender/draw/intern/draw_view.c')
-rw-r--r-- | source/blender/draw/intern/draw_view.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/source/blender/draw/intern/draw_view.c b/source/blender/draw/intern/draw_view.c index 2d5dbac5dd5..027eda05933 100644 --- a/source/blender/draw/intern/draw_view.c +++ b/source/blender/draw/intern/draw_view.c @@ -126,6 +126,41 @@ void DRW_draw_background(void) } } +GPUBatch *DRW_draw_background_clipping_batch_from_rv3d(const RegionView3D *rv3d) +{ + const BoundBox *bb = rv3d->clipbb; + const uint clipping_index[6][4] = { + {0, 1, 2, 3}, + {0, 4, 5, 1}, + {4, 7, 6, 5}, + {7, 3, 2, 6}, + {1, 5, 6, 2}, + {7, 4, 0, 3} + }; + GPUVertBuf *vbo; + GPUIndexBuf *el; + GPUIndexBufBuilder elb = {0}; + + /* Elements */ + GPU_indexbuf_init(&elb, GPU_PRIM_TRIS, ARRAY_SIZE(clipping_index) * 2, ARRAY_SIZE(bb->vec)); + for (int i = 0; i < ARRAY_SIZE(clipping_index); i++) { + const uint *idx = clipping_index[i]; + GPU_indexbuf_add_tri_verts(&elb, idx[0], idx[1], idx[2]); + GPU_indexbuf_add_tri_verts(&elb, idx[0], idx[2], idx[3]); + } + el = GPU_indexbuf_build(&elb); + + GPUVertFormat format = {0}; + uint pos_id = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); + + vbo = GPU_vertbuf_create_with_format(&format); + GPU_vertbuf_data_alloc(vbo, ARRAY_SIZE(bb->vec)); + GPU_vertbuf_attr_fill(vbo, pos_id, bb->vec); + + return GPU_batch_create_ex(GPU_PRIM_TRIS, vbo, el, GPU_BATCH_OWNS_VBO | GPU_BATCH_OWNS_INDEX); +} + + /* **************************** 3D Cursor ******************************** */ static bool is_cursor_visible(const DRWContextState *draw_ctx, Scene *scene, ViewLayer *view_layer) |