QOpenGLWindow example: use std::unique_ptr instead of QScopedPointer
QScopedPointer is scheduled for deprecation, and can't decide whether it wants to be a scoped, or a unique pointer. The use of a unique_ptr members requires that the destructor be out-of-line, since the payload classes are only forward-declared in the header file. Change-Id: Id0dcdde52cb3adc30d3051d2eed1d24c76154921 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
7303218e42
commit
082f10c9eb
@ -91,6 +91,9 @@ FragmentToy::FragmentToy(const QString &fragmentSource, QObject *parent)
|
||||
}
|
||||
}
|
||||
|
||||
FragmentToy::~FragmentToy()
|
||||
= default;
|
||||
|
||||
void FragmentToy::draw(const QSize &windowSize)
|
||||
{
|
||||
if (!m_program)
|
||||
@ -120,7 +123,7 @@ void FragmentToy::draw(const QSize &windowSize)
|
||||
if (!m_vertex_shader->compileSourceCode(vertex_shader)) {
|
||||
qWarning() << "Failed to compile the vertex shader:" << m_vertex_shader->log();
|
||||
}
|
||||
if (!m_program->addShader(m_vertex_shader.data())) {
|
||||
if (!m_program->addShader(m_vertex_shader.get())) {
|
||||
qWarning() << "Failed to add vertex shader to program:" << m_program->log();
|
||||
}
|
||||
}
|
||||
@ -153,7 +156,7 @@ void FragmentToy::draw(const QSize &windowSize)
|
||||
}
|
||||
|
||||
if (m_fragment_shader) {
|
||||
if (!m_program->addShader(m_fragment_shader.data())) {
|
||||
if (!m_program->addShader(m_fragment_shader.get())) {
|
||||
qWarning() << "Failed to add fragment shader to program:" << m_program->log();
|
||||
}
|
||||
}
|
||||
@ -197,14 +200,14 @@ void FragmentToy::fileChanged(const QString &path)
|
||||
m_fragment_file_last_modified = fragment_source.lastModified();
|
||||
m_recompile_shaders = true;
|
||||
if (m_program) {
|
||||
m_program->removeShader(m_fragment_shader.data());
|
||||
m_program->removeShader(m_fragment_shader.get());
|
||||
m_fragment_shader.reset(nullptr);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
m_recompile_shaders = true;
|
||||
if (m_program) {
|
||||
m_program->removeShader(m_fragment_shader.data());
|
||||
m_program->removeShader(m_fragment_shader.get());
|
||||
m_fragment_shader.reset(nullptr);
|
||||
}
|
||||
}
|
||||
|
@ -62,11 +62,14 @@
|
||||
#include <QOpenGLShaderProgram>
|
||||
#include <QOpenGLFunctions>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class FragmentToy : public QObject, protected QOpenGLFunctions
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FragmentToy(const QString &fragmentSource, QObject *parent = 0);
|
||||
explicit FragmentToy(const QString &fragmentSource, QObject *parent = nullptr);
|
||||
~FragmentToy();
|
||||
|
||||
void draw(const QSize &windowSize);
|
||||
|
||||
@ -79,9 +82,9 @@ private:
|
||||
QString m_fragment_file;
|
||||
QDateTime m_fragment_file_last_modified;
|
||||
|
||||
QScopedPointer<QOpenGLShaderProgram> m_program;
|
||||
QScopedPointer<QOpenGLShader> m_vertex_shader;
|
||||
QScopedPointer<QOpenGLShader> m_fragment_shader;
|
||||
std::unique_ptr<QOpenGLShaderProgram> m_program;
|
||||
std::unique_ptr<QOpenGLShader> m_vertex_shader;
|
||||
std::unique_ptr<QOpenGLShader> m_fragment_shader;
|
||||
QOpenGLVertexArrayObject m_vao;
|
||||
QOpenGLBuffer m_vertex_buffer;
|
||||
GLuint m_vertex_coord_pos;
|
||||
|
Loading…
x
Reference in New Issue
Block a user