[Bf-blender-cvs] [8e3c8912290] greasepencil-refactor: GPencil: Refactor: Add back basic fill drawing
Clément Foucault
noreply at git.blender.org
Sun Dec 8 01:39:12 CET 2019
Commit: 8e3c8912290e546158b6d2e8c80dab8704d74c57
Author: Clément Foucault
Date: Sun Dec 8 01:26:11 2019 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB8e3c8912290e546158b6d2e8c80dab8704d74c57
GPencil: Refactor: Add back basic fill drawing
===================================================================
M source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M source/blender/draw/engines/gpencil/gpencil_engine.c
===================================================================
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index 67e3635b880..171c3ff4e5f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -97,6 +97,7 @@ static GPUVertFormat *gpencil_stroke_format(void)
* \{ */
typedef struct gpIterData {
+ bGPdata *gpd;
gpStrokeVert *verts;
GPUIndexBufBuilder ibo;
int vert_len;
@@ -141,9 +142,11 @@ static void gpencil_buffer_add_stroke(gpStrokeVert *verts, const bGPDstroke *str
static void gpencil_buffer_add_fill(GPUIndexBufBuilder *ibo, const bGPDstroke *stroke)
{
- int v = stroke->runtime.fill_start;
- /* TODO ibo filling. */
- UNUSED_VARS(v, ibo);
+ int tri_len = stroke->tot_triangles;
+ for (int i = 0; i < tri_len; i++) {
+ uint *tri = stroke->triangles[i].verts;
+ GPU_indexbuf_add_tri_verts(ibo, tri[0], tri[1], tri[2]);
+ }
}
static void gpencil_stroke_iter_cb(bGPDlayer *UNUSED(layer),
@@ -153,8 +156,7 @@ static void gpencil_stroke_iter_cb(bGPDlayer *UNUSED(layer),
{
gpIterData *iter = (gpIterData *)thunk;
gpencil_buffer_add_stroke(iter->verts, stroke);
-
- if (true) { /* TODO */
+ if (stroke->tot_triangles > 0) {
gpencil_buffer_add_fill(&iter->ibo, stroke);
}
}
@@ -166,11 +168,23 @@ static void gp_object_verts_count_cb(bGPDlayer *UNUSED(layer),
{
gpIterData *iter = (gpIterData *)thunk;
+ /* Calculate triangles cache for filling area (must be done only after changes) */
+ if ((stroke->flag & GP_STROKE_RECALC_GEOMETRY) || (stroke->tot_triangles == 0) ||
+ (stroke->triangles == NULL)) {
+ if (stroke->totpoints >= 3) {
+ /* TODO OPTI only do this if the fill is actually displayed. */
+ BKE_gpencil_triangulate_stroke_fill(iter->gpd, stroke);
+ }
+ else {
+ stroke->tot_triangles = 0;
+ }
+ }
+
/* Store first index offset */
stroke->runtime.stroke_start = iter->vert_len;
stroke->runtime.fill_start = iter->tri_len;
iter->vert_len += stroke->totpoints + 2 + gpencil_stroke_is_cyclic(stroke);
- iter->tri_len += stroke->totpoints - 1;
+ iter->tri_len += stroke->tot_triangles;
}
static void gpencil_batches_ensure(Object *ob, GpencilBatchCache *cache)
@@ -184,6 +198,7 @@ static void gpencil_batches_ensure(Object *ob, GpencilBatchCache *cache)
/* First count how many vertices and triangles are needed for the whole object. */
gpIterData iter = {
+ .gpd = gpd,
.verts = NULL,
.ibo = {0},
.vert_len = 1, /* Start at 1 for the gl_InstanceID trick to work (see vert shader). */
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 4d527265aa3..57afb87049b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -762,6 +762,14 @@ static void gp_stroke_cache_populate(bGPDlayer *UNUSED(layer),
}
bool show_stroke = (gp_style->flag & GP_STYLE_STROKE_SHOW) != 0;
+ bool show_fill = (stroke->tot_triangles > 0) && (gp_style->flag & GP_STYLE_FILL_SHOW) != 0;
+
+ if (show_fill) {
+ GPUBatch *geom = GPENCIL_batch_cache_fills(iter->ob, iter->pd->cfra);
+ int vfirst = stroke->runtime.fill_start * 3;
+ int vcount = stroke->tot_triangles * 3;
+ DRW_shgroup_call_range(iter->grp, geom, vfirst, vcount);
+ }
if (show_stroke) {
GPUBatch *geom = GPENCIL_batch_cache_strokes(iter->ob, iter->pd->cfra);
More information about the Bf-blender-cvs
mailing list