diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2017-05-01 17:21:53 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2017-05-01 17:32:55 +0300 |
commit | d7d4bca23be91ec5b0ce562d47a34ee49dd337b8 (patch) | |
tree | 6184684f5300324294dbaa103522e7e817e3d6bd /source/blender/editors/space_nla | |
parent | 6ef497d401e5e7842d1e9d33e491672bb77d60e0 (diff) |
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).
Diffstat (limited to 'source/blender/editors/space_nla')
-rw-r--r-- | source/blender/editors/space_nla/nla_draw.c | 64 |
1 files changed, 18 insertions, 46 deletions
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 */ |