restore my error
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
find_package(OpenGL REQUIRED)
|
||||
_qt_project(qglview FALSE "QAD" "Gui;OpenGL;Xml" "qad_widgets;qad_utils;${OPENGL_LIBRARIES}")
|
||||
_qt_install(qglview FALSE "qad" "out_HDR" "out_QM")
|
||||
|
||||
qt_sources(test_SRC DIR "qglview_test")
|
||||
qt_wrap(${test_SRC} CPPS test_CPP)
|
||||
qt_add_executable(qglview_test test_CPP)
|
||||
qt_target_link_libraries(qglview_test qglview)
|
||||
find_package(OpenGL REQUIRED)
|
||||
_qt_project(qglview FALSE "QAD" "Gui;OpenGL;Xml" "qad_widgets;qad_utils;${OPENGL_LIBRARIES}")
|
||||
_qt_install(qglview FALSE "qad" "out_HDR" "out_QM")
|
||||
|
||||
qt_sources(test_SRC DIR "qglview_test")
|
||||
qt_wrap(${test_SRC} CPPS test_CPP)
|
||||
qt_add_executable(qglview_test test_CPP)
|
||||
qt_target_link_libraries(qglview_test qglview)
|
||||
|
||||
@@ -1,236 +1,236 @@
|
||||
#include "glwidget.h"
|
||||
#include "renderer_simple.h"
|
||||
#include "renderer_deferred_shading.h"
|
||||
#include <QVBoxLayout>
|
||||
|
||||
|
||||
GLWidget::GLWidget(QWidget *parent) : QWidget(parent) {
|
||||
view_ = new QGLView();
|
||||
view_->setFlags(windowFlags() | Qt::FramelessWindowHint);
|
||||
container = QWidget::createWindowContainer(view_, this);
|
||||
lay = new QVBoxLayout(this);
|
||||
lay->addWidget(container);
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
lay->setSpacing(0);
|
||||
setMouseTracking(true);
|
||||
setWindowIcon(QIcon("://icons/qglview.png"));
|
||||
connect(view_, &QGLView::doubleClick, this, &GLWidget::viewDoubleClicked);
|
||||
}
|
||||
|
||||
|
||||
QColor GLWidget::backColor() const {
|
||||
return view_->backColor();
|
||||
}
|
||||
|
||||
|
||||
qreal GLWidget::lineWidth() const {
|
||||
return view_->lineWidth();
|
||||
}
|
||||
|
||||
|
||||
qreal GLWidget::FOV() const {
|
||||
return view_->FOV();
|
||||
}
|
||||
|
||||
|
||||
qreal GLWidget::depthStart() const {
|
||||
return view_->depthStart();
|
||||
}
|
||||
|
||||
|
||||
qreal GLWidget::depthEnd() const {
|
||||
return view_->depthEnd();
|
||||
}
|
||||
|
||||
|
||||
QColor GLWidget::ambientColor() const {
|
||||
return view_->ambientColor();
|
||||
}
|
||||
|
||||
|
||||
bool GLWidget::isLightEnabled() const {
|
||||
return view_->isLightEnabled();
|
||||
}
|
||||
|
||||
|
||||
bool GLWidget::isGrabMouseEnabled() const {
|
||||
return view_->isGrabMouseEnabled();
|
||||
}
|
||||
|
||||
|
||||
bool GLWidget::isMouseRotateEnabled() const {
|
||||
return view_->isMouseRotateEnabled();
|
||||
}
|
||||
|
||||
|
||||
bool GLWidget::isMouseSelectionEnabled() const {
|
||||
return view_->isMouseSelectionEnabled();
|
||||
}
|
||||
|
||||
|
||||
bool GLWidget::isCameraOrbit() const
|
||||
{
|
||||
return view_->isCameraOrbit();
|
||||
}
|
||||
|
||||
|
||||
bool GLWidget::isHoverHaloEnabled() const {
|
||||
return view_->isHoverHaloEnabled();
|
||||
}
|
||||
|
||||
|
||||
QColor GLWidget::hoverHaloColor() const {
|
||||
return view_->hoverHaloColor();
|
||||
}
|
||||
|
||||
|
||||
qreal GLWidget::hoverHaloFillAlpha() const {
|
||||
return view_->hoverHaloFillAlpha();
|
||||
}
|
||||
|
||||
|
||||
bool GLWidget::isSelectionHaloEnabled() const {
|
||||
return view_->isSelectionHaloEnabled();
|
||||
}
|
||||
|
||||
|
||||
QColor GLWidget::selectionHaloColor() const {
|
||||
return view_->selectionHaloColor();
|
||||
}
|
||||
|
||||
|
||||
qreal GLWidget::selectionHaloFillAlpha() const {
|
||||
return view_->selectionHaloFillAlpha();
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::addObject(GLObjectBase * o) {
|
||||
view_->addObject(o);
|
||||
}
|
||||
|
||||
|
||||
QByteArray GLWidget::saveCamera() {
|
||||
return view_->saveCamera();
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::restoreCamera(const QByteArray &ba) {
|
||||
view_->restoreCamera(ba);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::stop() {
|
||||
view_->stop();
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::start(float freq, GLRendererBase * r) {
|
||||
if (r == nullptr) r = new RendererSimple(view_);
|
||||
GLRendererBase * pr = nullptr;
|
||||
view_->setRenderer(r, &pr);
|
||||
if (pr != nullptr && pr != r) delete pr;
|
||||
view_->start(freq);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setBackColor(const QColor & c) {
|
||||
view_->setBackColor(c);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setLineWidth(const qreal & arg) {
|
||||
view_->setLineWidth(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setFOV(const qreal & arg) {
|
||||
view_->setFOV(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setDepthStart(const qreal & arg) {
|
||||
view_->setDepthStart(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setDepthEnd(const qreal & arg) {
|
||||
view_->setDepthEnd(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setAmbientColor(const QColor & arg) {
|
||||
view_->setAmbientColor(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setLightEnabled(const bool & arg) {
|
||||
view_->setLightEnabled(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setGrabMouseEnabled(const bool & arg) {
|
||||
view_->setGrabMouseEnabled(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setMouseRotateEnabled(const bool & arg) {
|
||||
view_->setMouseRotateEnabled(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setMouseSelectionEnabled(const bool & arg) {
|
||||
view_->setMouseSelectionEnabled(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setCameraOrbit(const bool & arg) {
|
||||
view_->setCameraOrbit(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setHoverHaloEnabled(const bool & arg) {
|
||||
view_->setHoverHaloEnabled(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setHoverHaloColor(const QColor & arg) {
|
||||
view_->setHoverHaloColor(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setHoverHaloFillAlpha(const qreal & arg) {
|
||||
view_->setHoverHaloFillAlpha(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setSelectionHaloEnabled(const bool & arg) {
|
||||
view_->setSelectionHaloEnabled(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setSelectionHaloColor(const QColor & arg) {
|
||||
view_->setSelectionHaloColor(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setSelectionHaloFillAlpha(const qreal & arg) {
|
||||
view_->setSelectionHaloFillAlpha(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::viewDoubleClicked() {
|
||||
// qDebug() << "click widget!!";
|
||||
if (view_->windowState() == Qt::WindowFullScreen) {
|
||||
// view_->hide();
|
||||
container = QWidget::createWindowContainer(view_, this);
|
||||
lay->addWidget(container);
|
||||
container->show();
|
||||
// show();
|
||||
} else {
|
||||
// hide();
|
||||
view_->setParent(nullptr);
|
||||
view_->showFullScreen();
|
||||
lay->removeWidget(container);
|
||||
}
|
||||
// qDebug() << "click widge done!";
|
||||
}
|
||||
#include "glwidget.h"
|
||||
#include "renderer_simple.h"
|
||||
#include "renderer_deferred_shading.h"
|
||||
#include <QVBoxLayout>
|
||||
|
||||
|
||||
GLWidget::GLWidget(QWidget *parent) : QWidget(parent) {
|
||||
view_ = new QGLView();
|
||||
view_->setFlags(windowFlags() | Qt::FramelessWindowHint);
|
||||
container = QWidget::createWindowContainer(view_, this);
|
||||
lay = new QVBoxLayout(this);
|
||||
lay->addWidget(container);
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
lay->setSpacing(0);
|
||||
setMouseTracking(true);
|
||||
setWindowIcon(QIcon("://icons/qglview.png"));
|
||||
connect(view_, &QGLView::doubleClick, this, &GLWidget::viewDoubleClicked);
|
||||
}
|
||||
|
||||
|
||||
QColor GLWidget::backColor() const {
|
||||
return view_->backColor();
|
||||
}
|
||||
|
||||
|
||||
qreal GLWidget::lineWidth() const {
|
||||
return view_->lineWidth();
|
||||
}
|
||||
|
||||
|
||||
qreal GLWidget::FOV() const {
|
||||
return view_->FOV();
|
||||
}
|
||||
|
||||
|
||||
qreal GLWidget::depthStart() const {
|
||||
return view_->depthStart();
|
||||
}
|
||||
|
||||
|
||||
qreal GLWidget::depthEnd() const {
|
||||
return view_->depthEnd();
|
||||
}
|
||||
|
||||
|
||||
QColor GLWidget::ambientColor() const {
|
||||
return view_->ambientColor();
|
||||
}
|
||||
|
||||
|
||||
bool GLWidget::isLightEnabled() const {
|
||||
return view_->isLightEnabled();
|
||||
}
|
||||
|
||||
|
||||
bool GLWidget::isGrabMouseEnabled() const {
|
||||
return view_->isGrabMouseEnabled();
|
||||
}
|
||||
|
||||
|
||||
bool GLWidget::isMouseRotateEnabled() const {
|
||||
return view_->isMouseRotateEnabled();
|
||||
}
|
||||
|
||||
|
||||
bool GLWidget::isMouseSelectionEnabled() const {
|
||||
return view_->isMouseSelectionEnabled();
|
||||
}
|
||||
|
||||
|
||||
bool GLWidget::isCameraOrbit() const
|
||||
{
|
||||
return view_->isCameraOrbit();
|
||||
}
|
||||
|
||||
|
||||
bool GLWidget::isHoverHaloEnabled() const {
|
||||
return view_->isHoverHaloEnabled();
|
||||
}
|
||||
|
||||
|
||||
QColor GLWidget::hoverHaloColor() const {
|
||||
return view_->hoverHaloColor();
|
||||
}
|
||||
|
||||
|
||||
qreal GLWidget::hoverHaloFillAlpha() const {
|
||||
return view_->hoverHaloFillAlpha();
|
||||
}
|
||||
|
||||
|
||||
bool GLWidget::isSelectionHaloEnabled() const {
|
||||
return view_->isSelectionHaloEnabled();
|
||||
}
|
||||
|
||||
|
||||
QColor GLWidget::selectionHaloColor() const {
|
||||
return view_->selectionHaloColor();
|
||||
}
|
||||
|
||||
|
||||
qreal GLWidget::selectionHaloFillAlpha() const {
|
||||
return view_->selectionHaloFillAlpha();
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::addObject(GLObjectBase * o) {
|
||||
view_->addObject(o);
|
||||
}
|
||||
|
||||
|
||||
QByteArray GLWidget::saveCamera() {
|
||||
return view_->saveCamera();
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::restoreCamera(const QByteArray &ba) {
|
||||
view_->restoreCamera(ba);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::stop() {
|
||||
view_->stop();
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::start(float freq, GLRendererBase * r) {
|
||||
if (r == nullptr) r = new RendererSimple(view_);
|
||||
GLRendererBase * pr = nullptr;
|
||||
view_->setRenderer(r, &pr);
|
||||
if (pr != nullptr && pr != r) delete pr;
|
||||
view_->start(freq);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setBackColor(const QColor & c) {
|
||||
view_->setBackColor(c);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setLineWidth(const qreal & arg) {
|
||||
view_->setLineWidth(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setFOV(const qreal & arg) {
|
||||
view_->setFOV(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setDepthStart(const qreal & arg) {
|
||||
view_->setDepthStart(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setDepthEnd(const qreal & arg) {
|
||||
view_->setDepthEnd(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setAmbientColor(const QColor & arg) {
|
||||
view_->setAmbientColor(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setLightEnabled(const bool & arg) {
|
||||
view_->setLightEnabled(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setGrabMouseEnabled(const bool & arg) {
|
||||
view_->setGrabMouseEnabled(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setMouseRotateEnabled(const bool & arg) {
|
||||
view_->setMouseRotateEnabled(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setMouseSelectionEnabled(const bool & arg) {
|
||||
view_->setMouseSelectionEnabled(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setCameraOrbit(const bool & arg) {
|
||||
view_->setCameraOrbit(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setHoverHaloEnabled(const bool & arg) {
|
||||
view_->setHoverHaloEnabled(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setHoverHaloColor(const QColor & arg) {
|
||||
view_->setHoverHaloColor(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setHoverHaloFillAlpha(const qreal & arg) {
|
||||
view_->setHoverHaloFillAlpha(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setSelectionHaloEnabled(const bool & arg) {
|
||||
view_->setSelectionHaloEnabled(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setSelectionHaloColor(const QColor & arg) {
|
||||
view_->setSelectionHaloColor(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::setSelectionHaloFillAlpha(const qreal & arg) {
|
||||
view_->setSelectionHaloFillAlpha(arg);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::viewDoubleClicked() {
|
||||
// qDebug() << "click widget!!";
|
||||
if (view_->windowState() == Qt::WindowFullScreen) {
|
||||
// view_->hide();
|
||||
container = QWidget::createWindowContainer(view_, this);
|
||||
lay->addWidget(container);
|
||||
container->show();
|
||||
// show();
|
||||
} else {
|
||||
// hide();
|
||||
view_->setParent(nullptr);
|
||||
view_->showFullScreen();
|
||||
lay->removeWidget(container);
|
||||
}
|
||||
// qDebug() << "click widge done!";
|
||||
}
|
||||
|
||||
@@ -1,88 +1,88 @@
|
||||
#ifndef GLWIDGET_H
|
||||
#define GLWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
class QGLView;
|
||||
class GLRendererBase;
|
||||
class GLObjectBase;
|
||||
|
||||
class GLWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY (QColor backColor READ backColor WRITE setBackColor)
|
||||
Q_PROPERTY (qreal lineWidth READ lineWidth WRITE setLineWidth)
|
||||
Q_PROPERTY (qreal FOV READ FOV WRITE setFOV)
|
||||
Q_PROPERTY (qreal depthStart READ depthStart WRITE setDepthStart)
|
||||
Q_PROPERTY (qreal depthEnd READ depthEnd WRITE setDepthEnd)
|
||||
Q_PROPERTY (QColor ambientColor READ ambientColor WRITE setAmbientColor)
|
||||
Q_PROPERTY (bool grabMouse READ isGrabMouseEnabled WRITE setGrabMouseEnabled)
|
||||
Q_PROPERTY (bool mouseRotate READ isMouseRotateEnabled WRITE setMouseRotateEnabled)
|
||||
Q_PROPERTY (bool mouseSelection READ isMouseSelectionEnabled WRITE setMouseSelectionEnabled)
|
||||
Q_PROPERTY (bool cameraOrbit READ isCameraOrbit WRITE setCameraOrbit)
|
||||
Q_PROPERTY (bool hoverHalo READ isHoverHaloEnabled WRITE setHoverHaloEnabled)
|
||||
Q_PROPERTY (QColor hoverHaloColor READ hoverHaloColor WRITE setHoverHaloColor)
|
||||
Q_PROPERTY (qreal hoverHaloFillAlpha READ hoverHaloFillAlpha WRITE setHoverHaloFillAlpha)
|
||||
Q_PROPERTY (bool selectionHalo READ isSelectionHaloEnabled WRITE setSelectionHaloEnabled)
|
||||
Q_PROPERTY (QColor selectionHaloColor READ selectionHaloColor WRITE setSelectionHaloColor)
|
||||
Q_PROPERTY (qreal selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha)
|
||||
public:
|
||||
explicit GLWidget(QWidget *parent = nullptr);
|
||||
QGLView * view() {return view_;}
|
||||
|
||||
QColor backColor() const;
|
||||
qreal lineWidth() const;
|
||||
qreal FOV() const;
|
||||
qreal depthStart() const;
|
||||
qreal depthEnd() const;
|
||||
QColor ambientColor() const;
|
||||
bool isLightEnabled() const;
|
||||
bool isGrabMouseEnabled() const;
|
||||
bool isMouseRotateEnabled() const;
|
||||
bool isMouseSelectionEnabled() const;
|
||||
bool isCameraOrbit() const;
|
||||
bool isHoverHaloEnabled() const;
|
||||
QColor hoverHaloColor() const;
|
||||
qreal hoverHaloFillAlpha() const;
|
||||
bool isSelectionHaloEnabled() const;
|
||||
QColor selectionHaloColor() const;
|
||||
qreal selectionHaloFillAlpha() const;
|
||||
|
||||
void addObject(GLObjectBase * o);
|
||||
QByteArray saveCamera();
|
||||
void restoreCamera(const QByteArray & ba);
|
||||
|
||||
public slots:
|
||||
void stop();
|
||||
void start(float freq = 60.0, GLRendererBase * r = nullptr);
|
||||
void setBackColor(const QColor & c);
|
||||
void setLineWidth(const qreal & arg);
|
||||
void setFOV(const qreal & arg);
|
||||
void setDepthStart(const qreal & arg);
|
||||
void setDepthEnd(const qreal & arg);
|
||||
void setAmbientColor(const QColor & arg);
|
||||
void setLightEnabled(const bool & arg);
|
||||
void setGrabMouseEnabled(const bool & arg);
|
||||
void setMouseRotateEnabled(const bool & arg);
|
||||
void setMouseSelectionEnabled(const bool & arg);
|
||||
void setCameraOrbit(const bool & arg);
|
||||
void setHoverHaloEnabled(const bool & arg);
|
||||
void setHoverHaloColor(const QColor & arg);
|
||||
void setHoverHaloFillAlpha(const qreal & arg);
|
||||
void setSelectionHaloEnabled(const bool & arg);
|
||||
void setSelectionHaloColor(const QColor & arg);
|
||||
void setSelectionHaloFillAlpha(const qreal & arg);
|
||||
|
||||
private slots:
|
||||
void viewDoubleClicked();
|
||||
|
||||
private:
|
||||
QWidget * container;
|
||||
QGLView * view_;
|
||||
QLayout * lay;
|
||||
|
||||
signals:
|
||||
};
|
||||
|
||||
#endif // GLWIDGET_H
|
||||
#ifndef GLWIDGET_H
|
||||
#define GLWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
class QGLView;
|
||||
class GLRendererBase;
|
||||
class GLObjectBase;
|
||||
|
||||
class GLWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY (QColor backColor READ backColor WRITE setBackColor)
|
||||
Q_PROPERTY (qreal lineWidth READ lineWidth WRITE setLineWidth)
|
||||
Q_PROPERTY (qreal FOV READ FOV WRITE setFOV)
|
||||
Q_PROPERTY (qreal depthStart READ depthStart WRITE setDepthStart)
|
||||
Q_PROPERTY (qreal depthEnd READ depthEnd WRITE setDepthEnd)
|
||||
Q_PROPERTY (QColor ambientColor READ ambientColor WRITE setAmbientColor)
|
||||
Q_PROPERTY (bool grabMouse READ isGrabMouseEnabled WRITE setGrabMouseEnabled)
|
||||
Q_PROPERTY (bool mouseRotate READ isMouseRotateEnabled WRITE setMouseRotateEnabled)
|
||||
Q_PROPERTY (bool mouseSelection READ isMouseSelectionEnabled WRITE setMouseSelectionEnabled)
|
||||
Q_PROPERTY (bool cameraOrbit READ isCameraOrbit WRITE setCameraOrbit)
|
||||
Q_PROPERTY (bool hoverHalo READ isHoverHaloEnabled WRITE setHoverHaloEnabled)
|
||||
Q_PROPERTY (QColor hoverHaloColor READ hoverHaloColor WRITE setHoverHaloColor)
|
||||
Q_PROPERTY (qreal hoverHaloFillAlpha READ hoverHaloFillAlpha WRITE setHoverHaloFillAlpha)
|
||||
Q_PROPERTY (bool selectionHalo READ isSelectionHaloEnabled WRITE setSelectionHaloEnabled)
|
||||
Q_PROPERTY (QColor selectionHaloColor READ selectionHaloColor WRITE setSelectionHaloColor)
|
||||
Q_PROPERTY (qreal selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha)
|
||||
public:
|
||||
explicit GLWidget(QWidget *parent = nullptr);
|
||||
QGLView * view() {return view_;}
|
||||
|
||||
QColor backColor() const;
|
||||
qreal lineWidth() const;
|
||||
qreal FOV() const;
|
||||
qreal depthStart() const;
|
||||
qreal depthEnd() const;
|
||||
QColor ambientColor() const;
|
||||
bool isLightEnabled() const;
|
||||
bool isGrabMouseEnabled() const;
|
||||
bool isMouseRotateEnabled() const;
|
||||
bool isMouseSelectionEnabled() const;
|
||||
bool isCameraOrbit() const;
|
||||
bool isHoverHaloEnabled() const;
|
||||
QColor hoverHaloColor() const;
|
||||
qreal hoverHaloFillAlpha() const;
|
||||
bool isSelectionHaloEnabled() const;
|
||||
QColor selectionHaloColor() const;
|
||||
qreal selectionHaloFillAlpha() const;
|
||||
|
||||
void addObject(GLObjectBase * o);
|
||||
QByteArray saveCamera();
|
||||
void restoreCamera(const QByteArray & ba);
|
||||
|
||||
public slots:
|
||||
void stop();
|
||||
void start(float freq = 60.0, GLRendererBase * r = nullptr);
|
||||
void setBackColor(const QColor & c);
|
||||
void setLineWidth(const qreal & arg);
|
||||
void setFOV(const qreal & arg);
|
||||
void setDepthStart(const qreal & arg);
|
||||
void setDepthEnd(const qreal & arg);
|
||||
void setAmbientColor(const QColor & arg);
|
||||
void setLightEnabled(const bool & arg);
|
||||
void setGrabMouseEnabled(const bool & arg);
|
||||
void setMouseRotateEnabled(const bool & arg);
|
||||
void setMouseSelectionEnabled(const bool & arg);
|
||||
void setCameraOrbit(const bool & arg);
|
||||
void setHoverHaloEnabled(const bool & arg);
|
||||
void setHoverHaloColor(const QColor & arg);
|
||||
void setHoverHaloFillAlpha(const qreal & arg);
|
||||
void setSelectionHaloEnabled(const bool & arg);
|
||||
void setSelectionHaloColor(const QColor & arg);
|
||||
void setSelectionHaloFillAlpha(const qreal & arg);
|
||||
|
||||
private slots:
|
||||
void viewDoubleClicked();
|
||||
|
||||
private:
|
||||
QWidget * container;
|
||||
QGLView * view_;
|
||||
QLayout * lay;
|
||||
|
||||
signals:
|
||||
};
|
||||
|
||||
#endif // GLWIDGET_H
|
||||
|
||||
@@ -1,96 +1,96 @@
|
||||
#include "openglwindow.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QOpenGLContext>
|
||||
#include <QOpenGLPaintDevice>
|
||||
#include <QPainter>
|
||||
#include <qopenglext.h>
|
||||
|
||||
|
||||
OpenGLWindow::OpenGLWindow(QWindow *parent)
|
||||
: QWindow(parent)
|
||||
, m_context(nullptr)
|
||||
, m_device(nullptr)
|
||||
{
|
||||
setFlags(flags() | Qt::FramelessWindowHint);
|
||||
setSurfaceType(QWindow::OpenGLSurface);
|
||||
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
|
||||
// qDebug() << format;
|
||||
#ifdef QT_OPENGL_ES_2
|
||||
format.setRenderableType(QSurfaceFormat::OpenGLES);
|
||||
#else
|
||||
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
|
||||
format.setVersion(2, 0);
|
||||
format.setProfile(QSurfaceFormat::NoProfile);
|
||||
}
|
||||
#endif
|
||||
format.setDepthBufferSize(24);
|
||||
format.setSamples(8);
|
||||
// format.setStencilBufferSize(8);
|
||||
setFormat(format);
|
||||
QSurfaceFormat::setDefaultFormat(format);
|
||||
}
|
||||
|
||||
|
||||
OpenGLWindow::~OpenGLWindow() {
|
||||
delete m_device;
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::render(QPainter *painter) {
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::initialize() {
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::render() {
|
||||
// if (!m_device) m_device = new QOpenGLPaintDevice;
|
||||
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
// m_device->setSize(size() * devicePixelRatio());
|
||||
// m_device->setDevicePixelRatio(devicePixelRatio());
|
||||
// QPainter painter(m_device);
|
||||
// render(&painter);
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::renderLater() {
|
||||
requestUpdate();
|
||||
}
|
||||
|
||||
|
||||
bool OpenGLWindow::event(QEvent *event) {
|
||||
switch (event->type()) {
|
||||
case QEvent::UpdateRequest:
|
||||
renderNow();
|
||||
return true;
|
||||
default:
|
||||
return QWindow::event(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::exposeEvent(QExposeEvent *event) {
|
||||
if (isExposed()) renderNow();
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::renderNow() {
|
||||
if (!isExposed())
|
||||
return;
|
||||
bool needsInitialize = false;
|
||||
if (!m_context) {
|
||||
m_context = new QOpenGLContext(this);
|
||||
m_context->setFormat(requestedFormat());
|
||||
m_context->create();
|
||||
needsInitialize = true;
|
||||
}
|
||||
m_context->makeCurrent(this);
|
||||
if (needsInitialize) {
|
||||
initializeOpenGLFunctions();
|
||||
initialize();
|
||||
}
|
||||
render();
|
||||
m_context->swapBuffers(this);
|
||||
}
|
||||
|
||||
#include "openglwindow.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QOpenGLContext>
|
||||
#include <QOpenGLPaintDevice>
|
||||
#include <QPainter>
|
||||
#include <qopenglext.h>
|
||||
|
||||
|
||||
OpenGLWindow::OpenGLWindow(QWindow *parent)
|
||||
: QWindow(parent)
|
||||
, m_context(nullptr)
|
||||
, m_device(nullptr)
|
||||
{
|
||||
setFlags(flags() | Qt::FramelessWindowHint);
|
||||
setSurfaceType(QWindow::OpenGLSurface);
|
||||
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
|
||||
// qDebug() << format;
|
||||
#ifdef QT_OPENGL_ES_2
|
||||
format.setRenderableType(QSurfaceFormat::OpenGLES);
|
||||
#else
|
||||
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
|
||||
format.setVersion(2, 0);
|
||||
format.setProfile(QSurfaceFormat::NoProfile);
|
||||
}
|
||||
#endif
|
||||
format.setDepthBufferSize(24);
|
||||
format.setSamples(8);
|
||||
// format.setStencilBufferSize(8);
|
||||
setFormat(format);
|
||||
QSurfaceFormat::setDefaultFormat(format);
|
||||
}
|
||||
|
||||
|
||||
OpenGLWindow::~OpenGLWindow() {
|
||||
delete m_device;
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::render(QPainter *painter) {
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::initialize() {
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::render() {
|
||||
// if (!m_device) m_device = new QOpenGLPaintDevice;
|
||||
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
// m_device->setSize(size() * devicePixelRatio());
|
||||
// m_device->setDevicePixelRatio(devicePixelRatio());
|
||||
// QPainter painter(m_device);
|
||||
// render(&painter);
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::renderLater() {
|
||||
requestUpdate();
|
||||
}
|
||||
|
||||
|
||||
bool OpenGLWindow::event(QEvent *event) {
|
||||
switch (event->type()) {
|
||||
case QEvent::UpdateRequest:
|
||||
renderNow();
|
||||
return true;
|
||||
default:
|
||||
return QWindow::event(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::exposeEvent(QExposeEvent *event) {
|
||||
if (isExposed()) renderNow();
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::renderNow() {
|
||||
if (!isExposed())
|
||||
return;
|
||||
bool needsInitialize = false;
|
||||
if (!m_context) {
|
||||
m_context = new QOpenGLContext(this);
|
||||
m_context->setFormat(requestedFormat());
|
||||
m_context->create();
|
||||
needsInitialize = true;
|
||||
}
|
||||
m_context->makeCurrent(this);
|
||||
if (needsInitialize) {
|
||||
initializeOpenGLFunctions();
|
||||
initialize();
|
||||
}
|
||||
render();
|
||||
m_context->swapBuffers(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
#include <QWindow>
|
||||
#include <QOpenGLFunctions>
|
||||
|
||||
class QPainter;
|
||||
class QOpenGLContext;
|
||||
class QOpenGLPaintDevice;
|
||||
|
||||
|
||||
class OpenGLWindow : public QWindow, protected QOpenGLFunctions
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit OpenGLWindow(QWindow *parent = nullptr);
|
||||
~OpenGLWindow();
|
||||
|
||||
virtual void render(QPainter *painter);
|
||||
virtual void render();
|
||||
|
||||
virtual void initialize();
|
||||
|
||||
QOpenGLContext * context() {return m_context;}
|
||||
|
||||
public slots:
|
||||
void renderLater();
|
||||
void renderNow();
|
||||
|
||||
protected:
|
||||
bool event(QEvent *event) override;
|
||||
|
||||
void exposeEvent(QExposeEvent *event) override;
|
||||
|
||||
private:
|
||||
QOpenGLContext *m_context;
|
||||
QOpenGLPaintDevice *m_device;
|
||||
};
|
||||
|
||||
#include <QWindow>
|
||||
#include <QOpenGLFunctions>
|
||||
|
||||
class QPainter;
|
||||
class QOpenGLContext;
|
||||
class QOpenGLPaintDevice;
|
||||
|
||||
|
||||
class OpenGLWindow : public QWindow, protected QOpenGLFunctions
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit OpenGLWindow(QWindow *parent = nullptr);
|
||||
~OpenGLWindow();
|
||||
|
||||
virtual void render(QPainter *painter);
|
||||
virtual void render();
|
||||
|
||||
virtual void initialize();
|
||||
|
||||
QOpenGLContext * context() {return m_context;}
|
||||
|
||||
public slots:
|
||||
void renderLater();
|
||||
void renderNow();
|
||||
|
||||
protected:
|
||||
bool event(QEvent *event) override;
|
||||
|
||||
void exposeEvent(QExposeEvent *event) override;
|
||||
|
||||
private:
|
||||
QOpenGLContext *m_context;
|
||||
QOpenGLPaintDevice *m_device;
|
||||
};
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
_qt_plugin(qglview "Gui;Widgets;OpenGL" "qglview")
|
||||
_qt_plugin(qglview "Gui;Widgets;OpenGL" "qglview")
|
||||
|
||||
1692
qglview/qglview.cpp
1692
qglview/qglview.cpp
@@ -1,846 +1,846 @@
|
||||
/*
|
||||
QGLView
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "qglview.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QKeyEvent>
|
||||
|
||||
|
||||
QGLView::QGLView(): OpenGLWindow(), fbo_selection(3) {
|
||||
// setFrameShape(QFrame::NoFrame);
|
||||
// setViewportUpdateMode(FullViewportUpdate);
|
||||
// setCacheMode(CacheNone);
|
||||
// setMouseTracking(true);
|
||||
// setFocusPolicy(Qt::WheelFocus);
|
||||
// setScene(new QGraphicsScene());
|
||||
// setInteractive(true);
|
||||
setIcon(QIcon("://icons/qglview.png"));
|
||||
deleting_ = false;
|
||||
timer = 0;
|
||||
need_init_ = is_first_draw = true;
|
||||
objects_.is_root = true;
|
||||
objects_.view_ = this;
|
||||
backColor_ = Qt::darkGray;
|
||||
hoverHaloColor_ = QColor(195, 140, 255, 96);
|
||||
selectionHaloColor_ = QColor(175, 255, 140);
|
||||
ambientColor_ = QColor(10, 10, 10);
|
||||
lastPos = QPoint(-1, -1);
|
||||
lineWidth_ = 1.;
|
||||
max_anisotropic = 1;
|
||||
max_texture_chanels = 8;
|
||||
cameraOrbit_ = lightEnabled_ = true;
|
||||
shaders_supported = selecting_ = customMouseMove_ = false;
|
||||
sel_button = Qt::LeftButton;
|
||||
sel_mod = Qt::NoModifier;
|
||||
renderer_ = nullptr;
|
||||
fps_cnt = 0;
|
||||
fps_tm = fps_ = 0.;
|
||||
sel_obj = hov_obj = nullptr;
|
||||
fogDensity_ = fogEnd_ = 1.;
|
||||
fogStart_ = 0.;
|
||||
fogMode_ = Exp;
|
||||
hoverHaloFill_ = 0.333f;
|
||||
selectionHaloFill_ = 0.5f;
|
||||
//lmode = Simple;
|
||||
shader_select = shader_halo = nullptr;
|
||||
setFeature(qglMSAA, false);
|
||||
setFeature(qglFXAA, false);
|
||||
setFeature(qglLinearFiltering, true);
|
||||
setFeature(qglAnisotropicLevel, 8);
|
||||
setFeature(qglHDR, false);
|
||||
setFeature(qglEyeAccomodationEnabled, false);
|
||||
setFeature(qglEyeAccomodationTime, 16.);
|
||||
setFeature(qglEyeAccomodationMaxSpeed, 0.2);
|
||||
setFeature(qglBloomEnabled, false);
|
||||
setFeature(qglBloomThreshold, 0.9);
|
||||
setFeature(qglBloomFactor, 1.);
|
||||
setFeature(qglBloomRadius, 8);
|
||||
setFeature(qglMotionBlurEnabled, false);
|
||||
setFeature(qglMotionBlurFactor, 1.);
|
||||
setFeature(qglMotionBlurSteps, 8);
|
||||
setFeature(qglShadowsEnabled, false);
|
||||
setFeature(qglShadowsMapSize, 512);
|
||||
setFeature(qglShadowsSoftEnabled, true);
|
||||
setFeature(qglReflectionsEnabled, false);
|
||||
setFeature(qglReflectionsBlur, true);
|
||||
setFeature(qglSSAOEnabled, false);
|
||||
setFeature(qglSSAORadius, 5);
|
||||
setFeature(qglDepthOfFieldEnabled, false);
|
||||
setFeature(qglDepthOfFieldAutoFocusEnabled, true);
|
||||
setFeature(qglDepthOfFieldAutoFocusSpeed, 0.1);
|
||||
setFeature(qglDepthOfFieldFocus, 1.);
|
||||
setFeature(qglDepthOfFieldDiaphragm, 8.);
|
||||
mouse_first = mouseSelect_ = hoverHalo_ = selectionHalo_ = true;
|
||||
mouseRotate_ = true;
|
||||
fogEnabled_ = is_init = grabMouse_ = shaders_bind = changed_ = false;
|
||||
rmode = GLObjectBase::Fill;
|
||||
sel_mode = QGLView::SingleSelection;
|
||||
// sel_pen = QPen(Qt::black, 1, Qt::DashLine);
|
||||
// sel_brush = QBrush(QColor(170, 100, 255, 120));
|
||||
camera()->setAim(QVector3D());
|
||||
camera()->setPos(QVector3D(2, 2, 2));
|
||||
camera()->setName("Camera");
|
||||
addObject(camera());
|
||||
emit cameraPosChanged(camera()->pos());
|
||||
//camera().aim_ = camera().pos_;
|
||||
ktm_.restart();
|
||||
}
|
||||
|
||||
|
||||
QGLView::~QGLView() {
|
||||
stop();
|
||||
if (shader_select) delete shader_select;
|
||||
if (shader_halo) delete shader_halo;
|
||||
deleting_ = true;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::stop() {
|
||||
if (timer) killTimer(timer);
|
||||
timer = 0;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::start(float freq) {
|
||||
stop();
|
||||
timer = startTimer(freq <= 0.f ? 0 : int(1000.f / freq));
|
||||
}
|
||||
|
||||
|
||||
GLRendererBase * QGLView::renderer() {
|
||||
return renderer_;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::setRenderer(GLRendererBase * r, GLRendererBase ** prev) {
|
||||
if (prev != nullptr) *prev = renderer_;
|
||||
renderer_ = r;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::addObject(GLObjectBase * o) {
|
||||
objects_.addChild(o);
|
||||
o->setView(this);
|
||||
collectLights();
|
||||
QList<GLObjectBase*> cl = o->children(true);
|
||||
cl << o;
|
||||
foreach (GLObjectBase * i, cl) {
|
||||
emit objectAdded(i);
|
||||
}
|
||||
if (is_init) {
|
||||
o->init();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int QGLView::objectsCount(bool all) {
|
||||
if (!all) return objects_.childCount();
|
||||
int cnt = 0;
|
||||
objectsCountInternal(&cnt, &objects_);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::removeObject(GLObjectBase * o, bool inChildren) {
|
||||
o->setView(nullptr);
|
||||
if (inChildren)
|
||||
removeObjectInternal(o, &objects_);
|
||||
else
|
||||
objects_.removeChild(o);
|
||||
objectDeleted(o);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::removeObject(GLObjectBase & o, bool inChildren) {
|
||||
removeObject(&o, inChildren);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::clearObjects(bool deleteAll) {
|
||||
removeObject(camera_);
|
||||
objects_.clearChildren(deleteAll);
|
||||
addObject(camera());
|
||||
selectObject(nullptr);
|
||||
hov_obj = nullptr;
|
||||
}
|
||||
|
||||
|
||||
QList<GLObjectBase *> QGLView::objects(bool all) {
|
||||
return objects_.children(all);
|
||||
}
|
||||
|
||||
|
||||
int QGLView::lightsCount() const {
|
||||
return lights_.size();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::removeLight(int index) {
|
||||
removeObject(lights_.at(index));
|
||||
lights_.removeAt(index);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::removeLight(Light * l) {
|
||||
foreach (Light * i, lights_)
|
||||
if (i == l) removeObject(i);
|
||||
lights_.removeAll(l);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::clearLights(bool deleteAll) {
|
||||
if (deleteAll)
|
||||
foreach (Light * i, lights_) delete i;
|
||||
lights_.clear();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::addTexture(const QString & path) {
|
||||
textures_manager->addTexture(path);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::addAnimation(const QString & dir, const QString & name) {
|
||||
textures_manager->addAnimation(dir, name);
|
||||
}
|
||||
|
||||
|
||||
Light * QGLView::light(int index) {
|
||||
return lights_[index];
|
||||
}
|
||||
|
||||
|
||||
Light * QGLView::light(const QString & name) {
|
||||
foreach (Light * i, lights_)
|
||||
if (i->name_ == name) return i;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::selectObject(GLObjectBase * o) {
|
||||
if (o == sel_obj) return;
|
||||
GLObjectBase * pso = sel_obj;
|
||||
sel_obj = o;
|
||||
emit selectionChanged(sel_obj, pso);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::resizeEvent(QResizeEvent * e) {
|
||||
renderLater();
|
||||
}
|
||||
|
||||
void QGLView::timerEvent(QTimerEvent *) {
|
||||
renderNow();
|
||||
if (ktm_.elapsed() < QApplication::keyboardInputInterval()) return;
|
||||
Qt::KeyboardModifiers km = QApplication::keyboardModifiers();
|
||||
foreach (int i, keys_)
|
||||
emit keyEvent((Qt::Key)i, km);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::render() {
|
||||
if (!isVisible()) return;
|
||||
resizeGL(width(), height());
|
||||
QRect g_rect(QPoint(), size());
|
||||
emit glBeforePaint();
|
||||
//qDebug() << "paintGL";
|
||||
//QMutexLocker ml_v(&v_mutex);
|
||||
glEnable(GL_CULL_FACE);
|
||||
//glDisable(GL_CULL_FACE);
|
||||
camera()->apply(aspect);
|
||||
//objects_.preparePos(camera());
|
||||
start_rp.cam_offset_matrix = camera()->offsetMatrix();
|
||||
start_rp.proj_matrix = getGLMatrix(GL_PROJECTION_MATRIX);
|
||||
start_rp.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX);
|
||||
//objects_.buildTransform();
|
||||
|
||||
/// Selection detect
|
||||
//glClearFramebuffer(QColor(100, 0, 0, 0));
|
||||
if (mouseSelect_) {
|
||||
glReleaseTextures();
|
||||
glEnableDepth();
|
||||
glDisable(GL_TEXTURE_1D);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisable(GL_TEXTURE_CUBE_MAP);
|
||||
glDisable(GL_MULTISAMPLE);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glDisable(GL_RESCALE_NORMAL);
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
fbo_selection.bind();
|
||||
fbo_selection.setWriteBuffer(0);
|
||||
glClearFramebuffer(QColor(0, 0, 0, 0));
|
||||
if (shaders_supported && shader_select->isLinked()) shader_select->bind();
|
||||
renderSelection();
|
||||
if (shaders_supported && shader_select->isLinked()) shader_select->release();
|
||||
uchar cgid[4] = {0, 0, 0, 0};
|
||||
uint iid = 0;
|
||||
GLObjectBase * so = nullptr;
|
||||
if (!g_rect.contains(lastPos)) {
|
||||
if (hov_obj != nullptr) {
|
||||
hov_obj = nullptr;
|
||||
emit hoverChanged(nullptr, hov_obj);
|
||||
}
|
||||
} else {
|
||||
glReadPixels(lastPos.x(), height() - lastPos.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, cgid);
|
||||
iid = uint(cgid[0] << 24) | uint(cgid[1] << 16) | uint(cgid[2] << 8) | cgid[3];
|
||||
so = ids.value(iid, nullptr);
|
||||
//qDebug() <<cgid[0]<<cgid[1]<<cgid[2]<<cgid[3]<< iid;
|
||||
if (so != hov_obj) {
|
||||
emit hoverChanged(so, hov_obj);
|
||||
hov_obj = so;
|
||||
}
|
||||
//if (so != 0) qDebug() << sel_obj->name() << cgid[3];
|
||||
}
|
||||
if (selectionHalo_ && sel_obj) {
|
||||
fbo_selection.setWriteBuffer(2);
|
||||
renderHalo(sel_obj, qHash((quint64)sel_obj), selectionHaloColor_, selectionHaloFill_);
|
||||
}
|
||||
if (hoverHalo_ && hov_obj) {
|
||||
fbo_selection.setWriteBuffer(1);
|
||||
renderHalo(hov_obj, iid, hoverHaloColor_, hoverHaloFill_);
|
||||
}
|
||||
fbo_selection.release();
|
||||
glEnableDepth();
|
||||
/*glEnableClientState(GL_NORMAL_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);*/
|
||||
}
|
||||
|
||||
camera()->apply(aspect);
|
||||
start_rp.cam_offset_matrix = camera()->offsetMatrix();
|
||||
cur_mvpm = start_rp.proj_matrix * start_rp.view_matrix * start_rp.cam_offset_matrix;
|
||||
//objects_.preparePos(camera());
|
||||
|
||||
static GLRendererBase * prev_rend = nullptr;
|
||||
glShadeModel(GL_SMOOTH);
|
||||
if (prev_rend != renderer_) {
|
||||
prev_rend = renderer_;
|
||||
if (renderer_ != nullptr) {
|
||||
renderer_->init(width(), height());
|
||||
renderer_->resize(width(), height());
|
||||
renderer_->reloadShaders();
|
||||
}
|
||||
}
|
||||
emit glBeginPaint();
|
||||
if (renderer_ != nullptr) {
|
||||
renderer_->rp.prepare();
|
||||
renderer_->prepareScene();
|
||||
renderer_->renderScene();
|
||||
}
|
||||
emit glPainting();
|
||||
glUseProgram(0);
|
||||
if (selectionHalo_ || hoverHalo_) {
|
||||
glReleaseTextures();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
//glClearFramebuffer(Qt::black, false);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_TEXTURE_CUBE_MAP);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisableDepth();
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
if (selectionHalo_ && sel_obj) {
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture(2));
|
||||
//qDebug() << "draw sel";
|
||||
glDrawQuad();
|
||||
}
|
||||
if (hoverHalo_ && hov_obj) {
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture(1));
|
||||
//qDebug() << "draw hover";
|
||||
//glBindTexture(GL_TEXTURE_2D, textures_manager->loadTexture("batt_pn.jpg"));
|
||||
glDrawQuad();
|
||||
}
|
||||
}
|
||||
|
||||
glResetAllTransforms();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glUseProgram(0);
|
||||
|
||||
//glDisable(GL_BLEND);
|
||||
//glDisable(GL_LIGHTING);
|
||||
//glActiveTexture(GL_TEXTURE0);
|
||||
//glBindTexture(GL_TEXTURE_2D, textures_manager->loadTexture("batt_pn.jpg"));
|
||||
//glDrawQuad();
|
||||
|
||||
emit glEndPaint();
|
||||
|
||||
/*releaseShaders();
|
||||
glActiveTextureChannel(0);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glColor4f(0.3, 0.5, 0.8, 0.5);
|
||||
glResetAllTransforms();
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0.f, 0.f); glVertex2f(-1.f, -1.f);
|
||||
glTexCoord2f(1.f, 0.f); glVertex2f(1.f, -1.);
|
||||
glTexCoord2f(1.f, 1.f); glVertex2f(1.f, 1.f);
|
||||
glTexCoord2f(0.f, 1.f); glVertex2f(-1.f, 1.f);
|
||||
glEnd();*/
|
||||
/*
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glDisable(GL_LIGHTING);
|
||||
glActiveTextureChannel(0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo->texture());
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(1.f, 1.f, 1.f);
|
||||
glTexCoord2f(0.f, 0.f); glVertex2f(-1.f, -1.f);
|
||||
glTexCoord2f(0.f, 1.f); glVertex2f(-1.f, 1.f);
|
||||
glTexCoord2f(1.f, 1.f); glVertex2f(1.f, 1.f);
|
||||
glTexCoord2f(1.f, 0.f); glVertex2f(1.f, -1.);
|
||||
glEnd();
|
||||
glEnable(GL_DEPTH_TEST);*/
|
||||
fps_tm += time.elapsed();
|
||||
time.restart();
|
||||
fps_cnt++;
|
||||
if (fps_tm < 1000.) return;
|
||||
fps_ = fps_cnt / fps_tm * 1000.;
|
||||
fps_tm = 0.;
|
||||
fps_cnt = 0;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::initialize() {
|
||||
//initializeOpenGLFunctions();
|
||||
glEnable(GL_TEXTURE_MAX_ANISOTROPY_EXT);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glEnableDepth();
|
||||
glEnable(GL_CULL_FACE);
|
||||
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
|
||||
glActiveTexture(GL_TEXTURE0 + 3);
|
||||
glEnable(GL_TEXTURE_GEN_S);
|
||||
glEnable(GL_TEXTURE_GEN_T);
|
||||
glEnable(GL_TEXTURE_GEN_R);
|
||||
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glCullFace(GL_BACK);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glColorMaterial(GL_FRONT, GL_DIFFUSE);
|
||||
|
||||
textures_manager->loadTextures();
|
||||
objects_.initInternal();
|
||||
checkCaps();
|
||||
|
||||
shader_select = new QOpenGLShaderProgram(context());
|
||||
shader_halo = new QOpenGLShaderProgram(context());
|
||||
reloadThisShaders();
|
||||
is_init = true;
|
||||
//resizeGL(width(), height());
|
||||
need_init_ = false;
|
||||
emit glInitializeDone();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::renderHalo(const GLObjectBase * obj, const uint iid, const QColor & color, const float & fill) {
|
||||
if (!shaders_supported) return;
|
||||
if (!shader_halo) return;
|
||||
if (!shader_halo->isLinked()) return;
|
||||
if (obj) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture());
|
||||
shader_halo->bind();
|
||||
shader_halo->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
|
||||
shader_halo->setUniformValue("t0", 0);
|
||||
shader_halo->setUniformValue("dt", QVector2D(1.f / width(), 1.f / height()));
|
||||
shader_halo->setUniformValue("selected", QVector4D(float((iid >> 24) & 0xFF) / 255.f,
|
||||
float((iid >> 16) & 0xFF) / 255.f,
|
||||
float((iid >> 8) & 0xFF) / 255.f,
|
||||
float( iid & 0xFF) / 255.f));
|
||||
shader_halo->setUniformValue("color", color);
|
||||
shader_halo->setUniformValue("fill", GLfloat(fill));
|
||||
//qDebug() << "render halo" << iid << shader_halo->log() << shader_halo->programId();
|
||||
glDisableDepth();
|
||||
//glClearFramebuffer(color);
|
||||
glDrawQuad(shader_halo);
|
||||
glDepthMask(GL_TRUE);
|
||||
//glFlush();
|
||||
shader_halo->release();
|
||||
} else {
|
||||
glClearFramebuffer(Qt::black, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QGLView::renderSelection() {
|
||||
// cid = 1;
|
||||
ids.clear();
|
||||
if (shaders_supported) {
|
||||
if (shader_select) {
|
||||
if (shader_select->isLinked()) {
|
||||
sh_id_loc = shader_select->uniformLocation("id");
|
||||
shader_select->setUniformValue("z_far", GLfloat(depthEnd()));
|
||||
shader_select->setUniformValue("z_near", GLfloat(depthStart()));
|
||||
}
|
||||
}
|
||||
}
|
||||
//qDebug() << sh_id_loc;
|
||||
start_rp.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX);
|
||||
glPushMatrix();
|
||||
renderSingleSelection(objects_);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::renderSingleSelection(GLObjectBase & o) {
|
||||
if (!o.isInit()) {
|
||||
o.init();
|
||||
o.loadTextures();
|
||||
}
|
||||
if (!o.visible_ || !o.select_) return;
|
||||
QMatrix4x4 curview = start_rp.view_matrix * start_rp.cam_offset_matrix * o.itransform_;
|
||||
uint id = qHash((quint64)&o);
|
||||
ids.insert(id, &o);
|
||||
glLineWidth(o.line_width > 0.f ? o.line_width : lineWidth_);
|
||||
glPointSize(o.line_width > 0.f ? o.line_width : lineWidth_);
|
||||
if (shaders_supported){
|
||||
if (shader_select) {
|
||||
if (shader_select->isLinked()) {
|
||||
setUniformMatrices(shader_select, start_rp.proj_matrix, curview);
|
||||
shader_select->setUniformValue(sh_id_loc, QVector4D(float((id >> 24) & 0xFF) / 255.f,
|
||||
float((id >> 16) & 0xFF) / 255.f,
|
||||
float((id >> 8) & 0xFF) / 255.f,
|
||||
float(id & 0xFF) / 255.f));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
setGLMatrix(curview);
|
||||
glColor4f(float((id >> 24) & 0xFF) / 255.f,
|
||||
float((id >> 16) & 0xFF) / 255.f,
|
||||
float((id >> 8) & 0xFF) / 255.f,
|
||||
float(id & 0xFF) / 255.f);
|
||||
}
|
||||
//qDebug() << o.name() << "assign to" << sh_id_loc << cid;
|
||||
//glColor4f(float((cid >> 24) & 0xFF) / 255.f, float((cid >> 16) & 0xFF) / 255.f, float((cid >> 8) & 0xFF) / 255.f, float(cid & 0xFF) / 255.f);
|
||||
// ++cid;
|
||||
o.draw(nullptr, true);
|
||||
foreach (GLObjectBase * i, o.children_)
|
||||
renderSingleSelection(*i);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::collectLights() {
|
||||
lights_.clear();
|
||||
collectObjectLights(&objects_);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::objectDeleted(GLObjectBase * o) {
|
||||
if (deleting_) return;
|
||||
//qDebug() << "del" << o;
|
||||
if (sel_obj == o) selectObject(nullptr);
|
||||
if (hov_obj == o) hov_obj = nullptr;
|
||||
collectLights();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::collectObjectLights(GLObjectBase * o) {
|
||||
if (o->type_ == GLObjectBase::glLight) {
|
||||
lights_ << globject_cast<Light * >(o);
|
||||
o->view_ = this;
|
||||
}
|
||||
foreach (GLObjectBase * i, o->children())
|
||||
collectObjectLights(i);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::objectsCountInternal(int * cnt, GLObjectBase * where) {
|
||||
++(*cnt);
|
||||
foreach (GLObjectBase * i, where->children_)
|
||||
objectsCountInternal(cnt, i);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::removeObjectInternal(GLObjectBase * o, GLObjectBase * where) {
|
||||
foreach (GLObjectBase * i, where->children_) {
|
||||
if (o == i)
|
||||
where->removeChild(i);
|
||||
else
|
||||
removeObjectInternal(o, i);
|
||||
objectDeleted(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QGLView::checkCaps() {
|
||||
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropic);
|
||||
//glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_texture_chanels);
|
||||
//qDebug() << max_texture_chanels;
|
||||
//qDebug() << max_texture_chanels;
|
||||
shaders_supported = QOpenGLShaderProgram::hasOpenGLShaderPrograms();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::reloadThisShaders() {
|
||||
if (!shaders_supported) return;
|
||||
loadShaders(shader_select, "selection", "://shaders");
|
||||
loadShaders(shader_halo, "selection_halo", "://shaders");
|
||||
//loadShaders(shader_rope, "rope", "://shaders");
|
||||
}
|
||||
|
||||
void QGLView::glReleaseTextures(int channels) {
|
||||
for (int i = channels - 1; i >= 0; --i) {
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QGLView::applyFog() {
|
||||
GLfloat fog_col[4] = {float(fogColor_.redF()), float(fogColor_.greenF()), float(fogColor_.blueF()), .0f};
|
||||
if (fogEnabled_) {
|
||||
glEnable(GL_FOG);
|
||||
glFogf(GL_FOG_DENSITY, fogDensity_);
|
||||
glFogf(GL_FOG_START, fogStart_);
|
||||
glFogf(GL_FOG_END, fogEnd_);
|
||||
glFogi(GL_FOG_MODE, fogMode_);
|
||||
fog_col[0] = fogColor_.redF();
|
||||
fog_col[1] = fogColor_.greenF();
|
||||
fog_col[2] = fogColor_.blueF();
|
||||
glFogfv(GL_FOG_COLOR, fog_col);
|
||||
} else glDisable(GL_FOG);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::resizeGL(int width, int height) {
|
||||
if (!is_init) return;
|
||||
if (width <= 0 || height <= 0) return;
|
||||
if (prev_size == QSize(width, height)) return;
|
||||
prev_size = QSize(width, height);
|
||||
aspect = float(width) / float(height);
|
||||
if (renderer_) renderer_->resize(width, height);
|
||||
mouse_first = true;
|
||||
//qDebug() << "resize" << width << height;
|
||||
fbo_selection.resize(width, height);
|
||||
iaspect = (aspect == 0.f) ? 0. : 1 / aspect;
|
||||
glViewport(0, 0, width, height);
|
||||
emit glResize(width, height);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::mouseReleaseEvent(QMouseEvent * e) {
|
||||
// qDebug() << "mouseReleaseEvent" << e << isActive();
|
||||
// QGraphicsView::mouseReleaseEvent(e);
|
||||
//setCursor(QCursor(Qt::ArrowCursor));
|
||||
selecting_ = false;
|
||||
if (mouseSelect_ && e->button() == Qt::LeftButton) {
|
||||
if ((lastPos - downPos).manhattanLength() < 8) {
|
||||
if (sel_obj != hov_obj)
|
||||
selectObject(hov_obj);
|
||||
}
|
||||
}
|
||||
emit glMouseReleaseEvent(e);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::mousePressEvent(QMouseEvent * e) {
|
||||
// qDebug() << "mousePressEvent" << e << isActive();
|
||||
// QGraphicsView::mousePressEvent(e);
|
||||
// mouseThis_ = (scene()->itemAt(mapToScene(e->pos()) , QTransform() ) == 0);
|
||||
selecting_ = false;
|
||||
if (!QRect(QPoint(), size()).contains(e->pos())) return;
|
||||
/// TODO select by rect
|
||||
//if (e->button() == sel_button && e->modifiers() == sel_mod)
|
||||
// selecting_ = true;
|
||||
lastPos = e->pos();
|
||||
downPos = lastPos;
|
||||
//qDebug() << mouseThis_;
|
||||
emit glMousePressEvent(e);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::mouseMoveEvent(QMouseEvent * e) {
|
||||
// qDebug() << "mouseMoveEvent" << e << isActive();
|
||||
// QGraphicsView::mouseMoveEvent(e);
|
||||
//lastPos = e->pos();
|
||||
if (selecting_) {
|
||||
return;
|
||||
}
|
||||
// if (!QRect(QPoint(), size()).contains(e->pos())) return;
|
||||
//if (scene()->itemAt(mapToScene(e->pos())) != 0) return;
|
||||
///qDebug() << e->x() << e->y();
|
||||
QRect g_rect(QPoint(), size());
|
||||
if (mouseRotate_) {
|
||||
float dx = e->x() - lastPos.x();
|
||||
float dy = e->y() - lastPos.y();
|
||||
if (e->buttons() & Qt::LeftButton) {
|
||||
//camera().angle_z += dx / 4.;
|
||||
//camera().angle_xy += dy / 4.;
|
||||
if (cameraOrbit_) {
|
||||
camera()->orbitZ(dx / 4.f);
|
||||
camera()->orbitXY(dy / 4.f);
|
||||
} else {
|
||||
camera()->rotateZ(dx / 4.f);
|
||||
camera()->rotateXY(dy / 4.f);
|
||||
}
|
||||
emit cameraPosChanged(camera()->pos());
|
||||
} else if (e->buttons() & Qt::RightButton) {
|
||||
float ad = camera()->distance();
|
||||
camera()->moveLeft(dx / 1000.f * ad);
|
||||
camera()->moveUp(dy / 1000.f * ad);
|
||||
//camera().pos.setX(camera().pos.x() + camera().pos.z() * dx / 500.);
|
||||
//camera().pos.setY(camera().pos.y() - camera().pos.z() * dy / 500.);
|
||||
emit cameraPosChanged(camera()->pos());
|
||||
}
|
||||
//lights[0]->pos_ = camera().pos();
|
||||
}
|
||||
if (customMouseMove_) emit customMouseMoveEvent(e->pos(), lastPos, e->buttons());
|
||||
lastPos = e->pos();
|
||||
if (grabMouse_) {
|
||||
//if (!isrunning) return;
|
||||
QCursor::setPos(mapToGlobal(QRect(QPoint(), size()).center()));
|
||||
static bool mouse_sec = false;
|
||||
if (mouse_sec) {
|
||||
mouse_sec = false;
|
||||
return;
|
||||
}
|
||||
if (mouse_first) {
|
||||
mouse_first = false;
|
||||
mouse_sec = true;
|
||||
//qDebug() << "first" << e->pos();
|
||||
return;
|
||||
}
|
||||
lastPos = g_rect.center();
|
||||
int dx = e->x() - lastPos.x();
|
||||
int dy = e->y() - lastPos.y();
|
||||
emit glMouseMoveEvent(new QMouseEvent(QEvent::MouseMove, QPoint(dx, dy), e->button(), e->buttons(), e->modifiers()));
|
||||
return;
|
||||
}
|
||||
emit glMouseMoveEvent(e);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::wheelEvent(QWheelEvent * e) {
|
||||
if (mouseRotate_) {
|
||||
if (e->delta() > 0) camera()->flyCloser(0.1f); //camera().pos.setZ(camera().pos.z() - 0.1 * camera().pos.z());
|
||||
if (e->delta() < 0) camera()->flyFarer(0.1f); //camera().pos.setZ(camera().pos.z() + 0.1 * camera().pos.z());
|
||||
emit cameraPosChanged(camera()->pos());
|
||||
}
|
||||
emit glWheelEvent(e);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::leaveEvent(QEvent * ) {
|
||||
lastPos = QPoint(-1, -1);
|
||||
//qDebug() << lastPos;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::keyPressEvent(QKeyEvent * e) {
|
||||
emit glKeyPressEvent(e);
|
||||
if (e->key() > 0) keys_.insert(e->key());
|
||||
if (e->key() == Qt::Key_F11) {
|
||||
emit doubleClick();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QGLView::keyReleaseEvent(QKeyEvent * e) {
|
||||
emit glKeyReleaseEvent(e);
|
||||
keys_.remove(e->key());
|
||||
}
|
||||
|
||||
|
||||
void QGLView::focusOutEvent(QFocusEvent *) {
|
||||
keys_.clear();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::mouseDoubleClickEvent(QMouseEvent * e) {
|
||||
if (e->buttons().testFlag(Qt::MidButton))
|
||||
emit doubleClick();
|
||||
}
|
||||
|
||||
|
||||
QByteArray QGLView::saveCamera() {
|
||||
ChunkStream cs;
|
||||
const Camera * c = camera();
|
||||
cs.add(1, c->posX());
|
||||
cs.add(2, c->posY());
|
||||
cs.add(3, c->posZ());
|
||||
cs.add(4, c->aim().x());
|
||||
cs.add(5, c->aim().y());
|
||||
cs.add(6, c->aim().z());
|
||||
cs.add(7, c->angleZ());
|
||||
cs.add(8, c->angleXY());
|
||||
cs.add(9, c->angleRoll());
|
||||
cs.add(10, c->FOV());
|
||||
return cs.data();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::restoreCamera(const QByteArray &ba) {
|
||||
if (ba.isEmpty()) return;
|
||||
ChunkStream cs(ba);
|
||||
QVector3D pos, aim, ang;
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1: pos.setX(cs.getData<float>()); break;
|
||||
case 2: pos.setY(cs.getData<float>()); break;
|
||||
case 3: pos.setZ(cs.getData<float>()); break;
|
||||
case 4: aim.setX(cs.getData<float>()); break;
|
||||
case 5: aim.setY(cs.getData<float>()); break;
|
||||
case 6: aim.setZ(cs.getData<float>()); break;
|
||||
case 7: ang.setZ(cs.getData<float>()); break;
|
||||
case 8: ang.setY(cs.getData<float>()); break;
|
||||
case 9: ang.setX(cs.getData<float>()); break;
|
||||
case 10: setFOV(cs.getData<float>()); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
camera()->setPos(pos);
|
||||
camera()->setAim(aim);
|
||||
camera()->setAngles(ang);
|
||||
}
|
||||
|
||||
|
||||
QByteArray QGLView::saveFeatures() {
|
||||
QByteArray ba;
|
||||
QDataStream ds(&ba, QIODevice::WriteOnly);
|
||||
ds << features_;
|
||||
return ba;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::restoreFeatures(const QByteArray & ba) {
|
||||
QHash<int, QVariant> f;
|
||||
QDataStream ds(ba);
|
||||
ds >> f;
|
||||
features_ = f;
|
||||
}
|
||||
|
||||
/*
|
||||
QGLView
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "qglview.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QKeyEvent>
|
||||
|
||||
|
||||
QGLView::QGLView(): OpenGLWindow(), fbo_selection(3) {
|
||||
// setFrameShape(QFrame::NoFrame);
|
||||
// setViewportUpdateMode(FullViewportUpdate);
|
||||
// setCacheMode(CacheNone);
|
||||
// setMouseTracking(true);
|
||||
// setFocusPolicy(Qt::WheelFocus);
|
||||
// setScene(new QGraphicsScene());
|
||||
// setInteractive(true);
|
||||
setIcon(QIcon("://icons/qglview.png"));
|
||||
deleting_ = false;
|
||||
timer = 0;
|
||||
need_init_ = is_first_draw = true;
|
||||
objects_.is_root = true;
|
||||
objects_.view_ = this;
|
||||
backColor_ = Qt::darkGray;
|
||||
hoverHaloColor_ = QColor(195, 140, 255, 96);
|
||||
selectionHaloColor_ = QColor(175, 255, 140);
|
||||
ambientColor_ = QColor(10, 10, 10);
|
||||
lastPos = QPoint(-1, -1);
|
||||
lineWidth_ = 1.;
|
||||
max_anisotropic = 1;
|
||||
max_texture_chanels = 8;
|
||||
cameraOrbit_ = lightEnabled_ = true;
|
||||
shaders_supported = selecting_ = customMouseMove_ = false;
|
||||
sel_button = Qt::LeftButton;
|
||||
sel_mod = Qt::NoModifier;
|
||||
renderer_ = nullptr;
|
||||
fps_cnt = 0;
|
||||
fps_tm = fps_ = 0.;
|
||||
sel_obj = hov_obj = nullptr;
|
||||
fogDensity_ = fogEnd_ = 1.;
|
||||
fogStart_ = 0.;
|
||||
fogMode_ = Exp;
|
||||
hoverHaloFill_ = 0.333f;
|
||||
selectionHaloFill_ = 0.5f;
|
||||
//lmode = Simple;
|
||||
shader_select = shader_halo = nullptr;
|
||||
setFeature(qglMSAA, false);
|
||||
setFeature(qglFXAA, false);
|
||||
setFeature(qglLinearFiltering, true);
|
||||
setFeature(qglAnisotropicLevel, 8);
|
||||
setFeature(qglHDR, false);
|
||||
setFeature(qglEyeAccomodationEnabled, false);
|
||||
setFeature(qglEyeAccomodationTime, 16.);
|
||||
setFeature(qglEyeAccomodationMaxSpeed, 0.2);
|
||||
setFeature(qglBloomEnabled, false);
|
||||
setFeature(qglBloomThreshold, 0.9);
|
||||
setFeature(qglBloomFactor, 1.);
|
||||
setFeature(qglBloomRadius, 8);
|
||||
setFeature(qglMotionBlurEnabled, false);
|
||||
setFeature(qglMotionBlurFactor, 1.);
|
||||
setFeature(qglMotionBlurSteps, 8);
|
||||
setFeature(qglShadowsEnabled, false);
|
||||
setFeature(qglShadowsMapSize, 512);
|
||||
setFeature(qglShadowsSoftEnabled, true);
|
||||
setFeature(qglReflectionsEnabled, false);
|
||||
setFeature(qglReflectionsBlur, true);
|
||||
setFeature(qglSSAOEnabled, false);
|
||||
setFeature(qglSSAORadius, 5);
|
||||
setFeature(qglDepthOfFieldEnabled, false);
|
||||
setFeature(qglDepthOfFieldAutoFocusEnabled, true);
|
||||
setFeature(qglDepthOfFieldAutoFocusSpeed, 0.1);
|
||||
setFeature(qglDepthOfFieldFocus, 1.);
|
||||
setFeature(qglDepthOfFieldDiaphragm, 8.);
|
||||
mouse_first = mouseSelect_ = hoverHalo_ = selectionHalo_ = true;
|
||||
mouseRotate_ = true;
|
||||
fogEnabled_ = is_init = grabMouse_ = shaders_bind = changed_ = false;
|
||||
rmode = GLObjectBase::Fill;
|
||||
sel_mode = QGLView::SingleSelection;
|
||||
// sel_pen = QPen(Qt::black, 1, Qt::DashLine);
|
||||
// sel_brush = QBrush(QColor(170, 100, 255, 120));
|
||||
camera()->setAim(QVector3D());
|
||||
camera()->setPos(QVector3D(2, 2, 2));
|
||||
camera()->setName("Camera");
|
||||
addObject(camera());
|
||||
emit cameraPosChanged(camera()->pos());
|
||||
//camera().aim_ = camera().pos_;
|
||||
ktm_.restart();
|
||||
}
|
||||
|
||||
|
||||
QGLView::~QGLView() {
|
||||
stop();
|
||||
if (shader_select) delete shader_select;
|
||||
if (shader_halo) delete shader_halo;
|
||||
deleting_ = true;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::stop() {
|
||||
if (timer) killTimer(timer);
|
||||
timer = 0;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::start(float freq) {
|
||||
stop();
|
||||
timer = startTimer(freq <= 0.f ? 0 : int(1000.f / freq));
|
||||
}
|
||||
|
||||
|
||||
GLRendererBase * QGLView::renderer() {
|
||||
return renderer_;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::setRenderer(GLRendererBase * r, GLRendererBase ** prev) {
|
||||
if (prev != nullptr) *prev = renderer_;
|
||||
renderer_ = r;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::addObject(GLObjectBase * o) {
|
||||
objects_.addChild(o);
|
||||
o->setView(this);
|
||||
collectLights();
|
||||
QList<GLObjectBase*> cl = o->children(true);
|
||||
cl << o;
|
||||
foreach (GLObjectBase * i, cl) {
|
||||
emit objectAdded(i);
|
||||
}
|
||||
if (is_init) {
|
||||
o->init();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int QGLView::objectsCount(bool all) {
|
||||
if (!all) return objects_.childCount();
|
||||
int cnt = 0;
|
||||
objectsCountInternal(&cnt, &objects_);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::removeObject(GLObjectBase * o, bool inChildren) {
|
||||
o->setView(nullptr);
|
||||
if (inChildren)
|
||||
removeObjectInternal(o, &objects_);
|
||||
else
|
||||
objects_.removeChild(o);
|
||||
objectDeleted(o);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::removeObject(GLObjectBase & o, bool inChildren) {
|
||||
removeObject(&o, inChildren);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::clearObjects(bool deleteAll) {
|
||||
removeObject(camera_);
|
||||
objects_.clearChildren(deleteAll);
|
||||
addObject(camera());
|
||||
selectObject(nullptr);
|
||||
hov_obj = nullptr;
|
||||
}
|
||||
|
||||
|
||||
QList<GLObjectBase *> QGLView::objects(bool all) {
|
||||
return objects_.children(all);
|
||||
}
|
||||
|
||||
|
||||
int QGLView::lightsCount() const {
|
||||
return lights_.size();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::removeLight(int index) {
|
||||
removeObject(lights_.at(index));
|
||||
lights_.removeAt(index);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::removeLight(Light * l) {
|
||||
foreach (Light * i, lights_)
|
||||
if (i == l) removeObject(i);
|
||||
lights_.removeAll(l);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::clearLights(bool deleteAll) {
|
||||
if (deleteAll)
|
||||
foreach (Light * i, lights_) delete i;
|
||||
lights_.clear();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::addTexture(const QString & path) {
|
||||
textures_manager->addTexture(path);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::addAnimation(const QString & dir, const QString & name) {
|
||||
textures_manager->addAnimation(dir, name);
|
||||
}
|
||||
|
||||
|
||||
Light * QGLView::light(int index) {
|
||||
return lights_[index];
|
||||
}
|
||||
|
||||
|
||||
Light * QGLView::light(const QString & name) {
|
||||
foreach (Light * i, lights_)
|
||||
if (i->name_ == name) return i;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::selectObject(GLObjectBase * o) {
|
||||
if (o == sel_obj) return;
|
||||
GLObjectBase * pso = sel_obj;
|
||||
sel_obj = o;
|
||||
emit selectionChanged(sel_obj, pso);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::resizeEvent(QResizeEvent * e) {
|
||||
renderLater();
|
||||
}
|
||||
|
||||
void QGLView::timerEvent(QTimerEvent *) {
|
||||
renderNow();
|
||||
if (ktm_.elapsed() < QApplication::keyboardInputInterval()) return;
|
||||
Qt::KeyboardModifiers km = QApplication::keyboardModifiers();
|
||||
foreach (int i, keys_)
|
||||
emit keyEvent((Qt::Key)i, km);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::render() {
|
||||
if (!isVisible()) return;
|
||||
resizeGL(width(), height());
|
||||
QRect g_rect(QPoint(), size());
|
||||
emit glBeforePaint();
|
||||
//qDebug() << "paintGL";
|
||||
//QMutexLocker ml_v(&v_mutex);
|
||||
glEnable(GL_CULL_FACE);
|
||||
//glDisable(GL_CULL_FACE);
|
||||
camera()->apply(aspect);
|
||||
//objects_.preparePos(camera());
|
||||
start_rp.cam_offset_matrix = camera()->offsetMatrix();
|
||||
start_rp.proj_matrix = getGLMatrix(GL_PROJECTION_MATRIX);
|
||||
start_rp.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX);
|
||||
//objects_.buildTransform();
|
||||
|
||||
/// Selection detect
|
||||
//glClearFramebuffer(QColor(100, 0, 0, 0));
|
||||
if (mouseSelect_) {
|
||||
glReleaseTextures();
|
||||
glEnableDepth();
|
||||
glDisable(GL_TEXTURE_1D);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisable(GL_TEXTURE_CUBE_MAP);
|
||||
glDisable(GL_MULTISAMPLE);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glDisable(GL_RESCALE_NORMAL);
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
fbo_selection.bind();
|
||||
fbo_selection.setWriteBuffer(0);
|
||||
glClearFramebuffer(QColor(0, 0, 0, 0));
|
||||
if (shaders_supported && shader_select->isLinked()) shader_select->bind();
|
||||
renderSelection();
|
||||
if (shaders_supported && shader_select->isLinked()) shader_select->release();
|
||||
uchar cgid[4] = {0, 0, 0, 0};
|
||||
uint iid = 0;
|
||||
GLObjectBase * so = nullptr;
|
||||
if (!g_rect.contains(lastPos)) {
|
||||
if (hov_obj != nullptr) {
|
||||
hov_obj = nullptr;
|
||||
emit hoverChanged(nullptr, hov_obj);
|
||||
}
|
||||
} else {
|
||||
glReadPixels(lastPos.x(), height() - lastPos.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, cgid);
|
||||
iid = uint(cgid[0] << 24) | uint(cgid[1] << 16) | uint(cgid[2] << 8) | cgid[3];
|
||||
so = ids.value(iid, nullptr);
|
||||
//qDebug() <<cgid[0]<<cgid[1]<<cgid[2]<<cgid[3]<< iid;
|
||||
if (so != hov_obj) {
|
||||
emit hoverChanged(so, hov_obj);
|
||||
hov_obj = so;
|
||||
}
|
||||
//if (so != 0) qDebug() << sel_obj->name() << cgid[3];
|
||||
}
|
||||
if (selectionHalo_ && sel_obj) {
|
||||
fbo_selection.setWriteBuffer(2);
|
||||
renderHalo(sel_obj, qHash((quint64)sel_obj), selectionHaloColor_, selectionHaloFill_);
|
||||
}
|
||||
if (hoverHalo_ && hov_obj) {
|
||||
fbo_selection.setWriteBuffer(1);
|
||||
renderHalo(hov_obj, iid, hoverHaloColor_, hoverHaloFill_);
|
||||
}
|
||||
fbo_selection.release();
|
||||
glEnableDepth();
|
||||
/*glEnableClientState(GL_NORMAL_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);*/
|
||||
}
|
||||
|
||||
camera()->apply(aspect);
|
||||
start_rp.cam_offset_matrix = camera()->offsetMatrix();
|
||||
cur_mvpm = start_rp.proj_matrix * start_rp.view_matrix * start_rp.cam_offset_matrix;
|
||||
//objects_.preparePos(camera());
|
||||
|
||||
static GLRendererBase * prev_rend = nullptr;
|
||||
glShadeModel(GL_SMOOTH);
|
||||
if (prev_rend != renderer_) {
|
||||
prev_rend = renderer_;
|
||||
if (renderer_ != nullptr) {
|
||||
renderer_->init(width(), height());
|
||||
renderer_->resize(width(), height());
|
||||
renderer_->reloadShaders();
|
||||
}
|
||||
}
|
||||
emit glBeginPaint();
|
||||
if (renderer_ != nullptr) {
|
||||
renderer_->rp.prepare();
|
||||
renderer_->prepareScene();
|
||||
renderer_->renderScene();
|
||||
}
|
||||
emit glPainting();
|
||||
glUseProgram(0);
|
||||
if (selectionHalo_ || hoverHalo_) {
|
||||
glReleaseTextures();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
//glClearFramebuffer(Qt::black, false);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_TEXTURE_CUBE_MAP);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisableDepth();
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
if (selectionHalo_ && sel_obj) {
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture(2));
|
||||
//qDebug() << "draw sel";
|
||||
glDrawQuad();
|
||||
}
|
||||
if (hoverHalo_ && hov_obj) {
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture(1));
|
||||
//qDebug() << "draw hover";
|
||||
//glBindTexture(GL_TEXTURE_2D, textures_manager->loadTexture("batt_pn.jpg"));
|
||||
glDrawQuad();
|
||||
}
|
||||
}
|
||||
|
||||
glResetAllTransforms();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glUseProgram(0);
|
||||
|
||||
//glDisable(GL_BLEND);
|
||||
//glDisable(GL_LIGHTING);
|
||||
//glActiveTexture(GL_TEXTURE0);
|
||||
//glBindTexture(GL_TEXTURE_2D, textures_manager->loadTexture("batt_pn.jpg"));
|
||||
//glDrawQuad();
|
||||
|
||||
emit glEndPaint();
|
||||
|
||||
/*releaseShaders();
|
||||
glActiveTextureChannel(0);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glColor4f(0.3, 0.5, 0.8, 0.5);
|
||||
glResetAllTransforms();
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0.f, 0.f); glVertex2f(-1.f, -1.f);
|
||||
glTexCoord2f(1.f, 0.f); glVertex2f(1.f, -1.);
|
||||
glTexCoord2f(1.f, 1.f); glVertex2f(1.f, 1.f);
|
||||
glTexCoord2f(0.f, 1.f); glVertex2f(-1.f, 1.f);
|
||||
glEnd();*/
|
||||
/*
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glDisable(GL_LIGHTING);
|
||||
glActiveTextureChannel(0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo->texture());
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(1.f, 1.f, 1.f);
|
||||
glTexCoord2f(0.f, 0.f); glVertex2f(-1.f, -1.f);
|
||||
glTexCoord2f(0.f, 1.f); glVertex2f(-1.f, 1.f);
|
||||
glTexCoord2f(1.f, 1.f); glVertex2f(1.f, 1.f);
|
||||
glTexCoord2f(1.f, 0.f); glVertex2f(1.f, -1.);
|
||||
glEnd();
|
||||
glEnable(GL_DEPTH_TEST);*/
|
||||
fps_tm += time.elapsed();
|
||||
time.restart();
|
||||
fps_cnt++;
|
||||
if (fps_tm < 1000.) return;
|
||||
fps_ = fps_cnt / fps_tm * 1000.;
|
||||
fps_tm = 0.;
|
||||
fps_cnt = 0;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::initialize() {
|
||||
//initializeOpenGLFunctions();
|
||||
glEnable(GL_TEXTURE_MAX_ANISOTROPY_EXT);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glEnableDepth();
|
||||
glEnable(GL_CULL_FACE);
|
||||
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
|
||||
glActiveTexture(GL_TEXTURE0 + 3);
|
||||
glEnable(GL_TEXTURE_GEN_S);
|
||||
glEnable(GL_TEXTURE_GEN_T);
|
||||
glEnable(GL_TEXTURE_GEN_R);
|
||||
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glCullFace(GL_BACK);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glColorMaterial(GL_FRONT, GL_DIFFUSE);
|
||||
|
||||
textures_manager->loadTextures();
|
||||
objects_.initInternal();
|
||||
checkCaps();
|
||||
|
||||
shader_select = new QOpenGLShaderProgram(context());
|
||||
shader_halo = new QOpenGLShaderProgram(context());
|
||||
reloadThisShaders();
|
||||
is_init = true;
|
||||
//resizeGL(width(), height());
|
||||
need_init_ = false;
|
||||
emit glInitializeDone();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::renderHalo(const GLObjectBase * obj, const uint iid, const QColor & color, const float & fill) {
|
||||
if (!shaders_supported) return;
|
||||
if (!shader_halo) return;
|
||||
if (!shader_halo->isLinked()) return;
|
||||
if (obj) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture());
|
||||
shader_halo->bind();
|
||||
shader_halo->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
|
||||
shader_halo->setUniformValue("t0", 0);
|
||||
shader_halo->setUniformValue("dt", QVector2D(1.f / width(), 1.f / height()));
|
||||
shader_halo->setUniformValue("selected", QVector4D(float((iid >> 24) & 0xFF) / 255.f,
|
||||
float((iid >> 16) & 0xFF) / 255.f,
|
||||
float((iid >> 8) & 0xFF) / 255.f,
|
||||
float( iid & 0xFF) / 255.f));
|
||||
shader_halo->setUniformValue("color", color);
|
||||
shader_halo->setUniformValue("fill", GLfloat(fill));
|
||||
//qDebug() << "render halo" << iid << shader_halo->log() << shader_halo->programId();
|
||||
glDisableDepth();
|
||||
//glClearFramebuffer(color);
|
||||
glDrawQuad(shader_halo);
|
||||
glDepthMask(GL_TRUE);
|
||||
//glFlush();
|
||||
shader_halo->release();
|
||||
} else {
|
||||
glClearFramebuffer(Qt::black, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QGLView::renderSelection() {
|
||||
// cid = 1;
|
||||
ids.clear();
|
||||
if (shaders_supported) {
|
||||
if (shader_select) {
|
||||
if (shader_select->isLinked()) {
|
||||
sh_id_loc = shader_select->uniformLocation("id");
|
||||
shader_select->setUniformValue("z_far", GLfloat(depthEnd()));
|
||||
shader_select->setUniformValue("z_near", GLfloat(depthStart()));
|
||||
}
|
||||
}
|
||||
}
|
||||
//qDebug() << sh_id_loc;
|
||||
start_rp.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX);
|
||||
glPushMatrix();
|
||||
renderSingleSelection(objects_);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::renderSingleSelection(GLObjectBase & o) {
|
||||
if (!o.isInit()) {
|
||||
o.init();
|
||||
o.loadTextures();
|
||||
}
|
||||
if (!o.visible_ || !o.select_) return;
|
||||
QMatrix4x4 curview = start_rp.view_matrix * start_rp.cam_offset_matrix * o.itransform_;
|
||||
uint id = qHash((quint64)&o);
|
||||
ids.insert(id, &o);
|
||||
glLineWidth(o.line_width > 0.f ? o.line_width : lineWidth_);
|
||||
glPointSize(o.line_width > 0.f ? o.line_width : lineWidth_);
|
||||
if (shaders_supported){
|
||||
if (shader_select) {
|
||||
if (shader_select->isLinked()) {
|
||||
setUniformMatrices(shader_select, start_rp.proj_matrix, curview);
|
||||
shader_select->setUniformValue(sh_id_loc, QVector4D(float((id >> 24) & 0xFF) / 255.f,
|
||||
float((id >> 16) & 0xFF) / 255.f,
|
||||
float((id >> 8) & 0xFF) / 255.f,
|
||||
float(id & 0xFF) / 255.f));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
setGLMatrix(curview);
|
||||
glColor4f(float((id >> 24) & 0xFF) / 255.f,
|
||||
float((id >> 16) & 0xFF) / 255.f,
|
||||
float((id >> 8) & 0xFF) / 255.f,
|
||||
float(id & 0xFF) / 255.f);
|
||||
}
|
||||
//qDebug() << o.name() << "assign to" << sh_id_loc << cid;
|
||||
//glColor4f(float((cid >> 24) & 0xFF) / 255.f, float((cid >> 16) & 0xFF) / 255.f, float((cid >> 8) & 0xFF) / 255.f, float(cid & 0xFF) / 255.f);
|
||||
// ++cid;
|
||||
o.draw(nullptr, true);
|
||||
foreach (GLObjectBase * i, o.children_)
|
||||
renderSingleSelection(*i);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::collectLights() {
|
||||
lights_.clear();
|
||||
collectObjectLights(&objects_);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::objectDeleted(GLObjectBase * o) {
|
||||
if (deleting_) return;
|
||||
//qDebug() << "del" << o;
|
||||
if (sel_obj == o) selectObject(nullptr);
|
||||
if (hov_obj == o) hov_obj = nullptr;
|
||||
collectLights();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::collectObjectLights(GLObjectBase * o) {
|
||||
if (o->type_ == GLObjectBase::glLight) {
|
||||
lights_ << globject_cast<Light * >(o);
|
||||
o->view_ = this;
|
||||
}
|
||||
foreach (GLObjectBase * i, o->children())
|
||||
collectObjectLights(i);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::objectsCountInternal(int * cnt, GLObjectBase * where) {
|
||||
++(*cnt);
|
||||
foreach (GLObjectBase * i, where->children_)
|
||||
objectsCountInternal(cnt, i);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::removeObjectInternal(GLObjectBase * o, GLObjectBase * where) {
|
||||
foreach (GLObjectBase * i, where->children_) {
|
||||
if (o == i)
|
||||
where->removeChild(i);
|
||||
else
|
||||
removeObjectInternal(o, i);
|
||||
objectDeleted(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QGLView::checkCaps() {
|
||||
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropic);
|
||||
//glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_texture_chanels);
|
||||
//qDebug() << max_texture_chanels;
|
||||
//qDebug() << max_texture_chanels;
|
||||
shaders_supported = QOpenGLShaderProgram::hasOpenGLShaderPrograms();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::reloadThisShaders() {
|
||||
if (!shaders_supported) return;
|
||||
loadShaders(shader_select, "selection", "://shaders");
|
||||
loadShaders(shader_halo, "selection_halo", "://shaders");
|
||||
//loadShaders(shader_rope, "rope", "://shaders");
|
||||
}
|
||||
|
||||
void QGLView::glReleaseTextures(int channels) {
|
||||
for (int i = channels - 1; i >= 0; --i) {
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QGLView::applyFog() {
|
||||
GLfloat fog_col[4] = {float(fogColor_.redF()), float(fogColor_.greenF()), float(fogColor_.blueF()), .0f};
|
||||
if (fogEnabled_) {
|
||||
glEnable(GL_FOG);
|
||||
glFogf(GL_FOG_DENSITY, fogDensity_);
|
||||
glFogf(GL_FOG_START, fogStart_);
|
||||
glFogf(GL_FOG_END, fogEnd_);
|
||||
glFogi(GL_FOG_MODE, fogMode_);
|
||||
fog_col[0] = fogColor_.redF();
|
||||
fog_col[1] = fogColor_.greenF();
|
||||
fog_col[2] = fogColor_.blueF();
|
||||
glFogfv(GL_FOG_COLOR, fog_col);
|
||||
} else glDisable(GL_FOG);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::resizeGL(int width, int height) {
|
||||
if (!is_init) return;
|
||||
if (width <= 0 || height <= 0) return;
|
||||
if (prev_size == QSize(width, height)) return;
|
||||
prev_size = QSize(width, height);
|
||||
aspect = float(width) / float(height);
|
||||
if (renderer_) renderer_->resize(width, height);
|
||||
mouse_first = true;
|
||||
//qDebug() << "resize" << width << height;
|
||||
fbo_selection.resize(width, height);
|
||||
iaspect = (aspect == 0.f) ? 0. : 1 / aspect;
|
||||
glViewport(0, 0, width, height);
|
||||
emit glResize(width, height);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::mouseReleaseEvent(QMouseEvent * e) {
|
||||
// qDebug() << "mouseReleaseEvent" << e << isActive();
|
||||
// QGraphicsView::mouseReleaseEvent(e);
|
||||
//setCursor(QCursor(Qt::ArrowCursor));
|
||||
selecting_ = false;
|
||||
if (mouseSelect_ && e->button() == Qt::LeftButton) {
|
||||
if ((lastPos - downPos).manhattanLength() < 8) {
|
||||
if (sel_obj != hov_obj)
|
||||
selectObject(hov_obj);
|
||||
}
|
||||
}
|
||||
emit glMouseReleaseEvent(e);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::mousePressEvent(QMouseEvent * e) {
|
||||
// qDebug() << "mousePressEvent" << e << isActive();
|
||||
// QGraphicsView::mousePressEvent(e);
|
||||
// mouseThis_ = (scene()->itemAt(mapToScene(e->pos()) , QTransform() ) == 0);
|
||||
selecting_ = false;
|
||||
if (!QRect(QPoint(), size()).contains(e->pos())) return;
|
||||
/// TODO select by rect
|
||||
//if (e->button() == sel_button && e->modifiers() == sel_mod)
|
||||
// selecting_ = true;
|
||||
lastPos = e->pos();
|
||||
downPos = lastPos;
|
||||
//qDebug() << mouseThis_;
|
||||
emit glMousePressEvent(e);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::mouseMoveEvent(QMouseEvent * e) {
|
||||
// qDebug() << "mouseMoveEvent" << e << isActive();
|
||||
// QGraphicsView::mouseMoveEvent(e);
|
||||
//lastPos = e->pos();
|
||||
if (selecting_) {
|
||||
return;
|
||||
}
|
||||
// if (!QRect(QPoint(), size()).contains(e->pos())) return;
|
||||
//if (scene()->itemAt(mapToScene(e->pos())) != 0) return;
|
||||
///qDebug() << e->x() << e->y();
|
||||
QRect g_rect(QPoint(), size());
|
||||
if (mouseRotate_) {
|
||||
float dx = e->x() - lastPos.x();
|
||||
float dy = e->y() - lastPos.y();
|
||||
if (e->buttons() & Qt::LeftButton) {
|
||||
//camera().angle_z += dx / 4.;
|
||||
//camera().angle_xy += dy / 4.;
|
||||
if (cameraOrbit_) {
|
||||
camera()->orbitZ(dx / 4.f);
|
||||
camera()->orbitXY(dy / 4.f);
|
||||
} else {
|
||||
camera()->rotateZ(dx / 4.f);
|
||||
camera()->rotateXY(dy / 4.f);
|
||||
}
|
||||
emit cameraPosChanged(camera()->pos());
|
||||
} else if (e->buttons() & Qt::RightButton) {
|
||||
float ad = camera()->distance();
|
||||
camera()->moveLeft(dx / 1000.f * ad);
|
||||
camera()->moveUp(dy / 1000.f * ad);
|
||||
//camera().pos.setX(camera().pos.x() + camera().pos.z() * dx / 500.);
|
||||
//camera().pos.setY(camera().pos.y() - camera().pos.z() * dy / 500.);
|
||||
emit cameraPosChanged(camera()->pos());
|
||||
}
|
||||
//lights[0]->pos_ = camera().pos();
|
||||
}
|
||||
if (customMouseMove_) emit customMouseMoveEvent(e->pos(), lastPos, e->buttons());
|
||||
lastPos = e->pos();
|
||||
if (grabMouse_) {
|
||||
//if (!isrunning) return;
|
||||
QCursor::setPos(mapToGlobal(QRect(QPoint(), size()).center()));
|
||||
static bool mouse_sec = false;
|
||||
if (mouse_sec) {
|
||||
mouse_sec = false;
|
||||
return;
|
||||
}
|
||||
if (mouse_first) {
|
||||
mouse_first = false;
|
||||
mouse_sec = true;
|
||||
//qDebug() << "first" << e->pos();
|
||||
return;
|
||||
}
|
||||
lastPos = g_rect.center();
|
||||
int dx = e->x() - lastPos.x();
|
||||
int dy = e->y() - lastPos.y();
|
||||
emit glMouseMoveEvent(new QMouseEvent(QEvent::MouseMove, QPoint(dx, dy), e->button(), e->buttons(), e->modifiers()));
|
||||
return;
|
||||
}
|
||||
emit glMouseMoveEvent(e);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::wheelEvent(QWheelEvent * e) {
|
||||
if (mouseRotate_) {
|
||||
if (e->delta() > 0) camera()->flyCloser(0.1f); //camera().pos.setZ(camera().pos.z() - 0.1 * camera().pos.z());
|
||||
if (e->delta() < 0) camera()->flyFarer(0.1f); //camera().pos.setZ(camera().pos.z() + 0.1 * camera().pos.z());
|
||||
emit cameraPosChanged(camera()->pos());
|
||||
}
|
||||
emit glWheelEvent(e);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::leaveEvent(QEvent * ) {
|
||||
lastPos = QPoint(-1, -1);
|
||||
//qDebug() << lastPos;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::keyPressEvent(QKeyEvent * e) {
|
||||
emit glKeyPressEvent(e);
|
||||
if (e->key() > 0) keys_.insert(e->key());
|
||||
if (e->key() == Qt::Key_F11) {
|
||||
emit doubleClick();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QGLView::keyReleaseEvent(QKeyEvent * e) {
|
||||
emit glKeyReleaseEvent(e);
|
||||
keys_.remove(e->key());
|
||||
}
|
||||
|
||||
|
||||
void QGLView::focusOutEvent(QFocusEvent *) {
|
||||
keys_.clear();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::mouseDoubleClickEvent(QMouseEvent * e) {
|
||||
if (e->buttons().testFlag(Qt::MidButton))
|
||||
emit doubleClick();
|
||||
}
|
||||
|
||||
|
||||
QByteArray QGLView::saveCamera() {
|
||||
ChunkStream cs;
|
||||
const Camera * c = camera();
|
||||
cs.add(1, c->posX());
|
||||
cs.add(2, c->posY());
|
||||
cs.add(3, c->posZ());
|
||||
cs.add(4, c->aim().x());
|
||||
cs.add(5, c->aim().y());
|
||||
cs.add(6, c->aim().z());
|
||||
cs.add(7, c->angleZ());
|
||||
cs.add(8, c->angleXY());
|
||||
cs.add(9, c->angleRoll());
|
||||
cs.add(10, c->FOV());
|
||||
return cs.data();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::restoreCamera(const QByteArray &ba) {
|
||||
if (ba.isEmpty()) return;
|
||||
ChunkStream cs(ba);
|
||||
QVector3D pos, aim, ang;
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1: pos.setX(cs.getData<float>()); break;
|
||||
case 2: pos.setY(cs.getData<float>()); break;
|
||||
case 3: pos.setZ(cs.getData<float>()); break;
|
||||
case 4: aim.setX(cs.getData<float>()); break;
|
||||
case 5: aim.setY(cs.getData<float>()); break;
|
||||
case 6: aim.setZ(cs.getData<float>()); break;
|
||||
case 7: ang.setZ(cs.getData<float>()); break;
|
||||
case 8: ang.setY(cs.getData<float>()); break;
|
||||
case 9: ang.setX(cs.getData<float>()); break;
|
||||
case 10: setFOV(cs.getData<float>()); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
camera()->setPos(pos);
|
||||
camera()->setAim(aim);
|
||||
camera()->setAngles(ang);
|
||||
}
|
||||
|
||||
|
||||
QByteArray QGLView::saveFeatures() {
|
||||
QByteArray ba;
|
||||
QDataStream ds(&ba, QIODevice::WriteOnly);
|
||||
ds << features_;
|
||||
return ba;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::restoreFeatures(const QByteArray & ba) {
|
||||
QHash<int, QVariant> f;
|
||||
QDataStream ds(ba);
|
||||
ds >> f;
|
||||
features_ = f;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,301 +1,301 @@
|
||||
/*
|
||||
QGLView
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QGLVIEW_H
|
||||
#define QGLVIEW_H
|
||||
|
||||
#include "openglwindow.h"
|
||||
#include "glframebuffer.h"
|
||||
#include "glprimitives.h"
|
||||
#include "glparticles_system.h"
|
||||
#include "glrendererbase.h"
|
||||
#include <QTime>
|
||||
|
||||
|
||||
class QGLView: public OpenGLWindow, public QGLViewBase
|
||||
{
|
||||
friend class GLRendererBase;
|
||||
friend class GLObjectBase;
|
||||
Q_OBJECT
|
||||
Q_PROPERTY (QColor backColor READ backColor WRITE setBackColor)
|
||||
Q_PROPERTY (float lineWidth READ lineWidth WRITE setLineWidth)
|
||||
Q_PROPERTY (float FOV READ FOV WRITE setFOV)
|
||||
Q_PROPERTY (float depthStart READ depthStart WRITE setDepthStart)
|
||||
Q_PROPERTY (float depthEnd READ depthEnd WRITE setDepthEnd)
|
||||
Q_PROPERTY (QColor ambientColor READ ambientColor WRITE setAmbientColor)
|
||||
Q_PROPERTY (QColor fogColor READ fogColor WRITE setFogColor)
|
||||
Q_PROPERTY (float fogDensity READ fogDensity WRITE setFogDensity)
|
||||
Q_PROPERTY (float fogStart READ fogStart WRITE setFogStart)
|
||||
Q_PROPERTY (float fogEnd READ fogEnd WRITE setFogEnd)
|
||||
Q_PROPERTY (FogMode fogMode READ fogMode WRITE setFogMode)
|
||||
Q_PROPERTY (bool fogEnabled READ isFogEnabled WRITE setFogEnabled)
|
||||
Q_PROPERTY (int renderMode READ renderMode WRITE setRenderMode)
|
||||
Q_PROPERTY (bool grabMouse READ isGrabMouseEnabled WRITE setGrabMouseEnabled)
|
||||
Q_PROPERTY (bool mouseRotate READ isMouseRotateEnabled WRITE setMouseRotateEnabled)
|
||||
Q_PROPERTY (bool mouseSelection READ isMouseSelectionEnabled WRITE setMouseSelectionEnabled)
|
||||
Q_PROPERTY (bool cameraOrbit READ isCameraOrbit WRITE setCameraOrbit)
|
||||
Q_PROPERTY (bool hoverHalo READ isHoverHaloEnabled WRITE setHoverHaloEnabled)
|
||||
Q_PROPERTY (QColor hoverHaloColor READ hoverHaloColor WRITE setHoverHaloColor)
|
||||
Q_PROPERTY (float hoverHaloFillAlpha READ hoverHaloFillAlpha WRITE setHoverHaloFillAlpha)
|
||||
Q_PROPERTY (bool selectionHalo READ isSelectionHaloEnabled WRITE setSelectionHaloEnabled)
|
||||
Q_PROPERTY (QColor selectionHaloColor READ selectionHaloColor WRITE setSelectionHaloColor)
|
||||
Q_PROPERTY (float selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha)
|
||||
Q_PROPERTY (Qt::MouseButton selectionButton READ selectionButton WRITE setSelectionButton)
|
||||
Q_PROPERTY (Qt::KeyboardModifier selectionModifier READ selectionModifier WRITE setSelectionModifier)
|
||||
Q_PROPERTY (SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
|
||||
|
||||
public:
|
||||
QGLView();
|
||||
virtual ~QGLView();
|
||||
|
||||
enum FogMode {Linear = GL_LINEAR, Exp = GL_EXP, Exp2 = GL_EXP2};
|
||||
enum SelectionMode {NoSelection, SingleSelection, MultiSelection};
|
||||
enum Feature {
|
||||
qglMSAA,
|
||||
qglFXAA,
|
||||
qglLinearFiltering,
|
||||
qglAnisotropicLevel,
|
||||
qglHDR,
|
||||
qglEyeAccomodationEnabled,
|
||||
qglEyeAccomodationTime,
|
||||
qglEyeAccomodationMaxSpeed,
|
||||
qglBloomEnabled,
|
||||
qglBloomThreshold,
|
||||
qglBloomFactor,
|
||||
qglBloomRadius,
|
||||
qglMotionBlurEnabled,
|
||||
qglMotionBlurFactor,
|
||||
qglMotionBlurSteps,
|
||||
qglShadowsEnabled,
|
||||
qglShadowsMapSize,
|
||||
qglShadowsSoftEnabled,
|
||||
qglReflectionsEnabled,
|
||||
qglReflectionsBlur,
|
||||
qglSSAOEnabled,
|
||||
qglSSAORadius,
|
||||
qglDepthOfFieldEnabled,
|
||||
qglDepthOfFieldAutoFocusEnabled,
|
||||
qglDepthOfFieldAutoFocusSpeed,
|
||||
qglDepthOfFieldFocus,
|
||||
qglDepthOfFieldDiaphragm
|
||||
};
|
||||
|
||||
Q_ENUMS (FogMode)
|
||||
Q_ENUMS (SelectionMode)
|
||||
|
||||
void stop();
|
||||
void start(float freq = 60.);
|
||||
|
||||
GLRendererBase * renderer();
|
||||
void setRenderer(GLRendererBase * r, GLRendererBase ** prev = nullptr);
|
||||
|
||||
QColor backColor() const {return backColor_;}
|
||||
float lineWidth() const {return lineWidth_;}
|
||||
float FOV() const {return camera()->fov_;}
|
||||
float depthStart() const {return camera()->depth_start;}
|
||||
float depthEnd() const {return camera()->depth_end;}
|
||||
float currentFPS() const {return fps_;}
|
||||
int maxAnisotropicLevel() const {return max_anisotropic;}
|
||||
|
||||
QColor ambientColor() const {return ambientColor_;}
|
||||
QColor fogColor() const {return fogColor_;}
|
||||
float fogDensity() const {return fogDensity_;}
|
||||
float fogStart() const {return fogStart_;}
|
||||
float fogEnd() const {return fogEnd_;}
|
||||
FogMode fogMode() const {return fogMode_;}
|
||||
bool isFogEnabled() const {return fogEnabled_;}
|
||||
bool isLightEnabled() const {return lightEnabled_;}
|
||||
bool isGrabMouseEnabled() const {return grabMouse_;}
|
||||
bool isMouseRotateEnabled() const {return mouseRotate_;}
|
||||
bool isMouseSelectionEnabled() const {return mouseSelect_;}
|
||||
bool isCameraOrbit() const {return cameraOrbit_;}
|
||||
bool isHoverHaloEnabled() const {return hoverHalo_;}
|
||||
QColor hoverHaloColor() const {return hoverHaloColor_;}
|
||||
float hoverHaloFillAlpha() const {return hoverHaloFill_;}
|
||||
bool isSelectionHaloEnabled() const {return selectionHalo_;}
|
||||
QColor selectionHaloColor() const {return selectionHaloColor_;}
|
||||
float selectionHaloFillAlpha() const {return selectionHaloFill_;}
|
||||
|
||||
QVariant feature(Feature f) const {return features_.value(int(f));}
|
||||
QVariant setFeature(Feature f, const QVariant & value) {QVariant ret = features_.value(int(f)); features_[int(f)] = value; return ret;}
|
||||
bool isFeatureEnabled(Feature f) const {return features_[int(f)].toBool();}
|
||||
|
||||
int renderMode() const {return (int)rmode;}
|
||||
void setRenderMode(int mode) {rmode = (GLObjectBase::RenderMode)mode;}
|
||||
|
||||
void addObject(GLObjectBase * o);
|
||||
// void addObject(GLObjectBase & o) {addObject(&o);}
|
||||
int objectsCount(bool all = false);
|
||||
void removeObject(GLObjectBase * o, bool inChildren = true);
|
||||
void removeObject(GLObjectBase & o, bool inChildren = true);
|
||||
void clearObjects(bool deleteAll = false);
|
||||
QList<GLObjectBase * > objects(bool all = false);
|
||||
|
||||
int lightsCount() const;
|
||||
void removeLight(int index);
|
||||
void removeLight(Light * l);
|
||||
void clearLights(bool deleteAll = false);
|
||||
QList<Light * > lights() {return lights_;}
|
||||
|
||||
void addTexture(const QString & path);
|
||||
void addAnimation(const QString & dir, const QString & name);
|
||||
|
||||
const GLObjectBase & rootObject() {return objects_;}
|
||||
GLObjectBase * object(int index) {return objects_.child(index);}
|
||||
GLObjectBase * object(const QString & name) {return objects_.child(name);}
|
||||
Light * light(int index);
|
||||
Light * light(const QString & name);
|
||||
|
||||
SelectionMode selectionMode() const {return sel_mode;}
|
||||
Qt::MouseButton selectionButton() const {return sel_button;}
|
||||
Qt::KeyboardModifier selectionModifier() const {return sel_mod;}
|
||||
|
||||
void setSelectionMode(SelectionMode v) {sel_mode = v;}
|
||||
void setSelectionButton(Qt::MouseButton v) {sel_button = v;}
|
||||
void setSelectionModifier(Qt::KeyboardModifier v) {sel_mod = v;}
|
||||
void selectObject(GLObjectBase * o);
|
||||
GLObjectBase * selectedObject() const {return sel_obj;}
|
||||
|
||||
void glReleaseTextures(int channels = 8);
|
||||
QByteArray saveCamera();
|
||||
void restoreCamera(const QByteArray & ba);
|
||||
QByteArray saveFeatures();
|
||||
void restoreFeatures(const QByteArray & ba);
|
||||
|
||||
|
||||
GLfloat aspect, iaspect;
|
||||
QMatrix4x4 cur_mvpm;
|
||||
|
||||
protected:
|
||||
void render();
|
||||
void resizeEvent(QResizeEvent * e);
|
||||
|
||||
void timerEvent(QTimerEvent * );
|
||||
void initialize();
|
||||
void resizeGL(int width, int height);
|
||||
void mousePressEvent(QMouseEvent * e);
|
||||
void mouseMoveEvent(QMouseEvent * e);
|
||||
void mouseReleaseEvent(QMouseEvent * e);
|
||||
void wheelEvent(QWheelEvent * e);
|
||||
void leaveEvent(QEvent * );
|
||||
void mouseDoubleClickEvent(QMouseEvent * e);
|
||||
|
||||
void keyPressEvent(QKeyEvent * e);
|
||||
void keyReleaseEvent(QKeyEvent * e);
|
||||
void focusOutEvent(QFocusEvent *);
|
||||
|
||||
void applyFog();
|
||||
void renderSelection();
|
||||
|
||||
void checkCaps();
|
||||
void collectLights();
|
||||
|
||||
private:
|
||||
void objectDeleted(GLObjectBase * o);
|
||||
void collectObjectLights(GLObjectBase * o);
|
||||
void objectsCountInternal(int * cnt, GLObjectBase * where);
|
||||
void removeObjectInternal(GLObjectBase * o, GLObjectBase * where);
|
||||
void renderSingleSelection(GLObjectBase & o);
|
||||
//void renderSingleShadow(GLObjectBase & o);
|
||||
void renderHalo(const GLObjectBase * obj, const uint iid, const QColor & color, const float & fill);
|
||||
void reloadThisShaders();
|
||||
void processKeys();
|
||||
bool setupViewport();
|
||||
|
||||
QPoint lastPos, downPos;
|
||||
GLObjectBase objects_;
|
||||
QList<Light * > lights_;
|
||||
// uint cid;
|
||||
QHash<uint, GLObjectBase * > ids;
|
||||
QSet<int> keys_;
|
||||
FogMode fogMode_;
|
||||
QColor backColor_, fogColor_, ambientColor_, hoverHaloColor_, selectionHaloColor_;
|
||||
QTime time, ktm_;
|
||||
GLint max_anisotropic, max_texture_chanels;
|
||||
GLObjectBase::RenderMode rmode;
|
||||
GLObjectBase * sel_obj, * hov_obj;
|
||||
GLFramebuffer fbo_selection;
|
||||
QOpenGLShaderProgram * shader_select, * shader_halo;
|
||||
GLRendererBase * renderer_;
|
||||
SelectionMode sel_mode;
|
||||
Qt::MouseButton sel_button;
|
||||
Qt::KeyboardModifier sel_mod;
|
||||
GLRendererBase::RenderingParameters start_rp;
|
||||
QHash<int, QVariant> features_;
|
||||
QSize prev_size;
|
||||
float lineWidth_;
|
||||
float fogDensity_, fogStart_, fogEnd_, fps_, fps_tm, hoverHaloFill_, selectionHaloFill_, m_motionBlurFactor;
|
||||
int timer, fps_cnt, sh_id_loc, deleting_;
|
||||
bool is_first_draw, is_init, fogEnabled_, lightEnabled_, grabMouse_, mouse_first, mouseRotate_, mouseSelect_, customMouseMove_;
|
||||
bool shaders_supported, changed_, cameraOrbit_, need_init_;
|
||||
bool hoverHalo_, selectionHalo_, shaders_bind, selecting_;
|
||||
|
||||
public slots:
|
||||
void setBackColor(const QColor & arg) {backColor_ = arg;}
|
||||
void setLineWidth(const float & arg) {lineWidth_ = arg;}
|
||||
void setFOV(const float & arg) {camera()->fov_ = arg;}
|
||||
void setDepthStart(const float & arg) {camera()->depth_start = arg;}
|
||||
void setDepthEnd(const float & arg) {camera()->depth_end = arg;}
|
||||
void setAmbientColor(const QColor & arg) {ambientColor_ = arg;}
|
||||
void setFogColor(const QColor & arg) {fogColor_ = arg;}
|
||||
void setFogDensity(const float & arg) {fogDensity_ = arg;}
|
||||
void setFogStart(const float & arg) {fogStart_ = arg;}
|
||||
void setFogEnd(const float & arg) {fogEnd_ = arg;}
|
||||
void setFogMode(const FogMode & arg) {fogMode_ = arg;}
|
||||
void setFogEnabled(const bool & arg) {fogEnabled_ = arg;}
|
||||
void setLightEnabled(const bool & arg) {lightEnabled_ = arg;}
|
||||
void setGrabMouseEnabled(const bool & arg) {grabMouse_ = arg; mouse_first = true;}
|
||||
void setMouseRotateEnabled(const bool & arg) {mouseRotate_ = arg;}
|
||||
void setMouseSelectionEnabled(const bool & arg) {mouseSelect_ = arg;}
|
||||
void setCustomMouseMove(const bool & arg) {customMouseMove_ = arg;}
|
||||
void setCameraOrbit(const bool & arg) {cameraOrbit_ = arg;}
|
||||
void setHoverHaloEnabled(const bool & arg) {hoverHalo_ = arg;}
|
||||
void setHoverHaloColor(const QColor & arg) {hoverHaloColor_ = arg;}
|
||||
void setHoverHaloFillAlpha(const float & arg) {hoverHaloFill_ = arg;}
|
||||
void setSelectionHaloEnabled(const bool & arg) {selectionHalo_ = arg;}
|
||||
void setSelectionHaloColor(const QColor & arg) {selectionHaloColor_ = arg;}
|
||||
void setSelectionHaloFillAlpha(const float & arg) {selectionHaloFill_ = arg;}
|
||||
|
||||
void reloadShaders() {if (renderer_ != nullptr) renderer_->reloadShaders(); reloadThisShaders();}
|
||||
void deselect() {sel_obj = nullptr;}
|
||||
|
||||
signals:
|
||||
void glBeforePaint();
|
||||
void glBeginPaint();
|
||||
void glPainting();
|
||||
void glEndPaint();
|
||||
void glKeyPressEvent(QKeyEvent * e);
|
||||
void glKeyReleaseEvent(QKeyEvent * e);
|
||||
void glMousePressEvent(QMouseEvent * e);
|
||||
void glMouseMoveEvent(QMouseEvent * e);
|
||||
void glMouseReleaseEvent(QMouseEvent * e);
|
||||
void glWheelEvent(QWheelEvent * e);
|
||||
void glResize(int, int);
|
||||
void glInitializeDone();
|
||||
void cameraPosChanged(QVector3D pos);
|
||||
void keyEvent(Qt::Key key, Qt::KeyboardModifiers mod);
|
||||
void customMouseMoveEvent(QPoint curpos, QPoint lastpos, Qt::MouseButtons buttons);
|
||||
|
||||
void hoverChanged(GLObjectBase * cur, GLObjectBase * prev);
|
||||
void selectionChanged(GLObjectBase * cur, GLObjectBase * prev);
|
||||
void objectAdded(GLObjectBase * );
|
||||
void doubleClick();
|
||||
|
||||
};
|
||||
|
||||
#endif // QGLVIEW_H
|
||||
/*
|
||||
QGLView
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QGLVIEW_H
|
||||
#define QGLVIEW_H
|
||||
|
||||
#include "openglwindow.h"
|
||||
#include "glframebuffer.h"
|
||||
#include "glprimitives.h"
|
||||
#include "glparticles_system.h"
|
||||
#include "glrendererbase.h"
|
||||
#include <QTime>
|
||||
|
||||
|
||||
class QGLView: public OpenGLWindow, public QGLViewBase
|
||||
{
|
||||
friend class GLRendererBase;
|
||||
friend class GLObjectBase;
|
||||
Q_OBJECT
|
||||
Q_PROPERTY (QColor backColor READ backColor WRITE setBackColor)
|
||||
Q_PROPERTY (float lineWidth READ lineWidth WRITE setLineWidth)
|
||||
Q_PROPERTY (float FOV READ FOV WRITE setFOV)
|
||||
Q_PROPERTY (float depthStart READ depthStart WRITE setDepthStart)
|
||||
Q_PROPERTY (float depthEnd READ depthEnd WRITE setDepthEnd)
|
||||
Q_PROPERTY (QColor ambientColor READ ambientColor WRITE setAmbientColor)
|
||||
Q_PROPERTY (QColor fogColor READ fogColor WRITE setFogColor)
|
||||
Q_PROPERTY (float fogDensity READ fogDensity WRITE setFogDensity)
|
||||
Q_PROPERTY (float fogStart READ fogStart WRITE setFogStart)
|
||||
Q_PROPERTY (float fogEnd READ fogEnd WRITE setFogEnd)
|
||||
Q_PROPERTY (FogMode fogMode READ fogMode WRITE setFogMode)
|
||||
Q_PROPERTY (bool fogEnabled READ isFogEnabled WRITE setFogEnabled)
|
||||
Q_PROPERTY (int renderMode READ renderMode WRITE setRenderMode)
|
||||
Q_PROPERTY (bool grabMouse READ isGrabMouseEnabled WRITE setGrabMouseEnabled)
|
||||
Q_PROPERTY (bool mouseRotate READ isMouseRotateEnabled WRITE setMouseRotateEnabled)
|
||||
Q_PROPERTY (bool mouseSelection READ isMouseSelectionEnabled WRITE setMouseSelectionEnabled)
|
||||
Q_PROPERTY (bool cameraOrbit READ isCameraOrbit WRITE setCameraOrbit)
|
||||
Q_PROPERTY (bool hoverHalo READ isHoverHaloEnabled WRITE setHoverHaloEnabled)
|
||||
Q_PROPERTY (QColor hoverHaloColor READ hoverHaloColor WRITE setHoverHaloColor)
|
||||
Q_PROPERTY (float hoverHaloFillAlpha READ hoverHaloFillAlpha WRITE setHoverHaloFillAlpha)
|
||||
Q_PROPERTY (bool selectionHalo READ isSelectionHaloEnabled WRITE setSelectionHaloEnabled)
|
||||
Q_PROPERTY (QColor selectionHaloColor READ selectionHaloColor WRITE setSelectionHaloColor)
|
||||
Q_PROPERTY (float selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha)
|
||||
Q_PROPERTY (Qt::MouseButton selectionButton READ selectionButton WRITE setSelectionButton)
|
||||
Q_PROPERTY (Qt::KeyboardModifier selectionModifier READ selectionModifier WRITE setSelectionModifier)
|
||||
Q_PROPERTY (SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
|
||||
|
||||
public:
|
||||
QGLView();
|
||||
virtual ~QGLView();
|
||||
|
||||
enum FogMode {Linear = GL_LINEAR, Exp = GL_EXP, Exp2 = GL_EXP2};
|
||||
enum SelectionMode {NoSelection, SingleSelection, MultiSelection};
|
||||
enum Feature {
|
||||
qglMSAA,
|
||||
qglFXAA,
|
||||
qglLinearFiltering,
|
||||
qglAnisotropicLevel,
|
||||
qglHDR,
|
||||
qglEyeAccomodationEnabled,
|
||||
qglEyeAccomodationTime,
|
||||
qglEyeAccomodationMaxSpeed,
|
||||
qglBloomEnabled,
|
||||
qglBloomThreshold,
|
||||
qglBloomFactor,
|
||||
qglBloomRadius,
|
||||
qglMotionBlurEnabled,
|
||||
qglMotionBlurFactor,
|
||||
qglMotionBlurSteps,
|
||||
qglShadowsEnabled,
|
||||
qglShadowsMapSize,
|
||||
qglShadowsSoftEnabled,
|
||||
qglReflectionsEnabled,
|
||||
qglReflectionsBlur,
|
||||
qglSSAOEnabled,
|
||||
qglSSAORadius,
|
||||
qglDepthOfFieldEnabled,
|
||||
qglDepthOfFieldAutoFocusEnabled,
|
||||
qglDepthOfFieldAutoFocusSpeed,
|
||||
qglDepthOfFieldFocus,
|
||||
qglDepthOfFieldDiaphragm
|
||||
};
|
||||
|
||||
Q_ENUMS (FogMode)
|
||||
Q_ENUMS (SelectionMode)
|
||||
|
||||
void stop();
|
||||
void start(float freq = 60.);
|
||||
|
||||
GLRendererBase * renderer();
|
||||
void setRenderer(GLRendererBase * r, GLRendererBase ** prev = nullptr);
|
||||
|
||||
QColor backColor() const {return backColor_;}
|
||||
float lineWidth() const {return lineWidth_;}
|
||||
float FOV() const {return camera()->fov_;}
|
||||
float depthStart() const {return camera()->depth_start;}
|
||||
float depthEnd() const {return camera()->depth_end;}
|
||||
float currentFPS() const {return fps_;}
|
||||
int maxAnisotropicLevel() const {return max_anisotropic;}
|
||||
|
||||
QColor ambientColor() const {return ambientColor_;}
|
||||
QColor fogColor() const {return fogColor_;}
|
||||
float fogDensity() const {return fogDensity_;}
|
||||
float fogStart() const {return fogStart_;}
|
||||
float fogEnd() const {return fogEnd_;}
|
||||
FogMode fogMode() const {return fogMode_;}
|
||||
bool isFogEnabled() const {return fogEnabled_;}
|
||||
bool isLightEnabled() const {return lightEnabled_;}
|
||||
bool isGrabMouseEnabled() const {return grabMouse_;}
|
||||
bool isMouseRotateEnabled() const {return mouseRotate_;}
|
||||
bool isMouseSelectionEnabled() const {return mouseSelect_;}
|
||||
bool isCameraOrbit() const {return cameraOrbit_;}
|
||||
bool isHoverHaloEnabled() const {return hoverHalo_;}
|
||||
QColor hoverHaloColor() const {return hoverHaloColor_;}
|
||||
float hoverHaloFillAlpha() const {return hoverHaloFill_;}
|
||||
bool isSelectionHaloEnabled() const {return selectionHalo_;}
|
||||
QColor selectionHaloColor() const {return selectionHaloColor_;}
|
||||
float selectionHaloFillAlpha() const {return selectionHaloFill_;}
|
||||
|
||||
QVariant feature(Feature f) const {return features_.value(int(f));}
|
||||
QVariant setFeature(Feature f, const QVariant & value) {QVariant ret = features_.value(int(f)); features_[int(f)] = value; return ret;}
|
||||
bool isFeatureEnabled(Feature f) const {return features_[int(f)].toBool();}
|
||||
|
||||
int renderMode() const {return (int)rmode;}
|
||||
void setRenderMode(int mode) {rmode = (GLObjectBase::RenderMode)mode;}
|
||||
|
||||
void addObject(GLObjectBase * o);
|
||||
// void addObject(GLObjectBase & o) {addObject(&o);}
|
||||
int objectsCount(bool all = false);
|
||||
void removeObject(GLObjectBase * o, bool inChildren = true);
|
||||
void removeObject(GLObjectBase & o, bool inChildren = true);
|
||||
void clearObjects(bool deleteAll = false);
|
||||
QList<GLObjectBase * > objects(bool all = false);
|
||||
|
||||
int lightsCount() const;
|
||||
void removeLight(int index);
|
||||
void removeLight(Light * l);
|
||||
void clearLights(bool deleteAll = false);
|
||||
QList<Light * > lights() {return lights_;}
|
||||
|
||||
void addTexture(const QString & path);
|
||||
void addAnimation(const QString & dir, const QString & name);
|
||||
|
||||
const GLObjectBase & rootObject() {return objects_;}
|
||||
GLObjectBase * object(int index) {return objects_.child(index);}
|
||||
GLObjectBase * object(const QString & name) {return objects_.child(name);}
|
||||
Light * light(int index);
|
||||
Light * light(const QString & name);
|
||||
|
||||
SelectionMode selectionMode() const {return sel_mode;}
|
||||
Qt::MouseButton selectionButton() const {return sel_button;}
|
||||
Qt::KeyboardModifier selectionModifier() const {return sel_mod;}
|
||||
|
||||
void setSelectionMode(SelectionMode v) {sel_mode = v;}
|
||||
void setSelectionButton(Qt::MouseButton v) {sel_button = v;}
|
||||
void setSelectionModifier(Qt::KeyboardModifier v) {sel_mod = v;}
|
||||
void selectObject(GLObjectBase * o);
|
||||
GLObjectBase * selectedObject() const {return sel_obj;}
|
||||
|
||||
void glReleaseTextures(int channels = 8);
|
||||
QByteArray saveCamera();
|
||||
void restoreCamera(const QByteArray & ba);
|
||||
QByteArray saveFeatures();
|
||||
void restoreFeatures(const QByteArray & ba);
|
||||
|
||||
|
||||
GLfloat aspect, iaspect;
|
||||
QMatrix4x4 cur_mvpm;
|
||||
|
||||
protected:
|
||||
void render();
|
||||
void resizeEvent(QResizeEvent * e);
|
||||
|
||||
void timerEvent(QTimerEvent * );
|
||||
void initialize();
|
||||
void resizeGL(int width, int height);
|
||||
void mousePressEvent(QMouseEvent * e);
|
||||
void mouseMoveEvent(QMouseEvent * e);
|
||||
void mouseReleaseEvent(QMouseEvent * e);
|
||||
void wheelEvent(QWheelEvent * e);
|
||||
void leaveEvent(QEvent * );
|
||||
void mouseDoubleClickEvent(QMouseEvent * e);
|
||||
|
||||
void keyPressEvent(QKeyEvent * e);
|
||||
void keyReleaseEvent(QKeyEvent * e);
|
||||
void focusOutEvent(QFocusEvent *);
|
||||
|
||||
void applyFog();
|
||||
void renderSelection();
|
||||
|
||||
void checkCaps();
|
||||
void collectLights();
|
||||
|
||||
private:
|
||||
void objectDeleted(GLObjectBase * o);
|
||||
void collectObjectLights(GLObjectBase * o);
|
||||
void objectsCountInternal(int * cnt, GLObjectBase * where);
|
||||
void removeObjectInternal(GLObjectBase * o, GLObjectBase * where);
|
||||
void renderSingleSelection(GLObjectBase & o);
|
||||
//void renderSingleShadow(GLObjectBase & o);
|
||||
void renderHalo(const GLObjectBase * obj, const uint iid, const QColor & color, const float & fill);
|
||||
void reloadThisShaders();
|
||||
void processKeys();
|
||||
bool setupViewport();
|
||||
|
||||
QPoint lastPos, downPos;
|
||||
GLObjectBase objects_;
|
||||
QList<Light * > lights_;
|
||||
// uint cid;
|
||||
QHash<uint, GLObjectBase * > ids;
|
||||
QSet<int> keys_;
|
||||
FogMode fogMode_;
|
||||
QColor backColor_, fogColor_, ambientColor_, hoverHaloColor_, selectionHaloColor_;
|
||||
QTime time, ktm_;
|
||||
GLint max_anisotropic, max_texture_chanels;
|
||||
GLObjectBase::RenderMode rmode;
|
||||
GLObjectBase * sel_obj, * hov_obj;
|
||||
GLFramebuffer fbo_selection;
|
||||
QOpenGLShaderProgram * shader_select, * shader_halo;
|
||||
GLRendererBase * renderer_;
|
||||
SelectionMode sel_mode;
|
||||
Qt::MouseButton sel_button;
|
||||
Qt::KeyboardModifier sel_mod;
|
||||
GLRendererBase::RenderingParameters start_rp;
|
||||
QHash<int, QVariant> features_;
|
||||
QSize prev_size;
|
||||
float lineWidth_;
|
||||
float fogDensity_, fogStart_, fogEnd_, fps_, fps_tm, hoverHaloFill_, selectionHaloFill_, m_motionBlurFactor;
|
||||
int timer, fps_cnt, sh_id_loc, deleting_;
|
||||
bool is_first_draw, is_init, fogEnabled_, lightEnabled_, grabMouse_, mouse_first, mouseRotate_, mouseSelect_, customMouseMove_;
|
||||
bool shaders_supported, changed_, cameraOrbit_, need_init_;
|
||||
bool hoverHalo_, selectionHalo_, shaders_bind, selecting_;
|
||||
|
||||
public slots:
|
||||
void setBackColor(const QColor & arg) {backColor_ = arg;}
|
||||
void setLineWidth(const float & arg) {lineWidth_ = arg;}
|
||||
void setFOV(const float & arg) {camera()->fov_ = arg;}
|
||||
void setDepthStart(const float & arg) {camera()->depth_start = arg;}
|
||||
void setDepthEnd(const float & arg) {camera()->depth_end = arg;}
|
||||
void setAmbientColor(const QColor & arg) {ambientColor_ = arg;}
|
||||
void setFogColor(const QColor & arg) {fogColor_ = arg;}
|
||||
void setFogDensity(const float & arg) {fogDensity_ = arg;}
|
||||
void setFogStart(const float & arg) {fogStart_ = arg;}
|
||||
void setFogEnd(const float & arg) {fogEnd_ = arg;}
|
||||
void setFogMode(const FogMode & arg) {fogMode_ = arg;}
|
||||
void setFogEnabled(const bool & arg) {fogEnabled_ = arg;}
|
||||
void setLightEnabled(const bool & arg) {lightEnabled_ = arg;}
|
||||
void setGrabMouseEnabled(const bool & arg) {grabMouse_ = arg; mouse_first = true;}
|
||||
void setMouseRotateEnabled(const bool & arg) {mouseRotate_ = arg;}
|
||||
void setMouseSelectionEnabled(const bool & arg) {mouseSelect_ = arg;}
|
||||
void setCustomMouseMove(const bool & arg) {customMouseMove_ = arg;}
|
||||
void setCameraOrbit(const bool & arg) {cameraOrbit_ = arg;}
|
||||
void setHoverHaloEnabled(const bool & arg) {hoverHalo_ = arg;}
|
||||
void setHoverHaloColor(const QColor & arg) {hoverHaloColor_ = arg;}
|
||||
void setHoverHaloFillAlpha(const float & arg) {hoverHaloFill_ = arg;}
|
||||
void setSelectionHaloEnabled(const bool & arg) {selectionHalo_ = arg;}
|
||||
void setSelectionHaloColor(const QColor & arg) {selectionHaloColor_ = arg;}
|
||||
void setSelectionHaloFillAlpha(const float & arg) {selectionHaloFill_ = arg;}
|
||||
|
||||
void reloadShaders() {if (renderer_ != nullptr) renderer_->reloadShaders(); reloadThisShaders();}
|
||||
void deselect() {sel_obj = nullptr;}
|
||||
|
||||
signals:
|
||||
void glBeforePaint();
|
||||
void glBeginPaint();
|
||||
void glPainting();
|
||||
void glEndPaint();
|
||||
void glKeyPressEvent(QKeyEvent * e);
|
||||
void glKeyReleaseEvent(QKeyEvent * e);
|
||||
void glMousePressEvent(QMouseEvent * e);
|
||||
void glMouseMoveEvent(QMouseEvent * e);
|
||||
void glMouseReleaseEvent(QMouseEvent * e);
|
||||
void glWheelEvent(QWheelEvent * e);
|
||||
void glResize(int, int);
|
||||
void glInitializeDone();
|
||||
void cameraPosChanged(QVector3D pos);
|
||||
void keyEvent(Qt::Key key, Qt::KeyboardModifiers mod);
|
||||
void customMouseMoveEvent(QPoint curpos, QPoint lastpos, Qt::MouseButtons buttons);
|
||||
|
||||
void hoverChanged(GLObjectBase * cur, GLObjectBase * prev);
|
||||
void selectionChanged(GLObjectBase * cur, GLObjectBase * prev);
|
||||
void objectAdded(GLObjectBase * );
|
||||
void doubleClick();
|
||||
|
||||
};
|
||||
|
||||
#endif // QGLVIEW_H
|
||||
|
||||
Reference in New Issue
Block a user