diff --git a/libopenage/renderer/demo/demo_0.cpp b/libopenage/renderer/demo/demo_0.cpp index 16ce725aef..d1d679c0e4 100644 --- a/libopenage/renderer/demo/demo_0.cpp +++ b/libopenage/renderer/demo/demo_0.cpp @@ -9,6 +9,7 @@ #include "renderer/resources/mesh_data.h" #include "renderer/resources/shader_source.h" #include "renderer/shader_program.h" +#include "renderer/demo/util.h" namespace openage::renderer::tests { @@ -43,18 +44,17 @@ 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_unif, + display_shader->create_empty_input(), quad, false, false, }; + if (!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()) { diff --git a/libopenage/renderer/demo/demo_1.cpp b/libopenage/renderer/demo/demo_1.cpp index 65da534b2a..2fb3ce6201 100644 --- a/libopenage/renderer/demo/demo_1.cpp +++ b/libopenage/renderer/demo/demo_1.cpp @@ -15,6 +15,7 @@ #include "renderer/shader_program.h" #include "renderer/texture.h" #include "util/math_constants.h" +#include "renderer/demo/util.h" namespace openage::renderer::tests { @@ -172,10 +173,8 @@ 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."); + if (!check_uniform_completeness({obj1, obj2, obj3, proj_update, display_obj})) { + log::log(WARN << "Uniforms not complete."); } /* Data retrieved from the object index texture. */ diff --git a/libopenage/renderer/demo/demo_2.cpp b/libopenage/renderer/demo/demo_2.cpp index c5392f8590..863ea8c979 100644 --- a/libopenage/renderer/demo/demo_2.cpp +++ b/libopenage/renderer/demo/demo_2.cpp @@ -18,6 +18,7 @@ #include "renderer/resources/texture_data.h" #include "renderer/shader_program.h" #include "renderer/texture.h" +#include "renderer/demo/util.h" namespace openage::renderer::tests { @@ -224,9 +225,8 @@ 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."); + if (!check_uniform_completeness({proj_update, obj1, display_obj})) { + log::log(WARN << "Uniforms not complete."); } /* Data retrieved from the object index texture. */ diff --git a/libopenage/renderer/demo/demo_4.cpp b/libopenage/renderer/demo/demo_4.cpp index 515de4933b..35c795c427 100644 --- a/libopenage/renderer/demo/demo_4.cpp +++ b/libopenage/renderer/demo/demo_4.cpp @@ -16,6 +16,7 @@ #include "renderer/resources/shader_source.h" #include "renderer/resources/texture_data.h" #include "renderer/shader_program.h" +#include "renderer/demo/util.h" #include "time/clock.h" @@ -165,9 +166,8 @@ 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."); + if (!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*/) { diff --git a/libopenage/renderer/demo/demo_5.cpp b/libopenage/renderer/demo/demo_5.cpp index 1361d274fa..744c1b9fc7 100644 --- a/libopenage/renderer/demo/demo_5.cpp +++ b/libopenage/renderer/demo/demo_5.cpp @@ -17,6 +17,7 @@ #include "renderer/shader_program.h" #include "renderer/uniform_buffer.h" #include "renderer/uniform_input.h" +#include "renderer/demo/util.h" namespace openage::renderer::tests { @@ -134,9 +135,8 @@ 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."); + if (!check_uniform_completeness({terrain_obj})) { + log::log(WARN << "Uniforms not complete."); } // Move around the scene with WASD diff --git a/libopenage/renderer/demo/demo_6.cpp b/libopenage/renderer/demo/demo_6.cpp index 1c80e50150..016d9d41a3 100644 --- a/libopenage/renderer/demo/demo_6.cpp +++ b/libopenage/renderer/demo/demo_6.cpp @@ -23,6 +23,7 @@ #include "renderer/shader_program.h" #include "renderer/texture.h" #include "renderer/uniform_buffer.h" +#include "renderer/demo/util.h" #include "time/clock.h" #include "util/path.h" #include "util/vector.h" @@ -179,10 +180,6 @@ 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, @@ -202,10 +199,6 @@ 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}); @@ -269,9 +262,6 @@ 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, @@ -499,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 (!check_uniform_completeness({display_obj_3d, display_obj_2d, display_obj_frame})) { + log::log(WARN << "Uniforms not complete."); + } } } // namespace openage::renderer::tests diff --git a/libopenage/renderer/demo/util.cpp b/libopenage/renderer/demo/util.cpp index aafffebf8d..b160e9251c 100644 --- a/libopenage/renderer/demo/util.cpp +++ b/libopenage/renderer/demo/util.cpp @@ -1,8 +1,22 @@ // Copyright 2015-2023 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 &renderables) { + bool all_complete = true; + + // Iterate over each renderable object + for (const auto &renderable : renderables) { + if (renderable.uniform && !renderable.uniform->is_complete()) { + all_complete = false; + } + } + + return all_complete; +} + } // namespace openage::renderer::tests diff --git a/libopenage/renderer/demo/util.h b/libopenage/renderer/demo/util.h index 9899867e2b..cfb19f665a 100644 --- a/libopenage/renderer/demo/util.h +++ b/libopenage/renderer/demo/util.h @@ -2,6 +2,8 @@ #pragma once +#include +#include "renderer/renderable.h" namespace openage::renderer::tests { @@ -11,4 +13,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 &renderables); + } // namespace openage::renderer::tests diff --git a/libopenage/renderer/opengl/uniform_input.cpp b/libopenage/renderer/opengl/uniform_input.cpp index 8c021959b7..4a8a4b0496 100644 --- a/libopenage/renderer/opengl/uniform_input.cpp +++ b/libopenage/renderer/opengl/uniform_input.cpp @@ -51,12 +51,12 @@ GlUniformBufferInput::GlUniformBufferInput(const std::shared_ptr } bool GlUniformInput::is_complete() const { - for (const auto& uniform : this->update_offs) { - if (!uniform.used) { - return false; - } - } - return true; + for (const auto& uniform : this->update_offs) { + if (!uniform.used) { + return false; + } + } + return true; } } // namespace openage::renderer::opengl diff --git a/libopenage/renderer/util.cpp b/libopenage/renderer/util.cpp index 3cb3995790..8c316bdc60 100644 --- a/libopenage/renderer/util.cpp +++ b/libopenage/renderer/util.cpp @@ -2,6 +2,8 @@ #include "util.h" +#include +#include #include diff --git a/libopenage/renderer/util.h b/libopenage/renderer/util.h index 999392f122..d182b10999 100644 --- a/libopenage/renderer/util.h +++ b/libopenage/renderer/util.h @@ -6,6 +6,10 @@ #include +namespace openage::renderer { +class Renderable; +} // namespace openage::renderer + namespace openage::renderer::util { /**