Commit c2a3cd0b authored by Gus Grubba's avatar Gus Grubba

Merge pull request #2064 from dogmaphobic/windowsOpenGL

Fixing OpenGL issues for Windows (Video Streaming)
parents 465d562f c33134bd
......@@ -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 \
......
......@@ -28,6 +28,8 @@
#include <QStack>
#include <QPainter>
#include "glutils.h"
QtVideoSinkDelegate::QtVideoSinkDelegate(GstElement *sink, QObject *parent)
: BaseDelegate(sink, parent)
, m_painter(0)
......@@ -137,20 +139,22 @@ void QtVideoSinkDelegate::setGLContext(QGLContext *context)
if (m_glContext) {
m_glContext->makeCurrent();
const QByteArray extensions(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)));
GST_LOG_OBJECT(m_sink, "Available GL extensions: %s", extensions.constData());
QOpenGLFunctionsDef *funcs = getQOpenGLFunctions();
if (funcs) {
const QByteArray extensions(reinterpret_cast<const char *>(funcs->glGetString(GL_EXTENSIONS)));
GST_LOG_OBJECT(m_sink, "Available GL extensions: %s", extensions.constData());
#ifndef QT_OPENGL_ES
if (extensions.contains("ARB_fragment_program"))
m_supportedPainters |= ArbFp;
if (extensions.contains("ARB_fragment_program"))
m_supportedPainters |= ArbFp;
#endif
#ifndef QT_OPENGL_ES_2
if (QGLShaderProgram::hasOpenGLShaderPrograms(m_glContext)
if (QGLShaderProgram::hasOpenGLShaderPrograms(m_glContext)
&& extensions.contains("ARB_shader_objects"))
#endif
m_supportedPainters |= Glsl;
m_supportedPainters |= Glsl;
}
}
GST_LOG_OBJECT(m_sink, "Done setting GL context. m_supportedPainters=%x", (int) m_supportedPainters);
......@@ -227,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;
}
......@@ -240,6 +243,5 @@ bool QtVideoSinkDelegate::event(QEvent *event)
destroyPainter();
}
}
return BaseDelegate::event(event);
}
......@@ -26,9 +26,10 @@
#include <qmath.h>
#include <QOpenGLContext>
#include <QOpenGLFunctions>
#include <QtQuick/QSGMaterialShader>
#include "glutils.h"
static const char * const qtvideosink_glsl_vertexShader =
"uniform highp mat4 qt_Matrix; \n"
"attribute highp vec4 qt_VertexPosition; \n"
......@@ -256,7 +257,13 @@ VideoMaterial::VideoMaterial()
VideoMaterial::~VideoMaterial()
{
if (!m_textureSize.isEmpty())
glDeleteTextures(m_textureCount, m_textureIds);
{
QOpenGLFunctionsDef *funcs = getQOpenGLFunctions();
if (funcs)
{
funcs->glDeleteTextures(m_textureCount, m_textureIds);
}
}
gst_buffer_replace(&m_frame, NULL);
}
......@@ -323,9 +330,13 @@ void VideoMaterial::initYuv420PTextureInfo(bool uvSwapped, const QSize &size)
void VideoMaterial::init(GstVideoColorMatrix colorMatrixType)
{
glGenTextures(m_textureCount, m_textureIds);
m_colorMatrixType = colorMatrixType;
updateColors(0, 0, 0, 0);
QOpenGLFunctionsDef *funcs = getQOpenGLFunctions();
if (funcs)
{
funcs->glGenTextures(m_textureCount, m_textureIds);
m_colorMatrixType = colorMatrixType;
updateColors(0, 0, 0, 0);
}
}
void VideoMaterial::setCurrentFrame(GstBuffer *buffer)
......@@ -411,7 +422,10 @@ void VideoMaterial::updateColors(int brightness, int contrast, int hue, int satu
void VideoMaterial::bind()
{
QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
QOpenGLFunctionsDef *funcs = getQOpenGLFunctions();
if (!funcs)
return;
GstBuffer *frame = NULL;
m_frameMutex.lock();
......@@ -422,28 +436,32 @@ void VideoMaterial::bind()
if (frame) {
GstMapInfo info;
gst_buffer_map(frame, &info, GST_MAP_READ);
functions->glActiveTexture(GL_TEXTURE1);
funcs->glActiveTexture(GL_TEXTURE1);
bindTexture(1, info.data);
functions->glActiveTexture(GL_TEXTURE2);
funcs->glActiveTexture(GL_TEXTURE2);
bindTexture(2, info.data);
functions->glActiveTexture(GL_TEXTURE0); // Finish with 0 as default texture unit
funcs->glActiveTexture(GL_TEXTURE0); // Finish with 0 as default texture unit
bindTexture(0, info.data);
gst_buffer_unmap(frame, &info);
gst_buffer_unref(frame);
} else {
functions->glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_textureIds[1]);
functions->glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, m_textureIds[2]);
functions->glActiveTexture(GL_TEXTURE0); // Finish with 0 as default texture unit
glBindTexture(GL_TEXTURE_2D, m_textureIds[0]);
funcs->glActiveTexture(GL_TEXTURE1);
funcs->glBindTexture(GL_TEXTURE_2D, m_textureIds[1]);
funcs->glActiveTexture(GL_TEXTURE2);
funcs->glBindTexture(GL_TEXTURE_2D, m_textureIds[2]);
funcs->glActiveTexture(GL_TEXTURE0); // Finish with 0 as default texture unit
funcs->glBindTexture(GL_TEXTURE_2D, m_textureIds[0]);
}
}
void VideoMaterial::bindTexture(int i, const quint8 *data)
{
glBindTexture(GL_TEXTURE_2D, m_textureIds[i]);
glTexImage2D(
QOpenGLFunctionsDef *funcs = getQOpenGLFunctions();
if (!funcs)
return;
funcs->glBindTexture(GL_TEXTURE_2D, m_textureIds[i]);
funcs->glTexImage2D(
GL_TEXTURE_2D,
0,
m_textureInternalFormat,
......@@ -453,9 +471,9 @@ void VideoMaterial::bindTexture(int i, const quint8 *data)
m_textureFormat,
m_textureType,
data + m_textureOffsets[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief QGC Video Item
* @author Gus Grubba <mavlink@grubba.com>
*/
#ifndef GLUTILS_H
#define GLUTILS_H
#ifdef __android__
#include <QOpenGLFunctions>
#define getQOpenGLFunctions() QOpenGLContext::currentContext()->functions()
#define QOpenGLFunctionsDef QOpenGLFunctions
#else
#include <QOpenGLFunctions_2_0>
#define getQOpenGLFunctions() QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_2_0>()
#define QOpenGLFunctionsDef QOpenGLFunctions_2_0
#endif
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment