A few small refactorings
This commit is contained in:
parent
578b80e12c
commit
a9465ddedc
@ -4629,14 +4629,14 @@ void GCodeViewer::render_statistics()
|
|||||||
|
|
||||||
ImGuiWrapper& imgui = *wxGetApp().imgui();
|
ImGuiWrapper& imgui = *wxGetApp().imgui();
|
||||||
|
|
||||||
auto add_time = [this, &imgui](const std::string& label, int64_t time) {
|
auto add_time = [&imgui](const std::string& label, int64_t time) {
|
||||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label);
|
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label);
|
||||||
ImGui::SameLine(offset);
|
ImGui::SameLine(offset);
|
||||||
imgui.text(std::to_string(time) + " ms (" + get_time_dhms(static_cast<float>(time) * 0.001f) + ")");
|
imgui.text(std::to_string(time) + " ms (" + get_time_dhms(static_cast<float>(time) * 0.001f) + ")");
|
||||||
};
|
};
|
||||||
|
|
||||||
auto add_memory = [this, &imgui](const std::string& label, int64_t memory) {
|
auto add_memory = [&imgui](const std::string& label, int64_t memory) {
|
||||||
auto format_string = [memory](const std::string& units, float value) {
|
auto format_string = [memory](const std::string& units, float value) {
|
||||||
return std::to_string(memory) + " bytes (" +
|
return std::to_string(memory) + " bytes (" +
|
||||||
Slic3r::float_to_string_decimal_point(float(memory) * value, 3)
|
Slic3r::float_to_string_decimal_point(float(memory) * value, 3)
|
||||||
+ " " + units + ")";
|
+ " " + units + ")";
|
||||||
@ -4658,7 +4658,7 @@ void GCodeViewer::render_statistics()
|
|||||||
imgui.text(format_string("GB", inv_gb));
|
imgui.text(format_string("GB", inv_gb));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto add_counter = [this, &imgui](const std::string& label, int64_t counter) {
|
auto add_counter = [&imgui](const std::string& label, int64_t counter) {
|
||||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label);
|
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label);
|
||||||
ImGui::SameLine(offset);
|
ImGui::SameLine(offset);
|
||||||
imgui.text(std::to_string(counter));
|
imgui.text(std::to_string(counter));
|
||||||
|
@ -540,7 +540,7 @@ void GLModel::init_from(const indexed_triangle_set& its, const BoundingBoxf3 &bb
|
|||||||
|
|
||||||
// update bounding box
|
// update bounding box
|
||||||
for (size_t i = 0; i < vertices_count(); ++i) {
|
for (size_t i = 0; i < vertices_count(); ++i) {
|
||||||
m_bounding_box.merge(m_render_data.geometry.extract_position_3(i).cast<double>());
|
m_bounding_box.merge(data.extract_position_3(i).cast<double>());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (!m_render_data.empty()) // call reset() if you want to reuse this model
|
if (!m_render_data.empty()) // call reset() if you want to reuse this model
|
||||||
@ -622,7 +622,7 @@ void GLModel::init_from(const Polygons& polygons, float z)
|
|||||||
|
|
||||||
// update bounding box
|
// update bounding box
|
||||||
for (size_t i = 0; i < vertices_count(); ++i) {
|
for (size_t i = 0; i < vertices_count(); ++i) {
|
||||||
m_bounding_box.merge(m_render_data.geometry.extract_position_3(i).cast<double>());
|
m_bounding_box.merge(data.extract_position_3(i).cast<double>());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
auto append_polygon = [](const Polygon& polygon, float z, GUI::GLModel::Geometry& data) {
|
auto append_polygon = [](const Polygon& polygon, float z, GUI::GLModel::Geometry& data) {
|
||||||
@ -1081,31 +1081,32 @@ bool GLModel::send_to_gpu()
|
|||||||
// indices
|
// indices
|
||||||
glsafe(::glGenBuffers(1, &m_render_data.ibo_id));
|
glsafe(::glGenBuffers(1, &m_render_data.ibo_id));
|
||||||
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_render_data.ibo_id));
|
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_render_data.ibo_id));
|
||||||
|
const size_t indices_count = data.indices.size();
|
||||||
if (m_render_data.vertices_count <= 256) {
|
if (m_render_data.vertices_count <= 256) {
|
||||||
// convert indices to unsigned char to save gpu memory
|
// convert indices to unsigned char to save gpu memory
|
||||||
std::vector<unsigned char> reduced_indices(data.indices.size());
|
std::vector<unsigned char> reduced_indices(indices_count);
|
||||||
for (size_t i = 0; i < data.indices.size(); ++i) {
|
for (size_t i = 0; i < indices_count; ++i) {
|
||||||
reduced_indices[i] = (unsigned char)data.indices[i];
|
reduced_indices[i] = (unsigned char)data.indices[i];
|
||||||
}
|
}
|
||||||
data.index_type = Geometry::EIndexType::UBYTE;
|
data.index_type = Geometry::EIndexType::UBYTE;
|
||||||
glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, reduced_indices.size() * sizeof(unsigned char), reduced_indices.data(), GL_STATIC_DRAW));
|
glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_count * sizeof(unsigned char), reduced_indices.data(), GL_STATIC_DRAW));
|
||||||
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
||||||
}
|
}
|
||||||
else if (m_render_data.vertices_count <= 65536) {
|
else if (m_render_data.vertices_count <= 65536) {
|
||||||
// convert indices to unsigned short to save gpu memory
|
// convert indices to unsigned short to save gpu memory
|
||||||
std::vector<unsigned short> reduced_indices(data.indices.size());
|
std::vector<unsigned short> reduced_indices(indices_count);
|
||||||
for (size_t i = 0; i < data.indices.size(); ++i) {
|
for (size_t i = 0; i < data.indices.size(); ++i) {
|
||||||
reduced_indices[i] = (unsigned short)data.indices[i];
|
reduced_indices[i] = (unsigned short)data.indices[i];
|
||||||
}
|
}
|
||||||
data.index_type = Geometry::EIndexType::USHORT;
|
data.index_type = Geometry::EIndexType::USHORT;
|
||||||
glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, reduced_indices.size() * sizeof(unsigned short), reduced_indices.data(), GL_STATIC_DRAW));
|
glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_count * sizeof(unsigned short), reduced_indices.data(), GL_STATIC_DRAW));
|
||||||
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, data.indices_size_bytes(), data.indices.data(), GL_STATIC_DRAW));
|
glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, data.indices_size_bytes(), data.indices.data(), GL_STATIC_DRAW));
|
||||||
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
||||||
}
|
}
|
||||||
m_render_data.indices_count = indices_count();
|
m_render_data.indices_count = indices_count;
|
||||||
data.indices = std::vector<unsigned int>();
|
data.indices = std::vector<unsigned int>();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -223,15 +223,12 @@ void GLGizmoRotate::on_render()
|
|||||||
render_angle();
|
render_angle();
|
||||||
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
|
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
|
||||||
|
|
||||||
#if ENABLE_GL_SHADERS_ATTRIBUTES
|
|
||||||
glsafe(::glPushMatrix());
|
|
||||||
transform_to_local(selection);
|
|
||||||
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
|
|
||||||
|
|
||||||
render_grabber(box);
|
render_grabber(box);
|
||||||
render_grabber_extension(box, false);
|
render_grabber_extension(box, false);
|
||||||
|
|
||||||
|
#if !ENABLE_GL_SHADERS_ATTRIBUTES
|
||||||
glsafe(::glPopMatrix());
|
glsafe(::glPopMatrix());
|
||||||
|
#endif // !ENABLE_GL_SHADERS_ATTRIBUTES
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoRotate::on_render_for_picking()
|
void GLGizmoRotate::on_render_for_picking()
|
||||||
@ -683,8 +680,7 @@ Transform3d GLGizmoRotate::local_transform(const Selection& selection) const
|
|||||||
|
|
||||||
return Geometry::assemble_transform(m_center) * ret;
|
return Geometry::assemble_transform(m_center) * ret;
|
||||||
}
|
}
|
||||||
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
|
#else
|
||||||
|
|
||||||
void GLGizmoRotate::transform_to_local(const Selection& selection) const
|
void GLGizmoRotate::transform_to_local(const Selection& selection) const
|
||||||
{
|
{
|
||||||
glsafe(::glTranslated(m_center.x(), m_center.y(), m_center.z()));
|
glsafe(::glTranslated(m_center.x(), m_center.y(), m_center.z()));
|
||||||
@ -716,6 +712,7 @@ void GLGizmoRotate::transform_to_local(const Selection& selection) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
|
||||||
|
|
||||||
Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray, const Selection& selection) const
|
Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray, const Selection& selection) const
|
||||||
{
|
{
|
||||||
|
@ -108,9 +108,10 @@ private:
|
|||||||
|
|
||||||
#if ENABLE_GL_SHADERS_ATTRIBUTES
|
#if ENABLE_GL_SHADERS_ATTRIBUTES
|
||||||
Transform3d local_transform(const Selection& selection) const;
|
Transform3d local_transform(const Selection& selection) const;
|
||||||
|
#else
|
||||||
|
void transform_to_local(const Selection& selection) const;
|
||||||
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
|
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
|
||||||
|
|
||||||
void transform_to_local(const Selection& selection) const;
|
|
||||||
// returns the intersection of the mouse ray with the plane perpendicular to the gizmo axis, in local coordinate
|
// returns the intersection of the mouse ray with the plane perpendicular to the gizmo axis, in local coordinate
|
||||||
Vec3d mouse_position_in_local_plane(const Linef3& mouse_ray, const Selection& selection) const;
|
Vec3d mouse_position_in_local_plane(const Linef3& mouse_ray, const Selection& selection) const;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user