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:
authorClément Foucault <foucault.clem@gmail.com>2020-04-24 00:05:39 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-04-24 00:07:48 +0300
commitd712f1f83af881be536ec0d183b7d3025c172684 (patch)
treeeabecb450ce2d4697468d2758df28fd990c14ed6 /source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c
parentd0ff3434cffa2e056e4f191ead21226f32ea8c15 (diff)
GPU: Add Polyline shader (wide line emulation)
This new shader is able to emulate smooth wide lines drawing using a geometry shader. This shader needs viewportSize and lineWidth uniforms to be set. There is multiple variants to replace the usage of wide lines for most shaders. This patch only fix the gizmo_types files and the navigation gizmo. Other areas could be fixed afterward, I just limited the patch size. Fix T57570. Reviewed By: billreynish Differential Revision: https://developer.blender.org/D7487
Diffstat (limited to 'source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c')
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c
index 11253f01bf2..11b1b98ea12 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c
@@ -76,7 +76,8 @@ static void button2d_geom_draw_backdrop(const wmGizmo *gz,
const float fill_alpha,
const bool select)
{
- GPU_line_width(gz->line_width);
+ float viewport[4];
+ GPU_viewport_size_get_f(viewport);
GPUVertFormat *format = immVertexFormat();
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
@@ -85,10 +86,14 @@ static void button2d_geom_draw_backdrop(const wmGizmo *gz,
if (color[3] == 1.0 && fill_alpha == 1.0 && select == false) {
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
immUniformColor4fv(color);
- GPU_polygon_smooth(0);
imm_draw_circle_fill_2d(pos, 0, 0, 1.0f, CIRCLE_RESOLUTION);
+ immUnbindProgram();
+
+ immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR);
+ immUniform2fv("viewportSize", &viewport[2]);
+ immUniform1f("lineWidth", gz->line_width * U.pixelsize);
+ immUniformColor4fv(color);
imm_draw_circle_wire_2d(pos, 0, 0, 1.0f, CIRCLE_RESOLUTION);
- GPU_polygon_smooth(1);
immUnbindProgram();
}
else {
@@ -103,9 +108,10 @@ static void button2d_geom_draw_backdrop(const wmGizmo *gz,
/* Draw outline. */
if ((fill_alpha != 1.0f) && (select == false)) {
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR);
+ immUniform2fv("viewportSize", &viewport[2]);
+ immUniform1f("lineWidth", gz->line_width * U.pixelsize);
immUniformColor4fv(color);
- GPU_line_width(gz->line_width);
imm_draw_circle_wire_2d(pos, 0, 0, 1.0f, CIRCLE_RESOLUTION);
immUnbindProgram();
}
@@ -152,12 +158,13 @@ static void button2d_draw_intern(const bContext *C,
bool is_3d = (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) != 0;
if ((select == false) && (draw_options & ED_GIZMO_BUTTON_SHOW_HELPLINE)) {
- float matrix_final_no_offset[4][4];
+ float matrix_final_no_offset[4][4], viewport[4];
WM_gizmo_calc_matrix_final_no_offset(gz, matrix_final_no_offset);
uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- immUniformColor4fv(color);
- GPU_line_width(gz->line_width);
+ immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR);
+ GPU_viewport_size_get_f(viewport);
+ immUniform2fv("viewportSize", &viewport[2]);
+ immUniform1f("lineWidth", gz->line_width * U.pixelsize);
immUniformColor4fv(color);
immBegin(GPU_PRIM_LINE_STRIP, 2);
immVertex3fv(pos, matrix_final[3]);
@@ -197,7 +204,6 @@ static void button2d_draw_intern(const bContext *C,
if (button->shape_batch[0] != NULL) {
GPU_line_smooth(true);
GPU_polygon_smooth(false);
- GPU_line_width(1.0f);
for (uint i = 0; i < ARRAY_SIZE(button->shape_batch) && button->shape_batch[i]; i++) {
/* Invert line color for wire. */
GPU_batch_program_set_builtin(button->shape_batch[i], GPU_SHADER_2D_UNIFORM_COLOR);
@@ -216,7 +222,7 @@ static void button2d_draw_intern(const bContext *C,
GPU_batch_uniform_4f(button->shape_batch[i], "color", UNPACK4(color));
}
- GPU_batch_draw(button->shape_batch[i]);
+ // GPU_batch_draw(button->shape_batch[i]);
if (draw_options & ED_GIZMO_BUTTON_SHOW_OUTLINE) {
color[0] = 1.0f - color[0];