Skip to content

Commit

Permalink
simplify interface make it more c++ like
Browse files Browse the repository at this point in the history
  • Loading branch information
leanid committed Jan 18, 2025
1 parent 1620d19 commit 3b29a31
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
22 changes: 14 additions & 8 deletions 02-vulkan/09-vk-res-loading-1/platform_sdl3.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ platform_interface::extensions platform_sdl3::get_vulkan_extensions()
return extensions;
}

VkSurfaceKHR platform_sdl3::create_vulkan_surface(
VkInstance instance, VkAllocationCallbacks* alloc_callbacks)
vk::SurfaceKHR platform_sdl3::create_vulkan_surface(
vk::Instance instance, vk::AllocationCallbacks* alloc_callbacks)
{
VkSurfaceKHR surface{};
int result =
SDL_Vulkan_CreateSurface(window, instance, alloc_callbacks, &surface);
int result = SDL_Vulkan_CreateSurface(
window,
static_cast<VkInstance>(instance),
reinterpret_cast<VkAllocationCallbacks*>(alloc_callbacks),
&surface);

if (!result)
{
Expand All @@ -47,11 +50,14 @@ VkSurfaceKHR platform_sdl3::create_vulkan_surface(
}

void platform_sdl3::destroy_vulkan_surface(
VkInstance instance,
VkSurfaceKHR surface,
VkAllocationCallbacks* alloc_callbacks) noexcept
vk::Instance instance,
vk::SurfaceKHR surface,
vk::AllocationCallbacks* alloc_callbacks) noexcept
{
SDL_Vulkan_DestroySurface(instance, surface, alloc_callbacks);
SDL_Vulkan_DestroySurface(
static_cast<VkInstance>(instance),
static_cast<VkSurfaceKHR>(surface),
reinterpret_cast<VkAllocationCallbacks*>(alloc_callbacks));
}

platform_interface::buffer_size platform_sdl3::get_window_buffer_size()
Expand Down
13 changes: 7 additions & 6 deletions 02-vulkan/09-vk-res-loading-1/platform_sdl3.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ struct platform_sdl3 final : platform_interface
{
}

extensions get_vulkan_extensions() override;
VkSurfaceKHR create_vulkan_surface(
VkInstance instance, VkAllocationCallbacks* alloc_callbacks) override;
extensions get_vulkan_extensions() override;
vk::SurfaceKHR create_vulkan_surface(
vk::Instance instance,
vk::AllocationCallbacks* alloc_callbacks) override;
void destroy_vulkan_surface(
VkInstance instance,
VkSurfaceKHR surface,
VkAllocationCallbacks* alloc_callbacks) noexcept override;
vk::Instance instance,
vk::SurfaceKHR surface,
vk::AllocationCallbacks* alloc_callbacks) noexcept override;
buffer_size get_window_buffer_size() override;

std::ostream& get_logger() noexcept override;
Expand Down
17 changes: 7 additions & 10 deletions 02-vulkan/09-vk-res-loading-1/render.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

#include <experimental/scope> // not found on macOS

#undef VULKAN_HPP_NO_EXCEPTIONS // exceptions are enabled by default
// but we want to be explicit
#define VULKAN_HPP_NAMESPACE vk // explicit namespace to help IDE
#include <vulkan/vulkan.hpp>

namespace om::vulkan
Expand Down Expand Up @@ -62,14 +59,14 @@ struct platform_interface
}
};

virtual extensions get_vulkan_extensions() = 0;
virtual VkSurfaceKHR create_vulkan_surface(
VkInstance instance, VkAllocationCallbacks* alloc_callbacks) = 0;
virtual extensions get_vulkan_extensions() = 0;
virtual vk::SurfaceKHR create_vulkan_surface(
vk::Instance instance, vk::AllocationCallbacks* alloc_callbacks) = 0;
virtual void destroy_vulkan_surface(
VkInstance instance,
VkSurfaceKHR surface,
VkAllocationCallbacks* alloc_callbacks) noexcept = 0;
virtual buffer_size get_window_buffer_size() = 0;
vk::Instance instance,
vk::SurfaceKHR surface,
vk::AllocationCallbacks* alloc_callbacks) noexcept = 0;
virtual buffer_size get_window_buffer_size() = 0;

virtual std::ostream& get_logger() noexcept = 0;

Expand Down

0 comments on commit 3b29a31

Please sign in to comment.