Tech ENABLE_LEGACY_OPENGL_REMOVAL - Fixed rendering of layer editing background on older OpenGL compatibility profile

This commit is contained in:
enricoturri1966 2022-07-13 12:12:35 +02:00
parent e0c8ffc524
commit 642f64cb41
3 changed files with 62 additions and 37 deletions

View File

@ -389,7 +389,7 @@ void GLCanvas3D::LayersEditing::render_active_object_annotations(const GLCanvas3
m_profile.background.reset(); m_profile.background.reset();
GLModel::Geometry init_data; 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_vertices(4);
init_data.reserve_indices(6); init_data.reserve_indices(6);
@ -398,10 +398,10 @@ void GLCanvas3D::LayersEditing::render_active_object_annotations(const GLCanvas3
const float r = 1.0f; const float r = 1.0f;
const float t = 1.0f; const float t = 1.0f;
const float b = -1.0f; const float b = -1.0f;
init_data.add_vertex(Vec2f(l, b), Vec2f(0.0f, 0.0f)); init_data.add_vertex(Vec3f(l, b, 0.0f), Vec3f::UnitZ(), Vec2f(0.0f, 0.0f));
init_data.add_vertex(Vec2f(r, b), Vec2f(1.0f, 0.0f)); init_data.add_vertex(Vec3f(r, b, 0.0f), Vec3f::UnitZ(), Vec2f(1.0f, 0.0f));
init_data.add_vertex(Vec2f(r, t), Vec2f(1.0f, 1.0f)); init_data.add_vertex(Vec3f(r, t, 0.0f), Vec3f::UnitZ(), Vec2f(1.0f, 1.0f));
init_data.add_vertex(Vec2f(l, t), Vec2f(0.0f, 1.0f)); init_data.add_vertex(Vec3f(l, t, 0.0f), Vec3f::UnitZ(), Vec2f(0.0f, 1.0f));
// indices // indices
init_data.add_triangle(0, 1, 2); init_data.add_triangle(0, 1, 2);

View File

@ -112,6 +112,19 @@ void GLModel::Geometry::add_vertex(const Vec3f& position, const Vec3f& normal)
vertices.emplace_back(normal.z()); 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) void GLModel::Geometry::add_vertex(const Vec4f& position)
{ {
assert(format.vertex_layout == EVertexLayout::P4); assert(format.vertex_layout == EVertexLayout::P4);
@ -258,6 +271,7 @@ size_t GLModel::Geometry::vertex_stride_floats(const Format& format)
case EVertexLayout::P3: { return 3; } case EVertexLayout::P3: { return 3; }
case EVertexLayout::P3T2: { return 5; } case EVertexLayout::P3T2: { return 5; }
case EVertexLayout::P3N3: { return 6; } case EVertexLayout::P3N3: { return 6; }
case EVertexLayout::P3N3T2: { return 8; }
case EVertexLayout::P4: { return 4; } case EVertexLayout::P4: { return 4; }
default: { assert(false); return 0; } default: { assert(false); return 0; }
}; };
@ -271,7 +285,8 @@ size_t GLModel::Geometry::position_stride_floats(const Format& format)
case EVertexLayout::P2T2: { return 2; } case EVertexLayout::P2T2: { return 2; }
case EVertexLayout::P3: case EVertexLayout::P3:
case EVertexLayout::P3T2: case EVertexLayout::P3T2:
case EVertexLayout::P3N3: { return 3; } case EVertexLayout::P3N3:
case EVertexLayout::P3N3T2: { return 3; }
case EVertexLayout::P4: { return 4; } case EVertexLayout::P4: { return 4; }
default: { assert(false); return 0; } default: { assert(false); return 0; }
}; };
@ -286,6 +301,7 @@ size_t GLModel::Geometry::position_offset_floats(const Format& format)
case EVertexLayout::P3: case EVertexLayout::P3:
case EVertexLayout::P3T2: case EVertexLayout::P3T2:
case EVertexLayout::P3N3: case EVertexLayout::P3N3:
case EVertexLayout::P3N3T2:
case EVertexLayout::P4: { return 0; } case EVertexLayout::P4: { return 0; }
default: { assert(false); return 0; } default: { assert(false); return 0; }
}; };
@ -295,7 +311,8 @@ size_t GLModel::Geometry::normal_stride_floats(const Format& format)
{ {
switch (format.vertex_layout) switch (format.vertex_layout)
{ {
case EVertexLayout::P3N3: { return 3; } case EVertexLayout::P3N3:
case EVertexLayout::P3N3T2: { return 3; }
default: { assert(false); return 0; } default: { assert(false); return 0; }
}; };
} }
@ -304,7 +321,8 @@ size_t GLModel::Geometry::normal_offset_floats(const Format& format)
{ {
switch (format.vertex_layout) switch (format.vertex_layout)
{ {
case EVertexLayout::P3N3: { return 3; } case EVertexLayout::P3N3:
case EVertexLayout::P3N3T2: { return 3; }
default: { assert(false); return 0; } default: { assert(false); return 0; }
}; };
} }
@ -314,7 +332,8 @@ size_t GLModel::Geometry::tex_coord_stride_floats(const Format& format)
switch (format.vertex_layout) switch (format.vertex_layout)
{ {
case EVertexLayout::P2T2: case EVertexLayout::P2T2:
case EVertexLayout::P3T2: { return 2; } case EVertexLayout::P3T2:
case EVertexLayout::P3N3T2: { return 2; }
default: { assert(false); return 0; } default: { assert(false); return 0; }
}; };
} }
@ -325,6 +344,7 @@ size_t GLModel::Geometry::tex_coord_offset_floats(const Format& format)
{ {
case EVertexLayout::P2T2: { return 2; } case EVertexLayout::P2T2: { return 2; }
case EVertexLayout::P3T2: { return 3; } case EVertexLayout::P3T2: { return 3; }
case EVertexLayout::P3N3T2: { return 6; }
default: { assert(false); return 0; } default: { assert(false); return 0; }
}; };
} }
@ -349,6 +369,7 @@ bool GLModel::Geometry::has_position(const Format& format)
case EVertexLayout::P3: case EVertexLayout::P3:
case EVertexLayout::P3T2: case EVertexLayout::P3T2:
case EVertexLayout::P3N3: case EVertexLayout::P3N3:
case EVertexLayout::P3N3T2:
case EVertexLayout::P4: { return true; } case EVertexLayout::P4: { return true; }
default: { assert(false); return false; } default: { assert(false); return false; }
}; };
@ -363,7 +384,8 @@ bool GLModel::Geometry::has_normal(const Format& format)
case EVertexLayout::P3: case EVertexLayout::P3:
case EVertexLayout::P3T2: case EVertexLayout::P3T2:
case EVertexLayout::P4: { return false; } case EVertexLayout::P4: { return false; }
case EVertexLayout::P3N3: { return true; } case EVertexLayout::P3N3:
case EVertexLayout::P3N3T2: { return true; }
default: { assert(false); return false; } default: { assert(false); return false; }
}; };
} }
@ -373,7 +395,8 @@ bool GLModel::Geometry::has_tex_coord(const Format& format)
switch (format.vertex_layout) switch (format.vertex_layout)
{ {
case EVertexLayout::P2T2: case EVertexLayout::P2T2:
case EVertexLayout::P3T2: { return true; } case EVertexLayout::P3T2:
case EVertexLayout::P3N3T2: { return true; }
case EVertexLayout::P2: case EVertexLayout::P2:
case EVertexLayout::P3: case EVertexLayout::P3:
case EVertexLayout::P3N3: case EVertexLayout::P3N3:

View File

@ -63,6 +63,7 @@ namespace GUI {
P3, // position 3 floats P3, // position 3 floats
P3T2, // position 3 floats + texture coords 2 floats P3T2, // position 3 floats + texture coords 2 floats
P3N3, // position 3 floats + normal 3 floats P3N3, // position 3 floats + normal 3 floats
P3N3T2, // position 3 floats + normal 3 floats + texture coords 2 floats
P4, // position 4 floats P4, // position 4 floats
}; };
@ -93,6 +94,7 @@ namespace GUI {
void add_vertex(const Vec3f& position); // EVertexLayout::P3 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 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); // 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 add_vertex(const Vec4f& position); // EVertexLayout::P4
void set_vertex(size_t id, const Vec3f& position, const Vec3f& normal); // EVertexLayout::P3N3 void set_vertex(size_t id, const Vec3f& position, const Vec3f& normal); // EVertexLayout::P3N3