[Bf-blender-cvs] [ac7618d0dc7] greasepencil-object: GP: Primitives: tidy up control point code
Charlie Jolly
noreply at git.blender.org
Mon Dec 10 17:23:26 CET 2018
Commit: ac7618d0dc75147a542bf910077e4a895fe8e2ef
Author: Charlie Jolly
Date: Mon Dec 10 16:23:03 2018 +0000
Branches: greasepencil-object
https://developer.blender.org/rBac7618d0dc75147a542bf910077e4a895fe8e2ef
GP: Primitives: tidy up control point code
The display of control points is temporary as this is still wip.
===================================================================
M source/blender/editors/gpencil/drawgpencil.c
M source/blender/editors/gpencil/gpencil_primitive.c
M source/blender/editors/include/ED_gpencil.h
===================================================================
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index be664888719..8bcb8a2b4dd 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -1430,21 +1430,34 @@ void ED_gp_draw_interpolation(const bContext *C, tGPDinterpolate *tgpi, const in
glDisable(GL_BLEND);
}
-static void gp_primitive_draw_point(const tGPcontrolpoint *cp)
+/* draw points, this is temporary code */
+static void gp_primitive_draw_point(const tGPDprimitive *tgpi)
{
GPUVertFormat *format = immVertexFormat();
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- float color[4];
- UI_GetThemeColor3fv(cp->color, color);
- color[3] = 0.6f;
- /* if drawing a single point, draw it larger */
- GPU_point_size((float)cp->size);
- immBindBuiltinProgram(GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA);
- immUniformColor4fv(color);
- immBegin(GPU_PRIM_POINTS, 1);
- immVertex3fv(pos, &cp->x);
+ uint size = GPU_vertformat_attr_add(format, "size", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
+ uint color = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
+
+ //glEnable(GL_BLEND);
+ immBindBuiltinProgram(GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR);
+ GPU_enable_program_point_size();
+ immBegin(GPU_PRIM_POINTS, tgpi->tot_cp_points);
+
+ tGPcontrolpoint *cps = tgpi->cp_points;
+ for (int i = 0; i < tgpi->tot_cp_points; i++) {
+ tGPcontrolpoint *cp = &cps[i];
+ float ink[4];
+ UI_GetThemeColor4fv(cp->color, ink);
+ ink[3] = 0.5f;
+ immAttr4fv(color, ink);
+ immAttr1f(size, (float)cp->size);
+ immVertex3fv(pos, &cp->x);
+ }
+
immEnd();
immUnbindProgram();
+ GPU_disable_program_point_size();
+ //glDisable(GL_BLEND);
}
/* draw interpolate strokes (used only while operator is running) */
@@ -1504,12 +1517,7 @@ void ED_gp_draw_primitives(const bContext *C, tGPDprimitive *tgpi, const int typ
/* draw cps, this is temporary code */
if (tgpi->draw_cp_points) {
- tGPcontrolpoint *cps = tgpi->cp_points;
- for (int i = 0; i < tgpi->tot_cp_points; i++) {
- tGPcontrolpoint *cp = &cps[i];
- if (cp->display)
- gp_primitive_draw_point(cp);
- }
+ gp_primitive_draw_point(tgpi);
}
GPU_blend(false);
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index c3f167d5a49..17423cee2f7 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -294,8 +294,7 @@ static void gp_primitive_set_cp(tGPDprimitive *tgpi, float p[2], int color, int
tGPcontrolpoint *cp = &tgpi->cp_points[tgpi->tot_cp_points];
copy_v2_v2(&cp->x, p);
cp->color = color;
- cp->display = true;
- cp->size = MAX2(5, size);
+ cp->size = CLAMP(size, 5, 20);
tgpi->tot_cp_points += 1;
}
}
@@ -453,6 +452,10 @@ static void gp_primitive_arc(tGPDprimitive *tgpi, tGPspoint *points2D)
p2d->y = (end[1] - cosf(a) * length[1]);
a += step;
}
+
+ gp_primitive_set_cp(tgpi, tgpi->start, TH_ACTIVE_VERT, 20);
+ gp_primitive_set_cp(tgpi, tgpi->end, TH_ACTIVE_VERT, 20);
+ gp_primitive_set_cp(tgpi, tgpi->origin, TH_REDALERT, 10);
}
/* create a bezier */
@@ -476,6 +479,12 @@ static void gp_primitive_bezier(tGPDprimitive *tgpi, tGPspoint *points2D)
interp_v2_v2v2v2v2_cubic(&p2d->x, bcp1, bcp2, bcp3, bcp4, a);
a += step;
}
+
+ gp_primitive_set_cp(tgpi, tgpi->start, TH_ACTIVE_VERT, 20);
+ gp_primitive_set_cp(tgpi, tgpi->end, TH_ACTIVE_VERT, 20);
+ gp_primitive_set_cp(tgpi, tgpi->origin, TH_REDALERT, 10);
+ gp_primitive_set_cp(tgpi, tgpi->cp1, TH_GP_VERTEX_SELECT, 20);
+ gp_primitive_set_cp(tgpi, tgpi->cp2, TH_GP_VERTEX_SELECT, 20);
}
/* create a circle */
@@ -499,6 +508,13 @@ static void gp_primitive_circle(tGPDprimitive *tgpi, tGPspoint *points2D)
p2d->y = (center[1] + sinf(a) * radius[1]);
a += step;
}
+
+ gp_primitive_set_cp(tgpi, tgpi->start, TH_ACTIVE_VERT, 20);
+ gp_primitive_set_cp(tgpi, tgpi->end, TH_ACTIVE_VERT, 20);
+ gp_primitive_set_cp(tgpi, tgpi->origin, TH_REDALERT, 10);
+ gp_primitive_set_cp(tgpi, center, TH_REDALERT, 15);
+ gp_primitive_set_cp(tgpi, radius, TH_REDALERT, 15);
+
}
/* Helper: Update shape of the stroke */
@@ -683,22 +699,13 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
}
/* store cps and convert coords, this is temporary code */
- tgpi->draw_cp_points = ELEM(tgpi->flag, IN_PROGRESS, IN_CURVE_EDIT);
- if (tgpi->draw_cp_points) {
- gp_primitive_set_cp(tgpi, tgpi->start, TH_ACTIVE_VERT, 20);
- gp_primitive_set_cp(tgpi, tgpi->end, TH_ACTIVE_VERT, 20);
- gp_primitive_set_cp(tgpi, tgpi->origin, TH_REDALERT, 10);
- if (tgpi->type == GP_STROKE_BEZIER) {
- gp_primitive_set_cp(tgpi, tgpi->cp2, TH_GP_VERTEX_SELECT, 20);
- gp_primitive_set_cp(tgpi, tgpi->cp1, TH_GP_VERTEX_SELECT, 20);
- }
-
+ if (tgpi->tot_cp_points > 0) {
tGPcontrolpoint *cps = tgpi->cp_points;
for (int i = 0; i < tgpi->tot_cp_points; i++) {
tGPcontrolpoint *cp = &cps[i];
- if(cp->display)
- gp_stroke_convertcoords_tpoint(tgpi->scene, tgpi->ar, tgpi->ob, tgpi->gpl, (tGPspoint *)cp, NULL, &cp->x);
+ gp_stroke_convertcoords_tpoint(tgpi->scene, tgpi->ar, tgpi->ob, tgpi->gpl, (tGPspoint *)cp, NULL, &cp->x);
}
+ tgpi->draw_cp_points = true;
}
/* if axis locked, reproject to plane locked */
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 3ee8b04589a..376a3bd01ee 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -86,7 +86,6 @@ typedef struct tGPcontrolpoint {
float x, y, z; /* x and y coordinates of control point */
int color; /* theme color */
int size; /* radius */
- bool display; /* display */
} tGPcontrolpoint;
/* used to sort by zdepth gpencil objects in viewport */
More information about the Bf-blender-cvs
mailing list