diff --git a/src/VideoStreaming/VideoStreaming.pri b/src/VideoStreaming/VideoStreaming.pri index 32b2cfa944c2a1431ae612444aea49cb1ede4e0c..9f09c6cbc63a9120950ea5a57ec0f00da1776c7a 100644 --- a/src/VideoStreaming/VideoStreaming.pri +++ b/src/VideoStreaming/VideoStreaming.pri @@ -132,6 +132,7 @@ VideoEnabled { $$PWD/gstqtvideosink/painters/videonode.h \ $$PWD/gstqtvideosink/utils/bufferformat.h \ $$PWD/gstqtvideosink/utils/utils.h \ + $$PWD/gstqtvideosink/utils/glutils.h \ SOURCES += \ $$PWD/gstqtvideosink/delegates/basedelegate.cpp \ diff --git a/src/VideoStreaming/gstqtvideosink/delegates/qtvideosinkdelegate.cpp b/src/VideoStreaming/gstqtvideosink/delegates/qtvideosinkdelegate.cpp index ef2e9e8430928a060d88d42d294f1a2a1efbbe36..fd46d2a6f59b4512ff88241fe8a399c03ccbfac4 100644 --- a/src/VideoStreaming/gstqtvideosink/delegates/qtvideosinkdelegate.cpp +++ b/src/VideoStreaming/gstqtvideosink/delegates/qtvideosinkdelegate.cpp @@ -27,7 +27,8 @@ #include #include -#include + +#include "glutils.h" QtVideoSinkDelegate::QtVideoSinkDelegate(GstElement *sink, QObject *parent) : BaseDelegate(sink, parent) @@ -138,7 +139,7 @@ void QtVideoSinkDelegate::setGLContext(QGLContext *context) if (m_glContext) { m_glContext->makeCurrent(); - QOpenGLFunctions_2_0 *funcs = QOpenGLContext::currentContext()->versionFunctions(); + QOpenGLFunctionsDef *funcs = getQOpenGLFunctions(); if (funcs) { const QByteArray extensions(reinterpret_cast(funcs->glGetString(GL_EXTENSIONS))); GST_LOG_OBJECT(m_sink, "Available GL extensions: %s", extensions.constData()); @@ -230,7 +231,6 @@ void QtVideoSinkDelegate::changePainter(const BufferFormat & format) void QtVideoSinkDelegate::destroyPainter() { GST_LOG_OBJECT(m_sink, "Destroying painter"); - delete m_painter; m_painter = 0; } @@ -243,6 +243,5 @@ bool QtVideoSinkDelegate::event(QEvent *event) destroyPainter(); } } - return BaseDelegate::event(event); } diff --git a/src/VideoStreaming/gstqtvideosink/painters/openglsurfacepainter.cpp b/src/VideoStreaming/gstqtvideosink/painters/openglsurfacepainter.cpp index cd320d44d6fd8e3ad3d06ce2932bc148b89aaaee..dbdad9ba3db5512a37c2d7f57997a515c393c84b 100644 --- a/src/VideoStreaming/gstqtvideosink/painters/openglsurfacepainter.cpp +++ b/src/VideoStreaming/gstqtvideosink/painters/openglsurfacepainter.cpp @@ -23,7 +23,8 @@ #include "openglsurfacepainter.h" #include -#include + +#include "glutils.h" #ifndef GL_TEXTURE0 # define GL_TEXTURE0 0x84C0 @@ -178,7 +179,7 @@ void OpenGLSurfacePainter::paint(quint8 *data, QPainter *painter, const PaintAreas & areas) { - QOpenGLFunctions_2_0 *funcs = QOpenGLContext::currentContext()->versionFunctions(); + QOpenGLFunctionsDef *funcs = getQOpenGLFunctions(); if (!funcs) return; @@ -396,22 +397,17 @@ ArbFpSurfacePainter::ArbFpSurfacePainter() , m_programId(0) { const QGLContext *context = QGLContext::currentContext(); - glProgramStringARB = (_glProgramStringARB) context->getProcAddress( - QLatin1String("glProgramStringARB")); - glBindProgramARB = (_glBindProgramARB) context->getProcAddress( - QLatin1String("glBindProgramARB")); - glDeleteProgramsARB = (_glDeleteProgramsARB) context->getProcAddress( - QLatin1String("glDeleteProgramsARB")); - glGenProgramsARB = (_glGenProgramsARB) context->getProcAddress( - QLatin1String("glGenProgramsARB")); - glProgramLocalParameter4fARB = (_glProgramLocalParameter4fARB) context->getProcAddress( - QLatin1String("glProgramLocalParameter4fARB")); + glProgramStringARB = (_glProgramStringARB) context->getProcAddress(QLatin1String("glProgramStringARB")); + glBindProgramARB = (_glBindProgramARB) context->getProcAddress(QLatin1String("glBindProgramARB")); + glDeleteProgramsARB = (_glDeleteProgramsARB) context->getProcAddress(QLatin1String("glDeleteProgramsARB")); + glGenProgramsARB = (_glGenProgramsARB) context->getProcAddress(QLatin1String("glGenProgramsARB")); + glProgramLocalParameter4fARB = (_glProgramLocalParameter4fARB) context->getProcAddress(QLatin1String("glProgramLocalParameter4fARB")); } void ArbFpSurfacePainter::init(const BufferFormat &format) { Q_ASSERT(m_textureCount == 0); - QOpenGLFunctions_2_0 *funcs = QOpenGLContext::currentContext()->versionFunctions(); + QOpenGLFunctionsDef *funcs = getQOpenGLFunctions(); if (!funcs) return; @@ -501,7 +497,7 @@ void ArbFpSurfacePainter::init(const BufferFormat &format) void ArbFpSurfacePainter::cleanup() { - QOpenGLFunctions_2_0 *funcs = QOpenGLContext::currentContext()->versionFunctions(); + QOpenGLFunctionsDef *funcs = getQOpenGLFunctions(); if (funcs) { funcs->glDeleteTextures(m_textureCount, m_textureIds); @@ -516,7 +512,7 @@ void ArbFpSurfacePainter::paintImpl(const QPainter *painter, const GLfloat *textureCoordArray) { Q_UNUSED(painter); - QOpenGLFunctions_2_0 *funcs = QOpenGLContext::currentContext()->versionFunctions(); + QOpenGLFunctionsDef *funcs = getQOpenGLFunctions(); if (!funcs) return; @@ -734,14 +730,14 @@ void GlslSurfacePainter::init(const BufferFormat &format) throw QString("Shader link error ") + m_program.log(); } - QOpenGLFunctions_2_0 *funcs = QOpenGLContext::currentContext()->versionFunctions(); + QOpenGLFunctionsDef *funcs = getQOpenGLFunctions(); if (funcs) funcs->glGenTextures(m_textureCount, m_textureIds); } void GlslSurfacePainter::cleanup() { - QOpenGLFunctions_2_0 *funcs = QOpenGLContext::currentContext()->versionFunctions(); + QOpenGLFunctionsDef *funcs = getQOpenGLFunctions(); if (funcs) { funcs->glDeleteTextures(m_textureCount, m_textureIds); @@ -795,8 +791,8 @@ void GlslSurfacePainter::paintImpl(const QPainter *painter, m_program.setAttributeArray("textureCoordArray", textureCoordArray, 2); m_program.setUniformValue("positionMatrix", positionMatrix); - QOpenGLFunctions_2_0 *funcs = QOpenGLContext::currentContext()->versionFunctions(); - if (funcs) + QOpenGLFunctionsDef *funcs = getQOpenGLFunctions(); + if (!funcs) return; if (m_textureCount == 3) { diff --git a/src/VideoStreaming/gstqtvideosink/painters/videomaterial.cpp b/src/VideoStreaming/gstqtvideosink/painters/videomaterial.cpp index ef360cacedcdebcc21a77f002ccf6982b4379492..67daa4fc440694409d587924becfcac2c735cda8 100644 --- a/src/VideoStreaming/gstqtvideosink/painters/videomaterial.cpp +++ b/src/VideoStreaming/gstqtvideosink/painters/videomaterial.cpp @@ -26,9 +26,10 @@ #include #include -#include #include +#include "glutils.h" + static const char * const qtvideosink_glsl_vertexShader = "uniform highp mat4 qt_Matrix; \n" "attribute highp vec4 qt_VertexPosition; \n" @@ -257,7 +258,7 @@ VideoMaterial::~VideoMaterial() { if (!m_textureSize.isEmpty()) { - QOpenGLFunctions_2_0 *funcs = QOpenGLContext::currentContext()->versionFunctions(); + QOpenGLFunctionsDef *funcs = getQOpenGLFunctions(); if (funcs) { funcs->glDeleteTextures(m_textureCount, m_textureIds); @@ -329,7 +330,7 @@ void VideoMaterial::initYuv420PTextureInfo(bool uvSwapped, const QSize &size) void VideoMaterial::init(GstVideoColorMatrix colorMatrixType) { - QOpenGLFunctions_2_0 *funcs = QOpenGLContext::currentContext()->versionFunctions(); + QOpenGLFunctionsDef *funcs = getQOpenGLFunctions(); if (funcs) { funcs->glGenTextures(m_textureCount, m_textureIds); @@ -421,7 +422,7 @@ void VideoMaterial::updateColors(int brightness, int contrast, int hue, int satu void VideoMaterial::bind() { - QOpenGLFunctions_2_0 *funcs = QOpenGLContext::currentContext()->versionFunctions(); + QOpenGLFunctionsDef *funcs = getQOpenGLFunctions(); if (!funcs) return; @@ -455,7 +456,7 @@ void VideoMaterial::bind() void VideoMaterial::bindTexture(int i, const quint8 *data) { - QOpenGLFunctions_2_0 *funcs = QOpenGLContext::currentContext()->versionFunctions(); + QOpenGLFunctionsDef *funcs = getQOpenGLFunctions(); if (!funcs) return; diff --git a/src/VideoStreaming/gstqtvideosink/utils/glutils.h b/src/VideoStreaming/gstqtvideosink/utils/glutils.h new file mode 100644 index 0000000000000000000000000000000000000000..2ff461d20e19128922c9d72fba6dcf8bf38414ed --- /dev/null +++ b/src/VideoStreaming/gstqtvideosink/utils/glutils.h @@ -0,0 +1,43 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009, 2015 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief QGC Video Item + * @author Gus Grubba + */ + +#ifndef GLUTILS_H +#define GLUTILS_H + +#ifdef __android__ +#include +#define getQOpenGLFunctions() QOpenGLContext::currentContext()->functions() +#define QOpenGLFunctionsDef QOpenGLFunctions +#else +#include +#define getQOpenGLFunctions() QOpenGLContext::currentContext()->versionFunctions() +#define QOpenGLFunctionsDef QOpenGLFunctions_2_0 +#endif + +#endif