mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-13 05:09:03 +08:00
Refactoring of GLShaderProgram::set_uniform() methods
This commit is contained in:
parent
7f9e519baf
commit
c30f5823f5
@ -2661,7 +2661,7 @@ void GCodeViewer::render_toolpaths()
|
|||||||
// Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415.
|
// Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415.
|
||||||
assert(! path.sizes.empty());
|
assert(! path.sizes.empty());
|
||||||
assert(! path.offsets.empty());
|
assert(! path.offsets.empty());
|
||||||
glsafe(::glUniform4fv(uniform_color, 1, static_cast<const GLfloat*>(path.color.data())));
|
shader.set_uniform(uniform_color, path.color);
|
||||||
glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_SHORT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size()));
|
glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_SHORT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size()));
|
||||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
++m_statistics.gl_multi_points_calls_count;
|
++m_statistics.gl_multi_points_calls_count;
|
||||||
@ -2685,7 +2685,7 @@ void GCodeViewer::render_toolpaths()
|
|||||||
// Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415.
|
// Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415.
|
||||||
assert(! path.sizes.empty());
|
assert(! path.sizes.empty());
|
||||||
assert(! path.offsets.empty());
|
assert(! path.offsets.empty());
|
||||||
glsafe(::glUniform4fv(uniform_color, 1, static_cast<const GLfloat*>(path.color.data())));
|
shader.set_uniform(uniform_color, path.color);
|
||||||
glsafe(::glMultiDrawElements(GL_LINES, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_SHORT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size()));
|
glsafe(::glMultiDrawElements(GL_LINES, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_SHORT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size()));
|
||||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
++m_statistics.gl_multi_lines_calls_count;
|
++m_statistics.gl_multi_lines_calls_count;
|
||||||
@ -2703,7 +2703,7 @@ void GCodeViewer::render_toolpaths()
|
|||||||
// Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415.
|
// Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415.
|
||||||
assert(! path.sizes.empty());
|
assert(! path.sizes.empty());
|
||||||
assert(! path.offsets.empty());
|
assert(! path.offsets.empty());
|
||||||
glsafe(::glUniform4fv(uniform_color, 1, static_cast<const GLfloat*>(path.color.data())));
|
shader.set_uniform(uniform_color, path.color);
|
||||||
glsafe(::glMultiDrawElements(GL_TRIANGLES, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_SHORT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size()));
|
glsafe(::glMultiDrawElements(GL_TRIANGLES, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_SHORT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size()));
|
||||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
++m_statistics.gl_multi_triangles_calls_count;
|
++m_statistics.gl_multi_triangles_calls_count;
|
||||||
|
@ -206,154 +206,104 @@ void GLShaderProgram::stop_using() const
|
|||||||
glsafe(::glUseProgram(0));
|
glsafe(::glUseProgram(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLShaderProgram::set_uniform(const char* name, int value) const
|
void GLShaderProgram::set_uniform(int id, int value) const
|
||||||
{
|
{
|
||||||
int id = get_uniform_location(name);
|
if (id >= 0)
|
||||||
if (id >= 0) {
|
glsafe(::glUniform1i(id, value));
|
||||||
glsafe(::glUniform1i(id, static_cast<GLint>(value)));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLShaderProgram::set_uniform(const char* name, bool value) const
|
void GLShaderProgram::set_uniform(int id, bool value) const
|
||||||
{
|
{
|
||||||
return set_uniform(name, value ? 1 : 0);
|
set_uniform(id, value ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLShaderProgram::set_uniform(const char* name, float value) const
|
void GLShaderProgram::set_uniform(int id, float value) const
|
||||||
{
|
{
|
||||||
int id = get_uniform_location(name);
|
if (id >= 0)
|
||||||
if (id >= 0) {
|
glsafe(::glUniform1f(id, value));
|
||||||
glsafe(::glUniform1f(id, static_cast<GLfloat>(value)));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLShaderProgram::set_uniform(const char* name, double value) const
|
void GLShaderProgram::set_uniform(int id, double value) const
|
||||||
{
|
{
|
||||||
return set_uniform(name, static_cast<float>(value));
|
set_uniform(id, static_cast<float>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLShaderProgram::set_uniform(const char* name, const std::array<int, 2>& value) const
|
void GLShaderProgram::set_uniform(int id, const std::array<int, 2>& value) const
|
||||||
{
|
{
|
||||||
int id = get_uniform_location(name);
|
if (id >= 0)
|
||||||
if (id >= 0) {
|
|
||||||
glsafe(::glUniform2iv(id, 1, static_cast<const GLint*>(value.data())));
|
glsafe(::glUniform2iv(id, 1, static_cast<const GLint*>(value.data())));
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLShaderProgram::set_uniform(const char* name, const std::array<int, 3>& value) const
|
void GLShaderProgram::set_uniform(int id, const std::array<int, 3>& value) const
|
||||||
{
|
{
|
||||||
int id = get_uniform_location(name);
|
if (id >= 0)
|
||||||
if (id >= 0) {
|
|
||||||
glsafe(::glUniform3iv(id, 1, static_cast<const GLint*>(value.data())));
|
glsafe(::glUniform3iv(id, 1, static_cast<const GLint*>(value.data())));
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLShaderProgram::set_uniform(const char* name, const std::array<int, 4>& value) const
|
void GLShaderProgram::set_uniform(int id, const std::array<int, 4>& value) const
|
||||||
{
|
{
|
||||||
int id = get_uniform_location(name);
|
if (id >= 0)
|
||||||
if (id >= 0) {
|
|
||||||
glsafe(::glUniform4iv(id, 1, static_cast<const GLint*>(value.data())));
|
glsafe(::glUniform4iv(id, 1, static_cast<const GLint*>(value.data())));
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLShaderProgram::set_uniform(const char* name, const std::array<float, 2>& value) const
|
void GLShaderProgram::set_uniform(int id, const std::array<float, 2>& value) const
|
||||||
{
|
{
|
||||||
int id = get_uniform_location(name);
|
if (id >= 0)
|
||||||
if (id >= 0) {
|
|
||||||
glsafe(::glUniform2fv(id, 1, static_cast<const GLfloat*>(value.data())));
|
glsafe(::glUniform2fv(id, 1, static_cast<const GLfloat*>(value.data())));
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLShaderProgram::set_uniform(const char* name, const std::array<float, 3>& value) const
|
void GLShaderProgram::set_uniform(int id, const std::array<float, 3>& value) const
|
||||||
{
|
{
|
||||||
int id = get_uniform_location(name);
|
if (id >= 0)
|
||||||
if (id >= 0) {
|
|
||||||
glsafe(::glUniform3fv(id, 1, static_cast<const GLfloat*>(value.data())));
|
glsafe(::glUniform3fv(id, 1, static_cast<const GLfloat*>(value.data())));
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLShaderProgram::set_uniform(const char* name, const std::array<float, 4>& value) const
|
void GLShaderProgram::set_uniform(int id, const std::array<float, 4>& value) const
|
||||||
{
|
{
|
||||||
int id = get_uniform_location(name);
|
if (id >= 0)
|
||||||
if (id >= 0) {
|
|
||||||
glsafe(::glUniform4fv(id, 1, static_cast<const GLfloat*>(value.data())));
|
glsafe(::glUniform4fv(id, 1, static_cast<const GLfloat*>(value.data())));
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLShaderProgram::set_uniform(const char* name, const float* value, size_t size) const
|
void GLShaderProgram::set_uniform(int id, const float* value, size_t size) const
|
||||||
{
|
{
|
||||||
if (size == 1)
|
|
||||||
return set_uniform(name, value[0]);
|
|
||||||
else if (size < 5) {
|
|
||||||
int id = get_uniform_location(name);
|
|
||||||
if (id >= 0) {
|
|
||||||
if (size == 2)
|
|
||||||
glsafe(::glUniform2fv(id, 1, static_cast<const GLfloat*>(value)));
|
|
||||||
else if (size == 3)
|
|
||||||
glsafe(::glUniform3fv(id, 1, static_cast<const GLfloat*>(value)));
|
|
||||||
else
|
|
||||||
glsafe(::glUniform4fv(id, 1, static_cast<const GLfloat*>(value)));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GLShaderProgram::set_uniform(const char* name, const Transform3f& value) const
|
|
||||||
{
|
|
||||||
int id = get_uniform_location(name);
|
|
||||||
if (id >= 0) {
|
if (id >= 0) {
|
||||||
|
if (size == 1)
|
||||||
|
set_uniform(id, value[0]);
|
||||||
|
else if (size == 2)
|
||||||
|
glsafe(::glUniform2fv(id, 1, static_cast<const GLfloat*>(value)));
|
||||||
|
else if (size == 3)
|
||||||
|
glsafe(::glUniform3fv(id, 1, static_cast<const GLfloat*>(value)));
|
||||||
|
else if (size == 4)
|
||||||
|
glsafe(::glUniform4fv(id, 1, static_cast<const GLfloat*>(value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLShaderProgram::set_uniform(int id, const Transform3f& value) const
|
||||||
|
{
|
||||||
|
if (id >= 0)
|
||||||
glsafe(::glUniformMatrix4fv(id, 1, GL_FALSE, static_cast<const GLfloat*>(value.matrix().data())));
|
glsafe(::glUniformMatrix4fv(id, 1, GL_FALSE, static_cast<const GLfloat*>(value.matrix().data())));
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLShaderProgram::set_uniform(const char* name, const Transform3d& value) const
|
void GLShaderProgram::set_uniform(int id, const Transform3d& value) const
|
||||||
{
|
{
|
||||||
return set_uniform(name, value.cast<float>());
|
set_uniform(id, value.cast<float>());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLShaderProgram::set_uniform(const char* name, const Matrix3f& value) const
|
void GLShaderProgram::set_uniform(int id, const Matrix3f& value) const
|
||||||
{
|
{
|
||||||
int id = get_uniform_location(name);
|
if (id >= 0)
|
||||||
if (id >= 0) {
|
|
||||||
glsafe(::glUniformMatrix3fv(id, 1, GL_FALSE, static_cast<const GLfloat*>(value.data())));
|
glsafe(::glUniformMatrix3fv(id, 1, GL_FALSE, static_cast<const GLfloat*>(value.data())));
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLShaderProgram::set_uniform(const char* name, const Vec3f& value) const
|
void GLShaderProgram::set_uniform(int id, const Vec3f& value) const
|
||||||
{
|
{
|
||||||
int id = get_uniform_location(name);
|
if (id >= 0)
|
||||||
if (id >= 0) {
|
|
||||||
glsafe(::glUniform3fv(id, 1, static_cast<const GLfloat*>(value.data())));
|
glsafe(::glUniform3fv(id, 1, static_cast<const GLfloat*>(value.data())));
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLShaderProgram::set_uniform(const char* name, const Vec3d& value) const
|
void GLShaderProgram::set_uniform(int id, const Vec3d& value) const
|
||||||
{
|
{
|
||||||
return set_uniform(name, static_cast<Vec3f>(value.cast<float>()));
|
set_uniform(id, static_cast<Vec3f>(value.cast<float>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
int GLShaderProgram::get_attrib_location(const char* name) const
|
int GLShaderProgram::get_attrib_location(const char* name) const
|
||||||
|
@ -44,22 +44,39 @@ public:
|
|||||||
void start_using() const;
|
void start_using() const;
|
||||||
void stop_using() const;
|
void stop_using() const;
|
||||||
|
|
||||||
bool set_uniform(const char* name, int value) const;
|
void set_uniform(const char* name, int value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
bool set_uniform(const char* name, bool value) const;
|
void set_uniform(const char* name, bool value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
bool set_uniform(const char* name, float value) const;
|
void set_uniform(const char* name, float value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
bool set_uniform(const char* name, double value) const;
|
void set_uniform(const char* name, double value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
bool set_uniform(const char* name, const std::array<int, 2>& value) const;
|
void set_uniform(const char* name, const std::array<int, 2>& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
bool set_uniform(const char* name, const std::array<int, 3>& value) const;
|
void set_uniform(const char* name, const std::array<int, 3>& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
bool set_uniform(const char* name, const std::array<int, 4>& value) const;
|
void set_uniform(const char* name, const std::array<int, 4>& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
bool set_uniform(const char* name, const std::array<float, 2>& value) const;
|
void set_uniform(const char* name, const std::array<float, 2>& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
bool set_uniform(const char* name, const std::array<float, 3>& value) const;
|
void set_uniform(const char* name, const std::array<float, 3>& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
bool set_uniform(const char* name, const std::array<float, 4>& value) const;
|
void set_uniform(const char* name, const std::array<float, 4>& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
bool set_uniform(const char* name, const float* value, size_t size) const;
|
void set_uniform(const char* name, const float* value, size_t size) const { set_uniform(get_uniform_location(name), value, size); }
|
||||||
bool set_uniform(const char* name, const Transform3f& value) const;
|
void set_uniform(const char* name, const Transform3f& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
bool set_uniform(const char* name, const Transform3d& value) const;
|
void set_uniform(const char* name, const Transform3d& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
bool set_uniform(const char* name, const Matrix3f& value) const;
|
void set_uniform(const char* name, const Matrix3f& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
bool set_uniform(const char* name, const Vec3f& value) const;
|
void set_uniform(const char* name, const Vec3f& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
bool set_uniform(const char* name, const Vec3d& value) const;
|
void set_uniform(const char* name, const Vec3d& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
|
|
||||||
|
void set_uniform(int id, int value) const;
|
||||||
|
void set_uniform(int id, bool value) const;
|
||||||
|
void set_uniform(int id, float value) const;
|
||||||
|
void set_uniform(int id, double value) const;
|
||||||
|
void set_uniform(int id, const std::array<int, 2>& value) const;
|
||||||
|
void set_uniform(int id, const std::array<int, 3>& value) const;
|
||||||
|
void set_uniform(int id, const std::array<int, 4>& value) const;
|
||||||
|
void set_uniform(int id, const std::array<float, 2>& value) const;
|
||||||
|
void set_uniform(int id, const std::array<float, 3>& value) const;
|
||||||
|
void set_uniform(int id, const std::array<float, 4>& value) const;
|
||||||
|
void set_uniform(int id, const float* value, size_t size) const;
|
||||||
|
void set_uniform(int id, const Transform3f& value) const;
|
||||||
|
void set_uniform(int id, const Transform3d& value) const;
|
||||||
|
void set_uniform(int id, const Matrix3f& value) const;
|
||||||
|
void set_uniform(int id, const Vec3f& value) const;
|
||||||
|
void set_uniform(int id, const Vec3d& value) const;
|
||||||
|
|
||||||
// returns -1 if not found
|
// returns -1 if not found
|
||||||
int get_attrib_location(const char* name) const;
|
int get_attrib_location(const char* name) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user