Refactoring in GLModel::render() to simplify client code

This commit is contained in:
enricoturri1966 2021-07-20 12:36:56 +02:00
parent c61785f775
commit fd5cf8d0cc
6 changed files with 20 additions and 34 deletions

View File

@ -161,6 +161,8 @@ void GLModel::render() const
GLShaderProgram* shader = wxGetApp().get_current_shader();
if (shader != nullptr)
shader->set_uniform("uniform_color", data.color);
else
glsafe(::glColor4fv(data.color.data()));
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.ibo_id));
glsafe(::glDrawElements(mode, static_cast<GLsizei>(data.indices_count), GL_UNSIGNED_INT, (const void*)0));

View File

@ -61,11 +61,7 @@ void GLGizmoBase::Grabber::render(float size, const std::array<float, 4>& render
float fullsize = 2 * (dragging ? get_dragging_half_size(size) : get_half_size(size));
GLShaderProgram* shader = picking ? nullptr : wxGetApp().get_current_shader();
if (shader != nullptr)
const_cast<GLModel*>(&cube)->set_color(-1, render_color);
else
glsafe(::glColor4fv(render_color.data())); // picking
const_cast<GLModel*>(&cube)->set_color(-1, render_color);
glsafe(::glPushMatrix());
glsafe(::glTranslated(center.x(), center.y(), center.z()));

View File

@ -118,8 +118,7 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) cons
const sla::DrainHoles& drain_holes = m_c->selection_info()->model_object()->sla_drain_holes;
size_t cache_size = drain_holes.size();
for (size_t i = 0; i < cache_size; ++i)
{
for (size_t i = 0; i < cache_size; ++i) {
const sla::DrainHole& drain_hole = drain_holes[i];
const bool& point_selected = m_selected[i];
@ -129,13 +128,13 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) cons
// First decide about the color of the point.
if (picking) {
std::array<float, 4> color = picking_color_component(i);
render_color = color;
}
else {
if (size_t(m_hover_id) == i) {
render_color = {0.f, 1.f, 1.f, 1.f};
} else if (m_c->hollowed_mesh() &&
}
else if (m_c->hollowed_mesh() &&
i < m_c->hollowed_mesh()->get_drainholes().size() &&
m_c->hollowed_mesh()->get_drainholes()[i].failed) {
render_color = {1.f, 0.f, 0.f, .5f};
@ -149,10 +148,7 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) cons
}
}
if (shader && ! picking)
const_cast<GLModel*>(&m_vbo_cylinder)->set_color(-1 , render_color);
else // picking
glsafe(::glColor4fv(render_color.data()));
const_cast<GLModel*>(&m_vbo_cylinder)->set_color(-1, render_color);
// Inverse matrix of the instance scaling is applied so that the mark does not scale with the object.
glsafe(::glPushMatrix());

View File

@ -205,12 +205,11 @@ void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box
if (shader == nullptr)
return;
if (! picking) {
const_cast<GLModel*>(&m_vbo_cone)->set_color(-1, color);
if (!picking) {
shader->start_using();
shader->set_uniform("emission_factor", 0.1);
const_cast<GLModel*>(&m_vbo_cone)->set_color(-1, color);
} else
glsafe(::glColor4fv(color.data()));
}
glsafe(::glPushMatrix());
glsafe(::glTranslated(m_grabbers[axis].center.x(), m_grabbers[axis].center.y(), m_grabbers[axis].center.z()));

View File

@ -336,13 +336,11 @@ void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool pick
if (shader == nullptr)
return;
if (! picking) {
const_cast<GLModel*>(&m_cone)->set_color(-1, color);
if (!picking) {
shader->start_using();
shader->set_uniform("emission_factor", 0.1);
const_cast<GLModel*>(&m_cone)->set_color(-1, color);
}
else
glsafe(::glColor4fv(color.data()));
glsafe(::glPushMatrix());
glsafe(::glTranslated(m_grabbers[0].center.x(), m_grabbers[0].center.y(), m_grabbers[0].center.z()));

View File

@ -137,8 +137,7 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
glsafe(::glMultMatrixd(instance_matrix.data()));
std::array<float, 4> render_color;
for (size_t i = 0; i < cache_size; ++i)
{
for (size_t i = 0; i < cache_size; ++i) {
const sla::SupportPoint& support_point = m_editing_mode ? m_editing_cache[i].support_point : m_normal_cache[i];
const bool& point_selected = m_editing_mode ? m_editing_cache[i].selected : false;
@ -149,7 +148,7 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
if (picking)
render_color = picking_color_component(i);
else {
if ((size_t(m_hover_id) == i && m_editing_mode)) // ignore hover state unless editing mode is active
if (size_t(m_hover_id) == i && m_editing_mode) // ignore hover state unless editing mode is active
render_color = { 0.f, 1.f, 1.f, 1.f };
else { // neigher hover nor picking
bool supports_new_island = m_lock_unique_islands && support_point.is_new_island;
@ -166,14 +165,11 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
render_color = { 0.5f, 0.5f, 0.5f, 1.f };
}
}
if (shader && ! picking) {
const_cast<GLModel*>(&m_cone)->set_color(-1, render_color);
const_cast<GLModel*>(&m_sphere)->set_color(-1, render_color);
shader->set_uniform("emission_factor", 0.5);
}
else // picking
glsafe(::glColor4fv(render_color.data()));
const_cast<GLModel*>(&m_cone)->set_color(-1, render_color);
const_cast<GLModel*>(&m_sphere)->set_color(-1, render_color);
if (shader && !picking)
shader->set_uniform("emission_factor", 0.5);
// Inverse matrix of the instance scaling is applied so that the mark does not scale with the object.
glsafe(::glPushMatrix());
@ -226,10 +222,9 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
render_color[1] = 0.7f;
render_color[2] = 0.7f;
render_color[3] = 0.7f;
if (shader) {
const_cast<GLModel*>(&m_cylinder)->set_color(-1, render_color);
const_cast<GLModel*>(&m_cylinder)->set_color(-1, render_color);
if (shader)
shader->set_uniform("emission_factor", 0.5);
}
for (const sla::DrainHole& drain_hole : m_c->selection_info()->model_object()->sla_drain_holes) {
if (is_mesh_point_clipped(drain_hole.pos.cast<double>()))
continue;