Tech ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - Use vertex attributes and matrices in shaders.

Shader: flat - Volumes picking pass
This commit is contained in:
enricoturri1966 2022-02-28 12:05:08 +01:00
parent 507dda6641
commit 5b1c9a34d6
4 changed files with 33 additions and 5 deletions

View File

@ -71,7 +71,7 @@
// Enable replace GLIndexedVertexArray with GLModel
#define ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL (1 && ENABLE_GLBEGIN_GLEND_REMOVAL)
// Enable using vertex attributes and matrices in shaders
#define ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES (1 && ENABLE_GLBEGIN_GLEND_REMOVAL)
#define ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES (1 && ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL)
// Enable show non-manifold edges
#define ENABLE_SHOW_NON_MANIFOLD_EDGES (1 && ENABLE_2_5_0_ALPHA1)
// Enable rework of Reload from disk command

View File

@ -703,11 +703,24 @@ void GLVolume::render()
if (!is_active)
return;
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
GLShaderProgram* shader = GUI::wxGetApp().get_current_shader();
if (shader == nullptr)
return;
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (this->is_left_handed())
glFrontFace(GL_CW);
glsafe(::glCullFace(GL_BACK));
glsafe(::glPushMatrix());
glsafe(::glMultMatrixd(world_matrix().data()));
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
bool use_attributes = boost::algorithm::iends_with(shader->get_name(), "_attr");
if (!use_attributes) {
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glsafe(::glPushMatrix());
glsafe(::glMultMatrixd(world_matrix().data()));
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
}
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
if (tverts_range == std::make_pair<size_t, size_t>(0, -1))
@ -718,7 +731,11 @@ void GLVolume::render()
this->indexed_vertex_array.render(this->tverts_range, this->qverts_range);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
glsafe(::glPopMatrix());
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (!use_attributes)
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix());
if (this->is_left_handed())
glFrontFace(GL_CCW);
}

View File

@ -5612,7 +5612,11 @@ void GLCanvas3D::_render_overlays()
void GLCanvas3D::_render_volumes_for_picking() const
{
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (shader == nullptr)
return;
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
@ -5620,8 +5624,10 @@ void GLCanvas3D::_render_volumes_for_picking() const
// do not cull backfaces to show broken geometry, if any
glsafe(::glDisable(GL_CULL_FACE));
#if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glsafe(::glEnableClientState(GL_VERTEX_ARRAY));
glsafe(::glEnableClientState(GL_NORMAL_ARRAY));
#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
const Transform3d& view_matrix = wxGetApp().plater()->get_camera().get_view_matrix();
for (size_t type = 0; type < 2; ++ type) {
@ -5638,6 +5644,10 @@ void GLCanvas3D::_render_volumes_for_picking() const
#else
glsafe(::glColor4fv(picking_decode(id).data()));
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
const Transform3d matrix = wxGetApp().plater()->get_camera().get_projection_view_matrix() * volume.first->world_matrix();
shader->set_uniform("projection_view_model_matrix", matrix);
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
volume.first->render();
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
shader->stop_using();
@ -5645,8 +5655,10 @@ void GLCanvas3D::_render_volumes_for_picking() const
}
}
#if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glsafe(::glDisableClientState(GL_NORMAL_ARRAY));
glsafe(::glDisableClientState(GL_VERTEX_ARRAY));
#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
glsafe(::glEnable(GL_CULL_FACE));
}

View File

@ -960,7 +960,6 @@ void GLModel::render(const std::pair<size_t, size_t>& range)
return;
GLShaderProgram* shader = wxGetApp().get_current_shader();
if (shader == nullptr)
return;