From da0fba176063153d576164e7cccba9f1c7a71968 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 1 Jul 2020 16:27:47 +0800 Subject: [PATCH] add QTVulkan example --- CMCMakeModule | 2 +- CMPlatform | 2 +- CMakeLists.txt | 7 ++++ example/Vulkan/CMakeLists.txt | 23 +++++++++++ example/Vulkan/QtVulkanMainWindow.cpp | 21 ++++++++++ example/Vulkan/QtVulkanMainWindow.h | 24 ++++++++++++ example/Vulkan/QtVulkanWindow.cpp | 25 ++++++++++++ example/Vulkan/QtVulkanWindow.h | 40 +++++++++++++++++++ example/Vulkan/VulkanQtApp.cpp | 55 +++++++++++++++++++++++++++ 9 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 example/Vulkan/QtVulkanMainWindow.cpp create mode 100644 example/Vulkan/QtVulkanMainWindow.h create mode 100644 example/Vulkan/QtVulkanWindow.cpp create mode 100644 example/Vulkan/QtVulkanWindow.h create mode 100644 example/Vulkan/VulkanQtApp.cpp diff --git a/CMCMakeModule b/CMCMakeModule index 7d35df75..2b3b2256 160000 --- a/CMCMakeModule +++ b/CMCMakeModule @@ -1 +1 @@ -Subproject commit 7d35df757f12b204fd4556669d10b131cc373e3d +Subproject commit 2b3b225659aa182b69a53b887815aa915dd8723e diff --git a/CMPlatform b/CMPlatform index 9b1975a8..165e95c0 160000 --- a/CMPlatform +++ b/CMPlatform @@ -1 +1 @@ -Subproject commit 9b1975a8a5c74dfc5189b4d7f23d155b6e15cca8 +Subproject commit 165e95c0d54e4ba978bcba50a0f7b43200648309 diff --git a/CMakeLists.txt b/CMakeLists.txt index fa9bd8e5..e89d61ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,8 @@ use_cm_module(Platform) use_cm_module(AssetsManage) use_cm_module(SceneGraph) +OPTION(SUPPORT_QT_VULKAN OFF) + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") include_directories(${ULRE_3RDPTY_ROOT_PATH}/jsoncpp/include) add_subdirectory(3rdpty/jsoncpp) @@ -49,3 +51,8 @@ SET(ULRE_RUNTIME_PATH ${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory(src) add_subdirectory(example) + +IF(SUPPORT_QT_VULKAN) + fix_project_version(1,1) + add_project_meta(META_FILES_TO_INCLUDE) +ENDIF(SUPPORT_QT_VULKAN) \ No newline at end of file diff --git a/example/Vulkan/CMakeLists.txt b/example/Vulkan/CMakeLists.txt index d30cf8ad..3fade0e0 100644 --- a/example/Vulkan/CMakeLists.txt +++ b/example/Vulkan/CMakeLists.txt @@ -9,6 +9,20 @@ set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Vulkan") endmacro() +macro(CreateQtProject name) + add_executable(${name} ${ARGN} VulkanAppFramework.h) + + set(IDENTIFIER "com.hyzgame.texconv") + + target_link_libraries(${name} ${ULRE} Qt5::Core Qt5::Gui Qt5::Widgets) + + IF(WIN32) + set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH}) + ENDIF() + + set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Vulkan") +endmacro() + CreateProject(00.triangle first_triangle.cpp) CreateProject(01.FragCoord FragCoordTest.cpp) CreateProject(02.indices_rect indices_rect.cpp) @@ -23,6 +37,15 @@ CreateProject(10.InlineGeometryScene InlineGeometryScene.cpp) CreateProject(11.Atomsphere Atomsphere.cpp) CreateProject(12.DrawText DrawText.cpp) +IF(SUPPORT_QT_VULKAN) +include(QtCommon) +CreateQtProject(13.VulkanQT VulkanQtApp.cpp + QtVulkanWindow.cpp + QtVulkanWindow.h + QtVulkanMainWindow.h + QtVulkanMainWindow.cpp) +ENDIF(SUPPORT_QT_VULKAN) + #CreateProject(12.PBRBasic PBRBasic.cpp) #CreateProject(12.Deferred Deferred.cpp) #CreateProject(13.DeferredModel DeferredModel.cpp) diff --git a/example/Vulkan/QtVulkanMainWindow.cpp b/example/Vulkan/QtVulkanMainWindow.cpp new file mode 100644 index 00000000..1c26ec48 --- /dev/null +++ b/example/Vulkan/QtVulkanMainWindow.cpp @@ -0,0 +1,21 @@ +#include"QtVulkanMainWindow.h" + +MainWindow::MainWindow(QtVulkanWindow *w):m_window(w) +{ + this->setWindowTitle(QString("Vulkan and QT")); + + QWidget *wrapper = QWidget::createWindowContainer(w); + QVBoxLayout *layout = new QVBoxLayout; + + m_info=new QPlainTextEdit; + m_info->setReadOnly(true); + + layout->addWidget(m_info,1); + layout->addWidget(wrapper,5); + setLayout(layout); +} + +void MainWindow::onVulkanInfoReceived(const QString &text) +{ + m_info->setPlainText(text); +} \ No newline at end of file diff --git a/example/Vulkan/QtVulkanMainWindow.h b/example/Vulkan/QtVulkanMainWindow.h new file mode 100644 index 00000000..07b4f974 --- /dev/null +++ b/example/Vulkan/QtVulkanMainWindow.h @@ -0,0 +1,24 @@ +#pragma once +#include +#include +#include +#include"QtVulkanWindow.h" + +class MainWindow:public QWidget +{ + Q_OBJECT + +private: + + QtVulkanWindow *m_window; + QPlainTextEdit *m_info; + +public slots: + + void onVulkanInfoReceived(const QString &text); + +public: + + MainWindow(QtVulkanWindow *w); + virtual ~MainWindow()=default; +};// \ No newline at end of file diff --git a/example/Vulkan/QtVulkanWindow.cpp b/example/Vulkan/QtVulkanWindow.cpp new file mode 100644 index 00000000..03341b35 --- /dev/null +++ b/example/Vulkan/QtVulkanWindow.cpp @@ -0,0 +1,25 @@ +#include"QtVulkanWindow.h" + +void VulkanRenderer::initResources() +{ + m_devFuncs=m_window->vulkanInstance()->deviceFunctions(m_window->device()); + +} + +void VulkanRenderer::initSwapChainResources() +{ +} + +void VulkanRenderer::releaseSwapChainResources() +{ +} + +void VulkanRenderer::releaseResources() +{ +} + +void VulkanRenderer::startNextFrame() +{ + m_window->frameReady(); + m_window->requestUpdate(); // render continuously, throttled by the presentation rate +} \ No newline at end of file diff --git a/example/Vulkan/QtVulkanWindow.h b/example/Vulkan/QtVulkanWindow.h new file mode 100644 index 00000000..7b0dddb8 --- /dev/null +++ b/example/Vulkan/QtVulkanWindow.h @@ -0,0 +1,40 @@ +#pragma once +#include + +class VulkanRenderer:public QVulkanWindowRenderer +{ +private: + + QVulkanWindow *m_window; + QVulkanDeviceFunctions *m_devFuncs; + +public: + + VulkanRenderer(QVulkanWindow *w):m_window(w){} + virtual ~VulkanRenderer()=default; + + void initResources() override; + void initSwapChainResources() override; + void releaseSwapChainResources() override; + void releaseResources() override; + void startNextFrame() override; +};//class VulkanRenderer:public QVulkanWindowRenderer + +class QtVulkanWindow:public QVulkanWindow +{ + Q_OBJECT + +signals: + + void vulkanInfoReceived(const QString &text); + +public: + + using QVulkanWindow::QVulkanWindow; + virtual ~QtVulkanWindow()=default; + + QVulkanWindowRenderer *createRenderer() override + { + return(new VulkanRenderer(this)); + } +}; diff --git a/example/Vulkan/VulkanQtApp.cpp b/example/Vulkan/VulkanQtApp.cpp new file mode 100644 index 00000000..c459b168 --- /dev/null +++ b/example/Vulkan/VulkanQtApp.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include"QtVulkanMainWindow.h" +#include + +using namespace hgl; +using namespace hgl::graph; + +//vulkan::Device *CreateRenderDevice(QVulkanWindow *qvw) +//{ +// VkDevice vk_device=qvw->device(); +// VkPhysicalDevice vk_pdevice=qvw->physicalDevice(); +// +// +// +//} + +//class VulkanQtAppFramework +//{ +// QVulkanInstance qv_inst; +// QtVulkanWindow *qv_win; +// +//public: +// +// VulkanQtAppFramework() +// { +// } +// +//};// + +int main(int argc,char **argv) +{ + QApplication qt_app(argc,argv); + + QVulkanInstance qv_inst; + + if(!qv_inst.create()) + return -1; + + QtVulkanWindow *qv_win=new QtVulkanWindow; + qv_win->setVulkanInstance(&qv_inst); + + MainWindow win(qv_win); + + QObject::connect(qv_win,&QtVulkanWindow::vulkanInfoReceived,&win,&MainWindow::onVulkanInfoReceived); + + win.resize(1280,720); + win.show(); + + qt_app.exec(); + return 0; +} +