Cherry-picked a few changes from Tech ENABLE_GL_CORE_PROFILE

This commit is contained in:
enricoturri1966 2023-10-27 23:23:57 +08:00 committed by Noisyfox
parent 5ce3ec716e
commit 4fb5b1f904
5 changed files with 37 additions and 5 deletions

View file

@ -55,7 +55,7 @@ using Vec2f = Eigen::Matrix<float, 2, 1, Eigen::DontAlign>;
using Vec3f = Eigen::Matrix<float, 3, 1, Eigen::DontAlign>;
using Vec2d = Eigen::Matrix<double, 2, 1, Eigen::DontAlign>;
using Vec3d = Eigen::Matrix<double, 3, 1, Eigen::DontAlign>;
// BBS
using Vec4f = Eigen::Matrix<float, 4, 1, Eigen::DontAlign>;
using Vec4d = Eigen::Matrix<double, 4, 1, Eigen::DontAlign>;
using Points = std::vector<Point>;

View file

@ -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; }
};
}

View file

@ -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

View file

@ -317,6 +317,17 @@ void GLShaderProgram::set_uniform(int id, const Matrix4d& value) const
set_uniform(id, (Matrix4f)value.cast<float>());
}
void GLShaderProgram::set_uniform(int id, const Vec2f& value) const
{
if (id >= 0)
glsafe(::glUniform2fv(id, 1, static_cast<const GLfloat*>(value.data())));
}
void GLShaderProgram::set_uniform(int id, const Vec2d& value) const
{
set_uniform(id, static_cast<Vec2f>(value.cast<float>()));
}
void GLShaderProgram::set_uniform(int id, const Vec3f& value) const
{
if (id >= 0)

View file

@ -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;