Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/overlay/overlay_sculpt_curves.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later | /* SPDX-License-Identifier: GPL-2.0-or-later | ||||
| * Copyright 2022 Blender Foundation. */ | * Copyright 2022 Blender Foundation. */ | ||||
| /** \file | /** \file | ||||
| * \ingroup draw_engine | * \ingroup draw_engine | ||||
| */ | */ | ||||
| #include "DRW_render.h" | #include "DRW_render.h" | ||||
| #include "draw_cache_impl.h" | #include "draw_cache_impl.h" | ||||
| #include "overlay_private.hh" | #include "overlay_private.hh" | ||||
| #include "BKE_attribute.hh" | |||||
| #include "BKE_curves.hh" | #include "BKE_curves.hh" | ||||
| void OVERLAY_sculpt_curves_cache_init(OVERLAY_Data *vedata) | void OVERLAY_sculpt_curves_cache_init(OVERLAY_Data *vedata) | ||||
| { | { | ||||
| OVERLAY_PassList *psl = vedata->psl; | OVERLAY_PassList *psl = vedata->psl; | ||||
| OVERLAY_PrivateData *pd = vedata->stl->pd; | OVERLAY_PrivateData *pd = vedata->stl->pd; | ||||
| const DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_BLEND_ALPHA; | const DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_BLEND_ALPHA; | ||||
| DRW_PASS_CREATE(psl->sculpt_curves_selection_ps, state | pd->clipping_state); | DRW_PASS_CREATE(psl->sculpt_curves_selection_ps, state | pd->clipping_state); | ||||
| GPUShader *sh = OVERLAY_shader_sculpt_curves_selection(); | GPUShader *sh = OVERLAY_shader_sculpt_curves_selection(); | ||||
| pd->sculpt_curves_selection_grp = DRW_shgroup_create(sh, psl->sculpt_curves_selection_ps); | pd->sculpt_curves_selection_grp = DRW_shgroup_create(sh, psl->sculpt_curves_selection_ps); | ||||
| DRWShadingGroup *grp = pd->sculpt_curves_selection_grp; | DRWShadingGroup *grp = pd->sculpt_curves_selection_grp; | ||||
| /* Reuse the same mask opacity from sculpt mode, since it wasn't worth it to add a different | /* Reuse the same mask opacity from sculpt mode, since it wasn't worth it to add a different | ||||
| * property yet. */ | * property yet. */ | ||||
| DRW_shgroup_uniform_float_copy(grp, "selection_opacity", pd->overlay.sculpt_mode_mask_opacity); | DRW_shgroup_uniform_float_copy(grp, "selection_opacity", pd->overlay.sculpt_mode_mask_opacity); | ||||
| } | } | ||||
| static bool everything_selected(const Curves &curves_id) | static bool everything_selected(const Curves &curves_id) | ||||
| { | { | ||||
| const blender::bke::CurvesGeometry &curves = blender::bke::CurvesGeometry::wrap( | using namespace blender; | ||||
| curves_id.geometry); | const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry); | ||||
JacquesLucke: Not sure we can or should rely on automatic domain interpolation here. Would be nice if it were… | |||||
Done Inline Actions(from chat conversation for reference) It's just nice to be able to read it on any domain as a regular attribute, since that simplifies a lot of code. HooglyBoogly: (from chat conversation for reference)
It's just nice to be able to read it on any domain as a… | |||||
| blender::VArray<float> selection; | const VArray<bool> selection = curves.attributes().lookup_or_default<bool>( | ||||
| switch (curves_id.selection_domain) { | ".selection", ATTR_DOMAIN_POINT, true); | ||||
| case ATTR_DOMAIN_POINT: | return selection.is_single() && selection.get_internal_single(); | ||||
| selection = curves.selection_point_float(); | |||||
| break; | |||||
| case ATTR_DOMAIN_CURVE: | |||||
| selection = curves.selection_curve_float(); | |||||
| break; | |||||
| } | |||||
| return selection.is_single() && selection.get_internal_single() == 1.0f; | |||||
| } | } | ||||
| void OVERLAY_sculpt_curves_cache_populate(OVERLAY_Data *vedata, Object *object) | void OVERLAY_sculpt_curves_cache_populate(OVERLAY_Data *vedata, Object *object) | ||||
| { | { | ||||
| OVERLAY_PrivateData *pd = vedata->stl->pd; | OVERLAY_PrivateData *pd = vedata->stl->pd; | ||||
| Curves *curves = static_cast<Curves *>(object->data); | Curves *curves = static_cast<Curves *>(object->data); | ||||
| /* As an optimization, return early if everything is selected. */ | /* As an optimization, return early if everything is selected. */ | ||||
| if (everything_selected(*curves)) { | if (everything_selected(*curves)) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* Retrieve the location of the texture. */ | /* Retrieve the location of the texture. */ | ||||
| const char *name = curves->selection_domain == ATTR_DOMAIN_POINT ? ".selection_point_float" : | |||||
| ".selection_curve_float"; | |||||
| bool is_point_domain; | bool is_point_domain; | ||||
| GPUVertBuf **texture = DRW_curves_texture_for_evaluated_attribute( | GPUVertBuf **texture = DRW_curves_texture_for_evaluated_attribute( | ||||
| curves, name, &is_point_domain); | curves, ".selection", &is_point_domain); | ||||
| if (texture == nullptr) { | if (texture == nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* Evaluate curves and their attributes if necessary. */ | /* Evaluate curves and their attributes if necessary. */ | ||||
| DRWShadingGroup *grp = DRW_shgroup_curves_create_sub( | DRWShadingGroup *grp = DRW_shgroup_curves_create_sub( | ||||
| object, pd->sculpt_curves_selection_grp, nullptr); | object, pd->sculpt_curves_selection_grp, nullptr); | ||||
| if (*texture == nullptr) { | if (*texture == nullptr) { | ||||
| Show All 20 Lines | |||||
Not sure we can or should rely on automatic domain interpolation here. Would be nice if it were explicit how float selections are converted to booleans.