Tech ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - Use vertex attributes and matrices in shaders.
Shader: flat - Travel moves in gcode preview
This commit is contained in:
parent
cdf3cb83b6
commit
191222c3a8
@ -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));
|
||||
};
|
||||
|
||||
#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();
|
||||
|
@ -62,8 +62,10 @@ std::pair<bool, std::string> 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
|
||||
|
Loading…
Reference in New Issue
Block a user