GCodeViewer -> New shaders for options

This commit is contained in:
enricoturri1966 2020-05-22 13:21:43 +02:00
parent 80c2f107c1
commit 4d05ec0856
18 changed files with 132 additions and 408 deletions

View file

@ -440,12 +440,12 @@ void GCodeViewer::init_shaders()
{
switch (buffer_type(i))
{
case GCodeProcessor::EMoveType::Tool_change: { m_buffers[i].shader = "toolchanges"; break; }
case GCodeProcessor::EMoveType::Color_change: { m_buffers[i].shader = "colorchanges"; break; }
case GCodeProcessor::EMoveType::Pause_Print: { m_buffers[i].shader = "pauses"; break; }
case GCodeProcessor::EMoveType::Custom_GCode: { m_buffers[i].shader = "customs"; break; }
case GCodeProcessor::EMoveType::Retract: { m_buffers[i].shader = "retractions"; break; }
case GCodeProcessor::EMoveType::Unretract: { m_buffers[i].shader = "unretractions"; break; }
case GCodeProcessor::EMoveType::Tool_change: { m_buffers[i].shader = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20) ? "options_120" : "options_110"; break; }
case GCodeProcessor::EMoveType::Color_change: { m_buffers[i].shader = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20) ? "options_120" : "options_110"; break; }
case GCodeProcessor::EMoveType::Pause_Print: { m_buffers[i].shader = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20) ? "options_120" : "options_110"; break; }
case GCodeProcessor::EMoveType::Custom_GCode: { m_buffers[i].shader = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20) ? "options_120" : "options_110"; break; }
case GCodeProcessor::EMoveType::Retract: { m_buffers[i].shader = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20) ? "options_120" : "options_110"; break; }
case GCodeProcessor::EMoveType::Unretract: { m_buffers[i].shader = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20) ? "options_120" : "options_110"; break; }
case GCodeProcessor::EMoveType::Extrude: { m_buffers[i].shader = "extrusions"; break; }
case GCodeProcessor::EMoveType::Travel: { m_buffers[i].shader = "travels"; break; }
default: { break; }
@ -827,6 +827,12 @@ void GCodeViewer::render_toolpaths() const
};
#endif // !ENABLE_SHADERS_MANAGER
bool is_glsl_120 = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20);
int detected_point_sizes[2];
::glGetIntegerv(GL_ALIASED_POINT_SIZE_RANGE, detected_point_sizes);
std::array<float, 2> point_sizes = { 2.0f, std::min(64.0f, static_cast<float>(detected_point_sizes[1])) };
double zoom = wxGetApp().plater()->get_camera().get_zoom();
glsafe(::glCullFace(GL_BACK));
glsafe(::glLineWidth(3.0f));
@ -868,94 +874,139 @@ void GCodeViewer::render_toolpaths() const
{
#if ENABLE_SHADERS_MANAGER
shader->set_uniform("uniform_color", Options_Colors[static_cast<unsigned int>(EOptionsColors::ToolChanges)]);
shader->set_uniform("zoom", zoom);
shader->set_uniform("point_sizes", point_sizes);
if (is_glsl_120)
{
glsafe(::glEnable(GL_POINT_SPRITE));
glsafe(::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE));
}
#else
set_color(static_cast<GLint>(buffer.shader.get_shader_program_id()), Options_Colors[static_cast<unsigned int>(EOptionsColors::ToolChanges)]);
#endif // ENABLE_SHADERS_MANAGER
for (const RenderPath& path : buffer.render_paths)
{
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size()));
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
#if ENABLE_GCODE_VIEWER_STATISTICS
++m_statistics.gl_multi_points_calls_count;
#endif // ENABLE_GCODE_VIEWER_STATISTICS
}
if (is_glsl_120)
{
glsafe(::glDisable(GL_VERTEX_PROGRAM_POINT_SIZE));
glsafe(::glDisable(GL_POINT_SPRITE));
}
break;
}
case GCodeProcessor::EMoveType::Color_change:
{
#if ENABLE_SHADERS_MANAGER
shader->set_uniform("uniform_color", Options_Colors[static_cast<unsigned int>(EOptionsColors::ColorChanges)]);
shader->set_uniform("zoom", zoom);
shader->set_uniform("point_sizes", point_sizes);
if (is_glsl_120)
{
glsafe(::glEnable(GL_POINT_SPRITE));
glsafe(::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE));
}
#else
set_color(static_cast<GLint>(buffer.shader.get_shader_program_id()), Options_Colors[static_cast<unsigned int>(EOptionsColors::ColorChanges)]);
#endif // ENABLE_SHADERS_MANAGER
for (const RenderPath& path : buffer.render_paths)
{
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size()));
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
#if ENABLE_GCODE_VIEWER_STATISTICS
++m_statistics.gl_multi_points_calls_count;
#endif // ENABLE_GCODE_VIEWER_STATISTICS
}
if (is_glsl_120)
{
glsafe(::glDisable(GL_VERTEX_PROGRAM_POINT_SIZE));
glsafe(::glDisable(GL_POINT_SPRITE));
}
break;
}
case GCodeProcessor::EMoveType::Pause_Print:
{
#if ENABLE_SHADERS_MANAGER
shader->set_uniform("uniform_color", Options_Colors[static_cast<unsigned int>(EOptionsColors::PausePrints)]);
shader->set_uniform("zoom", zoom);
shader->set_uniform("point_sizes", point_sizes);
if (is_glsl_120)
{
glsafe(::glEnable(GL_POINT_SPRITE));
glsafe(::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE));
}
#else
set_color(static_cast<GLint>(buffer.shader.get_shader_program_id()), Options_Colors[static_cast<unsigned int>(EOptionsColors::PausePrints)]);
#endif // ENABLE_SHADERS_MANAGER
for (const RenderPath& path : buffer.render_paths)
{
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size()));
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
#if ENABLE_GCODE_VIEWER_STATISTICS
++m_statistics.gl_multi_points_calls_count;
#endif // ENABLE_GCODE_VIEWER_STATISTICS
}
if (is_glsl_120)
{
glsafe(::glDisable(GL_VERTEX_PROGRAM_POINT_SIZE));
glsafe(::glDisable(GL_POINT_SPRITE));
}
break;
}
case GCodeProcessor::EMoveType::Custom_GCode:
{
#if ENABLE_SHADERS_MANAGER
shader->set_uniform("uniform_color", Options_Colors[static_cast<unsigned int>(EOptionsColors::CustomGCodes)]);
shader->set_uniform("zoom", zoom);
shader->set_uniform("point_sizes", point_sizes);
if (is_glsl_120)
{
glsafe(::glEnable(GL_POINT_SPRITE));
glsafe(::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE));
}
#else
set_color(static_cast<GLint>(buffer.shader.get_shader_program_id()), Options_Colors[static_cast<unsigned int>(EOptionsColors::CustomGCodes)]);
#endif // ENABLE_SHADERS_MANAGER
for (const RenderPath& path : buffer.render_paths)
{
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size()));
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
#if ENABLE_GCODE_VIEWER_STATISTICS
++m_statistics.gl_multi_points_calls_count;
#endif // ENABLE_GCODE_VIEWER_STATISTICS
}
if (is_glsl_120)
{
glsafe(::glDisable(GL_VERTEX_PROGRAM_POINT_SIZE));
glsafe(::glDisable(GL_POINT_SPRITE));
}
break;
}
case GCodeProcessor::EMoveType::Retract:
{
#if ENABLE_SHADERS_MANAGER
shader->set_uniform("uniform_color", Options_Colors[static_cast<unsigned int>(EOptionsColors::Retractions)]);
shader->set_uniform("zoom", zoom);
shader->set_uniform("point_sizes", point_sizes);
if (is_glsl_120)
{
glsafe(::glEnable(GL_POINT_SPRITE));
glsafe(::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE));
}
#else
set_color(static_cast<GLint>(buffer.shader.get_shader_program_id()), Options_Colors[static_cast<unsigned int>(EOptionsColors::Retractions)]);
#endif // ENABLE_SHADERS_MANAGER
for (const RenderPath& path : buffer.render_paths)
{
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size()));
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
#if ENABLE_GCODE_VIEWER_STATISTICS
++m_statistics.gl_multi_points_calls_count;
#endif // ENABLE_GCODE_VIEWER_STATISTICS
if (is_glsl_120)
{
glsafe(::glDisable(GL_VERTEX_PROGRAM_POINT_SIZE));
glsafe(::glDisable(GL_POINT_SPRITE));
}
}
break;
}
@ -963,19 +1014,28 @@ void GCodeViewer::render_toolpaths() const
{
#if ENABLE_SHADERS_MANAGER
shader->set_uniform("uniform_color", Options_Colors[static_cast<unsigned int>(EOptionsColors::Unretractions)]);
shader->set_uniform("zoom", zoom);
shader->set_uniform("point_sizes", point_sizes);
if (is_glsl_120)
{
glsafe(::glEnable(GL_POINT_SPRITE));
glsafe(::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE));
}
#else
set_color(static_cast<GLint>(buffer.shader.get_shader_program_id()), Options_Colors[static_cast<unsigned int>(EOptionsColors::Unretractions)]);
#endif // ENABLE_SHADERS_MANAGER
for (const RenderPath& path : buffer.render_paths)
{
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size()));
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
#if ENABLE_GCODE_VIEWER_STATISTICS
++m_statistics.gl_multi_points_calls_count;
#endif // ENABLE_GCODE_VIEWER_STATISTICS
}
if (is_glsl_120)
{
glsafe(::glDisable(GL_VERTEX_PROGRAM_POINT_SIZE));
glsafe(::glDisable(GL_POINT_SPRITE));
}
break;
}
case GCodeProcessor::EMoveType::Extrude:

View file

@ -34,18 +34,9 @@ std::pair<bool, std::string> GLShadersManager::init()
valid &= append_shader("gouraud_light", { "gouraud_light.vs", "gouraud_light.fs" });
// used to render printbed
valid &= append_shader("printbed", { "printbed.vs", "printbed.fs" });
// used to render tool changes in gcode preview
valid &= append_shader("toolchanges", { "toolchanges.vs", "toolchanges.fs" });
// used to render color changes in gcode preview
valid &= append_shader("colorchanges", { "colorchanges.vs", "colorchanges.fs" });
// used to render pause prints in gcode preview
valid &= append_shader("pauses", { "pauses.vs", "pauses.fs" });
// used to render custom gcode points in gcode preview
valid &= append_shader("customs", { "customs.vs", "customs.fs" });
// used to render retractions in gcode preview
valid &= append_shader("retractions", { "retractions.vs", "retractions.fs" });
// used to render unretractions in gcode preview
valid &= append_shader("unretractions", { "unretractions.vs", "unretractions.fs" });
// used to render options in gcode preview
valid &= append_shader("options_110", { "options_110.vs", "options_110.fs" });
valid &= append_shader("options_120", { "options_120.vs", "options_120.fs" });
// used to render extrusion paths in gcode preview
valid &= append_shader("extrusions", { "extrusions.vs", "extrusions.fs" });
// used to render travel paths in gcode preview