Tech ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - Use vertex attributes and matrices in shaders.

Shader: gouraud_light - GLGizmoBase grabbers
This commit is contained in:
enricoturri1966 2022-03-03 13:04:00 +01:00
parent 14f4345389
commit 14c23a6526
2 changed files with 15 additions and 7 deletions

View File

@ -328,7 +328,6 @@ void GCodeViewer::SequentialView::Marker::render()
shader->start_using(); shader->start_using();
shader->set_uniform("emission_factor", 0.0f); shader->set_uniform("emission_factor", 0.0f);
#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();
const Transform3d matrix = camera.get_view_matrix() * m_world_transform.cast<double>(); const Transform3d matrix = camera.get_view_matrix() * m_world_transform.cast<double>();

View File

@ -41,6 +41,7 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, boo
return; return;
bool use_attributes = boost::algorithm::iends_with(shader->get_name(), "_attr"); bool use_attributes = boost::algorithm::iends_with(shader->get_name(), "_attr");
// assert(use_attributes);
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (!m_cube.is_initialized()) { if (!m_cube.is_initialized()) {
@ -64,12 +65,16 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, boo
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (use_attributes) { const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d trafo = wxGetApp().plater()->get_camera().get_projection_view_matrix() * matrix * const Transform3d view_model_matrix = camera.get_view_matrix() * matrix * Geometry::assemble_transform(center, angles, fullsize * Vec3d::Ones());
Geometry::assemble_transform(center, angles, fullsize * Vec3d::Ones()); const Transform3d& projection_matrix = camera.get_projection_matrix();
shader->set_uniform("projection_view_model_matrix", trafo); // normal render
} shader->set_uniform("view_model_matrix", view_model_matrix);
else { 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);
if (!use_attributes) {
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(center.x(), center.y(), center.z())); glsafe(::glTranslated(center.x(), center.y(), center.z()));
@ -138,7 +143,11 @@ void GLGizmoBase::render_grabbers(const BoundingBoxf3& box) const
void GLGizmoBase::render_grabbers(float size) const void GLGizmoBase::render_grabbers(float size) const
{ {
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
shader->start_using(); shader->start_using();