Skip to content

Commit ee6effd

Browse files
committed
Shifted Vulkan window surface creation into renderer
1 parent 577dbb1 commit ee6effd

File tree

5 files changed

+8
-14
lines changed

5 files changed

+8
-14
lines changed

engine/render/renderer/Renderer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ Renderer::Renderer(Window& window) : window {window}
2626

2727
if (instance == nullptr) instance = this;
2828

29-
auto extent = window.GetExtents();
29+
auto createWindowSurface = [&window](VkInstance instance, VkSurfaceKHR* surface) -> bool {
30+
return glfwCreateWindowSurface(instance, window.GetGlfwWindow(), nullptr, surface) == VK_SUCCESS;
31+
};
3032

33+
auto extent = window.GetExtents();
3134
context.Init({extent.width, extent.height},
3235
Window::GetRequiredExtensions,
33-
Window::CreateWindowSurface);
36+
createWindowSurface);
3437

3538
DescriptorPool::AddPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1024);
3639
DescriptorPool::AddPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1024);

engine/render/renderer/platform/vulkan/Context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Context::~Context()
2525

2626
void Context::Init(const Utils::Extent2D& extent,
2727
Instance::GetSurfaceExtensionsCallback surfaceExtensionsCallback,
28-
GetWindowSurfaceCallBack windowSurfaceCallback)
28+
const GetWindowSurfaceCallBack& windowSurfaceCallback)
2929
{
3030
CC_ASSERT(volkInitialize() == VK_SUCCESS, "Unable to initialise Volk!")
3131

engine/render/renderer/platform/vulkan/Context.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ class Context
2020
{
2121
public:
2222

23-
typedef bool (*getSurfaceCallback)(VkInstance, Surface*);
23+
typedef std::function<bool(VkInstance, VkSurfaceKHR*)> getSurfaceCallback;
2424
typedef getSurfaceCallback GetWindowSurfaceCallBack;
2525

2626
Context() = default;
2727
~Context();
2828

2929
void Init(const Utils::Extent2D& extent,
3030
Instance::GetSurfaceExtensionsCallback surfaceExtensionsCallback,
31-
GetWindowSurfaceCallBack windowSurfaceCallback);
31+
const GetWindowSurfaceCallBack& windowSurfaceCallback);
3232

3333
static Context& Get();
3434

engine/render/window/Window.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ bool Window::WindowShouldClose()
2424
return glfwWindowShouldClose(window);
2525
}
2626

27-
bool Window::CreateWindowSurface(VkInstance instance, VkSurfaceKHR* surface)
28-
{
29-
return glfwCreateWindowSurface(instance, window, nullptr, surface) == VK_SUCCESS;
30-
}
31-
3227
MHArray<const char*> Window::GetRequiredExtensions()
3328
{
3429
uint32_t glfwExtensionCount = 0;

engine/render/window/Window.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#ifndef SIEGE_ENGINE_RENDERER_WINDOW_H
1010
#define SIEGE_ENGINE_RENDERER_WINDOW_H
1111

12-
#include <volk/volk.h>
13-
1412
#include <cstdint>
1513

1614
#include <GLFW/glfw3.h>
@@ -120,8 +118,6 @@ class Window
120118

121119
bool WindowShouldClose();
122120

123-
static bool CreateWindowSurface(VkInstance instance, VkSurfaceKHR* surface);
124-
125121
bool WasResized() const
126122
{
127123
return wasResized;

0 commit comments

Comments
 (0)