Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_cache_impl_mesh.c
| Show First 20 Lines • Show All 521 Lines • ▼ Show 20 Lines | if (!drw_mesh_weight_state_compare(&cache->weight_state, wstate)) { | ||||
| GPU_BATCH_CLEAR_SAFE(cache->batch.surface_weights); | GPU_BATCH_CLEAR_SAFE(cache->batch.surface_weights); | ||||
| cache->batch_ready &= ~MBC_SURFACE_WEIGHTS; | cache->batch_ready &= ~MBC_SURFACE_WEIGHTS; | ||||
| drw_mesh_weight_state_clear(&cache->weight_state); | drw_mesh_weight_state_clear(&cache->weight_state); | ||||
| } | } | ||||
| } | } | ||||
| static void mesh_batch_cache_discard_shaded_batches(MeshBatchCache *cache) | static void mesh_batch_cache_request_surface_batches(MeshBatchCache *cache) | ||||
| { | { | ||||
| mesh_batch_cache_add_request(cache, MBC_SURFACE); | |||||
| DRW_batch_request(&cache->batch.surface); | |||||
| if (cache->surface_per_mat) { | |||||
| for (int i = 0; i < cache->mat_len; i++) { | |||||
| DRW_batch_request(&cache->surface_per_mat[i]); | |||||
| } | |||||
| } | |||||
| } | |||||
| static void mesh_batch_cache_discard_surface_batches(MeshBatchCache *cache) | |||||
| { | |||||
| GPU_BATCH_DISCARD_SAFE(cache->batch.surface); | |||||
| if (cache->surface_per_mat) { | if (cache->surface_per_mat) { | ||||
| for (int i = 0; i < cache->mat_len; i++) { | for (int i = 0; i < cache->mat_len; i++) { | ||||
| GPU_BATCH_DISCARD_SAFE(cache->surface_per_mat[i]); | GPU_BATCH_DISCARD_SAFE(cache->surface_per_mat[i]); | ||||
| } | } | ||||
| } | } | ||||
| cache->batch_ready &= ~MBC_SURF_PER_MAT; | cache->batch_ready &= ~MBC_SURFACE; | ||||
| } | } | ||||
| static void mesh_batch_cache_discard_shaded_tri(MeshBatchCache *cache) | static void mesh_batch_cache_discard_shaded_tri(MeshBatchCache *cache) | ||||
| { | { | ||||
| FOREACH_MESH_BUFFER_CACHE (cache, mbufcache) { | FOREACH_MESH_BUFFER_CACHE (cache, mbufcache) { | ||||
| GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.pos_nor); | GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.pos_nor); | ||||
| GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.uv); | GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.uv); | ||||
| GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.tan); | GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.tan); | ||||
| GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.vcol); | GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.vcol); | ||||
| GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.orco); | GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.orco); | ||||
| } | } | ||||
| mesh_batch_cache_discard_shaded_batches(cache); | mesh_batch_cache_discard_surface_batches(cache); | ||||
| mesh_cd_layers_type_clear(&cache->cd_used); | mesh_cd_layers_type_clear(&cache->cd_used); | ||||
| MEM_SAFE_FREE(cache->surface_per_mat); | MEM_SAFE_FREE(cache->surface_per_mat); | ||||
| cache->mat_len = 0; | cache->mat_len = 0; | ||||
| } | } | ||||
| static void mesh_batch_cache_discard_uvedit(MeshBatchCache *cache) | static void mesh_batch_cache_discard_uvedit(MeshBatchCache *cache) | ||||
| Show All 23 Lines | static void mesh_batch_cache_discard_uvedit(MeshBatchCache *cache) | ||||
| cache->batch_ready &= ~MBC_EDITUV; | cache->batch_ready &= ~MBC_EDITUV; | ||||
| /* We discarded the vbo.uv so we need to reset the cd_used flag. */ | /* We discarded the vbo.uv so we need to reset the cd_used flag. */ | ||||
| cache->cd_used.uv = 0; | cache->cd_used.uv = 0; | ||||
| cache->cd_used.edit_uv = 0; | cache->cd_used.edit_uv = 0; | ||||
| /* Discard other batches that uses vbo.uv */ | /* Discard other batches that uses vbo.uv */ | ||||
| mesh_batch_cache_discard_shaded_batches(cache); | mesh_batch_cache_discard_surface_batches(cache); | ||||
| GPU_BATCH_DISCARD_SAFE(cache->batch.surface); | |||||
| cache->batch_ready &= ~MBC_SURFACE; | |||||
| } | } | ||||
| static void mesh_batch_cache_discard_uvedit_select(MeshBatchCache *cache) | static void mesh_batch_cache_discard_uvedit_select(MeshBatchCache *cache) | ||||
| { | { | ||||
| FOREACH_MESH_BUFFER_CACHE (cache, mbufcache) { | FOREACH_MESH_BUFFER_CACHE (cache, mbufcache) { | ||||
| GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.edituv_data); | GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.edituv_data); | ||||
| GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.fdots_edituv_data); | GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.fdots_edituv_data); | ||||
| GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.edituv_tris); | GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.edituv_tris); | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | case BKE_MESH_BATCH_DIRTY_SELECT_PAINT: | ||||
| FOREACH_MESH_BUFFER_CACHE (cache, mbufcache) { | FOREACH_MESH_BUFFER_CACHE (cache, mbufcache) { | ||||
| GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.lines_paint_mask); | GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.lines_paint_mask); | ||||
| GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.pos_nor); | GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.pos_nor); | ||||
| GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.lnor); | GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.lnor); | ||||
| } | } | ||||
| GPU_BATCH_DISCARD_SAFE(cache->batch.surface); | GPU_BATCH_DISCARD_SAFE(cache->batch.surface); | ||||
| GPU_BATCH_DISCARD_SAFE(cache->batch.wire_loops); | GPU_BATCH_DISCARD_SAFE(cache->batch.wire_loops); | ||||
| GPU_BATCH_DISCARD_SAFE(cache->batch.wire_edges); | GPU_BATCH_DISCARD_SAFE(cache->batch.wire_edges); | ||||
| if (cache->surface_per_mat) { | mesh_batch_cache_discard_surface_batches(cache); | ||||
| for (int i = 0; i < cache->mat_len; i++) { | cache->batch_ready &= ~(MBC_SURFACE | MBC_WIRE_EDGES | MBC_WIRE_LOOPS); | ||||
| GPU_BATCH_DISCARD_SAFE(cache->surface_per_mat[i]); | |||||
| } | |||||
| } | |||||
| cache->batch_ready &= ~(MBC_SURFACE | MBC_WIRE_EDGES | MBC_WIRE_LOOPS | MBC_SURF_PER_MAT); | |||||
| break; | break; | ||||
| case BKE_MESH_BATCH_DIRTY_ALL: | case BKE_MESH_BATCH_DIRTY_ALL: | ||||
| cache->is_dirty = true; | cache->is_dirty = true; | ||||
| break; | break; | ||||
| case BKE_MESH_BATCH_DIRTY_SHADING: | case BKE_MESH_BATCH_DIRTY_SHADING: | ||||
| mesh_batch_cache_discard_shaded_tri(cache); | mesh_batch_cache_discard_shaded_tri(cache); | ||||
| mesh_batch_cache_discard_uvedit(cache); | mesh_batch_cache_discard_uvedit(cache); | ||||
| break; | break; | ||||
| ▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | GPUBatch *DRW_mesh_batch_cache_get_all_edges(Mesh *me) | ||||
| MeshBatchCache *cache = mesh_batch_cache_get(me); | MeshBatchCache *cache = mesh_batch_cache_get(me); | ||||
| mesh_batch_cache_add_request(cache, MBC_ALL_EDGES); | mesh_batch_cache_add_request(cache, MBC_ALL_EDGES); | ||||
| return DRW_batch_request(&cache->batch.all_edges); | return DRW_batch_request(&cache->batch.all_edges); | ||||
| } | } | ||||
| GPUBatch *DRW_mesh_batch_cache_get_surface(Mesh *me) | GPUBatch *DRW_mesh_batch_cache_get_surface(Mesh *me) | ||||
| { | { | ||||
| MeshBatchCache *cache = mesh_batch_cache_get(me); | MeshBatchCache *cache = mesh_batch_cache_get(me); | ||||
| mesh_batch_cache_add_request(cache, MBC_SURFACE); | mesh_batch_cache_request_surface_batches(cache); | ||||
| return DRW_batch_request(&cache->batch.surface); | return cache->batch.surface; | ||||
| } | } | ||||
| GPUBatch *DRW_mesh_batch_cache_get_loose_edges(Mesh *me) | GPUBatch *DRW_mesh_batch_cache_get_loose_edges(Mesh *me) | ||||
| { | { | ||||
| MeshBatchCache *cache = mesh_batch_cache_get(me); | MeshBatchCache *cache = mesh_batch_cache_get(me); | ||||
| mesh_batch_cache_add_request(cache, MBC_LOOSE_EDGES); | mesh_batch_cache_add_request(cache, MBC_LOOSE_EDGES); | ||||
| if (cache->no_loose_wire) { | if (cache->no_loose_wire) { | ||||
| return NULL; | return NULL; | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(Mesh *me, | ||||
| uint gpumat_array_len) | uint gpumat_array_len) | ||||
| { | { | ||||
| MeshBatchCache *cache = mesh_batch_cache_get(me); | MeshBatchCache *cache = mesh_batch_cache_get(me); | ||||
| DRW_MeshCDMask cd_needed = mesh_cd_calc_used_gpu_layers(me, gpumat_array, gpumat_array_len); | DRW_MeshCDMask cd_needed = mesh_cd_calc_used_gpu_layers(me, gpumat_array, gpumat_array_len); | ||||
| BLI_assert(gpumat_array_len == cache->mat_len); | BLI_assert(gpumat_array_len == cache->mat_len); | ||||
| mesh_cd_layers_type_merge(&cache->cd_needed, cd_needed); | mesh_cd_layers_type_merge(&cache->cd_needed, cd_needed); | ||||
| mesh_batch_cache_request_surface_batches(cache); | |||||
| mesh_batch_cache_add_request(cache, MBC_SURF_PER_MAT); | |||||
| for (int i = 0; i < cache->mat_len; i++) { | |||||
| DRW_batch_request(&cache->surface_per_mat[i]); | |||||
| } | |||||
| return cache->surface_per_mat; | return cache->surface_per_mat; | ||||
| } | } | ||||
| GPUBatch **DRW_mesh_batch_cache_get_surface_texpaint(Mesh *me) | GPUBatch **DRW_mesh_batch_cache_get_surface_texpaint(Mesh *me) | ||||
| { | { | ||||
| MeshBatchCache *cache = mesh_batch_cache_get(me); | MeshBatchCache *cache = mesh_batch_cache_get(me); | ||||
| mesh_batch_cache_add_request(cache, MBC_SURF_PER_MAT); | |||||
| texpaint_request_active_uv(cache, me); | texpaint_request_active_uv(cache, me); | ||||
| for (int i = 0; i < cache->mat_len; i++) { | mesh_batch_cache_request_surface_batches(cache); | ||||
| DRW_batch_request(&cache->surface_per_mat[i]); | |||||
| } | |||||
| return cache->surface_per_mat; | return cache->surface_per_mat; | ||||
| } | } | ||||
| GPUBatch *DRW_mesh_batch_cache_get_surface_texpaint_single(Mesh *me) | GPUBatch *DRW_mesh_batch_cache_get_surface_texpaint_single(Mesh *me) | ||||
| { | { | ||||
| MeshBatchCache *cache = mesh_batch_cache_get(me); | MeshBatchCache *cache = mesh_batch_cache_get(me); | ||||
| texpaint_request_active_uv(cache, me); | texpaint_request_active_uv(cache, me); | ||||
| mesh_batch_cache_add_request(cache, MBC_SURFACE); | mesh_batch_cache_request_surface_batches(cache); | ||||
| return DRW_batch_request(&cache->batch.surface); | return cache->batch.surface; | ||||
| } | } | ||||
| GPUBatch *DRW_mesh_batch_cache_get_surface_vertpaint(Mesh *me) | GPUBatch *DRW_mesh_batch_cache_get_surface_vertpaint(Mesh *me) | ||||
| { | { | ||||
| MeshBatchCache *cache = mesh_batch_cache_get(me); | MeshBatchCache *cache = mesh_batch_cache_get(me); | ||||
| texpaint_request_active_vcol(cache, me); | texpaint_request_active_vcol(cache, me); | ||||
| mesh_batch_cache_add_request(cache, MBC_SURFACE); | mesh_batch_cache_request_surface_batches(cache); | ||||
| return DRW_batch_request(&cache->batch.surface); | return cache->batch.surface; | ||||
| } | } | ||||
| GPUBatch *DRW_mesh_batch_cache_get_surface_sculpt(Mesh *me) | GPUBatch *DRW_mesh_batch_cache_get_surface_sculpt(Mesh *me) | ||||
| { | { | ||||
| MeshBatchCache *cache = mesh_batch_cache_get(me); | MeshBatchCache *cache = mesh_batch_cache_get(me); | ||||
| sculpt_request_active_vcol(cache, me); | sculpt_request_active_vcol(cache, me); | ||||
| mesh_batch_cache_add_request(cache, MBC_SURFACE); | mesh_batch_cache_request_surface_batches(cache); | ||||
| return DRW_batch_request(&cache->batch.surface); | return cache->batch.surface; | ||||
| } | } | ||||
| int DRW_mesh_material_count_get(Mesh *me) | int DRW_mesh_material_count_get(Mesh *me) | ||||
| { | { | ||||
| return mesh_render_mat_len_get(me); | return mesh_render_mat_len_get(me); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| /** \name Edit Mode API | /** \name Edit Mode API | ||||
| * \{ */ | * \{ */ | ||||
| GPUVertBuf *DRW_mesh_batch_cache_pos_vertbuf_get(Mesh *me) | GPUVertBuf *DRW_mesh_batch_cache_pos_vertbuf_get(Mesh *me) | ||||
| { | { | ||||
| MeshBatchCache *cache = mesh_batch_cache_get(me); | MeshBatchCache *cache = mesh_batch_cache_get(me); | ||||
| /* Request surface to trigger the vbo filling. Otherwise it may do nothing. */ | /* Request surface to trigger the vbo filling. Otherwise it may do nothing. */ | ||||
| mesh_batch_cache_add_request(cache, MBC_SURFACE); | mesh_batch_cache_request_surface_batches(cache); | ||||
| DRW_batch_request(&cache->batch.surface); | |||||
| DRW_vbo_request(NULL, &cache->final.vbo.pos_nor); | DRW_vbo_request(NULL, &cache->final.vbo.pos_nor); | ||||
| return cache->final.vbo.pos_nor; | return cache->final.vbo.pos_nor; | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| ▲ Show 20 Lines • Show All 285 Lines • ▼ Show 20 Lines | if ((cache->batch.surface_weights != NULL) && (ts != NULL)) { | ||||
| BLI_assert(ob->type == OB_MESH); | BLI_assert(ob->type == OB_MESH); | ||||
| drw_mesh_weight_state_extract(ob, me, ts, is_paint_mode, &wstate); | drw_mesh_weight_state_extract(ob, me, ts, is_paint_mode, &wstate); | ||||
| mesh_batch_cache_check_vertex_group(cache, &wstate); | mesh_batch_cache_check_vertex_group(cache, &wstate); | ||||
| drw_mesh_weight_state_copy(&cache->weight_state, &wstate); | drw_mesh_weight_state_copy(&cache->weight_state, &wstate); | ||||
| drw_mesh_weight_state_clear(&wstate); | drw_mesh_weight_state_clear(&wstate); | ||||
| } | } | ||||
| } | } | ||||
| /* HACK: if MBC_SURF_PER_MAT is requested and ibo.tris is already available, it won't have it's | |||||
| * index ranges initialized. So discard ibo.tris in order to recreate it. | |||||
| * This needs to happen before saved_elem_ranges is populated. */ | |||||
| if ((batch_requested & MBC_SURF_PER_MAT) != 0 && (cache->batch_ready & MBC_SURF_PER_MAT) == 0) { | |||||
| FOREACH_MESH_BUFFER_CACHE (cache, mbuffercache) { | |||||
| GPU_INDEXBUF_DISCARD_SAFE(mbuffercache->ibo.tris); | |||||
| } | |||||
| /* Clear all batches that reference ibo.tris. */ | |||||
| GPU_BATCH_CLEAR_SAFE(cache->batch.surface); | |||||
| GPU_BATCH_CLEAR_SAFE(cache->batch.surface_weights); | |||||
| GPU_BATCH_CLEAR_SAFE(cache->batch.edit_mesh_analysis); | |||||
| GPU_BATCH_CLEAR_SAFE(cache->batch.edit_triangles); | |||||
| GPU_BATCH_CLEAR_SAFE(cache->batch.edit_lnor); | |||||
| GPU_BATCH_CLEAR_SAFE(cache->batch.edit_selection_faces); | |||||
| for (int i = 0; i < cache->mat_len; i++) { | |||||
| GPU_BATCH_CLEAR_SAFE(cache->surface_per_mat[i]); | |||||
| } | |||||
| cache->batch_ready &= ~(MBC_SURFACE | MBC_SURFACE_WEIGHTS | MBC_EDIT_MESH_ANALYSIS | | |||||
| MBC_EDIT_TRIANGLES | MBC_EDIT_LNOR | MBC_EDIT_SELECTION_FACES); | |||||
| } | |||||
| if (batch_requested & | if (batch_requested & | ||||
| (MBC_SURFACE | MBC_SURF_PER_MAT | MBC_WIRE_LOOPS_UVS | MBC_EDITUV_FACES_STRETCH_AREA | | (MBC_SURFACE | MBC_WIRE_LOOPS_UVS | MBC_EDITUV_FACES_STRETCH_AREA | | ||||
| MBC_EDITUV_FACES_STRETCH_ANGLE | MBC_EDITUV_FACES | MBC_EDITUV_EDGES | MBC_EDITUV_VERTS)) { | MBC_EDITUV_FACES_STRETCH_ANGLE | MBC_EDITUV_FACES | MBC_EDITUV_EDGES | MBC_EDITUV_VERTS)) { | ||||
| /* Modifiers will only generate an orco layer if the mesh is deformed. */ | /* Modifiers will only generate an orco layer if the mesh is deformed. */ | ||||
| if (cache->cd_needed.orco != 0) { | if (cache->cd_needed.orco != 0) { | ||||
| /* Orco is always extracted from final mesh. */ | /* Orco is always extracted from final mesh. */ | ||||
| Mesh *me_final = (me->edit_mesh) ? me->edit_mesh->mesh_eval_final : me; | Mesh *me_final = (me->edit_mesh) ? me->edit_mesh->mesh_eval_final : me; | ||||
| if (CustomData_get_layer(&me_final->vdata, CD_ORCO) == NULL) { | if (CustomData_get_layer(&me_final->vdata, CD_ORCO) == NULL) { | ||||
| /* Skip orco calculation */ | /* Skip orco calculation */ | ||||
| cache->cd_needed.orco = 0; | cache->cd_needed.orco = 0; | ||||
| Show All 36 Lines | if (cd_overlap == false) { | ||||
| } | } | ||||
| } | } | ||||
| /* We can't discard batches at this point as they have been | /* We can't discard batches at this point as they have been | ||||
| * referenced for drawing. Just clear them in place. */ | * referenced for drawing. Just clear them in place. */ | ||||
| for (int i = 0; i < cache->mat_len; i++) { | for (int i = 0; i < cache->mat_len; i++) { | ||||
| GPU_BATCH_CLEAR_SAFE(cache->surface_per_mat[i]); | GPU_BATCH_CLEAR_SAFE(cache->surface_per_mat[i]); | ||||
| } | } | ||||
| GPU_BATCH_CLEAR_SAFE(cache->batch.surface); | GPU_BATCH_CLEAR_SAFE(cache->batch.surface); | ||||
| cache->batch_ready &= ~(MBC_SURFACE | MBC_SURF_PER_MAT); | cache->batch_ready &= ~(MBC_SURFACE); | ||||
| mesh_cd_layers_type_merge(&cache->cd_used, cache->cd_needed); | mesh_cd_layers_type_merge(&cache->cd_used, cache->cd_needed); | ||||
| } | } | ||||
| mesh_cd_layers_type_merge(&cache->cd_used_over_time, cache->cd_needed); | mesh_cd_layers_type_merge(&cache->cd_used_over_time, cache->cd_needed); | ||||
| mesh_cd_layers_type_clear(&cache->cd_needed); | mesh_cd_layers_type_clear(&cache->cd_needed); | ||||
| } | } | ||||
| if (batch_requested & MBC_EDITUV) { | if (batch_requested & MBC_EDITUV) { | ||||
| ▲ Show 20 Lines • Show All 286 Lines • Show Last 20 Lines | |||||