Commit 8983c746 authored by Gus Grubba's avatar Gus Grubba

Fixing OpenGL issues for Windows (Video Streaming)

parent 77be5c4b
......@@ -27,6 +27,7 @@
#include <QStack>
#include <QPainter>
#include <QOpenGLFunctions_2_0>
QtVideoSinkDelegate::QtVideoSinkDelegate(GstElement *sink, QObject *parent)
: BaseDelegate(sink, parent)
......@@ -137,20 +138,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());
QOpenGLFunctions_2_0 *funcs = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_2_0>();
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);
......
......@@ -26,7 +26,7 @@
#include <qmath.h>
#include <QOpenGLContext>
#include <QOpenGLFunctions>
#include <QOpenGLFunctions_2_0>
#include <QtQuick/QSGMaterialShader>
static const char * const qtvideosink_glsl_vertexShader =
......@@ -256,7 +256,13 @@ VideoMaterial::VideoMaterial()
VideoMaterial::~VideoMaterial()
{
if (!m_textureSize.isEmpty())
glDeleteTextures(m_textureCount, m_textureIds);
{
QOpenGLFunctions_2_0 *funcs = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_2_0>();
if (funcs)
{
funcs->glDeleteTextures(m_textureCount, m_textureIds);
}
}
gst_buffer_replace(&m_frame, NULL);
}
......@@ -323,9 +329,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);
QOpenGLFunctions_2_0 *funcs = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_2_0>();
if (funcs)
{
funcs->glGenTextures(m_textureCount, m_textureIds);
m_colorMatrixType = colorMatrixType;
updateColors(0, 0, 0, 0);
}
}
void VideoMaterial::setCurrentFrame(GstBuffer *buffer)
......@@ -411,7 +421,10 @@ void VideoMaterial::updateColors(int brightness, int contrast, int hue, int satu
void VideoMaterial::bind()
{
QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
QOpenGLFunctions_2_0 *funcs = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_2_0>();
if (!funcs)
return;
GstBuffer *frame = NULL;
m_frameMutex.lock();
......@@ -422,28 +435,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(
QOpenGLFunctions_2_0 *funcs = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_2_0>();
if (!funcs)
return;
funcs->glBindTexture(GL_TEXTURE_2D, m_textureIds[i]);
funcs->glTexImage2D(
GL_TEXTURE_2D,
0,
m_textureInternalFormat,
......@@ -453,9 +470,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);
}
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