From 4fb5b1f904968b248b72b9e68527e23bae47f170 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 27 Oct 2023 23:23:57 +0800 Subject: [PATCH] Cherry-picked a few changes from Tech ENABLE_GL_CORE_PROFILE --- src/libslic3r/Point.hpp | 2 +- src/slic3r/GUI/GLModel.cpp | 23 +++++++++++++++++++---- src/slic3r/GUI/GLModel.hpp | 2 ++ src/slic3r/GUI/GLShader.cpp | 11 +++++++++++ src/slic3r/GUI/GLShader.hpp | 4 ++++ 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/libslic3r/Point.hpp b/src/libslic3r/Point.hpp index 6c6bac8800..73252f4459 100644 --- a/src/libslic3r/Point.hpp +++ b/src/libslic3r/Point.hpp @@ -55,7 +55,7 @@ using Vec2f = Eigen::Matrix; using Vec3f = Eigen::Matrix; using Vec2d = Eigen::Matrix; using Vec3d = Eigen::Matrix; -// BBS +using Vec4f = Eigen::Matrix; using Vec4d = Eigen::Matrix; using Points = std::vector; diff --git a/src/slic3r/GUI/GLModel.cpp b/src/slic3r/GUI/GLModel.cpp index 2671076c37..bab13ba251 100644 --- a/src/slic3r/GUI/GLModel.cpp +++ b/src/slic3r/GUI/GLModel.cpp @@ -97,6 +97,15 @@ void GLModel::Geometry::add_vertex(const Vec3f& position, const Vec3f& normal) vertices.emplace_back(normal.z()); } +void GLModel::Geometry::add_vertex(const Vec4f& position) +{ + assert(format.vertex_layout == EVertexLayout::P4); + vertices.emplace_back(position.x()); + vertices.emplace_back(position.y()); + vertices.emplace_back(position.z()); + vertices.emplace_back(position.w()); +} + void GLModel::Geometry::add_index(unsigned int id) { indices.emplace_back(id); @@ -234,6 +243,7 @@ size_t GLModel::Geometry::vertex_stride_floats(const Format& format) 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; } }; } @@ -247,6 +257,7 @@ size_t GLModel::Geometry::position_stride_floats(const Format& format) case EVertexLayout::P3: case EVertexLayout::P3T2: case EVertexLayout::P3N3: { return 3; } + case EVertexLayout::P4: { return 4; } default: { assert(false); return 0; } }; } @@ -259,7 +270,8 @@ size_t GLModel::Geometry::position_offset_floats(const Format& format) case EVertexLayout::P2T2: case EVertexLayout::P3: case EVertexLayout::P3T2: - case EVertexLayout::P3N3: { return 0; } + case EVertexLayout::P3N3: + case EVertexLayout::P4: { return 0; } default: { assert(false); return 0; } }; } @@ -321,7 +333,8 @@ bool GLModel::Geometry::has_position(const Format& format) case EVertexLayout::P2T2: case EVertexLayout::P3: case EVertexLayout::P3T2: - case EVertexLayout::P3N3: { return true; } + case EVertexLayout::P3N3: + case EVertexLayout::P4: { return true; } default: { assert(false); return false; } }; } @@ -333,7 +346,8 @@ bool GLModel::Geometry::has_normal(const Format& format) case EVertexLayout::P2: case EVertexLayout::P2T2: case EVertexLayout::P3: - case EVertexLayout::P3T2: { return false; } + case EVertexLayout::P3T2: + case EVertexLayout::P4: { return false; } case EVertexLayout::P3N3: { return true; } default: { assert(false); return false; } }; @@ -347,7 +361,8 @@ bool GLModel::Geometry::has_tex_coord(const Format& format) case EVertexLayout::P3T2: { return true; } case EVertexLayout::P2: case EVertexLayout::P3: - case EVertexLayout::P3N3: { return false; } + case EVertexLayout::P3N3: + case EVertexLayout::P4: { return false; } default: { assert(false); return false; } }; } diff --git a/src/slic3r/GUI/GLModel.hpp b/src/slic3r/GUI/GLModel.hpp index e2a3e75daf..a3fa6c38d0 100644 --- a/src/slic3r/GUI/GLModel.hpp +++ b/src/slic3r/GUI/GLModel.hpp @@ -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 + P4, // position 4 floats }; enum class EIndexType : unsigned char @@ -70,6 +71,7 @@ namespace GUI { 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 set_vertex(size_t id, const Vec3f& position, const Vec3f& normal); // EVertexLayout::P3N3 diff --git a/src/slic3r/GUI/GLShader.cpp b/src/slic3r/GUI/GLShader.cpp index 9f13269c8d..5146f03fc6 100644 --- a/src/slic3r/GUI/GLShader.cpp +++ b/src/slic3r/GUI/GLShader.cpp @@ -317,6 +317,17 @@ void GLShaderProgram::set_uniform(int id, const Matrix4d& value) const set_uniform(id, (Matrix4f)value.cast()); } +void GLShaderProgram::set_uniform(int id, const Vec2f& value) const +{ + if (id >= 0) + glsafe(::glUniform2fv(id, 1, static_cast(value.data()))); +} + +void GLShaderProgram::set_uniform(int id, const Vec2d& value) const +{ + set_uniform(id, static_cast(value.cast())); +} + void GLShaderProgram::set_uniform(int id, const Vec3f& value) const { if (id >= 0) diff --git a/src/slic3r/GUI/GLShader.hpp b/src/slic3r/GUI/GLShader.hpp index e1b2915e0d..935daaaeaa 100644 --- a/src/slic3r/GUI/GLShader.hpp +++ b/src/slic3r/GUI/GLShader.hpp @@ -65,6 +65,8 @@ public: void set_uniform(const char* name, const Matrix3d& value) const { set_uniform(get_uniform_location(name), value); } void set_uniform(const char* name, const Matrix4f& value) const { set_uniform(get_uniform_location(name), value); } void set_uniform(const char* name, const Matrix4d& value) const { set_uniform(get_uniform_location(name), value); } + void set_uniform(const char* name, const Vec2f& value) const { set_uniform(get_uniform_location(name), value); } + void set_uniform(const char* name, const Vec2d& value) const { set_uniform(get_uniform_location(name), value); } void set_uniform(const char* name, const Vec3f& value) const { set_uniform(get_uniform_location(name), value); } void set_uniform(const char* name, const Vec3d& value) const { set_uniform(get_uniform_location(name), value); } void set_uniform(const char* name, const ColorRGB& value) const { set_uniform(get_uniform_location(name), value); } @@ -88,6 +90,8 @@ public: void set_uniform(int id, const Matrix3d& value) const; void set_uniform(int id, const Matrix4f& value) const; void set_uniform(int id, const Matrix4d& value) const; + void set_uniform(int id, const Vec2f& value) const; + void set_uniform(int id, const Vec2d& value) const; void set_uniform(int id, const Vec3f& value) const; void set_uniform(int id, const Vec3d& value) const; void set_uniform(int id, const ColorRGB& value) const;