Skip to content

Commit

Permalink
Updated Vulkan.cpp to allow vulkan to work on mac.
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Oct 8, 2024
1 parent 5f83757 commit 9a34229
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ if(LINUX)
find_package(VulkanLoader REQUIRED)
endif(LINUX)

if(APPLE)
find_package(Vulkan REQUIRED)
# find_package(VulkanHeaders REQUIRED)
endif(APPLE)

find_package(glm REQUIRED)
find_package(fmt REQUIRED)
find_package(spdlog REQUIRED)
Expand Down Expand Up @@ -107,5 +112,21 @@ target_link_libraries(
)
endif(LINUX)

if(APPLE)
target_link_libraries(
${PROJECT_NAME}
PRIVATE
glfw
${OPENGL_LIBRARIES}
Vulkan::Vulkan
# vulkan-headers::vulkan-headers
glm::glm
fmt::fmt
spdlog::spdlog
yaml-cpp::yaml-cpp
# imguidocking::imguidocking
box2d::box2d
)
endif(APPLE)

install(TARGETS ${PROJECT_NAME})
File renamed without changes.
10 changes: 5 additions & 5 deletions engine3d/Core/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ namespace engine3d{
* @param IWidnowSpecified is what the user defines as their window.
* @note TODO --- Probably would have this be in helper_functions.h as this is an exposed to the API that uses may used to get the right API.
*/
template<typename UWindowSpecified, typename IWindowSpecified>
static UWindowSpecified* As(IWindowSpecified){
return static_cast<UWindowSpecified *>(GetCurrentWindowAPI());
}
/* template<typename UWindowSpecified, typename IWindowSpecified> */
/* static UWindowSpecified* As(IWindowSpecified){ */
/* return static_cast<UWindowSpecified *>(GetCurrentWindowAPI()); */
/* } */

bool IsActive() const;

Expand Down Expand Up @@ -51,4 +51,4 @@ namespace engine3d{

virtual void Presentation() = 0;
};
};
};
17 changes: 14 additions & 3 deletions src/engine3d/Core/internal/VulkanCpp/Vulkan.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "EngineLogger.h"
#include <Core/internal/VulkanCpp/Vulkan.h>
#include <cstdio>
#include <vulkan/vulkan_core.h>
#include <vector>
#include <stdexcept>
Expand Down Expand Up @@ -38,9 +40,11 @@ namespace engine3d::vk{
// "VK_LAYER_KHRONOS_shader_object",
};

VkInstance g_Instance;
static VkInstance g_Instance;

void Vulkan::InitializeVulkanCore(){
/* std::print("Initialization at {}",__FUNCTION__); */
printf("Initialization at InitializeVulkanCore()!!!!\n");
//! @note to initialize vulkan we need to first specify our application properties.
//! @note Initialize vulkan's instance information for instantiation.
VkApplicationInfo appInfo = {
Expand All @@ -62,9 +66,16 @@ namespace engine3d::vk{
.ppEnabledExtensionNames = extensions.data()
};

#if defined(__APPLE__)
createInfo.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
#endif

VkResult res = vkCreateInstance(&createInfo, nullptr, &g_Instance);
if(res != VK_SUCCESS){
throw std::runtime_error("vkCreateInstance errored message ===> ");
/* ConsoleLogError("vkCreateInstance errored message ===> {}", res); */
printf("%i\n", res);
printf("%s\n", res);
throw std::runtime_error("vkCreateInstance errored message ===> {}");
}

if(g_Instance == VK_NULL_HANDLE){
Expand All @@ -83,4 +94,4 @@ namespace engine3d::vk{
}
return g_Instance;
}
};
};

0 comments on commit 9a34229

Please sign in to comment.