Skip to content
Snippets Groups Projects
Commit b0e06cd0 authored by Katharina Krämer's avatar Katharina Krämer
Browse files

[#16] added SwapChain class and added extension of swapchain to main

parent 42b402ba
Branches
Tags
4 merge requests!12Resolve "Swapchain Class",!7Resolve "Shader Program Class",!5Resolve "Pipeline State Object",!4Resolve "Renderpass Class"
......@@ -6,4 +6,6 @@ set(vkcv_sources
${vkcv_source}/vkcv/Window.cpp
${vkcv_source}/vkcv/CoreManager.hpp
${vkcv_source}/vkcv/CoreManager.cpp
${vkcv_source}/vkcv/SwapChain.hpp
${vkcv_source}/vkcv/SwapChain.cpp
)
#include <iostream>
#include <vkcv/Context.hpp>
#include <vkcv/Window.hpp>
#include <vkcv/SwapChain.hpp>
int main(int argc, const char** argv) {
const char* applicationName = "First Triangle";
......@@ -14,12 +15,16 @@ int main(int argc, const char** argv) {
applicationName,
VK_MAKE_VERSION(0, 0, 1),
20,
{vk::QueueFlagBits::eGraphics, vk::QueueFlagBits::eTransfer}
{vk::QueueFlagBits::eGraphics, vk::QueueFlagBits::eTransfer},
{},
{"VK_KHR_swapchain"}
);
GLFWwindow *glWindow = window.getWindow();
const vk::Instance& instance = context.getInstance();
const vk::PhysicalDevice& physicalDevice = context.getPhysicalDevice();
const vk::Device& device = context.getDevice();
const vkcv::SwapChain& swapChain = vkcv::SwapChain::create(glWindow, instance, physicalDevice, device);
std::cout << "Physical device: " << physicalDevice.getProperties().deviceName << std::endl;
......
#include "SwapChain.hpp"
#include "CoreManager.hpp"
#include <iostream>
namespace vkcv {
SwapChain::SwapChain(vk::SurfaceKHR surface)
: m_surface(surface)
{}
SwapChain SwapChain::create(GLFWwindow* window, const vk::Instance& instance, const vk::PhysicalDevice& physicalDevice, const vk::Device& device){
vk::SurfaceKHR surface = VK_NULL_HANDLE;
createSurface(window,surface,instance,physicalDevice);
vk::SurfaceCapabilitiesKHR surfaceCapabilities;
if(physicalDevice.getSurfaceCapabilitiesKHR(surface,&surfaceCapabilities) != vk::Result::eSuccess){
throw std::runtime_error("cannot get surface capabilites. There is an issue with the surface.");
}
return SwapChain(surface);
}
void SwapChain::createSurface(GLFWwindow *window, vk::SurfaceKHR &surface, const vk::Instance &instance, const vk::PhysicalDevice& physicalDevice) {
//create surface
auto newSurface = VkSurfaceKHR(surface);
// 0 means VK_SUCCESS
//std::cout << "FAIL: " << glfwCreateWindowSurface(VkInstance(instance), window, nullptr, &newSurface) << std::endl;
if(glfwCreateWindowSurface(VkInstance(instance), window, nullptr, &newSurface) != VK_SUCCESS) {
throw std::runtime_error("failed to create a window surface!");
}
vk::Bool32 surfaceSupport = false;
// ToDo: hierfuer brauchen wir jetzt den queuefamiliy Index -> siehe ToDo in Context.cpp
//if(physicalDevice.getSurfaceSupportKHR())
}
}
\ No newline at end of file
#pragma once
#include "vulkan/vulkan.hpp"
#include "Context.hpp"
#include "Window.hpp"
// glfw is not initialized in this class because ist must be sure that there exists a context first
// glfw is already initialized by the context or the window class
namespace vkcv {
class SwapChain final {
private:
vk::SurfaceKHR m_surface;
SwapChain(vk::SurfaceKHR);
public:
// bin mir grade unsicher wegen der Mehrfachinstanziierung der Klasse
// es muessen ja oefter mal neue erstellt werden, aber diese existieren ja nicht gleichzeitig, oder?
SwapChain(const SwapChain &other) = delete;
SwapChain(SwapChain &&other) = default;
static SwapChain create(GLFWwindow *window, const vk::Instance& instance,const vk::PhysicalDevice& physicalDevice,const vk::Device& device);
static void createSurface(GLFWwindow *window, vk::SurfaceKHR& surface, const vk::Instance& instance, const vk::PhysicalDevice& physicalDevice);
};
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment