diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2019-07-08 15:18:08 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2019-07-08 15:18:08 +0300 |
commit | 70e84a2c20c3be11482a7c30007b51a679edad6c (patch) | |
tree | 7f0e078667e0afb6054318123a214faa1a28f1d5 /source/blender/draw/intern | |
parent | 084a33ca94c09f6c5e6650ee4f3c176b324e6607 (diff) | |
parent | 4ca054617ba1552eb06d46f32b5c007632b0dd11 (diff) |
Merge branch 'master' into soc-2019-openxr
Diffstat (limited to 'source/blender/draw/intern')
-rw-r--r-- | source/blender/draw/intern/draw_cache.c | 2 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_curve.c | 3 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_mesh.c | 98 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 23 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_shader.c | 17 |
5 files changed, 119 insertions, 24 deletions
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c index 88125e884d5..ed099bae2eb 100644 --- a/source/blender/draw/intern/draw_cache.c +++ b/source/blender/draw/intern/draw_cache.c @@ -3016,7 +3016,7 @@ GPUBatch *DRW_cache_bone_dof_sphere_get(void) pz = z; } } - /* TODO alloc right count from the begining. */ + /* TODO allocate right count from the beginning. */ GPU_vertbuf_data_resize(vbo, v); SHC.drw_bone_dof_sphere = GPU_batch_create_ex(GPU_PRIM_TRIS, vbo, NULL, GPU_BATCH_OWNS_VBO); diff --git a/source/blender/draw/intern/draw_cache_impl_curve.c b/source/blender/draw/intern/draw_cache_impl_curve.c index 1d6f2aaa070..75c498dfd88 100644 --- a/source/blender/draw/intern/draw_cache_impl_curve.c +++ b/source/blender/draw/intern/draw_cache_impl_curve.c @@ -791,7 +791,7 @@ static void curve_create_edit_data_and_handles(CurveRenderData *rdata, } else if (bp) { int pt_len = nu->pntsu * nu->pntsv; - for (int a = 0; a < pt_len; a++, bp++) { + for (int a = 0; a < pt_len; a++, bp++, vbo_len_used += 1) { if (bp->hide == true) { continue; } @@ -819,7 +819,6 @@ static void curve_create_edit_data_and_handles(CurveRenderData *rdata, if (vbo_pos) { GPU_vertbuf_attr_set(vbo_pos, attr_id.pos, vbo_len_used, bp->vec); } - vbo_len_used += 1; } } } diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c index f4acb586c5e..1ebdab19375 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.c +++ b/source/blender/draw/intern/draw_cache_impl_mesh.c @@ -25,6 +25,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_bitmap.h" #include "BLI_buffer.h" #include "BLI_utildefines.h" #include "BLI_math_vector.h" @@ -1985,6 +1986,7 @@ typedef struct MeshBatchCache { /* Indices to vloops. */ GPUIndexBuf *loops_tris; GPUIndexBuf *loops_lines; + GPUIndexBuf *loops_lines_paint_mask; GPUIndexBuf *loops_line_strips; /* Edit mode. */ GPUIndexBuf *edit_loops_points; /* verts */ @@ -2025,7 +2027,7 @@ typedef struct MeshBatchCache { GPUBatch *loose_edges; GPUBatch *edge_detection; GPUBatch *wire_edges; /* Individual edges with face normals. */ - GPUBatch *wire_loops; /* Loops around faces. */ + GPUBatch *wire_loops; /* Loops around faces. no edges between selected faces */ GPUBatch *wire_loops_uvs; /* Same as wire_loops but only has uvs. */ } batch; @@ -2227,6 +2229,7 @@ void DRW_mesh_batch_cache_dirty_tag(Mesh *me, int mode) case BKE_MESH_BATCH_DIRTY_SELECT_PAINT: /* Paint mode selection flag is packed inside the nor attrib. * Note that it can be slow if auto smooth is enabled. (see T63946) */ + GPU_INDEXBUF_DISCARD_SAFE(cache->ibo.loops_lines_paint_mask); GPU_VERTBUF_DISCARD_SAFE(cache->ordered.loop_pos_nor); GPU_BATCH_DISCARD_SAFE(cache->batch.surface); GPU_BATCH_DISCARD_SAFE(cache->batch.wire_loops); @@ -3788,10 +3791,89 @@ static void mesh_create_loops_lines(MeshRenderData *rdata, GPUIndexBuf *ibo, con } } } - else { - /* Implement ... eventually if needed. */ + + GPU_indexbuf_build_in_place(&elb, ibo); +} + +static void mesh_create_loops_lines_paint_mask(MeshRenderData *rdata, GPUIndexBuf *ibo) +{ + const int loop_len = mesh_render_data_loops_len_get(rdata); + const int poly_len = mesh_render_data_polys_len_get(rdata); + const int edge_len = mesh_render_data_edges_len_get(rdata); + + GPUIndexBufBuilder elb; + GPU_indexbuf_init(&elb, GPU_PRIM_LINES, loop_len, loop_len); + + if (rdata->edit_bmesh) { + /* painting does not use the edit_bmesh */ BLI_assert(0); } + else { + if (rdata->me->editflag & ME_EDIT_PAINT_FACE_SEL) { + /* Each edge has two bits used to count selected edges as 0, 1, 2+. */ + BLI_bitmap *edges_used = BLI_BITMAP_NEW(edge_len * 2, __func__); + + /* Fill the edge bitmap table. */ + for (int poly = 0; poly < poly_len; poly++) { + const MPoly *mpoly = &rdata->mpoly[poly]; + + /* Do not check faces that are hidden and faces that aren't selected */ + if (mpoly->flag & ME_HIDE || ((mpoly->flag & ME_FACE_SEL) == 0)) { + continue; + } + + for (int loop_index = mpoly->loopstart, loop_index_end = mpoly->loopstart + mpoly->totloop; + loop_index < loop_index_end; + loop_index++) { + const MLoop *mloop = &rdata->mloop[loop_index]; + const int e_a = mloop->e * 2; + const int e_b = e_a + 1; + if (!BLI_BITMAP_TEST(edges_used, e_a)) { + BLI_BITMAP_ENABLE(edges_used, e_a); + } + else { + BLI_BITMAP_ENABLE(edges_used, e_b); + } + } + } + + for (int poly = 0; poly < poly_len; poly++) { + const MPoly *mpoly = &rdata->mpoly[poly]; + if (!(mpoly->flag & ME_HIDE)) { + + for (int loop_index_next = mpoly->loopstart, + loop_index_end = mpoly->loopstart + mpoly->totloop, + loop_index_curr = loop_index_end - 1; + loop_index_next < loop_index_end; + loop_index_curr = loop_index_next++) { + const MLoop *mloop = &rdata->mloop[loop_index_curr]; + const int e_a = mloop->e * 2; + const int e_b = e_a + 1; + + /* Draw if a boundary or entirely unselected. */ + if (!BLI_BITMAP_TEST(edges_used, e_b)) { + GPU_indexbuf_add_line_verts(&elb, loop_index_curr, loop_index_next); + } + } + } + } + + MEM_freeN(edges_used); + } + else { + /* Add edges. */ + for (int poly = 0; poly < poly_len; poly++) { + const MPoly *mpoly = &rdata->mpoly[poly]; + for (int loop_index_next = mpoly->loopstart, + loop_index_end = mpoly->loopstart + mpoly->totloop, + loop_index_curr = loop_index_end - 1; + loop_index_next < loop_index_end; + loop_index_curr = loop_index_next++) { + GPU_indexbuf_add_line_verts(&elb, loop_index_curr, loop_index_next); + } + } + } + } GPU_indexbuf_build_in_place(&elb, ibo); } @@ -5053,8 +5135,8 @@ void DRW_mesh_batch_cache_create_requested( DRW_vbo_request(cache->batch.surface_weights, &cache->ordered.pos_nor); DRW_vbo_request(cache->batch.surface_weights, &cache->ordered.weights); } - if (DRW_batch_requested(cache->batch.wire_loops, GPU_PRIM_LINE_STRIP)) { - DRW_ibo_request(cache->batch.wire_loops, &cache->ibo.loops_line_strips); + if (DRW_batch_requested(cache->batch.wire_loops, GPU_PRIM_LINES)) { + DRW_ibo_request(cache->batch.wire_loops, &cache->ibo.loops_lines_paint_mask); DRW_vbo_request(cache->batch.wire_loops, &cache->ordered.loop_pos_nor); } if (DRW_batch_requested(cache->batch.wire_edges, GPU_PRIM_LINES)) { @@ -5207,6 +5289,9 @@ void DRW_mesh_batch_cache_create_requested( mr_flag, cache->ibo.loops_tris, MR_DATATYPE_LOOP | MR_DATATYPE_POLY | MR_DATATYPE_LOOPTRI); DRW_ADD_FLAG_FROM_IBO_REQUEST( mr_flag, cache->ibo.loops_lines, MR_DATATYPE_LOOP | MR_DATATYPE_EDGE | MR_DATATYPE_POLY); + DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_flag, + cache->ibo.loops_lines_paint_mask, + MR_DATATYPE_LOOP | MR_DATATYPE_EDGE | MR_DATATYPE_POLY); DRW_ADD_FLAG_FROM_IBO_REQUEST( mr_flag, cache->ibo.loops_line_strips, MR_DATATYPE_LOOP | MR_DATATYPE_POLY); DRW_ADD_FLAG_FROM_IBO_REQUEST( @@ -5323,6 +5408,9 @@ void DRW_mesh_batch_cache_create_requested( if (DRW_ibo_requested(cache->ibo.loops_lines)) { mesh_create_loops_lines(rdata, cache->ibo.loops_lines, use_hide); } + if (DRW_ibo_requested(cache->ibo.loops_lines_paint_mask)) { + mesh_create_loops_lines_paint_mask(rdata, cache->ibo.loops_lines_paint_mask); + } if (DRW_ibo_requested(cache->ibo.loops_line_strips)) { mesh_create_loops_line_strips(rdata, cache->ibo.loops_line_strips, use_hide); } diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index d608593add2..47b0a21988a 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -88,6 +88,7 @@ #include "engines/basic/basic_engine.h" #include "engines/workbench/workbench_engine.h" #include "engines/external/external_engine.h" +#include "engines/gpencil/gpencil_engine.h" #include "GPU_context.h" @@ -1916,6 +1917,13 @@ void DRW_render_gpencil(struct RenderEngine *engine, struct Depsgraph *depsgraph DST.buffer_finish_called = false; } +static void drw_view_reset(void) +{ + DST.view_default = NULL; + DST.view_active = NULL; + DST.view_previous = NULL; +} + void DRW_render_to_image(RenderEngine *engine, struct Depsgraph *depsgraph) { Scene *scene = DEG_get_evaluated_scene(depsgraph); @@ -1998,14 +2006,12 @@ void DRW_render_to_image(RenderEngine *engine, struct Depsgraph *depsgraph) for (RenderView *render_view = render_result->views.first; render_view != NULL; render_view = render_view->next) { RE_SetActiveRenderView(render, render_view->name); - /* Reset the view. */ - DST.view_default = NULL; - DST.view_active = NULL; - DST.view_previous = NULL; + drw_view_reset(); engine_type->draw_engine->render_to_image(data, engine, render_layer, &render_rect); /* grease pencil: render result is merged in the previous render result. */ if (DRW_render_check_grease_pencil(depsgraph)) { DRW_state_reset(); + drw_view_reset(); DRW_render_gpencil_to_image(engine, render_layer, &render_rect); } DST.buffer_finish_called = false; @@ -2374,6 +2380,13 @@ void DRW_draw_select_loop(struct Depsgraph *depsgraph, } } + /* TODO: GPXX Workaround for grease pencil selection while draw manager support a callback from + * scene finish */ + void *data = GPU_viewport_engine_data_get(DST.viewport, &draw_engine_gpencil_type); + if (data != NULL) { + DRW_gpencil_free_runtime_data(data); + } + DRW_state_lock(0); DRW_draw_callbacks_post_scene(); @@ -2590,6 +2603,8 @@ void DRW_draw_depth_object(ARegion *ar, GPUViewport *viewport, Object *object) world_clip_planes = rv3d->clip_local; } + drw_batch_cache_validate(object); + switch (object->type) { case OB_MESH: { GPUBatch *batch; diff --git a/source/blender/draw/intern/draw_manager_shader.c b/source/blender/draw/intern/draw_manager_shader.c index 5c3b5aa8a8e..d0aa6d55c03 100644 --- a/source/blender/draw/intern/draw_manager_shader.c +++ b/source/blender/draw/intern/draw_manager_shader.c @@ -202,12 +202,8 @@ static void drw_deferred_shader_add(GPUMaterial *mat, bool deferred) /* Get the running job or a new one if none is running. Can only have one job per type & owner. */ - wmJob *wm_job = WM_jobs_get(wm, - win, - scene, - "Shaders Compilation", - WM_JOB_PROGRESS | WM_JOB_SUSPEND, - WM_JOB_TYPE_SHADER_COMPILATION); + wmJob *wm_job = WM_jobs_get( + wm, win, scene, "Shaders Compilation", WM_JOB_PROGRESS, WM_JOB_TYPE_SHADER_COMPILATION); DRWShaderCompiler *old_comp = (DRWShaderCompiler *)WM_jobs_customdata_get(wm_job); @@ -238,6 +234,7 @@ static void drw_deferred_shader_add(GPUMaterial *mat, bool deferred) WM_jobs_customdata_set(wm_job, comp, drw_deferred_shader_compilation_free); WM_jobs_timer(wm_job, 0.1, NC_MATERIAL | ND_SHADING_DRAW, 0); + WM_jobs_delay_start(wm_job, 0.1); WM_jobs_callbacks(wm_job, drw_deferred_shader_compilation_exec, NULL, NULL, NULL); WM_jobs_start(wm, wm_job); } @@ -252,12 +249,8 @@ void DRW_deferred_shader_remove(GPUMaterial *mat) continue; } for (wmWindow *win = wm->windows.first; win; win = win->next) { - wmJob *wm_job = WM_jobs_get(wm, - win, - scene, - "Shaders Compilation", - WM_JOB_PROGRESS | WM_JOB_SUSPEND, - WM_JOB_TYPE_SHADER_COMPILATION); + wmJob *wm_job = WM_jobs_get( + wm, win, scene, "Shaders Compilation", WM_JOB_PROGRESS, WM_JOB_TYPE_SHADER_COMPILATION); DRWShaderCompiler *comp = (DRWShaderCompiler *)WM_jobs_customdata_get(wm_job); if (comp != NULL) { |