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/cage3d_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/cage3d_gizmo.c')
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c52
1 files changed, 30 insertions, 22 deletions
diff --git a/source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c
index 6855268610e..b0af8641767 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c
@@ -130,14 +130,22 @@ static void gizmo_rect_pivot_from_scale_part(int part, float r_pt[3], bool r_con
* Useful for 3D views, see: #ED_GIZMO_CAGE2D_STYLE_BOX
* \{ */
-static void cage3d_draw_box_corners(const float r[3], const float margin[3], const float color[3])
+static void cage3d_draw_box_corners(const float r[3],
+ const float margin[3],
+ const float color[3],
+ const float line_width)
{
uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
UNUSED_VARS(margin);
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR);
immUniformColor3fv(color);
+ float viewport[4];
+ GPU_viewport_size_get_f(viewport);
+ immUniform2fv("viewportSize", &viewport[2]);
+ immUniform1f("lineWidth", line_width * U.pixelsize);
+
imm_draw_cube_wire_3d(pos, (float[3]){0}, r);
immUnbindProgram();
@@ -199,13 +207,19 @@ static void cage3d_draw_circle_wire(const float r[3],
const float margin[3],
const float color[3],
const int transform_flag,
- const int draw_options)
+ const int draw_options,
+ const float line_width)
{
uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR);
immUniformColor3fv(color);
+ float viewport[4];
+ GPU_viewport_size_get_f(viewport);
+ immUniform2fv("viewportSize", &viewport[2]);
+ immUniform1f("lineWidth", line_width * U.pixelsize);
+
imm_draw_cube_wire_3d(pos, (float[3]){0}, r);
#if 0
@@ -339,15 +353,14 @@ static void gizmo_cage3d_draw_intern(
};
#endif
if (draw_style == ED_GIZMO_CAGE2D_STYLE_BOX) {
+ float color[4], black[3] = {0, 0, 0};
+ gizmo_color_get(gz, highlight, color);
+
/* corner gizmos */
- GPU_line_width(gz->line_width + 3.0f);
- cage3d_draw_box_corners(size_real, margin, (const float[3]){0, 0, 0});
+ cage3d_draw_box_corners(size_real, margin, black, gz->line_width + 3.0f);
/* corner gizmos */
- float color[4];
- gizmo_color_get(gz, highlight, color);
- GPU_line_width(gz->line_width);
- cage3d_draw_box_corners(size_real, margin, color);
+ cage3d_draw_box_corners(size_real, margin, color, gz->line_width);
bool show = false;
if (gz->highlight_part == ED_GIZMO_CAGE3D_PART_TRANSLATE) {
@@ -366,34 +379,29 @@ static void gizmo_cage3d_draw_intern(
}
}
else if (draw_style == ED_GIZMO_CAGE2D_STYLE_CIRCLE) {
- float color[4];
+ float color[4], black[3] = {0, 0, 0};
gizmo_color_get(gz, highlight, color);
- GPU_line_smooth(true);
- GPU_polygon_smooth(true);
GPU_blend(true);
- GPU_line_width(gz->line_width + 3.0f);
cage3d_draw_circle_wire(
- size_real, margin, (const float[3]){0, 0, 0}, transform_flag, draw_options);
- GPU_line_width(gz->line_width);
- cage3d_draw_circle_wire(size_real, margin, color, transform_flag, draw_options);
+ size_real, margin, black, transform_flag, draw_options, gz->line_width + 3.0f);
+ cage3d_draw_circle_wire(
+ size_real, margin, color, transform_flag, draw_options, gz->line_width);
/* corner gizmos */
- cage3d_draw_circle_handles(
- rv3d, matrix_final, size_real, margin, (const float[3]){0, 0, 0}, true, 60);
+ GPU_polygon_smooth(true);
+ cage3d_draw_circle_handles(rv3d, matrix_final, size_real, margin, black, true, 60);
cage3d_draw_circle_handles(rv3d, matrix_final, size_real, margin, color, true, 40);
+ GPU_polygon_smooth(false);
GPU_blend(false);
- GPU_polygon_smooth(false);
- GPU_line_smooth(false);
}
else {
BLI_assert(0);
}
}
- GPU_line_width(1.0);
GPU_matrix_pop();
}