Tech ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - Use vertex attributes and matrices in shaders.

Shader: gouraud_light - Selection sidebar hints
This commit is contained in:
enricoturri1966 2022-03-04 10:52:30 +01:00
parent f7d06f4ec8
commit d6b0a9858b
5 changed files with 174 additions and 33 deletions

View File

@ -320,6 +320,7 @@ void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box
shader->set_uniform("view_model_matrix", view_model_matrix); shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix()); shader->set_uniform("projection_matrix", camera.get_projection_matrix());
shader->set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else #else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(m_grabbers[axis].center.x(), m_grabbers[axis].center.y(), m_grabbers[axis].center.z())); glsafe(::glTranslated(m_grabbers[axis].center.x(), m_grabbers[axis].center.y(), m_grabbers[axis].center.z()));

View File

@ -612,6 +612,7 @@ void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool pick
Geometry::assemble_transform(2.0 * size * Vec3d::UnitZ(), Vec3d::Zero(), Vec3d(0.75 * size, 0.75 * size, 3.0 * size)); Geometry::assemble_transform(2.0 * size * Vec3d::UnitZ(), Vec3d::Zero(), Vec3d(0.75 * size, 0.75 * size, 3.0 * size));
shader->set_uniform("view_model_matrix", view_model_matrix); shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else #else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(center.x(), center.y(), center.z())); glsafe(::glTranslated(center.x(), center.y(), center.z()));
@ -627,6 +628,7 @@ void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool pick
Geometry::assemble_transform(2.0 * size * Vec3d::UnitZ(), Vec3d::Zero(), Vec3d(0.75 * size, 0.75 * size, 3.0 * size)); Geometry::assemble_transform(2.0 * size * Vec3d::UnitZ(), Vec3d::Zero(), Vec3d(0.75 * size, 0.75 * size, 3.0 * size));
shader->set_uniform("view_model_matrix", view_model_matrix); shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else #else
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());

View File

@ -753,6 +753,7 @@ void GLGizmoSimplify::on_render()
const Transform3d view_model_matrix = camera.get_view_matrix() * trafo_matrix; const Transform3d view_model_matrix = camera.get_view_matrix() * trafo_matrix;
gouraud_shader->set_uniform("view_model_matrix", view_model_matrix); gouraud_shader->set_uniform("view_model_matrix", view_model_matrix);
gouraud_shader->set_uniform("projection_matrix", camera.get_projection_matrix()); gouraud_shader->set_uniform("projection_matrix", camera.get_projection_matrix());
gouraud_shader->set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glmodel.render(); glmodel.render();
gouraud_shader->stop_using(); gouraud_shader->stop_using();

View File

