From e4b51238f560317b4c294c8afbe1653d4740fa64 Mon Sep 17 00:00:00 2001 From: ZhuohaoHe Date: Wed, 27 Nov 2024 13:49:27 -0500 Subject: [PATCH] renderer: implement `is_complete()` to check if all uniforms have been set --- copying.md | 1 + libopenage/renderer/demo/demo_0.cpp | 7 ++++++- libopenage/renderer/demo/demo_1.cpp | 6 ++++++ libopenage/renderer/demo/demo_2.cpp | 5 +++++ libopenage/renderer/demo/demo_4.cpp | 5 +++++ libopenage/renderer/demo/demo_5.cpp | 5 +++++ libopenage/renderer/demo/demo_6.cpp | 12 ++++++++++++ libopenage/renderer/opengl/uniform_input.cpp | 9 +++++++++ libopenage/renderer/opengl/uniform_input.h | 5 +++++ libopenage/renderer/uniform_input.h | 2 ++ 10 files changed, 56 insertions(+), 1 deletion(-) diff --git a/copying.md b/copying.md index 61153fb9cf..3d97be2f8b 100644 --- a/copying.md +++ b/copying.md @@ -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. diff --git a/libopenage/renderer/demo/demo_0.cpp b/libopenage/renderer/demo/demo_0.cpp index 38fd467d0b..16ce725aef 100644 --- a/libopenage/renderer/demo/demo_0.cpp +++ b/libopenage/renderer/demo/demo_0.cpp @@ -43,8 +43,13 @@ void renderer_demo_0(const util::Path &path) { auto display_shader = renderer->add_shader({display_vshader_src, display_fshader_src}); auto quad = renderer->add_mesh_geometry(resources::MeshData::make_quad()); + auto display_unif = display_shader->create_empty_input(); + /* Check if all uniform values for uniform inputs have been set */ + if (!display_unif->is_complete()) { + log::log(WARN << "Some Uniform values have not been set."); + } Renderable display_stuff{ - display_shader->create_empty_input(), + display_unif, quad, false, false, diff --git a/libopenage/renderer/demo/demo_1.cpp b/libopenage/renderer/demo/demo_1.cpp index 23dfdfa67b..65da534b2a 100644 --- a/libopenage/renderer/demo/demo_1.cpp +++ b/libopenage/renderer/demo/demo_1.cpp @@ -172,6 +172,12 @@ void renderer_demo_1(const util::Path &path) { auto pass2 = renderer->add_render_pass({display_obj}, renderer->get_display_target()); + /* Check if all uniform values for uniform inputs have been set */ + if (!obj1_unifs->is_complete() || !obj2_unifs->is_complete() || !obj3_unifs->is_complete() + || !proj_unif->is_complete() || !color_texture_unif->is_complete()) { + log::log(WARN << "Some Uniform values have not been set."); + } + /* Data retrieved from the object index texture. */ resources::Texture2dData id_texture_data = id_texture->into_data(); bool texture_data_valid = false; diff --git a/libopenage/renderer/demo/demo_2.cpp b/libopenage/renderer/demo/demo_2.cpp index e615d238ba..c5392f8590 100644 --- a/libopenage/renderer/demo/demo_2.cpp +++ b/libopenage/renderer/demo/demo_2.cpp @@ -224,6 +224,11 @@ void renderer_demo_2(const util::Path &path) { auto pass2 = renderer->add_render_pass({display_obj}, renderer->get_display_target()); + /* Check if all uniform values for uniform inputs have been set */ + if (!obj1_unifs->is_complete() || !proj_unif->is_complete() || !color_texture_unif->is_complete()) { + log::log(WARN << "Some Uniform values have not been set."); + } + /* Data retrieved from the object index texture. */ resources::Texture2dData id_texture_data = id_texture->into_data(); bool texture_data_valid = false; diff --git a/libopenage/renderer/demo/demo_4.cpp b/libopenage/renderer/demo/demo_4.cpp index fb39057e5d..515de4933b 100644 --- a/libopenage/renderer/demo/demo_4.cpp +++ b/libopenage/renderer/demo/demo_4.cpp @@ -165,6 +165,11 @@ void renderer_demo_4(const util::Path &path) { auto pass2 = renderer->add_render_pass({display_obj}, renderer->get_display_target()); + /* Check if all uniform values for uniform inputs have been set */ + if (!obj1_unifs->is_complete() || !proj_unif->is_complete() || !color_texture_unif->is_complete()) { + log::log(WARN << "Some Uniform values have not been set."); + } + 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); diff --git a/libopenage/renderer/demo/demo_5.cpp b/libopenage/renderer/demo/demo_5.cpp index 85752db18c..1361d274fa 100644 --- a/libopenage/renderer/demo/demo_5.cpp +++ b/libopenage/renderer/demo/demo_5.cpp @@ -134,6 +134,11 @@ void renderer_demo_5(const util::Path &path) { "tex", gltex); + /* Check if all uniform values for uniform inputs have been set */ + if (!transform_unifs->is_complete()) { + log::log(WARN << "Some Uniform values have not been set."); + } + // Move around the scene with WASD window.add_key_callback([&](const QKeyEvent &ev) { bool cam_update = false; diff --git a/libopenage/renderer/demo/demo_6.cpp b/libopenage/renderer/demo/demo_6.cpp index 9844503e64..1c80e50150 100644 --- a/libopenage/renderer/demo/demo_6.cpp +++ b/libopenage/renderer/demo/demo_6.cpp @@ -179,6 +179,10 @@ const std::vector RenderManagerDemo6::create_2d_obj() { this->obj_2d_texture, "tile_params", tile_params); + /* Check if all uniform values for uniform inputs have been set */ + if (!animation_2d_unifs->is_complete()) { + log::log(WARN << "Some Uniform values have not been set."); + } auto quad = this->renderer->add_mesh_geometry(resources::MeshData::make_quad()); Renderable animation_2d_obj{ animation_2d_unifs, @@ -198,6 +202,11 @@ const renderer::Renderable RenderManagerDemo6::create_3d_obj() { auto terrain_unifs = this->obj_3d_shader->new_uniform_input( "tex", this->obj_3d_texture); + /* Check if all uniform values for uniform inputs have been set */ + if (!terrain_unifs->is_complete()) { + log::log(WARN << "Some Uniform values have not been set."); + } + std::vector terrain_pos{}; terrain_pos.push_back({-25, -25, 0}); terrain_pos.push_back({25, -25, 0}); @@ -260,6 +269,9 @@ const std::vector RenderManagerDemo6::create_frame_obj() { frame_size, "incol", Eigen::Vector4f{0.0f, 0.0f, 1.0f, 1.0f}); + if (!frame_unifs->is_complete()) { + log::log(WARN << "Some Uniform values have not been set."); + } Renderable frame_obj{ frame_unifs, frame_geometry, diff --git a/libopenage/renderer/opengl/uniform_input.cpp b/libopenage/renderer/opengl/uniform_input.cpp index 38c63f2d66..8c021959b7 100644 --- a/libopenage/renderer/opengl/uniform_input.cpp +++ b/libopenage/renderer/opengl/uniform_input.cpp @@ -50,4 +50,13 @@ GlUniformBufferInput::GlUniformBufferInput(const std::shared_ptr this->update_data.resize(offset); } +bool GlUniformInput::is_complete() const { + for (const auto& uniform : this->update_offs) { + if (!uniform.used) { + return false; + } + } + return true; +} + } // namespace openage::renderer::opengl diff --git a/libopenage/renderer/opengl/uniform_input.h b/libopenage/renderer/opengl/uniform_input.h index 961e12a2a5..d635836b05 100644 --- a/libopenage/renderer/opengl/uniform_input.h +++ b/libopenage/renderer/opengl/uniform_input.h @@ -35,6 +35,11 @@ class GlUniformInput final : public UniformInput { public: GlUniformInput(const std::shared_ptr &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. */ diff --git a/libopenage/renderer/uniform_input.h b/libopenage/renderer/uniform_input.h index 6f2536459b..39bb4ea983 100644 --- a/libopenage/renderer/uniform_input.h +++ b/libopenage/renderer/uniform_input.h @@ -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;