[Bf-blender-cvs] [ab5a4bc51c9] greasepencil-refactor: GPencil: Refactor: Fix broken shader & undefined behavior
Clément Foucault
noreply at git.blender.org
Fri Dec 13 02:11:51 CET 2019
Commit: ab5a4bc51c93bb7ab7b581070c958180b8127a97
Author: Clément Foucault
Date: Fri Dec 13 00:33:57 2019 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rBab5a4bc51c93bb7ab7b581070c958180b8127a97
GPencil: Refactor: Fix broken shader & undefined behavior
===================================================================
M source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
===================================================================
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 695a959c6f6..fbf2beb809e 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -112,19 +112,20 @@ static int gpencil_stroke_is_cyclic(const bGPDstroke *gps)
static void gpencil_buffer_add_point(
gpStrokeVert *verts, const bGPDstroke *gps, const bGPDspoint *pt, int v, bool is_endpoint)
{
- copy_v3_v3(verts->pos, &pt->x);
- copy_v2_v2(verts->uv, pt->uv_fill);
- copy_v4_v4(verts->col, pt->mix_color);
- verts->strength = pt->strength;
- verts->u_stroke = pt->uv_fac;
- verts->stroke_id = gps->runtime.stroke_start;
- verts->point_id = v;
+ gpStrokeVert *vert = &verts[v];
+ copy_v3_v3(vert->pos, &pt->x);
+ copy_v2_v2(vert->uv, pt->uv_fill);
+ copy_v4_v4(vert->col, pt->mix_color);
+ vert->strength = pt->strength;
+ vert->u_stroke = pt->uv_fac;
+ vert->stroke_id = gps->runtime.stroke_start;
+ vert->point_id = v;
/* Rotation are in [-90°..90°] range, so we can encode the sign of the angle + the cosine
* because the cosine will always be positive. */
- verts->v_rot = cosf(pt->uv_rot) * signf(pt->uv_rot);
- verts->thickness = gps->thickness * pt->pressure;
+ vert->v_rot = cosf(pt->uv_rot) * signf(pt->uv_rot);
+ vert->thickness = gps->thickness * pt->pressure;
/* Tag endpoint material to -1 so they get discarded by vertex shader. */
- verts->mat = (is_endpoint) ? -1 : (gps->mat_nr % GPENCIL_MATERIAL_BUFFER_LEN);
+ vert->mat = (is_endpoint) ? -1 : (gps->mat_nr % GPENCIL_MATERIAL_BUFFER_LEN);
}
static void gpencil_buffer_add_stroke(gpStrokeVert *verts, const bGPDstroke *gps)
@@ -136,18 +137,18 @@ static void gpencil_buffer_add_stroke(gpStrokeVert *verts, const bGPDstroke *gps
/* First point for adjacency (not drawn). */
int adj_idx = (is_cyclic) ? (pts_len - 1) : 1;
- gpencil_buffer_add_point(&verts[v++], gps, &pts[adj_idx], v, true);
+ gpencil_buffer_add_point(verts, gps, &pts[adj_idx], v++, true);
for (int i = 0; i < pts_len; i++) {
- gpencil_buffer_add_point(&verts[v++], gps, &pts[i], v, false);
+ gpencil_buffer_add_point(verts, gps, &pts[i], v++, false);
}
/* Draw line to first point to complete the loop for cyclic strokes. */
if (is_cyclic) {
- gpencil_buffer_add_point(&verts[v++], gps, &pts[0], v, false);
+ gpencil_buffer_add_point(verts, gps, &pts[0], v++, false);
}
/* Last adjacency point (not drawn). */
adj_idx = (is_cyclic) ? 1 : (pts_len - 2);
- gpencil_buffer_add_point(&verts[v++], gps, &pts[adj_idx], v, true);
+ gpencil_buffer_add_point(verts, gps, &pts[adj_idx], v++, true);
}
static void gpencil_buffer_add_fill(GPUIndexBufBuilder *ibo, const bGPDstroke *gps)
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
index 45d17f090a1..ddb73d56981 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
@@ -263,7 +263,7 @@ void fill_vertex()
depth = -1.0;
}
else {
- /* Use the index of first point of the stroke as depth.
+ /* Use the index of first point of the stroke as depth. */
depth = stroke_id1 * 0.0000002;
}
}
@@ -273,12 +273,12 @@ void main()
/* Trick to detect if a drawcall is stroke or fill.
* This does mean that we need to draw an empty stroke segment before starting
* to draw the real stroke segments. */
- bool is_fill = (gl_InstanceID == 0);
+ bool is_fill = (gl_InstanceID == 0);
- if (!is_fill) {
- stroke_vertex();
- }
- else {
- fill_vertex();
- }
+ if (!is_fill) {
+ stroke_vertex();
}
+ else {
+ fill_vertex();
+ }
+}
More information about the Bf-blender-cvs
mailing list