Skip to content

Commit

Permalink
Introduce enum class vkb::BindingType to select between C- and C++-bi…
Browse files Browse the repository at this point in the history
…ndings of vulkan; replaces the boolean template parameter of VulkanSample.
  • Loading branch information
asuessenbach committed Feb 27, 2024
1 parent 6e66fc7 commit 265a888
Show file tree
Hide file tree
Showing 124 changed files with 347 additions and 322 deletions.
2 changes: 1 addition & 1 deletion app/plugins/batch_mode/batch_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void BatchMode::on_update(float delta_time)
elapsed_time = 0.0f;

// Only check and advance the config if the application is a vulkan sample
if (auto *vulkan_app = dynamic_cast<vkb::VulkanSample<false> *>(&platform->get_app()))
if (auto *vulkan_app = dynamic_cast<vkb::VulkanSample<vkb::BindingType::C> *>(&platform->get_app()))
{
auto &configuration = vulkan_app->get_configuration();

Expand Down
2 changes: 1 addition & 1 deletion framework/api_vulkan_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct Meshlet
*
* See vkb::VulkanSample for documentation
*/
class ApiVulkanSample : public vkb::VulkanSample<false>
class ApiVulkanSample : public vkb::VulkanSample<vkb::BindingType::C>
{
public:
ApiVulkanSample() = default;
Expand Down
6 changes: 6 additions & 0 deletions framework/common/vk_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ using BindingMap = std::map<uint32_t, std::map<uint32_t, T>>;

namespace vkb
{
enum class BindingType
{
C,
Cpp
};

/**
* @brief Helper function to determine if a Vulkan format is depth only.
* @param format Vulkan format to check.
Expand Down
2 changes: 1 addition & 1 deletion framework/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const ImGuiWindowFlags Gui::options_flags = Gui::common_flags;

const ImGuiWindowFlags Gui::info_flags = Gui::common_flags | ImGuiWindowFlags_NoInputs;

Gui::Gui(VulkanSample<false> &sample_, const Window &window, const Stats *stats, const float font_size, bool explicit_update) :
Gui::Gui(VulkanSample<vkb::BindingType::C> &sample_, const Window &window, const Stats *stats, const float font_size, bool explicit_update) :
sample{sample_},
content_scale_factor{window.get_content_scale_factor()},
dpi_factor{window.get_dpi_factor() * content_scale_factor},
Expand Down
8 changes: 3 additions & 5 deletions framework/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "platform/input_events.h"
#include "rendering/render_context.h"
#include "stats/stats.h"
#include "vulkan_sample.h"

namespace vkb
{
Expand Down Expand Up @@ -233,9 +234,6 @@ bool Drawer::color_op_impl<Drawer::ColorOp::Pick, 3>(const char *caption, float
template <>
bool Drawer::color_op_impl<Drawer::ColorOp::Pick, 4>(const char *caption, float *colors, ImGuiColorEditFlags flags);

template <bool CppBindings>
class VulkanSample;

/**
* @brief Vulkan helper class for Dear ImGui
*/
Expand Down Expand Up @@ -307,7 +305,7 @@ class Gui
* @param font_size The font size
* @param explicit_update If true, update buffers every frame
*/
Gui(VulkanSample<false> &sample, const Window &window, const Stats *stats = nullptr, const float font_size = 21.0f, bool explicit_update = false);
Gui(VulkanSample<vkb::BindingType::C> &sample, const Window &window, const Stats *stats = nullptr, const float font_size = 21.0f, bool explicit_update = false);

/**
* @brief Destroys the Gui
Expand Down Expand Up @@ -429,7 +427,7 @@ class Gui

static const ImGuiWindowFlags info_flags;

VulkanSample<false> &sample;
VulkanSample<vkb::BindingType::C> &sample;

std::unique_ptr<core::Buffer> vertex_buffer;

Expand Down
8 changes: 4 additions & 4 deletions framework/hpp_api_vulkan_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE

bool HPPApiVulkanSample::prepare(const vkb::ApplicationOptions &options)
{
if (!VulkanSample<true>::prepare(options))
if (!VulkanSample<vkb::BindingType::Cpp>::prepare(options))
{
return false;
}
Expand Down Expand Up @@ -162,17 +162,17 @@ void HPPApiVulkanSample::create_render_context()
auto surface_priority_list = std::vector<vk::SurfaceFormatKHR>{{vk::Format::eB8G8R8A8Srgb, vk::ColorSpaceKHR::eSrgbNonlinear},
{vk::Format::eR8G8B8A8Srgb, vk::ColorSpaceKHR::eSrgbNonlinear}};

VulkanSample<true>::create_render_context(surface_priority_list);
VulkanSample<vkb::BindingType::Cpp>::create_render_context(surface_priority_list);
}

void HPPApiVulkanSample::prepare_render_context()
{
VulkanSample<true>::prepare_render_context();
VulkanSample<vkb::BindingType::Cpp>::prepare_render_context();
}

void HPPApiVulkanSample::input_event(const vkb::InputEvent &input_event)
{
VulkanSample<true>::input_event(input_event);
VulkanSample<vkb::BindingType::Cpp>::input_event(input_event);

bool gui_captures_event = false;

Expand Down
2 changes: 1 addition & 1 deletion framework/hpp_api_vulkan_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct HPPVertex
*
* See vkb::ApiVulkanSample for documentation
*/
class HPPApiVulkanSample : public vkb::VulkanSample<true>
class HPPApiVulkanSample : public vkb::VulkanSample<vkb::BindingType::Cpp>
{
public:
HPPApiVulkanSample() = default;
Expand Down
2 changes: 1 addition & 1 deletion framework/hpp_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const ImGuiWindowFlags HPPGui::common_flags = ImGuiWindowFlags_NoMove |
const ImGuiWindowFlags HPPGui::options_flags = HPPGui::common_flags;
const ImGuiWindowFlags HPPGui::info_flags = HPPGui::common_flags | ImGuiWindowFlags_NoInputs;

HPPGui::HPPGui(VulkanSample<true> &sample_, const vkb::Window &window, const vkb::stats::HPPStats *stats, float font_size, bool explicit_update) :
HPPGui::HPPGui(VulkanSample<BindingType::Cpp> &sample_, const vkb::Window &window, const vkb::stats::HPPStats *stats, float font_size, bool explicit_update) :
sample{sample_}, content_scale_factor{window.get_content_scale_factor()}, dpi_factor{window.get_dpi_factor() * content_scale_factor}, explicit_update{explicit_update}, stats_view(stats)
{
ImGui::CreateContext();
Expand Down
18 changes: 9 additions & 9 deletions framework/hpp_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

namespace vkb
{
template <vkb::BindingType bindingType>
class VulkanSample;

/**
* @brief Helper structure for fonts loaded from TTF
*/
Expand Down Expand Up @@ -221,9 +224,6 @@ bool HPPDrawer::color_op_impl<HPPDrawer::ColorOp::Pick, 3>(const char *caption,
template <>
bool HPPDrawer::color_op_impl<HPPDrawer::ColorOp::Pick, 4>(const char *caption, float *colors, ImGuiColorEditFlags flags);

template <bool CppBindings>
class VulkanSample;

/**
* @brief Vulkan helper class for Dear ImGui, based on vulkan.hpp
*/
Expand Down Expand Up @@ -274,11 +274,11 @@ class HPPGui
* @param font_size The font size
* @param explicit_update If true, update buffers every frame
*/
HPPGui(VulkanSample<true> &sample,
const vkb::Window &window,
const vkb::stats::HPPStats *stats = nullptr,
float font_size = 21.0f,
bool explicit_update = false);
HPPGui(VulkanSample<vkb::BindingType::Cpp> &sample,
const vkb::Window &window,
const vkb::stats::HPPStats *stats = nullptr,
float font_size = 21.0f,
bool explicit_update = false);

/**
* @brief Destroys the HPPGui
Expand Down Expand Up @@ -415,7 +415,7 @@ class HPPGui

private:
PushConstBlock push_const_block;
VulkanSample<true> &sample;
VulkanSample<vkb::BindingType::Cpp> &sample;
std::unique_ptr<vkb::core::HPPBuffer> vertex_buffer;
std::unique_ptr<vkb::core::HPPBuffer> index_buffer;
size_t last_vertex_buffer_size = 0;
Expand Down
4 changes: 2 additions & 2 deletions framework/platform/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ void Platform::update()

active_app->update(delta_time);

if (auto *app = dynamic_cast<VulkanSample<true> *>(active_app.get()))
if (auto *app = dynamic_cast<VulkanSample<vkb::BindingType::Cpp> *>(active_app.get()))
{
if (app->has_render_context())
{
on_post_draw(reinterpret_cast<vkb::RenderContext &>(app->get_render_context()));
}
}
else if (auto *app = dynamic_cast<VulkanSample<false> *>(active_app.get()))
else if (auto *app = dynamic_cast<VulkanSample<vkb::BindingType::C> *>(active_app.get()))
{
if (app->has_render_context())
{
Expand Down
Loading

0 comments on commit 265a888

Please sign in to comment.