Cleanup QtOpenGL examples
Cleanup the OpenGL examples - use nullptr (clang-tidy) - use member-initialization - avoid redundant checks for != nullptr when deleting a pointer Change-Id: I3e4702690ed79e71c3e952d51ceef83b907b45b7 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
parent
fbda189e08
commit
b0042601ed
@ -50,36 +50,30 @@
|
|||||||
|
|
||||||
#include "openglwindow.h"
|
#include "openglwindow.h"
|
||||||
|
|
||||||
#include <QtGui/QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QtGui/QMatrix4x4>
|
#include <QMatrix4x4>
|
||||||
#include <QtGui/QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
#include <QtGui/QScreen>
|
#include <QScreen>
|
||||||
|
#include <QtMath>
|
||||||
|
|
||||||
#include <QtCore/qmath.h>
|
|
||||||
|
|
||||||
//! [1]
|
//! [1]
|
||||||
class TriangleWindow : public OpenGLWindow
|
class TriangleWindow : public OpenGLWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TriangleWindow();
|
using OpenGLWindow::OpenGLWindow;
|
||||||
|
|
||||||
void initialize() override;
|
void initialize() override;
|
||||||
void render() override;
|
void render() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLuint m_posAttr;
|
GLuint m_posAttr = 0;
|
||||||
GLuint m_colAttr;
|
GLuint m_colAttr = 0;
|
||||||
GLuint m_matrixUniform;
|
GLuint m_matrixUniform = 0;
|
||||||
|
|
||||||
QOpenGLShaderProgram *m_program;
|
QOpenGLShaderProgram *m_program = nullptr;
|
||||||
int m_frame;
|
int m_frame = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
TriangleWindow::TriangleWindow()
|
|
||||||
: m_program(0)
|
|
||||||
, m_frame(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
//! [1]
|
//! [1]
|
||||||
|
|
||||||
//! [2]
|
//! [2]
|
||||||
@ -144,7 +138,7 @@ void TriangleWindow::render()
|
|||||||
m_program->bind();
|
m_program->bind();
|
||||||
|
|
||||||
QMatrix4x4 matrix;
|
QMatrix4x4 matrix;
|
||||||
matrix.perspective(60.0f, 4.0f/3.0f, 0.1f, 100.0f);
|
matrix.perspective(60.0f, 4.0f / 3.0f, 0.1f, 100.0f);
|
||||||
matrix.translate(0, 0, -2);
|
matrix.translate(0, 0, -2);
|
||||||
matrix.rotate(100.0f * m_frame / screen()->refreshRate(), 0, 1, 0);
|
matrix.rotate(100.0f * m_frame / screen()->refreshRate(), 0, 1, 0);
|
||||||
|
|
||||||
|
@ -50,18 +50,13 @@
|
|||||||
|
|
||||||
#include "openglwindow.h"
|
#include "openglwindow.h"
|
||||||
|
|
||||||
#include <QtCore/QCoreApplication>
|
#include <QOpenGLContext>
|
||||||
|
#include <QOpenGLPaintDevice>
|
||||||
#include <QtGui/QOpenGLContext>
|
#include <QPainter>
|
||||||
#include <QtGui/QOpenGLPaintDevice>
|
|
||||||
#include <QtGui/QPainter>
|
|
||||||
|
|
||||||
//! [1]
|
//! [1]
|
||||||
OpenGLWindow::OpenGLWindow(QWindow *parent)
|
OpenGLWindow::OpenGLWindow(QWindow *parent)
|
||||||
: QWindow(parent)
|
: QWindow(parent)
|
||||||
, m_animating(false)
|
|
||||||
, m_context(0)
|
|
||||||
, m_device(0)
|
|
||||||
{
|
{
|
||||||
setSurfaceType(QWindow::OpenGLSurface);
|
setSurfaceType(QWindow::OpenGLSurface);
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,8 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtGui/QWindow>
|
#include <QWindow>
|
||||||
#include <QtGui/QOpenGLFunctions>
|
#include <QOpenGLFunctions>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QPainter;
|
class QPainter;
|
||||||
@ -62,7 +62,7 @@ class OpenGLWindow : public QWindow, protected QOpenGLFunctions
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit OpenGLWindow(QWindow *parent = 0);
|
explicit OpenGLWindow(QWindow *parent = nullptr);
|
||||||
~OpenGLWindow();
|
~OpenGLWindow();
|
||||||
|
|
||||||
virtual void render(QPainter *painter);
|
virtual void render(QPainter *painter);
|
||||||
@ -82,10 +82,10 @@ protected:
|
|||||||
void exposeEvent(QExposeEvent *event) override;
|
void exposeEvent(QExposeEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_animating;
|
bool m_animating = false;
|
||||||
|
|
||||||
QOpenGLContext *m_context;
|
QOpenGLContext *m_context = nullptr;
|
||||||
QOpenGLPaintDevice *m_device;
|
QOpenGLPaintDevice *m_device = nullptr;
|
||||||
};
|
};
|
||||||
//! [1]
|
//! [1]
|
||||||
|
|
||||||
|
@ -73,15 +73,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
GLWindow::GLWindow()
|
GLWindow::GLWindow()
|
||||||
: m_texImageInput(0),
|
|
||||||
m_texImageTmp(0),
|
|
||||||
m_texImageProcessed(0),
|
|
||||||
m_shaderDisplay(0),
|
|
||||||
m_shaderComputeV(0),
|
|
||||||
m_shaderComputeH(0),
|
|
||||||
m_blurRadius(0.0f),
|
|
||||||
m_animate(true),
|
|
||||||
m_vao(0)
|
|
||||||
{
|
{
|
||||||
const float animationStart = 0.0;
|
const float animationStart = 0.0;
|
||||||
const float animationEnd = 10.0;
|
const float animationEnd = 10.0;
|
||||||
@ -324,27 +315,18 @@ void GLWindow::initializeGL()
|
|||||||
<< ((ctx->format().renderableType() == QSurfaceFormat::OpenGLES) ? (" GLES") : (" GL"))
|
<< ((ctx->format().renderableType() == QSurfaceFormat::OpenGLES) ? (" GLES") : (" GL"))
|
||||||
<< " context";
|
<< " context";
|
||||||
|
|
||||||
if (m_texImageInput) {
|
|
||||||
delete m_texImageInput;
|
|
||||||
m_texImageInput = 0;
|
|
||||||
}
|
|
||||||
QImage img(":/Qt-logo-medium.png");
|
QImage img(":/Qt-logo-medium.png");
|
||||||
Q_ASSERT(!img.isNull());
|
Q_ASSERT(!img.isNull());
|
||||||
|
delete m_texImageInput;
|
||||||
m_texImageInput = new QOpenGLTexture(img.convertToFormat(QImage::Format_RGBA8888).mirrored());
|
m_texImageInput = new QOpenGLTexture(img.convertToFormat(QImage::Format_RGBA8888).mirrored());
|
||||||
|
|
||||||
if (m_texImageTmp) {
|
delete m_texImageTmp;
|
||||||
delete m_texImageTmp;
|
|
||||||
m_texImageTmp = 0;
|
|
||||||
}
|
|
||||||
m_texImageTmp = new QOpenGLTexture(QOpenGLTexture::Target2D);
|
m_texImageTmp = new QOpenGLTexture(QOpenGLTexture::Target2D);
|
||||||
m_texImageTmp->setFormat(m_texImageInput->format());
|
m_texImageTmp->setFormat(m_texImageInput->format());
|
||||||
m_texImageTmp->setSize(m_texImageInput->width(),m_texImageInput->height());
|
m_texImageTmp->setSize(m_texImageInput->width(),m_texImageInput->height());
|
||||||
m_texImageTmp->allocateStorage(QOpenGLTexture::RGBA,QOpenGLTexture::UInt8); // WTF?
|
m_texImageTmp->allocateStorage(QOpenGLTexture::RGBA,QOpenGLTexture::UInt8); // WTF?
|
||||||
|
|
||||||
if (m_texImageProcessed) {
|
delete m_texImageProcessed;
|
||||||
delete m_texImageProcessed;
|
|
||||||
m_texImageProcessed = 0;
|
|
||||||
}
|
|
||||||
m_texImageProcessed = new QOpenGLTexture(QOpenGLTexture::Target2D);
|
m_texImageProcessed = new QOpenGLTexture(QOpenGLTexture::Target2D);
|
||||||
m_texImageProcessed->setFormat(m_texImageInput->format());
|
m_texImageProcessed->setFormat(m_texImageInput->format());
|
||||||
m_texImageProcessed->setSize(m_texImageInput->width(),m_texImageInput->height());
|
m_texImageProcessed->setSize(m_texImageInput->width(),m_texImageInput->height());
|
||||||
@ -354,10 +336,7 @@ void GLWindow::initializeGL()
|
|||||||
m_texImageProcessed->setMinificationFilter(QOpenGLTexture::Linear);
|
m_texImageProcessed->setMinificationFilter(QOpenGLTexture::Linear);
|
||||||
m_texImageProcessed->setWrapMode(QOpenGLTexture::ClampToEdge);
|
m_texImageProcessed->setWrapMode(QOpenGLTexture::ClampToEdge);
|
||||||
|
|
||||||
if (m_shaderDisplay) {
|
delete m_shaderDisplay;
|
||||||
delete m_shaderDisplay;
|
|
||||||
m_shaderDisplay = 0;
|
|
||||||
}
|
|
||||||
m_shaderDisplay = new QOpenGLShaderProgram;
|
m_shaderDisplay = new QOpenGLShaderProgram;
|
||||||
// Prepend the correct version directive to the sources. The rest is the
|
// Prepend the correct version directive to the sources. The rest is the
|
||||||
// same, thanks to the common GLSL syntax.
|
// same, thanks to the common GLSL syntax.
|
||||||
@ -365,18 +344,12 @@ void GLWindow::initializeGL()
|
|||||||
m_shaderDisplay->addShaderFromSourceCode(QOpenGLShader::Fragment, versionedShaderCode(fsDisplaySource));
|
m_shaderDisplay->addShaderFromSourceCode(QOpenGLShader::Fragment, versionedShaderCode(fsDisplaySource));
|
||||||
m_shaderDisplay->link();
|
m_shaderDisplay->link();
|
||||||
|
|
||||||
if (m_shaderComputeV) {
|
delete m_shaderComputeV;
|
||||||
delete m_shaderComputeV;
|
|
||||||
m_shaderComputeV = 0;
|
|
||||||
}
|
|
||||||
m_shaderComputeV = new QOpenGLShaderProgram;
|
m_shaderComputeV = new QOpenGLShaderProgram;
|
||||||
m_shaderComputeV->addShaderFromSourceCode(QOpenGLShader::Compute, versionedShaderCode(csComputeSourceV));
|
m_shaderComputeV->addShaderFromSourceCode(QOpenGLShader::Compute, versionedShaderCode(csComputeSourceV));
|
||||||
m_shaderComputeV->link();
|
m_shaderComputeV->link();
|
||||||
|
|
||||||
if (m_shaderComputeH) {
|
delete m_shaderComputeH;
|
||||||
delete m_shaderComputeH;
|
|
||||||
m_shaderComputeH = 0;
|
|
||||||
}
|
|
||||||
m_shaderComputeH = new QOpenGLShaderProgram;
|
m_shaderComputeH = new QOpenGLShaderProgram;
|
||||||
m_shaderComputeH->addShaderFromSourceCode(QOpenGLShader::Compute, versionedShaderCode(csComputeSourceH));
|
m_shaderComputeH->addShaderFromSourceCode(QOpenGLShader::Compute, versionedShaderCode(csComputeSourceH));
|
||||||
m_shaderComputeH->link();
|
m_shaderComputeH->link();
|
||||||
|
@ -90,21 +90,21 @@ protected:
|
|||||||
void setAnimating(bool animate);
|
void setAnimating(bool animate);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPropertyAnimation *m_animationForward;
|
QPropertyAnimation *m_animationForward = nullptr;
|
||||||
QPropertyAnimation *m_animationBackward;
|
QPropertyAnimation *m_animationBackward = nullptr;
|
||||||
QSequentialAnimationGroup *m_animationGroup;
|
QSequentialAnimationGroup *m_animationGroup;
|
||||||
QOpenGLTexture *m_texImageInput;
|
QOpenGLTexture *m_texImageInput = nullptr;
|
||||||
QOpenGLTexture *m_texImageTmp;
|
QOpenGLTexture *m_texImageTmp = nullptr;
|
||||||
QOpenGLTexture *m_texImageProcessed;
|
QOpenGLTexture *m_texImageProcessed = nullptr;
|
||||||
QOpenGLShaderProgram *m_shaderDisplay;
|
QOpenGLShaderProgram *m_shaderDisplay = nullptr;
|
||||||
QOpenGLShaderProgram *m_shaderComputeV;
|
QOpenGLShaderProgram *m_shaderComputeV = nullptr;
|
||||||
QOpenGLShaderProgram *m_shaderComputeH;
|
QOpenGLShaderProgram *m_shaderComputeH = nullptr;
|
||||||
QMatrix4x4 m_proj;
|
QMatrix4x4 m_proj;
|
||||||
QSizeF m_quadSize;
|
QSizeF m_quadSize;
|
||||||
|
|
||||||
int m_blurRadius;
|
int m_blurRadius = 0;
|
||||||
bool m_animate;
|
bool m_animate = true;
|
||||||
QOpenGLVertexArrayObject *m_vao;
|
QOpenGLVertexArrayObject *m_vao = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
#include <QOpenGLFunctions>
|
#include <QOpenGLFunctions>
|
||||||
|
|
||||||
RenderWindow::RenderWindow(const QSurfaceFormat &format)
|
RenderWindow::RenderWindow(const QSurfaceFormat &format)
|
||||||
: m_context(0),
|
: m_context(nullptr),
|
||||||
m_initialized(false),
|
m_initialized(false),
|
||||||
m_forceGLSL110(false),
|
m_forceGLSL110(false),
|
||||||
m_angle(0.0f)
|
m_angle(0.0f)
|
||||||
@ -67,7 +67,7 @@ RenderWindow::RenderWindow(const QSurfaceFormat &format)
|
|||||||
m_context->setFormat(requestedFormat());
|
m_context->setFormat(requestedFormat());
|
||||||
if (!m_context->create()) {
|
if (!m_context->create()) {
|
||||||
delete m_context;
|
delete m_context;
|
||||||
m_context = 0;
|
m_context = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ class Widget : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Widget(QWidget *parent = 0);
|
explicit Widget(QWidget *parent = nullptr);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void start();
|
void start();
|
||||||
|
@ -174,6 +174,6 @@ void GeometryEngine::drawCubeGeometry(QOpenGLShaderProgram *program)
|
|||||||
program->setAttributeBuffer(texcoordLocation, GL_FLOAT, offset, 2, sizeof(VertexData));
|
program->setAttributeBuffer(texcoordLocation, GL_FLOAT, offset, 2, sizeof(VertexData));
|
||||||
|
|
||||||
// Draw cube geometry using indices from VBO 1
|
// Draw cube geometry using indices from VBO 1
|
||||||
glDrawElements(GL_TRIANGLE_STRIP, 34, GL_UNSIGNED_SHORT, 0);
|
glDrawElements(GL_TRIANGLE_STRIP, 34, GL_UNSIGNED_SHORT, nullptr);
|
||||||
}
|
}
|
||||||
//! [2]
|
//! [2]
|
||||||
|
@ -52,15 +52,7 @@
|
|||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
|
||||||
#include <math.h>
|
#include <cmath>
|
||||||
|
|
||||||
MainWidget::MainWidget(QWidget *parent) :
|
|
||||||
QOpenGLWidget(parent),
|
|
||||||
geometries(0),
|
|
||||||
texture(0),
|
|
||||||
angularSpeed(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
MainWidget::~MainWidget()
|
MainWidget::~MainWidget()
|
||||||
{
|
{
|
||||||
|
@ -69,7 +69,7 @@ class MainWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWidget(QWidget *parent = 0);
|
using QOpenGLWidget::QOpenGLWidget;
|
||||||
~MainWidget();
|
~MainWidget();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -87,15 +87,15 @@ protected:
|
|||||||
private:
|
private:
|
||||||
QBasicTimer timer;
|
QBasicTimer timer;
|
||||||
QOpenGLShaderProgram program;
|
QOpenGLShaderProgram program;
|
||||||
GeometryEngine *geometries;
|
GeometryEngine *geometries = nullptr;
|
||||||
|
|
||||||
QOpenGLTexture *texture;
|
QOpenGLTexture *texture = nullptr;
|
||||||
|
|
||||||
QMatrix4x4 projection;
|
QMatrix4x4 projection;
|
||||||
|
|
||||||
QVector2D mousePressPosition;
|
QVector2D mousePressPosition;
|
||||||
QVector3D rotationAxis;
|
QVector3D rotationAxis;
|
||||||
qreal angularSpeed;
|
qreal angularSpeed = 0;
|
||||||
QQuaternion rotation;
|
QQuaternion rotation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -57,11 +57,7 @@
|
|||||||
bool GLWidget::m_transparent = false;
|
bool GLWidget::m_transparent = false;
|
||||||
|
|
||||||
GLWidget::GLWidget(QWidget *parent)
|
GLWidget::GLWidget(QWidget *parent)
|
||||||
: QOpenGLWidget(parent),
|
: QOpenGLWidget(parent)
|
||||||
m_xRot(0),
|
|
||||||
m_yRot(0),
|
|
||||||
m_zRot(0),
|
|
||||||
m_program(0)
|
|
||||||
{
|
{
|
||||||
m_core = QSurfaceFormat::defaultFormat().profile() == QSurfaceFormat::CoreProfile;
|
m_core = QSurfaceFormat::defaultFormat().profile() == QSurfaceFormat::CoreProfile;
|
||||||
// --transparent causes the clear color to be transparent. Therefore, on systems that
|
// --transparent causes the clear color to be transparent. Therefore, on systems that
|
||||||
@ -133,7 +129,7 @@ void GLWidget::cleanup()
|
|||||||
makeCurrent();
|
makeCurrent();
|
||||||
m_logoVbo.destroy();
|
m_logoVbo.destroy();
|
||||||
delete m_program;
|
delete m_program;
|
||||||
m_program = 0;
|
m_program = nullptr;
|
||||||
doneCurrent();
|
doneCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,8 +246,10 @@ void GLWidget::setupVertexAttribs()
|
|||||||
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
||||||
f->glEnableVertexAttribArray(0);
|
f->glEnableVertexAttribArray(0);
|
||||||
f->glEnableVertexAttribArray(1);
|
f->glEnableVertexAttribArray(1);
|
||||||
f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), 0);
|
f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
|
||||||
f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), reinterpret_cast<void *>(3 * sizeof(GLfloat)));
|
nullptr);
|
||||||
|
f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
|
||||||
|
reinterpret_cast<void *>(3 * sizeof(GLfloat)));
|
||||||
m_logoVbo.release();
|
m_logoVbo.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GLWidget(QWidget *parent = 0);
|
GLWidget(QWidget *parent = nullptr);
|
||||||
~GLWidget();
|
~GLWidget();
|
||||||
|
|
||||||
static bool isTransparent() { return m_transparent; }
|
static bool isTransparent() { return m_transparent; }
|
||||||
@ -96,18 +96,18 @@ private:
|
|||||||
void setupVertexAttribs();
|
void setupVertexAttribs();
|
||||||
|
|
||||||
bool m_core;
|
bool m_core;
|
||||||
int m_xRot;
|
int m_xRot = 0;
|
||||||
int m_yRot;
|
int m_yRot = 0;
|
||||||
int m_zRot;
|
int m_zRot = 0;
|
||||||
QPoint m_lastPos;
|
QPoint m_lastPos;
|
||||||
Logo m_logo;
|
Logo m_logo;
|
||||||
QOpenGLVertexArrayObject m_vao;
|
QOpenGLVertexArrayObject m_vao;
|
||||||
QOpenGLBuffer m_logoVbo;
|
QOpenGLBuffer m_logoVbo;
|
||||||
QOpenGLShaderProgram *m_program;
|
QOpenGLShaderProgram *m_program = nullptr;
|
||||||
int m_projMatrixLoc;
|
int m_projMatrixLoc = 0;
|
||||||
int m_mvMatrixLoc;
|
int m_mvMatrixLoc = 0;
|
||||||
int m_normalMatrixLoc;
|
int m_normalMatrixLoc = 0;
|
||||||
int m_lightPosLoc;
|
int m_lightPosLoc = 0;
|
||||||
QMatrix4x4 m_proj;
|
QMatrix4x4 m_proj;
|
||||||
QMatrix4x4 m_camera;
|
QMatrix4x4 m_camera;
|
||||||
QMatrix4x4 m_world;
|
QMatrix4x4 m_world;
|
||||||
|
@ -52,7 +52,6 @@
|
|||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
|
|
||||||
Logo::Logo()
|
Logo::Logo()
|
||||||
: m_count(0)
|
|
||||||
{
|
{
|
||||||
m_data.resize(2500 * 6);
|
m_data.resize(2500 * 6);
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ private:
|
|||||||
void add(const QVector3D &v, const QVector3D &n);
|
void add(const QVector3D &v, const QVector3D &n);
|
||||||
|
|
||||||
QVector<GLfloat> m_data;
|
QVector<GLfloat> m_data;
|
||||||
int m_count;
|
int m_count = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOGO_H
|
#endif // LOGO_H
|
||||||
|
@ -72,5 +72,6 @@ void MainWindow::onAddNew()
|
|||||||
if (!centralWidget())
|
if (!centralWidget())
|
||||||
setCentralWidget(new Window(this));
|
setCentralWidget(new Window(this));
|
||||||
else
|
else
|
||||||
QMessageBox::information(0, tr("Cannot add new window"), tr("Already occupied. Undock first."));
|
QMessageBox::information(nullptr, tr("Cannot add new window"),
|
||||||
|
tr("Already occupied. Undock first."));
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ void Window::keyPressEvent(QKeyEvent *e)
|
|||||||
void Window::dockUndock()
|
void Window::dockUndock()
|
||||||
{
|
{
|
||||||
if (parent()) {
|
if (parent()) {
|
||||||
setParent(0);
|
setParent(nullptr);
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
move(QApplication::desktop()->width() / 2 - width() / 2,
|
move(QApplication::desktop()->width() / 2 - width() / 2,
|
||||||
QApplication::desktop()->height() / 2 - height() / 2);
|
QApplication::desktop()->height() / 2 - height() / 2);
|
||||||
@ -134,10 +134,12 @@ void Window::dockUndock()
|
|||||||
dockBtn->setText(tr("Undock"));
|
dockBtn->setText(tr("Undock"));
|
||||||
mainWindow->setCentralWidget(this);
|
mainWindow->setCentralWidget(this);
|
||||||
} else {
|
} else {
|
||||||
QMessageBox::information(0, tr("Cannot dock"), tr("Main window already closed"));
|
QMessageBox::information(nullptr, tr("Cannot dock"),
|
||||||
|
tr("Main window already closed"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QMessageBox::information(0, tr("Cannot dock"), tr("Main window already occupied"));
|
QMessageBox::information(nullptr, tr("Cannot dock"),
|
||||||
|
tr("Main window already occupied"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,19 +57,10 @@
|
|||||||
#include <QOpenGLVertexArrayObject>
|
#include <QOpenGLVertexArrayObject>
|
||||||
#include <QOpenGLExtraFunctions>
|
#include <QOpenGLExtraFunctions>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QPauseAnimation>
|
|
||||||
#include <QSequentialAnimationGroup>
|
#include <QSequentialAnimationGroup>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
GLWindow::GLWindow()
|
GLWindow::GLWindow()
|
||||||
: m_texture(0),
|
|
||||||
m_program(0),
|
|
||||||
m_vbo(0),
|
|
||||||
m_vao(0),
|
|
||||||
m_target(0, 0, -1),
|
|
||||||
m_uniformsDirty(true),
|
|
||||||
m_r(0),
|
|
||||||
m_r2(0)
|
|
||||||
{
|
{
|
||||||
m_world.setToIdentity();
|
m_world.setToIdentity();
|
||||||
m_world.translate(0, 0, -1);
|
m_world.translate(0, 0, -1);
|
||||||
@ -197,18 +188,12 @@ void GLWindow::initializeGL()
|
|||||||
{
|
{
|
||||||
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
||||||
|
|
||||||
if (m_texture) {
|
|
||||||
delete m_texture;
|
|
||||||
m_texture = 0;
|
|
||||||
}
|
|
||||||
QImage img(":/qtlogo.png");
|
QImage img(":/qtlogo.png");
|
||||||
Q_ASSERT(!img.isNull());
|
Q_ASSERT(!img.isNull());
|
||||||
|
delete m_texture;
|
||||||
m_texture = new QOpenGLTexture(img.scaled(32, 36).mirrored());
|
m_texture = new QOpenGLTexture(img.scaled(32, 36).mirrored());
|
||||||
|
|
||||||
if (m_program) {
|
delete m_program;
|
||||||
delete m_program;
|
|
||||||
m_program = 0;
|
|
||||||
}
|
|
||||||
m_program = new QOpenGLShaderProgram;
|
m_program = new QOpenGLShaderProgram;
|
||||||
// Prepend the correct version directive to the sources. The rest is the
|
// Prepend the correct version directive to the sources. The rest is the
|
||||||
// same, thanks to the common GLSL syntax.
|
// same, thanks to the common GLSL syntax.
|
||||||
@ -223,26 +208,21 @@ void GLWindow::initializeGL()
|
|||||||
m_lightPosLoc = m_program->uniformLocation("lightPos");
|
m_lightPosLoc = m_program->uniformLocation("lightPos");
|
||||||
|
|
||||||
// Create a VAO. Not strictly required for ES 3, but it is for plain OpenGL.
|
// Create a VAO. Not strictly required for ES 3, but it is for plain OpenGL.
|
||||||
if (m_vao) {
|
delete m_vao;
|
||||||
delete m_vao;
|
|
||||||
m_vao = 0;
|
|
||||||
}
|
|
||||||
m_vao = new QOpenGLVertexArrayObject;
|
m_vao = new QOpenGLVertexArrayObject;
|
||||||
if (m_vao->create())
|
if (m_vao->create())
|
||||||
m_vao->bind();
|
m_vao->bind();
|
||||||
|
|
||||||
if (m_vbo) {
|
|
||||||
delete m_vbo;
|
|
||||||
m_vbo = 0;
|
|
||||||
}
|
|
||||||
m_program->bind();
|
m_program->bind();
|
||||||
|
delete m_vbo;
|
||||||
m_vbo = new QOpenGLBuffer;
|
m_vbo = new QOpenGLBuffer;
|
||||||
m_vbo->create();
|
m_vbo->create();
|
||||||
m_vbo->bind();
|
m_vbo->bind();
|
||||||
m_vbo->allocate(m_logo.constData(), m_logo.count() * sizeof(GLfloat));
|
m_vbo->allocate(m_logo.constData(), m_logo.count() * sizeof(GLfloat));
|
||||||
f->glEnableVertexAttribArray(0);
|
f->glEnableVertexAttribArray(0);
|
||||||
f->glEnableVertexAttribArray(1);
|
f->glEnableVertexAttribArray(1);
|
||||||
f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), 0);
|
f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
|
||||||
|
nullptr);
|
||||||
f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
|
f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
|
||||||
reinterpret_cast<void *>(3 * sizeof(GLfloat)));
|
reinterpret_cast<void *>(3 * sizeof(GLfloat)));
|
||||||
m_vbo->release();
|
m_vbo->release();
|
||||||
|
@ -90,23 +90,23 @@ public:
|
|||||||
private slots:
|
private slots:
|
||||||
void startSecondStage();
|
void startSecondStage();
|
||||||
private:
|
private:
|
||||||
QOpenGLTexture *m_texture;
|
QOpenGLTexture *m_texture = nullptr;
|
||||||
QOpenGLShaderProgram *m_program;
|
QOpenGLShaderProgram *m_program = nullptr;
|
||||||
QOpenGLBuffer *m_vbo;
|
QOpenGLBuffer *m_vbo = nullptr;
|
||||||
QOpenGLVertexArrayObject *m_vao;
|
QOpenGLVertexArrayObject *m_vao = nullptr;
|
||||||
Logo m_logo;
|
Logo m_logo;
|
||||||
int m_projMatrixLoc;
|
int m_projMatrixLoc = 0;
|
||||||
int m_camMatrixLoc;
|
int m_camMatrixLoc = 0;
|
||||||
int m_worldMatrixLoc;
|
int m_worldMatrixLoc = 0;
|
||||||
int m_myMatrixLoc;
|
int m_myMatrixLoc = 0;
|
||||||
int m_lightPosLoc;
|
int m_lightPosLoc = 0;
|
||||||
QMatrix4x4 m_proj;
|
QMatrix4x4 m_proj;
|
||||||
QMatrix4x4 m_world;
|
QMatrix4x4 m_world;
|
||||||
QVector3D m_eye;
|
QVector3D m_eye;
|
||||||
QVector3D m_target;
|
QVector3D m_target = {0, 0, -1};
|
||||||
bool m_uniformsDirty;
|
bool m_uniformsDirty = true;
|
||||||
float m_r;
|
float m_r = 0;
|
||||||
float m_r2;
|
float m_r2 = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -57,15 +57,13 @@ Bubble::Bubble(const QPointF &position, qreal radius, const QPointF &velocity)
|
|||||||
{
|
{
|
||||||
innerColor = randomColor();
|
innerColor = randomColor();
|
||||||
outerColor = randomColor();
|
outerColor = randomColor();
|
||||||
cache = 0;
|
|
||||||
updateBrush();
|
updateBrush();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
void Bubble::updateCache()
|
void Bubble::updateCache()
|
||||||
{
|
{
|
||||||
if (cache)
|
delete cache;
|
||||||
delete cache;
|
|
||||||
cache = new QImage(qRound(radius * 2 + 2), qRound(radius * 2 + 2), QImage::Format_ARGB32_Premultiplied);
|
cache = new QImage(qRound(radius * 2 + 2), qRound(radius * 2 + 2), QImage::Format_ARGB32_Premultiplied);
|
||||||
cache->fill(0x00000000);
|
cache->fill(0x00000000);
|
||||||
QPainter p(cache);
|
QPainter p(cache);
|
||||||
@ -80,8 +78,7 @@ void Bubble::updateCache()
|
|||||||
|
|
||||||
Bubble::~Bubble()
|
Bubble::~Bubble()
|
||||||
{
|
{
|
||||||
if (cache)
|
delete cache;
|
||||||
delete cache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bubble::updateBrush()
|
void Bubble::updateBrush()
|
||||||
|
@ -80,7 +80,7 @@ private:
|
|||||||
qreal radius;
|
qreal radius;
|
||||||
QColor innerColor;
|
QColor innerColor;
|
||||||
QColor outerColor;
|
QColor outerColor;
|
||||||
QImage *cache;
|
QImage *cache = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -68,14 +68,6 @@ const int bubbleNum = 8;
|
|||||||
|
|
||||||
GLWidget::GLWidget(MainWindow *mw, bool button, const QColor &background)
|
GLWidget::GLWidget(MainWindow *mw, bool button, const QColor &background)
|
||||||
: m_mainWindow(mw),
|
: m_mainWindow(mw),
|
||||||
m_showBubbles(true),
|
|
||||||
m_qtLogo(true),
|
|
||||||
m_frames(0),
|
|
||||||
m_program1(0),
|
|
||||||
m_program2(0),
|
|
||||||
m_texture(0),
|
|
||||||
m_transparent(false),
|
|
||||||
m_btn(0),
|
|
||||||
m_hasButton(button),
|
m_hasButton(button),
|
||||||
m_background(background)
|
m_background(background)
|
||||||
{
|
{
|
||||||
|
@ -98,34 +98,34 @@ private:
|
|||||||
void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
|
void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
|
||||||
|
|
||||||
MainWindow *m_mainWindow;
|
MainWindow *m_mainWindow;
|
||||||
qreal m_fAngle;
|
qreal m_fAngle = 0;
|
||||||
qreal m_fScale;
|
qreal m_fScale = 1;
|
||||||
bool m_showBubbles;
|
bool m_showBubbles = true;
|
||||||
QVector<QVector3D> m_vertices;
|
QVector<QVector3D> m_vertices;
|
||||||
QVector<QVector3D> m_normals;
|
QVector<QVector3D> m_normals;
|
||||||
bool m_qtLogo;
|
bool m_qtLogo = true;
|
||||||
QList<Bubble *> m_bubbles;
|
QVector<Bubble *> m_bubbles;
|
||||||
int m_frames;
|
int m_frames = 0;
|
||||||
QElapsedTimer m_time;
|
QElapsedTimer m_time;
|
||||||
QOpenGLShader *m_vshader1;
|
QOpenGLShader *m_vshader1 = nullptr;
|
||||||
QOpenGLShader *m_fshader1;
|
QOpenGLShader *m_fshader1 = nullptr;
|
||||||
QOpenGLShader *m_vshader2;
|
QOpenGLShader *m_vshader2 = nullptr;
|
||||||
QOpenGLShader *m_fshader2;
|
QOpenGLShader *m_fshader2 = nullptr;
|
||||||
QOpenGLShaderProgram *m_program1;
|
QOpenGLShaderProgram *m_program1 = nullptr;
|
||||||
QOpenGLShaderProgram *m_program2;
|
QOpenGLShaderProgram *m_program2 = nullptr;
|
||||||
QOpenGLTexture *m_texture;
|
QOpenGLTexture *m_texture = nullptr;
|
||||||
QOpenGLBuffer m_vbo1;
|
QOpenGLBuffer m_vbo1;
|
||||||
QOpenGLBuffer m_vbo2;
|
QOpenGLBuffer m_vbo2;
|
||||||
int m_vertexAttr1;
|
int m_vertexAttr1 = 0;
|
||||||
int m_normalAttr1;
|
int m_normalAttr1 = 0;
|
||||||
int m_matrixUniform1;
|
int m_matrixUniform1 = 0;
|
||||||
int m_vertexAttr2;
|
int m_vertexAttr2 = 0;
|
||||||
int m_normalAttr2;
|
int m_normalAttr2 = 0;
|
||||||
int m_texCoordAttr2;
|
int m_texCoordAttr2 = 0;
|
||||||
int m_matrixUniform2;
|
int m_matrixUniform2 = 0;
|
||||||
int m_textureUniform2;
|
int m_textureUniform2 = 0;
|
||||||
bool m_transparent;
|
bool m_transparent = false;
|
||||||
QPushButton *m_btn;
|
QPushButton *m_btn = nullptr;
|
||||||
bool m_hasButton;
|
bool m_hasButton;
|
||||||
QColor m_background;
|
QColor m_background;
|
||||||
};
|
};
|
||||||
|
@ -53,17 +53,6 @@
|
|||||||
#include <QOpenGLTexture>
|
#include <QOpenGLTexture>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
|
||||||
GLWidget::GLWidget(QWidget *parent)
|
|
||||||
: QOpenGLWidget(parent),
|
|
||||||
clearColor(Qt::black),
|
|
||||||
xRot(0),
|
|
||||||
yRot(0),
|
|
||||||
zRot(0),
|
|
||||||
program(0)
|
|
||||||
{
|
|
||||||
memset(textures, 0, sizeof(textures));
|
|
||||||
}
|
|
||||||
|
|
||||||
GLWidget::~GLWidget()
|
GLWidget::~GLWidget()
|
||||||
{
|
{
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
|
@ -63,7 +63,7 @@ class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit GLWidget(QWidget *parent = 0);
|
using QOpenGLWidget::QOpenGLWidget;
|
||||||
~GLWidget();
|
~GLWidget();
|
||||||
|
|
||||||
QSize minimumSizeHint() const override;
|
QSize minimumSizeHint() const override;
|
||||||
@ -85,13 +85,13 @@ protected:
|
|||||||
private:
|
private:
|
||||||
void makeObject();
|
void makeObject();
|
||||||
|
|
||||||
QColor clearColor;
|
QColor clearColor = Qt::black;
|
||||||
QPoint lastPos;
|
QPoint lastPos;
|
||||||
int xRot;
|
int xRot = 0;
|
||||||
int yRot;
|
int yRot = 0;
|
||||||
int zRot;
|
int zRot = 0;
|
||||||
QOpenGLTexture *textures[6];
|
QOpenGLTexture *textures[6] = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
|
||||||
QOpenGLShaderProgram *program;
|
QOpenGLShaderProgram *program = nullptr;
|
||||||
QOpenGLBuffer vbo;
|
QOpenGLBuffer vbo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -115,12 +115,7 @@ void GLWidget::grabContext()
|
|||||||
m_renderer->unlockRenderer();
|
m_renderer->unlockRenderer();
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::Renderer(GLWidget *w)
|
Renderer::Renderer(GLWidget *w) : m_glwidget(w) {}
|
||||||
: m_inited(false),
|
|
||||||
m_glwidget(w),
|
|
||||||
m_exiting(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::paintQtLogo()
|
void Renderer::paintQtLogo()
|
||||||
{
|
{
|
||||||
|
@ -88,29 +88,29 @@ private:
|
|||||||
void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4);
|
void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4);
|
||||||
void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
|
void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
|
||||||
|
|
||||||
bool m_inited;
|
bool m_inited = false;
|
||||||
qreal m_fAngle;
|
qreal m_fAngle = 0;
|
||||||
qreal m_fScale;
|
qreal m_fScale = 1;
|
||||||
QVector<QVector3D> vertices;
|
QVector<QVector3D> vertices;
|
||||||
QVector<QVector3D> normals;
|
QVector<QVector3D> normals;
|
||||||
QOpenGLShaderProgram program;
|
QOpenGLShaderProgram program;
|
||||||
QOpenGLBuffer vbo;
|
QOpenGLBuffer vbo;
|
||||||
int vertexAttr;
|
int vertexAttr = 0;
|
||||||
int normalAttr;
|
int normalAttr = 0;
|
||||||
int matrixUniform;
|
int matrixUniform = 0;
|
||||||
GLWidget *m_glwidget;
|
GLWidget *m_glwidget = nullptr;
|
||||||
QMutex m_renderMutex;
|
QMutex m_renderMutex;
|
||||||
QElapsedTimer m_elapsed;
|
QElapsedTimer m_elapsed;
|
||||||
QMutex m_grabMutex;
|
QMutex m_grabMutex;
|
||||||
QWaitCondition m_grabCond;
|
QWaitCondition m_grabCond;
|
||||||
bool m_exiting;
|
bool m_exiting = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GLWidget : public QOpenGLWidget
|
class GLWidget : public QOpenGLWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit GLWidget(QWidget *parent = 0);
|
explicit GLWidget(QWidget *parent = nullptr);
|
||||||
~GLWidget();
|
~GLWidget();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
Reference in New Issue
Block a user