From 66ba21971b24942c7481eeb4a4ff156f54ea658a Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 5 Feb 2014 15:54:36 +0100 Subject: Support dynamic opengl32 - ANGLE switching on Windows Change-Id: I38532db3ab0ad4fcb8dbabd0cbb528f7d8e4ba06 Reviewed-by: Andrew Knight Reviewed-by: Friedemann Kleint --- src/qtmultimediaquicktools/qsgvideonode_i420.cpp | 32 ++++++++++++---------- src/qtmultimediaquicktools/qsgvideonode_rgb.cpp | 30 ++++++++++---------- .../qsgvideonode_texture.cpp | 23 ++++++++-------- 3 files changed, 44 insertions(+), 41 deletions(-) (limited to 'src/qtmultimediaquicktools') diff --git a/src/qtmultimediaquicktools/qsgvideonode_i420.cpp b/src/qtmultimediaquicktools/qsgvideonode_i420.cpp index 2d904f8eb..aac9f6d70 100644 --- a/src/qtmultimediaquicktools/qsgvideonode_i420.cpp +++ b/src/qtmultimediaquicktools/qsgvideonode_i420.cpp @@ -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) : diff --git a/src/qtmultimediaquicktools/qsgvideonode_rgb.cpp b/src/qtmultimediaquicktools/qsgvideonode_rgb.cpp index ad01a08ae..5911cb19b 100644 --- a/src/qtmultimediaquicktools/qsgvideonode_rgb.cpp +++ b/src/qtmultimediaquicktools/qsgvideonode_rgb.cpp @@ -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); } } diff --git a/src/qtmultimediaquicktools/qsgvideonode_texture.cpp b/src/qtmultimediaquicktools/qsgvideonode_texture.cpp index 2320387b1..45d2736fb 100644 --- a/src/qtmultimediaquicktools/qsgvideonode_texture.cpp +++ b/src/qtmultimediaquicktools/qsgvideonode_texture.cpp @@ -45,6 +45,7 @@ #include #include #include +#include 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; } -- cgit v1.2.3