Tech ENABLE_GLBEGIN_GLEND_REMOVAL - A few fixes in layers editing profile rendering

This commit is contained in:
enricoturri1966 2022-01-27 15:19:29 +01:00
parent 5db3c66cf7
commit 8c807dbcc4
5 changed files with 38 additions and 72 deletions

View File

@ -99,49 +99,6 @@ float RetinaHelper::get_scale_factor() { return float(m_window->GetContentScaleF
#undef Convex #undef Convex
#endif #endif
Size::Size()
: m_width(0)
, m_height(0)
{
}
Size::Size(int width, int height, float scale_factor)
: m_width(width)
, m_height(height)
, m_scale_factor(scale_factor)
{
}
int Size::get_width() const
{
return m_width;
}
void Size::set_width(int width)
{
m_width = width;
}
int Size::get_height() const
{
return m_height;
}
void Size::set_height(int height)
{
m_height = height;
}
int Size::get_scale_factor() const
{
return m_scale_factor;
}
void Size::set_scale_factor(int scale_factor)
{
m_scale_factor = scale_factor;
}
GLCanvas3D::LayersEditing::~LayersEditing() GLCanvas3D::LayersEditing::~LayersEditing()
{ {
if (m_z_texture_id != 0) { if (m_z_texture_id != 0) {
@ -418,7 +375,6 @@ void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect)
// Make the vertical bar a bit wider so the layer height curve does not touch the edge of the bar region. // Make the vertical bar a bit wider so the layer height curve does not touch the edge of the bar region.
const float scale_x = bar_rect.get_width() / float(1.12 * m_slicing_parameters->max_layer_height); const float scale_x = bar_rect.get_width() / float(1.12 * m_slicing_parameters->max_layer_height);
const float scale_y = bar_rect.get_height() / m_object_max_z; const float scale_y = bar_rect.get_height() / m_object_max_z;
const float x = bar_rect.get_left() + float(m_slicing_parameters->layer_height) * scale_x;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
const bool bar_rect_changed = m_profile.old_bar_rect != bar_rect; const bool bar_rect_changed = m_profile.old_bar_rect != bar_rect;
@ -426,17 +382,18 @@ void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect)
// Baseline // Baseline
if (!m_profile.baseline.is_initialized() || bar_rect_changed) { if (!m_profile.baseline.is_initialized() || bar_rect_changed) {
m_profile.old_bar_rect = bar_rect; m_profile.baseline.reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P2, GLModel::Geometry::EIndexType::USHORT };
init_data.color = ColorRGBA::BLACK(); init_data.color = ColorRGBA::BLACK();
init_data.vertices.reserve(2 * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.vertices.reserve(2 * GLModel::Geometry::vertex_stride_floats(init_data.format));
init_data.indices.reserve(2 * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.indices.reserve(2 * GLModel::Geometry::index_stride_bytes(init_data.format));
// vertices // vertices
init_data.add_vertex(Vec3f(x, bar_rect.get_bottom(), 0.0f)); const float x = bar_rect.get_left() + float(m_slicing_parameters->layer_height) * scale_x;
init_data.add_vertex(Vec3f(x, bar_rect.get_top(), 0.0f)); init_data.add_vertex(Vec2f(x, bar_rect.get_bottom()));
init_data.add_vertex(Vec2f(x, bar_rect.get_top()));
// indices // indices
init_data.add_ushort_line(0, 1); init_data.add_ushort_line(0, 1);
@ -449,16 +406,15 @@ void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect)
m_profile.profile.reset(); m_profile.profile.reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::LineStrip, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::UINT }; init_data.format = { GLModel::Geometry::EPrimitiveType::LineStrip, GLModel::Geometry::EVertexLayout::P2, GLModel::Geometry::EIndexType::UINT };
init_data.color = ColorRGBA::BLUE(); init_data.color = ColorRGBA::BLUE();
init_data.vertices.reserve(m_layer_height_profile.size() * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.vertices.reserve(m_layer_height_profile.size() * GLModel::Geometry::vertex_stride_floats(init_data.format));
init_data.indices.reserve(m_layer_height_profile.size() * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.indices.reserve(m_layer_height_profile.size() * GLModel::Geometry::index_stride_bytes(init_data.format));
// vertices + indices // vertices + indices
for (unsigned int i = 0; i < (unsigned int)m_layer_height_profile.size(); i += 2) { for (unsigned int i = 0; i < (unsigned int)m_layer_height_profile.size(); i += 2) {
init_data.add_vertex(Vec3f(bar_rect.get_left() + float(m_layer_height_profile[i + 1]) * scale_x, init_data.add_vertex(Vec2f(bar_rect.get_left() + float(m_layer_height_profile[i + 1]) * scale_x,
bar_rect.get_bottom() + float(m_layer_height_profile[i]) * scale_y, bar_rect.get_bottom() + float(m_layer_height_profile[i]) * scale_y));
0.0f));
init_data.add_uint_index(i / 2); init_data.add_uint_index(i / 2);
} }
@ -473,6 +429,8 @@ void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect)
shader->stop_using(); shader->stop_using();
} }
#else #else
const float x = bar_rect.get_left() + float(m_slicing_parameters->layer_height) * scale_x;
// Baseline // Baseline
glsafe(::glColor3f(0.0f, 0.0f, 0.0f)); glsafe(::glColor3f(0.0f, 0.0f, 0.0f));
::glBegin(GL_LINE_STRIP); ::glBegin(GL_LINE_STRIP);

View File

@ -59,25 +59,24 @@ class RetinaHelper;
class Size class Size
{ {
int m_width; int m_width{ 0 };
int m_height; int m_height{ 0 };
float m_scale_factor; float m_scale_factor{ 1.0f };
public: public:
Size(); Size() = default;
Size(int width, int height, float scale_factor = 1.0); Size(int width, int height, float scale_factor = 1.0f) : m_width(width), m_height(height), m_scale_factor(scale_factor) {}
int get_width() const; int get_width() const { return m_width; }
void set_width(int width); void set_width(int width) { m_width = width; }
int get_height() const; int get_height() const { return m_height; }
void set_height(int height); void set_height(int height) { m_height = height; }
int get_scale_factor() const; float get_scale_factor() const { return m_scale_factor; }
void set_scale_factor(int height); void set_scale_factor(float factor) { m_scale_factor = factor; }
}; };
class RenderTimerEvent : public wxEvent class RenderTimerEvent : public wxEvent
{ {
public: public:

View File

@ -356,8 +356,11 @@ void GLModel::init_from(const Geometry& data)
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
{ {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
if (is_initialized()) // call reset() if you want to reuse this model if (is_initialized()) {
// call reset() if you want to reuse this model
assert(false);
return; return;
}
if (data.vertices.empty() || data.indices.empty()) { if (data.vertices.empty() || data.indices.empty()) {
assert(false); assert(false);
@ -427,8 +430,11 @@ void GLModel::init_from(const indexed_triangle_set& its, const BoundingBoxf3 &bb
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
{ {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
if (is_initialized()) // call reset() if you want to reuse this model if (is_initialized()) {
// call reset() if you want to reuse this model
assert(false);
return; return;
}
if (its.vertices.empty() || its.indices.empty()){ if (its.vertices.empty() || its.indices.empty()){
assert(false); assert(false);
@ -500,8 +506,11 @@ void GLModel::init_from(const indexed_triangle_set& its)
void GLModel::init_from(const Polygons& polygons, float z) void GLModel::init_from(const Polygons& polygons, float z)
{ {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
if (is_initialized()) // call reset() if you want to reuse this model if (is_initialized()) {
// call reset() if you want to reuse this model
assert(false);
return; return;
}
if (polygons.empty()) { if (polygons.empty()) {
assert(false); assert(false);
@ -582,7 +591,8 @@ bool GLModel::init_from_file(const std::string& filename)
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
init_from(model.mesh()); init_from(model.mesh());
#else #else
init_from(model.mesh().its, mesh.bounding_box()); const TriangleMesh& mesh = model.mesh();
init_from(mesh.its, mesh.bounding_box());
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
m_filename = filename; m_filename = filename;

View File

@ -34,8 +34,7 @@ std::pair<bool, std::string> GLShadersManager::init()
bool valid = true; bool valid = true;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
// basic shader, used to render selection bbox, gizmo cut plane and grabbers connections, // basic shader, used to render all what was previously rendered using the immediate mode
// gizmo move grabbers connections, gizmo scale grabbers connections
valid &= append_shader("flat", { "flat.vs", "flat.fs" }); valid &= append_shader("flat", { "flat.vs", "flat.fs" });
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
// used to render bed axes and model, selection hints, gcode sequential view marker model, preview shells, options in gcode preview // used to render bed axes and model, selection hints, gcode sequential view marker model, preview shells, options in gcode preview

View File

@ -35,14 +35,14 @@ public:
Rect(float left, float top, float right, float bottom) : m_left(left) , m_top(top) , m_right(right) , m_bottom(bottom) {} Rect(float left, float top, float right, float bottom) : m_left(left) , m_top(top) , m_right(right) , m_bottom(bottom) {}
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
bool operator == (const Rect& other) { bool operator == (const Rect& other) const {
if (std::abs(m_left - other.m_left) > EPSILON) return false; if (std::abs(m_left - other.m_left) > EPSILON) return false;
if (std::abs(m_top - other.m_top) > EPSILON) return false; if (std::abs(m_top - other.m_top) > EPSILON) return false;
if (std::abs(m_right - other.m_right) > EPSILON) return false; if (std::abs(m_right - other.m_right) > EPSILON) return false;
if (std::abs(m_bottom - other.m_bottom) > EPSILON) return false; if (std::abs(m_bottom - other.m_bottom) > EPSILON) return false;
return true; return true;
} }
bool operator != (const Rect& other) { return !operator==(other); } bool operator != (const Rect& other) const { return !operator==(other); }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
float get_left() const { return m_left; } float get_left() const { return m_left; }