@ -1325,7 +1325,7 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field)
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader(boost::starts_with(sidebar_field, "layer") ? "flat_attr" : "gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader(boost::starts_with(sidebar_field, "layer") ? "flat_attr" : "gouraud_light_attr");
#else #else
GLShaderProgram* shader = wxGetApp().get_shader(boost::starts_with(sidebar_field, "layer") ? "flat" : "gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader(boost::starts_with(sidebar_field, "layer") ? "flat" : "gouraud_light");
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
@ -1349,16 +1349,26 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field)
glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_DEPTH_TEST));
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (!boost::starts_with(sidebar_field, "layer")) const Transform3d base_matrix = Geometry::assemble_transform(get_bounding_box().center());
Transform3d orient_matrix = Transform3d::Identity();
#else
glsafe(::glPushMatrix());
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glsafe(::glPushMatrix());
if (!boost::starts_with(sidebar_field, "layer")) { if (!boost::starts_with(sidebar_field, "layer")) {
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
shader->set_uniform("emission_factor", 0.05f);
#else
const Vec3d& center = get_bounding_box().center(); const Vec3d& center = get_bounding_box().center();
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (is_single_full_instance() && !wxGetApp().obj_manipul()->get_world_coordinates()) { if (is_single_full_instance() && !wxGetApp().obj_manipul()->get_world_coordinates()) {
#if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glsafe(::glTranslated(center.x(), center.y(), center.z())); glsafe(::glTranslated(center.x(), center.y(), center.z()));
#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (!boost::starts_with(sidebar_field, "position")) { if (!boost::starts_with(sidebar_field, "position")) {
#if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
Transform3d orient_matrix = Transform3d::Identity(); Transform3d orient_matrix = Transform3d::Identity();
#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (boost::starts_with(sidebar_field, "scale")) if (boost::starts_with(sidebar_field, "scale"))
orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true);
else if (boost::starts_with(sidebar_field, "rotation")) { else if (boost::starts_with(sidebar_field, "rotation")) {
@ -1366,30 +1376,42 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field)
orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true);
else if (boost::ends_with(sidebar_field, "y")) { else if (boost::ends_with(sidebar_field, "y")) {
const Vec3d& rotation = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_rotation(); const Vec3d& rotation = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_rotation();
if (rotation(0) == 0.0) if (rotation.x() == 0.0)
orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true);
else else
orient_matrix.rotate(Eigen::AngleAxisd(rotation(2), Vec3d::UnitZ())); orient_matrix.rotate(Eigen::AngleAxisd(rotation.z(), Vec3d::UnitZ()));
} }
} }
#if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glsafe(::glMultMatrixd(orient_matrix.data())); glsafe(::glMultMatrixd(orient_matrix.data()));
#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
} }
} }
else if (is_single_volume() || is_single_modifier()) { else if (is_single_volume() || is_single_modifier()) {
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true);
#else
glsafe(::glTranslated(center.x(), center.y(), center.z())); glsafe(::glTranslated(center.x(), center.y(), center.z()));
Transform3d orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); Transform3d orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true);
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (!boost::starts_with(sidebar_field, "position")) if (!boost::starts_with(sidebar_field, "position"))
orient_matrix = orient_matrix * (*m_volumes)[*m_list.begin()]->get_volume_transformation().get_matrix(true, false, true, true); orient_matrix = orient_matrix * (*m_volumes)[*m_list.begin()]->get_volume_transformation().get_matrix(true, false, true, true);
#if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glsafe(::glMultMatrixd(orient_matrix.data())); glsafe(::glMultMatrixd(orient_matrix.data()));
#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
} }
else { else {
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (requires_local_axes())
orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true);
#else
glsafe(::glTranslated(center.x(), center.y(), center.z())); glsafe(::glTranslated(center.x(), center.y(), center.z()));
if (requires_local_axes()) { if (requires_local_axes()) {
const Transform3d orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); const Transform3d orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true);
glsafe(::glMultMatrixd(orient_matrix.data())); glsafe(::glMultMatrixd(orient_matrix.data()));
} }
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
} }
} }
@ -1398,6 +1420,16 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field)
glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (boost::starts_with(sidebar_field, "position"))
render_sidebar_position_hints(sidebar_field, *shader, base_matrix * orient_matrix);
else if (boost::starts_with(sidebar_field, "rotation"))
render_sidebar_rotation_hints(sidebar_field, *shader, base_matrix * orient_matrix);
else if (boost::starts_with(sidebar_field, "scale") || boost::starts_with(sidebar_field, "size"))
render_sidebar_scale_hints(sidebar_field, *shader, base_matrix * orient_matrix);
else if (boost::starts_with(sidebar_field, "layer"))
render_sidebar_layers_hints(sidebar_field, *shader);
#else
if (boost::starts_with(sidebar_field, "position")) if (boost::starts_with(sidebar_field, "position"))
render_sidebar_position_hints(sidebar_field); render_sidebar_position_hints(sidebar_field);
else if (boost::starts_with(sidebar_field, "rotation")) else if (boost::starts_with(sidebar_field, "rotation"))
@ -1405,16 +1437,10 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field)
else if (boost::starts_with(sidebar_field, "scale") || boost::starts_with(sidebar_field, "size")) else if (boost::starts_with(sidebar_field, "scale") || boost::starts_with(sidebar_field, "size"))
render_sidebar_scale_hints(sidebar_field); render_sidebar_scale_hints(sidebar_field);
else if (boost::starts_with(sidebar_field, "layer")) else if (boost::starts_with(sidebar_field, "layer"))
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
render_sidebar_layers_hints(sidebar_field, shader);
#else
render_sidebar_layers_hints(sidebar_field); render_sidebar_layers_hints(sidebar_field);
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES glsafe(::glPopMatrix());
if (!boost::starts_with(sidebar_field, "layer"))
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix());
#if !ENABLE_GLBEGIN_GLEND_REMOVAL #if !ENABLE_GLBEGIN_GLEND_REMOVAL
if (!boost::starts_with(sidebar_field, "layer")) if (!boost::starts_with(sidebar_field, "layer"))
@ -1424,7 +1450,7 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field)
bool Selection::requires_local_axes() const bool Selection::requires_local_axes() const
{ {
return (m_mode == Volume) && is_from_single_instance(); return m_mode == Volume && is_from_single_instance();
} }
void Selection::copy_to_clipboard() void Selection::copy_to_clipboard()
@ -1434,8 +1460,7 @@ void Selection::copy_to_clipboard()
m_clipboard.reset(); m_clipboard.reset();
for (const ObjectIdxsToInstanceIdxsMap::value_type& object : m_cache.content) for (const ObjectIdxsToInstanceIdxsMap::value_type& object : m_cache.content) {
{
ModelObject* src_object = m_model->objects[object.first]; ModelObject* src_object = m_model->objects[object.first];
ModelObject* dst_object = m_clipboard.add_object(); ModelObject* dst_object = m_clipboard.add_object();
dst_object->name = src_object->name; dst_object->name = src_object->name;
@ -1448,26 +1473,22 @@ void Selection::copy_to_clipboard()
dst_object->layer_height_profile.assign(src_object->layer_height_profile); dst_object->layer_height_profile.assign(src_object->layer_height_profile);
dst_object->origin_translation = src_object->origin_translation; dst_object->origin_translation = src_object->origin_translation;
for (int i : object.second) for (int i : object.second) {
{
dst_object->add_instance(*src_object->instances[i]); dst_object->add_instance(*src_object->instances[i]);
} }
for (unsigned int i : m_list) for (unsigned int i : m_list) {
{
// Copy the ModelVolumes only for the selected GLVolumes of the 1st selected instance. // Copy the ModelVolumes only for the selected GLVolumes of the 1st selected instance.
const GLVolume* volume = (*m_volumes)[i]; const GLVolume* volume = (*m_volumes)[i];
if ((volume->object_idx() == object.first) && (volume->instance_idx() == *object.second.begin())) if (volume->object_idx() == object.first && volume->instance_idx() == *object.second.begin()) {
{
int volume_idx = volume->volume_idx(); int volume_idx = volume->volume_idx();
if ((0 <= volume_idx) && (volume_idx < (int)src_object->volumes.size())) if (0 <= volume_idx && volume_idx < (int)src_object->volumes.size()) {
{
ModelVolume* src_volume = src_object->volumes[volume_idx]; ModelVolume* src_volume = src_object->volumes[volume_idx];
ModelVolume* dst_volume = dst_object->add_volume(*src_volume); ModelVolume* dst_volume = dst_object->add_volume(*src_volume);
dst_volume->set_new_unique_id(); dst_volume->set_new_unique_id();
} else {
assert(false);
} }
else
assert(false);
} }
} }
} }
@ -2060,20 +2081,46 @@ static ColorRGBA get_color(Axis axis)
return AXES_COLOR[axis]; return AXES_COLOR[axis];
} }
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
void Selection::render_sidebar_position_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix)
#else
void Selection::render_sidebar_position_hints(const std::string& sidebar_field) void Selection::render_sidebar_position_hints(const std::string& sidebar_field)
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
{ {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d view_matrix = camera.get_view_matrix() * matrix;
shader.set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (boost::ends_with(sidebar_field, "x")) { if (boost::ends_with(sidebar_field, "x")) {
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
const Transform3d view_model_matrix = view_matrix * Geometry::assemble_transform(Vec3d::Zero(), -0.5 * PI * Vec3d::UnitZ());
shader.set_uniform("view_model_matrix", view_model_matrix);
shader.set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glRotated(-90.0, 0.0, 0.0, 1.0)); glsafe(::glRotated(-90.0, 0.0, 0.0, 1.0));
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
m_arrow.set_color(get_color(X)); m_arrow.set_color(get_color(X));
m_arrow.render(); m_arrow.render();
} }
else if (boost::ends_with(sidebar_field, "y")) { else if (boost::ends_with(sidebar_field, "y")) {
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
shader.set_uniform("view_model_matrix", view_matrix);
shader.set_uniform("normal_matrix", (Matrix3d)view_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
m_arrow.set_color(get_color(Y)); m_arrow.set_color(get_color(Y));
m_arrow.render(); m_arrow.render();
} }
else if (boost::ends_with(sidebar_field, "z")) { else if (boost::ends_with(sidebar_field, "z")) {
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
const Transform3d view_model_matrix = view_matrix * Geometry::assemble_transform(Vec3d::Zero(), 0.5 * PI * Vec3d::UnitX());
shader.set_uniform("view_model_matrix", view_model_matrix);
shader.set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glRotated(90.0, 1.0, 0.0, 0.0)); glsafe(::glRotated(90.0, 1.0, 0.0, 0.0));
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
m_arrow.set_color(get_color(Z)); m_arrow.set_color(get_color(Z));
m_arrow.render(); m_arrow.render();
} }
@ -2095,28 +2142,65 @@ void Selection::render_sidebar_position_hints(const std::string& sidebar_field)
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
} }
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix)
#else
void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field) void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field)
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
{ {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
auto render_sidebar_rotation_hint = [this](GLShaderProgram& shader, const Transform3d& matrix) {
Transform3d view_model_matrix = matrix;
shader.set_uniform("view_model_matrix", view_model_matrix);
shader.set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
m_curved_arrow.render();
view_model_matrix = matrix * Geometry::assemble_transform(Vec3d::Zero(), PI * Vec3d::UnitZ());
shader.set_uniform("view_model_matrix", view_model_matrix);
shader.set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
m_curved_arrow.render();
};
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d view_matrix = camera.get_view_matrix() * matrix;
shader.set_uniform("projection_matrix", camera.get_projection_matrix());
#else
auto render_sidebar_rotation_hint = [this]() { auto render_sidebar_rotation_hint = [this]() {
m_curved_arrow.render(); m_curved_arrow.render();
glsafe(::glRotated(180.0, 0.0, 0.0, 1.0)); glsafe(::glRotated(180.0, 0.0, 0.0, 1.0));
m_curved_arrow.render(); m_curved_arrow.render();
}; };
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (boost::ends_with(sidebar_field, "x")) { if (boost::ends_with(sidebar_field, "x")) {
#if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glsafe(::glRotated(90.0, 0.0, 1.0, 0.0)); glsafe(::glRotated(90.0, 0.0, 1.0, 0.0));
#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
m_curved_arrow.set_color(get_color(X)); m_curved_arrow.set_color(get_color(X));
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
render_sidebar_rotation_hint(shader, view_matrix * Geometry::assemble_transform(Vec3d::Zero(), 0.5 * PI * Vec3d::UnitY()));
#else
render_sidebar_rotation_hint(); render_sidebar_rotation_hint();
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
} }
else if (boost::ends_with(sidebar_field, "y")) { else if (boost::ends_with(sidebar_field, "y")) {
#if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0)); glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0));
#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
m_curved_arrow.set_color(get_color(Y)); m_curved_arrow.set_color(get_color(Y));
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
render_sidebar_rotation_hint(shader, view_matrix * Geometry::assemble_transform(Vec3d::Zero(), -0.5 * PI * Vec3d::UnitX()));
#else
render_sidebar_rotation_hint(); render_sidebar_rotation_hint();
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
} }
else if (boost::ends_with(sidebar_field, "z")) { else if (boost::ends_with(sidebar_field, "z")) {
m_curved_arrow.set_color(get_color(Z)); m_curved_arrow.set_color(get_color(Z));
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
render_sidebar_rotation_hint(shader, view_matrix);
#else
render_sidebar_rotation_hint(); render_sidebar_rotation_hint();
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
} }
#else #else
auto render_sidebar_rotation_hint = [this]() { auto render_sidebar_rotation_hint = [this]() {
@ -2142,51 +2226,90 @@ void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field)
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
} }
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
void Selection::render_sidebar_scale_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix)
#else
void Selection::render_sidebar_scale_hints(const std::string& sidebar_field) void Selection::render_sidebar_scale_hints(const std::string& sidebar_field)
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
{ {
bool uniform_scale = requires_uniform_scale() || wxGetApp().obj_manipul()->get_uniform_scaling(); const bool uniform_scale = requires_uniform_scale() || wxGetApp().obj_manipul()->get_uniform_scaling();
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
auto render_sidebar_scale_hint = [this, uniform_scale](Axis axis, GLShaderProgram& shader, const Transform3d& matrix) {
#else
auto render_sidebar_scale_hint = [this, uniform_scale](Axis axis) { auto render_sidebar_scale_hint = [this, uniform_scale](Axis axis) {
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
m_arrow.set_color(uniform_scale ? UNIFORM_SCALE_COLOR : get_color(axis)); m_arrow.set_color(uniform_scale ? UNIFORM_SCALE_COLOR : get_color(axis));
#else #else
m_arrow.set_color(-1, uniform_scale ? UNIFORM_SCALE_COLOR : get_color(axis)); m_arrow.set_color(-1, uniform_scale ? UNIFORM_SCALE_COLOR : get_color(axis));
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
Transform3d view_model_matrix = matrix * Geometry::assemble_transform(5.0 * Vec3d::UnitY());
shader.set_uniform("view_model_matrix", view_model_matrix);
shader.set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
GLShaderProgram* shader = wxGetApp().get_current_shader(); GLShaderProgram* shader = wxGetApp().get_current_shader();
if (shader != nullptr) if (shader != nullptr)
shader->set_uniform("emission_factor", 0.0f); shader->set_uniform("emission_factor", 0.0f);
glsafe(::glTranslated(0.0, 5.0, 0.0)); glsafe(::glTranslated(0.0, 5.0, 0.0));
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
m_arrow.render(); m_arrow.render();
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
view_model_matrix = matrix * Geometry::assemble_transform(-5.0 * Vec3d::UnitY(), PI * Vec3d::UnitZ());
shader.set_uniform("view_model_matrix", view_model_matrix);
shader.set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose());
#else
glsafe(::glTranslated(0.0, -10.0, 0.0)); glsafe(::glTranslated(0.0, -10.0, 0.0));
glsafe(::glRotated(180.0, 0.0, 0.0, 1.0)); glsafe(::glRotated(180.0, 0.0, 0.0, 1.0));
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
m_arrow.render(); m_arrow.render();
}; };
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d view_matrix = camera.get_view_matrix() * matrix;
shader.set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (boost::ends_with(sidebar_field, "x") || uniform_scale) { if (boost::ends_with(sidebar_field, "x") || uniform_scale) {
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
render_sidebar_scale_hint(X, shader, view_matrix * Geometry::assemble_transform(Vec3d::Zero(), -0.5 * PI * Vec3d::UnitZ()));
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glRotated(-90.0, 0.0, 0.0, 1.0)); glsafe(::glRotated(-90.0, 0.0, 0.0, 1.0));
render_sidebar_scale_hint(X); render_sidebar_scale_hint(X);
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
} }
if (boost::ends_with(sidebar_field, "y") || uniform_scale) { if (boost::ends_with(sidebar_field, "y") || uniform_scale) {
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
render_sidebar_scale_hint(Y, shader, view_matrix);
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
render_sidebar_scale_hint(Y); render_sidebar_scale_hint(Y);
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
} }
if (boost::ends_with(sidebar_field, "z") || uniform_scale) { if (boost::ends_with(sidebar_field, "z") || uniform_scale) {
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
render_sidebar_scale_hint(Z, shader, view_matrix * Geometry::assemble_transform(Vec3d::Zero(), 0.5 * PI * Vec3d::UnitX()));
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glRotated(90.0, 1.0, 0.0, 0.0)); glsafe(::glRotated(90.0, 1.0, 0.0, 0.0));
render_sidebar_scale_hint(Z); render_sidebar_scale_hint(Z);
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
} }
} }
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
void Selection::render_sidebar_layers_hints(const std::string& sidebar_field, GLShaderProgram* shader) void Selection::render_sidebar_layers_hints(const std::string& sidebar_field, GLShaderProgram& shader)
#else #else
void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) void Selection::render_sidebar_layers_hints(const std::string& sidebar_field)
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
@ -2289,8 +2412,8 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field)
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera(); const Camera& camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix()); shader.set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix()); shader.set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
m_planes.models[0].set_color((camera_on_top && type == 1) || (!camera_on_top && type == 2) ? SOLID_PLANE_COLOR : TRANSPARENT_PLANE_COLOR); m_planes.models[0].set_color((camera_on_top && type == 1) || (!camera_on_top && type == 2) ? SOLID_PLANE_COLOR : TRANSPARENT_PLANE_COLOR);

