Skip to content

Commit

Permalink
Added window_base::should_be_closed and using it in example applicati…
Browse files Browse the repository at this point in the history
…ons.
  • Loading branch information
johannesugb committed Aug 14, 2023
1 parent f83983f commit e74a804
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 15 deletions.
8 changes: 8 additions & 0 deletions auto_vk_toolkit/include/window_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ namespace avk
*/
bool is_cursor_disabled() const;

/** Returns true if the window should be closed.
* Attention: Could be that a positive result is returned with a delay of 1 frame.
*/
bool should_be_closed();

protected:
/** Static variable which holds the ID that the next window will get assigned */
static uint32_t mNextWindowId;
Expand Down Expand Up @@ -149,5 +154,8 @@ namespace avk

// Whether or not the cursor is operating in disabled-mode
cursor mCursorMode;

// Initially false, set to true if window should close.
bool mShouldClose;
};
}
10 changes: 10 additions & 0 deletions auto_vk_toolkit/src/window_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,14 @@ namespace avk
});
}

bool window_base::should_be_closed()
{
assert(handle());
context().dispatch_to_main_thread([this]{
assert(handle());
// Note: The update of the value might not happen before the next frame:
this->mShouldClose = glfwWindowShouldClose(handle()->mHandle);
});
return mShouldClose;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class compute_image_processing_app : public avk::invokee
mUpdateToRenderDependency = std::move(semaphore);
}

