Compare commits

...

2 Commits

Author SHA1 Message Date
Shaun Reed 3bed6d2fd3 Use git submodule for assimp 2022-08-14 18:08:06 -04:00
Shaun Reed 590ac52dfb Add assimp as external dependency 2022-08-14 17:02:50 -04:00
10 changed files with 100 additions and 54 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "extern/assimp/assimp"]
path = extern/assimp/assimp
url = https://github.com/assimp/assimp.git

View File

@ -19,16 +19,25 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Qtk build options
option(QTK_DEBUG "Enable debugger" ON)
option(BUILD_SHARED_LIBS "Build shared library" ON)
option(ASSIMP_NEW_INTERFACE "Use assimp::assimp as target instead of assimp" OFF)
option(UPDATE_SUBMODULES "Update external project (assimp) git submodule" ON)
# Qt options
set(QT_DIR "$ENV{HOME}/Code/Clones/Qt/6.3.1/gcc_64/" CACHE PATH "Path to Qt6")
# Options for bringing your own assimp installation; Otherwise not needed
set(ASSIMP_DIR "" CACHE PATH "Path to local installation of assimp")
option(ASSIMP_NEW_INTERFACE "Use the assimp::assimp interface (WIN / OSX)" OFF)
################################################################################
# External Libraries
################################################################################
# For CLion builds, point CMAKE_PREFIX_PATH to Qt6 install directory
list(APPEND CMAKE_PREFIX_PATH $ENV{HOME}/Code/Clones/Qt/6.3.1/gcc_64/)
# + QtCreator will handle this for you if that is used instead
list(APPEND CMAKE_PREFIX_PATH "${QT_DIR}")
# Find Qt
find_package(Qt6 COMPONENTS OpenGLWidgets)
@ -37,11 +46,24 @@ if (NOT Qt6_FOUND)
message(FATAL_ERROR "Specify path to Qt6 with `cmake -DCMAKE_PREFIX_PATH=/path/to/Qt/6.x.x/gcc_64 -S /path/to/qtk -B /path/to/qtk/build && cmake --build /path/to/qtk/build -j $(nprocs)`")
endif()
# Find Assimp
# https://github.com/assimp/assimp/commit/6ac8279977c3a54118551e549d77329497116f66
find_package(assimp REQUIRED)
if (UPDATE_SUBMODULES)
include("${CMAKE_SOURCE_DIR}/cmake/include/git_submodule.cmake")
submodule_update(extern/assimp/assimp/)
add_subdirectory(extern/assimp/assimp)
else()
if (ASSIMP_DIR)
message(STATUS "Using custom ASSIMP_DIR: ${ASSIMP_DIR}")
list(APPEND CMAKE_PREFIX_PATH "${ASSIMP_DIR}")
endif()
find_package(assimp REQUIRED)
if (assimp_FOUND)
message(STATUS "Found assimp: ${assimp_DIR}")
else()
message(FATAL_ERROR "Could not find assimp at: ${CMAKE_PREFIX_PATH}")
endif()
endif()
include(GenerateExportHeader)
################################################################################
# Qtk
@ -75,6 +97,8 @@ set(SOURCE_FILES
src/texture.cpp
src/transform3D.cpp
)
include(GenerateExportHeader)
qt_add_library(qtk-widget STATIC ${PUBLIC_HEADERS} ${SOURCE_FILES})
target_include_directories(qtk-widget PRIVATE src/ app/)
generate_export_header(qtk-widget)
@ -84,23 +108,12 @@ set_target_properties(qtk-widget PROPERTIES
VERSION ${PROJECT_VERSION}
)
target_include_directories(qtk-widget PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
if(BUILD_SHARED_LIBS)
target_compile_definitions(qtk-widget PRIVATE QTK_EXPORT PUBLIC QTK_SHARED)
target_link_libraries(qtk-widget PRIVATE Qt6::OpenGLWidgets)
if(ASSIMP_NEW_INTERFACE)
target_link_libraries(qtk-widget PUBLIC assimp::assimp)
else()
target_link_libraries(qtk-widget PUBLIC assimp)
endif()
else()
target_compile_definitions(qtk-widget PUBLIC QTK_STATIC)
target_link_libraries(qtk-widget PUBLIC Qt6::OpenGLWidgets)
if(ASSIMP_NEW_INTERFACE)
target_link_libraries(qtk-widget PUBLIC assimp::assimp)
else()
target_link_libraries(qtk-widget PUBLIC assimp)
endif()
target_link_libraries(qtk-widget PUBLIC Qt6::OpenGLWidgets)
if ((UPDATE_SUBMODULES AND NOT ASSIMP_DIR) OR NOT ASSIMP_NEW_INTERFACE)
target_link_libraries(qtk-widget PRIVATE assimp)
elseif(ASSIMP_NEW_INTERFACE)
target_link_libraries(qtk-widget PRIVATE assimp::assimp)
endif()
if(QTK_DEBUG)
@ -148,19 +161,19 @@ set(QTK_APP_SOURCES app/main.cpp
)
qt6_add_big_resources(QTK_APP_SOURCES resources.qrc)
qt_add_executable(qtk-app ${QTK_APP_SOURCES})
target_include_directories(qtk-app PRIVATE src/ app/)
qt_add_executable(qtk-main ${QTK_APP_SOURCES})
target_include_directories(qtk-main PRIVATE src/ app/)
# Link qtk-app executable to main qtk-widget library
target_link_libraries(qtk-app PRIVATE Qt6::OpenGLWidgets qtk-widget)
# Link qtk-main executable to main qtk-widget library
target_link_libraries(qtk-main PRIVATE qtk-widget)
set_target_properties(qtk-app PROPERTIES
set_target_properties(qtk-main PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
)
install(TARGETS qtk-app
install(TARGETS qtk-main
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
@ -170,16 +183,16 @@ if(WIN32)
execute_process(COMMAND "${_qt6_qmake_location}" -query QT_INSTALL_PREFIX RESULT_VARIABLE return_code OUTPUT_VARIABLE qt6_install_prefix OUTPUT_STRIP_TRAILING_WHITESPACE)
file(TO_NATIVE_PATH "${qt6_install_prefix}/bin" qt6_install_prefix)
if(TARGET Qt6::windeployqt)
add_custom_command(TARGET qtk-app
add_custom_command(TARGET qtk-main
POST_BUILD
COMMAND set PATH=%PATH%$<SEMICOLON>${qt6_install_prefix}
COMMAND Qt6::windeployqt --dir "${CMAKE_BINARY_DIR}/windeployqt" "$<TARGET_FILE_DIR:qtk-app>/$<TARGET_FILE_NAME:qtk-app>"
COMMAND Qt6::windeployqt --dir "${CMAKE_BINARY_DIR}/windeployqt" "$<TARGET_FILE_DIR:qtk-main>/$<TARGET_FILE_NAME:qtk-main>"
)
install(DIRECTORY "${CMAKE_BINARY_DIR}/windeployqt/" DESTINATION bin)
endif()
if(MSVC AND TARGET Qt6::qmake)
set(VSUSER_FILE ${CMAKE_CURRENT_BINARY_DIR}/qtk-app.vcxproj.user)
file(TO_NATIVE_PATH "${assimp_DIR}/bin" assimp_bin)
set(VSUSER_FILE ${CMAKE_CURRENT_BINARY_DIR}/qtk-main.vcxproj.user)
file(TO_NATIVE_PATH "${ASSIMP_INSTALL_DIR}/bin" assimp_bin)
file(WRITE ${VSUSER_FILE} "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
file(APPEND ${VSUSER_FILE} "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n")
file(APPEND ${VSUSER_FILE} " <PropertyGroup>\n")

View File

@ -14,7 +14,7 @@
<string>Qtk - MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="Qtk::MainWidget" name="openGLWidget">
<widget class="Qtk::MainWidget" name="openGLWidget" native="true">
<property name="geometry">
<rect>
<x>10</x>
@ -94,8 +94,8 @@
</widget>
<customwidgets>
<customwidget>
<class>MainWidget</class>
<extends>QOpenGLWidget</extends>
<class>Qtk::MainWidget</class>
<extends>QWidget</extends>
<header>mainwidget.h</header>
</customwidget>
</customwidgets>

View File

@ -602,11 +602,7 @@ void ExampleScene::init()
void ExampleScene::draw()
{
mSkybox->draw();
for (auto & model : mModels) model->draw();
for (const auto &mesh : mMeshes) mesh->draw();
Scene::draw();
mTestPhong->mProgram.bind();
mTestPhong->setUniform("uModelInverseTransposed",

View File

@ -17,12 +17,13 @@
class ExampleScene : public Qtk::Scene {
public:
ExampleScene();
~ExampleScene();
virtual void init();
virtual void draw();
virtual void draw() override;
virtual void update();
private:

View File

@ -0,0 +1,31 @@
################################################################################
## Author: Shaun Reed | Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ##
## ##
## CMake function to update git submodules ##
################################################################################
include_guard()
find_package(Git)
# _PATH: Path to git submodule location that we want to update
# + submodule_update(extern/assimp)
function(submodule_update _PATH)
if (NOT UPDATE_SUBMODULES)
return()
endif()
if (NOT GIT_FOUND)
message(FATAL_ERROR "Error: No git executable found")
endif()
message(STATUS "${_PATH}")
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init "${_PATH}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE result
)
if (NOT result EQUAL 0)
message(FATAL_ERROR "Error: Unable to update git submodule at ${_PATH}")
endif()
endfunction()

1
extern/assimp/assimp vendored Submodule

@ -0,0 +1 @@
Subproject commit bd64cc88dff17f118ecf32ebcbacaf566f6b6449

View File

@ -20,12 +20,13 @@
namespace Qtk {
class Scene : protected QOpenGLFunctions {
friend class MainWidget;
public:
Scene();
~Scene();
virtual void init() = 0;
virtual void draw() = 0;
virtual void draw() { privDraw(); };
virtual void update() = 0;
static Camera3D & Camera() { return mCamera;}

View File

@ -65,7 +65,7 @@ void MainWidget::paintGL()
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
// Draw the scene first, since it handles drawing our skybox
if (mScene != Q_NULLPTR) mScene->privDraw();
if (mScene != Q_NULLPTR) mScene->draw();
}
void MainWidget::initializeGL()

View File

@ -15,14 +15,16 @@ using namespace Qtk;
Skybox::Skybox(std::string right, std::string top, std::string front,
std::string left, std::string bottom, std::string back,
const std::string & name)
: mCubeMap(Texture::initCubeMap(
QImage(right.c_str()).mirrored(), QImage(top.c_str()),
QImage(front.c_str()), QImage(left.c_str()),
QImage(bottom.c_str()), QImage(back.c_str()))),
mVBO(QOpenGLBuffer::VertexBuffer),
: mVBO(QOpenGLBuffer::VertexBuffer),
mVertices(Cube(QTK_DRAW_ELEMENTS).vertices()),
mIndices(Cube(QTK_DRAW_ELEMENTS).indices())
{ init();}
{
init();
mCubeMap = Texture::initCubeMap(
QImage(right.c_str()).mirrored(), QImage(top.c_str()),
QImage(front.c_str()), QImage(left.c_str()),
QImage(bottom.c_str()), QImage(back.c_str()));
}
Skybox::Skybox(std::string name)
: Skybox(":/right.png", ":/top.png", ":/front.png",
@ -87,13 +89,11 @@ void Skybox::init()
mVBO.setUsagePattern(QOpenGLBuffer::StaticDraw);
mVBO.bind();
// Allocate vertex positions into VBO
mVBO.allocate(mVertices.data(),
mVertices.size() * sizeof(mVertices[0]));
mVBO.allocate(mVertices.data(), mVertices.size() * sizeof(mVertices[0]));
// Enable attribute array for vertex positions
mProgram.enableAttributeArray(0);
mProgram.setAttributeBuffer(0, GL_FLOAT, 0,
3, sizeof(QVector3D));
mProgram.setAttributeBuffer(0, GL_FLOAT, 0, 3, sizeof(QVector3D));
// Set shader texture unit to 0
mProgram.setUniformValue("uTexture", 0);