mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2024-12-04 19:23:28 +01:00
load vulkan using volk and create window instance surface
This commit is contained in:
parent
0f361f6505
commit
96722abe4e
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -37,3 +37,6 @@
|
||||
path = external/physfs/physfs
|
||||
url = https://github.com/icculus/physfs.git
|
||||
branch = main
|
||||
[submodule "external/volk"]
|
||||
path = external/volk
|
||||
url = https://github.com/zeux/volk.git
|
||||
|
8
external/CMakeLists.txt
vendored
8
external/CMakeLists.txt
vendored
@ -38,6 +38,13 @@ if(NOT MM_HEADLESS)
|
||||
add_subdirectory("glad-debug")
|
||||
endif()
|
||||
|
||||
# TODO: determain if we need this
|
||||
#if (WIN32)
|
||||
#set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_WIN32_KHR)
|
||||
#elseif()
|
||||
#endif()
|
||||
add_subdirectory("volk")
|
||||
|
||||
# stb utilies
|
||||
add_subdirectory("stb")
|
||||
|
||||
@ -54,4 +61,3 @@ if(NOT MM_HEADLESS)
|
||||
add_subdirectory("soloud")
|
||||
endif()
|
||||
|
||||
|
||||
|
1
external/volk
vendored
Submodule
1
external/volk
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 2784718c913433d718561f9a9488996b4c05c2ff
|
@ -40,6 +40,9 @@ else()
|
||||
target_link_libraries(sdl_service glad)
|
||||
endif()
|
||||
|
||||
# TODO: conditionaly
|
||||
target_link_libraries(sdl_service volk::volk)
|
||||
|
||||
if(VCPKG_TARGET_TRIPLET)
|
||||
target_link_libraries(sdl_service SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static)
|
||||
endif()
|
||||
|
@ -1,4 +1,7 @@
|
||||
add_executable(sdl_service_test start_test.cpp)
|
||||
add_executable(sdl_service_test
|
||||
./start_test.cpp
|
||||
./volk_test1.cpp
|
||||
)
|
||||
|
||||
target_include_directories(sdl_service_test PRIVATE ".")
|
||||
|
||||
|
82
framework/sdl_service/test/volk_test1.cpp
Normal file
82
framework/sdl_service/test/volk_test1.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <mm/engine.hpp>
|
||||
#include <mm/services/sdl_service.hpp>
|
||||
|
||||
#include <SDL_vulkan.h>
|
||||
|
||||
#include <volk.h>
|
||||
|
||||
TEST(sdl_service, window_volk) {
|
||||
MM::Engine engine;
|
||||
|
||||
engine.addService<MM::Services::SDLService>();
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::SDLService>());
|
||||
|
||||
auto* sdl_ss_ptr = engine.tryService<MM::Services::SDLService>();
|
||||
ASSERT_NE(sdl_ss_ptr, nullptr);
|
||||
|
||||
// init volk
|
||||
auto init_res = volkInitialize();
|
||||
ASSERT_EQ(init_res, VK_SUCCESS);
|
||||
|
||||
|
||||
// create window
|
||||
ASSERT_EQ(sdl_ss_ptr->win, nullptr);
|
||||
ASSERT_TRUE(sdl_ss_ptr->createWindow("test vulkan window", 800, 600, SDL_WINDOW_VULKAN));
|
||||
ASSERT_NE(sdl_ss_ptr->win, nullptr);
|
||||
|
||||
// create vulkan instance
|
||||
|
||||
// Get the required extension count
|
||||
unsigned int count;
|
||||
ASSERT_TRUE(
|
||||
SDL_Vulkan_GetInstanceExtensions(
|
||||
sdl_ss_ptr->win,
|
||||
&count,
|
||||
nullptr
|
||||
)
|
||||
);
|
||||
|
||||
std::vector<const char*> extensions {
|
||||
//VK_EXT_DEBUG_REPORT_EXTENSION_NAME // Sample additional extension
|
||||
};
|
||||
size_t additional_extension_count = extensions.size();
|
||||
extensions.resize(additional_extension_count + count);
|
||||
|
||||
ASSERT_TRUE(
|
||||
SDL_Vulkan_GetInstanceExtensions(
|
||||
sdl_ss_ptr->win,
|
||||
&count,
|
||||
extensions.data() + additional_extension_count
|
||||
)
|
||||
);
|
||||
|
||||
// Now we can make the Vulkan instance
|
||||
VkInstanceCreateInfo create_info {};
|
||||
//create_info.pApplicationInfo;
|
||||
create_info.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
|
||||
create_info.ppEnabledExtensionNames = extensions.data();
|
||||
|
||||
VkInstance instance;
|
||||
VkResult result = vkCreateInstance(&create_info, nullptr, &instance);
|
||||
ASSERT_EQ(result, VK_SUCCESS);
|
||||
|
||||
// finish setting up volk ?
|
||||
volkLoadInstance(instance);
|
||||
|
||||
// the surface for the window
|
||||
VkSurfaceKHR surface;
|
||||
ASSERT_TRUE(
|
||||
SDL_Vulkan_CreateSurface(
|
||||
sdl_ss_ptr->win,
|
||||
instance,
|
||||
&surface
|
||||
)
|
||||
);
|
||||
|
||||
engine.disableService<MM::Services::SDLService>();
|
||||
|
||||
ASSERT_EQ(sdl_ss_ptr->win, nullptr);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user