Compare commits
41 Commits
logging
...
0ef62ebfa5
| Author | SHA1 | Date | |
|---|---|---|---|
| 0ef62ebfa5 | |||
| 2476d125f7 | |||
| 5118726cde | |||
| b3f9e3230e | |||
| f5de113c9a | |||
| 98793f7a75 | |||
| cd641072ab | |||
| 460a44e7e6 | |||
| b0e123e6dd | |||
| be69d2d242 | |||
| 3c2f7e8b5d | |||
| fc1ded833d | |||
| 5015c5c3a4 | |||
| 2087f10681 | |||
| e6b197d6fa | |||
| 6a52eee501 | |||
| 6d51aef9cf | |||
| 5bde82d956 | |||
| ae5abb9939 | |||
| d9c59a04ec | |||
| e6bcd131b7 | |||
| 0659df94bd | |||
| 0dcb6d337b | |||
| 002bedd7ef | |||
| 6ce71dda86 | |||
| b3484ced03 | |||
| 5e886672da | |||
| 126cd438e1 | |||
| 39fa8e8cdc | |||
| 48719412f2 | |||
| aa32cbcc17 | |||
| cfefc49c53 | |||
| 195a4ef30d | |||
| 55dd8e5c3c | |||
| cf433ad7fc | |||
| 4bc0ae22c6 | |||
| faa9fe28f7 | |||
| f83f68207d | |||
| 85c9e2eac1 | |||
| 194888ed19 | |||
| c948d9e1a6 |
35
.github/workflows/all-builds.yml
vendored
35
.github/workflows/all-builds.yml
vendored
@@ -5,9 +5,6 @@ on:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
QT_VERSION: 6.6.0
|
||||
|
||||
jobs:
|
||||
Qtk:
|
||||
env:
|
||||
@@ -18,13 +15,13 @@ jobs:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
cmake: -DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG
|
||||
cmake: -DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/6.5.0/gcc_64/ $CONFIG
|
||||
flags: -j $(nproc)
|
||||
- os: windows-latest
|
||||
cmake: -DCMAKE_PREFIX_PATH=D:/a/qtk/qtk/Qt/$QT_VERSION/mingw81_64/ $CONFIG
|
||||
cmake: -DCMAKE_PREFIX_PATH=D:/a/qtk/qtk/Qt/6.5.0/mingw81_64/ $CONFIG
|
||||
flags: ''
|
||||
- os: macos-latest
|
||||
cmake: -DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG
|
||||
cmake: -DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/6.5.0/gcc_64/ $CONFIG
|
||||
flags: -j $(nproc)
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
@@ -34,7 +31,7 @@ jobs:
|
||||
- name: Install Qt
|
||||
uses: jurplel/install-qt-action@v2
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
version: '6.5.0'
|
||||
|
||||
# Windows
|
||||
|
||||
@@ -148,13 +145,13 @@ jobs:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
cmake: -DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG
|
||||
cmake: -DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/6.5.0/gcc_64/ $CONFIG
|
||||
flags: -j $(nproc)
|
||||
- os: windows-latest
|
||||
cmake: -DCMAKE_PREFIX_PATH=D:/a/qtk/qtk/Qt/$QT_VERSION/mingw81_64/ $CONFIG
|
||||
cmake: -DCMAKE_PREFIX_PATH=D:/a/qtk/qtk/Qt/6.5.0/mingw81_64/ $CONFIG
|
||||
flags: ''
|
||||
- os: macos-latest
|
||||
cmake: -DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG
|
||||
cmake: -DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/6.5.0/gcc_64/ $CONFIG
|
||||
flags: -j $(nproc)
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
@@ -164,7 +161,7 @@ jobs:
|
||||
- name: Install Qt
|
||||
uses: jurplel/install-qt-action@v2
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
version: '6.5.0'
|
||||
|
||||
# Windows
|
||||
|
||||
@@ -253,13 +250,13 @@ jobs:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
cmake: -DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG
|
||||
cmake: -DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/6.5.0/gcc_64/ $CONFIG
|
||||
flags: -j $(nproc)
|
||||
- os: windows-latest
|
||||
cmake: -DCMAKE_PREFIX_PATH=D:/a/qtk/qtk/Qt/$QT_VERSION/mingw81_64/ $CONFIG
|
||||
cmake: -DCMAKE_PREFIX_PATH=D:/a/qtk/qtk/Qt/6.5.0/mingw81_64/ $CONFIG
|
||||
flags: ''
|
||||
- os: macos-latest
|
||||
cmake: -DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG
|
||||
cmake: -DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/6.5.0/gcc_64/ $CONFIG
|
||||
flags: -j $(nproc)
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
@@ -269,7 +266,7 @@ jobs:
|
||||
- name: Install Qt
|
||||
uses: jurplel/install-qt-action@v2
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
version: '6.5.0'
|
||||
|
||||
- name: Chocolatey Action
|
||||
if: matrix.os == 'windows-latest'
|
||||
@@ -298,9 +295,9 @@ jobs:
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
cmake: -DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/
|
||||
cmake: -DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/6.5.0/gcc_64/
|
||||
- os: macos-latest
|
||||
cmake: -DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/
|
||||
cmake: -DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/6.5.0/gcc_64/ -DASSIMP_NEW_INTERFACE=ON
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
@@ -309,7 +306,7 @@ jobs:
|
||||
- name: Install Qt
|
||||
uses: jurplel/install-qt-action@v2
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
version: '6.5.0'
|
||||
|
||||
- name: Install Assimp MacOS
|
||||
if: matrix.os == 'macos-latest'
|
||||
@@ -325,7 +322,7 @@ jobs:
|
||||
|
||||
- name: Configure Qtk
|
||||
shell: bash
|
||||
run: cmake -B build/ ${{ matrix.cmake }} -DQTK_CCACHE=OFF -DQTK_ASSIMP_NEW_INTERFACE=ON
|
||||
run: cmake -B build/ ${{ matrix.cmake }} -DQTK_CCACHE=OFF
|
||||
|
||||
- name: Build Qtk
|
||||
shell: bash
|
||||
|
||||
@@ -84,13 +84,17 @@ endif ()
|
||||
set(QTK_RESOURCES "${CMAKE_SOURCE_DIR}/resources")
|
||||
set(QTK_OSX_ICONS ${CMAKE_SOURCE_DIR}/resources/icons/osx/kilroy.icns)
|
||||
|
||||
# Print all QTK options and their values at the end of configuration.
|
||||
get_cmake_property(VAR_NAMES VARIABLES)
|
||||
list(FILTER VAR_NAMES INCLUDE REGEX "^Q[tT][kK]_.*$")
|
||||
list(SORT VAR_NAMES)
|
||||
|
||||
################################################################################
|
||||
# External Dependencies
|
||||
################################################################################
|
||||
# Point CMAKE_PREFIX_PATH to Qt6 install directory
|
||||
# If Qtk is built within Qt Creator this is not required.
|
||||
list(APPEND CMAKE_PREFIX_PATH "${QT_INSTALL_DIR}")
|
||||
if (QTK_PREFIX_QTCREATOR)
|
||||
# TODO: This might be a bit strange and needs more testing.
|
||||
set(CMAKE_INSTALL_PREFIX "${QT_INSTALL_DIR}")
|
||||
endif()
|
||||
|
||||
set(
|
||||
QT_CREATOR_DIR
|
||||
@@ -98,11 +102,10 @@ set(
|
||||
CACHE PATH "Qt Creator path used to install Qtk plugins for Qt Designer."
|
||||
)
|
||||
|
||||
# Print all QTK options and their values at the end of configuration.
|
||||
# We initialize this list here so that we can append to it as needed.
|
||||
# All variables in this list will be printed at the end of configuration.
|
||||
|
||||
# Print all QTK options and their values.
|
||||
get_cmake_property(VAR_NAMES VARIABLES)
|
||||
list(FILTER VAR_NAMES INCLUDE REGEX "^[qQ][tT][kK]_.*$")
|
||||
list(FILTER VAR_NAMES INCLUDE REGEX "^Q[tT][kK]_.*$")
|
||||
list(SORT VAR_NAMES)
|
||||
|
||||
################################################################################
|
||||
@@ -145,7 +148,6 @@ set(
|
||||
CMAKE_PREFIX_PATH CMAKE_INSTALL_PREFIX QTK_PLUGIN_INSTALL_DIR QT6_INSTALL_PREFIX
|
||||
QT_INSTALL_DIR
|
||||
)
|
||||
# Add QT6_INSTALL_PLUGINS to VAR_NAMES so it is printed at end of configuration.
|
||||
list(APPEND VAR_NAMES QT6_INSTALL_PLUGINS)
|
||||
|
||||
# Find Assimp.
|
||||
@@ -187,8 +189,6 @@ if(QTK_EXAMPLE)
|
||||
add_subdirectory(example-app EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
# Print all QTK options and their values at the end of configuration. This also
|
||||
# prints any additional variables that we have added to VAR_NAMES and VAR_PATHS.
|
||||
foreach(VAR_NAME IN LISTS VAR_NAMES VAR_PATHS)
|
||||
if(VAR_NAME IN_LIST VAR_PATHS)
|
||||
# Print absolute if variable is path
|
||||
|
||||
18
README.md
18
README.md
@@ -40,26 +40,26 @@ and [Qt Creator](https://github.com/qt-creator/qt-creator).
|
||||
Simply open the root `CMakeLists.txt` with either of these editors and
|
||||
configurations will be loaded.
|
||||
|
||||
This project has been ported to **Qt 6.6.0**, which is not yet available in
|
||||
This project has been ported to **Qt 6.5.0**, which is not yet available in
|
||||
Ubuntu apt repositories.
|
||||
To run this project, you will *need* to
|
||||
install [Qt6 Open Source Binaries](https://www.qt.io/download-qt-installer) for
|
||||
your system, **version 6.6.0** or later.
|
||||
your system, **version 6.5.0** or later.
|
||||
Be sure to take note of the Qt6 installation directory, as we will need it to
|
||||
correctly set our `CMAKE_PREFIX_PATH` in the next steps.
|
||||
|
||||
If you are building on **Windows / Mac**, consider setting
|
||||
the `-DQTK_ASSIMP_NEW_INTERFACE` cmake build option.
|
||||
the `-DASSIMP_NEW_INTERFACE` build flag.
|
||||
|
||||
If the build is configured with all options enabled, we can subsequently install
|
||||
individual components as needed with cmake.
|
||||
|
||||
```bash
|
||||
sudo apt update -y && sudo apt install libassimp-dev cmake build-essential git ccache libgl1-mesa-dev libglvnd-dev zlib1g-dev -y
|
||||
sudo apt update -y && sudo apt install libassimp-dev cmake build-essential git ccache libgl1-mesa-dev libglvnd-dev -y
|
||||
git clone https://github.com/shaunrd0/qtk
|
||||
cd qtk
|
||||
# Configure the build with all components enabled
|
||||
cmake -B build-all -DQTK_GUI=ON -DQTK_PLUGINS=ON -DQTK_EXAMPLE=ON -DCMAKE_PREFIX_PATH=$HOME/Qt/6.6.0/gcc_64
|
||||
cmake -B build-all -DQTK_GUI=ON -DQTK_PLUGINS=ON -DQTK_EXAMPLE=ON -DCMAKE_PREFIX_PATH=$HOME/Qt/6.5.0/gcc_64
|
||||
# Build all targets
|
||||
cmake --build build-all/
|
||||
````
|
||||
@@ -75,7 +75,7 @@ Windows / Mac / Linux) and may be easier
|
||||
to configure.
|
||||
|
||||
```bash
|
||||
cmake -B build-all -DQTK_GUI=ON -DQTK_PLUGINS=ON -DQTK_EXAMPLE=ON -DQTK_SUBMODULES=ON -DCMAKE_PREFIX_PATH=$HOME/Qt/6.6.0/gcc_64
|
||||
cmake -B build-all -DQTK_GUI=ON -DQTK_PLUGINS=ON -DQTK_EXAMPLE=ON -DQTK_SUBMODULES=ON -DCMAKE_PREFIX_PATH=$HOME/Qt/6.5.0/gcc_64
|
||||
```
|
||||
|
||||
#### Qtk GUI
|
||||
@@ -149,9 +149,9 @@ cmake --build build-all/ --target qtk_plugins -- -j $(nproc)
|
||||
# The path here should be initialized during build configuration, so no need for --prefix
|
||||
cmake --install build-all/ --component qtk_plugins
|
||||
-- Install configuration: "Release"
|
||||
-- Up-to-date: /home/shaun/Qt/6.6.0/gcc_64/../../Tools/QtCreator/lib/Qt/lib/libqtk_library.a
|
||||
-- Up-to-date: /home/shaun/Qt/6.6.0/gcc_64/../../Tools/QtCreator/lib/Qt/lib/libqtk_plugin_library.a
|
||||
-- Up-to-date: /home/shaun/Qt/6.6.0/gcc_64/../../Tools/QtCreator/lib/Qt/plugins/designer/libqtk_collection.so
|
||||
-- Up-to-date: /home/shaun/Qt/6.5.0/gcc_64/../../Tools/QtCreator/lib/Qt/lib/libqtk_library.a
|
||||
-- Up-to-date: /home/shaun/Qt/6.5.0/gcc_64/../../Tools/QtCreator/lib/Qt/lib/libqtk_plugin_library.a
|
||||
-- Up-to-date: /home/shaun/Qt/6.5.0/gcc_64/../../Tools/QtCreator/lib/Qt/plugins/designer/libqtk_collection.so
|
||||
```
|
||||
|
||||
To uninstall after a previous installation, we can run the following command
|
||||
|
||||
@@ -13,8 +13,8 @@ using namespace Qtk;
|
||||
|
||||
ExampleScene::ExampleScene(Qtk::Scene * scene) : Qtk::SceneInterface(scene) {
|
||||
setSceneName("Example Scene");
|
||||
getCamera().setTranslation({-8.0f, 0.0f, 10.0f});
|
||||
getCamera().setRotation(0.0f, 1.0f, 0.0f, -5.0f);
|
||||
getCamera().getTransform().setTranslation(-8.0f, 0.0f, 10.0f);
|
||||
getCamera().getTransform().setRotation(-5.0f, 0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
ExampleScene::~ExampleScene() {}
|
||||
@@ -23,9 +23,9 @@ void ExampleScene::init() {
|
||||
auto skybox = new Qtk::Skybox("Skybox");
|
||||
setSkybox(skybox);
|
||||
|
||||
std::string spartanPath = QTK_EXAMPLE_SOURCE_DIR;
|
||||
spartanPath += "/resources/models/spartan/spartan.obj";
|
||||
auto spartan = new Model("spartan", spartanPath.c_str());
|
||||
auto spartan = new Model(
|
||||
"spartan", std::string(QTK_EXAMPLE_SOURCE_DIR)
|
||||
+ "/../resources/models/spartan/spartan.obj");
|
||||
addObject(spartan);
|
||||
spartan->getTransform().setTranslation(-4.0f, 0.0f, 0.0f);
|
||||
|
||||
@@ -64,10 +64,10 @@ void ExampleScene::update() {
|
||||
// Pitch forward and roll sideways
|
||||
MeshRenderer::getInstance("leftTriangle")
|
||||
->getTransform()
|
||||
.rotate(1.0f, 0.0f, 0.0f, 0.75f);
|
||||
.rotate(0.75f, 1.0f, 0.0f, 0.0f);
|
||||
MeshRenderer::getInstance("rightTriangle")
|
||||
->getTransform()
|
||||
.rotate(0.0f, 0.0f, 1.0f, 0.75f);
|
||||
.rotate(0.75f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
static float translateX = 0.025f;
|
||||
float limit = -9.0f; // Origin position.x - 2.0f
|
||||
@@ -86,12 +86,12 @@ void ExampleScene::update() {
|
||||
.translate(-translateX, 0.0f, 0.0f);
|
||||
MeshRenderer::getInstance("topTriangle")
|
||||
->getTransform()
|
||||
.rotate(0.2f, 0.0f, 0.4f, 0.75f);
|
||||
.rotate(0.75f, 0.2f, 0.0f, 0.4f);
|
||||
MeshRenderer::getInstance("bottomTriangle")
|
||||
->getTransform()
|
||||
.rotate(0.0f, 0.2f, 0.4f, 0.75f);
|
||||
.rotate(0.75f, 0.0f, 0.2f, 0.4f);
|
||||
|
||||
MeshRenderer::getInstance("centerCube")
|
||||
->getTransform()
|
||||
.rotate(0.2f, 0.4f, 0.6f, 0.75f);
|
||||
.rotate(0.75f, 0.2f, 0.4f, 0.6f);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifndef QTK_RESOURCES_H_IN_H
|
||||
#define QTK_RESOURCES_H_IN_H
|
||||
|
||||
#define QTK_EXAMPLE_SOURCE_DIR "@CMAKE_SOURCE_DIR@"
|
||||
#define QTK_EXAMPLE_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@"
|
||||
|
||||
#endif // QTK_RESOURCES_H_IN_H
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.8 MiB |
@@ -1,6 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/textures">
|
||||
<file alias="plaster.png">images/plaster.png</file>
|
||||
<file alias="crate.png">images/crate.png</file>
|
||||
<file alias="stone.png">images/stone.png</file>
|
||||
<file alias="wood.png">images/wood.png</file>
|
||||
|
||||
@@ -47,13 +47,13 @@ target_link_libraries(qtk_plugins PUBLIC qtk_plugin_library)
|
||||
################################################################################
|
||||
# Final Qtk Application
|
||||
################################################################################
|
||||
# Source files for the main window and core application
|
||||
|
||||
set(
|
||||
QTK_GUI_SOURCES
|
||||
qtkscene.cpp qtkscene.h
|
||||
# logger.cpp logger.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_executable(qtk_gui ${QTK_GUI_SOURCES})
|
||||
target_link_libraries(qtk_gui PRIVATE qtk_plugin_library)
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ DebugConsole::DebugConsole(
|
||||
|
||||
auto qtkWidget = dynamic_cast<QtkWidget *>(owner);
|
||||
if(qtkWidget) {
|
||||
connect(
|
||||
qtkWidget->getLogger(), &Logger::sendLog, this, &DebugConsole::sendLog);
|
||||
connect(qtkWidget, &QtkWidget::sendLog, this, &DebugConsole::sendLog);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,8 +61,7 @@ namespace Qtk {
|
||||
* @param context The DebugContext to use for the message.
|
||||
* Default value is Status.
|
||||
*/
|
||||
inline void sendLog(QString message, Qtk::DebugContext context = Status) {
|
||||
// qDebug() << "[LOGGER]: " << qPrintable(message) << "; LOGGER";
|
||||
inline void sendLog(QString message, DebugContext context = Status) {
|
||||
mConsole->setTextColor(logColor(context));
|
||||
mConsole->append(logPrefix(message, context));
|
||||
}
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: Logger for Qtk ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
##############################################################################*/
|
||||
|
||||
#include "logger.h"
|
||||
#include "qtkwidget.h"
|
||||
|
||||
using namespace Qtk;
|
||||
|
||||
Logger::Logger(Qtk::QtkWidget * parent) : QObject(parent) {
|
||||
// connect(
|
||||
// this, SIGNAL(sendLog(QString, Qtk::DebugContext)), this,
|
||||
// SLOT(log(QString, Qtk::DebugContext)));
|
||||
if(parent != Q_NULLPTR) {
|
||||
connect(
|
||||
parent, SIGNAL(sendLog(QString, Qtk::DebugContext)), this,
|
||||
SLOT(log(QString, Qtk::DebugContext)));
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<QString, DebugContext> Logger::log(const QOpenGLDebugMessage & msg) {
|
||||
QString error_msg;
|
||||
DebugContext context;
|
||||
|
||||
// Format based on severity
|
||||
switch(msg.severity()) {
|
||||
case QOpenGLDebugMessage::NotificationSeverity:
|
||||
error_msg += "--";
|
||||
context = Status;
|
||||
break;
|
||||
case QOpenGLDebugMessage::HighSeverity:
|
||||
error_msg += "!!";
|
||||
context = Fatal;
|
||||
break;
|
||||
case QOpenGLDebugMessage::MediumSeverity:
|
||||
error_msg += "!~";
|
||||
context = Error;
|
||||
break;
|
||||
case QOpenGLDebugMessage::LowSeverity:
|
||||
error_msg += "~~";
|
||||
context = Warn;
|
||||
break;
|
||||
case QOpenGLDebugMessage::InvalidSeverity:
|
||||
error_msg += "??";
|
||||
context = Invalid;
|
||||
break;
|
||||
case QOpenGLDebugMessage::AnySeverity:
|
||||
error_msg += "**";
|
||||
context = Any;
|
||||
break;
|
||||
}
|
||||
|
||||
error_msg += " (";
|
||||
|
||||
// Format based on source
|
||||
#define CASE(c) \
|
||||
case QOpenGLDebugMessage::c: \
|
||||
error_msg += #c; \
|
||||
break
|
||||
switch(msg.source()) {
|
||||
CASE(APISource);
|
||||
CASE(WindowSystemSource);
|
||||
CASE(ShaderCompilerSource);
|
||||
CASE(ThirdPartySource);
|
||||
CASE(ApplicationSource);
|
||||
CASE(OtherSource);
|
||||
CASE(InvalidSource);
|
||||
CASE(AnySource);
|
||||
}
|
||||
#undef CASE
|
||||
|
||||
error_msg += " : ";
|
||||
|
||||
// Format based on type
|
||||
#define CASE(c) \
|
||||
case QOpenGLDebugMessage::c: \
|
||||
error_msg += #c; \
|
||||
break
|
||||
switch(msg.type()) {
|
||||
CASE(InvalidType);
|
||||
CASE(ErrorType);
|
||||
CASE(DeprecatedBehaviorType);
|
||||
CASE(UndefinedBehaviorType);
|
||||
CASE(PortabilityType);
|
||||
CASE(PerformanceType);
|
||||
CASE(OtherType);
|
||||
CASE(MarkerType);
|
||||
CASE(GroupPushType);
|
||||
CASE(GroupPopType);
|
||||
CASE(AnyType);
|
||||
}
|
||||
#undef CASE
|
||||
|
||||
error_msg += ")\n" + msg.message();
|
||||
log(error_msg, context);
|
||||
return {error_msg, context};
|
||||
}
|
||||
|
||||
void Logger::log(const QString & message, DebugContext context) {
|
||||
const QString log_msg = "[LOGGER]: " + message + "; LOGGER";
|
||||
qDebug() << qPrintable(log_msg);
|
||||
emit sendLog(log_msg, context);
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
||||
## About: Logger for Qtk ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
##############################################################################*/
|
||||
|
||||
#ifndef QTK_LOGGER_H
|
||||
#define QTK_LOGGER_H
|
||||
|
||||
#include <QOpenGLDebugMessage>
|
||||
#include <QString>
|
||||
#include "qtk/qtkapi.h"
|
||||
namespace Qtk {
|
||||
class QtkWidget;
|
||||
|
||||
class Logger : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Logger(Qtk::QtkWidget * parent = nullptr);
|
||||
|
||||
public slots:
|
||||
std::pair<QString, DebugContext> log(
|
||||
const QOpenGLDebugMessage & msg);
|
||||
|
||||
void log(
|
||||
const QString & message,
|
||||
Qtk::DebugContext context = Qtk::DebugContext::Status);
|
||||
|
||||
signals:
|
||||
void sendLog(const QString & message, Qtk::DebugContext context);
|
||||
};
|
||||
} // namespace Qtk
|
||||
|
||||
#endif // QTK_LOGGER_H
|
||||
@@ -41,11 +41,6 @@ MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent) {
|
||||
&Qtk::ToolBox::updateFocus);
|
||||
}
|
||||
|
||||
// TODO: Fix / use MainWindow in Qt Designer to add these dock widgets.
|
||||
// For now we will add them manually, but we should be able to do this in the
|
||||
// designer. At the moment if you edit the UI in designer the dock widget
|
||||
// areas below will override the designer settings.
|
||||
|
||||
// Dock the toolbox widget to the main window.
|
||||
addDockWidget(Qt::LeftDockWidgetArea, ui_->qtk__ToolBox);
|
||||
// Add an option to toggle active widgets in the GUI's toolbar 'view' menu.
|
||||
@@ -87,7 +82,7 @@ Qtk::QtkWidget * MainWindow::getQtkWidget(const QString & name) {
|
||||
return views_[name];
|
||||
}
|
||||
|
||||
void MainWindow::refreshScene(const QString & sceneName) {
|
||||
// TODO: Select TreeView using sceneName
|
||||
void MainWindow::refreshScene(QString sceneName) {
|
||||
// TODO: Select TreeView using sceneName>
|
||||
ui_->qtk__TreeView->updateView(getQtkWidget()->getScene());
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class MainWindow : public QMainWindow {
|
||||
* Trigger a refresh for widgets related to a scene that has been updated.
|
||||
* @param sceneName The name of the scene that has been modified.
|
||||
*/
|
||||
void refreshScene(const QString & sceneName);
|
||||
void refreshScene(QString sceneName);
|
||||
|
||||
private:
|
||||
/***************************************************************************
|
||||
|
||||
@@ -37,10 +37,10 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Object details and configuration panel.</string>
|
||||
<string>A custom widget tool tip.</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string>When an object is double-clicked in the TreeView for a scene, this panel will display relevant details and options.</string>
|
||||
<string>Custom widget what's this?</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -66,10 +66,10 @@
|
||||
<item>
|
||||
<widget class="Qtk::QtkWidget" name="qtk::QtkWidget">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
<string>A custom widget tool tip.</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string>Qtk scene view rendered using OpenGL.</string>
|
||||
<string>Custom widget what's this?</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -91,10 +91,10 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>TreeView of objects within the current scene.</string>
|
||||
<string>A custom widget tool tip.</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string>TreeView of objects within the current scene. Double-click to select an object and snap to it's position.</string>
|
||||
<string>Custom widget what's this?</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -16,9 +16,8 @@ using namespace Qtk;
|
||||
|
||||
QtkScene::QtkScene(Qtk::Scene * scene) : Qtk::SceneInterface(scene) {
|
||||
setSceneName("Qtk Scene");
|
||||
getCamera().setTranslation({0.0f, 0.0f, 20.0f});
|
||||
getCamera().setRotation(
|
||||
QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, -5.0f));
|
||||
getCamera().getTransform().setTranslation(0.0f, 0.0f, 20.0f);
|
||||
getCamera().getTransform().setRotation(-5.0f, 0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
QtkScene::~QtkScene() {
|
||||
@@ -90,7 +89,7 @@ void QtkScene::init() {
|
||||
model->getTransform().setTranslation(2.0f, 2.0f, -10.0f);
|
||||
// Sometimes the models are very large
|
||||
model->getTransform().scale(0.0025f);
|
||||
model->getTransform().rotate(0.0f, 1.0f, 0.0f, -110.0f);
|
||||
model->getTransform().rotate(-110.0f, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
model = addObject(
|
||||
new Qtk::Model("alien", ":/models/models/alien-hominid/alien.obj"));
|
||||
@@ -100,8 +99,8 @@ void QtkScene::init() {
|
||||
model = addObject(
|
||||
new Qtk::Model("My scythe", ":/models/models/scythe/scythe.obj"));
|
||||
model->getTransform().setTranslation(-6.0f, 0.0f, -10.0f);
|
||||
model->getTransform().rotate(1.0f, 0.0f, 0.0f, -90.0f);
|
||||
model->getTransform().rotate(0.0f, 1.0f, 0.0f, 90.0f);
|
||||
model->getTransform().rotate(-90.0f, 1.0f, 0.0f, 0.0f);
|
||||
model->getTransform().rotate(90.0f, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
model = addObject(
|
||||
new Qtk::Model("masterChief", ":/models/models/spartan/spartan.obj"));
|
||||
@@ -332,14 +331,14 @@ void QtkScene::init() {
|
||||
mesh->reallocateNormals(mesh->getNormals());
|
||||
mesh->reallocateTexCoords(mesh->getTexCoords(), 3);
|
||||
mesh->releaseShaders();
|
||||
mesh->getTransform().rotate(0.0f, 1.0f, 0.0f, 45.0f);
|
||||
mesh->getTransform().rotate(45.0f, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
// Texturing a cube using a cube map
|
||||
// + Cube map texturing works with both QTK_DRAW_ARRAYS and QTK_DRAW_ELEMENTS
|
||||
mesh =
|
||||
addObject(new Qtk::MeshRenderer("testCubeMap", Cube(QTK_DRAW_ELEMENTS)));
|
||||
mesh->getTransform().setTranslation(-3.0f, 1.0f, -2.0f);
|
||||
mesh->getTransform().setRotation(0.0f, 1.0f, 0.0f, 45.0f);
|
||||
mesh->getTransform().setRotation(45.0f, 0.0f, 1.0f, 0.0f);
|
||||
mesh->setShaders(
|
||||
":/shaders/texture-cubemap.vert", ":/shaders/texture-cubemap.frag");
|
||||
mesh->setCubeMap(":/textures/crate.png");
|
||||
@@ -440,10 +439,10 @@ void QtkScene::draw() {
|
||||
|
||||
void QtkScene::update() {
|
||||
auto mySpartan = Model::getInstance("My spartan");
|
||||
mySpartan->getTransform().rotate(0.0f, 1.0f, 0.0f, 0.75f);
|
||||
mySpartan->getTransform().rotate(0.75f, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
auto myCube = MeshRenderer::getInstance("My cube");
|
||||
myCube->getTransform().rotate(-0.0f, 1.0f, 0.0f, 0.75f);
|
||||
myCube->getTransform().rotate(-0.75f, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
auto position = MeshRenderer::getInstance("alienTestLight")
|
||||
->getTransform()
|
||||
@@ -457,7 +456,7 @@ void QtkScene::update() {
|
||||
alien->setUniform("uMVP.model", posMatrix);
|
||||
alien->setUniform("uMVP.view", QtkScene::getCamera().toMatrix());
|
||||
alien->setUniform("uMVP.projection", QtkScene::getProjectionMatrix());
|
||||
alien->getTransform().rotate(0.0f, 1.0f, 0.0f, 0.75f);
|
||||
alien->getTransform().rotate(0.75f, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
position = MeshRenderer::getInstance("spartanTestLight")
|
||||
->getTransform()
|
||||
@@ -471,10 +470,10 @@ void QtkScene::update() {
|
||||
spartan->setUniform("uMVP.model", posMatrix);
|
||||
spartan->setUniform("uMVP.view", QtkScene::getCamera().toMatrix());
|
||||
spartan->setUniform("uMVP.projection", QtkScene::getProjectionMatrix());
|
||||
spartan->getTransform().rotate(0.0f, 1.0f, 0.0f, 0.75f);
|
||||
spartan->getTransform().rotate(0.75f, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
auto phong = MeshRenderer::getInstance("testPhong");
|
||||
phong->getTransform().rotate(1.0f, 0.5f, 0.0f, 0.75f);
|
||||
phong->getTransform().rotate(0.75f, 1.0f, 0.5f, 0.0f);
|
||||
phong->bindShaders();
|
||||
position =
|
||||
MeshRenderer::getInstance("testLight")->getTransform().getTranslation();
|
||||
@@ -489,27 +488,27 @@ void QtkScene::update() {
|
||||
phong->releaseShaders();
|
||||
|
||||
// Rotate lighting example cubes
|
||||
mTestPhong->getTransform().rotate(0.5f, 0.3f, 0.2f, 0.75f);
|
||||
mTestPhong->getTransform().rotate(0.75f, 0.5f, 0.3f, 0.2f);
|
||||
MeshRenderer::getInstance("noLight")->getTransform().rotate(
|
||||
0.5f, 0.3f, 0.2f, 0.75f);
|
||||
mTestAmbient->getTransform().rotate(0.5f, 0.3f, 0.2f, 0.75f);
|
||||
mTestDiffuse->getTransform().rotate(0.5f, 0.3f, 0.2f, 0.75f);
|
||||
mTestSpecular->getTransform().rotate(0.5f, 0.3f, 0.2f, 0.75f);
|
||||
0.75f, 0.5f, 0.3f, 0.2f);
|
||||
mTestAmbient->getTransform().rotate(0.75f, 0.5f, 0.3f, 0.2f);
|
||||
mTestDiffuse->getTransform().rotate(0.75f, 0.5f, 0.3f, 0.2f);
|
||||
mTestSpecular->getTransform().rotate(0.75f, 0.5f, 0.3f, 0.2f);
|
||||
|
||||
// Examples of various translations and rotations
|
||||
|
||||
// Rotate in multiple directions simultaneously
|
||||
MeshRenderer::getInstance("rgbNormalsCube")
|
||||
->getTransform()
|
||||
.rotate(0.2f, 0.4f, 0.6f, 0.75f);
|
||||
.rotate(0.75f, 0.2f, 0.4f, 0.6f);
|
||||
|
||||
// Pitch forward and roll sideways
|
||||
MeshRenderer::getInstance("leftTriangle")
|
||||
->getTransform()
|
||||
.rotate(1.0f, 0.0f, 0.0f, 0.75f);
|
||||
.rotate(0.75f, 1.0f, 0.0f, 0.0f);
|
||||
MeshRenderer::getInstance("rightTriangle")
|
||||
->getTransform()
|
||||
.rotate(0.0f, 0.0f, 1.0f, 0.75f);
|
||||
.rotate(0.75f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
// Move between two positions over time
|
||||
static float translateX = 0.025f;
|
||||
@@ -530,15 +529,15 @@ void QtkScene::update() {
|
||||
// And lets rotate the triangles in two directions at once
|
||||
MeshRenderer::getInstance("topTriangle")
|
||||
->getTransform()
|
||||
.rotate(0.2f, 0.0f, 0.4f, 0.75f);
|
||||
.rotate(0.75f, 0.2f, 0.0f, 0.4f);
|
||||
MeshRenderer::getInstance("bottomTriangle")
|
||||
->getTransform()
|
||||
.rotate(0.0f, 0.2f, 0.4f, 0.75f);
|
||||
.rotate(0.75f, 0.0f, 0.2f, 0.4f);
|
||||
// And make the bottom triangle green, instead of RGB
|
||||
|
||||
// Rotate center cube in several directions simultaneously
|
||||
// + Not subject to gimbal lock since we are using quaternions :)
|
||||
MeshRenderer::getInstance("centerCube")
|
||||
->getTransform()
|
||||
.rotate(0.2f, 0.4f, 0.6f, 0.75f);
|
||||
.rotate(0.75f, 0.2f, 0.4f, 0.6f);
|
||||
}
|
||||
|
||||
@@ -10,12 +10,16 @@
|
||||
#include <QMimeData>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <qtk/input.h>
|
||||
#include <qtk/scene.h>
|
||||
#include <qtk/shape.h>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <qtk/input.h>
|
||||
#include <qtk/scene.h>
|
||||
#include <qtk/shape.h>
|
||||
|
||||
#include "debugconsole.h"
|
||||
#include "qtk/qtkmessagelogger.h"
|
||||
#include "qtkmainwindow.h"
|
||||
#include "qtkwidget.h"
|
||||
|
||||
@@ -31,9 +35,8 @@ QtkWidget::QtkWidget(QWidget * parent, const QString & name) :
|
||||
QtkWidget(parent, name, Q_NULLPTR) {}
|
||||
|
||||
QtkWidget::QtkWidget(QWidget * parent, const QString & name, Scene * scene) :
|
||||
QOpenGLWidget(parent), mDebugLogger(new QOpenGLDebugLogger(this)),
|
||||
mConsole(new DebugConsole(this, name)), mScene(Q_NULLPTR),
|
||||
mLogger(new Qtk::Logger(this)) {
|
||||
QOpenGLWidget(parent), mDebugLogger(Q_NULLPTR),
|
||||
mConsole(new DebugConsole(this, name)), mScene(Q_NULLPTR) {
|
||||
setAcceptDrops(true);
|
||||
setScene(scene);
|
||||
setObjectName(name);
|
||||
@@ -74,22 +77,17 @@ void QtkWidget::initializeGL() {
|
||||
// Connect the frameSwapped signal to call the update() function
|
||||
connect(this, SIGNAL(frameSwapped()), this, SLOT(update()));
|
||||
|
||||
toggleConsole();
|
||||
// Initialize OpenGL debug context
|
||||
mDebugLogger = new QOpenGLDebugLogger(this);
|
||||
if(mDebugLogger->initialize()) {
|
||||
qDebug() << "GL_DEBUG Debug Logger" << mDebugLogger << "\n";
|
||||
connect(
|
||||
mDebugLogger, SIGNAL(messageLogged(QOpenGLDebugMessage)), mLogger,
|
||||
SLOT(log(QOpenGLDebugMessage)));
|
||||
// connect(
|
||||
// Qtk::QtkMessageLogger::get(),
|
||||
// &Qtk::QtkMessageLogger::messageLogged, mLogger,
|
||||
// &Qtk::Logger::parseError);
|
||||
mDebugLogger, SIGNAL(messageLogged(QOpenGLDebugMessage)), this,
|
||||
SLOT(messageLogged(QOpenGLDebugMessage)));
|
||||
// connect(
|
||||
// mDebugLogger, SIGNAL(messageLogged(QOpenGLDebugMessage)),
|
||||
// mConsole, SLOT(sendLog(QOpenGLDebugMessage)));
|
||||
mDebugLogger->startLogging();
|
||||
QString msg;
|
||||
QTextStream stream(&msg);
|
||||
stream << "Logging started on GL_DEBUG Debug Logger: " << mDebugLogger;
|
||||
mDebugLogger->logMessage(QOpenGLDebugMessage::createApplicationMessage(
|
||||
stream.string()->toStdString().c_str()));
|
||||
}
|
||||
|
||||
printContextInformation();
|
||||
@@ -159,8 +157,8 @@ void QtkWidget::dragEnterEvent(QDragEnterEvent * event) {
|
||||
|
||||
void QtkWidget::dropEvent(QDropEvent * event) {
|
||||
mConsole->sendLog(event->mimeData()->text());
|
||||
auto urls = event->mimeData()->urls();
|
||||
if(!urls.isEmpty()) {
|
||||
if(event->mimeData()->hasUrls()) {
|
||||
auto urls = event->mimeData()->urls();
|
||||
if(urls.size() > 1) {
|
||||
qDebug() << "Cannot accept drop of multiple files.";
|
||||
event->ignore();
|
||||
@@ -173,7 +171,7 @@ void QtkWidget::dropEvent(QDropEvent * event) {
|
||||
mScene->loadModel(url);
|
||||
event->acceptProposedAction();
|
||||
} else {
|
||||
qDebug() << "Unsupported file type: " + url.fileName() + "\n";
|
||||
qDebug() << "Unsupported file type.";
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
@@ -214,6 +212,74 @@ void QtkWidget::update() {
|
||||
QWidget::update();
|
||||
}
|
||||
|
||||
void QtkWidget::messageLogged(const QOpenGLDebugMessage & msg) {
|
||||
QString error;
|
||||
|
||||
DebugContext context;
|
||||
// Format based on severity
|
||||
switch(msg.severity()) {
|
||||
case QOpenGLDebugMessage::NotificationSeverity:
|
||||
error += "--";
|
||||
context = Status;
|
||||
break;
|
||||
case QOpenGLDebugMessage::HighSeverity:
|
||||
error += "!!";
|
||||
context = Fatal;
|
||||
break;
|
||||
case QOpenGLDebugMessage::MediumSeverity:
|
||||
error += "!~";
|
||||
context = Error;
|
||||
break;
|
||||
case QOpenGLDebugMessage::LowSeverity:
|
||||
error += "~~";
|
||||
context = Warn;
|
||||
break;
|
||||
}
|
||||
|
||||
error += " (";
|
||||
|
||||
// Format based on source
|
||||
#define CASE(c) \
|
||||
case QOpenGLDebugMessage::c: \
|
||||
error += #c; \
|
||||
break
|
||||
switch(msg.source()) {
|
||||
CASE(APISource);
|
||||
CASE(WindowSystemSource);
|
||||
CASE(ShaderCompilerSource);
|
||||
CASE(ThirdPartySource);
|
||||
CASE(ApplicationSource);
|
||||
CASE(OtherSource);
|
||||
CASE(InvalidSource);
|
||||
}
|
||||
#undef CASE
|
||||
|
||||
error += " : ";
|
||||
|
||||
// Format based on type
|
||||
#define CASE(c) \
|
||||
case QOpenGLDebugMessage::c: \
|
||||
error += #c; \
|
||||
break
|
||||
switch(msg.type()) {
|
||||
CASE(InvalidType);
|
||||
CASE(ErrorType);
|
||||
CASE(DeprecatedBehaviorType);
|
||||
CASE(UndefinedBehaviorType);
|
||||
CASE(PortabilityType);
|
||||
CASE(PerformanceType);
|
||||
CASE(OtherType);
|
||||
CASE(MarkerType);
|
||||
CASE(GroupPushType);
|
||||
CASE(GroupPopType);
|
||||
}
|
||||
#undef CASE
|
||||
|
||||
error += ")\n" + msg.message() + "\n";
|
||||
qDebug() << qPrintable(error);
|
||||
sendLog("(OpenGL) " + error.replace("\n", "\n(OpenGL) "), context);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Private Methods
|
||||
******************************************************************************/
|
||||
@@ -230,10 +296,10 @@ void QtkWidget::updateCameraInput() {
|
||||
static const float rotSpeed = 0.5f;
|
||||
|
||||
// Handle rotations
|
||||
Scene::getCamera().rotate(QQuaternion::fromAxisAndAngle(
|
||||
Camera3D::LocalUp, -rotSpeed * Input::mouseDelta().x()));
|
||||
Scene::getCamera().rotate(QQuaternion::fromAxisAndAngle(
|
||||
Scene::getCamera().getRight(), -rotSpeed * Input::mouseDelta().y()));
|
||||
Scene::getCamera().getTransform().rotate(
|
||||
-rotSpeed * Input::mouseDelta().x(), Camera3D::LocalUp);
|
||||
Scene::getCamera().getTransform().rotate(
|
||||
-rotSpeed * Input::mouseDelta().y(), Scene::getCamera().getRight());
|
||||
|
||||
// Handle translations
|
||||
QVector3D translation;
|
||||
@@ -255,7 +321,7 @@ void QtkWidget::updateCameraInput() {
|
||||
if(Input::keyPressed(Qt::Key_E)) {
|
||||
translation += Scene::getCamera().getUp() / 2.0f;
|
||||
}
|
||||
Scene::getCamera().translate(transSpeed * translation);
|
||||
Scene::getCamera().getTransform().translate(transSpeed * translation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,5 +354,6 @@ void QtkWidget::printContextInformation() {
|
||||
auto message = QString(glType) + glVersion + "(" + glProfile + ")"
|
||||
+ "\nOpenGL Vendor: " + glVendor
|
||||
+ "\nRendering Device: " + glRenderer;
|
||||
emit sendLog("(OpenGL) " + message.replace("\n", "\n(OpenGL) "), Status);
|
||||
qDebug() << qPrintable(message);
|
||||
sendLog("(OpenGL) " + message.replace("\n", "\n(OpenGL) "), Status);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#include <qtk/qtkapi.h>
|
||||
#include <qtk/scene.h>
|
||||
#include "logger.h"
|
||||
|
||||
namespace Qtk {
|
||||
class DebugConsole;
|
||||
@@ -108,8 +107,6 @@ namespace Qtk {
|
||||
return mDebugLogger;
|
||||
}
|
||||
|
||||
inline Logger * getLogger() { return mLogger; }
|
||||
|
||||
/*************************************************************************
|
||||
* Setters
|
||||
************************************************************************/
|
||||
@@ -132,7 +129,7 @@ namespace Qtk {
|
||||
* @param message The message to log.
|
||||
* @param context The context of the log message.
|
||||
*/
|
||||
void sendLog(const QString & message, Qtk::DebugContext context = Status);
|
||||
void sendLog(const QString & message, DebugContext context = Status);
|
||||
|
||||
// TODO: Use this signal in treeview and toolbox to update object
|
||||
// properties
|
||||
@@ -181,7 +178,7 @@ namespace Qtk {
|
||||
*
|
||||
* @param msg The message logged.
|
||||
*/
|
||||
// void messageLogged(const QOpenGLDebugMessage & msg);
|
||||
void messageLogged(const QOpenGLDebugMessage & msg);
|
||||
|
||||
private:
|
||||
/*************************************************************************
|
||||
@@ -207,7 +204,6 @@ namespace Qtk {
|
||||
* Private Members
|
||||
************************************************************************/
|
||||
|
||||
Qtk::Logger * mLogger;
|
||||
QOpenGLDebugLogger * mDebugLogger;
|
||||
Qtk::Scene * mScene;
|
||||
Qtk::DebugConsole * mConsole;
|
||||
|
||||
@@ -22,6 +22,7 @@ ToolBox::ToolBox(QWidget * parent) : QDockWidget(parent), ui(new Ui::ToolBox) {
|
||||
}
|
||||
|
||||
void ToolBox::updateFocus(const QString & name) {
|
||||
qDebug() << "Called updateFocus on Toolbox.";
|
||||
auto object =
|
||||
MainWindow::getMainWindow()->getQtkWidget()->getScene()->getObject(name);
|
||||
if(object != Q_NULLPTR) {
|
||||
|
||||
@@ -46,6 +46,7 @@ void Qtk::TreeView::updateView(const Qtk::Scene * scene) {
|
||||
void Qtk::TreeView::itemFocus(QTreeWidgetItem * item, int column) {
|
||||
QString name = item->text(column);
|
||||
auto scene = MainWindow::getMainWindow()->getQtkWidget()->getScene();
|
||||
auto & transform = scene->getCamera().getTransform();
|
||||
auto object = scene->getObject(name);
|
||||
Transform3D * objectTransform;
|
||||
// If the object is a mesh or model, focus the camera on it.
|
||||
@@ -58,11 +59,13 @@ void Qtk::TreeView::itemFocus(QTreeWidgetItem * item, int column) {
|
||||
objectTransform = &dynamic_cast<Model *>(object)->getTransform();
|
||||
}
|
||||
auto focusScale = objectTransform->getScale();
|
||||
float width = focusScale.x() / 2.0f;
|
||||
float height = focusScale.y() / 2.0f;
|
||||
QVector3D pos = objectTransform->getTranslation();
|
||||
// pos.setX(pos.x() + width);
|
||||
pos.setY(pos.y() + height);
|
||||
Qtk::Scene::getCamera().setTranslation(pos);
|
||||
Qtk::Scene::getCamera().translate({0.0f, 0.0f, 3.0f});
|
||||
transform.setTranslation(pos);
|
||||
transform.translate(0.0f, 0.0f, 3.0f);
|
||||
|
||||
// Emit signal from qtk widget for new object focus. Triggers GUI updates.
|
||||
emit MainWindow::getMainWindow()->getQtkWidget()->objectFocusChanged(name);
|
||||
|
||||
@@ -24,8 +24,6 @@ set(
|
||||
skybox.h
|
||||
texture.h
|
||||
transform3D.h
|
||||
qtkmessagelogger.h
|
||||
../app/logger.h
|
||||
)
|
||||
|
||||
set(
|
||||
@@ -43,8 +41,6 @@ set(
|
||||
skybox.cpp
|
||||
texture.cpp
|
||||
transform3D.cpp
|
||||
qtkmessagelogger.cpp
|
||||
../app/logger.cpp
|
||||
)
|
||||
|
||||
qt6_add_big_resources(QTK_LIBRARY_SOURCES "${QTK_RESOURCES}/resources.qrc")
|
||||
@@ -72,9 +68,9 @@ target_link_libraries(
|
||||
Qt6::Core Qt6::OpenGLWidgets Qt6::Widgets
|
||||
)
|
||||
|
||||
if(QTK_SUBMODULES OR NOT QTK_ASSIMP_NEW_INTERFACE)
|
||||
if(QTK_SUBMODULES OR NOT ASSIMP_NEW_INTERFACE)
|
||||
target_link_libraries(qtk_library PUBLIC assimp)
|
||||
elseif(QTK_ASSIMP_NEW_INTERFACE)
|
||||
elseif(ASSIMP_NEW_INTERFACE)
|
||||
target_link_libraries(qtk_library PUBLIC assimp::assimp)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -29,3 +29,28 @@ const QMatrix4x4 & Camera3D::toMatrix() {
|
||||
mWorld.translate(-mTransform.getTranslation());
|
||||
return mWorld;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Qt Streams
|
||||
******************************************************************************/
|
||||
|
||||
QDataStream & operator<<(QDataStream & out, Camera3D & transform) {
|
||||
out << transform.getTransform();
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream & operator>>(QDataStream & in, Camera3D & transform) {
|
||||
in >> transform.getTransform();
|
||||
return in;
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Camera3D & transform) {
|
||||
dbg << "Camera3D\n{\n";
|
||||
dbg << "Position: <" << transform.getTranslation().x() << ", "
|
||||
<< transform.getTranslation().y() << ", "
|
||||
<< transform.getTranslation().z() << ">\n";
|
||||
dbg << "Rotation: <" << transform.getRotation().x() << ", "
|
||||
<< transform.getRotation().y() << ", " << transform.getRotation().z()
|
||||
<< " | " << transform.getRotation().scalar() << ">\n}";
|
||||
return dbg;
|
||||
}
|
||||
|
||||
@@ -32,9 +32,7 @@ namespace Qtk {
|
||||
/**
|
||||
* @return Transform3D associated with this camera.
|
||||
*/
|
||||
[[nodiscard]] inline const Transform3D & getTransform() const {
|
||||
return mTransform;
|
||||
}
|
||||
inline Transform3D & getTransform() { return mTransform; }
|
||||
|
||||
/**
|
||||
* @return Current translation of the camera as a QVector3D.
|
||||
@@ -80,85 +78,33 @@ namespace Qtk {
|
||||
*/
|
||||
const QMatrix4x4 & toMatrix();
|
||||
|
||||
/**
|
||||
* Set the translation for this camera.
|
||||
* TODO: Replace these methods by inheriting from a base class.
|
||||
*
|
||||
* @param translation QVector3D for the new translation.
|
||||
*/
|
||||
inline void setTranslation(const QVector3D & translation) {
|
||||
mTransform.setTranslation(translation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rotation for this camera.
|
||||
*
|
||||
* @param rotation QQuaternion for the new rotation.
|
||||
*/
|
||||
inline void setRotation(const QQuaternion & rotation) {
|
||||
mTransform.setRotation(rotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a rotation upon an axis represented by the 3D vector (x, y, z)
|
||||
*
|
||||
* @param ax X axis to set angle for.
|
||||
* @param ay Y axis to set angle for.
|
||||
* @param az Z axis to set angle for.
|
||||
* @param angle Angle to set rotation.
|
||||
*/
|
||||
inline void setRotation(float ax, float ay, float az, float angle) {
|
||||
mTransform.setRotation(ax, ay, az, angle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate the camera by the given position.
|
||||
*
|
||||
* @param position QVector3D for the position to translate by.
|
||||
*/
|
||||
inline void translate(const QVector3D & position) {
|
||||
mTransform.translate(position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate the camera by the given rotation.
|
||||
*
|
||||
* @param rotation QQaternion for the rotation to apply.
|
||||
*/
|
||||
inline void rotate(const QQuaternion & rotation) {
|
||||
mTransform.rotate(rotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a rotation upon an axis represented by the 3D vector (x, y, z)
|
||||
*
|
||||
* @param ax X axis to set angle for.
|
||||
* @param ay Y axis to set angle for.
|
||||
* @param az Z axis to set angle for.
|
||||
* @param angle Angle to set rotation.
|
||||
*/
|
||||
inline void rotate(float ax, float ay, float az, float angle) {
|
||||
mTransform.rotate(ax, ay, az, angle);
|
||||
}
|
||||
|
||||
private:
|
||||
/*************************************************************************
|
||||
* Private Methods
|
||||
************************************************************************/
|
||||
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
friend QDataStream & operator<<(QDataStream & out, Camera3D & transform);
|
||||
friend QDataStream & operator>>(QDataStream & in, Camera3D & transform);
|
||||
#endif
|
||||
|
||||
/*************************************************************************
|
||||
* Private Members
|
||||
************************************************************************/
|
||||
|
||||
Transform3D mTransform;
|
||||
QMatrix4x4 mWorld;
|
||||
|
||||
/*************************************************************************
|
||||
* Qt Streams
|
||||
************************************************************************/
|
||||
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
friend QDataStream & operator<<(
|
||||
QDataStream & out, const Camera3D & camera);
|
||||
friend QDataStream & operator>>(QDataStream & in, Camera3D & camera);
|
||||
#endif
|
||||
};
|
||||
|
||||
// Qt Streams
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
QDataStream & operator<<(QDataStream & out, const Camera3D & transform);
|
||||
QDataStream & operator>>(QDataStream & in, Camera3D & transform);
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug dbg, const Camera3D & transform);
|
||||
#endif
|
||||
} // namespace Qtk
|
||||
|
||||
Q_DECLARE_TYPEINFO(Qtk::Camera3D, Q_MOVABLE_TYPE);
|
||||
|
||||
@@ -43,7 +43,7 @@ void Model::flipTexture(const std::string & fileName, bool flipX, bool flipY) {
|
||||
texture.mTexture->destroy();
|
||||
texture.mTexture->create();
|
||||
texture.mTexture->setData(
|
||||
OpenGLTextureFactory::initImage(fullPath.c_str(), flipX, flipY));
|
||||
*OpenGLTextureFactory::initImage(fullPath.c_str(), flipX, flipY));
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
@@ -238,7 +238,7 @@ ModelMesh::Textures Model::loadMaterialTextures(
|
||||
// Add the texture to the textures container
|
||||
textures.push_back(texture);
|
||||
// Add the texture to the loaded textures to avoid loading it twice
|
||||
mTexturesLoaded.push_back(textures.back());
|
||||
mTexturesLoaded.push_back(texture);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,10 +52,6 @@ void ModelMesh::draw(QOpenGLShaderProgram & shader) {
|
||||
shader.setUniformValue((name + number).c_str(), i);
|
||||
}
|
||||
|
||||
// Always reset active texture to GL_TEXTURE0 before we draw.
|
||||
// This is important for models with no textures.
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
// Draw the mesh
|
||||
glDrawElements(
|
||||
GL_TRIANGLES, mIndices.size(), GL_UNSIGNED_INT, mIndices.data());
|
||||
@@ -66,6 +62,7 @@ void ModelMesh::draw(QOpenGLShaderProgram & shader) {
|
||||
}
|
||||
shader.release();
|
||||
mVAO->release();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
|
||||
@@ -30,21 +30,6 @@ namespace Qtk {
|
||||
* Struct to store model textures. 3D Models may have multiple.
|
||||
*/
|
||||
struct QTKAPI ModelTexture {
|
||||
ModelTexture() = default;
|
||||
|
||||
/**
|
||||
* Construct a ModelTexture.
|
||||
*
|
||||
* @param id Texture ID for this texture.
|
||||
* @param type Type of texture in string format.
|
||||
* @param path Path to the texture on disk.
|
||||
*/
|
||||
ModelTexture(const std::string & type, const std::string & path) :
|
||||
mType(type), mPath(path) {
|
||||
mTexture = OpenGLTextureFactory::initTexture(path.c_str());
|
||||
mID = mTexture->textureId();
|
||||
}
|
||||
|
||||
/** Texture ID for for this texture. */
|
||||
GLuint mID {};
|
||||
QOpenGLTexture * mTexture {};
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
#define QTKAPI
|
||||
#endif
|
||||
|
||||
#include "qtk/qtkmessagelogger.h"
|
||||
|
||||
/**
|
||||
* Initialize Qt resources required by the Qtk library.
|
||||
* This cannot be defined within any namespace, but can be called by ctors.
|
||||
@@ -37,7 +35,7 @@ namespace Qtk {
|
||||
/**
|
||||
* Flag to set context for debug messages.
|
||||
*/
|
||||
enum DebugContext { Status, Debug, Warn, Error, Fatal, Invalid, Any };
|
||||
enum DebugContext { Status, Debug, Warn, Error, Fatal };
|
||||
|
||||
/**
|
||||
* Find top level parent for a widget.
|
||||
|
||||
@@ -17,23 +17,17 @@ using namespace Qtk;
|
||||
QtkIOStream::QtkIOStream(const char * pFile, const char * pMode) :
|
||||
mFile(pFile) {
|
||||
QString mode(pMode);
|
||||
bool open = false;
|
||||
if(mode == "w" || mode == "wb") {
|
||||
open = mFile.open(QIODeviceBase::WriteOnly);
|
||||
} else if(mode == "r" || mode == "rb") {
|
||||
open = mFile.open(QIODeviceBase::ReadOnly);
|
||||
} else if(mode == "wt") {
|
||||
open = mFile.open(QIODeviceBase::WriteOnly | QIODeviceBase::Text);
|
||||
} else if(mode == "rt") {
|
||||
open = mFile.open(QIODeviceBase::ReadOnly | QIODeviceBase::Text);
|
||||
bool read = mode.contains('r');
|
||||
bool write = mode.contains('w');
|
||||
if(read && write) {
|
||||
mFile.open(QIODevice::ReadWrite);
|
||||
} else if(read) {
|
||||
mFile.open(QIODevice::ReadOnly);
|
||||
} else if(write) {
|
||||
mFile.open(QIODevice::WriteOnly);
|
||||
} else {
|
||||
open = false;
|
||||
qDebug() << "[Qtk::QtkIOStream] Invalid file open mode: " << mode << "\n";
|
||||
}
|
||||
if(!open) {
|
||||
qDebug() << "[Qtk::QtkIOStream] Could not open file: " << QString(pFile)
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
@@ -41,24 +35,34 @@ QtkIOStream::QtkIOStream(const char * pFile, const char * pMode) :
|
||||
******************************************************************************/
|
||||
|
||||
size_t QtkIOStream::Read(void * pvBuffer, size_t pSize, size_t pCount) {
|
||||
qint64 readSize = mFile.read((char *)pvBuffer, pSize * pCount);
|
||||
if(readSize < 0) {
|
||||
qDebug() << "[Qtk::QtkIOStream] Failed to read (" << pSize
|
||||
<< ") bytes from file at: " << mFile.filesystemFileName().c_str()
|
||||
<< "\n";
|
||||
return -1;
|
||||
}
|
||||
return readSize;
|
||||
size_t read = 0;
|
||||
do {
|
||||
auto readSize = mFile.read((char *)pvBuffer + read, pSize);
|
||||
if(readSize < 0) {
|
||||
qDebug() << "[Qtk::QtkIOStream] Failed to read (" << pSize
|
||||
<< ") bytes from file at: " << mFile.filesystemFileName().c_str()
|
||||
<< "\n";
|
||||
return -1;
|
||||
}
|
||||
read += readSize;
|
||||
} while(pCount--);
|
||||
return read;
|
||||
}
|
||||
|
||||
size_t QtkIOStream::Write(const void * pvBuffer, size_t pSize, size_t pCount) {
|
||||
qint64 writeSize = mFile.write((char *)pvBuffer, pSize * pCount);
|
||||
if(writeSize < 0) {
|
||||
qDebug() << "[Qtk::QtkIOStream] Failed to write buffer with size (" << pSize
|
||||
<< ") to file at: " << mFile.filesystemFileName().c_str() << "\n";
|
||||
return -1;
|
||||
}
|
||||
return writeSize;
|
||||
size_t wrote = 0;
|
||||
do {
|
||||
auto writeSize = mFile.write((char *)pvBuffer + wrote, pSize);
|
||||
if(writeSize < 0) {
|
||||
qDebug() << "[Qtk::QtkIOStream] Failed to write buffer with size ("
|
||||
<< pSize
|
||||
<< ") to file at: " << mFile.filesystemFileName().c_str()
|
||||
<< "\n";
|
||||
return -1;
|
||||
}
|
||||
wrote += writeSize;
|
||||
} while(pCount--);
|
||||
return wrote;
|
||||
}
|
||||
|
||||
aiReturn QtkIOStream::Seek(size_t pOffset, aiOrigin pOrigin) {
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
##############################################################################*/
|
||||
|
||||
#include "qtkiosystem.h"
|
||||
#include <QDir>
|
||||
|
||||
using namespace Qtk;
|
||||
|
||||
@@ -20,11 +19,15 @@ bool QtkIOSystem::Exists(const char * pFile) const {
|
||||
}
|
||||
|
||||
char QtkIOSystem::getOsSeparator() const {
|
||||
return QDir::separator().toLatin1();
|
||||
#ifndef _WIN32
|
||||
return '/';
|
||||
#else
|
||||
return '\\';
|
||||
#endif
|
||||
}
|
||||
|
||||
Assimp::IOStream * QtkIOSystem::Open(const char * pFile, const char * pMode) {
|
||||
if(!Exists(pFile)) {
|
||||
if(!QFileInfo::exists(pFile)) {
|
||||
qDebug() << "[Qtk::QtkIOSystem] failed to open file: " << pFile << "\n";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
|
||||
#include "qtkmessagelogger.h"
|
||||
#include "camera3d.h"
|
||||
#include "transform3D.h"
|
||||
|
||||
|
||||
Qtk::QtkDebug Qtk::QtkDebug::operator<<(const Qtk::Transform3D & transform) {}
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug Qtk::operator<<(QDebug dbg, const Qtk::Transform3D & transform) {
|
||||
dbg << "Transform3D\n{\n";
|
||||
dbg << "Position: <" << transform.getTranslation().x() << ", "
|
||||
<< transform.getTranslation().y() << ", "
|
||||
<< transform.getTranslation().z() << ">\n";
|
||||
dbg << "Scale: <" << transform.getScale().x() << ", "
|
||||
<< transform.getScale().y() << ", " << transform.getScale().z() << ">\n";
|
||||
dbg << "Rotation: <" << transform.getRotation().x() << ", "
|
||||
<< transform.getRotation().y() << ", " << transform.getRotation().z()
|
||||
<< " | " << transform.getRotation().scalar() << ">\n}";
|
||||
return dbg;
|
||||
}
|
||||
|
||||
QDebug Qtk::operator<<(QDebug dbg, const Qtk::Camera3D & transform) {
|
||||
dbg << "Camera3D\n{\n";
|
||||
dbg << "Position: <" << transform.getTranslation().x() << ", "
|
||||
<< transform.getTranslation().y() << ", "
|
||||
<< transform.getTranslation().z() << ">\n";
|
||||
dbg << "Rotation: <" << transform.getRotation().x() << ", "
|
||||
<< transform.getRotation().y() << ", " << transform.getRotation().z()
|
||||
<< " | " << transform.getRotation().scalar() << ">\n}";
|
||||
return dbg;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
QDataStream & Qtk::operator<<(
|
||||
QDataStream & out, const Qtk::Transform3D & transform) {
|
||||
out << transform.mTranslation;
|
||||
out << transform.mScale;
|
||||
out << transform.mRotation;
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream & Qtk::operator>>(QDataStream & in, Qtk::Transform3D & transform) {
|
||||
in >> transform.mTranslation;
|
||||
in >> transform.mScale;
|
||||
in >> transform.mRotation;
|
||||
transform.m_dirty = true;
|
||||
return in;
|
||||
}
|
||||
|
||||
QDataStream & Qtk::operator<<(QDataStream & out, const Qtk::Camera3D & camera) {
|
||||
out << camera.getTransform();
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream & Qtk::operator>>(QDataStream & in, Qtk::Camera3D & camera) {
|
||||
in >> camera.mTransform;
|
||||
return in;
|
||||
}
|
||||
#endif
|
||||
@@ -1,96 +0,0 @@
|
||||
|
||||
#ifndef QTK_QTKMESSAGELOGGER_H
|
||||
#define QTK_QTKMESSAGELOGGER_H
|
||||
|
||||
#include "qtkapi.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMessageLogger>
|
||||
#include <Qt>
|
||||
|
||||
// #define qtkDebug Qtk::QtkMessageLogger::get().debug
|
||||
// #define qtkInfo Qtk::QtkMessageLogger::get().info
|
||||
// #define qtkWarning Qtk::QtkMessageLogger::get().warning
|
||||
// #define qtkCritical Qtk::QtkMessageLogger::get().critical
|
||||
// #define qtkFatal Qtk::QtkMessageLogger::get().fatal
|
||||
|
||||
#define qtkDebug \
|
||||
Qtk::QtkMessageLogger( \
|
||||
QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC) \
|
||||
.logger() \
|
||||
.debug
|
||||
#define qtkInfo \
|
||||
Qtk::QtkMessageLogger( \
|
||||
QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC) \
|
||||
.logger() \
|
||||
.info
|
||||
#define qtkWarning \
|
||||
Qtk::QtkMessageLogger( \
|
||||
QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC) \
|
||||
.logger() \
|
||||
.warning
|
||||
#define qtkCritical \
|
||||
Qtk::QtkMessageLogger( \
|
||||
QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC) \
|
||||
.logger() \
|
||||
.critical
|
||||
#define qtkFatal \
|
||||
Qtk::QtkMessageLogger( \
|
||||
QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC) \
|
||||
.logger() \
|
||||
.fatal
|
||||
|
||||
namespace Qtk {
|
||||
class Transform3D;
|
||||
class Camera3D;
|
||||
|
||||
class QTKAPI QtkDebug : public QDebug {
|
||||
public:
|
||||
QtkDebug operator<<(const Transform3D & transform);
|
||||
};
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug dbg, const Transform3D & transform);
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Camera3D & camera);
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
QDataStream & operator<<(QDataStream & out, const Transform3D & transform);
|
||||
QDataStream & operator>>(QDataStream & in, Transform3D & transform);
|
||||
|
||||
QDataStream & operator<<(QDataStream & out, const Camera3D & camera);
|
||||
QDataStream & operator>>(QDataStream & in, Camera3D & camera);
|
||||
#endif
|
||||
|
||||
class QTKAPI QtkMessageLogger {
|
||||
public:
|
||||
QtkMessageLogger(const char * file, int line, const char * function) :
|
||||
mQMessageLogger(file, line, function) {
|
||||
qDebug();
|
||||
}
|
||||
|
||||
// static QtkMessageLogger * get() {
|
||||
// if(mQtkMessageLogger == Q_NULLPTR) {
|
||||
// mQtkMessageLogger = new QtkMessageLogger();
|
||||
// }
|
||||
// return mQtkMessageLogger;
|
||||
// }
|
||||
|
||||
// QtkDebug debug() const {}
|
||||
|
||||
[[nodiscard]] inline const QMessageLogger & logger() const {
|
||||
return mQMessageLogger;
|
||||
}
|
||||
|
||||
inline QtkDebug debug() const { return {}; };
|
||||
|
||||
|
||||
static QtkMessageLogger * mQtkMessageLogger;
|
||||
QMessageLogger mQMessageLogger;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Qtk
|
||||
|
||||
#endif // QTK_QTKMESSAGELOGGER_H
|
||||
@@ -19,8 +19,8 @@ QMatrix4x4 Scene::mProjection;
|
||||
******************************************************************************/
|
||||
|
||||
Scene::Scene() : mSceneName("Default Scene") {
|
||||
mCamera.setTranslation({0.0f, 0.0f, 20.0f});
|
||||
mCamera.setRotation({-5.0f, 0.0f, 1.0f, 0.0f});
|
||||
mCamera.getTransform().setTranslation(0.0f, 0.0f, 20.0f);
|
||||
mCamera.getTransform().setRotation(-5.0f, 0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
Scene::~Scene() {
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <QUrl>
|
||||
|
||||
#include <queue>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
#include "camera3d.h"
|
||||
@@ -87,7 +86,7 @@ namespace Qtk {
|
||||
void loadModel(const std::string & name, const std::string & path) {
|
||||
// Add the dropped model to the load queue.
|
||||
// This is consumed during rendering of the scene if not empty.
|
||||
mModelLoadQueue.emplace(name, path);
|
||||
mModelLoadQueue.push({name, path});
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
|
||||
@@ -9,18 +9,19 @@
|
||||
#include <QDebug>
|
||||
#include <QImageReader>
|
||||
|
||||
#include "app/qtkmainwindow.h"
|
||||
#include "texture.h"
|
||||
|
||||
using namespace Qtk;
|
||||
|
||||
QImage OpenGLTextureFactory::initImage(
|
||||
QImage * OpenGLTextureFactory::initImage(
|
||||
const char * image, bool flipX, bool flipY) {
|
||||
// Qt6 limits loaded images to 256MB by default
|
||||
QImageReader::setAllocationLimit(1024);
|
||||
auto loadedImage = QImage(image).mirrored(flipX, flipY);
|
||||
if(loadedImage.isNull()) {
|
||||
return defaultTexture();
|
||||
QImageReader::setAllocationLimit(512);
|
||||
auto loadedImage = new QImage(QImage(image).mirrored(flipX, flipY));
|
||||
if(loadedImage->isNull()) {
|
||||
qDebug() << "[Qtk::OpenGLTextureFactory] Error loading image: " << image
|
||||
<< "\nSupported types: " << QImageReader::supportedImageFormats();
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
|
||||
return loadedImage;
|
||||
@@ -28,12 +29,13 @@ QImage OpenGLTextureFactory::initImage(
|
||||
|
||||
QOpenGLTexture * OpenGLTextureFactory::initTexture(
|
||||
const char * texture, bool flipX, bool flipY) {
|
||||
QImage image = initImage(texture, flipX, flipY);
|
||||
QImage * image = initImage(texture, flipX, flipY);
|
||||
auto newTexture = new QOpenGLTexture(QOpenGLTexture::Target2D);
|
||||
newTexture->setData(image);
|
||||
newTexture->setData(*image);
|
||||
newTexture->setWrapMode(QOpenGLTexture::Repeat);
|
||||
newTexture->setMinMagFilters(
|
||||
QOpenGLTexture::LinearMipMapLinear, QOpenGLTexture::Linear);
|
||||
delete image;
|
||||
return newTexture;
|
||||
}
|
||||
|
||||
@@ -69,7 +71,6 @@ QOpenGLTexture * OpenGLTextureFactory::initCubeMap(
|
||||
QImage faceImage(faceTextures[i]);
|
||||
if(faceImage.isNull()) {
|
||||
qDebug() << "Error loading cube map image\n";
|
||||
faceImage = defaultTexture();
|
||||
}
|
||||
faceImage = faceImage.convertToFormat(QImage::Format_RGBA8888);
|
||||
|
||||
|
||||
@@ -74,9 +74,9 @@ namespace Qtk {
|
||||
* Can be absolute or Qt resource path.
|
||||
* @param flipX If true the image will be flipped on X axis.
|
||||
* @param flipY If true the image will be flipped on Y axis.
|
||||
* @return QImage object.
|
||||
* @return Pointer to an initialized QImage object.
|
||||
*/
|
||||
static QImage initImage(
|
||||
static QImage * initImage(
|
||||
const char * image, bool flipX = false, bool flipY = false);
|
||||
|
||||
/**
|
||||
@@ -132,14 +132,6 @@ namespace Qtk {
|
||||
const char * right, const char * top, const char * front,
|
||||
const char * left, const char * bottom, const char * back);
|
||||
|
||||
/// The texture used in place of a missing texture.
|
||||
static QImage defaultTexture() {
|
||||
// Use plaster for default texture if image fails to load.
|
||||
// This prevents segfaults when loading a texture that doesn't exist.
|
||||
// TODO: Replace with a '?' texture to indicate missing texture.
|
||||
return QImage(":/textures/plaster.png");
|
||||
}
|
||||
|
||||
private:
|
||||
// Private ctor to prevent creating instances of this class
|
||||
OpenGLTextureFactory() = default;
|
||||
|
||||
@@ -42,7 +42,6 @@ void Transform3D::rotate(const QQuaternion & dr) {
|
||||
|
||||
void Transform3D::setTranslation(const QVector3D & t) {
|
||||
m_dirty = true;
|
||||
qtkDebug() << "Setting translation to " << t;
|
||||
mTranslation = t;
|
||||
}
|
||||
|
||||
@@ -78,3 +77,45 @@ QVector3D Transform3D::getUp() const {
|
||||
QVector3D Transform3D::getRight() const {
|
||||
return mRotation.rotatedVector(LocalRight);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Private Methods
|
||||
******************************************************************************/
|
||||
|
||||
namespace Qtk {
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Transform3D & transform) {
|
||||
dbg << "Transform3D\n{\n";
|
||||
dbg << "Position: <" << transform.getTranslation().x() << ", "
|
||||
<< transform.getTranslation().y() << ", "
|
||||
<< transform.getTranslation().z() << ">\n";
|
||||
dbg << "Scale: <" << transform.getScale().x() << ", "
|
||||
<< transform.getScale().y() << ", " << transform.getScale().z()
|
||||
<< ">\n";
|
||||
dbg << "Rotation: <" << transform.getRotation().x() << ", "
|
||||
<< transform.getRotation().y() << ", " << transform.getRotation().z()
|
||||
<< " | " << transform.getRotation().scalar() << ">\n}";
|
||||
return dbg;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
QDataStream & operator<<(QDataStream & out, const Transform3D & transform) {
|
||||
out << transform.mTranslation;
|
||||
out << transform.mScale;
|
||||
out << transform.mRotation;
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream & operator>>(QDataStream & in, Transform3D & transform) {
|
||||
in >> transform.mTranslation;
|
||||
in >> transform.mScale;
|
||||
in >> transform.mRotation;
|
||||
transform.m_dirty = true;
|
||||
return in;
|
||||
}
|
||||
|
||||
#endif
|
||||
} // namespace Qtk
|
||||
|
||||
@@ -116,12 +116,12 @@ namespace Qtk {
|
||||
/**
|
||||
* Apply rotation upon an axis represented by the 3D vector (x, y, z)
|
||||
*
|
||||
* @param angle Angle to rotate.
|
||||
* @param ax X axis to apply the rotation on.
|
||||
* @param ay Y axis to apply the rotation on.
|
||||
* @param az Z axis to apply the rotation on.
|
||||
* @param angle Angle to rotate.
|
||||
*/
|
||||
inline void rotate(float ax, float ay, float az, float angle) {
|
||||
inline void rotate(float angle, float ax, float ay, float az) {
|
||||
rotate(QQuaternion::fromAxisAndAngle(ax, ay, az, angle));
|
||||
}
|
||||
|
||||
@@ -178,12 +178,12 @@ namespace Qtk {
|
||||
/**
|
||||
* Sets a rotation upon an axis represented by the 3D vector (x, y, z)
|
||||
*
|
||||
* @param angle Angle to set rotation.
|
||||
* @param ax X axis to set angle for.
|
||||
* @param ay Y axis to set angle for.
|
||||
* @param az Z axis to set angle for.
|
||||
* @param angle Angle to set rotation.
|
||||
*/
|
||||
inline void setRotation(float ax, float ay, float az, float angle) {
|
||||
inline void setRotation(float angle, float ax, float ay, float az) {
|
||||
setRotation(QQuaternion::fromAxisAndAngle(ax, ay, az, angle));
|
||||
}
|
||||
|
||||
@@ -249,10 +249,6 @@ namespace Qtk {
|
||||
|
||||
bool m_dirty;
|
||||
|
||||
/*************************************************************************
|
||||
* Qt Streams
|
||||
************************************************************************/
|
||||
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
friend QDataStream & operator<<(
|
||||
QDataStream & out, const Transform3D & transform);
|
||||
@@ -260,6 +256,15 @@ namespace Qtk {
|
||||
QDataStream & in, Transform3D & transform);
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug dbg, const Transform3D & transform);
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
QDataStream & operator<<(QDataStream & out, const Transform3D & transform);
|
||||
QDataStream & operator>>(QDataStream & in, Transform3D & transform);
|
||||
#endif
|
||||
} // namespace Qtk
|
||||
|
||||
Q_DECLARE_TYPEINFO(Qtk::Transform3D, Q_MOVABLE_TYPE);
|
||||
|
||||
Reference in New Issue
Block a user