Add uniform setters for int[2..4] vectors in Shader class.

This commit is contained in:
Kai Blaschke
2023-10-24 19:31:42 +02:00
parent 42966cdb7b
commit 37ec15d13b
2 changed files with 55 additions and 1 deletions

View File

@ -109,6 +109,16 @@ void Shader::SetUniformFloat2(const char* uniform, const glm::vec2& values) cons
glUniform2fv(location, 1, glm::value_ptr(values));
}
void Shader::SetUniformInt2(const char* uniform, const glm::ivec2& values) const
{
auto location = glGetUniformLocation(m_shaderProgram, uniform);
if (location < 0)
{
return;
}
glUniform2iv(location, 1, glm::value_ptr(values));
}
void Shader::SetUniformFloat3(const char* uniform, const glm::vec3& values) const
{
auto location = glGetUniformLocation(m_shaderProgram, uniform);
@ -119,6 +129,16 @@ void Shader::SetUniformFloat3(const char* uniform, const glm::vec3& values) cons
glUniform3fv(location, 1, glm::value_ptr(values));
}
void Shader::SetUniformInt3(const char* uniform, const glm::ivec3& values) const
{
auto location = glGetUniformLocation(m_shaderProgram, uniform);
if (location < 0)
{
return;
}
glUniform3iv(location, 1, glm::value_ptr(values));
}
void Shader::SetUniformFloat4(const char* uniform, const glm::vec4& values) const
{
auto location = glGetUniformLocation(m_shaderProgram, uniform);
@ -129,6 +149,16 @@ void Shader::SetUniformFloat4(const char* uniform, const glm::vec4& values) cons
glUniform4fv(location, 1, glm::value_ptr(values));
}
void Shader::SetUniformInt4(const char* uniform, const glm::ivec4& values) const
{
auto location = glGetUniformLocation(m_shaderProgram, uniform);
if (location < 0)
{
return;
}
glUniform4iv(location, 1, glm::value_ptr(values));
}
void Shader::SetUniformMat3x4(const char* uniform, const glm::mat3x4& values) const
{
auto location = glGetUniformLocation(m_shaderProgram, uniform);
@ -202,4 +232,4 @@ auto Shader::GetShaderLanguageVersion() -> Shader::GlslVersion
int versionMinor = std::stoi(shaderLanguageVersionString.substr(dotPos + 1));
return {versionMajor, versionMinor};
}
}

View File

@ -112,6 +112,14 @@ public:
*/
void SetUniformFloat2(const char* uniform, const glm::vec2& values) const;
/**
* @brief Sets an int vec2 uniform.
* The program must be bound before calling this method!
* @param uniform The uniform name
* @param values The values to set.
*/
void SetUniformInt2(const char* uniform, const glm::ivec2& values) const;
/**
* @brief Sets a float vec3 uniform.
* The program must be bound before calling this method!
@ -120,6 +128,14 @@ public:
*/
void SetUniformFloat3(const char* uniform, const glm::vec3& values) const;
/**
* @brief Sets an int vec3 uniform.
* The program must be bound before calling this method!
* @param uniform The uniform name
* @param values The values to set.
*/
void SetUniformInt3(const char* uniform, const glm::ivec3& values) const;
/**
* @brief Sets a float vec4 uniform.
* The program must be bound before calling this method!
@ -128,6 +144,14 @@ public:
*/
void SetUniformFloat4(const char* uniform, const glm::vec4& values) const;
/**
* @brief Sets an int vec4 uniform.
* The program must be bound before calling this method!
* @param uniform The uniform name
* @param values The values to set.
*/
void SetUniformInt4(const char* uniform, const glm::ivec4& values) const;
/**
* @brief Sets a float 3x4 matrix uniform.
* The program must be bound before calling this method!