[Bf-blender-cvs] [f7a81abe190] blender2.8: Edit Surface: Use edit curve engine to display edit surface
Clément Foucault
noreply at git.blender.org
Wed Sep 26 16:43:07 CEST 2018
Commit: f7a81abe190a3ed546831577a077507758200777
Author: Clément Foucault
Date: Wed Sep 26 16:40:09 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBf7a81abe190a3ed546831577a077507758200777
Edit Surface: Use edit curve engine to display edit surface
It's so similar in practice that we don't need a separate engine for edit
surface overlays.
===================================================================
M source/blender/draw/intern/draw_cache.c
M source/blender/draw/intern/draw_cache_impl_curve.c
M source/blender/draw/intern/draw_common.c
M source/blender/draw/intern/draw_common.h
M source/blender/draw/modes/draw_mode_engines.h
M source/blender/draw/modes/edit_curve_mode.c
M source/blender/draw/modes/shaders/common_globals_lib.glsl
M source/blender/draw/modes/shaders/edit_curve_overlay_handle_geom.glsl
M source/blender/draw/modes/shaders/edit_curve_overlay_loosevert_vert.glsl
===================================================================
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index 9e6e50bb516..6376855ed43 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -3116,7 +3116,7 @@ GPUBatch *DRW_cache_curve_edge_normal_get(Object *ob, float normal_size)
GPUBatch *DRW_cache_curve_edge_overlay_get(Object *ob)
{
- BLI_assert(ob->type == OB_CURVE);
+ BLI_assert(ELEM(ob->type, OB_CURVE, OB_SURF));
struct Curve *cu = ob->data;
return DRW_curve_batch_cache_get_overlay_edges(cu);
@@ -3124,7 +3124,7 @@ GPUBatch *DRW_cache_curve_edge_overlay_get(Object *ob)
GPUBatch *DRW_cache_curve_vert_overlay_get(Object *ob, bool handles)
{
- BLI_assert(ob->type == OB_CURVE);
+ BLI_assert(ELEM(ob->type, OB_CURVE, OB_SURF));
struct Curve *cu = ob->data;
return DRW_curve_batch_cache_get_overlay_verts(cu, handles);
diff --git a/source/blender/draw/intern/draw_cache_impl_curve.c b/source/blender/draw/intern/draw_cache_impl_curve.c
index 0f06f360b4a..4702319364c 100644
--- a/source/blender/draw/intern/draw_cache_impl_curve.c
+++ b/source/blender/draw/intern/draw_cache_impl_curve.c
@@ -46,6 +46,7 @@
#define SELECT 1
#define ACTIVE_NURB 1 << 2
+#define EVEN_U_BIT 1 << 3 /* Alternate this bit for every U vert. */
/* Used as values of `color_id` in `edit_curve_overlay_handle_geom.glsl` */
enum {
@@ -79,9 +80,10 @@ static void curve_render_overlay_verts_edges_len_get(
edge_len += 2 * nu->pntsu;
}
else if (nu->bp) {
- vert_len += nu->pntsu;
+ vert_len += nu->pntsu * nu->pntsv;
/* segments between points */
- edge_len += nu->pntsu - 1;
+ edge_len += (nu->pntsu - 1) * nu->pntsv;
+ edge_len += (nu->pntsv - 1) * nu->pntsu;
}
}
if (r_vert_len) {
@@ -169,9 +171,6 @@ typedef struct CurveRenderData {
EditFont *edit_font;
} text;
- bool hide_handles;
- bool hide_normals;
-
/* borrow from 'Object' */
CurveCache *ob_curve_cache;
@@ -206,10 +205,6 @@ static CurveRenderData *curve_render_data_create(Curve *cu, CurveCache *ob_curve
rdata->types = types;
ListBase *nurbs;
- /* TODO(fclem): hide them in the shader/draw engine */
- rdata->hide_handles = false;
- rdata->hide_normals = false;
-
rdata->actnu = cu->actnu;
rdata->actvert = cu->actvert;
@@ -537,14 +532,6 @@ static GPUIndexBuf *curve_batch_cache_get_wire_edges(CurveRenderData *rdata, Cur
}
}
}
-
- if (rdata->hide_handles) {
- BLI_assert(edge_len_used <= edge_len);
- }
- else {
- BLI_assert(edge_len_used == edge_len);
- }
-
cache->wire.elem = GPU_indexbuf_build(&elb);
}
@@ -680,7 +667,7 @@ static void curve_batch_cache_create_overlay_batches(Curve *cu)
vflag |= (is_active_nurb) ? ACTIVE_NURB : 0;
/* handle color id */
char col_id = (&bezt->h1)[j / 2];
- vflag |= col_id << 3; /* << 3 because of ACTIVE_NURB */
+ vflag |= col_id << 4; /* << 4 because of EVEN_U_BIT */
GPU_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used, bezt->vec[j]);
GPU_vertbuf_attr_set(vbo, attr_id.data, vbo_len_used, &vflag);
vbo_len_used += 1;
@@ -691,13 +678,15 @@ static void curve_batch_cache_create_overlay_batches(Curve *cu)
}
else if (nu->bp) {
int a = 0;
- for (const BPoint *bp = nu->bp; a < nu->pntsu; a++, bp++) {
+ int pt_len = nu->pntsu * nu->pntsv;
+ for (const BPoint *bp = nu->bp; a < pt_len; a++, bp++) {
if (bp->hide == false) {
const bool is_active = (i == rdata->actvert);
char vflag = (bp->f1 & SELECT) ? VFLAG_VERTEX_SELECTED : 0;
vflag |= (is_active) ? VFLAG_VERTEX_ACTIVE : 0;
vflag |= (is_active_nurb) ? ACTIVE_NURB : 0;
- vflag |= COLOR_NURB_ULINE_ID << 3; /* << 3 because of ACTIVE_NURB */
+ vflag |= (((a % nu->pntsu) % 2) == 0) ? EVEN_U_BIT : 0;
+ vflag |= COLOR_NURB_ULINE_ID << 4; /* << 4 because of EVEN_U_BIT */
GPU_indexbuf_add_point_vert(&elb, vbo_len_used);
GPU_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used, bp->vec);
GPU_vertbuf_attr_set(vbo, attr_id.data, vbo_len_used, &vflag);
@@ -718,7 +707,6 @@ static void curve_batch_cache_create_overlay_batches(Curve *cu)
cache->overlay.verts_no_handles = GPU_batch_create_ex(GPU_PRIM_POINTS, vbo, ibo, GPU_BATCH_OWNS_INDEX);
}
-
if (cache->overlay.edges == NULL) {
GPUVertBuf *vbo = cache->overlay.verts->verts[0];
@@ -742,15 +730,31 @@ static void curve_batch_cache_create_overlay_batches(Curve *cu)
}
}
else if (nu->bp) {
- curr_index += 1;
- int a = 1;
- for (const BPoint *bp_prev = nu->bp, *bp_curr = &nu->bp[1]; a < nu->pntsu; a++, bp_prev = bp_curr++) {
- if (bp_prev->hide == false) {
- if (bp_curr->hide == false) {
- GPU_indexbuf_add_line_verts(&elb, curr_index - 1, curr_index + 0);
+ int a = 0;
+ int next_v_index = curr_index;
+ for (const BPoint *bp = nu->bp; a < nu->pntsu; a++, bp++) {
+ if (bp->hide == false) {
+ next_v_index += 1;
+ }
+ }
+
+ int pt_len = nu->pntsu * nu->pntsv;
+ for (a = 0; a < pt_len; a++) {
+ const BPoint *bp_curr = &nu->bp[a];
+ const BPoint *bp_next_u = ((a % nu->pntsu) < (nu->pntsu - 1)) ? &nu->bp[a + 1] : NULL;
+ const BPoint *bp_next_v = (a < (pt_len - nu->pntsu)) ? &nu->bp[a + nu->pntsu] : NULL;
+ if (bp_curr->hide == false) {
+ if (bp_next_u && (bp_next_u->hide == false)) {
+ GPU_indexbuf_add_line_verts(&elb, curr_index, curr_index + 1);
+ }
+ if (bp_next_v && (bp_next_v->hide == false)) {
+ GPU_indexbuf_add_line_verts(&elb, curr_index, next_v_index);
}
curr_index += 1;
}
+ if (bp_next_v && (bp_next_v->hide == false)) {
+ next_v_index += 1;
+ }
}
}
}
diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c
index 876f4401927..eeaa204a252 100644
--- a/source/blender/draw/intern/draw_common.c
+++ b/source/blender/draw/intern/draw_common.c
@@ -99,7 +99,9 @@ void DRW_globals_update(void)
UI_GetThemeColor4fv(TH_HANDLE_SEL_ALIGN, ts.colorHandleSelAlign);
UI_GetThemeColor4fv(TH_HANDLE_SEL_AUTOCLAMP, ts.colorHandleSelAutoclamp);
UI_GetThemeColor4fv(TH_NURB_ULINE, ts.colorNurbUline);
+ UI_GetThemeColor4fv(TH_NURB_VLINE, ts.colorNurbVline);
UI_GetThemeColor4fv(TH_NURB_SEL_ULINE, ts.colorNurbSelUline);
+ UI_GetThemeColor4fv(TH_NURB_SEL_VLINE, ts.colorNurbSelVline);
UI_GetThemeColor4fv(TH_ACTIVE_SPLINE, ts.colorActiveSpline);
UI_GetThemeColor4fv(TH_BONE_POSE, ts.colorBonePose);
diff --git a/source/blender/draw/intern/draw_common.h b/source/blender/draw/intern/draw_common.h
index ceeefdd38a5..2640451a889 100644
--- a/source/blender/draw/intern/draw_common.h
+++ b/source/blender/draw/intern/draw_common.h
@@ -90,7 +90,9 @@ typedef struct GlobalsUboStorage {
float colorHandleSelAlign[4];
float colorHandleSelAutoclamp[4];
float colorNurbUline[4];
+ float colorNurbVline[4];
float colorNurbSelUline[4];
+ float colorNurbSelVline[4];
float colorActiveSpline[4];
float colorBonePose[4];
diff --git a/source/blender/draw/modes/draw_mode_engines.h b/source/blender/draw/modes/draw_mode_engines.h
index 8e8ddfef5a4..059724384ea 100644
--- a/source/blender/draw/modes/draw_mode_engines.h
+++ b/source/blender/draw/modes/draw_mode_engines.h
@@ -32,7 +32,6 @@ extern DrawEngineType draw_engine_edit_curve_type;
extern DrawEngineType draw_engine_edit_lattice_type;
extern DrawEngineType draw_engine_edit_mesh_type;
extern DrawEngineType draw_engine_edit_metaball_type;
-extern DrawEngineType draw_engine_edit_surface_type;
extern DrawEngineType draw_engine_edit_text_type;
extern DrawEngineType draw_engine_motion_path_type;
extern DrawEngineType draw_engine_paint_texture_type;
diff --git a/source/blender/draw/modes/edit_curve_mode.c b/source/blender/draw/modes/edit_curve_mode.c
index 9dc61619503..8f61c8db965 100644
--- a/source/blender/draw/modes/edit_curve_mode.c
+++ b/source/blender/draw/modes/edit_curve_mode.c
@@ -241,12 +241,7 @@ static void EDIT_CURVE_cache_populate(void *vedata, Object *ob)
UNUSED_VARS(psl, stl);
if (ob->type == OB_CURVE) {
-#if 0
- if (ob == draw_ctx->object_edit)
-#else
- if ((ob == draw_ctx->object_edit) || BKE_object_is_in_editmode(ob))
-#endif
- {
+ if (BKE_object_is_in_editmode(ob)) {
Curve *cu = ob->data;
/* Get geometry cache */
struct GPUBatch *geom;
@@ -268,16 +263,16 @@ static void EDIT_CURVE_cache_populate(void *vedata, Object *ob)
DRW_shgroup_call_add(stl->g_data->overlay_vert_shgrp, geom, ob->obmat);
}
}
-}
-/* Optional: Post-cache_populate callback */
-static void EDIT_CURVE_cache_finish(void *vedata)
-{
- EDIT_CURVE_PassList *psl = ((EDIT_CURVE_Data *)vedata)->psl;
- EDIT_CURVE_StorageList *stl = ((EDIT_CURVE_Data *)vedata)->stl;
+ if (ob->type == OB_SURF) {
+ if (BKE_object_is_in_editmode(ob)) {
+ struct GPUBatch *geom = DRW_cache_curve_edge_overlay_get(ob);
+ DRW_shgroup_call_add(stl->g_data->overlay_edge_shgrp, geom, ob->obmat);
- /* Do something here! dependent on the objects gathered */
- UNUSED_VARS(psl, stl);
+ geom = DRW_cache_curve_vert_overlay_get(ob, false);
+ DRW_shgroup_call_add(stl->g_data->overlay_vert_shgrp, geom, ob->obmat);
+ }
+ }
}
/* Draw time ! Control rendering pipeline from here */
@@ -325,7 +320,7 @@ DrawEngineType draw_engine_edit_curve_type = {
&EDIT_CURVE_engine_free,
&EDIT_CURVE_cache_init,
&EDIT_CURVE_cache_populate,
- &EDIT_CURVE_cache_finish,
+ NULL,
NULL, /* draw_background but not needed by mode engines */
&EDIT_CURVE_draw_scene,
NULL,
diff --git a/source/blender/draw/modes/shaders/common_globals_lib.glsl b/source/blender/draw/modes/shaders/common_globals_lib.glsl
index c0243838c65..bf761cd7c79 100644
--- a/source/blender/draw/modes/shaders/common_globals_lib.glsl
+++ b/source/blender/draw/modes/shaders/common_globals_lib.glsl
@@ -46,7 +46,9 @@ layout(std140) uniform globalsBlock {
vec4 colorHandleSelAlign;
vec4 colorHandleSelAutoclamp;
vec4 colorNurbUline;
+ vec4 colorNurbVline;
vec4 colorNurbSelUline;
+ vec4 colorNurbSelVline;
vec4 colorActiveSpline;
vec4 colorBonePose;
diff --git a/source/blender/draw/modes/shaders/edit_curve_overlay_handle_geom.glsl b/source/blender/draw/modes/shader
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list