if (avk::input().key_pressed(avk::key_code::escape)) {
if (avk::input().key_pressed(avk::key_code::escape) || avk::context().main_window()->should_be_closed()) {
// Stop the current composition:
avk::composition_interface::current()->stop();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/framebuffer/source/framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class framebuffer_app : public avk::invokee
}

// On Esc pressed,
if (avk::input().key_pressed(avk::key_code::escape)) {
if (avk::input().key_pressed(avk::key_code::escape) || avk::context().main_window()->should_be_closed()) {
// stop the current composition:
avk::current_composition()->stop();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world/source/hello_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class draw_a_triangle_app : public avk::invokee
}

// On Esc pressed,
if (avk::input().key_pressed(avk::key_code::escape)) {
if (avk::input().key_pressed(avk::key_code::escape) || avk::context().main_window()->should_be_closed()) {
// stop the current composition:
avk::current_composition()->stop();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/model_loader/source/model_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class model_loader_app : public avk::invokee
auto resolution = avk::context().main_window()->resolution();
avk::context().main_window()->set_cursor_pos({ resolution[0] / 2.0, resolution[1] / 2.0 });
}
if (!mQuakeCam.is_enabled() && avk::input().key_pressed(avk::key_code::escape)) {
if (!mQuakeCam.is_enabled() && avk::input().key_pressed(avk::key_code::escape) || avk::context().main_window()->should_be_closed()) {
// Stop the current composition:
avk::current_composition()->stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class multi_invokee_rendering_app : public avk::invokee
void update() override
{
// On Esc pressed,
if (avk::input().key_pressed(avk::key_code::escape)) {
if (avk::input().key_pressed(avk::key_code::escape) || avk::context().main_window()->should_be_closed()) {
// stop the current composition:
avk::current_composition()->stop();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/multiple_queues/source/multiple_queues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class multiple_queues_app : public avk::invokee
void update() override
{
// On Esc pressed,
if (avk::input().key_pressed(avk::key_code::escape)) {
if (avk::input().key_pressed(avk::key_code::escape) || avk::context().main_window()->should_be_closed()) {
// stop the current composition:
avk::current_composition()->stop();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/orca_loader/source/orca_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ class orca_loader_app : public avk::invokee
auto resolution = avk::context().main_window()->resolution();
avk::context().main_window()->set_cursor_pos({ resolution[0] / 2.0, resolution[1] / 2.0 });
}
if (!mQuakeCam.is_enabled() && avk::input().key_pressed(avk::key_code::escape)) {
if (!mQuakeCam.is_enabled() && avk::input().key_pressed(avk::key_code::escape) || avk::context().main_window()->should_be_closed()) {
// Stop the current composition:
avk::current_composition()->stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class present_from_compute_app : public avk::invokee
mUiQueueSelectionPrevFrame = mUiQueueSelection;

// On Esc pressed,
if (avk::input().key_pressed(avk::key_code::escape)) {
if (avk::input().key_pressed(avk::key_code::escape) || avk::context().main_window()->should_be_closed()) {
// stop the current composition:
avk::current_composition()->stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class ray_query_in_ray_tracing_shaders_invokee : public avk::invokee
auto pos = mQuakeCam.translation();
LOG_INFO(fmt::format("Current camera position: {}", avk::to_string(pos)));
}
if (avk::input().key_pressed(avk::key_code::escape)) {
if (avk::input().key_pressed(avk::key_code::escape) || avk::context().main_window()->should_be_closed()) {
// Stop the current composition:
avk::current_composition()->stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class ray_tracing_custom_intersection_app : public avk::invokee
auto pos = mQuakeCam.translation();
LOG_INFO(fmt::format("Current camera position: {}", avk::to_string(pos)));
}
if (avk::input().key_pressed(avk::key_code::escape)) {
if (avk::input().key_pressed(avk::key_code::escape) || avk::context().main_window()->should_be_closed()) {
// Stop the current composition:
avk::current_composition()->stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class ray_tracing_with_shadows_and_ao_invokee : public avk::invokee
auto pos = mQuakeCam.translation();
LOG_INFO(fmt::format("Current camera position: {}", avk::to_string(pos)));
}
if (avk::input().key_pressed(avk::key_code::escape)) {
if (avk::input().key_pressed(avk::key_code::escape) || avk::context().main_window()->should_be_closed()) {
// Stop the current composition:
avk::current_composition()->stop();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/skinned_meshlets/source/skinned_meshlets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ class skinned_meshlets_app : public avk::invokee
auto resolution = avk::context().main_window()->resolution();
avk::context().main_window()->set_cursor_pos({ resolution[0] / 2.0, resolution[1] / 2.0 });
}
if (!mQuakeCam.is_enabled() && avk::input().key_pressed(avk::key_code::escape)) {
if (!mQuakeCam.is_enabled() && avk::input().key_pressed(avk::key_code::escape) || avk::context().main_window()->should_be_closed()) {
// Stop the current composition:
avk::current_composition()->stop();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/static_meshlets/source/static_meshlets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class static_meshlets_app : public avk::invokee
auto resolution = avk::context().main_window()->resolution();
avk::context().main_window()->set_cursor_pos({ resolution[0] / 2.0, resolution[1] / 2.0 });
}
if (!mQuakeCam.is_enabled() && avk::input().key_pressed(avk::key_code::escape)) {
if (!mQuakeCam.is_enabled() && avk::input().key_pressed(avk::key_code::escape) || avk::context().main_window()->should_be_closed()) {
// Stop the current composition:
avk::current_composition()->stop();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/texture_cubemap/source/texture_cubemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class texture_cubemap_app : public avk::invokee

void update() override
{
if (avk::input().key_pressed(avk::key_code::escape)) {
if (avk::input().key_pressed(avk::key_code::escape) || avk::context().main_window()->should_be_closed()) {
// Stop the current composition:
avk::current_composition()->stop();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/vertex_buffers/source/vertex_buffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class vertex_buffers_app : public avk::invokee
void update() override
{
// On Esc pressed,
if (avk::input().key_pressed(avk::key_code::escape)) {
if (avk::input().key_pressed(avk::key_code::escape) || avk::context().main_window()->should_be_closed()) {
// stop the current composition:
avk::current_composition()->stop();
}
Expand Down

0 comments on commit e74a804

Please sign in to comment.