Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update syntax of GlUniformBuffer to match that of GlUniformInput #1683 #1690

Merged
merged 5 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 25 additions & 26 deletions libopenage/renderer/opengl/uniform_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ std::shared_ptr<UniformBufferInput> GlUniformBuffer::new_unif_in() {
return in;
}

void GlUniformBuffer::set_unif(std::shared_ptr<UniformBufferInput> const &in, const char *unif, void const *val, GLenum type) {
auto unif_in = std::dynamic_pointer_cast<GlUniformBufferInput>(in);
void GlUniformBuffer::set_unif(UniformBufferInput &in, const char *unif, void const *val, GLenum type) {
auto &unif_in = dynamic_cast<GlUniformBufferInput &>(in);

auto uniform = this->uniforms.find(unif);
ENSURE(uniform != std::end(this->uniforms),
Expand All @@ -96,83 +96,82 @@ void GlUniformBuffer::set_unif(std::shared_ptr<UniformBufferInput> const &in, co
ENSURE(size == unif_data.size,
"Tried to set uniform " << unif << " to a value of the wrong size.");

auto update_off = unif_in->update_offs.find(unif);
if (update_off != std::end(unif_in->update_offs)) [[likely]] { // always used after the uniform value is written once
// already wrote to this uniform since last upload
auto update_off = unif_in.update_offs.find(unif);
if (update_off != std::end(unif_in.update_offs)) [[likely]] { // always used after the uniform value is written once // already wrote to this uniform since last upload
size_t off = update_off->second;
memcpy(unif_in->update_data.data() + off, val, size);
memcpy(unif_in.update_data.data() + off, val, size);
}
else {
// first time writing to this uniform since last upload, so
// extend the buffer before storing the uniform value
size_t prev_size = unif_in->update_data.size();
unif_in->update_data.resize(prev_size + size);
memcpy(unif_in->update_data.data() + prev_size, val, size);
unif_in->update_offs.emplace(unif, prev_size);
size_t prev_size = unif_in.update_data.size();
unif_in.update_data.resize(prev_size + size);
memcpy(unif_in.update_data.data() + prev_size, val, size);
unif_in.update_offs.emplace(unif, prev_size);
}
}

void GlUniformBuffer::set_i32(std::shared_ptr<UniformBufferInput> const &in, const char *unif, int32_t val) {
void GlUniformBuffer::set_i32(UniformBufferInput &in, const char *unif, int32_t val) {
this->set_unif(in, unif, &val, GL_INT);
}

void GlUniformBuffer::set_u32(std::shared_ptr<UniformBufferInput> const &in, const char *unif, uint32_t val) {
void GlUniformBuffer::set_u32(UniformBufferInput &in, const char *unif, uint32_t val) {
this->set_unif(in, unif, &val, GL_UNSIGNED_INT);
}

void GlUniformBuffer::set_f32(std::shared_ptr<UniformBufferInput> const &in, const char *unif, float val) {
void GlUniformBuffer::set_f32(UniformBufferInput &in, const char *unif, float val) {
this->set_unif(in, unif, &val, GL_FLOAT);
}

void GlUniformBuffer::set_f64(std::shared_ptr<UniformBufferInput> const &in, const char *unif, double val) {
void GlUniformBuffer::set_f64(UniformBufferInput &in, const char *unif, double val) {
this->set_unif(in, unif, &val, GL_DOUBLE);
}

void GlUniformBuffer::set_bool(std::shared_ptr<UniformBufferInput> const &in, const char *unif, bool val) {
void GlUniformBuffer::set_bool(UniformBufferInput &in, const char *unif, bool val) {
this->set_unif(in, unif, &val, GL_BOOL);
}

void GlUniformBuffer::set_v2f32(std::shared_ptr<UniformBufferInput> const &in, const char *unif, Eigen::Vector2f const &val) {
void GlUniformBuffer::set_v2f32(UniformBufferInput &in, const char *unif, Eigen::Vector2f const &val) {
this->set_unif(in, unif, val.data(), GL_FLOAT_VEC2);
}

void GlUniformBuffer::set_v3f32(std::shared_ptr<UniformBufferInput> const &in, const char *unif, Eigen::Vector3f const &val) {
void GlUniformBuffer::set_v3f32(UniformBufferInput &in, const char *unif, Eigen::Vector3f const &val) {
this->set_unif(in, unif, val.data(), GL_FLOAT_VEC3);
}

void GlUniformBuffer::set_v4f32(std::shared_ptr<UniformBufferInput> const &in, const char *unif, Eigen::Vector4f const &val) {
void GlUniformBuffer::set_v4f32(UniformBufferInput &in, const char *unif, Eigen::Vector4f const &val) {
this->set_unif(in, unif, val.data(), GL_FLOAT_VEC4);
}

void GlUniformBuffer::set_v2i32(std::shared_ptr<UniformBufferInput> const &in, const char *unif, Eigen::Vector2i const &val) {
void GlUniformBuffer::set_v2i32(UniformBufferInput &in, const char *unif, Eigen::Vector2i const &val) {
this->set_unif(in, unif, val.data(), GL_INT_VEC2);
}

void GlUniformBuffer::set_v3i32(std::shared_ptr<UniformBufferInput> const &in, const char *unif, Eigen::Vector3i const &val) {
void GlUniformBuffer::set_v3i32(UniformBufferInput &in, const char *unif, Eigen::Vector3i const &val) {
this->set_unif(in, unif, val.data(), GL_INT_VEC3);
}

void GlUniformBuffer::set_v4i32(std::shared_ptr<UniformBufferInput> const &in, const char *unif, Eigen::Vector4i const &val) {
void GlUniformBuffer::set_v4i32(UniformBufferInput &in, const char *unif, Eigen::Vector4i const &val) {
this->set_unif(in, unif, val.data(), GL_INT_VEC4);
}

void GlUniformBuffer::set_v2ui32(std::shared_ptr<UniformBufferInput> const &in, const char *unif, Eigen::Vector2<uint32_t> const &val) {
void GlUniformBuffer::set_v2ui32(UniformBufferInput &in, const char *unif, Eigen::Vector2<uint32_t> const &val) {
this->set_unif(in, unif, val.data(), GL_UNSIGNED_INT_VEC2);
}

void GlUniformBuffer::set_v3ui32(std::shared_ptr<UniformBufferInput> const &in, const char *unif, Eigen::Vector3<uint32_t> const &val) {
void GlUniformBuffer::set_v3ui32(UniformBufferInput &in, const char *unif, Eigen::Vector3<uint32_t> const &val) {
this->set_unif(in, unif, val.data(), GL_UNSIGNED_INT_VEC3);
}

void GlUniformBuffer::set_v4ui32(std::shared_ptr<UniformBufferInput> const &in, const char *unif, Eigen::Vector4<uint32_t> const &val) {
void GlUniformBuffer::set_v4ui32(UniformBufferInput &in, const char *unif, Eigen::Vector4<uint32_t> const &val) {
this->set_unif(in, unif, val.data(), GL_UNSIGNED_INT_VEC4);
}

void GlUniformBuffer::set_m4f32(std::shared_ptr<UniformBufferInput> const &in, const char *unif, Eigen::Matrix4f const &val) {
void GlUniformBuffer::set_m4f32(UniformBufferInput &in, const char *unif, Eigen::Matrix4f const &val) {
this->set_unif(in, unif, val.data(), GL_FLOAT_MAT4);
}

void GlUniformBuffer::set_tex(std::shared_ptr<UniformBufferInput> const &in, const char *unif, std::shared_ptr<Texture2d> const &val) {
void GlUniformBuffer::set_tex(UniformBufferInput &in, const char *unif, std::shared_ptr<Texture2d> const &val) {
auto tex = std::dynamic_pointer_cast<GlTexture2d>(val);
GLuint handle = tex->get_handle();
this->set_unif(in, unif, &handle, GL_SAMPLER_2D);
Expand Down
34 changes: 17 additions & 17 deletions libopenage/renderer/opengl/uniform_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ class GlUniformBuffer final : public UniformBuffer

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

private:
/**
Expand All @@ -80,7 +80,7 @@ class GlUniformBuffer final : public UniformBuffer
* @param val Pointer to the value to update the uniform with.
* @param type Type of the uniform.
*/
void set_unif(std::shared_ptr<UniformBufferInput> const &in,
void set_unif(UniformBufferInput &in,
const char *name,
void const *val,
GLenum type);
Expand Down
32 changes: 16 additions & 16 deletions libopenage/renderer/uniform_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ class UniformBuffer : public std::enable_shared_from_this<UniformBuffer> {
protected:
virtual std::shared_ptr<UniformBufferInput> new_unif_in() = 0;

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

} // namespace openage::renderer
34 changes: 17 additions & 17 deletions libopenage/renderer/uniform_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,71 +157,71 @@ UniformBufferInput::UniformBufferInput(std::shared_ptr<UniformBuffer> const &buf
void UniformBufferInput::update() {}

void UniformBufferInput::update(const char *unif, int32_t val) {
this->buffer->set_i32(this->shared_from_this(), unif, val);
this->buffer->set_i32(*this, unif, val);
}

void UniformBufferInput::update(const char *unif, uint32_t val) {
this->buffer->set_u32(this->shared_from_this(), unif, val);
this->buffer->set_u32(*this, unif, val);
}

void UniformBufferInput::update(const char *unif, float val) {
this->buffer->set_f32(this->shared_from_this(), unif, val);
this->buffer->set_f32(*this, unif, val);
}

void UniformBufferInput::update(const char *unif, double val) {
this->buffer->set_f64(this->shared_from_this(), unif, val);
this->buffer->set_f64(*this, unif, val);
}

void UniformBufferInput::update(const char *unif, bool val) {
this->buffer->set_bool(this->shared_from_this(), unif, val);
this->buffer->set_bool(*this, unif, val);
}

void UniformBufferInput::update(const char *unif, Eigen::Vector2f const &val) {
this->buffer->set_v2f32(this->shared_from_this(), unif, val);
this->buffer->set_v2f32(*this, unif, val);
}

void UniformBufferInput::update(const char *unif, Eigen::Vector3f const &val) {
this->buffer->set_v3f32(this->shared_from_this(), unif, val);
this->buffer->set_v3f32(*this, unif, val);
}

void UniformBufferInput::update(const char *unif, Eigen::Vector4f const &val) {
this->buffer->set_v4f32(this->shared_from_this(), unif, val);
this->buffer->set_v4f32(*this, unif, val);
}

void UniformBufferInput::update(const char *unif, Eigen::Vector2i const &val) {
this->buffer->set_v2i32(this->shared_from_this(), unif, val);
this->buffer->set_v2i32(*this, unif, val);
}

void UniformBufferInput::update(const char *unif, Eigen::Vector3i const &val) {
this->buffer->set_v3i32(this->shared_from_this(), unif, val);
this->buffer->set_v3i32(*this, unif, val);
}

void UniformBufferInput::update(const char *unif, Eigen::Vector4i const &val) {
this->buffer->set_v4i32(this->shared_from_this(), unif, val);
this->buffer->set_v4i32(*this, unif, val);
}

void UniformBufferInput::update(const char *unif, Eigen::Vector2<uint32_t> const &val) {
this->buffer->set_v2ui32(this->shared_from_this(), unif, val);
this->buffer->set_v2ui32(*this, unif, val);
}

void UniformBufferInput::update(const char *unif, Eigen::Vector3<uint32_t> const &val) {
this->buffer->set_v3ui32(this->shared_from_this(), unif, val);
this->buffer->set_v3ui32(*this, unif, val);
}

void UniformBufferInput::update(const char *unif, Eigen::Vector4<uint32_t> const &val) {
this->buffer->set_v4ui32(this->shared_from_this(), unif, val);
this->buffer->set_v4ui32(*this, unif, val);
}

void UniformBufferInput::update(const char *unif, std::shared_ptr<Texture2d> const &val) {
this->buffer->set_tex(this->shared_from_this(), unif, val);
this->buffer->set_tex(*this, unif, val);
}

void UniformBufferInput::update(const char *unif, std::shared_ptr<Texture2d> &val) {
this->buffer->set_tex(this->shared_from_this(), unif, val);
this->buffer->set_tex(*this, unif, val);
}

void UniformBufferInput::update(const char *unif, Eigen::Matrix4f const &val) {
this->buffer->set_m4f32(this->shared_from_this(), unif, val);
this->buffer->set_m4f32(*this, unif, val);
}

} // namespace openage::renderer
Loading