Skip to content

Commit

Permalink
Tech ENABLE_LEGACY_OPENGL_REMOVAL - Fixed rendering of layer editing …
Browse files Browse the repository at this point in the history
…background on older OpenGL compatibility profile

(cherry picked from commit prusa3d/PrusaSlicer@642f64c)
  • Loading branch information
enricoturri1966 authored and Noisyfox committed Oct 27, 2023
1 parent ccce5aa commit 4b6da10
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 37 deletions.
10 changes: 5 additions & 5 deletions src/slic3r/GUI/GLCanvas3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ void GLCanvas3D::LayersEditing::render_active_object_annotations(const GLCanvas3
m_profile.background.reset();

GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P2T2 };
init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3T2 };
init_data.reserve_vertices(4);
init_data.reserve_indices(6);

Expand All @@ -430,10 +430,10 @@ void GLCanvas3D::LayersEditing::render_active_object_annotations(const GLCanvas3
const float r = 1.0f;
const float t = 1.0f;
const float b = -1.0f;
init_data.add_vertex(Vec2f(l, b), Vec2f(0.0f, 0.0f));
init_data.add_vertex(Vec2f(r, b), Vec2f(1.0f, 0.0f));
init_data.add_vertex(Vec2f(r, t), Vec2f(1.0f, 1.0f));
init_data.add_vertex(Vec2f(l, t), Vec2f(0.0f, 1.0f));
init_data.add_vertex(Vec3f(l, b, 0.0f), Vec3f::UnitZ(), Vec2f(0.0f, 0.0f));
init_data.add_vertex(Vec3f(r, b, 0.0f), Vec3f::UnitZ(), Vec2f(1.0f, 0.0f));
init_data.add_vertex(Vec3f(r, t, 0.0f), Vec3f::UnitZ(), Vec2f(1.0f, 1.0f));
init_data.add_vertex(Vec3f(l, t, 0.0f), Vec3f::UnitZ(), Vec2f(0.0f, 1.0f));

// indices
init_data.add_triangle(0, 1, 2);
Expand Down
75 changes: 49 additions & 26 deletions src/slic3r/GUI/GLModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ void GLModel::Geometry::add_vertex(const Vec3f& position, const Vec3f& normal)
vertices.emplace_back(normal.z());
}

void GLModel::Geometry::add_vertex(const Vec3f& position, const Vec3f& normal, const Vec2f& tex_coord)
{
assert(format.vertex_layout == EVertexLayout::P3N3T2);
vertices.emplace_back(position.x());
vertices.emplace_back(position.y());
vertices.emplace_back(position.z());
vertices.emplace_back(normal.x());
vertices.emplace_back(normal.y());
vertices.emplace_back(normal.z());
vertices.emplace_back(tex_coord.x());
vertices.emplace_back(tex_coord.y());
}

void GLModel::Geometry::add_vertex(const Vec4f& position)
{
assert(format.vertex_layout == EVertexLayout::P4);
Expand Down Expand Up @@ -238,13 +251,14 @@ size_t GLModel::Geometry::vertex_stride_floats(const Format& format)
{
switch (format.vertex_layout)
{
case EVertexLayout::P2: { return 2; }
case EVertexLayout::P2T2: { return 4; }
case EVertexLayout::P3: { return 3; }
case EVertexLayout::P3T2: { return 5; }
case EVertexLayout::P3N3: { return 6; }
case EVertexLayout::P4: { return 4; }
default: { assert(false); return 0; }
case EVertexLayout::P2: { return 2; }
case EVertexLayout::P2T2: { return 4; }
case EVertexLayout::P3: { return 3; }
case EVertexLayout::P3T2: { return 5; }
case EVertexLayout::P3N3: { return 6; }
case EVertexLayout::P3N3T2: { return 8; }
case EVertexLayout::P4: { return 4; }
default: { assert(false); return 0; }
};
}

Expand All @@ -253,12 +267,13 @@ size_t GLModel::Geometry::position_stride_floats(const Format& format)
switch (format.vertex_layout)
{
case EVertexLayout::P2:
case EVertexLayout::P2T2: { return 2; }
case EVertexLayout::P2T2: { return 2; }
case EVertexLayout::P3:
case EVertexLayout::P3T2:
case EVertexLayout::P3N3: { return 3; }
case EVertexLayout::P4: { return 4; }
default: { assert(false); return 0; }
case EVertexLayout::P3N3:
case EVertexLayout::P3N3T2: { return 3; }
case EVertexLayout::P4: { return 4; }
default: { assert(false); return 0; }
};
}

Expand All @@ -271,6 +286,7 @@ size_t GLModel::Geometry::position_offset_floats(const Format& format)
case EVertexLayout::P3:
case EVertexLayout::P3T2:
case EVertexLayout::P3N3:
case EVertexLayout::P3N3T2:
case EVertexLayout::P4: { return 0; }
default: { assert(false); return 0; }
};
Expand All @@ -280,17 +296,19 @@ size_t GLModel::Geometry::normal_stride_floats(const Format& format)
{
switch (format.vertex_layout)
{
case EVertexLayout::P3N3: { return 3; }
default: { assert(false); return 0; }
case EVertexLayout::P3N3:
case EVertexLayout::P3N3T2: { return 3; }
default: { assert(false); return 0; }
};
}

