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 { ...@@ -132,6 +132,7 @@ VideoEnabled {
$$PWD/gstqtvideosink/painters/videonode.h \ $$PWD/gstqtvideosink/painters/videonode.h \
$$PWD/gstqtvideosink/utils/bufferformat.h \ $$PWD/gstqtvideosink/utils/bufferformat.h \
$$PWD/gstqtvideosink/utils/utils.h \ $$PWD/gstqtvideosink/utils/utils.h \
$$PWD/gstqtvideosink/utils/glutils.h \
SOURCES += \ SOURCES += \
$$PWD/gstqtvideosink/delegates/basedelegate.cpp \ $$PWD/gstqtvideosink/delegates/basedelegate.cpp \
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include <QStack> #include <QStack>
#include <QPainter> #include <QPainter>
#include "glutils.h"
QtVideoSinkDelegate::QtVideoSinkDelegate(GstElement *sink, QObject *parent) QtVideoSinkDelegate::QtVideoSinkDelegate(GstElement *sink, QObject *parent)
: BaseDelegate(sink, parent) : BaseDelegate(sink, parent)
, m_painter(0) , m_painter(0)
...@@ -137,20 +139,22 @@ void QtVideoSinkDelegate::setGLContext(QGLContext *context) ...@@ -137,20 +139,22 @@ void QtVideoSinkDelegate::setGLContext(QGLContext *context)
if (m_glContext) { if (m_glContext) {
m_glContext->makeCurrent(); m_glContext->makeCurrent();
QOpenGLFunctionsDef *funcs = getQOpenGLFunctions();
const QByteArray extensions(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS))); if (funcs) {
GST_LOG_OBJECT(m_sink, "Available GL extensions: %s", extensions.constData()); 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 #ifndef QT_OPENGL_ES
if (extensions.contains("ARB_fragment_program")) if (extensions.contains("ARB_fragment_program"))
m_supportedPainters |= ArbFp; m_supportedPainters |= ArbFp;
#endif #endif
#ifndef QT_OPENGL_ES_2 #ifndef QT_OPENGL_ES_2
if (QGLShaderProgram::hasOpenGLShaderPrograms(m_glContext) if (QGLShaderProgram::hasOpenGLShaderPrograms(m_glContext)
&& extensions.contains("ARB_shader_objects")) && extensions.contains("ARB_shader_objects"))
#endif #endif
m_supportedPainters |= Glsl; m_supportedPainters |= Glsl;
}
} }
GST_LOG_OBJECT(m_sink, "Done setting GL context. m_supportedPainters=%x", (int) m_supportedPainters); 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) ...@@ -227,7 +231,6 @@ void QtVideoSinkDelegate::changePainter(const BufferFormat & format)
void QtVideoSinkDelegate::destroyPainter() void QtVideoSinkDelegate::destroyPainter()
{ {
GST_LOG_OBJECT(m_sink, "Destroying painter"); GST_LOG_OBJECT(m_sink, "Destroying painter");
delete m_painter; delete m_painter;
m_painter = 0; m_painter = 0;
} }
...@@ -240,6 +243,5 @@ bool QtVideoSinkDelegate::event(QEvent *event) ...@@ -240,6 +243,5 @@ bool QtVideoSinkDelegate::event(QEvent *event)
destroyPainter(); destroyPainter();
} }
} }
return BaseDelegate::event(event); return BaseDelegate::event(event);
} }
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include "openglsurfacepainter.h" #include "openglsurfacepainter.h"
#include <QtCore/qmath.h> #include <QtCore/qmath.h>
#include "glutils.h"
#ifndef GL_TEXTURE0 #ifndef GL_TEXTURE0
# define GL_TEXTURE0 0x84C0 # define GL_TEXTURE0 0x84C0
# define GL_TEXTURE1 0x84C1 # define GL_TEXTURE1 0x84C1
...@@ -58,8 +60,7 @@ OpenGLSurfacePainter::OpenGLSurfacePainter() ...@@ -58,8 +60,7 @@ OpenGLSurfacePainter::OpenGLSurfacePainter()
, m_videoColorMatrix(GST_VIDEO_COLOR_MATRIX_UNKNOWN) , m_videoColorMatrix(GST_VIDEO_COLOR_MATRIX_UNKNOWN)
{ {
#ifndef QT_OPENGL_ES #ifndef QT_OPENGL_ES
glActiveTexture = (_glActiveTexture) QGLContext::currentContext()->getProcAddress( glActiveTexture = (_glActiveTexture) QGLContext::currentContext()->getProcAddress(QLatin1String("glActiveTexture"));
QLatin1String("glActiveTexture"));
#endif #endif
} }
...@@ -178,24 +179,28 @@ void OpenGLSurfacePainter::paint(quint8 *data, ...@@ -178,24 +179,28 @@ void OpenGLSurfacePainter::paint(quint8 *data,
QPainter *painter, QPainter *painter,
const PaintAreas & areas) const PaintAreas & areas)
{ {
QOpenGLFunctionsDef *funcs = getQOpenGLFunctions();
if (!funcs)
return;
// if these are enabled, we need to reenable them after beginNativePainting() // if these are enabled, we need to reenable them after beginNativePainting()
// has been called, as they may get disabled // has been called, as they may get disabled
bool stencilTestEnabled = glIsEnabled(GL_STENCIL_TEST); bool stencilTestEnabled = funcs->glIsEnabled(GL_STENCIL_TEST);
bool scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST); bool scissorTestEnabled = funcs->glIsEnabled(GL_SCISSOR_TEST);
painter->beginNativePainting(); painter->beginNativePainting();
if (stencilTestEnabled) if (stencilTestEnabled)
glEnable(GL_STENCIL_TEST); funcs->glEnable(GL_STENCIL_TEST);
if (scissorTestEnabled) if (scissorTestEnabled)
glEnable(GL_SCISSOR_TEST); funcs->glEnable(GL_SCISSOR_TEST);
const GLfloat vertexCoordArray[] = QRECT_TO_GLMATRIX(areas.videoArea); const GLfloat vertexCoordArray[] = QRECT_TO_GLMATRIX(areas.videoArea);
const GLfloat txLeft = areas.sourceRect.left(); const GLfloat txLeft = areas.sourceRect.left();
const GLfloat txRight = areas.sourceRect.right(); const GLfloat txRight = areas.sourceRect.right();
const GLfloat txTop = areas.sourceRect.top(); const GLfloat txTop = areas.sourceRect.top();
const GLfloat txBottom = areas.sourceRect.bottom(); const GLfloat txBottom = areas.sourceRect.bottom();
const GLfloat textureCoordArray[] = const GLfloat textureCoordArray[] =
{ {
...@@ -206,8 +211,8 @@ void OpenGLSurfacePainter::paint(quint8 *data, ...@@ -206,8 +211,8 @@ void OpenGLSurfacePainter::paint(quint8 *data,
}; };
for (int i = 0; i < m_textureCount; ++i) { for (int i = 0; i < m_textureCount; ++i) {
glBindTexture(GL_TEXTURE_2D, m_textureIds[i]); funcs->glBindTexture(GL_TEXTURE_2D, m_textureIds[i]);
glTexImage2D( funcs->glTexImage2D(
GL_TEXTURE_2D, GL_TEXTURE_2D,
0, 0,
m_textureInternalFormat, m_textureInternalFormat,
...@@ -217,10 +222,10 @@ void OpenGLSurfacePainter::paint(quint8 *data, ...@@ -217,10 +222,10 @@ void OpenGLSurfacePainter::paint(quint8 *data,
m_textureFormat, m_textureFormat,
m_textureType, m_textureType,
data + m_textureOffsets[i]); data + m_textureOffsets[i]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
} }
paintImpl(painter, vertexCoordArray, textureCoordArray); paintImpl(painter, vertexCoordArray, textureCoordArray);
...@@ -392,22 +397,19 @@ ArbFpSurfacePainter::ArbFpSurfacePainter() ...@@ -392,22 +397,19 @@ ArbFpSurfacePainter::ArbFpSurfacePainter()
, m_programId(0) , m_programId(0)
{ {
const QGLContext *context = QGLContext::currentContext(); const QGLContext *context = QGLContext::currentContext();
glProgramStringARB = (_glProgramStringARB) context->getProcAddress(QLatin1String("glProgramStringARB"));
glProgramStringARB = (_glProgramStringARB) context->getProcAddress( glBindProgramARB = (_glBindProgramARB) context->getProcAddress(QLatin1String("glBindProgramARB"));
QLatin1String("glProgramStringARB")); glDeleteProgramsARB = (_glDeleteProgramsARB) context->getProcAddress(QLatin1String("glDeleteProgramsARB"));
glBindProgramARB = (_glBindProgramARB) context->getProcAddress( glGenProgramsARB = (_glGenProgramsARB) context->getProcAddress(QLatin1String("glGenProgramsARB"));
QLatin1String("glBindProgramARB")); glProgramLocalParameter4fARB = (_glProgramLocalParameter4fARB) context->getProcAddress(QLatin1String("glProgramLocalParameter4fARB"));
glDeleteProgramsARB = (_glDeleteProgramsARB) context->getProcAddress(
QLatin1String("glDeleteProgramsARB"));
glGenProgramsARB = (_glGenProgramsARB) context->getProcAddress(
QLatin1String("glGenProgramsARB"));
glProgramLocalParameter4fARB = (_glProgramLocalParameter4fARB) context->getProcAddress(
QLatin1String("glProgramLocalParameter4fARB"));
} }
void ArbFpSurfacePainter::init(const BufferFormat &format) void ArbFpSurfacePainter::init(const BufferFormat &format)
{ {
Q_ASSERT(m_textureCount == 0); Q_ASSERT(m_textureCount == 0);
QOpenGLFunctionsDef *funcs = getQOpenGLFunctions();
if (!funcs)
return;
const char *program = 0; const char *program = 0;
...@@ -467,7 +469,7 @@ void ArbFpSurfacePainter::init(const BufferFormat &format) ...@@ -467,7 +469,7 @@ void ArbFpSurfacePainter::init(const BufferFormat &format)
glGenProgramsARB(1, &m_programId); glGenProgramsARB(1, &m_programId);
GLenum glError = glGetError(); GLenum glError = funcs->glGetError();
if (glError != GL_NO_ERROR) { if (glError != GL_NO_ERROR) {
throw QString("ARBfb Shader allocation error ") + throw QString("ARBfb Shader allocation error ") +
QString::number(static_cast<int>(glError), 16); QString::number(static_cast<int>(glError), 16);
...@@ -479,27 +481,28 @@ void ArbFpSurfacePainter::init(const BufferFormat &format) ...@@ -479,27 +481,28 @@ void ArbFpSurfacePainter::init(const BufferFormat &format)
qstrlen(program), qstrlen(program),
reinterpret_cast<const GLvoid *>(program)); reinterpret_cast<const GLvoid *>(program));
if ((glError = glGetError()) != GL_NO_ERROR) { if ((glError = funcs->glGetError()) != GL_NO_ERROR) {
const GLubyte* errorString = glGetString(GL_PROGRAM_ERROR_STRING_ARB); const GLubyte* errorString = funcs->glGetString(GL_PROGRAM_ERROR_STRING_ARB);
glDeleteProgramsARB(1, &m_programId); glDeleteProgramsARB(1, &m_programId);
m_textureCount = 0; m_textureCount = 0;
m_programId = 0; m_programId = 0;
throw QString("ARBfp Shader compile error ") + throw QString("ARBfp Shader compile error ") +
QString::number(static_cast<int>(glError), 16) + QString::number(static_cast<int>(glError), 16) +
reinterpret_cast<const char *>(errorString); reinterpret_cast<const char *>(errorString);
} else { } else {
glGenTextures(m_textureCount, m_textureIds); funcs->glGenTextures(m_textureCount, m_textureIds);
} }
} }
} }
void ArbFpSurfacePainter::cleanup() void ArbFpSurfacePainter::cleanup()
{ {
glDeleteTextures(m_textureCount, m_textureIds); QOpenGLFunctionsDef *funcs = getQOpenGLFunctions();
glDeleteProgramsARB(1, &m_programId); if (funcs)
{
funcs->glDeleteTextures(m_textureCount, m_textureIds);
glDeleteProgramsARB(1, &m_programId);
}
m_textureCount = 0; m_textureCount = 0;
m_programId = 0; m_programId = 0;
} }
...@@ -509,8 +512,11 @@ void ArbFpSurfacePainter::paintImpl(const QPainter *painter, ...@@ -509,8 +512,11 @@ void ArbFpSurfacePainter::paintImpl(const QPainter *painter,
const GLfloat *textureCoordArray) const GLfloat *textureCoordArray)
{ {
Q_UNUSED(painter); Q_UNUSED(painter);
QOpenGLFunctionsDef *funcs = getQOpenGLFunctions();
if (!funcs)
return;
glEnable(GL_FRAGMENT_PROGRAM_ARB); funcs->glEnable(GL_FRAGMENT_PROGRAM_ARB);
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, m_programId); glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, m_programId);
glProgramLocalParameter4fARB( glProgramLocalParameter4fARB(
...@@ -535,28 +541,28 @@ void ArbFpSurfacePainter::paintImpl(const QPainter *painter, ...@@ -535,28 +541,28 @@ void ArbFpSurfacePainter::paintImpl(const QPainter *painter,
m_colorMatrix(2, 2), m_colorMatrix(2, 2),
m_colorMatrix(2, 3)); m_colorMatrix(2, 3));
glActiveTexture(GL_TEXTURE0); funcs->glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_textureIds[0]); funcs->glBindTexture(GL_TEXTURE_2D, m_textureIds[0]);
if (m_textureCount == 3) { if (m_textureCount == 3) {
glActiveTexture(GL_TEXTURE1); funcs->glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_textureIds[1]); funcs->glBindTexture(GL_TEXTURE_2D, m_textureIds[1]);
glActiveTexture(GL_TEXTURE2); funcs->glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, m_textureIds[2]); funcs->glBindTexture(GL_TEXTURE_2D, m_textureIds[2]);
glActiveTexture(GL_TEXTURE0); funcs->glActiveTexture(GL_TEXTURE0);
} }
glVertexPointer(2, GL_FLOAT, 0, vertexCoordArray); funcs->glVertexPointer(2, GL_FLOAT, 0, vertexCoordArray);
glTexCoordPointer(2, GL_FLOAT, 0, textureCoordArray); funcs->glTexCoordPointer(2, GL_FLOAT, 0, textureCoordArray);
glEnableClientState(GL_VERTEX_ARRAY); funcs->glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY); funcs->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); funcs->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY); funcs->glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY); funcs->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_FRAGMENT_PROGRAM_ARB); funcs->glDisable(GL_FRAGMENT_PROGRAM_ARB);
} }
#endif #endif
...@@ -724,14 +730,19 @@ void GlslSurfacePainter::init(const BufferFormat &format) ...@@ -724,14 +730,19 @@ void GlslSurfacePainter::init(const BufferFormat &format)
throw QString("Shader link error ") + m_program.log(); throw QString("Shader link error ") + m_program.log();
} }
glGenTextures(m_textureCount, m_textureIds); QOpenGLFunctionsDef *funcs = getQOpenGLFunctions();
if (funcs)
funcs->glGenTextures(m_textureCount, m_textureIds);
} }
void GlslSurfacePainter::cleanup() void GlslSurfacePainter::cleanup()
{ {
glDeleteTextures(m_textureCount, m_textureIds); QOpenGLFunctionsDef *funcs = getQOpenGLFunctions();
m_program.removeAllShaders(); if (funcs)
{
funcs->glDeleteTextures(m_textureCount, m_textureIds);
m_program.removeAllShaders();
}
m_textureCount = 0; m_textureCount = 0;
} }
...@@ -739,8 +750,8 @@ void GlslSurfacePainter::paintImpl(const QPainter *painter, ...@@ -739,8 +750,8 @@ void GlslSurfacePainter::paintImpl(const QPainter *painter,
const GLfloat *vertexCoordArray, const GLfloat *vertexCoordArray,
const GLfloat *textureCoordArray) const GLfloat *textureCoordArray)
{ {
const int deviceWidth = painter->device()->width(); const int deviceWidth = painter->device()->width();
const int deviceHeight = painter->device()->height(); const int deviceHeight = painter->device()->height();
const QTransform transform = painter->deviceTransform(); const QTransform transform = painter->deviceTransform();
...@@ -780,27 +791,31 @@ void GlslSurfacePainter::paintImpl(const QPainter *painter, ...@@ -780,27 +791,31 @@ void GlslSurfacePainter::paintImpl(const QPainter *painter,
m_program.setAttributeArray("textureCoordArray", textureCoordArray, 2); m_program.setAttributeArray("textureCoordArray", textureCoordArray, 2);
m_program.setUniformValue("positionMatrix", positionMatrix); m_program.setUniformValue("positionMatrix", positionMatrix);
QOpenGLFunctionsDef *funcs = getQOpenGLFunctions();
if (!funcs)
return;
if (m_textureCount == 3) { if (m_textureCount == 3) {
glActiveTexture(GL_TEXTURE0); funcs->glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_textureIds[0]); funcs->glBindTexture(GL_TEXTURE_2D, m_textureIds[0]);
glActiveTexture(GL_TEXTURE1); funcs->glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_textureIds[1]); funcs->glBindTexture(GL_TEXTURE_2D, m_textureIds[1]);
glActiveTexture(GL_TEXTURE2); funcs->glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, m_textureIds[2]); funcs->glBindTexture(GL_TEXTURE_2D, m_textureIds[2]);
glActiveTexture(GL_TEXTURE0); funcs->glActiveTexture(GL_TEXTURE0);
m_program.setUniformValue("texY", 0); m_program.setUniformValue("texY", 0);
m_program.setUniformValue("texU", 1); m_program.setUniformValue("texU", 1);
m_program.setUniformValue("texV", 2); m_program.setUniformValue("texV", 2);
} else { } else {
glActiveTexture(GL_TEXTURE0); funcs->glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_textureIds[0]); funcs->glBindTexture(GL_TEXTURE_2D, m_textureIds[0]);
m_program.setUniformValue("texRgb", 0); m_program.setUniformValue("texRgb", 0);
} }
m_program.setUniformValue("colorMatrix", m_colorMatrix); m_program.setUniformValue("colorMatrix", m_colorMatrix);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); funcs->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
m_program.release(); m_program.release();
} }
...@@ -26,9 +26,10 @@ ...@@ -26,9 +26,10 @@
#include <qmath.h> #include <qmath.h>
#include <QOpenGLContext> #include <QOpenGLContext>
#include <QOpenGLFunctions>
#include <QtQuick/QSGMaterialShader> #include <QtQuick/QSGMaterialShader>
#include "glutils.h"
static const char * const qtvideosink_glsl_vertexShader = static const char * const qtvideosink_glsl_vertexShader =
"uniform highp mat4 qt_Matrix; \n" "uniform highp mat4 qt_Matrix; \n"
"attribute highp vec4 qt_VertexPosition; \n" "attribute highp vec4 qt_VertexPosition; \n"
...@@ -256,7 +257,13 @@ VideoMaterial::VideoMaterial() ...@@ -256,7 +257,13 @@ VideoMaterial::VideoMaterial()
VideoMaterial::~VideoMaterial() VideoMaterial::~VideoMaterial()
{ {
if (!m_textureSize.isEmpty()) 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); gst_buffer_replace(&m_frame, NULL);
} }
...@@ -323,9 +330,13 @@ void VideoMaterial::initYuv420PTextureInfo(bool uvSwapped, const QSize &size) ...@@ -323,9 +330,13 @@ void VideoMaterial::initYuv420PTextureInfo(bool uvSwapped, const QSize &size)
void VideoMaterial::init(GstVideoColorMatrix colorMatrixType) void VideoMaterial::init(GstVideoColorMatrix colorMatrixType)
{ {
glGenTextures(m_textureCount, m_textureIds); QOpenGLFunctionsDef *funcs = getQOpenGLFunctions();
m_colorMatrixType = colorMatrixType; if (funcs)
updateColors(0, 0, 0, 0); {
funcs->glGenTextures(m_textureCount, m_textureIds);
m_colorMatrixType = colorMatrixType;
updateColors(0, 0, 0, 0);
}
} }
void VideoMaterial::setCurrentFrame(GstBuffer *buffer) void VideoMaterial::setCurrentFrame(GstBuffer *buffer)
...@@ -411,7 +422,10 @@ void VideoMaterial::updateColors(int brightness, int contrast, int hue, int satu ...@@ -411,7 +422,10 @@ void VideoMaterial::updateColors(int brightness, int contrast, int hue, int satu
void VideoMaterial::bind() void VideoMaterial::bind()
{ {
QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions(); QOpenGLFunctionsDef *funcs = getQOpenGLFunctions();
if (!funcs)
return;
GstBuffer *frame = NULL; GstBuffer *frame = NULL;
m_frameMutex.lock(); m_frameMutex.lock();
...@@ -422,28 +436,32 @@ void VideoMaterial::bind() ...@@ -422,28 +436,32 @@ void VideoMaterial::bind()
if (frame) { if (frame) {
GstMapInfo info; GstMapInfo info;
gst_buffer_map(frame, &info, GST_MAP_READ); gst_buffer_map(frame, &info, GST_MAP_READ);
functions->glActiveTexture(GL_TEXTURE1); funcs->glActiveTexture(GL_TEXTURE1);
bindTexture(1, info.data); bindTexture(1, info.data);
functions->glActiveTexture(GL_TEXTURE2); funcs->glActiveTexture(GL_TEXTURE2);
bindTexture(2, info.data); 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); bindTexture(0, info.data);
gst_buffer_unmap(frame, &info); gst_buffer_unmap(frame, &info);
gst_buffer_unref(frame); gst_buffer_unref(frame);
} else { } else {
functions->glActiveTexture(GL_TEXTURE1); funcs->glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_textureIds[1]); funcs->glBindTexture(GL_TEXTURE_2D, m_textureIds[1]);
functions->glActiveTexture(GL_TEXTURE2); funcs->glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, m_textureIds[2]); funcs->glBindTexture(GL_TEXTURE_2D, m_textureIds[2]);
functions->glActiveTexture(GL_TEXTURE0); // Finish with 0 as default texture unit funcs->glActiveTexture(GL_TEXTURE0); // Finish with 0 as default texture unit
glBindTexture(GL_TEXTURE_2D, m_textureIds[0]); funcs->glBindTexture(GL_TEXTURE_2D, m_textureIds[0]);
} }
} }
void VideoMaterial::bindTexture(int i, const quint8 *data) void VideoMaterial::bindTexture(int i, const quint8 *data)
{ {
glBindTexture(GL_TEXTURE_2D, m_textureIds[i]); QOpenGLFunctionsDef *funcs = getQOpenGLFunctions();
glTexImage2D( if (!funcs)
return;
funcs->glBindTexture(GL_TEXTURE_2D, m_textureIds[i]);
funcs->glTexImage2D(
GL_TEXTURE_2D, GL_TEXTURE_2D,
0, 0,
m_textureInternalFormat, m_textureInternalFormat,
...@@ -453,9 +471,9 @@ void VideoMaterial::bindTexture(int i, const quint8 *data) ...@@ -453,9 +471,9 @@ void VideoMaterial::bindTexture(int i, const quint8 *data)
m_textureFormat, m_textureFormat,
m_textureType, m_textureType,
data + m_textureOffsets[i]); data + m_textureOffsets[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); funcs->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_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