mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-11-02 20:51:23 -07:00 
			
		
		
		
	Reduced count of opengl draw calls for full 3D transform
This commit is contained in:
		
							parent
							
								
									a651f5f5d7
								
							
						
					
					
						commit
						51cf964b51
					
				
					 3 changed files with 19 additions and 45 deletions
				
			
		| 
						 | 
				
			
			@ -445,13 +445,11 @@ void GLVolume::render() const
 | 
			
		|||
 | 
			
		||||
    ::glCullFace(GL_BACK);
 | 
			
		||||
    ::glPushMatrix();
 | 
			
		||||
    ::glTranslated(m_offset(0), m_offset(1), m_offset(2));
 | 
			
		||||
 | 
			
		||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
    ::glRotated(m_rotation(2) * 180.0 / (double)PI, 0.0, 0.0, 1.0);
 | 
			
		||||
    ::glRotated(m_rotation(1) * 180.0 / (double)PI, 0.0, 1.0, 0.0);
 | 
			
		||||
    ::glRotated(m_rotation(0) * 180.0 / (double)PI, 1.0, 0.0, 0.0);
 | 
			
		||||
    ::glScaled(m_scaling_factor(0), m_scaling_factor(1), m_scaling_factor(2));
 | 
			
		||||
    ::glMultMatrixf(world_matrix().data());
 | 
			
		||||
#else
 | 
			
		||||
    ::glTranslated(m_offset(0), m_offset(1), m_offset(2));
 | 
			
		||||
    ::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
 | 
			
		||||
    ::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
 | 
			
		||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
| 
						 | 
				
			
			@ -578,13 +576,11 @@ void GLVolume::render_VBOs(int color_id, int detection_id, int worldmatrix_id) c
 | 
			
		|||
    ::glNormalPointer(GL_FLOAT, 6 * sizeof(float), nullptr);
 | 
			
		||||
 | 
			
		||||
    ::glPushMatrix();
 | 
			
		||||
    ::glTranslated(m_offset(0), m_offset(1), m_offset(2));
 | 
			
		||||
 | 
			
		||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
    ::glRotated(m_rotation(2) * 180.0 / (double)PI, 0.0, 0.0, 1.0);
 | 
			
		||||
    ::glRotated(m_rotation(1) * 180.0 / (double)PI, 0.0, 1.0, 0.0);
 | 
			
		||||
    ::glRotated(m_rotation(0) * 180.0 / (double)PI, 1.0, 0.0, 0.0);
 | 
			
		||||
    ::glScaled(m_scaling_factor(0), m_scaling_factor(1), m_scaling_factor(2));
 | 
			
		||||
    ::glMultMatrixf(world_matrix().data());
 | 
			
		||||
#else
 | 
			
		||||
    ::glTranslated(m_offset(0), m_offset(1), m_offset(2));
 | 
			
		||||
    ::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
 | 
			
		||||
    ::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
 | 
			
		||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
| 
						 | 
				
			
			@ -630,13 +626,11 @@ void GLVolume::render_legacy() const
 | 
			
		|||
    ::glNormalPointer(GL_FLOAT, 6 * sizeof(float), indexed_vertex_array.vertices_and_normals_interleaved.data());
 | 
			
		||||
 | 
			
		||||
    ::glPushMatrix();
 | 
			
		||||
    ::glTranslated(m_offset(0), m_offset(1), m_offset(2));
 | 
			
		||||
 | 
			
		||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
    ::glRotated(m_rotation(2) * 180.0 / (double)PI, 0.0, 0.0, 1.0);
 | 
			
		||||
    ::glRotated(m_rotation(1) * 180.0 / (double)PI, 0.0, 1.0, 0.0);
 | 
			
		||||
    ::glRotated(m_rotation(0) * 180.0 / (double)PI, 1.0, 0.0, 0.0);
 | 
			
		||||
    ::glScaled(m_scaling_factor(0), m_scaling_factor(1), m_scaling_factor(2));
 | 
			
		||||
    ::glMultMatrixf(world_matrix().data());
 | 
			
		||||
#else
 | 
			
		||||
    ::glTranslated(m_offset(0), m_offset(1), m_offset(2));
 | 
			
		||||
    ::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
 | 
			
		||||
    ::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
 | 
			
		||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -769,13 +769,7 @@ void GLGizmoScale3D::on_update(const Linef3& mouse_ray)
 | 
			
		|||
#if ENABLE_GIZMOS_RESET
 | 
			
		||||
void GLGizmoScale3D::on_process_double_click()
 | 
			
		||||
{
 | 
			
		||||
    if ((m_hover_id == 0) || (m_hover_id == 1))
 | 
			
		||||
        m_scale(0) = 1.0;
 | 
			
		||||
    else if ((m_hover_id == 2) || (m_hover_id == 3))
 | 
			
		||||
        m_scale(1) = 1.0;
 | 
			
		||||
    else if ((m_hover_id == 4) || (m_hover_id == 5))
 | 
			
		||||
        m_scale(2) = 1.0;
 | 
			
		||||
    else if (m_hover_id >= 6)
 | 
			
		||||
    if (m_hover_id >= 6)
 | 
			
		||||
        m_scale = Vec3d::Ones();
 | 
			
		||||
}
 | 
			
		||||
