Curves edit mode: show dots for points

This adds support to show dots for the curves points when in edit mode,
using a specific overlay.

This also adds `DRW_curves_batch_cache_create_requested` which for now
only creates the point buffer for the newly added `edit_points` batch.
In the future, this will also handle other edit mode overlays, and
probably also replace the current curves batch cache creation.

Maniphest Tasks: T95770

Differential Revision: https://developer.blender.org/D14262
This commit is contained in:
2022-04-08 18:23:40 +02:00
parent 3039b215ba
commit e15320568a
9 changed files with 161 additions and 4 deletions

View File

@@ -158,6 +158,7 @@ set(SRC
engines/overlay/overlay_armature.c
engines/overlay/overlay_background.c
engines/overlay/overlay_edit_curve.c
engines/overlay/overlay_edit_curves.cc
engines/overlay/overlay_edit_mesh.c
engines/overlay/overlay_edit_text.c
engines/overlay/overlay_edit_uv.c

View File

@@ -0,0 +1,92 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2022 Blender Foundation. */
/** \file
* \ingroup draw_engine
*/
#include "DRW_render.h"
#include "ED_view3d.h"
#include "draw_cache_impl.h"
#include "overlay_private.h"
void OVERLAY_edit_curves_init(OVERLAY_Data *vedata)
{
OVERLAY_PrivateData *pd = vedata->stl->pd;
const DRWContextState *draw_ctx = DRW_context_state_get();
pd->edit_curves.do_zbufclip = XRAY_FLAG_ENABLED(draw_ctx->v3d);
/* Create view with depth offset. */
DRWView *default_view = (DRWView *)DRW_view_default_get();
pd->view_edit_curves_points = default_view;
}
void OVERLAY_edit_curves_cache_init(OVERLAY_Data *vedata)
{
OVERLAY_TextureList *txl = vedata->txl;
OVERLAY_PassList *psl = vedata->psl;
OVERLAY_PrivateData *pd = vedata->stl->pd;
/* Desired masks (write to color and depth) and blend mode for rendering. */
DRWState state = (DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND_ALPHA |
DRW_STATE_WRITE_DEPTH);
/* Common boilerplate for shading groups. */
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
const DRWContextState *draw_ctx = DRW_context_state_get();
const View3D *v3d = draw_ctx->v3d;
GPUTexture **depth_tex = (pd->edit_curves.do_zbufclip) ? &dtxl->depth : &txl->dummy_depth_tx;
const float backwire_opacity = (pd->edit_curves.do_zbufclip) ? v3d->overlay.backwire_opacity :
1.0f;
/* Run Twice for in-front passes. */
for (int i = 0; i < 2; i++) {
DRW_PASS_CREATE(psl->edit_curves_points_ps[i], (state | pd->clipping_state));
GPUShader *sh = OVERLAY_shader_edit_curve_point();
DRWShadingGroup *grp = pd->edit_curves_points_grp[i] = DRW_shgroup_create(
sh, psl->edit_curves_points_ps[i]);
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
DRW_shgroup_uniform_float_copy(grp, "alpha", backwire_opacity);
DRW_shgroup_uniform_texture_ref(grp, "depthTex", depth_tex);
}
}
static void overlay_edit_curves_add_ob_to_pass(OVERLAY_PrivateData *pd, Object *ob, bool in_front)
{
Curves *curves = static_cast<Curves *>(ob->data);
DRWShadingGroup *point_shgrp = pd->edit_curves_points_grp[in_front];
struct GPUBatch *geom_points = DRW_curves_batch_cache_get_edit_points(curves);
DRW_shgroup_call_no_cull(point_shgrp, geom_points, ob);
}
void OVERLAY_edit_curves_cache_populate(OVERLAY_Data *vedata, Object *ob)
{
OVERLAY_PrivateData *pd = vedata->stl->pd;
if (pd->edit_curves.do_zbufclip) {
overlay_edit_curves_add_ob_to_pass(pd, ob, false);
}
else {
overlay_edit_curves_add_ob_to_pass(pd, ob, true);
}
}
void OVERLAY_edit_curves_draw(OVERLAY_Data *vedata)
{
OVERLAY_PassList *psl = vedata->psl;
OVERLAY_PrivateData *pd = vedata->stl->pd;
if (pd->edit_curves.do_zbufclip) {
DRW_view_set_active(pd->view_edit_curves_points);
DRW_draw_pass(psl->edit_curves_points_ps[NOT_IN_FRONT]);
}
else {
DRW_view_set_active(pd->view_edit_curves_points);
DRW_draw_pass(psl->edit_curves_points_ps[IN_FRONT]);
}
}

View File

@@ -111,6 +111,9 @@ static void OVERLAY_engine_init(void *vedata)
case CTX_MODE_EDIT_MESH:
OVERLAY_edit_mesh_init(vedata);
break;
case CTX_MODE_EDIT_CURVES:
OVERLAY_edit_curves_init(vedata);
break;
default:
/* Nothing to do. */
break;
@@ -182,9 +185,11 @@ static void OVERLAY_cache_init(void *vedata)
case CTX_MODE_WEIGHT_GPENCIL:
OVERLAY_edit_gpencil_cache_init(vedata);
break;
case CTX_MODE_EDIT_CURVES:
OVERLAY_edit_curves_cache_init(vedata);
break;
case CTX_MODE_SCULPT_CURVES:
case CTX_MODE_OBJECT:
case CTX_MODE_EDIT_CURVES:
break;
default:
BLI_assert_msg(0, "Draw mode invalid");
@@ -250,6 +255,7 @@ static bool overlay_object_is_edit_mode(const OVERLAY_PrivateData *pd, const Obj
case OB_FONT:
return pd->ctx_mode == CTX_MODE_EDIT_TEXT;
case OB_CURVES:
return pd->ctx_mode == CTX_MODE_EDIT_CURVES;
case OB_POINTCLOUD:
case OB_VOLUME:
/* No edit mode yet. */
@@ -389,6 +395,9 @@ static void OVERLAY_cache_populate(void *vedata, Object *ob)
case OB_FONT:
OVERLAY_edit_text_cache_populate(vedata, ob);
break;
case OB_CURVES:
OVERLAY_edit_curves_cache_populate(vedata, ob);
break;
}
}
else if (in_pose_mode && draw_bones) {
@@ -671,6 +680,9 @@ static void OVERLAY_draw_scene(void *vedata)
break;
case CTX_MODE_SCULPT_CURVES:
break;
case CTX_MODE_EDIT_CURVES:
OVERLAY_edit_curves_draw(vedata);
break;
default:
break;
}

View File

@@ -72,6 +72,7 @@ typedef struct OVERLAY_PassList {
DRWPass *edit_mesh_edges_ps[2];
DRWPass *edit_mesh_faces_ps[2];
DRWPass *edit_mesh_faces_cage_ps[2];
DRWPass *edit_curves_points_ps[2];
DRWPass *edit_mesh_analysis_ps;
DRWPass *edit_mesh_normals_ps;
DRWPass *edit_particle_ps;
@@ -266,6 +267,7 @@ typedef struct OVERLAY_PrivateData {
DRWShadingGroup *edit_uv_faces_grp;
DRWShadingGroup *edit_uv_face_dots_grp;
DRWShadingGroup *edit_uv_stretching_grp;
DRWShadingGroup *edit_curves_points_grp[2];
DRWShadingGroup *extra_grid_grp;
DRWShadingGroup *facing_grp[2];
DRWShadingGroup *fade_grp[2];
@@ -299,6 +301,7 @@ typedef struct OVERLAY_PrivateData {
DRWView *view_edit_verts;
DRWView *view_edit_text;
DRWView *view_reference_images;
DRWView *view_edit_curves_points;
/** TODO: get rid of this. */
ListBase smoke_domains;
@@ -346,6 +349,9 @@ typedef struct OVERLAY_PrivateData {
bool select_edge;
int flag; /** Copy of #v3d->overlay.edit_flag. */
} edit_mesh;
struct {
bool do_zbufclip;
} edit_curves;
struct {
bool use_weight;
int select_mode;
@@ -669,6 +675,11 @@ void OVERLAY_wireframe_cache_populate(OVERLAY_Data *vedata,
void OVERLAY_wireframe_draw(OVERLAY_Data *vedata);
void OVERLAY_wireframe_in_front_draw(OVERLAY_Data *vedata);
void OVERLAY_edit_curves_init(OVERLAY_Data *vedata);
void OVERLAY_edit_curves_cache_init(OVERLAY_Data *vedata);
void OVERLAY_edit_curves_cache_populate(OVERLAY_Data *vedata, Object *ob);
void OVERLAY_edit_curves_draw(OVERLAY_Data *vedata);
void OVERLAY_shader_library_ensure(void);
GPUShader *OVERLAY_shader_antialiasing(void);
GPUShader *OVERLAY_shader_armature_degrees_of_freedom_wire(void);

View File

@@ -367,6 +367,8 @@ typedef enum {
DRW_STATE_PROGRAM_POINT_SIZE = (1u << 31),
} DRWState;
ENUM_OPERATORS(DRWState, DRW_STATE_PROGRAM_POINT_SIZE);
#define DRW_STATE_DEFAULT \
(DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL)
#define DRW_STATE_BLEND_ENABLED \

View File

@@ -3348,6 +3348,9 @@ void drw_batch_cache_generate_requested(Object *ob)
case OB_SURF:
DRW_curve_batch_cache_create_requested(ob, scene);
break;
case OB_CURVES:
DRW_curves_batch_cache_create_requested(ob);
break;
/* TODO: all cases. */
default:
break;

View File

@@ -351,6 +351,16 @@ struct GPUBatch *DRW_particles_batch_cache_get_edit_tip_points(struct Object *ob
/** \} */
/* -------------------------------------------------------------------- */
/** \name Curves
* \{ */
struct GPUBatch *DRW_curves_batch_cache_get_edit_points(struct Curves *curves);
void DRW_curves_batch_cache_create_requested(const struct Object *ob);
/** \} */
#ifdef __cplusplus
}
#endif

View File

@@ -21,6 +21,7 @@
#include "DNA_curves_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "BKE_curves.hh"
@@ -28,7 +29,8 @@
#include "GPU_material.h"
#include "GPU_texture.h"
#include "draw_cache_impl.h" /* own include */
#include "draw_cache_impl.h" /* own include */
#include "draw_cache_inline.h"
#include "draw_hair_private.h" /* own include */
using blender::float3;
@@ -41,6 +43,8 @@ using blender::Span;
struct CurvesBatchCache {
ParticleHairCache hair;
GPUBatch *edit_points;
/* To determine if cache is invalid. */
bool is_dirty;
};
@@ -74,6 +78,7 @@ static void curves_batch_cache_clear(Curves &curves)
}
particle_batch_cache_clear_hair(&cache->hair);
GPU_BATCH_DISCARD_SAFE(cache->edit_points);
}
void DRW_curves_batch_cache_validate(Curves *curves)
@@ -167,10 +172,11 @@ static void curves_batch_cache_ensure_procedural_pos(Curves &curves,
ParticleHairCache &cache,
GPUMaterial *gpu_material)
{
if (cache.proc_point_buf == nullptr) {
if (cache.proc_point_buf == nullptr || DRW_vbo_requested(cache.proc_point_buf)) {
/* Initialize vertex format. */
GPUVertFormat format = {0};
uint pos_id = GPU_vertformat_attr_add(&format, "posTime", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
GPU_vertformat_alias_add(&format, "pos");
cache.proc_point_buf = GPU_vertbuf_create_with_format(&format);
GPU_vertbuf_data_alloc(cache.proc_point_buf, cache.point_len);
@@ -366,3 +372,23 @@ int DRW_curves_material_count_get(Curves *curves)
{
return max_ii(1, curves->totcol);
}
GPUBatch *DRW_curves_batch_cache_get_edit_points(Curves *curves)
{
CurvesBatchCache &cache = curves_batch_cache_get(*curves);
return DRW_batch_request(&cache.edit_points);
}
void DRW_curves_batch_cache_create_requested(const Object *ob)
{
Curves *curves = static_cast<Curves *>(ob->data);
CurvesBatchCache &cache = curves_batch_cache_get(*curves);
if (DRW_batch_requested(cache.edit_points, GPU_PRIM_POINTS)) {
DRW_vbo_request(cache.edit_points, &cache.hair.proc_point_buf);
}
if (DRW_vbo_requested(cache.hair.proc_point_buf)) {
curves_batch_cache_ensure_procedural_pos(*curves, cache.hair, nullptr);
}
}

View File

@@ -197,7 +197,7 @@ bool DRW_object_is_renderable(const Object *ob)
bool DRW_object_is_in_edit_mode(const Object *ob)
{
if (BKE_object_is_in_editmode(ob)) {
if (ob->type == OB_MESH) {
if (ELEM(ob->type, OB_MESH, OB_CURVES)) {
if ((ob->mode & OB_MODE_EDIT) == 0) {
return false;
}