diff options
Diffstat (limited to 'source/blender/draw/engines/workbench/workbench_engine.c')
-rw-r--r-- | source/blender/draw/engines/workbench/workbench_engine.c | 72 |
1 files changed, 55 insertions, 17 deletions
diff --git a/source/blender/draw/engines/workbench/workbench_engine.c b/source/blender/draw/engines/workbench/workbench_engine.c index 828a9127fb1..53119723fab 100644 --- a/source/blender/draw/engines/workbench/workbench_engine.c +++ b/source/blender/draw/engines/workbench/workbench_engine.c @@ -130,6 +130,17 @@ static void workbench_cache_sculpt_populate(WORKBENCH_PrivateData *wpd, } } +BLI_INLINE void workbench_object_drawcall(DRWShadingGroup *grp, struct GPUBatch *geom, Object *ob) +{ + if (ob->type == OB_POINTCLOUD) { + /* Draw range to avoid drawcall batching messing up the instance attrib. */ + DRW_shgroup_call_instance_range(grp, ob, geom, 0, 0); + } + else { + DRW_shgroup_call(grp, geom, ob); + } +} + static void workbench_cache_texpaint_populate(WORKBENCH_PrivateData *wpd, Object *ob) { const DRWContextState *draw_ctx = DRW_context_state_get(); @@ -145,7 +156,7 @@ static void workbench_cache_texpaint_populate(WORKBENCH_PrivateData *wpd, Object SET_FLAG_FROM_TEST(state, imapaint->interp == IMAGEPAINT_INTERP_LINEAR, GPU_SAMPLER_FILTER); DRWShadingGroup *grp = workbench_image_setup(wpd, ob, 0, ima, NULL, state); - DRW_shgroup_call(grp, geom, ob); + workbench_object_drawcall(grp, geom, ob); } } else { @@ -157,7 +168,7 @@ static void workbench_cache_texpaint_populate(WORKBENCH_PrivateData *wpd, Object continue; } DRWShadingGroup *grp = workbench_image_setup(wpd, ob, i + 1, NULL, NULL, 0); - DRW_shgroup_call(grp, geoms[i], ob); + workbench_object_drawcall(grp, geoms[i], ob); } } } @@ -174,11 +185,27 @@ static void workbench_cache_common_populate(WORKBENCH_PrivateData *wpd, color_type, V3D_SHADING_MATERIAL_COLOR, V3D_SHADING_TEXTURE_COLOR); if (use_single_drawcall) { - struct GPUBatch *geom = (use_vcol) ? DRW_cache_mesh_surface_vertpaint_get(ob) : - DRW_cache_object_surface_get(ob); + struct GPUBatch *geom; + if (use_vcol) { + if (ob->mode & OB_MODE_VERTEX_PAINT) { + geom = DRW_cache_mesh_surface_vertpaint_get(ob); + } + else { + if (U.experimental.use_sculpt_vertex_colors) { + geom = DRW_cache_mesh_surface_sculptcolors_get(ob); + } + else { + geom = DRW_cache_mesh_surface_vertpaint_get(ob); + } + } + } + else { + geom = DRW_cache_object_surface_get(ob); + } + if (geom) { DRWShadingGroup *grp = workbench_material_setup(wpd, ob, 0, color_type, r_transp); - DRW_shgroup_call(grp, geom, ob); + workbench_object_drawcall(grp, geom, ob); } } else { @@ -191,7 +218,7 @@ static void workbench_cache_common_populate(WORKBENCH_PrivateData *wpd, continue; } DRWShadingGroup *grp = workbench_material_setup(wpd, ob, i + 1, color_type, r_transp); - DRW_shgroup_call(grp, geoms[i], ob); + workbench_object_drawcall(grp, geoms[i], ob); } } } @@ -240,15 +267,26 @@ static eV3DShadingColorType workbench_color_type_get(WORKBENCH_PrivateData *wpd, const bool is_texpaint_mode = is_active && (wpd->ctx_mode == CTX_MODE_PAINT_TEXTURE); const bool is_vertpaint_mode = is_active && (wpd->ctx_mode == CTX_MODE_PAINT_VERTEX); - if ((color_type == V3D_SHADING_TEXTURE_COLOR) && (ob->dt < OB_TEXTURE)) { - color_type = V3D_SHADING_MATERIAL_COLOR; - } - /* Disable color mode if data layer is unavailable. */ - if ((color_type == V3D_SHADING_TEXTURE_COLOR) && (me == NULL || me->mloopuv == NULL)) { - color_type = V3D_SHADING_MATERIAL_COLOR; + if (color_type == V3D_SHADING_TEXTURE_COLOR) { + if (ob->dt < OB_TEXTURE) { + color_type = V3D_SHADING_MATERIAL_COLOR; + } + else if ((me == NULL) || (me->mloopuv == NULL)) { + /* Disable color mode if data layer is unavailable. */ + color_type = V3D_SHADING_MATERIAL_COLOR; + } } - if ((color_type == V3D_SHADING_VERTEX_COLOR) && (me == NULL || me->mloopcol == NULL)) { - color_type = V3D_SHADING_OBJECT_COLOR; + else if (color_type == V3D_SHADING_VERTEX_COLOR) { + if (U.experimental.use_sculpt_vertex_colors) { + if ((me == NULL) || !CustomData_has_layer(&me->vdata, CD_PROP_COLOR)) { + color_type = V3D_SHADING_OBJECT_COLOR; + } + } + else { + if ((me == NULL) || !CustomData_has_layer(&me->ldata, CD_MLOOPCOL)) { + color_type = V3D_SHADING_OBJECT_COLOR; + } + } } if (r_sculpt_pbvh) { @@ -379,7 +417,7 @@ void workbench_cache_finish(void *ved) /* TODO(fclem) Only do this when really needed. */ { - /* HACK we allocate the infront depth here to avoid the overhead when if is not needed. */ + /* HACK we allocate the in front depth here to avoid the overhead when if is not needed. */ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); @@ -423,7 +461,7 @@ void workbench_cache_finish(void *ved) /* TODO don't free reuse next redraw. */ for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { - for (int k = 0; k < 2; k++) { + for (int k = 0; k < WORKBENCH_DATATYPE_MAX; k++) { if (wpd->prepass[i][j][k].material_hash) { BLI_ghash_free(wpd->prepass[i][j][k].material_hash, NULL, NULL); wpd->prepass[i][j][k].material_hash = NULL; @@ -603,7 +641,7 @@ RenderEngineType DRW_engine_viewport_workbench_type = { NULL, WORKBENCH_ENGINE, N_("Workbench"), - RE_INTERNAL | RE_USE_STEREO_VIEWPORT, + RE_INTERNAL | RE_USE_STEREO_VIEWPORT | RE_USE_GPU_CONTEXT, NULL, &DRW_render_to_image, NULL, |