Compare commits

..

No commits in common. "3bed6d2fd31e3a12a9947fe1a36ee0f72aaaa273" and "30d5712c0729d9eb8cffd533fc119250ee451787" have entirely different histories.

10 changed files with 54 additions and 100 deletions

3
.gitmodules vendored
View File

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

View File

@ -19,25 +19,16 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Qtk build options
option(QTK_DEBUG "Enable debugger" ON) option(QTK_DEBUG "Enable debugger" ON)
option(BUILD_SHARED_LIBS "Build shared library" ON) option(BUILD_SHARED_LIBS "Build shared library" ON)
option(UPDATE_SUBMODULES "Update external project (assimp) git submodule" ON) option(ASSIMP_NEW_INTERFACE "Use assimp::assimp as target instead of assimp" OFF)
# 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 # External Libraries
################################################################################ ################################################################################
# For CLion builds, point CMAKE_PREFIX_PATH to Qt6 install directory # For CLion builds, point CMAKE_PREFIX_PATH to Qt6 install directory
# + QtCreator will handle this for you if that is used instead list(APPEND CMAKE_PREFIX_PATH $ENV{HOME}/Code/Clones/Qt/6.3.1/gcc_64/)
list(APPEND CMAKE_PREFIX_PATH "${QT_DIR}")
# Find Qt # Find Qt
find_package(Qt6 COMPONENTS OpenGLWidgets) find_package(Qt6 COMPONENTS OpenGLWidgets)
@ -46,24 +37,11 @@ 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)`") 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() endif()
if (UPDATE_SUBMODULES) # Find Assimp
include("${CMAKE_SOURCE_DIR}/cmake/include/git_submodule.cmake") # https://github.com/assimp/assimp/commit/6ac8279977c3a54118551e549d77329497116f66
submodule_update(extern/assimp/assimp/) find_package(assimp REQUIRED)
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 # Qtk
@ -97,8 +75,6 @@ set(SOURCE_FILES
src/texture.cpp src/texture.cpp
src/transform3D.cpp src/transform3D.cpp
) )
include(GenerateExportHeader)
qt_add_library(qtk-widget STATIC ${PUBLIC_HEADERS} ${SOURCE_FILES}) qt_add_library(qtk-widget STATIC ${PUBLIC_HEADERS} ${SOURCE_FILES})
target_include_directories(qtk-widget PRIVATE src/ app/) target_include_directories(qtk-widget PRIVATE src/ app/)
generate_export_header(qtk-widget) generate_export_header(qtk-widget)
@ -108,12 +84,23 @@ set_target_properties(qtk-widget PROPERTIES
VERSION ${PROJECT_VERSION} VERSION ${PROJECT_VERSION}
) )
target_link_libraries(qtk-widget PUBLIC Qt6::OpenGLWidgets) target_include_directories(qtk-widget PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
if(BUILD_SHARED_LIBS)
if ((UPDATE_SUBMODULES AND NOT ASSIMP_DIR) OR NOT ASSIMP_NEW_INTERFACE) target_compile_definitions(qtk-widget PRIVATE QTK_EXPORT PUBLIC QTK_SHARED)
target_link_libraries(qtk-widget PRIVATE assimp) target_link_libraries(qtk-widget PRIVATE Qt6::OpenGLWidgets)
elseif(ASSIMP_NEW_INTERFACE) if(ASSIMP_NEW_INTERFACE)
target_link_libraries(qtk-widget PRIVATE assimp::assimp) 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()
endif() endif()
if(QTK_DEBUG) if(QTK_DEBUG)
@ -161,19 +148,19 @@ set(QTK_APP_SOURCES app/main.cpp
) )
qt6_add_big_resources(QTK_APP_SOURCES resources.qrc) qt6_add_big_resources(QTK_APP_SOURCES resources.qrc)
qt_add_executable(qtk-main ${QTK_APP_SOURCES}) qt_add_executable(qtk-app ${QTK_APP_SOURCES})
target_include_directories(qtk-main PRIVATE src/ app/) target_include_directories(qtk-app PRIVATE src/ app/)
# Link qtk-main executable to main qtk-widget library # Link qtk-app executable to main qtk-widget library
target_link_libraries(qtk-main PRIVATE qtk-widget) target_link_libraries(qtk-app PRIVATE Qt6::OpenGLWidgets qtk-widget)
set_target_properties(qtk-main PROPERTIES set_target_properties(qtk-app PROPERTIES
WIN32_EXECUTABLE TRUE WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
) )
install(TARGETS qtk-main install(TARGETS qtk-app
BUNDLE DESTINATION . BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
) )
@ -183,16 +170,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) 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) file(TO_NATIVE_PATH "${qt6_install_prefix}/bin" qt6_install_prefix)
if(TARGET Qt6::windeployqt) if(TARGET Qt6::windeployqt)
add_custom_command(TARGET qtk-main add_custom_command(TARGET qtk-app
POST_BUILD POST_BUILD
COMMAND set PATH=%PATH%$<SEMICOLON>${qt6_install_prefix} COMMAND set PATH=%PATH%$<SEMICOLON>${qt6_install_prefix}
COMMAND Qt6::windeployqt --dir "${CMAKE_BINARY_DIR}/windeployqt" "$<TARGET_FILE_DIR:qtk-main>/$<TARGET_FILE_NAME:qtk-main>" COMMAND Qt6::windeployqt --dir "${CMAKE_BINARY_DIR}/windeployqt" "$<TARGET_FILE_DIR:qtk-app>/$<TARGET_FILE_NAME:qtk-app>"
) )
install(DIRECTORY "${CMAKE_BINARY_DIR}/windeployqt/" DESTINATION bin) install(DIRECTORY "${CMAKE_BINARY_DIR}/windeployqt/" DESTINATION bin)
endif() endif()
if(MSVC AND TARGET Qt6::qmake) if(MSVC AND TARGET Qt6::qmake)
set(VSUSER_FILE ${CMAKE_CURRENT_BINARY_DIR}/qtk-main.vcxproj.user) set(VSUSER_FILE ${CMAKE_CURRENT_BINARY_DIR}/qtk-app.vcxproj.user)
file(TO_NATIVE_PATH "${ASSIMP_INSTALL_DIR}/bin" assimp_bin) file(TO_NATIVE_PATH "${assimp_DIR}/bin" assimp_bin)
file(WRITE ${VSUSER_FILE} "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n") 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} "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n")
file(APPEND ${VSUSER_FILE} " <PropertyGroup>\n") file(APPEND ${VSUSER_FILE} " <PropertyGroup>\n")

View File

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

View File

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

View File

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

View File

@ -1,31 +0,0 @@
################################################################################
## 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 +0,0 @@
Subproject commit bd64cc88dff17f118ecf32ebcbacaf566f6b6449

View File

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

View File

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

View File

@ -15,16 +15,14 @@ using namespace Qtk;
Skybox::Skybox(std::string right, std::string top, std::string front, Skybox::Skybox(std::string right, std::string top, std::string front,
std::string left, std::string bottom, std::string back, std::string left, std::string bottom, std::string back,
const std::string & name) const std::string & name)
: mVBO(QOpenGLBuffer::VertexBuffer), : 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),
mVertices(Cube(QTK_DRAW_ELEMENTS).vertices()), mVertices(Cube(QTK_DRAW_ELEMENTS).vertices()),
mIndices(Cube(QTK_DRAW_ELEMENTS).indices()) 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::Skybox(std::string name)
: Skybox(":/right.png", ":/top.png", ":/front.png", : Skybox(":/right.png", ":/top.png", ":/front.png",
@ -89,11 +87,13 @@ void Skybox::init()
mVBO.setUsagePattern(QOpenGLBuffer::StaticDraw); mVBO.setUsagePattern(QOpenGLBuffer::StaticDraw);
mVBO.bind(); mVBO.bind();
// Allocate vertex positions into VBO // 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 // Enable attribute array for vertex positions
mProgram.enableAttributeArray(0); 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 // Set shader texture unit to 0
mProgram.setUniformValue("uTexture", 0); mProgram.setUniformValue("uTexture", 0);