Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2017-05-01 17:21:53 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2017-05-01 17:32:55 +0300
commitd7d4bca23be91ec5b0ce562d47a34ee49dd337b8 (patch)
tree6184684f5300324294dbaa103522e7e817e3d6bd /source/blender/editors/transform
parent6ef497d401e5e7842d1e9d33e491672bb77d60e0 (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/transform')
-rw-r--r--source/blender/editors/transform/transform.c50
-rw-r--r--source/blender/editors/transform/transform_constraints.c20
2 files changed, 23 insertions, 47 deletions
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index 1c194a06005..02ad292e5c1 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -1722,15 +1722,11 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
/* Dashed lines first. */
if (ELEM(t->helpline, HLP_SPRING, HLP_ANGLE)) {
- VertexFormat *format = immVertexFormat();
- uint pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT);
- uint line_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT);
+ const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT);
- UNUSED_VARS_NDEBUG(pos); /* silence warning */
- BLI_assert(pos == POS_INDEX);
+ UNUSED_VARS_NDEBUG(shdr_pos); /* silence warning */
+ BLI_assert(shdr_pos == POS_INDEX);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
glLineWidth(1.0f);
immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR);
@@ -1739,22 +1735,17 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
glGetFloatv(GL_VIEWPORT, viewport_size);
immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
- float color1[4];
- UI_GetThemeColor4fv(TH_VIEW_OVERLAY, color1);
- immUniform4fv("color1", color1);
- immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f);
+ immUniform1i("num_colors", 0); /* "simple" mode */
+ immUniformThemeColor(TH_VIEW_OVERLAY);
immUniform1f("dash_width", 6.0f);
- immUniform1f("dash_width_on", 3.0f);
+ immUniform1f("dash_factor", 0.5f);
immBegin(PRIM_LINES, 2);
- immAttrib2fv(line_origin, cent);
immVertex2fv(POS_INDEX, cent);
immVertex2f(POS_INDEX, (float)t->mval[0], (float)t->mval[1]);
immEnd();
immUnbindProgram();
-
- glDisable(GL_BLEND);
}
/* And now, solid lines. */
@@ -7495,7 +7486,7 @@ static void drawVertSlide(TransInfo *t)
glLineWidth(line_size);
- uint pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT);
+ const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT);
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
immUniformThemeColorShadeAlpha(TH_EDGE_SELECT, 80, alpha_shade);
@@ -7504,8 +7495,8 @@ static void drawVertSlide(TransInfo *t)
if (is_clamp) {
sv = sld->sv;
for (i = 0; i < sld->totsv; i++, sv++) {
- immVertex3fv(pos, sv->co_orig_3d);
- immVertex3fv(pos, sv->co_link_orig_3d[sv->co_link_curr]);
+ immVertex3fv(shdr_pos, sv->co_orig_3d);
+ immVertex3fv(shdr_pos, sv->co_link_orig_3d[sv->co_link_curr]);
}
}
else {
@@ -7518,8 +7509,8 @@ static void drawVertSlide(TransInfo *t)
add_v3_v3(a, sv->co_orig_3d);
add_v3_v3(b, sv->co_orig_3d);
- immVertex3fv(pos, a);
- immVertex3fv(pos, b);
+ immVertex3fv(shdr_pos, a);
+ immVertex3fv(shdr_pos, b);
}
}
immEnd();
@@ -7527,7 +7518,7 @@ static void drawVertSlide(TransInfo *t)
glPointSize(ctrl_size);
immBegin(PRIM_POINTS, 1);
- immVertex3fv(pos, (sld->flipped && sld->use_even) ?
+ immVertex3fv(shdr_pos, (sld->flipped && sld->use_even) ?
curr_sv->co_link_orig_3d[curr_sv->co_link_curr] :
curr_sv->co_orig_3d);
immEnd();
@@ -7558,32 +7549,25 @@ static void drawVertSlide(TransInfo *t)
glLineWidth(1.0f);
- VertexFormat *format = immVertexFormat();
- pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 3, KEEP_FLOAT);
- uint line_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 3, KEEP_FLOAT);
-
immBindBuiltinProgram(GPU_SHADER_3D_LINE_DASHED_COLOR);
float viewport_size[4];
glGetFloatv(GL_VIEWPORT, viewport_size);
immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
- immUniform4f("color1", 1.0f, 1.0f, 1.0f, 1.0f);
- immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f);
+ immUniform1i("num_colors", 0); /* "simple" mode */
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 1.0f);
immUniform1f("dash_width", 6.0f);
- immUniform1f("dash_width_on", 3.0f);
+ immUniform1f("dash_factor", 0.5f);
immBegin(PRIM_LINES, 2);
- immAttrib3fv(line_origin, curr_sv->co_orig_3d);
- immVertex3fv(pos, curr_sv->co_orig_3d);
- immVertex3fv(pos, co_dest_3d);
+ immVertex3fv(shdr_pos, curr_sv->co_orig_3d);
+ immVertex3fv(shdr_pos, co_dest_3d);
immEnd();
immUnbindProgram();
}
- glDisable(GL_BLEND);
-
gpuPopMatrix();
if (v3d && v3d->zbuf)
diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c
index a2cb1bdd6d0..7b658d9c636 100644
--- a/source/blender/editors/transform/transform_constraints.c
+++ b/source/blender/editors/transform/transform_constraints.c
@@ -728,12 +728,7 @@ void drawConstraint(TransInfo *t)
if (depth_test_enabled)
glDisable(GL_DEPTH_TEST);
- VertexFormat *format = immVertexFormat();
- unsigned int pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 3, KEEP_FLOAT);
- unsigned int line_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 3, KEEP_FLOAT);
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
+ const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT);
immBindBuiltinProgram(GPU_SHADER_3D_LINE_DASHED_COLOR);
@@ -741,21 +736,18 @@ void drawConstraint(TransInfo *t)
glGetFloatv(GL_VIEWPORT, viewport_size);
immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
- immUniform4f("color1", 1.0f, 1.0f, 1.0f, 1.0f);
- immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f);
+ immUniform1i("num_colors", 0); /* "simple" mode */
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 1.0f);
immUniform1f("dash_width", 2.0f);
- immUniform1f("dash_width_on", 1.0f);
+ immUniform1f("dash_factor", 0.5f);
immBegin(PRIM_LINES, 2);
- immAttrib3fv(line_origin, t->center_global);
- immVertex3fv(pos, t->center_global);
- immVertex3fv(pos, vec);
+ immVertex3fv(shdr_pos, t->center_global);
+ immVertex3fv(shdr_pos, vec);
immEnd();
immUnbindProgram();
- glDisable(GL_BLEND);
-
if (depth_test_enabled)
glEnable(GL_DEPTH_TEST);
}