diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-05-29 16:02:08 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-05-30 13:25:20 +0300 |
commit | 93de6ca2dbaee10482fa20de6a7ad384b232dd87 (patch) | |
tree | f9baa8182ab58dbe0c1f77937043aa0921782f66 /source | |
parent | 0488b728ebec61b50351d850d8fd52bfe67a40f0 (diff) |
DRW: Instance selection id: use Batch buffers instead of DRWInstanceData
This is motivated by the refactor of DRWInstanceData to be actual non
contiguous mempools.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/draw/intern/draw_manager.h | 2 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_data.c | 37 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_exec.c | 5 |
3 files changed, 37 insertions, 7 deletions
diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index 6fd000c0939..77bb37b9c8a 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -253,7 +253,7 @@ struct DRWShadingGroup { #endif #ifdef USE_GPU_SELECT - DRWInstanceData *inst_selectid; + Gwn_VertBuf *inst_selectid; DRWPass *pass_parent; /* backlink to pass we're in */ int override_selectid; /* Override for single object instances. */ #endif diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c index 105eab5a958..c5d7f205687 100644 --- a/source/blender/draw/intern/draw_manager_data.c +++ b/source/blender/draw/intern/draw_manager_data.c @@ -517,12 +517,10 @@ void DRW_shgroup_call_dynamic_add_array(DRWShadingGroup *shgroup, const void *at { #ifdef USE_GPU_SELECT if (G.f & G_PICKSEL) { - if (shgroup->inst_selectid == NULL) { - shgroup->inst_selectid = DRW_instance_data_request(DST.idatalist, 1, 128); + if (shgroup->instance_count == shgroup->inst_selectid->vertex_ct) { + GWN_vertbuf_data_resize(shgroup->inst_selectid, shgroup->instance_count + 32); } - - int *select_id = DRW_instance_data_next(shgroup->inst_selectid); - *select_id = DST.select_id; + GWN_vertbuf_attr_set(shgroup->inst_selectid, 0, shgroup->instance_count, &DST.select_id); } #endif @@ -622,6 +620,21 @@ static void drw_shgroup_instance_init( DRW_instancing_buffer_request(DST.idatalist, format, batch, shgroup, &shgroup->instance_geom, &shgroup->instance_vbo); + +#ifdef USE_GPU_SELECT + if (G.f & G_PICKSEL) { + /* Not actually used for rendering but alloced in one chunk. + * Plus we don't have to care about ownership. */ + static Gwn_VertFormat inst_select_format = {0}; + if (inst_select_format.attrib_ct == 0) { + GWN_vertformat_attr_add(&inst_select_format, "selectId", GWN_COMP_I32, 1, GWN_FETCH_INT); + } + Gwn_Batch *batch_dummy; /* Not used */ + DRW_batching_buffer_request(DST.idatalist, &inst_select_format, + GWN_PRIM_POINTS, shgroup, + &batch_dummy, &shgroup->inst_selectid); + } +#endif } static void drw_shgroup_batching_init( @@ -644,6 +657,20 @@ static void drw_shgroup_batching_init( DRW_batching_buffer_request(DST.idatalist, format, type, shgroup, &shgroup->batch_geom, &shgroup->batch_vbo); + +#ifdef USE_GPU_SELECT + if (G.f & G_PICKSEL) { + /* Not actually used for rendering but alloced in one chunk. */ + static Gwn_VertFormat inst_select_format = {0}; + if (inst_select_format.attrib_ct == 0) { + GWN_vertformat_attr_add(&inst_select_format, "selectId", GWN_COMP_I32, 1, GWN_FETCH_INT); + } + Gwn_Batch *batch; /* Not used */ + DRW_batching_buffer_request(DST.idatalist, &inst_select_format, + GWN_PRIM_POINTS, shgroup, + &batch, &shgroup->inst_selectid); + } +#endif } static DRWShadingGroup *drw_shgroup_create_ex(struct GPUShader *shader, DRWPass *pass) diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index 8b0bbb3ad15..98135a614d9 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -1045,7 +1045,10 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state) int *select_id = NULL; \ if (G.f & G_PICKSEL) { \ if (_shgroup->override_selectid == -1) { \ - select_id = DRW_instance_data_get(_shgroup->inst_selectid); \ + /* Hack : get vbo data without actually drawing. */ \ + Gwn_VertBufRaw raw; \ + GWN_vertbuf_attr_get_raw_data(_shgroup->inst_selectid, 0, &raw); \ + select_id = GWN_vertbuf_raw_step(&raw); \ switch (_shgroup->type) { \ case DRW_SHG_TRIANGLE_BATCH: _count = 3; break; \ case DRW_SHG_LINE_BATCH: _count = 2; break; \ |