Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SET(CMAKE_CXX_COMPILER "g++")

PROJECT(QtVulkan)

CMAKE_MINIMUM_REQUIRED(VERSION 3.5.0)

SET(CMAKE_CXX_STANDARD 14)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)

ADD_SUBDIRECTORY(lib)
ADD_SUBDIRECTORY(cube)
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,15 @@ Also make sure the include and library paths in cube.pro and lib.pro are correct

The plan is to port the rotating cube demo, as well as have a Qt Widget that contains a lot of the boilerplate for vulkan setup.

# building with CMake
If you would like to build the project using CMake instead of qmake, follow the below instructions

```
cd build
./build.sh
cd cube/
qtvulkan_cube
```

## known issues:
* resizing is stuck after one resize event
6 changes: 6 additions & 0 deletions build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CMakeCache.txt
cmake_install.cmake
Makefile
CMakeFiles/
cube/
lib/
13 changes: 13 additions & 0 deletions build/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# clean up the old build items
rm -rf CMakeCache.txt CMakeFiles/ cmake_install.cmake cube/ lib/ Makefile
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this part of a "make clean" target?


# build the project
cmake ..
make

# post work for assets
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this part of the cmake script?

mkdir cube/shaders
cp ../cube/*.spv cube/shaders
cp ../cube/lunarg.ppm cube
57 changes: 57 additions & 0 deletions cube/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
SET(CMAKE_AUTOMOC ON)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)

SET(CMAKE_CXX_LINK_FLAGS "-lvulkan")
SET(CMAKE_CXX_LINK_FLAGS "-lassimp")
SET(CMAKE_CXX_LINK_FLAGS "-lxcb")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_XCB_KHR")

MESSAGE(STATUS ${VULKAN_LIB})

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOMINMAX -DVK_PROTOTYPES -D_USE_MATH_DEFINES")

ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)

FIND_PACKAGE(Qt5Widgets REQUIRED)
FIND_PACKAGE(Qt5Gui REQUIRED)
FIND_PACKAGE(Qt5Core REQUIRED)
#FIND_PACKAGE(Qt5Quick REQUIRED)
#FIND_PACKAGE(Qt5Qml REQUIRED)

SET(qtvulkan_cube_SRCS
cube.cpp
)

INCLUDE_DIRECTORIES(${Qt5Gui_INCLUDE_DIRS}
${Qt5Core_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
#${Qt5Quick_INCLUDE_DIRS}
#${Qt5Qml_INCLUDE_DIRS}
)

SET(qtvulkan_cube_LIBS
${Qt5Widgets_LIBRARIES}
${Qt5Quick_LIBRARIES}
${Qt5Core_LIBRARIES}
#${Qt5Gui_LIBRARIES}
#${QT5Qml_LIBRARIES}
)

ADD_EXECUTABLE(qtvulkan_cube ${qtvulkan_cube_SRCS} ${qtvulkan_cube_MOC_SRCS})

SET_TARGET_PROPERTIES(qtvulkan_cube
PROPERTIES
CMAKE_CXX_STANDARD 11
CMAKE_CXX_STANDARD_REQUIRED ON
)

TARGET_LINK_LIBRARIES(qtvulkan_cube "-lvulkan" ${qtvulkan_cube_LIBS})

# INSTALL
#INSTALL( TARGETS qtvulkan_cube RUNTIME DESTINATION /usr/local/qtvulkan)

#FILE(GLOB SPIRV_FILES "*.spv")
#INSTALL(FILES ${SPIRV_FILES} DESTINATION /usr/local/qtvulkan/shaders)
9 changes: 6 additions & 3 deletions cube/cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
#include <QResizeEvent>

#include <QtMath>
#include <qpa/qplatformnativeinterface.h>
//#include <qpa/qplatformnativeinterface.h>
// TODO - I need to fix this below line so that you can build using the above line
#include <QtGui/5.6.0/QtGui/qpa/qplatformnativeinterface.h>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I won't merge it if it ties the whole build to this qt version

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you need qplatformnativeinterface for?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



static PFN_vkGetDeviceProcAddr g_gdpa = NULL;

Expand Down Expand Up @@ -1343,7 +1346,7 @@ VkShaderModule Demo::prepare_vs() {
char *vertShaderCode;
size_t size;

vertShaderCode = demo_read_spv("cube-vert.spv", &size);
vertShaderCode = demo_read_spv("shaders/cube-vert.spv", &size);

assert(vertShaderCode);
m_vert_shader_module =
Expand All @@ -1360,7 +1363,7 @@ VkShaderModule Demo::prepare_fs() {
char *fragShaderCode;
size_t size;

fragShaderCode = demo_read_spv("cube-frag.spv", &size);
fragShaderCode = demo_read_spv("shaders/cube-frag.spv", &size);
assert(fragShaderCode);
m_frag_shader_module =
prepare_shader_module(fragShaderCode, size);
Expand Down
56 changes: 56 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
SET(CMAKE_AUTOMOC ON)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)

SET(CMAKE_CXX_LINK_FLAGS "-lvulkan")
SET(CMAKE_CXX_LINK_FLAGS "-lassimp")
SET(CMAKE_CXX_LINK_FLAGS "-lxcb")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_XCB_KHR")

MESSAGE(STATUS ${VULKAN_LIB})

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOMINMAX -DVK_PROTOTYPES -D_USE_MATH_DEFINES")

ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)

FIND_PACKAGE(Qt5Widgets REQUIRED)
FIND_PACKAGE(Qt5Gui REQUIRED)
FIND_PACKAGE(Qt5Core REQUIRED)
#FIND_PACKAGE(Qt5Quick REQUIRED)
#FIND_PACKAGE(Qt5Qml REQUIRED)

SET(qtvulkan_SRCS
qvulkaninstance.cpp
qvulkanview.cpp
main.cpp
)

INCLUDE_DIRECTORIES(${Qt5Gui_INCLUDE_DIRS}
${Qt5Core_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
#${Qt5Quick_INCLUDE_DIRS}
#${Qt5Qml_INCLUDE_DIRS}
)

SET(qtvulkan_LIBS
${Qt5Widgets_LIBRARIES}
${Qt5Quick_LIBRARIES}
${Qt5Core_LIBRARIES}
#${Qt5Gui_LIBRARIES}
#${QT5Qml_LIBRARIES}
)

ADD_EXECUTABLE(qtvulkan ${qtvulkan_SRCS} ${qtvulkan_MOC_SRCS})

SET_TARGET_PROPERTIES(qtvulkan
PROPERTIES
CMAKE_CXX_STANDARD 11
CMAKE_CXX_STANDARD_REQUIRED ON
)

TARGET_LINK_LIBRARIES(qtvulkan "-lvulkan" ${qtvulkan_LIBS})

# INSTALL
#INSTALL( TARGETS qtvulkan RUNTIME DESTINATION /usr/local/qtvulkan)
5 changes: 4 additions & 1 deletion lib/qvulkanview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#include <QApplication>
#include <QStringList>
#include "qvulkaninstance.h"
#include <qpa/qplatformnativeinterface.h>
//#include <qpa/qplatformnativeinterface.h>
// TODO - I need to fix this below line so that you can build using the above line
#include <QtGui/5.6.0/QtGui/qpa/qplatformnativeinterface.h>


QVulkanInstance* QVulkanView::s_vulkanInstance = nullptr;

Expand Down