mirror of
https://git.mirrors.martin98.com/https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-16 08:25:56 +08:00
Reduced count of opengl draw calls for full 3D transform
This commit is contained in:
parent
a651f5f5d7
commit
51cf964b51
@ -445,13 +445,11 @@ void GLVolume::render() const
|
|||||||
|
|
||||||
::glCullFace(GL_BACK);
|
::glCullFace(GL_BACK);
|
||||||
::glPushMatrix();
|
::glPushMatrix();
|
||||||
::glTranslated(m_offset(0), m_offset(1), m_offset(2));
|
|
||||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||||
::glRotated(m_rotation(2) * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
::glMultMatrixf(world_matrix().data());
|
||||||
::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));
|
|
||||||
#else
|
#else
|
||||||
|
::glTranslated(m_offset(0), m_offset(1), m_offset(2));
|
||||||
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
||||||
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
|
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
#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);
|
::glNormalPointer(GL_FLOAT, 6 * sizeof(float), nullptr);
|
||||||
|
|
||||||
::glPushMatrix();
|
::glPushMatrix();
|
||||||
::glTranslated(m_offset(0), m_offset(1), m_offset(2));
|
|
||||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||||
::glRotated(m_rotation(2) * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
::glMultMatrixf(world_matrix().data());
|
||||||
::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));
|
|
||||||
#else
|
#else
|
||||||
|
::glTranslated(m_offset(0), m_offset(1), m_offset(2));
|
||||||
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
||||||
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
|
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
#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());
|
::glNormalPointer(GL_FLOAT, 6 * sizeof(float), indexed_vertex_array.vertices_and_normals_interleaved.data());
|
||||||
|
|
||||||
::glPushMatrix();
|
::glPushMatrix();
|
||||||
::glTranslated(m_offset(0), m_offset(1), m_offset(2));
|
|
||||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||||
::glRotated(m_rotation(2) * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
::glMultMatrixf(world_matrix().data());
|
||||||
::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));
|
|
||||||
#else
|
#else
|
||||||
|
::glTranslated(m_offset(0), m_offset(1), m_offset(2));
|
||||||
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
||||||
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
|
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||||
|
@ -769,13 +769,7 @@ void GLGizmoScale3D::on_update(const Linef3& mouse_ray)
|
|||||||
#if ENABLE_GIZMOS_RESET
|
#if ENABLE_GIZMOS_RESET
|
||||||
void GLGizmoScale3D::on_process_double_click()
|
void GLGizmoScale3D::on_process_double_click()
|
||||||
{
|
{
|
||||||
if ((m_hover_id == 0) || (m_hover_id == 1))
|
if (m_hover_id >= 6)
|
||||||
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)
|
|
||||||
m_scale = Vec3d::Ones();
|
m_scale = Vec3d::Ones();
|
||||||
}
|
}
|
||||||
#endif // ENABLE_GIZMOS_RESET
|
#endif // ENABLE_GIZMOS_RESET
|
||||||
@ -1265,19 +1259,14 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const
|
|||||||
|
|
||||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||||
for (const InstanceData& inst : m_instances) {
|
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
|
#else
|
||||||
for (Vec2d offset : m_instances_positions) {
|
for (Vec2d offset : m_instances_positions) {
|
||||||
offset += to_2d(dragged_offset);
|
offset += to_2d(dragged_offset);
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
|
||||||
::glPushMatrix();
|
::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);
|
::glTranslatef((GLfloat)offset(0), (GLfloat)offset(1), 0.0f);
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||||
::glBegin(GL_POLYGON);
|
::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));
|
::glColor3f(1.0f, 1.0f, picking_color_component(i));
|
||||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||||
for (const InstanceData& inst : m_instances) {
|
for (const InstanceData& inst : m_instances) {
|
||||||
|
::glPushMatrix();
|
||||||
|
::glMultMatrixd(inst.matrix.data());
|
||||||
#else
|
#else
|
||||||
for (const Vec2d& offset : m_instances_positions) {
|
for (const Vec2d& offset : m_instances_positions) {
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
|
||||||
::glPushMatrix();
|
::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);
|
::glTranslatef((GLfloat)offset(0), (GLfloat)offset(1), 0.0f);
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||||
::glBegin(GL_POLYGON);
|
::glBegin(GL_POLYGON);
|
||||||
@ -1335,7 +1318,7 @@ void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object)
|
|||||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||||
for (const auto* instance : m_model_object->instances)
|
for (const auto* instance : m_model_object->instances)
|
||||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
#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
|
#else
|
||||||
m_instances_positions.emplace_back(instance->offset);
|
m_instances_positions.emplace_back(instance->offset);
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||||
|
@ -368,11 +368,8 @@ private:
|
|||||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||||
struct InstanceData
|
struct InstanceData
|
||||||
{
|
{
|
||||||
Vec3d position;
|
Transform3d matrix;
|
||||||
Vec3d rotation;
|
InstanceData(const Transform3d& matrix) : matrix(matrix) {}
|
||||||
Vec3d scaling_factor;
|
|
||||||
|
|
||||||
InstanceData(const Vec3d& position, const Vec3d& rotation, const Vec3d& scaling_factor) : position(position), rotation(rotation), scaling_factor(scaling_factor) {}
|
|
||||||
};
|
};
|
||||||
std::vector<InstanceData> m_instances;
|
std::vector<InstanceData> m_instances;
|
||||||
#else
|
#else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user