From 194cab75d9f3dc761e75c80445f11d5b6e21471f Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 1 Apr 2021 08:24:19 +0200 Subject: [PATCH] Refactoring in GCodeViewer --- src/slic3r/GUI/GCodeViewer.cpp | 8 ++++---- src/slic3r/GUI/GCodeViewer.hpp | 31 ++++++++----------------------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 66bdafb56..eacf69c91 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -3756,11 +3756,11 @@ void GCodeViewer::render_toolpaths() const const IBuffer& i_buffer = buffer.indices[j]; glsafe(::glBindBuffer(GL_ARRAY_BUFFER, i_buffer.vbo)); - glsafe(::glVertexPointer(buffer.vertices.position_size_floats(), GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_size())); + glsafe(::glVertexPointer(buffer.vertices.position_size_floats(), GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes())); glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); bool has_normals = buffer.vertices.normal_size_floats() > 0; if (has_normals) { - glsafe(::glNormalPointer(GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_size())); + glsafe(::glNormalPointer(GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes())); glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); } @@ -3802,11 +3802,11 @@ void GCodeViewer::render_toolpaths() const shader->start_using(); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, cap.vbo)); - glsafe(::glVertexPointer(cap.buffer->vertices.position_size_floats(), GL_FLOAT, cap.buffer->vertices.vertex_size_bytes(), (const void*)cap.buffer->vertices.position_offset_size())); + glsafe(::glVertexPointer(cap.buffer->vertices.position_size_floats(), GL_FLOAT, cap.buffer->vertices.vertex_size_bytes(), (const void*)cap.buffer->vertices.position_offset_bytes())); glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); bool has_normals = cap.buffer->vertices.normal_size_floats() > 0; if (has_normals) { - glsafe(::glNormalPointer(GL_FLOAT, cap.buffer->vertices.vertex_size_bytes(), (const void*)cap.buffer->vertices.normal_offset_size())); + glsafe(::glNormalPointer(GL_FLOAT, cap.buffer->vertices.vertex_size_bytes(), (const void*)cap.buffer->vertices.normal_offset_bytes())); glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); } diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index cc897c7bc..051260b72 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -89,35 +89,20 @@ class GCodeViewer size_t vertex_size_bytes() const { return vertex_size_floats() * sizeof(float); } size_t position_offset_floats() const { return 0; } - size_t position_offset_size() const { return position_offset_floats() * sizeof(float); } - size_t position_size_floats() const { - switch (format) - { - case EFormat::Position: - case EFormat::PositionNormal3: { return 3; } - case EFormat::PositionNormal1: { return 4; } - default: { return 0; } - } - } + size_t position_offset_bytes() const { return position_offset_floats() * sizeof(float); } + + size_t position_size_floats() const { return 3; } size_t position_size_bytes() const { return position_size_floats() * sizeof(float); } - size_t normal_offset_floats() const { - switch (format) - { - case EFormat::Position: - case EFormat::PositionNormal1: { return 0; } - case EFormat::PositionNormal3: { return 3; } - default: { return 0; } - } - } - size_t normal_offset_size() const { return normal_offset_floats() * sizeof(float); } + size_t normal_offset_floats() const { return position_size_floats(); } + size_t normal_offset_bytes() const { return normal_offset_floats() * sizeof(float); } + size_t normal_size_floats() const { switch (format) { - default: - case EFormat::Position: - case EFormat::PositionNormal1: { return 0; } + case EFormat::PositionNormal1: { return 1; } case EFormat::PositionNormal3: { return 3; } + default: { return 0; } } } size_t normal_size_bytes() const { return normal_size_floats() * sizeof(float); }