Skip to content

Commit

Permalink
renderer: Pass uniform ID by value to avoid dereference.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Aug 1, 2024
1 parent 3791e50 commit e57f865
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 85 deletions.
34 changes: 17 additions & 17 deletions libopenage/renderer/opengl/shader_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ void GlShaderProgram::set_unif(UniformInput &in,
}

void GlShaderProgram::set_unif(UniformInput &in,
const uniform_id_t &unif_id,
uniform_id_t unif_id,
void const *val,
size_t size,
GLenum type) {
Expand Down Expand Up @@ -596,68 +596,68 @@ void GlShaderProgram::set_tex(UniformInput &in, const char *unif, std::shared_pt
this->set_unif(in, unif, &handle, get_uniform_type_size(GL_SAMPLER_2D), GL_SAMPLER_2D);
}

void GlShaderProgram::set_i32(UniformInput &in, const uniform_id_t &id, int32_t val) {
void GlShaderProgram::set_i32(UniformInput &in, uniform_id_t id, int32_t val) {
this->set_unif(in, id, &val, get_uniform_type_size(GL_INT), GL_INT);
}

void GlShaderProgram::set_u32(UniformInput &in, const uniform_id_t &id, uint32_t val) {
void GlShaderProgram::set_u32(UniformInput &in, uniform_id_t id, uint32_t val) {
this->set_unif(in, id, &val, get_uniform_type_size(GL_UNSIGNED_INT), GL_UNSIGNED_INT);
}

void GlShaderProgram::set_f32(UniformInput &in, const uniform_id_t &id, float val) {
void GlShaderProgram::set_f32(UniformInput &in, uniform_id_t id, float val) {
this->set_unif(in, id, &val, get_uniform_type_size(GL_FLOAT), GL_FLOAT);
}

void GlShaderProgram::set_f64(UniformInput &in, const uniform_id_t &id, double val) {
void GlShaderProgram::set_f64(UniformInput &in, uniform_id_t id, double val) {
// TODO requires extension
this->set_unif(in, id, &val, get_uniform_type_size(GL_DOUBLE), GL_DOUBLE);
}

void GlShaderProgram::set_bool(UniformInput &in, const uniform_id_t &id, bool val) {
void GlShaderProgram::set_bool(UniformInput &in, uniform_id_t id, bool val) {
this->set_unif(in, id, &val, get_uniform_type_size(GL_BOOL), GL_BOOL);
}

void GlShaderProgram::set_v2f32(UniformInput &in, const uniform_id_t &id, Eigen::Vector2f const &val) {
void GlShaderProgram::set_v2f32(UniformInput &in, uniform_id_t id, Eigen::Vector2f const &val) {
this->set_unif(in, id, &val, get_uniform_type_size(GL_FLOAT_VEC2), GL_FLOAT_VEC2);
}

void GlShaderProgram::set_v3f32(UniformInput &in, const uniform_id_t &id, Eigen::Vector3f const &val) {
void GlShaderProgram::set_v3f32(UniformInput &in, uniform_id_t id, Eigen::Vector3f const &val) {
this->set_unif(in, id, &val, get_uniform_type_size(GL_FLOAT_VEC3), GL_FLOAT_VEC3);
}

void GlShaderProgram::set_v4f32(UniformInput &in, const uniform_id_t &id, Eigen::Vector4f const &val) {
void GlShaderProgram::set_v4f32(UniformInput &in, uniform_id_t id, Eigen::Vector4f const &val) {
this->set_unif(in, id, &val, get_uniform_type_size(GL_FLOAT_VEC4), GL_FLOAT_VEC4);
}

void GlShaderProgram::set_v2i32(UniformInput &in, const uniform_id_t &id, Eigen::Vector2i const &val) {
void GlShaderProgram::set_v2i32(UniformInput &in, uniform_id_t id, Eigen::Vector2i const &val) {
this->set_unif(in, id, &val, get_uniform_type_size(GL_INT_VEC2), GL_INT_VEC2);
}

void GlShaderProgram::set_v3i32(UniformInput &in, const uniform_id_t &id, Eigen::Vector3i const &val) {
void GlShaderProgram::set_v3i32(UniformInput &in, uniform_id_t id, Eigen::Vector3i const &val) {
this->set_unif(in, id, &val, get_uniform_type_size(GL_INT_VEC3), GL_INT_VEC3);
}

void GlShaderProgram::set_v4i32(UniformInput &in, const uniform_id_t &id, Eigen::Vector4i const &val) {
void GlShaderProgram::set_v4i32(UniformInput &in, uniform_id_t id, Eigen::Vector4i const &val) {
this->set_unif(in, id, &val, get_uniform_type_size(GL_INT_VEC4), GL_INT_VEC4);
}

void GlShaderProgram::set_v2ui32(UniformInput &in, const uniform_id_t &id, Eigen::Vector2<uint32_t> const &val) {
void GlShaderProgram::set_v2ui32(UniformInput &in, uniform_id_t id, Eigen::Vector2<uint32_t> const &val) {
this->set_unif(in, id, &val, get_uniform_type_size(GL_UNSIGNED_INT_VEC2), GL_UNSIGNED_INT_VEC2);
}

void GlShaderProgram::set_v3ui32(UniformInput &in, const uniform_id_t &id, Eigen::Vector3<uint32_t> const &val) {
void GlShaderProgram::set_v3ui32(UniformInput &in, uniform_id_t id, Eigen::Vector3<uint32_t> const &val) {
this->set_unif(in, id, &val, get_uniform_type_size(GL_UNSIGNED_INT_VEC3), GL_UNSIGNED_INT_VEC3);
}

void GlShaderProgram::set_v4ui32(UniformInput &in, const uniform_id_t &id, Eigen::Vector4<uint32_t> const &val) {
void GlShaderProgram::set_v4ui32(UniformInput &in, uniform_id_t id, Eigen::Vector4<uint32_t> const &val) {
this->set_unif(in, id, &val, get_uniform_type_size(GL_UNSIGNED_INT_VEC4), GL_UNSIGNED_INT_VEC4);
}

void GlShaderProgram::set_m4f32(UniformInput &in, const uniform_id_t &id, Eigen::Matrix4f const &val) {
void GlShaderProgram::set_m4f32(UniformInput &in, uniform_id_t id, Eigen::Matrix4f const &val) {
this->set_unif(in, id, val.data(), get_uniform_type_size(GL_FLOAT_MAT4), GL_FLOAT_MAT4);
}

void GlShaderProgram::set_tex(UniformInput &in, const uniform_id_t &id, std::shared_ptr<Texture2d> const &val) {
void GlShaderProgram::set_tex(UniformInput &in, uniform_id_t id, std::shared_ptr<Texture2d> const &val) {
auto tex = std::dynamic_pointer_cast<GlTexture2d>(val);
GLuint handle = tex->get_handle();
this->set_unif(in, id, &handle, get_uniform_type_size(GL_SAMPLER_2D), GL_SAMPLER_2D);
Expand Down
36 changes: 18 additions & 18 deletions libopenage/renderer/opengl/shader_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,22 @@ class GlShaderProgram final : public ShaderProgram
void set_m4f32(UniformInput &in, const char *, Eigen::Matrix4f const &) override;
void set_tex(UniformInput &in, const char *, std::shared_ptr<Texture2d> const &) override;

void set_i32(UniformInput &in, const uniform_id_t &, int32_t) override;
void set_u32(UniformInput &in, const uniform_id_t &, uint32_t) override;
void set_f32(UniformInput &in, const uniform_id_t &, float) override;
void set_f64(UniformInput &in, const uniform_id_t &, double) override;
void set_bool(UniformInput &in, const uniform_id_t &, bool) override;
void set_v2f32(UniformInput &in, const uniform_id_t &, Eigen::Vector2f const &) override;
void set_v3f32(UniformInput &in, const uniform_id_t &, Eigen::Vector3f const &) override;
void set_v4f32(UniformInput &in, const uniform_id_t &, Eigen::Vector4f const &) override;
void set_v2i32(UniformInput &in, const uniform_id_t &, Eigen::Vector2i const &) override;
void set_v3i32(UniformInput &in, const uniform_id_t &, Eigen::Vector3i const &) override;
void set_v4i32(UniformInput &in, const uniform_id_t &, Eigen::Vector4i const &) override;
void set_v2ui32(UniformInput &in, const uniform_id_t &, Eigen::Vector2<uint32_t> const &) override;
void set_v3ui32(UniformInput &in, const uniform_id_t &, Eigen::Vector3<uint32_t> const &) override;
void set_v4ui32(UniformInput &in, const uniform_id_t &, Eigen::Vector4<uint32_t> const &) override;
void set_m4f32(UniformInput &in, const uniform_id_t &, Eigen::Matrix4f const &) override;
void set_tex(UniformInput &in, const uniform_id_t &, std::shared_ptr<Texture2d> const &) override;
void set_i32(UniformInput &in, uniform_id_t id, int32_t) override;
void set_u32(UniformInput &in, uniform_id_t id, uint32_t) override;
void set_f32(UniformInput &in, uniform_id_t id, float) override;
void set_f64(UniformInput &in, uniform_id_t id, double) override;
void set_bool(UniformInput &in, uniform_id_t id, bool) override;
void set_v2f32(UniformInput &in, uniform_id_t id, Eigen::Vector2f const &) override;
void set_v3f32(UniformInput &in, uniform_id_t id, Eigen::Vector3f const &) override;
void set_v4f32(UniformInput &in, uniform_id_t id, Eigen::Vector4f const &) override;
void set_v2i32(UniformInput &in, uniform_id_t id, Eigen::Vector2i const &) override;
void set_v3i32(UniformInput &in, uniform_id_t id, Eigen::Vector3i const &) override;
void set_v4i32(UniformInput &in, uniform_id_t id, Eigen::Vector4i const &) override;
void set_v2ui32(UniformInput &in, uniform_id_t id, Eigen::Vector2<uint32_t> const &) override;
void set_v3ui32(UniformInput &in, uniform_id_t id, Eigen::Vector3<uint32_t> const &) override;
void set_v4ui32(UniformInput &in, uniform_id_t id, Eigen::Vector4<uint32_t> const &) override;
void set_m4f32(UniformInput &in, uniform_id_t id, Eigen::Matrix4f const &) override;
void set_tex(UniformInput &in, uniform_id_t id, std::shared_ptr<Texture2d> const &) override;

private:
/**
Expand All @@ -170,13 +170,13 @@ class GlShaderProgram final : public ShaderProgram
* Set the uniform value via uniform ID from a uniform input.
*
* @param in Uniform input.
* @param id ID of the uniform.
* @param unif_id ID of the uniform.
* @param value Value to set.
* @param size Size of the value (in bytes).
* @param type Type of the value.
*/
void set_unif(UniformInput &in,
const uniform_id_t &unif_id,
uniform_id_t unif_id,
void const *value,
size_t size,
GLenum type);
Expand Down
32 changes: 16 additions & 16 deletions libopenage/renderer/shader_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,22 @@ class ShaderProgram : public std::enable_shared_from_this<ShaderProgram> {
virtual void set_m4f32(UniformInput &in, const char *, Eigen::Matrix4f const &) = 0;
virtual void set_tex(UniformInput &in, const char *, std::shared_ptr<Texture2d> const &) = 0;

virtual void set_i32(UniformInput &in, const uniform_id_t &, int32_t) = 0;
virtual void set_u32(UniformInput &in, const uniform_id_t &, uint32_t) = 0;
virtual void set_f32(UniformInput &in, const uniform_id_t &, float) = 0;
virtual void set_f64(UniformInput &in, const uniform_id_t &, double) = 0;
virtual void set_bool(UniformInput &in, const uniform_id_t &, bool) = 0;
virtual void set_v2f32(UniformInput &in, const uniform_id_t &, Eigen::Vector2f const &) = 0;
virtual void set_v3f32(UniformInput &in, const uniform_id_t &, Eigen::Vector3f const &) = 0;
virtual void set_v4f32(UniformInput &in, const uniform_id_t &, Eigen::Vector4f const &) = 0;
virtual void set_v2i32(UniformInput &in, const uniform_id_t &, Eigen::Vector2i const &) = 0;
virtual void set_v3i32(UniformInput &in, const uniform_id_t &, Eigen::Vector3i const &) = 0;
virtual void set_v4i32(UniformInput &in, const uniform_id_t &, Eigen::Vector4i const &) = 0;
virtual void set_v2ui32(UniformInput &in, const uniform_id_t &, Eigen::Vector2<uint32_t> const &) = 0;
virtual void set_v3ui32(UniformInput &in, const uniform_id_t &, Eigen::Vector3<uint32_t> const &) = 0;
virtual void set_v4ui32(UniformInput &in, const uniform_id_t &, Eigen::Vector4<uint32_t> const &) = 0;
virtual void set_m4f32(UniformInput &in, const uniform_id_t &, Eigen::Matrix4f const &) = 0;
virtual void set_tex(UniformInput &in, const uniform_id_t &, std::shared_ptr<Texture2d> const &) = 0;
virtual void set_i32(UniformInput &in, uniform_id_t id, int32_t) = 0;
virtual void set_u32(UniformInput &in, uniform_id_t id, uint32_t) = 0;
virtual void set_f32(UniformInput &in, uniform_id_t id, float) = 0;
virtual void set_f64(UniformInput &in, uniform_id_t id, double) = 0;
virtual void set_bool(UniformInput &in, uniform_id_t id, bool) = 0;
virtual void set_v2f32(UniformInput &in, uniform_id_t id, Eigen::Vector2f const &) = 0;
virtual void set_v3f32(UniformInput &in, uniform_id_t id, Eigen::Vector3f const &) = 0;
virtual void set_v4f32(UniformInput &in, uniform_id_t id, Eigen::Vector4f const &) = 0;
virtual void set_v2i32(UniformInput &in, uniform_id_t id, Eigen::Vector2i const &) = 0;
virtual void set_v3i32(UniformInput &in, uniform_id_t id, Eigen::Vector3i const &) = 0;
virtual void set_v4i32(UniformInput &in, uniform_id_t id, Eigen::Vector4i const &) = 0;
virtual void set_v2ui32(UniformInput &in, uniform_id_t id, Eigen::Vector2<uint32_t> const &) = 0;
virtual void set_v3ui32(UniformInput &in, uniform_id_t id, Eigen::Vector3<uint32_t> const &) = 0;
virtual void set_v4ui32(UniformInput &in, uniform_id_t id, Eigen::Vector4<uint32_t> const &) = 0;
virtual void set_m4f32(UniformInput &in, uniform_id_t id, Eigen::Matrix4f const &) = 0;
virtual void set_tex(UniformInput &in, uniform_id_t id, std::shared_ptr<Texture2d> const &) = 0;
};

} // namespace renderer
Expand Down
34 changes: 17 additions & 17 deletions libopenage/renderer/uniform_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,71 +82,71 @@ void UniformInput::update(const char *unif, Eigen::Matrix4f const &val) {
}


void UniformInput::update(const uniform_id_t &id, int32_t val) {
void UniformInput::update(uniform_id_t id, int32_t val) {
this->program->set_i32(*this, id, val);
}

void UniformInput::update(const uniform_id_t &id, uint32_t val) {
void UniformInput::update(uniform_id_t id, uint32_t val) {
this->program->set_u32(*this, id, val);
}

void UniformInput::update(const uniform_id_t &id, float val) {
void UniformInput::update(uniform_id_t id, float val) {
this->program->set_f32(*this, id, val);
}

void UniformInput::update(const uniform_id_t &id, double val) {
void UniformInput::update(uniform_id_t id, double val) {
this->program->set_f64(*this, id, val);
}

void UniformInput::update(const uniform_id_t &id, bool val) {
void UniformInput::update(uniform_id_t id, bool val) {
this->program->set_bool(*this, id, val);
}

void UniformInput::update(const uniform_id_t &id, Eigen::Vector2f const &val) {
void UniformInput::update(uniform_id_t id, Eigen::Vector2f const &val) {
this->program->set_v2f32(*this, id, val);
}

void UniformInput::update(const uniform_id_t &id, Eigen::Vector3f const &val) {
void UniformInput::update(uniform_id_t id, Eigen::Vector3f const &val) {
this->program->set_v3f32(*this, id, val);
}

void UniformInput::update(const uniform_id_t &id, Eigen::Vector4f const &val) {
void UniformInput::update(uniform_id_t id, Eigen::Vector4f const &val) {
this->program->set_v4f32(*this, id, val);
}

void UniformInput::update(const uniform_id_t &id, Eigen::Vector2i const &val) {
void UniformInput::update(uniform_id_t id, Eigen::Vector2i const &val) {
this->program->set_v2i32(*this, id, val);
}

void UniformInput::update(const uniform_id_t &id, Eigen::Vector3i const &val) {
void UniformInput::update(uniform_id_t id, Eigen::Vector3i const &val) {
this->program->set_v3i32(*this, id, val);
}

void UniformInput::update(const uniform_id_t &id, Eigen::Vector4i const &val) {
void UniformInput::update(uniform_id_t id, Eigen::Vector4i const &val) {
this->program->set_v4i32(*this, id, val);
}

void UniformInput::update(const uniform_id_t &id, Eigen::Vector2<uint32_t> const &val) {
void UniformInput::update(uniform_id_t id, Eigen::Vector2<uint32_t> const &val) {
this->program->set_v2ui32(*this, id, val);
}

void UniformInput::update(const uniform_id_t &id, Eigen::Vector3<uint32_t> const &val) {
void UniformInput::update(uniform_id_t id, Eigen::Vector3<uint32_t> const &val) {
this->program->set_v3ui32(*this, id, val);
}

void UniformInput::update(const uniform_id_t &id, Eigen::Vector4<uint32_t> const &val) {
void UniformInput::update(uniform_id_t id, Eigen::Vector4<uint32_t> const &val) {
this->program->set_v4ui32(*this, id, val);
}

void UniformInput::update(const uniform_id_t &id, std::shared_ptr<Texture2d> const &val) {
void UniformInput::update(uniform_id_t id, std::shared_ptr<Texture2d> const &val) {
this->program->set_tex(*this, id, val);
}

void UniformInput::update(const uniform_id_t &id, std::shared_ptr<Texture2d> &val) {
void UniformInput::update(uniform_id_t id, std::shared_ptr<Texture2d> &val) {
this->program->set_tex(*this, id, val);
}

void UniformInput::update(const uniform_id_t &id, Eigen::Matrix4f const &val) {
void UniformInput::update(uniform_id_t id, Eigen::Matrix4f const &val) {
this->program->set_m4f32(*this, id, val);
}

Expand Down
34 changes: 17 additions & 17 deletions libopenage/renderer/uniform_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,23 @@ class UniformInput : public DataInput {
void update(const char *unif, std::shared_ptr<Texture2d> &val) override;
void update(const char *unif, Eigen::Matrix4f const &val) override;

void update(const uniform_id_t &id, int32_t val);
void update(const uniform_id_t &id, uint32_t val);
void update(const uniform_id_t &id, float val);
void update(const uniform_id_t &id, double val);
void update(const uniform_id_t &id, bool val);
void update(const uniform_id_t &id, Eigen::Vector2f const &val);
void update(const uniform_id_t &id, Eigen::Vector3f const &val);
void update(const uniform_id_t &id, Eigen::Vector4f const &val);
void update(const uniform_id_t &id, Eigen::Vector2i const &val);
void update(const uniform_id_t &id, Eigen::Vector3i const &val);
void update(const uniform_id_t &id, Eigen::Vector4i const &val);
void update(const uniform_id_t &id, Eigen::Vector2<uint32_t> const &val);
void update(const uniform_id_t &id, Eigen::Vector3<uint32_t> const &val);
void update(const uniform_id_t &id, Eigen::Vector4<uint32_t> const &val);
void update(const uniform_id_t &id, std::shared_ptr<Texture2d> const &val);
void update(const uniform_id_t &id, std::shared_ptr<Texture2d> &val);
void update(const uniform_id_t &id, Eigen::Matrix4f const &val);
void update(uniform_id_t id, int32_t val);
void update(uniform_id_t id, uint32_t val);
void update(uniform_id_t id, float val);
void update(uniform_id_t id, double val);
void update(uniform_id_t id, bool val);
void update(uniform_id_t id, Eigen::Vector2f const &val);
void update(uniform_id_t id, Eigen::Vector3f const &val);
void update(uniform_id_t id, Eigen::Vector4f const &val);
void update(uniform_id_t id, Eigen::Vector2i const &val);
void update(uniform_id_t id, Eigen::Vector3i const &val);
void update(uniform_id_t id, Eigen::Vector4i const &val);
void update(uniform_id_t id, Eigen::Vector2<uint32_t> const &val);
void update(uniform_id_t id, Eigen::Vector3<uint32_t> const &val);
void update(uniform_id_t id, Eigen::Vector4<uint32_t> const &val);
void update(uniform_id_t id, std::shared_ptr<Texture2d> const &val);
void update(uniform_id_t id, std::shared_ptr<Texture2d> &val);
void update(uniform_id_t id, Eigen::Matrix4f const &val);

/**
* Catch-all template in order to handle unsupported types and avoid infinite recursion.
Expand Down

0 comments on commit e57f865

Please sign in to comment.