mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-11-02 20:51:23 -07:00 
			
		
		
		
	Render picking pass renders volumes in the same order as the regular render pass
This commit is contained in:
		
							parent
							
								
									ffde525100
								
							
						
					
					
						commit
						e61be7d260
					
				
					 4 changed files with 41 additions and 41 deletions
				
			
		| 
						 | 
				
			
			@ -721,32 +721,31 @@ int GLVolumeCollection::load_wipe_tower_preview(
 | 
			
		|||
    return int(this->volumes.size() - 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
typedef std::pair<GLVolume*, double> GLVolumeWithZ;
 | 
			
		||||
typedef std::vector<GLVolumeWithZ> GLVolumesWithZList;
 | 
			
		||||
static GLVolumesWithZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCollection::ERenderType type, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func)
 | 
			
		||||
GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCollection::ERenderType type, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func)
 | 
			
		||||
{
 | 
			
		||||
    GLVolumesWithZList list;
 | 
			
		||||
    GLVolumeWithIdAndZList list;
 | 
			
		||||
    list.reserve(volumes.size());
 | 
			
		||||
 | 
			
		||||
    for (GLVolume* volume : volumes)
 | 
			
		||||
    for (unsigned int i = 0; i < (unsigned int)volumes.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        GLVolume* volume = volumes[i];
 | 
			
		||||
        bool is_transparent = (volume->render_color[3] < 1.0f);
 | 
			
		||||
        if ((((type == GLVolumeCollection::Opaque) && !is_transparent) ||
 | 
			
		||||
             ((type == GLVolumeCollection::Transparent) && is_transparent) ||
 | 
			
		||||
             (type == GLVolumeCollection::All)) &&
 | 
			
		||||
            (! filter_func || filter_func(*volume)))
 | 
			
		||||
            list.emplace_back(std::make_pair(volume, 0.0));
 | 
			
		||||
            list.emplace_back(std::make_pair(volume, std::make_pair(i, 0.0)));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if ((type == GLVolumeCollection::Transparent) && (list.size() > 1))
 | 
			
		||||
    {
 | 
			
		||||
        for (GLVolumeWithZ& volume : list)
 | 
			
		||||
        for (GLVolumeWithIdAndZ& volume : list)
 | 
			
		||||
        {
 | 
			
		||||
            volume.second = volume.first->bounding_box.transformed(view_matrix * volume.first->world_matrix()).max(2);
 | 
			
		||||
            volume.second.second = volume.first->bounding_box.transformed(view_matrix * volume.first->world_matrix()).max(2);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        std::sort(list.begin(), list.end(),
 | 
			
		||||
            [](const GLVolumeWithZ& v1, const GLVolumeWithZ& v2) -> bool { return v1.second < v2.second; }
 | 
			
		||||
            [](const GLVolumeWithIdAndZ& v1, const GLVolumeWithIdAndZ& v2) -> bool { return v1.second.second < v2.second.second; }
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -784,8 +783,8 @@ void GLVolumeCollection::render_VBOs(GLVolumeCollection::ERenderType type, bool
 | 
			
		|||
    if (z_range_id != -1)
 | 
			
		||||
        glsafe(::glUniform2fv(z_range_id, 1, (const GLfloat*)z_range));
 | 
			
		||||
 | 
			
		||||
    GLVolumesWithZList to_render = volumes_to_render(this->volumes, type, view_matrix, filter_func);
 | 
			
		||||
    for (GLVolumeWithZ& volume : to_render) {
 | 
			
		||||
    GLVolumeWithIdAndZList to_render = volumes_to_render(this->volumes, type, view_matrix, filter_func);
 | 
			
		||||
    for (GLVolumeWithIdAndZ& volume : to_render) {
 | 
			
		||||
        volume.first->set_render_color();
 | 
			
		||||
        volume.first->render_VBOs(color_id, print_box_detection_id, print_box_worldmatrix_id);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -814,8 +813,8 @@ void GLVolumeCollection::render_legacy(ERenderType type, bool disable_cullface,
 | 
			
		|||
    glsafe(::glEnableClientState(GL_VERTEX_ARRAY));
 | 
			
		||||
    glsafe(::glEnableClientState(GL_NORMAL_ARRAY));
 | 
			
		||||
 
 | 
			
		||||
    GLVolumesWithZList to_render = volumes_to_render(this->volumes, type, view_matrix, filter_func);
 | 
			
		||||
    for (GLVolumeWithZ& volume : to_render)
 | 
			
		||||
    GLVolumeWithIdAndZList to_render = volumes_to_render(this->volumes, type, view_matrix, filter_func);
 | 
			
		||||
    for (GLVolumeWithIdAndZ& volume : to_render)
 | 
			
		||||
    {
 | 
			
		||||
        volume.first->set_render_color();
 | 
			
		||||
        volume.first->render_legacy();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -412,6 +412,8 @@ public:
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
typedef std::vector<GLVolume*> GLVolumePtrs;
 | 
			
		||||
typedef std::pair<GLVolume*, std::pair<unsigned int, double>> GLVolumeWithIdAndZ;
 | 
			
		||||
typedef std::vector<GLVolumeWithIdAndZ> GLVolumeWithIdAndZList;
 | 
			
		||||
 | 
			
		||||
class GLVolumeCollection
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -505,6 +507,8 @@ private:
 | 
			
		|||
    GLVolumeCollection& operator=(const GLVolumeCollection &);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCollection::ERenderType type, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func = nullptr);
 | 
			
		||||
 | 
			
		||||
class GLModel
 | 
			
		||||
{
 | 
			
		||||
protected:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3490,7 +3490,7 @@ void GLCanvas3D::_picking_pass() const
 | 
			
		|||
 | 
			
		||||
        glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
 | 
			
		||||
 | 
			
		||||
        _render_volumes(true);
 | 
			
		||||
        _render_volumes_for_picking();
 | 
			
		||||
        m_gizmos.render_current_gizmo_for_picking_pass(m_selection);
 | 
			
		||||
 | 
			
		||||
        if (m_multisample_allowed)
 | 
			
		||||
| 
						 | 
				
			
			@ -3675,13 +3675,10 @@ void GLCanvas3D::_render_legend_texture() const
 | 
			
		|||
    m_legend_texture.render(*this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void GLCanvas3D::_render_volumes(bool fake_colors) const
 | 
			
		||||
void GLCanvas3D::_render_volumes_for_picking() const
 | 
			
		||||
{
 | 
			
		||||
    static const GLfloat INV_255 = 1.0f / 255.0f;
 | 
			
		||||
 | 
			
		||||
    if (!fake_colors)
 | 
			
		||||
        glsafe(::glEnable(GL_LIGHTING));
 | 
			
		||||
 | 
			
		||||
    // do not cull backfaces to show broken geometry, if any
 | 
			
		||||
    glsafe(::glDisable(GL_CULL_FACE));
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -3691,27 +3688,31 @@ void GLCanvas3D::_render_volumes(bool fake_colors) const
 | 
			
		|||
    glsafe(::glEnableClientState(GL_VERTEX_ARRAY));
 | 
			
		||||
    glsafe(::glEnableClientState(GL_NORMAL_ARRAY));
 | 
			
		||||
 | 
			
		||||
    unsigned int volume_id = 0;
 | 
			
		||||
    for (GLVolume* vol : m_volumes.volumes)
 | 
			
		||||
    const Transform3d& view_matrix = m_camera.get_view_matrix();
 | 
			
		||||
    GLVolumeWithIdAndZList to_render = volumes_to_render(m_volumes.volumes, GLVolumeCollection::Opaque, view_matrix);
 | 
			
		||||
    for (const GLVolumeWithIdAndZ& volume : to_render)
 | 
			
		||||
    {
 | 
			
		||||
        if (fake_colors)
 | 
			
		||||
        {
 | 
			
		||||
            // Object picking mode. Render the object with a color encoding the object index.
 | 
			
		||||
            unsigned int r = (volume_id & 0x000000FF) >> 0;
 | 
			
		||||
            unsigned int g = (volume_id & 0x0000FF00) >> 8;
 | 
			
		||||
            unsigned int b = (volume_id & 0x00FF0000) >> 16;
 | 
			
		||||
            glsafe(::glColor3f((GLfloat)r * INV_255, (GLfloat)g * INV_255, (GLfloat)b * INV_255));
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            vol->set_render_color();
 | 
			
		||||
            glsafe(::glColor4fv(vol->render_color));
 | 
			
		||||
        }
 | 
			
		||||
        // Object picking mode. Render the object with a color encoding the object index.
 | 
			
		||||
        unsigned int r = (volume.second.first & 0x000000FF) >> 0;
 | 
			
		||||
        unsigned int g = (volume.second.first & 0x0000FF00) >> 8;
 | 
			
		||||
        unsigned int b = (volume.second.first & 0x00FF0000) >> 16;
 | 
			
		||||
        glsafe(::glColor3f((GLfloat)r * INV_255, (GLfloat)g * INV_255, (GLfloat)b * INV_255));
 | 
			
		||||
 | 
			
		||||
        if ((!fake_colors || !vol->disabled) && (vol->composite_id.volume_id >= 0 || m_render_sla_auxiliaries))
 | 
			
		||||
            vol->render();
 | 
			
		||||
        if (!volume.first->disabled && ((volume.first->composite_id.volume_id >= 0) || m_render_sla_auxiliaries))
 | 
			
		||||
            volume.first->render();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        ++volume_id;
 | 
			
		||||
    to_render = volumes_to_render(m_volumes.volumes, GLVolumeCollection::Transparent, view_matrix);
 | 
			
		||||
    for (const GLVolumeWithIdAndZ& volume : to_render)
 | 
			
		||||
    {
 | 
			
		||||
        // Object picking mode. Render the object with a color encoding the object index.
 | 
			
		||||
        unsigned int r = (volume.second.first & 0x000000FF) >> 0;
 | 
			
		||||
        unsigned int g = (volume.second.first & 0x0000FF00) >> 8;
 | 
			
		||||
        unsigned int b = (volume.second.first & 0x00FF0000) >> 16;
 | 
			
		||||
        glsafe(::glColor3f((GLfloat)r * INV_255, (GLfloat)g * INV_255, (GLfloat)b * INV_255));
 | 
			
		||||
 | 
			
		||||
        if (!volume.first->disabled && ((volume.first->composite_id.volume_id >= 0) || m_render_sla_auxiliaries))
 | 
			
		||||
            volume.first->render();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    glsafe(::glDisableClientState(GL_NORMAL_ARRAY));
 | 
			
		||||
| 
						 | 
				
			
			@ -3719,9 +3720,6 @@ void GLCanvas3D::_render_volumes(bool fake_colors) const
 | 
			
		|||
    glsafe(::glDisable(GL_BLEND));
 | 
			
		||||
 | 
			
		||||
    glsafe(::glEnable(GL_CULL_FACE));
 | 
			
		||||
 | 
			
		||||
    if (!fake_colors)
 | 
			
		||||
        glsafe(::glDisable(GL_LIGHTING));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void GLCanvas3D::_render_current_gizmo() const
 | 
			
		||||
| 
						 | 
				
			
			@ -3999,7 +3997,6 @@ void GLCanvas3D::_update_volumes_hover_state() const
 | 
			
		|||
        return;
 | 
			
		||||
 | 
			
		||||
    GLVolume* volume = m_volumes.volumes[m_hover_volume_id];
 | 
			
		||||
 | 
			
		||||
    switch (m_selection.get_mode())
 | 
			
		||||
    {
 | 
			
		||||
    case Selection::Volume:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -605,7 +605,7 @@ private:
 | 
			
		|||
#endif // ENABLE_RENDER_SELECTION_CENTER
 | 
			
		||||
    void _render_warning_texture() const;
 | 
			
		||||
    void _render_legend_texture() const;
 | 
			
		||||
    void _render_volumes(bool fake_colors) const;
 | 
			
		||||
    void _render_volumes_for_picking() const;
 | 
			
		||||
    void _render_current_gizmo() const;
 | 
			
		||||
    void _render_gizmos_overlay() const;
 | 
			
		||||
    void _render_toolbar() const;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue