[vlc-commits] [Git][videolan/vlc][master] 3 commits: doc: QtGL: switch to C++14
Hugo Beauzée-Luyssen (@chouquette)
gitlab at videolan.org
Wed Dec 15 15:03:26 UTC 2021
Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC
Commits:
a6ab2189 by Alexandre Janniaux at 2021-12-15T14:47:15+00:00
doc: QtGL: switch to C++14
C++14 is needed to use std::make_unique<> in particular, and is already
a requirement for libvlc anyway.
- - - - -
530cc094 by Alexandre Janniaux at 2021-12-15T14:47:15+00:00
doc: QtGl: use std::unique_ptr<>
This improves the documentation by exposing a C++-idiomatic way to
handle the resources without leaking for most users copying this part of
the code to their application.
- - - - -
b225c6db by Alexandre Janniaux at 2021-12-15T14:47:15+00:00
doc: QtGl: use nullptr and remove stray comments
- - - - -
3 changed files:
- doc/libvlc/QtGL/QtGl.pro
- doc/libvlc/QtGL/qtvlcwidget.cpp
- doc/libvlc/QtGL/qtvlcwidget.h
Changes:
=====================================
doc/libvlc/QtGL/QtGl.pro
=====================================
@@ -1,7 +1,7 @@
TEMPLATE = app
TARGET = qtglvlc
-CONFIG += link_pkgconfig force_debug_info
+CONFIG += c++14 link_pkgconfig force_debug_info
PKGCONFIG = libvlc
QT += widgets
=====================================
doc/libvlc/QtGL/qtvlcwidget.cpp
=====================================
@@ -18,10 +18,6 @@ public:
VLCVideo(QtVLCWidget *widget)
:mWidget(widget)
{
- mBuffers[0] = NULL;
- mBuffers[1] = NULL;
- mBuffers[2] = NULL;
-
/* Use default format for context. */
mContext = new QOpenGLContext(widget);
@@ -62,7 +58,7 @@ public:
std::swap(m_idx_swap, m_idx_display);
m_updated = false;
}
- return mBuffers[m_idx_display];
+ return mBuffers[m_idx_display].get();
}
/// this callback will create the surfaces and FBO used by VLC to perform its rendering
@@ -73,9 +69,8 @@ public:
if (cfg->width != that->m_width || cfg->height != that->m_height)
cleanup(data);
- that->mBuffers[0] = new QOpenGLFramebufferObject(cfg->width, cfg->height);
- that->mBuffers[1] = new QOpenGLFramebufferObject(cfg->width, cfg->height);
- that->mBuffers[2] = new QOpenGLFramebufferObject(cfg->width, cfg->height);
+ for (auto &buffer : that->mBuffers)
+ buffer = std::make_unique<QOpenGLFramebufferObject>(cfg->width, cfg->height);
that->m_width = cfg->width;
that->m_height = cfg->height;
@@ -121,12 +116,8 @@ public:
if (that->m_width == 0 && that->m_height == 0)
return;
- delete that->mBuffers[0];
- that->mBuffers[0] = NULL;
- delete that->mBuffers[1];
- that->mBuffers[1] = NULL;
- delete that->mBuffers[2];
- that->mBuffers[2] = NULL;
+ for (auto &buffer : that->mBuffers)
+ buffer.reset(nullptr);
}
//This callback is called after VLC performs drawing calls
@@ -176,7 +167,7 @@ private:
unsigned m_width = 0;
unsigned m_height = 0;
QMutex m_text_lock;
- QOpenGLFramebufferObject *mBuffers[3];
+ std::unique_ptr<QOpenGLFramebufferObject> mBuffers[3];
size_t m_idx_render = 0;
size_t m_idx_swap = 1;
size_t m_idx_display = 2;
@@ -186,7 +177,6 @@ private:
QtVLCWidget::QtVLCWidget(QWidget *parent)
: QOpenGLWidget(parent),
- m_program(nullptr),
vertexBuffer(QOpenGLBuffer::VertexBuffer),
vertexIndexBuffer(QOpenGLBuffer::IndexBuffer)
{
@@ -257,8 +247,7 @@ void QtVLCWidget::cleanup()
makeCurrent();
vertexBuffer.destroy();
vertexIndexBuffer.destroy();
- delete m_program;
- m_program = 0;
+ m_program.reset(nullptr);
doneCurrent();
}
@@ -337,7 +326,7 @@ void QtVLCWidget::initializeGL()
vertexIndexBuffer.bind();
vertexIndexBuffer.allocate(g_element_buffer_data, sizeof(g_element_buffer_data));
- m_program = new QOpenGLShaderProgram;
+ m_program = std::make_unique<QOpenGLShaderProgram>();
m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource);
m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
m_program->link();
@@ -353,7 +342,7 @@ void QtVLCWidget::paintGL()
{
QOpenGLFunctions *GL = context()->functions();
QOpenGLFramebufferObject *fbo = mVLC->getVideoFrame();
- if (fbo != NULL && GL != NULL)
+ if (fbo != nullptr && GL != nullptr)
{
m_program->bind();
@@ -364,7 +353,6 @@ void QtVLCWidget::paintGL()
vertexBuffer.bind();
m_program->setAttributeArray("position", (const QVector2D *)nullptr, sizeof(GLfloat)*2);
- //vertexBuffer.release();
m_program->enableAttributeArray("position");
@@ -375,11 +363,8 @@ void QtVLCWidget::paintGL()
GL_UNSIGNED_SHORT, /* type */
(void*)0 /* element array buffer offset */
);
- //vertexIndexBuffer.release();
m_program->disableAttributeArray("position");
-
- //m_program->release();
}
}
=====================================
doc/libvlc/QtGL/qtvlcwidget.h
=====================================
@@ -33,7 +33,7 @@ protected:
private:
QOpenGLVertexArrayObject m_vao;
- QOpenGLShaderProgram *m_program;
+ std::unique_ptr<QOpenGLShaderProgram> m_program;
std::unique_ptr<class VLCVideo> mVLC;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/7577cfd2f67d2a3204efb296308a1031160bd6f5...b225c6dbc0e0905c21ad53557cb6fc4a2712a902
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/7577cfd2f67d2a3204efb296308a1031160bd6f5...b225c6dbc0e0905c21ad53557cb6fc4a2712a902
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list