2021-09-03 16:56:57 +00:00
|
|
|
/*##############################################################################
|
|
|
|
## Author: Shaun Reed ##
|
2022-03-06 16:54:05 +00:00
|
|
|
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
|
|
|
## About: Main window for Qt6 OpenGL widget application ##
|
2021-09-03 16:56:57 +00:00
|
|
|
## ##
|
|
|
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
|
|
|
##############################################################################*/
|
2022-08-21 19:37:42 +00:00
|
|
|
#ifndef QTK_QTKWIDGET_H
|
|
|
|
#define QTK_QTKWIDGET_H
|
2021-09-03 16:56:57 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <QMatrix4x4>
|
|
|
|
#include <QOpenGLDebugLogger>
|
|
|
|
#include <QOpenGLFunctions>
|
|
|
|
#include <QOpenGLWidget>
|
|
|
|
|
2022-11-24 22:26:53 +00:00
|
|
|
#include <qtkapi.h>
|
2022-11-25 19:36:12 +00:00
|
|
|
#include <scene.h>
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
namespace Qtk {
|
2022-11-25 19:36:12 +00:00
|
|
|
/**
|
|
|
|
* QtkWidget class to define required QOpenGLWidget functionality.
|
|
|
|
*
|
|
|
|
* This object has a Scene attached which manages the objects to render.
|
|
|
|
* Client input is passed through this widget to control the camera view.
|
|
|
|
*/
|
2022-11-24 22:26:53 +00:00
|
|
|
class QTKAPI QtkWidget : public QOpenGLWidget, protected QOpenGLFunctions {
|
|
|
|
Q_OBJECT;
|
|
|
|
|
|
|
|
public:
|
2022-11-25 19:36:12 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* Contructors / Destructors
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default ctor will configure a QSurfaceFormat with default settings.
|
|
|
|
*/
|
2022-11-24 22:26:53 +00:00
|
|
|
QtkWidget();
|
2022-11-25 19:36:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Qt Designer will call this ctor when creating this widget as a child.
|
|
|
|
*
|
|
|
|
* @param parent The parent QWidget
|
|
|
|
*/
|
2022-11-24 22:26:53 +00:00
|
|
|
explicit QtkWidget(QWidget * parent);
|
2022-11-25 19:36:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allow constructing the widget with a preconfigured QSurfaceFormat.
|
|
|
|
*
|
|
|
|
* @param format QSurfaceFormat already configured by the caller.
|
|
|
|
*/
|
2022-11-24 22:26:53 +00:00
|
|
|
explicit QtkWidget(const QSurfaceFormat & format);
|
2022-11-25 19:36:12 +00:00
|
|
|
|
2022-11-24 22:26:53 +00:00
|
|
|
~QtkWidget() override;
|
|
|
|
|
|
|
|
private:
|
2022-11-25 19:36:12 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* Private Methods
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
void teardownGL() { /* Nothing to teardown yet... */ }
|
|
|
|
// clang-format on
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-11-24 22:26:53 +00:00
|
|
|
public:
|
2022-11-25 19:36:12 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* Public Inherited Virtual Methods
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the widget is first constructed.
|
|
|
|
*/
|
2022-11-24 22:26:53 +00:00
|
|
|
void initializeGL() override;
|
2022-11-25 19:36:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the application window is resized.
|
|
|
|
*
|
|
|
|
* @param width The new width of the window.
|
|
|
|
* @param height The new height of the window.
|
|
|
|
*/
|
2022-11-24 22:26:53 +00:00
|
|
|
void resizeGL(int width, int height) override;
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-11-25 19:36:12 +00:00
|
|
|
/**
|
|
|
|
* Called when OpenGL repaints the widget.
|
|
|
|
*/
|
|
|
|
void paintGL() override;
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* Accessors
|
|
|
|
************************************************************************/
|
|
|
|
|
2022-11-24 22:26:53 +00:00
|
|
|
inline Qtk::Scene * getScene() { return mScene; }
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-11-25 19:36:12 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* Setters
|
|
|
|
************************************************************************/
|
|
|
|
|
2022-11-24 22:26:53 +00:00
|
|
|
inline void setScene(Qtk::Scene * scene) {
|
|
|
|
delete mScene;
|
|
|
|
mScene = scene;
|
|
|
|
}
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-11-24 22:26:53 +00:00
|
|
|
protected slots:
|
2022-11-25 19:36:12 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* Qt Slots
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the `frameSwapped` signal is caught.
|
|
|
|
* See definition of initializeGL()
|
|
|
|
*/
|
2022-11-24 22:26:53 +00:00
|
|
|
void update();
|
2022-11-25 19:36:12 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
#ifdef QTK_DEBUG
|
2022-11-25 19:36:12 +00:00
|
|
|
/**
|
|
|
|
* Called when the `messageLogged` signal is caught.
|
|
|
|
* See definition of initializeGL()
|
|
|
|
*
|
|
|
|
* @param msg The message logged.
|
|
|
|
*/
|
2022-11-24 22:26:53 +00:00
|
|
|
static void messageLogged(const QOpenGLDebugMessage & msg);
|
2022-08-07 17:12:12 +00:00
|
|
|
#endif
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-11-24 22:26:53 +00:00
|
|
|
protected:
|
2022-11-25 19:36:12 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* Protected Methods
|
|
|
|
************************************************************************/
|
|
|
|
|
2022-11-24 22:26:53 +00:00
|
|
|
void keyPressEvent(QKeyEvent * event) override;
|
|
|
|
void keyReleaseEvent(QKeyEvent * event) override;
|
|
|
|
void mousePressEvent(QMouseEvent * event) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent * event) override;
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-11-24 22:26:53 +00:00
|
|
|
private:
|
2022-11-25 19:36:12 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* Private Methods
|
|
|
|
************************************************************************/
|
|
|
|
|
2022-11-24 22:26:53 +00:00
|
|
|
void initializeWidget();
|
|
|
|
static void updateCameraInput();
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
#ifdef QTK_DEBUG
|
2022-11-24 22:26:53 +00:00
|
|
|
void printContextInformation();
|
|
|
|
QOpenGLDebugLogger * mDebugLogger;
|
2022-08-07 17:12:12 +00:00
|
|
|
#endif
|
2022-11-25 19:36:12 +00:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* Private Members
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
Qtk::Scene * mScene;
|
2022-08-07 17:12:12 +00:00
|
|
|
};
|
2022-11-24 22:26:53 +00:00
|
|
|
} // namespace Qtk
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-11-24 22:26:53 +00:00
|
|
|
#endif // QTK_QTKWIDGET_H
|