Add shader uniform data setters
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include <vector> // std::vector
|
#include <vector> // std::vector
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
#include <glm/gtc/type_ptr.hpp> // glm::value_ptr
|
||||||
|
|
||||||
#include "inferno/assertions.h"
|
#include "inferno/assertions.h"
|
||||||
#include "inferno/core.h"
|
#include "inferno/core.h"
|
||||||
@@ -38,6 +39,64 @@ namespace Inferno {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------
|
||||||
|
|
||||||
|
void Shader::setInt(const std::string &name, int value)
|
||||||
|
{
|
||||||
|
// Set unifrom int
|
||||||
|
GLint location = glGetUniformLocation(m_program, name.c_str());
|
||||||
|
glUniform1i(location, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setFloat(const std::string &name, float f1) const
|
||||||
|
{
|
||||||
|
// Set uniform float
|
||||||
|
GLint location = glGetUniformLocation(m_program, name.c_str());
|
||||||
|
glUniform1f(location, f1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setFloat(const std::string &name, float f1, float f2, float f3, float f4) const
|
||||||
|
{
|
||||||
|
// Set uniform vec4 data
|
||||||
|
GLint location = glGetUniformLocation(m_program, name.c_str());
|
||||||
|
glUniform4f(location, f1, f2, f3, f4);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setFloat(const std::string &name, glm::vec2 value) const
|
||||||
|
{
|
||||||
|
// Set uniform vec2 data
|
||||||
|
GLint location = glGetUniformLocation(m_program, name.c_str());
|
||||||
|
glUniform2f(location, value.x, value.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setFloat(const std::string &name, glm::vec3 value) const
|
||||||
|
{
|
||||||
|
// Set uniform vec3 data
|
||||||
|
GLint location = glGetUniformLocation(m_program, name.c_str());
|
||||||
|
glUniform3f(location, value.x, value.y, value.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setFloat(const std::string &name, glm::vec4 value) const
|
||||||
|
{
|
||||||
|
// Set uniform vec4 data
|
||||||
|
GLint location = glGetUniformLocation(m_program, name.c_str());
|
||||||
|
glUniform4f(location, value.x, value.y, value.z, value.w);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setFloat(const std::string &name, glm::mat3 matrix) const
|
||||||
|
{
|
||||||
|
// Set uniform mat3 data
|
||||||
|
GLint location = glGetUniformLocation(m_program, name.c_str());
|
||||||
|
glUniformMatrix3fv(location, 1, GL_FALSE, glm::value_ptr(matrix));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setFloat(const std::string &name, glm::mat4 matrix) const
|
||||||
|
{
|
||||||
|
// Set uniform mat4 data
|
||||||
|
GLint location = glGetUniformLocation(m_program, name.c_str());
|
||||||
|
glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(matrix));
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
void Shader::bind() const
|
void Shader::bind() const
|
||||||
@@ -50,13 +109,6 @@ namespace Inferno {
|
|||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------
|
|
||||||
|
|
||||||
uint32_t Shader::getProgram() const
|
|
||||||
{
|
|
||||||
return m_program;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
uint32_t Shader::compileShader(int32_t type, const char* source) const
|
uint32_t Shader::compileShader(int32_t type, const char* source) const
|
||||||
|
|||||||
@@ -13,6 +13,18 @@ namespace Inferno {
|
|||||||
Shader(const std::string &vertexSource, const std::string &fragmentSource);
|
Shader(const std::string &vertexSource, const std::string &fragmentSource);
|
||||||
~Shader();
|
~Shader();
|
||||||
|
|
||||||
|
// -----------------------------------------
|
||||||
|
|
||||||
|
// Set uniform data
|
||||||
|
void setInt(const std::string& name, int value);
|
||||||
|
void setFloat(const std::string &name, float f1) const;
|
||||||
|
void setFloat(const std::string &name, float f1, float f2, float f3, float f4) const;
|
||||||
|
void setFloat(const std::string &name, glm::vec2 v) const;
|
||||||
|
void setFloat(const std::string &name, glm::vec3 v) const;
|
||||||
|
void setFloat(const std::string &name, glm::vec4 v) const;
|
||||||
|
void setFloat(const std::string &name, glm::mat3 m) const;
|
||||||
|
void setFloat(const std::string &name, glm::mat4 m) const;
|
||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
void bind() const;
|
void bind() const;
|
||||||
@@ -20,7 +32,7 @@ namespace Inferno {
|
|||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
uint32_t getProgram() const;
|
inline uint32_t getProgram() const { return m_program; }
|
||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user