From d7d4bca23be91ec5b0ce562d47a34ee49dd337b8 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 1 May 2017 16:21:53 +0200 Subject: Reworked version of dashed line shader. Using geometry shader allows us to get rid of the 'line origin' extra vertex attribute, which means dashed shader no longer requires fiddling with those vertex attributes definition, and, most importantly, does not require anymore special drawing code! As you can see, this makes code much simpler, and much less verbose, especially in complex cases. In addition, changed how dashes are handled, to have two 'modes', a simple one with single color (using default "color" uniform name), and a more advanced one allowing more complex and multi-color patterns. Note that since GLSL 1.2 does not support geometry shaders, a hack was added for now (which gives solid lines, but at least does not make Blender crash). --- source/blender/editors/space_nla/nla_draw.c | 64 ++++++++--------------------- 1 file changed, 18 insertions(+), 46 deletions(-) (limited to 'source/blender/editors/space_nla/nla_draw.c') diff --git a/source/blender/editors/space_nla/nla_draw.c b/source/blender/editors/space_nla/nla_draw.c index 8121bfe9dc8..623646040d8 100644 --- a/source/blender/editors/space_nla/nla_draw.c +++ b/source/blender/editors/space_nla/nla_draw.c @@ -121,6 +121,8 @@ static void nla_action_draw_keyframes(AnimData *adt, bAction *act, float y, floa VertexFormat *format = immVertexFormat(); unsigned int pos_id = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + immUniformColor4fv(color); /* - draw a rect from the first to the last frame (no extra overlaps for now) @@ -175,67 +177,37 @@ static void nla_actionclip_draw_markers(NlaStrip *strip, float yminc, float ymax if (!(act && act->markers.first)) return; - float color[4]; - UI_GetThemeColorShade4fv(TH_STRIP_SELECT, shade, color); - + const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); if (dashed) { - VertexFormat *format = immVertexFormat(); - const uint shdr_dashed_pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); - const uint shdr_dashed_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); float viewport_size[4]; glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); - immUniform4fv("color1", color); - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniform1i("num_colors", 0); /* "simple" mode */ immUniform1f("dash_width", 6.0f); - immUniform1f("dash_width_on", 3.0f); - - immBeginAtMost(PRIM_LINES, BLI_listbase_count(&act->markers) * 2); - for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) { - if ((marker->frame > strip->actstart) && (marker->frame < strip->actend)) { - float frame = nlastrip_get_frame(strip, marker->frame, NLATIME_CONVERT_MAP); - - /* just a simple line for now */ - /* XXX: draw a triangle instead... */ - immAttrib2f(shdr_dashed_origin, frame, yminc + 1); - immVertex2f(shdr_dashed_pos, frame, yminc + 1); - immVertex2f(shdr_dashed_pos, frame, ymaxc - 1); - } - } - immEnd(); - - immUnbindProgram(); - - glDisable(GL_BLEND); + immUniform1f("dash_factor", 0.5f); } else { - const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + } + immUniformThemeColorShade(TH_STRIP_SELECT, shade); - immUniformColor4fv(color); - - immBeginAtMost(PRIM_LINES, BLI_listbase_count(&act->markers) * 2); - for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) { - if ((marker->frame > strip->actstart) && (marker->frame < strip->actend)) { - float frame = nlastrip_get_frame(strip, marker->frame, NLATIME_CONVERT_MAP); + immBeginAtMost(PRIM_LINES, BLI_listbase_count(&act->markers) * 2); + for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) { + if ((marker->frame > strip->actstart) && (marker->frame < strip->actend)) { + float frame = nlastrip_get_frame(strip, marker->frame, NLATIME_CONVERT_MAP); - /* just a simple line for now */ - /* XXX: draw a triangle instead... */ - immVertex2f(shdr_pos, frame, yminc + 1); - immVertex2f(shdr_pos, frame, ymaxc - 1); - } + /* just a simple line for now */ + /* XXX: draw a triangle instead... */ + immVertex2f(shdr_pos, frame, yminc + 1); + immVertex2f(shdr_pos, frame, ymaxc - 1); } - immEnd(); - - immUnbindProgram(); } + immEnd(); + + immUnbindProgram(); } /* Markers inside a NLA-Strip */ -- cgit v1.2.3