From 2ec08561f1a375633097bb785b9cec5924d8e486 Mon Sep 17 00:00:00 2001 From: Benedikt Ziemons Date: Thu, 13 Jan 2022 23:06:09 +0100 Subject: [PATCH] Initial commit --- .gitignore | 1 + .idea/.gitignore | 8 ++++++++ .idea/VulkanCppSetup.iml | 2 ++ .idea/codeStyles/codeStyleConfig.xml | 5 +++++ .idea/encodings.xml | 6 ++++++ .idea/misc.xml | 4 ++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ CMakeLists.txt | 11 +++++++++++ README.md | 9 +++++++++ src/VulkanRenderer.cpp | 21 +++++++++++++++++++++ src/VulkanRenderer.h | 23 +++++++++++++++++++++++ src/VulkanWindow.cpp | 19 +++++++++++++++++++ src/VulkanWindow.h | 22 ++++++++++++++++++++++ src/main.cpp | 20 ++++++++++++++++++++ 15 files changed, 165 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/VulkanCppSetup.iml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 src/VulkanRenderer.cpp create mode 100644 src/VulkanRenderer.h create mode 100644 src/VulkanWindow.cpp create mode 100644 src/VulkanWindow.h create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ca3806 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/cmake-build-* diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/VulkanCppSetup.iml b/.idea/VulkanCppSetup.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/VulkanCppSetup.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..79b3c94 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1e6ad92 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9bbaa4c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.22) +project(VulkanCppSetup) + +set(CMAKE_CXX_STANDARD 20) + +find_package(Vulkan REQUIRED) +find_package(Qt5 COMPONENTS Gui REQUIRED) + +add_executable(VulkanCppSetup src/main.cpp src/VulkanWindow.cpp src/VulkanRenderer.cpp) +#include_directories(VulkanCppSetup ${Vulkan_INCLUDE_DIRS} ${Qt5_INCLUDE_DIRS}) +target_link_libraries(VulkanCppSetup ${Vulkan_LIBRARIES} Qt5::Gui) diff --git a/README.md b/README.md new file mode 100644 index 0000000..f4a5598 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# Vulkan Renderer + +## Building + +Needs cmake 3.22+, C++20 compiler, Qt 5.10+ + +## Usage + +ESC to quit diff --git a/src/VulkanRenderer.cpp b/src/VulkanRenderer.cpp new file mode 100644 index 0000000..c3a6352 --- /dev/null +++ b/src/VulkanRenderer.cpp @@ -0,0 +1,21 @@ +#include "VulkanRenderer.h" + +VulkanRenderer::VulkanRenderer(QVulkanWindow *w) + : m_window(w), m_devFuncs(nullptr) {} + +void VulkanRenderer::initResources() { + m_devFuncs = + m_window->vulkanInstance()->deviceFunctions(m_window->device()); +} + +void VulkanRenderer::initSwapChainResources() {} +void VulkanRenderer::releaseSwapChainResources() {} +void VulkanRenderer::releaseResources() {} + +void VulkanRenderer::startNextFrame() { + VkCommandBuffer cmdBuf = m_window->currentCommandBuffer(); + + // m_devFuncs->vkCmdBeginRenderPass(…); + + m_window->frameReady(); +} diff --git a/src/VulkanRenderer.h b/src/VulkanRenderer.h new file mode 100644 index 0000000..2c68057 --- /dev/null +++ b/src/VulkanRenderer.h @@ -0,0 +1,23 @@ +#ifndef VULKANCPPSETUP_VULKANRENDERER_H +#define VULKANCPPSETUP_VULKANRENDERER_H + +#include +#include + +class VulkanRenderer : public QVulkanWindowRenderer { +public: + explicit VulkanRenderer(QVulkanWindow *w); + + void initResources() override; + void initSwapChainResources() override; + void releaseSwapChainResources() override; + void releaseResources() override; + + void startNextFrame() override; + +private: + QVulkanWindow *m_window; + QVulkanDeviceFunctions *m_devFuncs; +}; + +#endif // VULKANCPPSETUP_VULKANRENDERER_H diff --git a/src/VulkanWindow.cpp b/src/VulkanWindow.cpp new file mode 100644 index 0000000..52abf89 --- /dev/null +++ b/src/VulkanWindow.cpp @@ -0,0 +1,19 @@ +#include "VulkanWindow.h" +#include "VulkanRenderer.h" +#include + +static const int KEY_ESCAPE = 16777216; + +void VulkanWindow::keyPressEvent(QKeyEvent *event) { + QWindow::keyPressEvent(event); + qDebug() << "text" << event->text() + << "key" << event->key() + << "modifiers" << event->modifiers(); + if (event->matches(QKeySequence::Quit) || event->key() == KEY_ESCAPE) { + close(); + } +} + +QVulkanWindowRenderer *VulkanWindow::createRenderer() { + return new VulkanRenderer(this); +} diff --git a/src/VulkanWindow.h b/src/VulkanWindow.h new file mode 100644 index 0000000..c515314 --- /dev/null +++ b/src/VulkanWindow.h @@ -0,0 +1,22 @@ +// +// Created by ben on 13.01.22. +// + +#ifndef VULKANCPPSETUP_VULKANWINDOW_H +#define VULKANCPPSETUP_VULKANWINDOW_H + +#include +#include +#include + +class VulkanWindow : public QVulkanWindow +{ +public: + QVulkanWindowRenderer *createRenderer() override; + +protected: + void keyPressEvent(QKeyEvent* event) override; + +}; + +#endif //VULKANCPPSETUP_VULKANWINDOW_H diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..466527f --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,20 @@ +#include "VulkanWindow.h" +#include +#include + +int main(int argc, char **argv) { + QGuiApplication app(argc, argv); + + QVulkanInstance inst; + QByteArrayList layers{"VK_LAYER_LUNARG_standard_validation"}; + inst.setLayers(layers); + if (!inst.create()) + return EXIT_FAILURE; + + VulkanWindow window{}; + window.setVulkanInstance(&inst); + window.resize(800, 600); + window.show(); + + return QGuiApplication::exec(); +}