#endif // ENABLE_GIZMOS_RESET
 | 
			
		||||
| 
						 | 
				
			
			@ -1265,19 +1259,14 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const
 | 
			
		|||
 | 
			
		||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
        for (const InstanceData& inst : m_instances) {
 | 
			
		||||
            Vec3d position = inst.position + dragged_offset;
 | 
			
		||||
            Transform3d m = inst.matrix;
 | 
			
		||||
            m.pretranslate(dragged_offset);
 | 
			
		||||
            ::glPushMatrix();
 | 
			
		||||
            ::glMultMatrixd(m.data());
 | 
			
		||||
#else
 | 
			
		||||
        for (Vec2d offset : m_instances_positions) {
 | 
			
		||||
            offset += to_2d(dragged_offset);
 | 
			
		||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
            ::glPushMatrix();
 | 
			
		||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
            ::glTranslated(position(0), position(1), position(2));
 | 
			
		||||
            ::glRotated(inst.rotation(2) * 180.0 / (double)PI, 0.0, 0.0, 1.0);
 | 
			
		||||
            ::glRotated(inst.rotation(1) * 180.0 / (double)PI, 0.0, 1.0, 0.0);
 | 
			
		||||
            ::glRotated(inst.rotation(0) * 180.0 / (double)PI, 1.0, 0.0, 0.0);
 | 
			
		||||
            ::glScaled(inst.scaling_factor(0), inst.scaling_factor(1), inst.scaling_factor(2));
 | 
			
		||||
#else
 | 
			
		||||
            ::glTranslatef((GLfloat)offset(0), (GLfloat)offset(1), 0.0f);
 | 
			
		||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
            ::glBegin(GL_POLYGON);
 | 
			
		||||
| 
						 | 
				
			
			@ -1300,17 +1289,11 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const
 | 
			
		|||
        ::glColor3f(1.0f, 1.0f, picking_color_component(i));
 | 
			
		||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
        for (const InstanceData& inst : m_instances) {
 | 
			
		||||
            ::glPushMatrix();
 | 
			
		||||
            ::glMultMatrixd(inst.matrix.data());
 | 
			
		||||
#else
 | 
			
		||||
        for (const Vec2d& offset : m_instances_positions) {
 | 
			
		||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
            ::glPushMatrix();
 | 
			
		||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
            ::glTranslated(inst.position(0), inst.position(1), inst.position(2));
 | 
			
		||||
            ::glRotated(inst.rotation(2) * 180.0 / (double)PI, 0.0, 0.0, 1.0);
 | 
			
		||||
            ::glRotated(inst.rotation(1) * 180.0 / (double)PI, 0.0, 1.0, 0.0);
 | 
			
		||||
            ::glRotated(inst.rotation(0) * 180.0 / (double)PI, 1.0, 0.0, 0.0);
 | 
			
		||||
            ::glScaled(inst.scaling_factor(0), inst.scaling_factor(1), inst.scaling_factor(2));
 | 
			
		||||
#else
 | 
			
		||||
            ::glTranslatef((GLfloat)offset(0), (GLfloat)offset(1), 0.0f);
 | 
			
		||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
            ::glBegin(GL_POLYGON);
 | 
			
		||||
| 
						 | 
				
			
			@ -1335,7 +1318,7 @@ void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object)
 | 
			
		|||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
        for (const auto* instance : m_model_object->instances)
 | 
			
		||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
            m_instances.emplace_back(instance->get_offset(), instance->get_rotation(), instance->get_scaling_factor());
 | 
			
		||||
            m_instances.emplace_back(instance->world_matrix());
 | 
			
		||||
#else
 | 
			
		||||
            m_instances_positions.emplace_back(instance->offset);
 | 
			
		||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -368,11 +368,8 @@ private:
 | 
			
		|||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | 
			
		||||
    struct InstanceData
 | 
			
		||||
    {
 | 
			
		||||
        Vec3d position;
 | 
			
		||||
        Vec3d rotation;
 | 
			
		||||
        Vec3d scaling_factor;
 | 
			
		||||
 | 
			
		||||
        InstanceData(const Vec3d& position, const Vec3d& rotation, const Vec3d& scaling_factor) : position(position), rotation(rotation), scaling_factor(scaling_factor) {}
 | 
			
		||||
        Transform3d matrix;
 | 
			
		||||
        InstanceData(const Transform3d& matrix) : matrix(matrix) {}
 | 
			
		||||
    };
 | 
			
		||||
    std::vector<InstanceData> m_instances;
 | 
			
		||||
#else
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue