From 191222c3a81344e603c494350ffcdbad6f7427b0 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 4 Mar 2022 13:14:03 +0100 Subject: [PATCH] Tech ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - Use vertex attributes and matrices in shaders. Shader: flat - Travel moves in gcode preview --- src/slic3r/GUI/GCodeViewer.cpp | 25 ++++++++++++++++++++++++- src/slic3r/GUI/GLShadersManager.cpp | 2 ++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index abbde51c8..188a803a3 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -716,8 +716,13 @@ void GCodeViewer::init() } case EMoveType::Travel: { buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Line; +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + buffer.vertices.format = VBuffer::EFormat::Position; + buffer.shader = "flat_attr"; +#else buffer.vertices.format = VBuffer::EFormat::PositionNormal3; buffer.shader = "toolpaths_lines"; +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES break; } } @@ -1305,9 +1310,19 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) auto add_vertices_as_line = [](const GCodeProcessorResult::MoveVertex& prev, const GCodeProcessorResult::MoveVertex& curr, VertexBuffer& vertices) { // x component of the normal to the current segment (the normal is parallel to the XY plane) const Vec3f dir = (curr.position - prev.position).normalized(); +#if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES Vec3f normal(dir.y(), -dir.x(), 0.0); normal.normalize(); +#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + auto add_vertex = [&vertices](const GCodeProcessorResult::MoveVertex& vertex) { + // add position + vertices.push_back(vertex.position.x()); + vertices.push_back(vertex.position.y()); + vertices.push_back(vertex.position.z()); + }; +#else auto add_vertex = [&vertices, &normal](const GCodeProcessorResult::MoveVertex& vertex) { // add position vertices.push_back(vertex.position.x()); @@ -1318,6 +1333,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) vertices.push_back(normal.y()); vertices.push_back(normal.z()); }; +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES // add previous vertex add_vertex(prev); @@ -2985,9 +3001,11 @@ void GCodeViewer::render_toolpaths() glsafe(::glDisable(GL_VERTEX_PROGRAM_POINT_SIZE)); }; - auto shader_init_as_lines = [light_intensity](GLShaderProgram &shader) { +#if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + auto shader_init_as_lines = [light_intensity](GLShaderProgram &shader) { shader.set_uniform("light_intensity", light_intensity); }; +#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES auto render_as_lines = [ #if ENABLE_GCODE_VIEWER_STATISTICS this @@ -3187,11 +3205,16 @@ void GCodeViewer::render_toolpaths() shader->set_uniform("emission_factor", 0.0f); } else { +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::Point) + shader_init_as_points(*shader); +#else switch (buffer.render_primitive_type) { case TBuffer::ERenderPrimitiveType::Point: shader_init_as_points(*shader); break; case TBuffer::ERenderPrimitiveType::Line: shader_init_as_lines(*shader); break; default: break; } +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES const int uniform_color = shader->get_uniform_location("uniform_color"); auto it_path = buffer.render_paths.begin(); diff --git a/src/slic3r/GUI/GLShadersManager.cpp b/src/slic3r/GUI/GLShadersManager.cpp index b35670d27..41c6a1120 100644 --- a/src/slic3r/GUI/GLShadersManager.cpp +++ b/src/slic3r/GUI/GLShadersManager.cpp @@ -62,8 +62,10 @@ std::pair GLShadersManager::init() valid &= append_shader("gouraud_light_instanced_attr", { "gouraud_light_instanced_attr.vs", "gouraud_light_instanced.fs" }); #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES } +#if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES // used to render extrusion and travel paths as lines in gcode preview valid &= append_shader("toolpaths_lines", { "toolpaths_lines.vs", "toolpaths_lines.fs" }); +#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES // used to render objects in 3d editor valid &= append_shader("gouraud", { "gouraud.vs", "gouraud.fs" } #if ENABLE_ENVIRONMENT_MAP