Skip to content

Commit

Permalink
Fix: Compilation without vulkan support
Browse files Browse the repository at this point in the history
  • Loading branch information
brenocq committed Dec 27, 2023
1 parent 84083ba commit ba6015d
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 44 deletions.
63 changes: 34 additions & 29 deletions src/atta/graphics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,6 @@ set(ATTA_GRAPHICS_MODULE_SOURCE
apis/openGL/indexBuffer.cpp
apis/openGL/pipeline.cpp
apis/openGL/mesh.cpp
apis/vulkan/buffer.cpp
apis/vulkan/commandBuffers.cpp
apis/vulkan/commandPool.cpp
apis/vulkan/common.cpp
apis/vulkan/debugMessenger.cpp
apis/vulkan/descriptorPool.cpp
apis/vulkan/descriptorSetLayout.cpp
apis/vulkan/descriptorSets.cpp
apis/vulkan/device.cpp
apis/vulkan/fence.cpp
apis/vulkan/framebuffer.cpp
apis/vulkan/image.cpp
apis/vulkan/indexBuffer.cpp
apis/vulkan/instance.cpp
apis/vulkan/mesh.cpp
apis/vulkan/physicalDevice.cpp
apis/vulkan/pipelineLayout.cpp
apis/vulkan/pushConstant.cpp
apis/vulkan/renderPass.cpp
apis/vulkan/renderQueue.cpp
apis/vulkan/semaphore.cpp
apis/vulkan/pipeline.cpp
apis/vulkan/shader.cpp
apis/vulkan/stagingBuffer.cpp
apis/vulkan/surface.cpp
apis/vulkan/swapChain.cpp
apis/vulkan/uniformBuffer.cpp
apis/vulkan/vertexBuffer.cpp
apis/vulkan/vulkanAPI.cpp

cameras/camera.cpp
cameras/perspectiveCamera.cpp
Expand Down Expand Up @@ -75,6 +46,40 @@ set(ATTA_GRAPHICS_MODULE_SOURCE
viewport.cpp
)

if(ATTA_VULKAN_SUPPORT)
list(ATTA_GRAPHICS_MODULE_SOURCE APPEND
apis/vulkan/buffer.cpp
apis/vulkan/commandBuffers.cpp
apis/vulkan/commandPool.cpp
apis/vulkan/common.cpp
apis/vulkan/debugMessenger.cpp
apis/vulkan/descriptorPool.cpp
apis/vulkan/descriptorSetLayout.cpp
apis/vulkan/descriptorSets.cpp
apis/vulkan/device.cpp
apis/vulkan/fence.cpp
apis/vulkan/framebuffer.cpp
apis/vulkan/image.cpp
apis/vulkan/indexBuffer.cpp
apis/vulkan/instance.cpp
apis/vulkan/mesh.cpp
apis/vulkan/physicalDevice.cpp
apis/vulkan/pipelineLayout.cpp
apis/vulkan/pushConstant.cpp
apis/vulkan/renderPass.cpp
apis/vulkan/renderQueue.cpp
apis/vulkan/semaphore.cpp
apis/vulkan/pipeline.cpp
apis/vulkan/shader.cpp
apis/vulkan/stagingBuffer.cpp
apis/vulkan/surface.cpp
apis/vulkan/swapChain.cpp
apis/vulkan/uniformBuffer.cpp
apis/vulkan/vertexBuffer.cpp
apis/vulkan/vulkanAPI.cpp
)
endif()

add_library(atta_graphics_module STATIC
${ATTA_GRAPHICS_MODULE_SOURCE}
)
Expand Down
35 changes: 25 additions & 10 deletions src/atta/graphics/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include <atta/graphics/manager.h>

#include <atta/graphics/apis/openGL/openGL.h>
#if ATTA_VULKAN_SUPPORT
#include <atta/graphics/apis/vulkan/vulkan.h>
#endif
#include <atta/graphics/cameras/orthographicCamera.h>
#include <atta/graphics/cameras/perspectiveCamera.h>
#include <atta/graphics/renderers/fastRenderer.h>
Expand All @@ -31,8 +33,11 @@
namespace atta::graphics {

Manager::Manager() {
// TODO check vulkan support
#if ATTA_VULKAN_SUPPORT
_desiredGraphicsAPI = GraphicsAPI::VULKAN;
#else
_desiredGraphicsAPI = GraphicsAPI::OPENGL;
#endif
}

Manager& Manager::getInstance() {
Expand Down Expand Up @@ -62,9 +67,11 @@ void Manager::startUpImpl() {
_window = std::static_pointer_cast<Window>(std::make_shared<GlfwWindow>(windowInfo));

//----- Renderer API -----//
#if ATTA_VULKAN_SUPPORT
if (_desiredGraphicsAPI == GraphicsAPI::VULKAN)
_graphicsAPI = std::static_pointer_cast<GraphicsAPI>(std::make_shared<VulkanAPI>(_window));
else
#endif
_graphicsAPI = std::static_pointer_cast<GraphicsAPI>(std::make_shared<OpenGLAPI>(_window));
_graphicsAPI->startUp();

Expand Down Expand Up @@ -299,34 +306,42 @@ const std::unordered_map<StringId, std::shared_ptr<Image>>& Manager::getImages()
// If the derived (e.g. VulkanImage) has the same type as the base (e.g. Image), it means that does not exists
// an implementation of Image for vulkan

#if ATTA_VULKAN_SUPPORT
// Vulkan supported
#define CHECK_VK_SUPPORT(x) vk::x
#else
// Vulkan not supported
#define CHECK_VK_SUPPORT(x) x
#endif

template <>
std::shared_ptr<Image> Manager::createImpl<Image>(Image::CreateInfo info) {
return createSpecific<Image, gl::Image, vk::Image>(info);
return createSpecific<Image, gl::Image, CHECK_VK_SUPPORT(Image)>(info);
}

template <>
std::shared_ptr<Mesh> Manager::createImpl<Mesh>(Mesh::CreateInfo info) {
return createSpecific<Mesh, gl::Mesh, vk::Mesh>(info);
return createSpecific<Mesh, gl::Mesh, CHECK_VK_SUPPORT(Mesh)>(info);
}

template <>
std::shared_ptr<Framebuffer> Manager::createImpl<Framebuffer>(Framebuffer::CreateInfo info) {
return createSpecific<Framebuffer, gl::Framebuffer, vk::Framebuffer>(info);
return createSpecific<Framebuffer, gl::Framebuffer, CHECK_VK_SUPPORT(Framebuffer)>(info);
}

template <>
std::shared_ptr<VertexBuffer> Manager::createImpl<VertexBuffer>(VertexBuffer::CreateInfo info) {
return createSpecific<VertexBuffer, gl::VertexBuffer, vk::VertexBuffer>(info);
return createSpecific<VertexBuffer, gl::VertexBuffer, CHECK_VK_SUPPORT(VertexBuffer)>(info);
}

template <>
std::shared_ptr<IndexBuffer> Manager::createImpl<IndexBuffer>(IndexBuffer::CreateInfo info) {
return createSpecific<IndexBuffer, gl::IndexBuffer, vk::IndexBuffer>(info);
return createSpecific<IndexBuffer, gl::IndexBuffer, CHECK_VK_SUPPORT(IndexBuffer)>(info);
}

template <>
std::shared_ptr<RenderPass> Manager::createImpl<RenderPass>(RenderPass::CreateInfo info) {
return createSpecific<RenderPass, gl::RenderPass, vk::RenderPass>(info);
return createSpecific<RenderPass, gl::RenderPass, CHECK_VK_SUPPORT(RenderPass)>(info);
}

template <>
Expand All @@ -336,17 +351,17 @@ std::shared_ptr<Shader> Manager::createImpl<Shader>(const char* file) {

template <>
std::shared_ptr<Shader> Manager::createImpl<Shader>(fs::path file) {
return createSpecific<Shader, gl::Shader, vk::Shader>(file);
return createSpecific<Shader, gl::Shader, CHECK_VK_SUPPORT(Shader)>(file);
}

template <>
std::shared_ptr<Pipeline> Manager::createImpl<Pipeline>(Pipeline::CreateInfo info) {
return createSpecific<Pipeline, gl::Pipeline, vk::Pipeline>(info);
return createSpecific<Pipeline, gl::Pipeline, CHECK_VK_SUPPORT(Pipeline)>(info);
}

template <>
std::shared_ptr<RenderQueue> Manager::createImpl<RenderQueue>() {
return createSpecific<RenderQueue, gl::RenderQueue, vk::RenderQueue>();
return createSpecific<RenderQueue, gl::RenderQueue, CHECK_VK_SUPPORT(RenderQueue)>();
}

} // namespace atta::graphics
7 changes: 6 additions & 1 deletion src/atta/ui/editor/moduleWindows/graphicsModuleWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ GraphicsModuleWindow::GraphicsModuleWindow() {

void GraphicsModuleWindow::renderImpl() {
// Graphics API control
const char* graphicsAPIs[] = {"OpenGL", "Vulkan"};
const char* graphicsAPIs[] = {
"OpenGL",
#if ATTA_VULKAN_SUPPORT
"Vulkan"
#endif
};
int currentGraphicsAPI = int(graphics::getGraphicsAPI()->getType());
if (ImGui::Combo("Graphics API", &currentGraphicsAPI, graphicsAPIs, IM_ARRAYSIZE(graphicsAPIs)))
graphics::setGraphicsAPI(graphics::GraphicsAPI::Type(currentGraphicsAPI));
Expand Down
10 changes: 10 additions & 0 deletions src/atta/ui/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#include <imgui.h>
#include <backends/imgui_impl_glfw.h>
#include <backends/imgui_impl_opengl3.h>
#if ATTA_VULKAN_SUPPORT
#include <backends/imgui_impl_vulkan.h>
#endif
#include <ImGuizmo.h>
#include <implot.h>
// clang-format on
Expand Down Expand Up @@ -72,7 +74,9 @@ void Manager::shutDownImpl() {
ImGui_ImplOpenGL3_Shutdown();
break;
case gfx::GraphicsAPI::VULKAN:
#if ATTA_VULKAN_SUPPORT
ImGui_ImplVulkan_Shutdown();
#endif
break;
}
ImGui_ImplGlfw_Shutdown();
Expand Down Expand Up @@ -119,6 +123,7 @@ void Manager::initOpenGL() {
}

void Manager::initVulkan() {
#if ATTA_VULKAN_SUPPORT
GLFWwindow* window = (GLFWwindow*)gfx::getWindow()->getHandle();
ImGui_ImplGlfw_InitForVulkan(window, true);
std::shared_ptr<gfx::VulkanAPI> vulkanAPI = std::dynamic_pointer_cast<gfx::VulkanAPI>(gfx::getGraphicsAPI());
Expand All @@ -139,6 +144,7 @@ void Manager::initVulkan() {
// Upload Fonts
if (!ImGui_ImplVulkan_CreateFontsTexture())
LOG_WARN("ui::Manager", "Failed to created ImGui font texture");
#endif
}

void Manager::render() {
Expand All @@ -148,7 +154,9 @@ void Manager::render() {
ImGui_ImplOpenGL3_NewFrame();
break;
case gfx::GraphicsAPI::VULKAN:
#if ATTA_VULKAN_SUPPORT
ImGui_ImplVulkan_NewFrame();
#endif
break;
}
ImGui_ImplGlfw_NewFrame();
Expand All @@ -165,8 +173,10 @@ void Manager::render() {
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
break;
case gfx::GraphicsAPI::VULKAN:
#if ATTA_VULKAN_SUPPORT
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(),
std::dynamic_pointer_cast<gfx::VulkanAPI>(gfx::getGraphicsAPI())->getCommandBuffers()->getCurrent());
#endif
break;
}

Expand Down
8 changes: 4 additions & 4 deletions src/extern/solveVulkan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ set(ATTA_VULKAN_TARGETS "")
find_package(Vulkan)

if(Vulkan_FOUND)
set(ATTA_VULKAN_SUPPORT TRUE)
set(ATTA_VULKAN_TARGETS ${Vulkan_LIBRARY})
atta_add_include_dirs(${Vulkan_INCLUDE_DIRS})
atta_log(Success Extern "Vulkan support (installed)")
#set(ATTA_VULKAN_SUPPORT TRUE)
#set(ATTA_VULKAN_TARGETS ${Vulkan_LIBRARY})
#atta_add_include_dirs(${Vulkan_INCLUDE_DIRS})
#atta_log(Success Extern "Vulkan support (installed)")
else()
atta_log(Warn Extern "Vulkan not supported")
endif()
Expand Down

0 comments on commit ba6015d

Please sign in to comment.