Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_manager_data.c
| Show First 20 Lines • Show All 500 Lines • ▼ Show 20 Lines | static void drw_call_obinfos_init(DRWObjectInfos *ob_infos, Object *ob) | ||||
| drw_call_calc_orco(ob, ob_infos->orcotexfac); | drw_call_calc_orco(ob, ob_infos->orcotexfac); | ||||
| /* Random float value. */ | /* Random float value. */ | ||||
| uint random = (DST.dupli_source) ? | uint random = (DST.dupli_source) ? | ||||
| DST.dupli_source->random_id : | DST.dupli_source->random_id : | ||||
| /* TODO(fclem) this is rather costly to do at runtime. Maybe we can | /* TODO(fclem) this is rather costly to do at runtime. Maybe we can | ||||
| * put it in ob->runtime and make depsgraph ensure it is up to date. */ | * put it in ob->runtime and make depsgraph ensure it is up to date. */ | ||||
| BLI_hash_int_2d(BLI_hash_string(ob->id.name + 2), 0); | BLI_hash_int_2d(BLI_hash_string(ob->id.name + 2), 0); | ||||
| ob_infos->ob_random = random * (1.0f / (float)0xFFFFFFFF); | ob_infos->ob_random = random * (1.0f / (float)0xFFFFFFFF); | ||||
| /* Object State. */ | |||||
| ob_infos->ob_flag = 1.0f; /* Required to have a correct sign */ | |||||
| ob_infos->ob_flag += (ob->base_flag & BASE_SELECTED) ? (1 << 1) : 0; | |||||
| ob_infos->ob_flag += (ob->base_flag & BASE_FROM_DUPLI) ? (1 << 2) : 0; | |||||
| ob_infos->ob_flag += (ob->base_flag & BASE_FROM_SET) ? (1 << 3) : 0; | |||||
| ob_infos->ob_flag += (ob == DST.draw_ctx.obact) ? (1 << 4) : 0; | |||||
| /* Negative scalling. */ | /* Negative scalling. */ | ||||
| ob_infos->ob_neg_scale = (ob->transflag & OB_NEG_SCALE) ? -1.0f : 1.0f; | ob_infos->ob_flag *= (ob->transflag & OB_NEG_SCALE) ? -1.0f : 1.0f; | ||||
| /* Object Color. */ | /* Object Color. */ | ||||
| copy_v4_v4(ob_infos->ob_color, ob->color); | copy_v4_v4(ob_infos->ob_color, ob->color); | ||||
| } | } | ||||
| static void drw_call_culling_init(DRWCullingState *cull, Object *ob) | static void drw_call_culling_init(DRWCullingState *cull, Object *ob) | ||||
| { | { | ||||
| BoundBox *bbox; | BoundBox *bbox; | ||||
| if (ob != NULL && (bbox = BKE_object_boundbox_get(ob))) { | if (ob != NULL && (bbox = BKE_object_boundbox_get(ob))) { | ||||
| ▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | static void drw_command_draw_range(DRWShadingGroup *shgroup, | ||||
| cmd->batch = batch; | cmd->batch = batch; | ||||
| cmd->vert_first = start; | cmd->vert_first = start; | ||||
| cmd->vert_count = count; | cmd->vert_count = count; | ||||
| } | } | ||||
| static void drw_command_draw_instance(DRWShadingGroup *shgroup, | static void drw_command_draw_instance(DRWShadingGroup *shgroup, | ||||
| GPUBatch *batch, | GPUBatch *batch, | ||||
| DRWResourceHandle handle, | DRWResourceHandle handle, | ||||
| uint count) | uint count, | ||||
| bool use_attrib) | |||||
| { | { | ||||
| DRWCommandDrawInstance *cmd = drw_command_create(shgroup, DRW_CMD_DRAW_INSTANCE); | DRWCommandDrawInstance *cmd = drw_command_create(shgroup, DRW_CMD_DRAW_INSTANCE); | ||||
| cmd->batch = batch; | cmd->batch = batch; | ||||
| cmd->handle = handle; | cmd->handle = handle; | ||||
| cmd->inst_count = count; | cmd->inst_count = count; | ||||
| cmd->use_attribs = use_attrib; | |||||
| } | } | ||||
| static void drw_command_draw_procedural(DRWShadingGroup *shgroup, | static void drw_command_draw_procedural(DRWShadingGroup *shgroup, | ||||
| GPUBatch *batch, | GPUBatch *batch, | ||||
| DRWResourceHandle handle, | DRWResourceHandle handle, | ||||
| uint vert_count) | uint vert_count) | ||||
| { | { | ||||
| DRWCommandDrawProcedural *cmd = drw_command_create(shgroup, DRW_CMD_DRAW_PROCEDURAL); | DRWCommandDrawProcedural *cmd = drw_command_create(shgroup, DRW_CMD_DRAW_PROCEDURAL); | ||||
| ▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | void DRW_shgroup_call_instances(DRWShadingGroup *shgroup, | ||||
| struct GPUBatch *geom, | struct GPUBatch *geom, | ||||
| uint count) | uint count) | ||||
| { | { | ||||
| BLI_assert(geom != NULL); | BLI_assert(geom != NULL); | ||||
| if (G.f & G_FLAG_PICKSEL) { | if (G.f & G_FLAG_PICKSEL) { | ||||
| drw_command_set_select_id(shgroup, NULL, DST.select_id); | drw_command_set_select_id(shgroup, NULL, DST.select_id); | ||||
| } | } | ||||
| DRWResourceHandle handle = drw_resource_handle(shgroup, ob ? ob->obmat : NULL, ob); | DRWResourceHandle handle = drw_resource_handle(shgroup, ob ? ob->obmat : NULL, ob); | ||||
| drw_command_draw_instance(shgroup, geom, handle, count); | drw_command_draw_instance(shgroup, geom, handle, count, false); | ||||
| } | } | ||||
| void DRW_shgroup_call_instances_with_attribs(DRWShadingGroup *shgroup, | void DRW_shgroup_call_instances_with_attribs(DRWShadingGroup *shgroup, | ||||
| Object *ob, | Object *ob, | ||||
| struct GPUBatch *geom, | struct GPUBatch *geom, | ||||
| struct GPUBatch *inst_attributes) | struct GPUBatch *inst_attributes) | ||||
| { | { | ||||
| BLI_assert(geom != NULL); | BLI_assert(geom != NULL); | ||||
| BLI_assert(inst_attributes->verts[0] != NULL); | BLI_assert(inst_attributes != NULL); | ||||
| if (G.f & G_FLAG_PICKSEL) { | if (G.f & G_FLAG_PICKSEL) { | ||||
| drw_command_set_select_id(shgroup, NULL, DST.select_id); | drw_command_set_select_id(shgroup, NULL, DST.select_id); | ||||
| } | } | ||||
| DRWResourceHandle handle = drw_resource_handle(shgroup, ob ? ob->obmat : NULL, ob); | DRWResourceHandle handle = drw_resource_handle(shgroup, ob ? ob->obmat : NULL, ob); | ||||
| GPUVertBuf *buf_inst = inst_attributes->verts[0]; | GPUBatch *batch = DRW_temp_batch_instance_request(DST.idatalist, NULL, inst_attributes, geom); | ||||
| GPUBatch *batch = DRW_temp_batch_instance_request(DST.idatalist, buf_inst, geom); | drw_command_draw_instance(shgroup, batch, handle, 0, true); | ||||
| drw_command_draw(shgroup, batch, handle); | |||||
| } | } | ||||
| #define SCULPT_DEBUG_BUFFERS (G.debug_value == 889) | #define SCULPT_DEBUG_BUFFERS (G.debug_value == 889) | ||||
| typedef struct DRWSculptCallbackData { | typedef struct DRWSculptCallbackData { | ||||
| Object *ob; | Object *ob; | ||||
| DRWShadingGroup **shading_groups; | DRWShadingGroup **shading_groups; | ||||
| bool use_wire; | bool use_wire; | ||||
| bool use_mats; | bool use_mats; | ||||
| ▲ Show 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | if (inst_select_format.attr_len == 0) { | ||||
| GPU_vertformat_attr_add(&inst_select_format, "selectId", GPU_COMP_I32, 1, GPU_FETCH_INT); | GPU_vertformat_attr_add(&inst_select_format, "selectId", GPU_COMP_I32, 1, GPU_FETCH_INT); | ||||
| } | } | ||||
| callbuf->buf_select = DRW_temp_buffer_request( | callbuf->buf_select = DRW_temp_buffer_request( | ||||
| DST.idatalist, &inst_select_format, &callbuf->count); | DST.idatalist, &inst_select_format, &callbuf->count); | ||||
| drw_command_set_select_id(shgroup, callbuf->buf_select, -1); | drw_command_set_select_id(shgroup, callbuf->buf_select, -1); | ||||
| } | } | ||||
| DRWResourceHandle handle = drw_resource_handle(shgroup, NULL, NULL); | DRWResourceHandle handle = drw_resource_handle(shgroup, NULL, NULL); | ||||
| GPUBatch *batch = DRW_temp_batch_instance_request(DST.idatalist, callbuf->buf, geom); | GPUBatch *batch = DRW_temp_batch_instance_request(DST.idatalist, callbuf->buf, NULL, geom); | ||||
| drw_command_draw(shgroup, batch, handle); | drw_command_draw(shgroup, batch, handle); | ||||
| return callbuf; | return callbuf; | ||||
| } | } | ||||
| void DRW_buffer_add_entry_struct(DRWCallBuffer *callbuf, const void *data) | |||||
| { | |||||
| GPUVertBuf *buf = callbuf->buf; | |||||
| const bool resize = (callbuf->count == buf->vertex_alloc); | |||||
| if (UNLIKELY(resize)) { | |||||
| GPU_vertbuf_data_resize(buf, callbuf->count + DRW_BUFFER_VERTS_CHUNK); | |||||
| } | |||||
| GPU_vertbuf_vert_set(buf, callbuf->count, data); | |||||
| if (G.f & G_FLAG_PICKSEL) { | |||||
| if (UNLIKELY(resize)) { | |||||
| GPU_vertbuf_data_resize(callbuf->buf_select, callbuf->count + DRW_BUFFER_VERTS_CHUNK); | |||||
| } | |||||
| GPU_vertbuf_attr_set(callbuf->buf_select, 0, callbuf->count, &DST.select_id); | |||||
| } | |||||
| callbuf->count++; | |||||
| } | |||||
| void DRW_buffer_add_entry_array(DRWCallBuffer *callbuf, const void *attr[], uint attr_len) | void DRW_buffer_add_entry_array(DRWCallBuffer *callbuf, const void *attr[], uint attr_len) | ||||
| { | { | ||||
| GPUVertBuf *buf = callbuf->buf; | GPUVertBuf *buf = callbuf->buf; | ||||
| const bool resize = (callbuf->count == buf->vertex_alloc); | const bool resize = (callbuf->count == buf->vertex_alloc); | ||||
| BLI_assert(attr_len == buf->format.attr_len); | BLI_assert(attr_len == buf->format.attr_len); | ||||
| UNUSED_VARS_NDEBUG(attr_len); | UNUSED_VARS_NDEBUG(attr_len); | ||||
| ▲ Show 20 Lines • Show All 546 Lines • ▼ Show 20 Lines | DRWView *DRW_view_create(const float viewmat[4][4], | ||||
| return view; | return view; | ||||
| } | } | ||||
| /* Create a view with culling done by another view. */ | /* Create a view with culling done by another view. */ | ||||
| DRWView *DRW_view_create_sub(const DRWView *parent_view, | DRWView *DRW_view_create_sub(const DRWView *parent_view, | ||||
| const float viewmat[4][4], | const float viewmat[4][4], | ||||
| const float winmat[4][4]) | const float winmat[4][4]) | ||||
| { | { | ||||
| BLI_assert(parent_view && parent_view->parent == NULL); | /* Search original parent. */ | ||||
| const DRWView *ori_view = parent_view; | |||||
| while (ori_view->parent != NULL) { | |||||
| ori_view = ori_view->parent; | |||||
| } | |||||
| DRWView *view = BLI_memblock_alloc(DST.vmempool->views); | DRWView *view = BLI_memblock_alloc(DST.vmempool->views); | ||||
| /* Perform copy. */ | /* Perform copy. */ | ||||
| *view = *parent_view; | *view = *ori_view; | ||||
| view->parent = (DRWView *)parent_view; | view->parent = (DRWView *)ori_view; | ||||
| DRW_view_update_sub(view, viewmat, winmat); | DRW_view_update_sub(view, viewmat, winmat); | ||||
| return view; | return view; | ||||
| } | } | ||||
| /** | /** | ||||
| * DRWView Update: | * DRWView Update: | ||||
| ▲ Show 20 Lines • Show All 311 Lines • ▼ Show 20 Lines | void DRW_pass_sort_shgroup_z(DRWPass *pass) | ||||
| DRWShadingGroup *last = pass->shgroups.first; | DRWShadingGroup *last = pass->shgroups.first; | ||||
| while ((last = last->next)) { | while ((last = last->next)) { | ||||
| /* Reset the pass id for debugging. */ | /* Reset the pass id for debugging. */ | ||||
| last->pass_handle = pass->handle; | last->pass_handle = pass->handle; | ||||
| } | } | ||||
| pass->shgroups.last = last; | pass->shgroups.last = last; | ||||
| } | } | ||||
| /** | |||||
| * Reverse Shading group submission order. | |||||
| */ | |||||
| void DRW_pass_sort_shgroup_reverse(DRWPass *pass) | |||||
| { | |||||
| pass->shgroups.last = pass->shgroups.first; | |||||
| /* WARNING: Assume that DRWShadingGroup->next is the first member. */ | |||||
| BLI_linklist_reverse((LinkNode **)&pass->shgroups.first); | |||||
| } | |||||
| /** \} */ | /** \} */ | ||||