Commit c3c25098 authored by Tim Übelhör's avatar Tim Übelhör

fixed setting uniforms in shader program

parent a9886304
......@@ -90,7 +90,7 @@ void process_input(GLFWwindow *window,
glfwSetWindowShouldClose(window, true);
}
// movement
float cameraSpeed = 0.001;
float cameraSpeed = 0.005;
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
{
camera_pose.position.y += cameraSpeed;
......
......@@ -46,6 +46,7 @@ void DepthSimulator::render_pose(const QuaternionPose &object_pose,
camera.pose = camera_pose;
camera.set_in_shader(depth_shader);
model.pose = object_pose;
depth_shader.activate();
model.draw(depth_shader);
}
} // namespace scigl_render
\ No newline at end of file
......@@ -16,15 +16,15 @@ void OnscreenRender::next_frame(
GLContext &gl_context, const CvCamera &camera,
const Model &model, const DiffuseLight &light)
{
shader.activate();
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
camera.set_in_shader(shader);
light.set_in_shader(shader);
shader.activate();
model.draw(shader);
shader.deactivate();
glfwSwapBuffers(gl_context.get_window());
check_gl_error("rendered next frame");
}
......
......@@ -77,7 +77,6 @@ void CvCamera::resize_intrinsics(int width, int height)
void CvCamera::set_in_shader(const Shader &shader) const
{
shader.activate();
shader.setVec3("camera_position", this->pose.position);
shader.setFloatArray("dist_coeffs", this->intrinsics.dist_coeffs,
sizeof(this->intrinsics.dist_coeffs));
......
......@@ -2,7 +2,6 @@
void scigl_render::DiffuseLight::set_in_shader(const Shader &shader) const
{
shader.activate();
shader.setVec3("light_position", position);
shader.setVec3("light_color", color);
}
\ No newline at end of file
......@@ -131,7 +131,6 @@ void Mesh::init()
void Mesh::draw(const Shader &shader) const
{
shader.activate();
shader.setVec3("material.ambient", material.ambient);
shader.setVec3("material.diffuse", material.diffuse);
shader.setVec3("material.specular", material.specular);
......@@ -139,6 +138,7 @@ void Mesh::draw(const Shader &shader) const
// Shader shall sample form texture0
shader.setInt("texture0", 0);
shader.setFloat("diffuse_texture_strength", texture.strength);
shader.activate();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture.id);
// draw the vertex array
......
......@@ -30,148 +30,139 @@ void Shader::set_program_id(GLuint id)
void Shader::setBool(const std::string &name, bool value) const
{
activate();
glUniform1i(glGetUniformLocation(program_id, name.c_str()), (int)value);
deactivate();
glProgramUniform1i(program_id,
glGetUniformLocation(program_id, name.c_str()),
(int)value);
}
void Shader::setInt(const std::string &name, int value) const
{
activate();
glUniform1i(glGetUniformLocation(program_id, name.c_str()), value);
deactivate();
glProgramUniform1i(program_id,
glGetUniformLocation(program_id, name.c_str()),
value);
}
void Shader::setUInt(const std::string &name, uint32_t value) const
{
activate();
glUniform1ui(glGetUniformLocation(program_id, name.c_str()), value);
deactivate();
glProgramUniform1ui(program_id,
glGetUniformLocation(program_id, name.c_str()), value);
}
void Shader::setFloat(const std::string &name, float value) const
{
activate();
glUniform1f(glGetUniformLocation(program_id, name.c_str()), value);
deactivate();
glProgramUniform1f(program_id,
glGetUniformLocation(program_id, name.c_str()), value);
}
void Shader::setVec2(const std::string &name, const glm::vec2 &value) const
{
activate();
glUniform2fv(glGetUniformLocation(program_id, name.c_str()), 1, &value[0]);
deactivate();
glProgramUniform2fv(program_id,
glGetUniformLocation(program_id, name.c_str()),
1, &value[0]);
}
void Shader::setVec2(const std::string &name, float x, float y) const
{
activate();
glUniform2f(glGetUniformLocation(program_id, name.c_str()), x, y);
deactivate();
glProgramUniform2f(program_id,
glGetUniformLocation(program_id, name.c_str()), x, y);
}
void Shader::setVec3(const std::string &name, const glm::vec3 &value) const
{
activate();
glUniform3fv(glGetUniformLocation(program_id, name.c_str()), 1, &value[0]);
deactivate();
glProgramUniform3fv(program_id,
glGetUniformLocation(program_id, name.c_str()),
1, &value[0]);
}
void Shader::setVec3(const std::string &name, float x, float y, float z) const
{
activate();
glUniform3f(glGetUniformLocation(program_id, name.c_str()), x, y, z);
deactivate();
glProgramUniform3f(program_id,
glGetUniformLocation(program_id, name.c_str()), x, y, z);
}
void Shader::setVec4(const std::string &name, const glm::vec4 &value) const
{
activate();
glUniform4fv(glGetUniformLocation(program_id, name.c_str()), 1, &value[0]);
deactivate();
glProgramUniform4fv(program_id,
glGetUniformLocation(program_id, name.c_str()),
1, &value[0]);
}
void Shader::setVec4(const std::string &name, float x, float y, float z,
float w) const
{
activate();
glUniform4f(glGetUniformLocation(program_id, name.c_str()), x, y, z, w);
deactivate();
glProgramUniform4f(program_id,
glGetUniformLocation(program_id, name.c_str()),
x, y, z, w);
}
void Shader::setMat2(const std::string &name, const glm::mat2 &mat) const
{
activate();
glUniformMatrix2fv(glGetUniformLocation(program_id, name.c_str()), 1,
GL_FALSE, &mat[0][0]);
deactivate();
glProgramUniformMatrix2fv(program_id,
glGetUniformLocation(program_id, name.c_str()), 1,
GL_FALSE, &mat[0][0]);
}
void Shader::setMat3(const std::string &name, const glm::mat3 &mat) const
{
activate();
glUniformMatrix3fv(glGetUniformLocation(program_id, name.c_str()), 1,
GL_FALSE, &mat[0][0]);
deactivate();
glProgramUniformMatrix3fv(program_id,
glGetUniformLocation(program_id, name.c_str()), 1,
GL_FALSE, &mat[0][0]);
}
void Shader::setMat4(const std::string &name, const glm::mat4 &mat) const
{
activate();
glUniformMatrix4fv(glGetUniformLocation(program_id, name.c_str()), 1,
GL_FALSE, &mat[0][0]);
deactivate();
glProgramUniformMatrix4fv(program_id,
glGetUniformLocation(program_id, name.c_str()), 1,
GL_FALSE, &mat[0][0]);
}
void Shader::setUVec2(const std::string &name, const glm::uvec2 &value) const
{
activate();
glUniform2uiv(glGetUniformLocation(program_id, name.c_str()), 1, &value[0]);
deactivate();
glProgramUniform2uiv(program_id,
glGetUniformLocation(program_id, name.c_str()),
1, &value[0]);
}
void Shader::setUVec3(const std::string &name, const glm::uvec3 &value) const
{
activate();
glUniform3uiv(glGetUniformLocation(program_id, name.c_str()), 1, &value[0]);
deactivate();
glProgramUniform3uiv(program_id,
glGetUniformLocation(program_id, name.c_str()),
1, &value[0]);
}
void Shader::setUVec4(const std::string &name, const glm::uvec4 &value) const
{
activate();
glUniform4uiv(glGetUniformLocation(program_id, name.c_str()), 1, &value[0]);
deactivate();
glProgramUniform4uiv(program_id,
glGetUniformLocation(program_id, name.c_str()),
1, &value[0]);
}
void Shader::setUVec2(const std::string &name, uint32_t x, uint32_t y) const
{
activate();
glUniform2ui(glGetUniformLocation(program_id, name.c_str()), x, y);
deactivate();
glProgramUniform2ui(program_id,
glGetUniformLocation(program_id, name.c_str()), x, y);
}
void Shader::setUVec3(const std::string &name,
uint32_t x, uint32_t y, uint32_t z) const
{
activate();
glUniform3ui(glGetUniformLocation(program_id, name.c_str()), x, y, z);
deactivate();
glProgramUniform3ui(program_id,
glGetUniformLocation(program_id, name.c_str()), x, y, z);
}
void Shader::setUVec4(const std::string &name,
uint32_t x, uint32_t y, uint32_t z, uint32_t w) const
{
activate();
glUniform4ui(glGetUniformLocation(program_id, name.c_str()), x, y, z, w);
deactivate();
glProgramUniform4ui(program_id,
glGetUniformLocation(program_id, name.c_str()),
x, y, z, w);
}
void Shader::setFloatArray(
const std::string &name, const float array[], int count) const
{
activate();
glUniform1fv(glGetUniformLocation(program_id, name.c_str()), count, array);
deactivate();
glProgramUniform1fv(program_id,
glGetUniformLocation(program_id, name.c_str()),
count, array);
}
} // namespace scigl_render
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment