Skip to content

Commit 8c95f34

Browse files
directly create a surface
1 parent e7e7ebf commit 8c95f34

File tree

8 files changed

+49
-169
lines changed

8 files changed

+49
-169
lines changed

bldsys/cmake/component_helpers.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function(vkb__register_component)
4444
if(TARGET_SRC) # Create static library
4545
message("ADDING STATIC: vkb__${TARGET_NAME}")
4646

47-
add_library("vkb__${TARGET_NAME}" STATIC ${TARGET_SRC} ${TARGET_HEADERS})
47+
add_library("vkb__${TARGET_NAME}" STATIC ${TARGET_SRC})
4848

4949
if(TARGET_LINK_LIBS)
5050
target_link_libraries("vkb__${TARGET_NAME}" PUBLIC ${TARGET_LINK_LIBS})

components/vfs/include/components/vfs/std_filesystem.hpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@ class StdFSFileSystem : public FileSystem
3333
{
3434
public:
3535
StdFSFileSystem(const std::filesystem::path &base_path = "");
36-
virtual ~StdFSFileSystem() = default;
37-
38-
virtual bool folder_exists(const std::string &file_path) override;
39-
virtual bool file_exists(const std::string &file_path) override;
40-
virtual StackErrorPtr read_chunk(const std::string &file_path, const size_t offset, const size_t count, std::shared_ptr<Blob> *blob) override;
41-
virtual size_t file_size(const std::string &file_path) override;
42-
virtual StackErrorPtr write_file(const std::string &file_path, const void *data, size_t size) override;
43-
virtual StackErrorPtr enumerate_files(const std::string &file_path, std::vector<std::string> *files) override;
44-
virtual StackErrorPtr enumerate_folders(const std::string &file_path, std::vector<std::string> *folders) override;
45-
virtual void make_directory(const std::string &path) override;
46-
virtual bool remove(const std::string &path) override;
36+
~StdFSFileSystem() override = default;
37+
38+
bool folder_exists(const std::string &folder_path) const override;
39+
bool file_exists(const std::string &file_path) const override;
40+
std::vector<uint8_t> read_chunk(const std::string &file_path, size_t offset, size_t count) const override;
41+
size_t file_size(const std::string &file_path) const override;
42+
void write_file(const std::string &file_path, const void *data, size_t size) override;
43+
void make_directory(const std::string &path) override;
44+
bool remove(const std::string &path) override;
45+
46+
std::vector<std::string> enumerate_files(const std::string &folder_path) const override;
47+
std::vector<std::string> enumerate_folders(const std::string &folderPath) const override;
4748

4849
protected:
4950
std::filesystem::path m_base_path;
@@ -57,7 +58,7 @@ class StdFSTempFileSystem final : public StdFSFileSystem
5758
{
5859
public:
5960
StdFSTempFileSystem();
60-
virtual ~StdFSTempFileSystem() = default;
61+
~StdFSTempFileSystem() override = default;
6162
};
6263
} // namespace vfs
6364
} // namespace components

components/vfs/src/root_file_system.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ std::vector<uint8_t> FileSystem::read_file(const std::string &file_path) const
3333
return read_chunk(file_path, 0, file_size(file_path));
3434
}
3535

36-
StackErrorPtr FileSystem::read_file(const std::string &file_path, std::shared_ptr<Blob> *blob)
37-
{
38-
return read_chunk(file_path, 0, file_size(file_path), blob);
39-
}
4036

4137
void FileSystem::make_directory_recursive(const std::string &path)
4238
{
@@ -118,8 +114,6 @@ RootFileSystem::RootFileSystem(const std::string &base_path) :
118114

119115
bool RootFileSystem::folder_exists(const std::string &folder_path) const
120116
{
121-
assert(blob);
122-
123117
std::string adjusted_path;
124118
auto fs = find_file_system(folder_path, &adjusted_path);
125119
if (!fs)
@@ -143,8 +137,6 @@ bool RootFileSystem::file_exists(const std::string &file_path) const
143137

144138
std::vector<uint8_t> RootFileSystem::read_chunk(const std::string &file_path, size_t offset, size_t count) const
145139
{
146-
assert(data);
147-
148140
std::string adjusted_path;
149141
auto fs = find_file_system(file_path, &adjusted_path);
150142
if (!fs)
@@ -157,8 +149,6 @@ std::vector<uint8_t> RootFileSystem::read_chunk(const std::string &file_path, si
157149

158150
size_t RootFileSystem::file_size(const std::string &file_path) const
159151
{
160-
assert(files);
161-
162152
std::string adjusted_path;
163153
auto fs = find_file_system(file_path, &adjusted_path);
164154
if (!fs)
@@ -236,18 +226,6 @@ bool RootFileSystem::remove(const std::string &path)
236226
return fs->remove(adjusted_path);
237227
}
238228

239-
bool RootFileSystem::remove(const std::string &path)
240-
{
241-
std::string adjusted_path;
242-
auto fs = find_file_system(path, &adjusted_path);
243-
if (!fs)
244-
{
245-
return false;
246-
}
247-
248-
return fs->remove(adjusted_path);
249-
}
250-
251229
void RootFileSystem::mount(const std::string &file_path, std::shared_ptr<FileSystem> file_system)
252230
{
253231
for (auto &mount : m_mounts)

components/windows/include/components/windows/glfw.hpp

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -34,47 +34,18 @@ class GLFWWindow : public Window
3434

3535
public:
3636
GLFWWindow(const std::string &title = "New Window", const Extent &initial_extent = {600, 600});
37-
virtual ~GLFWWindow();
38-
virtual void set_extent(const Extent &extent) override;
39-
virtual Extent extent() const override;
40-
virtual void set_position(const Position &position) override;
41-
virtual Position position() const override;
42-
virtual float dpi_factor() const override;
43-
virtual void set_title(const std::string &title) override;
44-
virtual std::string_view title() const override;
45-
virtual void update() override;
46-
virtual void attach(events::EventBus &bus) override;
37+
~GLFWWindow();
38+
void set_extent(const Extent &extent) override;
39+
Extent extent() const override;
40+
void set_position(const Position &position) override;
41+
Position position() const override;
42+
float dpi_factor() const override;
43+
void set_title(const std::string &title) override;
44+
std::string_view title() const override;
45+
void update() override;
46+
void attach(events::EventBus &bus) override;
4747

48-
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
49-
virtual VkResult populate_surface_create_info(VkAndroidSurfaceCreateInfoKHR * /* info */) const override
50-
{
51-
return VK_INCOMPLETE;
52-
}
53-
#elif defined(VK_USE_PLATFORM_WIN32_KHR)
54-
virtual VkResult populate_surface_create_info(VkWin32SurfaceCreateInfoKHR * /* info */) const override;
55-
#elif defined(VK_USE_PLATFORM_METAL_EXT)
56-
virtual VkResult populate_surface_create_info(VkMetalSurfaceCreateInfoEXT * /* info */) const override
57-
{
58-
return VK_INCOMPLETE;
59-
}
60-
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
61-
virtual VkResult populate_surface_create_info(VkXlibSurfaceCreateInfoKHR * /* info */) const override;
62-
#elif defined(VK_USE_PLATFORM_XCB_KHR)
63-
virtual VkResult populate_surface_create_info(VkXcbSurfaceCreateInfoKHR * /* info */) const override
64-
{
65-
return VK_INCOMPLETE;
66-
}
67-
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
68-
virtual VkResult populate_surface_create_info(VkWaylandSurfaceCreateInfoKHR * /* info */) const override
69-
{
70-
return VK_INCOMPLETE;
71-
}
72-
#elif defined(VK_USE_PLATFORM_DISPLAY_KHR)
73-
virtual VkResult populate_surface_create_info(VkDisplaySurfaceCreateInfoKHR * /* info */) const override
74-
{
75-
return VK_INCOMPLETE;
76-
}
77-
#endif
48+
VkResult create_surface(VkInstance instance, VkSurfaceKHR* surface) override;
7849

7950
protected:
8051
std::string m_title;

components/windows/include/components/windows/headless.hpp

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -27,53 +27,18 @@ class HeadlessWindow : public Window
2727
{
2828
public:
2929
HeadlessWindow(const std::string &title = "New Window", const Extent &initial_extent = {600, 600});
30-
virtual ~HeadlessWindow() = default;
31-
virtual void set_extent(const Extent &extent) override;
32-
virtual Extent extent() const override;
33-
virtual void set_position(const Position &position) override;
34-
virtual Position position() const override;
35-
virtual float dpi_factor() const override;
36-
virtual void set_title(const std::string &title) override;
37-
virtual std::string_view title() const override;
38-
virtual void update() override;
39-
virtual void attach(events::EventBus &bus) override;
40-
41-
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
42-
virtual VkResult populate_surface_create_info(VkAndroidSurfaceCreateInfoKHR * /* info */) const override
43-
{
44-
return VK_INCOMPLETE;
45-
}
46-
#elif defined(VK_USE_PLATFORM_WIN32_KHR)
47-
virtual VkResult populate_surface_create_info(VkWin32SurfaceCreateInfoKHR * /* info */) const override
48-
{
49-
return VK_INCOMPLETE;
50-
}
51-
#elif defined(VK_USE_PLATFORM_METAL_EXT)
52-
virtual VkResult populate_surface_create_info(VkMetalSurfaceCreateInfoEXT * /* info */) const override
53-
{
54-
return VK_INCOMPLETE;
55-
}
56-
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
57-
virtual VkResult populate_surface_create_info(VkXlibSurfaceCreateInfoKHR * /* info */) const override
58-
{
59-
return VK_INCOMPLETE;
60-
}
61-
#elif defined(VK_USE_PLATFORM_XCB_KHR)
62-
virtual VkResult populate_surface_create_info(VkXcbSurfaceCreateInfoKHR * /* info */) const override
63-
{
64-
return VK_INCOMPLETE;
65-
}
66-
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
67-
virtual VkResult populate_surface_create_info(VkWaylandSurfaceCreateInfoKHR * /* info */) const override
68-
{
69-
return VK_INCOMPLETE;
70-
}
71-
#elif defined(VK_USE_PLATFORM_DISPLAY_KHR)
72-
virtual VkResult populate_surface_create_info(VkDisplaySurfaceCreateInfoKHR * /* info */) const override
73-
{
74-
return VK_INCOMPLETE;
75-
}
76-
#endif
30+
~HeadlessWindow() = default;
31+
void set_extent(const Extent &extent) override;
32+
Extent extent() const override;
33+
void set_position(const Position &position) override;
34+
Position position() const override;
35+
float dpi_factor() const override;
36+
void set_title(const std::string &title) override;
37+
std::string_view title() const override;
38+
void update() override;
39+
void attach(events::EventBus &bus) override;
40+
41+
VkResult create_surface(VkInstance instance, VkSurfaceKHR* surface) override;
7742

7843
private:
7944
std::string m_title;

components/windows/include/components/windows/window.hpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,7 @@ class Window : public events::EventObserver
7676
virtual void set_title(const std::string &title) = 0;
7777
virtual std::string_view title() const = 0;
7878

79-
// supported vulkan surface create infos
80-
// compile errors indicate that a platform supports a surface but we do not have an implementation for it
81-
82-
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
83-
virtual VkResult populate_surface_create_info(VkAndroidSurfaceCreateInfoKHR * /* info */) const = 0;
84-
#elif defined(VK_USE_PLATFORM_WIN32_KHR)
85-
virtual VkResult populate_surface_create_info(VkWin32SurfaceCreateInfoKHR * /* info */) const = 0;
86-
#elif defined(VK_USE_PLATFORM_METAL_EXT)
87-
virtual VkResult populate_surface_create_info(VkMetalSurfaceCreateInfoEXT * /* info */) const = 0;
88-
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
89-
virtual VkResult populate_surface_create_info(VkXlibSurfaceCreateInfoKHR * /* info */) const = 0;
90-
#elif defined(VK_USE_PLATFORM_XCB_KHR)
91-
virtual VkResult populate_surface_create_info(VkXcbSurfaceCreateInfoKHR * /* info */) const = 0;
92-
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
93-
virtual VkResult populate_surface_create_info(VkWaylandSurfaceCreateInfoKHR * /* info */) const = 0;
94-
#elif defined(VK_USE_PLATFORM_DISPLAY_KHR)
95-
virtual VkResult populate_surface_create_info(VkDisplaySurfaceCreateInfoKHR * /* info */) const = 0;
96-
#endif
79+
virtual VkResult create_surface(VkInstance instance, VkSurfaceKHR* surface) = 0;
9780
};
9881
} // namespace windows
9982
} // namespace components

components/windows/src/glfw.cpp

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include <components/windows/glfw.hpp>
1919

20+
#include <vulkan/vulkan.h>
21+
2022
#include <GLFW/glfw3.h>
2123

2224
#ifdef VK_USE_PLATFORM_WIN32_KHR
@@ -469,36 +471,9 @@ void GLFWWindow::attach(events::EventBus &bus)
469471
m_touch_sender = bus.request_sender<events::TouchEvent>();
470472
}
471473

472-
#ifdef VK_USE_PLATFORM_WIN32_KHR
473-
VkResult GLFWWindow::populate_surface_create_info(VkWin32SurfaceCreateInfoKHR *o_info) const
474+
VkResult GLFWWindow::create_surface(VkInstance instance, VkSurfaceKHR *surface)
474475
{
475-
assert(o_info);
476-
477-
VkWin32SurfaceCreateInfoKHR info{};
478-
info.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
479-
info.hwnd = glfwGetWin32Window(m_handle);
480-
481-
*o_info = info;
482-
483-
return VK_SUCCESS;
476+
return glfwCreateWindowSurface(instance, m_handle, nullptr, surface);
484477
}
485-
#endif
486-
487-
#ifdef VK_USE_PLATFORM_XLIB_KHR
488-
VkResult GLFWWindow::populate_surface_create_info(VkXlibSurfaceCreateInfoKHR *o_info) const
489-
{
490-
assert(o_info);
491-
492-
VkXlibSurfaceCreateInfoKHR info{};
493-
info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
494-
info.window = glfwGetX11Window(m_handle);
495-
info.dpy = glfwGetX11Display();
496-
497-
*o_info = info;
498-
499-
return VK_SUCCESS;
500-
}
501-
#endif
502-
503478
} // namespace windows
504479
} // namespace components

components/windows/src/headless.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include <components/windows/headless.hpp>
1919

20+
#include <vulkan/vulkan.h>
21+
2022
namespace components
2123
{
2224
namespace windows
@@ -86,5 +88,10 @@ void HeadlessWindow::attach(events::EventBus &bus)
8688
m_position_sender = bus.request_sender<PositionChangedEvent>();
8789
}
8890

91+
VkResult HeadlessWindow::create_surface(VkInstance /* instance */, VkSurfaceKHR * /* surface */)
92+
{
93+
return VK_ERROR_INCOMPATIBLE_DISPLAY_KHR;
94+
}
95+
8996
} // namespace windows
9097
} // namespace components

0 commit comments

Comments
 (0)