View File

@ -376,14 +376,28 @@ private:
void render_selected_volumes() const; void render_selected_volumes() const;
void render_bounding_box(const BoundingBoxf3& box, float* color) const; void render_bounding_box(const BoundingBoxf3& box, float* color) const;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
void render_sidebar_position_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix);
void render_sidebar_rotation_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix);
void render_sidebar_scale_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix);
void render_sidebar_layers_hints(const std::string& sidebar_field, GLShaderProgram& shader);
#else
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void render_sidebar_position_hints(const std::string& sidebar_field); void render_sidebar_position_hints(const std::string& sidebar_field);
void render_sidebar_rotation_hints(const std::string& sidebar_field); void render_sidebar_rotation_hints(const std::string& sidebar_field);
void render_sidebar_scale_hints(const std::string& sidebar_field); void render_sidebar_scale_hints(const std::string& sidebar_field);
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
void render_sidebar_layers_hints(const std::string& sidebar_field, GLShaderProgram* shader);
#else
void render_sidebar_layers_hints(const std::string& sidebar_field); void render_sidebar_layers_hints(const std::string& sidebar_field);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
// void render_sidebar_layers_hints(const std::string& sidebar_field, GLShaderProgram& shader);
//#else
// void render_sidebar_layers_hints(const std::string& sidebar_field);
//#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public: public:
enum SyncRotationType { enum SyncRotationType {