Commit: ae1f563899de458b94d315823fd077ea4002dd86 Author: Clément Foucault Date: Sun Dec 9 11:21:23 2018 +0100 Branches: blender2.8 https://developer.blender.org/rBae1f563899de458b94d315823fd077ea4002dd86
DRW: Batch Cache: Mesh: Port more batches to batch request method =================================================================== M source/blender/draw/intern/draw_cache_impl_mesh.c =================================================================== diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c index 0933d890881..aaec7295f5f 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.c +++ b/source/blender/draw/intern/draw_cache_impl_mesh.c @@ -948,6 +948,22 @@ static MeshRenderData *mesh_render_data_create_ex( return rdata; } +/* Warning replace mesh pointer. */ +#define MBC_GET_FINAL_MESH(mesh) do { \ + /* Hack to show the final result. */ \ + const bool use_em_final = ( \ + (mesh)->edit_btmesh && \ + (mesh)->edit_btmesh->mesh_eval_final && \ + ((mesh)->edit_btmesh->mesh_eval_final->runtime.is_original == false)); \ + Mesh me_fake; \ + if (use_em_final) { \ + me_fake = *(mesh)->edit_btmesh->mesh_eval_final; \ + me_fake.mat = (mesh)->mat; \ + me_fake.totcol = (mesh)->totcol; \ + (mesh) = &me_fake; \ + } \ +} while (0) + static void mesh_render_data_free(MeshRenderData *rdata) { if (rdata->is_orco_allocated) { @@ -2001,13 +2017,27 @@ bool DRW_mesh_weight_state_compare(const struct DRW_MeshWeightState *a, const st * \{ */ typedef struct MeshBatchCache { - GPUVertBuf *pos_in_order; + /* Vert buffers. */ + GPUVertBuf *pos_and_nor; + + /* Tesselated: (all verts specified for each triangles). + * Indices does not match the CPU data structure's. */ + struct { + GPUVertBuf *pos_and_nor; + + GPUVertBuf *wireframe_data; + } tess; + + GPUBatch *all_verts; + + GPUBatch *face_wireframe; /* Triangles for object mode wireframe. */ + + /* Indices buffers. */ GPUIndexBuf *edges_in_order; GPUIndexBuf *edges_adjacency; /* Store edges with adjacent vertices. */ GPUIndexBuf *triangles_in_order; GPUIndexBuf *ledges_in_order; - GPUBatch *all_verts; GPUBatch *all_edges; GPUBatch *all_triangles; @@ -2049,8 +2079,6 @@ typedef struct MeshBatchCache { GPUBatch *edge_detection; - GPUVertBuf *edges_face_overlay_data; - GPUBatch *edges_face_overlay; /* Maybe have shaded_triangles_data split into pos_nor and uv_tangent * to minimize data transfer for skinned mesh. */ @@ -2406,7 +2434,7 @@ static void mesh_batch_cache_clear(Mesh *me) GPU_BATCH_DISCARD_SAFE(cache->all_edges); GPU_BATCH_DISCARD_SAFE(cache->all_triangles); - GPU_VERTBUF_DISCARD_SAFE(cache->pos_in_order); + GPU_VERTBUF_DISCARD_SAFE(cache->pos_and_nor); GPU_INDEXBUF_DISCARD_SAFE(cache->edges_in_order); GPU_INDEXBUF_DISCARD_SAFE(cache->triangles_in_order); GPU_INDEXBUF_DISCARD_SAFE(cache->ledges_in_order); @@ -2457,8 +2485,9 @@ static void mesh_batch_cache_clear(Mesh *me) GPU_INDEXBUF_DISCARD_SAFE(cache->edges_adjacency); GPU_BATCH_DISCARD_SAFE(cache->edge_detection); - GPU_VERTBUF_DISCARD_SAFE(cache->edges_face_overlay_data); - GPU_BATCH_DISCARD_SAFE(cache->edges_face_overlay); + GPU_VERTBUF_DISCARD_SAFE(cache->tess.wireframe_data); + GPU_VERTBUF_DISCARD_SAFE(cache->tess.pos_and_nor); + GPU_BATCH_DISCARD_SAFE(cache->face_wireframe); mesh_batch_cache_discard_shaded_tri(cache); @@ -2795,106 +2824,164 @@ static GPUVertBuf *mesh_batch_cache_get_tri_uv_active( return cache->tri_aligned_uv; } -static GPUVertBuf *mesh_batch_cache_get_tri_pos_and_normals_ex( - MeshRenderData *rdata, const bool use_hide, - GPUVertBuf **r_vbo) +static void mesh_create_pos_and_nor_tess(MeshRenderData *rdata, GPUVertBuf *vbo, bool use_hide) { - BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY)); + static GPUVertFormat format = { 0 }; + static struct { uint pos, nor; } attr_id; + if (format.attr_len == 0) { + attr_id.pos = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); + attr_id.nor = GPU_vertformat_attr_add(&format, "nor", GPU_COMP_I10, 3, GPU_FETCH_INT_TO_FLOAT_UNIT); + GPU_vertformat_triple_load(&format); + } - if (*r_vbo == NULL) { - static GPUVertFormat format = { 0 }; - static struct { uint pos, nor; } attr_id; - if (format.attr_len == 0) { - attr_id.pos = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); - attr_id.nor = GPU_vertformat_attr_add(&format, "nor", GPU_COMP_I10, 3, GPU_FETCH_INT_TO_FLOAT_UNIT); - GPU_vertformat_triple_load(&format); - } + GPU_vertbuf_init_with_format(vbo, &format); - const int tri_len = mesh_render_data_looptri_len_get_maybe_mapped(rdata); + const int tri_len = mesh_render_data_looptri_len_get_maybe_mapped(rdata); + const int vbo_len_capacity = tri_len * 3; + int vbo_len_used = 0; + GPU_vertbuf_data_alloc(vbo, vbo_len_capacity); - GPUVertBuf *vbo = *r_vbo = GPU_vertbuf_create_with_format(&format); + GPUVertBufRaw pos_step, nor_step; + GPU_vertbuf_attr_get_raw_data(vbo, attr_id.pos, &pos_step); + GPU_vertbuf_attr_get_raw_data(vbo, attr_id.nor, &nor_step); - const int vbo_len_capacity = tri_len * 3; - int vbo_len_used = 0; - GPU_vertbuf_data_alloc(vbo, vbo_len_capacity); + if (rdata->mapped.use == false) { + float (*lnors)[3] = rdata->loop_normals; + if (rdata->edit_bmesh) { + GPUPackedNormal *pnors_pack, *vnors_pack; - GPUVertBufRaw pos_step, nor_step; - GPU_vertbuf_attr_get_raw_data(vbo, attr_id.pos, &pos_step); - GPU_vertbuf_attr_get_raw_data(vbo, attr_id.nor, &nor_step); + if (lnors == NULL) { + mesh_render_data_ensure_poly_normals_pack(rdata); + mesh_render_data_ensure_vert_normals_pack(rdata); - if (rdata->mapped.use == false) { - float (*lnors)[3] = rdata->loop_normals; - if (rdata->edit_bmesh) { - GPUPackedNormal *pnors_pack, *vnors_pack; + pnors_pack = rdata->poly_normals_pack; + vnors_pack = rdata->vert_normals_pack; + } - if (lnors == NULL) { - mesh_render_data_ensure_poly_normals_pack(rdata); - mesh_render_data_ensure_vert_normals_pack(rdata); + for (int i = 0; i < tri_len; i++) { + const BMLoop **bm_looptri = (const BMLoop **)rdata->edit_bmesh->looptris[i]; + const BMFace *bm_face = bm_looptri[0]->f; - pnors_pack = rdata->poly_normals_pack; - vnors_pack = rdata->vert_normals_pack; + /* use_hide always for edit-mode */ + if (BM_elem_flag_test(bm_face, BM_ELEM_HIDDEN)) { + continue; } - for (int i = 0; i < tri_len; i++) { - const BMLoop **bm_looptri = (const BMLoop **)rdata->edit_bmesh->looptris[i]; - const BMFace *bm_face = bm_looptri[0]->f; - - /* use_hide always for edit-mode */ - if (BM_elem_flag_test(bm_face, BM_ELEM_HIDDEN)) { - continue; - } - - if (lnors) { - for (uint t = 0; t < 3; t++) { - const float *nor = lnors[BM_elem_index_get(bm_looptri[t])]; - *((GPUPackedNormal *)GPU_vertbuf_raw_step(&nor_step)) = GPU_normal_convert_i10_v3(nor); - } + if (lnors) { + for (uint t = 0; t < 3; t++) { + const float *nor = lnors[BM_elem_index_get(bm_looptri[t])]; + *((GPUPackedNormal *)GPU_vertbuf_raw_step(&nor_step)) = GPU_normal_convert_i10_v3(nor); } - else if (BM_elem_flag_test(bm_face, BM_ELEM_SMOOTH)) { - for (uint t = 0; t < 3; t++) { - *((GPUPackedNormal *)GPU_vertbuf_raw_step(&nor_step)) = vnors_pack[BM_elem_index_get(bm_looptri[t]->v)]; - } + } + else if (BM_elem_flag_test(bm_face, BM_ELEM_SMOOTH)) { + for (uint t = 0; t < 3; t++) { + *((GPUPackedNormal *)GPU_vertbuf_raw_step(&nor_step)) = vnors_pack[BM_elem_index_get(bm_looptri[t]->v)]; } - else { - const GPUPackedNormal *snor_pack = &pnors_pack[BM_elem_index_get(bm_face)]; - for (uint t = 0; t < 3; t++) { - *((GPUPackedNormal *)GPU_vertbuf_raw_step(&nor_step)) = *snor_pack; - } + } + else { + const GPUPackedNormal *snor_pack = &pnors_pack[BM_elem_index_get(bm_face)]; + for (uint t = 0; t < 3; t++) { + *((GPUPackedNormal *)GPU_vertbuf_raw_step(&nor_step)) = *snor_pack; } + } - /* TODO(sybren): deduplicate this and all the other places it's pasted to in this file. */ - if (rdata->edit_data && rdata->edit_data->vertexCos) { - for (uint t = 0; t < 3; t++) { - int vidx = BM_elem_index_get(bm_looptri[t]->v); - const float *pos = rdata->edit_data->vertexCos[vidx]; - copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), pos); - } + /* TODO(sybren): deduplicate this and all the other places it's pasted to in this file. */ + if (rdata->edit_data && rdata->edit_data->vertexCos) { + for (uint t = 0; t < 3; t++) { + int vidx = BM_elem_index_get(bm_looptri[t]->v); + const float *pos = rdata->edit_data->vertexCos[vidx]; + copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), pos); } - else { - for (uint t = 0; t < 3; t++) { - copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), bm_looptri[t]->v->co); - } + } + else { + for (uint t = 0; t < 3; t++) { + copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), bm_looptri[t]->v->co); } } } - else { - if (lnors == NULL) { - /* Use normals from vertex. */ - mesh_render_data_ensure_poly_normals_pack(rdata); + } + else { + if (lnors == NULL) { + /* Use normals from vertex. */ + mesh_render_data_ensure_poly_normals_pack(rdata); + } + + for (int i = 0; i < tri_len; i++) { + const MLoopTri *mlt = &rdata->mlooptri[i]; + const MPoly *mp = &rdata->mpoly[mlt->poly]; + + if (use_hide && (mp->flag & ME_HIDE)) { + continue; } - for (int i = 0; i < tri_len; i++) { - const MLoopTri *mlt = &rdata->mlooptri[i]; - const MPoly *mp = &rdata->mpoly[mlt->poly]; + const uint vtri[3] = { + rdata->mloop[mlt->tri[0]].v, + rdata->mloop[mlt->tri[1]].v, + rdata->mloop[mlt->tri[2]].v, + }; - if (use_hide && (mp->flag & ME_HIDE)) { - continue; + if (lnors) { + for (uint t = 0; t < 3; t++) { + const float *nor = lnors[mlt->tri[t]]; + *((GPUPackedNormal *)GPU_vertbuf_raw_step(&nor_step)) = GPU_normal_convert_i10_v3(nor); + } + } + else if (mp->flag & ME_SMOOTH) { + for (uint t = 0; t < 3; t++) { + const MVert *mv = &rdata->mvert[vtri[t]]; + *((GPUPackedNormal *)GPU_vertbuf_raw_step(&nor_step)) = GPU_normal_convert_i10_s3(mv->no); } + } + else { + const GPUPackedNormal *pnors_pack = &rdata->poly_normals_pack[mlt->poly]; + for (uint t = 0; t < 3; t++) { + *((GPUPackedNormal *)GPU_vertbuf_raw_step(&nor_ @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs