Tech ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - Use vertex attributes and matrices in shaders.

Shader: gouraud_light - Gizmo Hollow
This commit is contained in:
enricoturri1966 2022-03-03 14:01:34 +01:00
parent bceeb67c53
commit 919730e969

View File

@ -105,17 +105,13 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking)
{ {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
GLShaderProgram* shader = picking ? wxGetApp().get_shader("flat_attr") : wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = picking ? wxGetApp().get_shader("flat_attr") : wxGetApp().get_shader("gouraud_light_attr");
#else #else
GLShaderProgram* shader = picking ? wxGetApp().get_shader("flat") : wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = picking ? wxGetApp().get_shader("flat") : wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
bool use_attributes = boost::algorithm::iends_with(shader->get_name(), "_attr");
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
shader->start_using(); shader->start_using();
ScopeGuard guard([shader]() { shader->stop_using(); }); ScopeGuard guard([shader]() { shader->stop_using(); });
#else #else
@ -129,19 +125,17 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking)
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
const Transform3d instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse(); const Transform3d instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse();
const Transform3d instance_matrix = Geometry::assemble_transform(m_c->selection_info()->get_sla_shift() * Vec3d::UnitZ()) * vol->get_instance_transformation().get_matrix(); const Transform3d instance_matrix = Geometry::assemble_transform(m_c->selection_info()->get_sla_shift() * Vec3d::UnitZ()) * vol->get_instance_transformation().get_matrix();
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d& view_matrix = camera.get_view_matrix();
const Transform3d& projection_matrix = camera.get_projection_matrix();
#else #else
const Transform3d& instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse(); const Transform3d& instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse();
const Transform3d& instance_matrix = vol->get_instance_transformation().get_matrix(); const Transform3d& instance_matrix = vol->get_instance_transformation().get_matrix();
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (!use_attributes) {
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(0.0, 0.0, m_c->selection_info()->get_sla_shift())); glsafe(::glTranslated(0.0, 0.0, m_c->selection_info()->get_sla_shift()));
glsafe(::glMultMatrixd(instance_matrix.data())); glsafe(::glMultMatrixd(instance_matrix.data()));
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
}
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
ColorRGBA render_color; ColorRGBA render_color;
@ -179,13 +173,10 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking)
// Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object.
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
const Transform3d hole_matrix = Geometry::assemble_transform(drain_hole.pos.cast<double>()) * instance_scaling_matrix_inverse; const Transform3d hole_matrix = Geometry::assemble_transform(drain_hole.pos.cast<double>()) * instance_scaling_matrix_inverse;
if (!use_attributes) { #else
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslatef(drain_hole.pos.x(), drain_hole.pos.y(), drain_hole.pos.z())); glsafe(::glTranslatef(drain_hole.pos.x(), drain_hole.pos.y(), drain_hole.pos.z()));
glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data())); glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data()));
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
}
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (vol->is_left_handed()) if (vol->is_left_handed())
@ -196,35 +187,33 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking)
q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * (-drain_hole.normal).cast<double>()); q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * (-drain_hole.normal).cast<double>());
const Eigen::AngleAxisd aa(q); const Eigen::AngleAxisd aa(q);
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (use_attributes) { const Transform3d view_model_matrix = view_matrix * instance_matrix * hole_matrix * Transform3d(aa.toRotationMatrix()) *
const Transform3d matrix = wxGetApp().plater()->get_camera().get_projection_view_matrix() * instance_matrix *
hole_matrix * Transform3d(aa.toRotationMatrix()) *
Geometry::assemble_transform(-drain_hole.height * Vec3d::UnitZ(), Vec3d::Zero(), Vec3d(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength)); Geometry::assemble_transform(-drain_hole.height * Vec3d::UnitZ(), Vec3d::Zero(), Vec3d(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength));
shader->set_uniform("projection_view_model_matrix", matrix);
} // normal render
else { shader->set_uniform("view_model_matrix", view_model_matrix);
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES shader->set_uniform("projection_matrix", projection_matrix);
shader->set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
// picking render
shader->set_uniform("projection_view_model_matrix", projection_matrix * view_model_matrix);
#else
glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z())); glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z()));
glsafe(::glTranslated(0., 0., -drain_hole.height)); glsafe(::glTranslated(0., 0., -drain_hole.height));
glsafe(::glScaled(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength)); glsafe(::glScaled(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength));
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
}
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
m_cylinder.render(); m_cylinder.render();
if (vol->is_left_handed()) if (vol->is_left_handed())
glFrontFace(GL_CCW); glFrontFace(GL_CCW);
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (!use_attributes)
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
} }
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (!use_attributes)
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
} }
bool GLGizmoHollow::is_mesh_point_clipped(const Vec3d& point) const bool GLGizmoHollow::is_mesh_point_clipped(const Vec3d& point) const