size_t GLModel::Geometry::normal_offset_floats(const Format& format)
{
switch (format.vertex_layout)
{
case EVertexLayout::P3N3: { return 3; }
default: { assert(false); return 0; }
case EVertexLayout::P3N3:
case EVertexLayout::P3N3T2: { return 3; }
default: { assert(false); return 0; }
};
}

Expand All @@ -299,18 +317,20 @@ size_t GLModel::Geometry::tex_coord_stride_floats(const Format& format)
switch (format.vertex_layout)
{
case EVertexLayout::P2T2:
case EVertexLayout::P3T2: { return 2; }
default: { assert(false); return 0; }
case EVertexLayout::P3T2:
case EVertexLayout::P3N3T2: { return 2; }
default: { assert(false); return 0; }
};
}

size_t GLModel::Geometry::tex_coord_offset_floats(const Format& format)
{
switch (format.vertex_layout)
{
case EVertexLayout::P2T2: { return 2; }
case EVertexLayout::P3T2: { return 3; }
default: { assert(false); return 0; }
case EVertexLayout::P2T2: { return 2; }
case EVertexLayout::P3T2: { return 3; }
case EVertexLayout::P3N3T2: { return 6; }
default: { assert(false); return 0; }
};
}

Expand All @@ -334,6 +354,7 @@ bool GLModel::Geometry::has_position(const Format& format)
case EVertexLayout::P3:
case EVertexLayout::P3T2:
case EVertexLayout::P3N3:
case EVertexLayout::P3N3T2:
case EVertexLayout::P4: { return true; }
default: { assert(false); return false; }
};
Expand All @@ -347,9 +368,10 @@ bool GLModel::Geometry::has_normal(const Format& format)
case EVertexLayout::P2T2:
case EVertexLayout::P3:
case EVertexLayout::P3T2:
case EVertexLayout::P4: { return false; }
case EVertexLayout::P3N3: { return true; }
default: { assert(false); return false; }
case EVertexLayout::P4: { return false; }
case EVertexLayout::P3N3:
case EVertexLayout::P3N3T2: { return true; }
default: { assert(false); return false; }
};
}

Expand All @@ -358,12 +380,13 @@ bool GLModel::Geometry::has_tex_coord(const Format& format)
switch (format.vertex_layout)
{
case EVertexLayout::P2T2:
case EVertexLayout::P3T2: { return true; }
case EVertexLayout::P3T2:
case EVertexLayout::P3N3T2: { return true; }
case EVertexLayout::P2:
case EVertexLayout::P3:
case EVertexLayout::P3N3:
case EVertexLayout::P4: { return false; }
default: { assert(false); return false; }
case EVertexLayout::P4: { return false; }
default: { assert(false); return false; }
};
}

Expand Down
14 changes: 8 additions & 6 deletions src/slic3r/GUI/GLModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace GUI {
P3, // position 3 floats
P3T2, // position 3 floats + texture coords 2 floats
P3N3, // position 3 floats + normal 3 floats
P3N3T2, // position 3 floats + normal 3 floats + texture coords 2 floats
P4, // position 4 floats
};

Expand All @@ -66,12 +67,13 @@ namespace GUI {
void reserve_vertices(size_t vertices_count) { vertices.reserve(vertices_count * vertex_stride_floats(format)); }
void reserve_indices(size_t indices_count) { indices.reserve(indices_count); }

void add_vertex(const Vec2f& position); // EVertexLayout::P2
void add_vertex(const Vec2f& position, const Vec2f& tex_coord); // EVertexLayout::P2T2
void add_vertex(const Vec3f& position); // EVertexLayout::P3
void add_vertex(const Vec3f& position, const Vec2f& tex_coord); // EVertexLayout::P3T2
void add_vertex(const Vec3f& position, const Vec3f& normal); // EVertexLayout::P3N3
void add_vertex(const Vec4f& position); // EVertexLayout::P4
void add_vertex(const Vec2f& position); // EVertexLayout::P2
void add_vertex(const Vec2f& position, const Vec2f& tex_coord); // EVertexLayout::P2T2
void add_vertex(const Vec3f& position); // EVertexLayout::P3
void add_vertex(const Vec3f& position, const Vec2f& tex_coord); // EVertexLayout::P3T2
void add_vertex(const Vec3f& position, const Vec3f& normal); // EVertexLayout::P3N3
void add_vertex(const Vec3f& position, const Vec3f& normal, const Vec2f& tex_coord); // EVertexLayout::P3N3T2
void add_vertex(const Vec4f& position); // EVertexLayout::P4

void set_vertex(size_t id, const Vec3f& position, const Vec3f& normal); // EVertexLayout::P3N3

Expand Down

0 comments on commit 4b6da10

Please sign in to comment.