Support dynamic opengl32 - ANGLE switching on Windows
Change-Id: I38532db3ab0ad4fcb8dbabd0cbb528f7d8e4ba06 Reviewed-by: Andrew Knight <andrew.knight@digia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
@@ -236,7 +236,7 @@ QSGVideoMaterial_YUV420::QSGVideoMaterial_YUV420(const QVideoSurfaceFormat &form
|
||||
QSGVideoMaterial_YUV420::~QSGVideoMaterial_YUV420()
|
||||
{
|
||||
if (!m_textureSize.isEmpty())
|
||||
glDeleteTextures(Num_Texture_IDs, m_textureIds);
|
||||
QOpenGLContext::currentContext()->functions()->glDeleteTextures(Num_Texture_IDs, m_textureIds);
|
||||
}
|
||||
|
||||
void QSGVideoMaterial_YUV420::bind()
|
||||
@@ -252,8 +252,8 @@ void QSGVideoMaterial_YUV420::bind()
|
||||
// Frame has changed size, recreate textures...
|
||||
if (m_textureSize != m_frame.size()) {
|
||||
if (!m_textureSize.isEmpty())
|
||||
glDeleteTextures(Num_Texture_IDs, m_textureIds);
|
||||
glGenTextures(Num_Texture_IDs, m_textureIds);
|
||||
functions->glDeleteTextures(Num_Texture_IDs, m_textureIds);
|
||||
functions->glGenTextures(Num_Texture_IDs, m_textureIds);
|
||||
m_textureSize = m_frame.size();
|
||||
}
|
||||
|
||||
@@ -265,8 +265,8 @@ void QSGVideoMaterial_YUV420::bind()
|
||||
m_uvWidth = qreal(fw) / (2 * m_frame.bytesPerLine(u));
|
||||
|
||||
GLint previousAlignment;
|
||||
glGetIntegerv(GL_UNPACK_ALIGNMENT, &previousAlignment);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
functions->glGetIntegerv(GL_UNPACK_ALIGNMENT, &previousAlignment);
|
||||
functions->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
functions->glActiveTexture(GL_TEXTURE1);
|
||||
bindTexture(m_textureIds[1], m_frame.bytesPerLine(u), fh / 2, m_frame.bits(u));
|
||||
@@ -275,7 +275,7 @@ void QSGVideoMaterial_YUV420::bind()
|
||||
functions->glActiveTexture(GL_TEXTURE0); // Finish with 0 as default texture unit
|
||||
bindTexture(m_textureIds[0], m_frame.bytesPerLine(y), fh, m_frame.bits(y));
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, previousAlignment);
|
||||
functions->glPixelStorei(GL_UNPACK_ALIGNMENT, previousAlignment);
|
||||
|
||||
m_frame.unmap();
|
||||
}
|
||||
@@ -283,22 +283,24 @@ void QSGVideoMaterial_YUV420::bind()
|
||||
m_frame = QVideoFrame();
|
||||
} else {
|
||||
functions->glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, m_textureIds[1]);
|
||||
functions->glBindTexture(GL_TEXTURE_2D, m_textureIds[1]);
|
||||
functions->glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, m_textureIds[2]);
|
||||
functions->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]);
|
||||
functions->glBindTexture(GL_TEXTURE_2D, m_textureIds[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void QSGVideoMaterial_YUV420::bindTexture(int id, int w, int h, const uchar *bits)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, w, h, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, bits);
|
||||
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);
|
||||
QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
|
||||
|
||||
functions->glBindTexture(GL_TEXTURE_2D, id);
|
||||
functions->glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, w, h, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, bits);
|
||||
functions->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
functions->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
functions->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
functions->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
QSGVideoNode_I420::QSGVideoNode_I420(const QVideoSurfaceFormat &format) :
|
||||
|
||||
@@ -176,7 +176,7 @@ public:
|
||||
~QSGVideoMaterial_RGB()
|
||||
{
|
||||
if (m_textureId)
|
||||
glDeleteTextures(1, &m_textureId);
|
||||
QOpenGLContext::currentContext()->functions()->glDeleteTextures(1, &m_textureId);
|
||||
}
|
||||
|
||||
virtual QSGMaterialType *type() const {
|
||||
@@ -225,8 +225,8 @@ public:
|
||||
|
||||
if (m_textureSize != textureSize) {
|
||||
if (!m_textureSize.isEmpty())
|
||||
glDeleteTextures(1, &m_textureId);
|
||||
glGenTextures(1, &m_textureId);
|
||||
functions->glDeleteTextures(1, &m_textureId);
|
||||
functions->glGenTextures(1, &m_textureId);
|
||||
m_textureSize = textureSize;
|
||||
}
|
||||
|
||||
@@ -239,28 +239,28 @@ public:
|
||||
}
|
||||
|
||||
GLint previousAlignment;
|
||||
glGetIntegerv(GL_UNPACK_ALIGNMENT, &previousAlignment);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
functions->glGetIntegerv(GL_UNPACK_ALIGNMENT, &previousAlignment);
|
||||
functions->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
functions->glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_textureId);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, dataFormat,
|
||||
m_textureSize.width(), m_textureSize.height(),
|
||||
0, dataFormat, dataType, m_frame.bits());
|
||||
functions->glBindTexture(GL_TEXTURE_2D, m_textureId);
|
||||
functions->glTexImage2D(GL_TEXTURE_2D, 0, dataFormat,
|
||||
m_textureSize.width(), m_textureSize.height(),
|
||||
0, dataFormat, dataType, m_frame.bits());
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, previousAlignment);
|
||||
functions->glPixelStorei(GL_UNPACK_ALIGNMENT, previousAlignment);
|
||||
|
||||
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);
|
||||
functions->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
functions->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
functions->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
functions->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
m_frame.unmap();
|
||||
}
|
||||
m_frame = QVideoFrame();
|
||||
} else {
|
||||
functions->glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_textureId);
|
||||
functions->glBindTexture(GL_TEXTURE_2D, m_textureId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include <QtGui/QOpenGLContext>
|
||||
#include <QtGui/QOpenGLFunctions>
|
||||
#include <QtGui/QOpenGLShaderProgram>
|
||||
#include <QtMultimedia/private/qmediaopenglhelper_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@@ -120,7 +121,6 @@ protected:
|
||||
" gl_FragColor = texture2D(rgbTexture, qt_TexCoord) * opacity;"
|
||||
"}";
|
||||
|
||||
#ifndef QT_OPENGL_ES_2_ANGLE
|
||||
static const char *colorsSwapShader =
|
||||
"uniform sampler2D rgbTexture;"
|
||||
"uniform lowp float opacity;"
|
||||
@@ -132,17 +132,17 @@ protected:
|
||||
" gl_FragColor = vec4(texture2D(rgbTexture, qt_TexCoord).bgr, 1.0) * opacity;"
|
||||
"}";
|
||||
|
||||
|
||||
switch (m_pixelFormat) {
|
||||
if (!QMediaOpenGLHelper::isANGLE()) {
|
||||
switch (m_pixelFormat) {
|
||||
case QVideoFrame::Format_RGB32:
|
||||
case QVideoFrame::Format_ARGB32:
|
||||
return colorsSwapShader;
|
||||
default:
|
||||
return shader;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
return shader;
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual void initialize() {
|
||||
@@ -210,12 +210,13 @@ public:
|
||||
QMutexLocker lock(&m_frameMutex);
|
||||
if (m_frame.isValid()) {
|
||||
m_textureId = m_frame.handle().toUInt();
|
||||
glBindTexture(GL_TEXTURE_2D, m_textureId);
|
||||
QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
|
||||
functions->glBindTexture(GL_TEXTURE_2D, m_textureId);
|
||||
|
||||
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);
|
||||
functions->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
functions->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
functions->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
functions->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
} else {
|
||||
m_textureId = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user