Initial commit

This commit is contained in:
Ben 2022-01-13 23:06:09 +01:00
commit 2ec08561f1
Signed by: ben
GPG Key ID: 0F54A7ED232D3319
15 changed files with 165 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/cmake-build-*

8
.idea/.gitignore vendored Normal file
View File

@ -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

2
.idea/VulkanCppSetup.iml Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

6
.idea/encodings.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/VulkanCppSetup.iml" filepath="$PROJECT_DIR$/.idea/VulkanCppSetup.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

11
CMakeLists.txt Normal file
View File

@ -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)

9
README.md Normal file
View File

@ -0,0 +1,9 @@
# Vulkan Renderer
## Building
Needs cmake 3.22+, C++20 compiler, Qt 5.10+
## Usage
ESC to quit

21
src/VulkanRenderer.cpp Normal file
View File

@ -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();
}

23
src/VulkanRenderer.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef VULKANCPPSETUP_VULKANRENDERER_H
#define VULKANCPPSETUP_VULKANRENDERER_H
#include <QVulkanWindowRenderer>
#include <qvulkanfunctions.h>
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

19
src/VulkanWindow.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "VulkanWindow.h"
#include "VulkanRenderer.h"
#include <qevent.h>
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);
}

22
src/VulkanWindow.h Normal file
View File

@ -0,0 +1,22 @@
//
// Created by ben on 13.01.22.
//
#ifndef VULKANCPPSETUP_VULKANWINDOW_H
#define VULKANCPPSETUP_VULKANWINDOW_H
#include <iostream>
#include <qevent.h>
#include <QVulkanWindow>
class VulkanWindow : public QVulkanWindow
{
public:
QVulkanWindowRenderer *createRenderer() override;
protected:
void keyPressEvent(QKeyEvent* event) override;
};
#endif //VULKANCPPSETUP_VULKANWINDOW_H

20
src/main.cpp Normal file
View File

@ -0,0 +1,20 @@
#include "VulkanWindow.h"
#include <QtGui/QGuiApplication>
#include <QtGui/QVulkanWindow>
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();
}