Skip to content

Commit

Permalink
renderer: implement is_complete() to check if all uniforms have bee…
Browse files Browse the repository at this point in the history
…n set
  • Loading branch information
ZzzhHe committed Nov 28, 2024
1 parent faec07d commit e4b5123
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 1 deletion.
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
7 changes: 6 additions & 1 deletion libopenage/renderer/demo/demo_0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions libopenage/renderer/demo/demo_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions libopenage/renderer/demo/demo_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 @@ -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);
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 @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions libopenage/renderer/demo/demo_6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ const std::vector<renderer::Renderable> 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,
Expand All @@ -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<coord::scene3> terrain_pos{};
terrain_pos.push_back({-25, -25, 0});
terrain_pos.push_back({25, -25, 0});
Expand Down Expand Up @@ -260,6 +269,9 @@ const std::vector<renderer::Renderable> 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,
Expand Down
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 (!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

0 comments on commit e4b5123

Please sign in to comment.