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

Add is_complete() to UniformInput and Implement Checks in Demos #1718

Merged
merged 6 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions copying.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ _the openage authors_ are:
| Edvin Lindholm | EdvinLndh | edvinlndh à gmail dawt com |
| Jeremiah Morgan | jere8184 | jeremiahmorgan dawt bham à outlook dawt com |
| Tobias Alam | alamt22 | tobiasal à umich dawt edu |
| Alex Zhuohao He | ZzzhHe | zhuohao dawt he à outlook dawt com |

If you're a first-time committer, add yourself to the above list. This is not
just for legal reasons, but also to keep an overview of all those nicknames.
Expand Down
5 changes: 5 additions & 0 deletions libopenage/renderer/demo/demo_0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "demo_0.h"

#include "renderer/demo/util.h"
#include "renderer/gui/integration/public/gui_application_with_logger.h"
#include "renderer/opengl/window.h"
#include "renderer/render_pass.h"
Expand Down Expand Up @@ -50,6 +51,10 @@ void renderer_demo_0(const util::Path &path) {
false,
};

if (not check_uniform_completeness({display_stuff})) {
log::log(WARN << "Uniforms not complete.");
}

auto pass = renderer->add_render_pass({display_stuff}, renderer->get_display_target());

while (not window.should_close()) {
Expand Down
7 changes: 6 additions & 1 deletion libopenage/renderer/demo/demo_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <epoxy/gl.h>
#include <QMouseEvent>

#include "renderer/demo/util.h"
#include "renderer/gui/integration/public/gui_application_with_logger.h"
#include "renderer/opengl/window.h"
#include "renderer/render_pass.h"
Expand Down Expand Up @@ -172,6 +173,10 @@ void renderer_demo_1(const util::Path &path) {

auto pass2 = renderer->add_render_pass({display_obj}, renderer->get_display_target());

if (not check_uniform_completeness({obj1, obj2, obj3, proj_update, display_obj})) {
log::log(WARN << "Uniforms not complete.");
}

/* Data retrieved from the object index texture. */
resources::Texture2dData id_texture_data = id_texture->into_data();
bool texture_data_valid = false;
Expand All @@ -188,7 +193,7 @@ void renderer_demo_1(const util::Path &path) {
ssize_t y = qpos.y();

log::log(INFO << "Clicked at location (" << x << ", " << y << ")");
if (!texture_data_valid) {
if (not texture_data_valid) {
id_texture_data = id_texture->into_data();
texture_data_valid = true;
}
Expand Down
7 changes: 6 additions & 1 deletion libopenage/renderer/demo/demo_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <epoxy/gl.h>
#include <QMouseEvent>

#include "renderer/demo/util.h"
#include "renderer/gui/integration/public/gui_application_with_logger.h"
#include "renderer/opengl/window.h"
#include "renderer/render_pass.h"
Expand Down Expand Up @@ -224,6 +225,10 @@ void renderer_demo_2(const util::Path &path) {

auto pass2 = renderer->add_render_pass({display_obj}, renderer->get_display_target());

if (not check_uniform_completeness({proj_update, obj1, display_obj})) {
log::log(WARN << "Uniforms not complete.");
}

/* Data retrieved from the object index texture. */
resources::Texture2dData id_texture_data = id_texture->into_data();
bool texture_data_valid = false;
Expand All @@ -243,7 +248,7 @@ void renderer_demo_2(const util::Path &path) {
ssize_t y = qpos.y();

log::log(INFO << "Clicked at location (" << x << ", " << y << ")");
if (!texture_data_valid) {
if (not texture_data_valid) {
id_texture_data = id_texture->into_data();
texture_data_valid = true;
}
Expand Down
5 changes: 5 additions & 0 deletions libopenage/renderer/demo/demo_4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <eigen3/Eigen/Dense>
#include <QKeyEvent>

#include "renderer/demo/util.h"
#include "renderer/gui/integration/public/gui_application_with_logger.h"
#include "renderer/opengl/window.h"
#include "renderer/render_pass.h"
Expand Down Expand Up @@ -165,6 +166,10 @@ void renderer_demo_4(const util::Path &path) {

auto pass2 = renderer->add_render_pass({display_obj}, renderer->get_display_target());

if (not check_uniform_completeness({proj_update, obj1, display_obj})) {
log::log(WARN << "Uniforms not complete.");
}

window.add_resize_callback([&](size_t w, size_t h, double /*scale*/) {
/* Calculate a projection matrix for the new screen size. */
float aspectRatio = float(w) / float(h);
Expand Down
5 changes: 5 additions & 0 deletions libopenage/renderer/demo/demo_5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QMouseEvent>

#include "renderer/camera/camera.h"
#include "renderer/demo/util.h"
#include "renderer/gui/integration/public/gui_application_with_logger.h"
#include "renderer/opengl/window.h"
#include "renderer/render_pass.h"
Expand Down Expand Up @@ -134,6 +135,10 @@ void renderer_demo_5(const util::Path &path) {
"tex",
gltex);

if (not check_uniform_completeness({terrain_obj})) {
log::log(WARN << "Uniforms not complete.");
}

// Move around the scene with WASD
window.add_key_callback([&](const QKeyEvent &ev) {
bool cam_update = false;
Expand Down
6 changes: 6 additions & 0 deletions libopenage/renderer/demo/demo_6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "renderer/camera/camera.h"
#include "renderer/camera/frustum_2d.h"
#include "renderer/camera/frustum_3d.h"
#include "renderer/demo/util.h"
#include "renderer/gui/integration/public/gui_application_with_logger.h"
#include "renderer/opengl/window.h"
#include "renderer/render_pass.h"
Expand Down Expand Up @@ -198,6 +199,7 @@ const renderer::Renderable RenderManagerDemo6::create_3d_obj() {
auto terrain_unifs = this->obj_3d_shader->new_uniform_input(
"tex",
this->obj_3d_texture);

std::vector<coord::scene3> terrain_pos{};
terrain_pos.push_back({-25, -25, 0});
terrain_pos.push_back({25, -25, 0});
Expand Down Expand Up @@ -487,6 +489,10 @@ void RenderManagerDemo6::create_render_passes() {
this->display_pass = renderer->add_render_pass(
{display_obj_3d, display_obj_2d, display_obj_frame},
renderer->get_display_target());

if (not check_uniform_completeness({display_obj_3d, display_obj_2d, display_obj_frame})) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as you see above, the render pass stores the exact same renderables, so the render pass can get the feature to check if all its uniform inputs are complete.
when the render pass is added to the renderer, the check can be invoked there directly, i think.

log::log(WARN << "Uniforms not complete.");
}
}

} // namespace openage::renderer::tests
15 changes: 14 additions & 1 deletion libopenage/renderer/demo/util.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
// Copyright 2015-2023 the openage authors. See copying.md for legal info.
// Copyright 2015-2024 the openage authors. See copying.md for legal info.

#include "util.h"

#include "renderer/uniform_input.h"


namespace openage::renderer::tests {

bool check_uniform_completeness(const std::vector<Renderable> &renderables) {
// Iterate over each renderable object
for (const auto &renderable : renderables) {
if (renderable.uniform and not renderable.uniform->is_complete()) {
return false;
}
}

return true;
}

} // namespace openage::renderer::tests
13 changes: 12 additions & 1 deletion libopenage/renderer/demo/util.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright 2023-2023 the openage authors. See copying.md for legal info.
// Copyright 2023-2024 the openage authors. See copying.md for legal info.

#pragma once

#include <vector>

#include "renderer/renderable.h"

namespace openage::renderer::tests {

Expand All @@ -11,4 +14,12 @@ namespace openage::renderer::tests {
opengl::GlContext::check_error(); \
printf("after %s\n", txt);

/**
* Check if all uniform values for the given renderables have been set.
*
* @param renderables The list of renderable objects to check.
* @return true if all uniforms have been set, false otherwise.
*/
bool check_uniform_completeness(const std::vector<Renderable> &renderables);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means we need to copy the renderables into the vector, which we don't need :)
you can convert the type to const std::vector<Renderable &> &renderables.
if this is known at compiletime, you can do it even better by using a variadic template.

on another note: this is useful not only for the demos, but for the renderer in general. so it should be put outside the demo directory.

} // namespace openage::renderer::tests
9 changes: 9 additions & 0 deletions libopenage/renderer/opengl/uniform_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,13 @@ GlUniformBufferInput::GlUniformBufferInput(const std::shared_ptr<UniformBuffer>
this->update_data.resize(offset);
}

bool GlUniformInput::is_complete() const {
for (const auto &uniform : this->update_offs) {
if (not uniform.used) {
return false;
}
}
return true;
}

} // namespace openage::renderer::opengl
5 changes: 5 additions & 0 deletions libopenage/renderer/opengl/uniform_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class GlUniformInput final : public UniformInput {
public:
GlUniformInput(const std::shared_ptr<ShaderProgram> &prog);

/**
* Check if all uniforms have been set.
*/
bool is_complete() const override;

/**
* Store the IDs of the uniforms from the shader set by this uniform input.
*/
Expand Down
2 changes: 2 additions & 0 deletions libopenage/renderer/uniform_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class UniformInput : public DataInput {
public:
virtual ~UniformInput() = default;

virtual bool is_complete() const = 0;

void update() override;
void update(const char *unif, int32_t val) override;
void update(const char *unif, uint32_t val) override;
Expand Down
Loading