mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 01:07:57 -06:00
GCodeViewer refactoring and GLShaderProgram upgrade
This commit is contained in:
parent
ed252f1741
commit
1c826c063b
5 changed files with 59 additions and 124 deletions
|
@ -5,10 +5,11 @@ uniform vec3 uniform_color;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 pos = gl_PointCoord - vec2(0.5, 0.5);
|
vec2 pos = gl_PointCoord - vec2(0.5, 0.5);
|
||||||
float sq_radius = pos.x * pos.x + pos.y * pos.y;
|
float sq_radius = dot(pos, pos);
|
||||||
if (sq_radius > 0.25)
|
if (sq_radius > 0.25)
|
||||||
discard;
|
discard;
|
||||||
else if ((sq_radius < 0.005625) || (sq_radius > 0.180625))
|
|
||||||
|
if ((sq_radius < 0.005625) || (sq_radius > 0.180625))
|
||||||
gl_FragColor = vec4(0.5 * uniform_color, 1.0);
|
gl_FragColor = vec4(0.5 * uniform_color, 1.0);
|
||||||
else
|
else
|
||||||
gl_FragColor = vec4(uniform_color, 1.0);
|
gl_FragColor = vec4(uniform_color, 1.0);
|
||||||
|
|
|
@ -672,7 +672,7 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab
|
||||||
shader->set_uniform("print_box.actived", volume.first->shader_outside_printer_detection_enabled);
|
shader->set_uniform("print_box.actived", volume.first->shader_outside_printer_detection_enabled);
|
||||||
shader->set_uniform("print_box.volume_world_matrix", volume.first->world_matrix());
|
shader->set_uniform("print_box.volume_world_matrix", volume.first->world_matrix());
|
||||||
shader->set_uniform("slope.actived", m_slope.active && !volume.first->is_modifier && !volume.first->is_wipe_tower);
|
shader->set_uniform("slope.actived", m_slope.active && !volume.first->is_modifier && !volume.first->is_wipe_tower);
|
||||||
shader->set_uniform("slope.volume_world_normal_matrix", volume.first->world_matrix().matrix().block(0, 0, 3, 3).inverse().transpose().cast<float>());
|
shader->set_uniform("slope.volume_world_normal_matrix", static_cast<Matrix3f>(volume.first->world_matrix().matrix().block(0, 0, 3, 3).inverse().transpose().cast<float>()));
|
||||||
|
|
||||||
volume.first->render();
|
volume.first->render();
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -740,9 +740,29 @@ void GCodeViewer::render_toolpaths() const
|
||||||
bool is_glsl_120 = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20);
|
bool is_glsl_120 = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20);
|
||||||
int detected_point_sizes[2];
|
int detected_point_sizes[2];
|
||||||
::glGetIntegerv(GL_ALIASED_POINT_SIZE_RANGE, detected_point_sizes);
|
::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])) };
|
std::array<float, 2> point_sizes = { std::min(8.0f, static_cast<float>(detected_point_sizes[1])), std::min(48.0f, static_cast<float>(detected_point_sizes[1])) };
|
||||||
double zoom = wxGetApp().plater()->get_camera().get_zoom();
|
double zoom = wxGetApp().plater()->get_camera().get_zoom();
|
||||||
|
|
||||||
|
auto render_options = [this, is_glsl_120, zoom, point_sizes](const IBuffer& buffer, EOptionsColors colors_id, GLShaderProgram& shader) {
|
||||||
|
shader.set_uniform("uniform_color", Options_Colors[static_cast<unsigned int>(colors_id)]);
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
for (const RenderPath& path : buffer.render_paths) {
|
||||||
|
glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.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));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
glsafe(::glCullFace(GL_BACK));
|
glsafe(::glCullFace(GL_BACK));
|
||||||
glsafe(::glLineWidth(3.0f));
|
glsafe(::glLineWidth(3.0f));
|
||||||
|
|
||||||
|
@ -773,146 +793,32 @@ void GCodeViewer::render_toolpaths() const
|
||||||
{
|
{
|
||||||
case GCodeProcessor::EMoveType::Tool_change:
|
case GCodeProcessor::EMoveType::Tool_change:
|
||||||
{
|
{
|
||||||
shader->set_uniform("uniform_color", Options_Colors[static_cast<unsigned int>(EOptionsColors::ToolChanges)]);
|
render_options(buffer, EOptionsColors::ToolChanges, *shader);
|
||||||
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));
|
|
||||||
}
|
|
||||||
for (const RenderPath& path : buffer.render_paths)
|
|
||||||
{
|
|
||||||
glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.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;
|
break;
|
||||||
}
|
}
|
||||||
case GCodeProcessor::EMoveType::Color_change:
|
case GCodeProcessor::EMoveType::Color_change:
|
||||||
{
|
{
|
||||||
shader->set_uniform("uniform_color", Options_Colors[static_cast<unsigned int>(EOptionsColors::ColorChanges)]);
|
render_options(buffer, EOptionsColors::ColorChanges, *shader);
|
||||||
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));
|
|
||||||
}
|
|
||||||
for (const RenderPath& path : buffer.render_paths)
|
|
||||||
{
|
|
||||||
glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.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;
|
break;
|
||||||
}
|
}
|
||||||
case GCodeProcessor::EMoveType::Pause_Print:
|
case GCodeProcessor::EMoveType::Pause_Print:
|
||||||
{
|
{
|
||||||
shader->set_uniform("uniform_color", Options_Colors[static_cast<unsigned int>(EOptionsColors::PausePrints)]);
|
render_options(buffer, EOptionsColors::PausePrints, *shader);
|
||||||
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));
|
|
||||||
}
|
|
||||||
for (const RenderPath& path : buffer.render_paths)
|
|
||||||
{
|
|
||||||
glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.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;
|
break;
|
||||||
}
|
}
|
||||||
case GCodeProcessor::EMoveType::Custom_GCode:
|
case GCodeProcessor::EMoveType::Custom_GCode:
|
||||||
{
|
{
|
||||||
shader->set_uniform("uniform_color", Options_Colors[static_cast<unsigned int>(EOptionsColors::CustomGCodes)]);
|
render_options(buffer, EOptionsColors::CustomGCodes, *shader);
|
||||||
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));
|
|
||||||
}
|
|
||||||
for (const RenderPath& path : buffer.render_paths)
|
|
||||||
{
|
|
||||||
glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.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;
|
break;
|
||||||
}
|
}
|
||||||
case GCodeProcessor::EMoveType::Retract:
|
case GCodeProcessor::EMoveType::Retract:
|
||||||
{
|
{
|
||||||
shader->set_uniform("uniform_color", Options_Colors[static_cast<unsigned int>(EOptionsColors::Retractions)]);
|
render_options(buffer, EOptionsColors::Retractions, *shader);
|
||||||
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));
|
|
||||||
}
|
|
||||||
for (const RenderPath& path : buffer.render_paths)
|
|
||||||
{
|
|
||||||
glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.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;
|
break;
|
||||||
}
|
}
|
||||||
case GCodeProcessor::EMoveType::Unretract:
|
case GCodeProcessor::EMoveType::Unretract:
|
||||||
{
|
{
|
||||||
shader->set_uniform("uniform_color", Options_Colors[static_cast<unsigned int>(EOptionsColors::Unretractions)]);
|
render_options(buffer, EOptionsColors::Unretractions, *shader);
|
||||||
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));
|
|
||||||
}
|
|
||||||
for (const RenderPath& path : buffer.render_paths)
|
|
||||||
{
|
|
||||||
glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.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;
|
break;
|
||||||
}
|
}
|
||||||
case GCodeProcessor::EMoveType::Extrude:
|
case GCodeProcessor::EMoveType::Extrude:
|
||||||
|
|
|
@ -215,6 +215,16 @@ bool GLShaderProgram::set_uniform(const char* name, double value) const
|
||||||
return set_uniform(name, static_cast<float>(value));
|
return set_uniform(name, static_cast<float>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GLShaderProgram::set_uniform(const char* name, const std::array<int, 4>& value) const
|
||||||
|
{
|
||||||
|
int id = get_uniform_location(name);
|
||||||
|
if (id >= 0) {
|
||||||
|
glsafe(::glUniform4iv(id, 1, static_cast<const GLint*>(value.data())));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool GLShaderProgram::set_uniform(const char* name, const std::array<float, 2>& value) const
|
bool GLShaderProgram::set_uniform(const char* name, const std::array<float, 2>& value) const
|
||||||
{
|
{
|
||||||
int id = get_uniform_location(name);
|
int id = get_uniform_location(name);
|
||||||
|
@ -290,6 +300,21 @@ bool GLShaderProgram::set_uniform(const char* name, const Matrix3f& value) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GLShaderProgram::set_uniform(const char* name, const Vec3f& value) const
|
||||||
|
{
|
||||||
|
int id = get_uniform_location(name);
|
||||||
|
if (id >= 0) {
|
||||||
|
glsafe(::glUniform3fv(id, 1, static_cast<const GLfloat*>(value.data())));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GLShaderProgram::set_uniform(const char* name, const Vec3d& value) const
|
||||||
|
{
|
||||||
|
return set_uniform(name, static_cast<Vec3f>(value.cast<float>()));
|
||||||
|
}
|
||||||
|
|
||||||
int GLShaderProgram::get_attrib_location(const char* name) const
|
int GLShaderProgram::get_attrib_location(const char* name) const
|
||||||
{
|
{
|
||||||
return (m_id > 0) ? ::glGetAttribLocation(m_id, name) : -1;
|
return (m_id > 0) ? ::glGetAttribLocation(m_id, name) : -1;
|
||||||
|
|
|
@ -43,6 +43,7 @@ public:
|
||||||
bool set_uniform(const char* name, bool value) const;
|
bool set_uniform(const char* name, bool value) const;
|
||||||
bool set_uniform(const char* name, float value) const;
|
bool set_uniform(const char* name, float value) const;
|
||||||
bool set_uniform(const char* name, double value) const;
|
bool set_uniform(const char* name, double value) const;
|
||||||
|
bool set_uniform(const char* name, const std::array<int, 4>& value) const;
|
||||||
bool set_uniform(const char* name, const std::array<float, 2>& value) const;
|
bool set_uniform(const char* name, const std::array<float, 2>& value) const;
|
||||||
bool set_uniform(const char* name, const std::array<float, 3>& value) const;
|
bool set_uniform(const char* name, const std::array<float, 3>& value) const;
|
||||||
bool set_uniform(const char* name, const std::array<float, 4>& value) const;
|
bool set_uniform(const char* name, const std::array<float, 4>& value) const;
|
||||||
|
@ -50,6 +51,8 @@ public:
|
||||||
bool set_uniform(const char* name, const Transform3f& value) const;
|
bool set_uniform(const char* name, const Transform3f& value) const;
|
||||||
bool set_uniform(const char* name, const Transform3d& value) const;
|
bool set_uniform(const char* name, const Transform3d& value) const;
|
||||||
bool set_uniform(const char* name, const Matrix3f& value) const;
|
bool set_uniform(const char* name, const Matrix3f& value) const;
|
||||||
|
bool set_uniform(const char* name, const Vec3f& value) const;
|
||||||
|
bool set_uniform(const char* name, const Vec3d& value) const;
|
||||||
|
|
||||||
// returns -1 if not found
|
// returns -1 if not found
|
||||||
int get_attrib_location(const char* name) const;
|
int get_attrib_location(const char* name) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue