From f22c6e2df892cbc0aff51ca0e7053c4164758f10 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 4 Feb 2015 16:24:54 +0100 Subject: Make textures functional with GLES2 OpenGL ES 2.0, unlike 3.0 and later, does not support sized formats. Therefore RGBA8_UNorm and friends will all fail. Instead, we must map and pass RGBAFormat and similar. Change-Id: I37c3581fbddc8b58af7af66ba4392e57e9cb965a Reviewed-by: Sean Harmer --- src/render/backend/rendertexture.cpp | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'src/render/backend/rendertexture.cpp') diff --git a/src/render/backend/rendertexture.cpp b/src/render/backend/rendertexture.cpp index 737bccdda..f60d150b9 100644 --- a/src/render/backend/rendertexture.cpp +++ b/src/render/backend/rendertexture.cpp @@ -212,14 +212,36 @@ QOpenGLTexture *RenderTexture::getOrCreateGLTexture() // RenderThread QOpenGLTexture *RenderTexture::buildGLTexture() { + QOpenGLContext *ctx = QOpenGLContext::currentContext(); + if (!ctx) { + qWarning() << Q_FUNC_INFO << "requires an OpenGL context"; + return Q_NULLPTR; + } + QOpenGLTexture* glTex = new QOpenGLTexture(static_cast(m_target)); if (m_format == QAbstractTextureProvider::Automatic) qWarning() << Q_FUNC_INFO << "something went wrong, format shouldn't be automatic at this point"; - glTex->setFormat(m_format == QAbstractTextureProvider::Automatic ? + // m_format may not be ES2 compatible. Now it's time to convert it, if necessary. + QAbstractTextureProvider::TextureFormat format = m_format; + if (ctx->isOpenGLES() && ctx->format().majorVersion() < 3) { + switch (m_format) { + case QOpenGLTexture::RGBA8_UNorm: + format = QAbstractTextureProvider::RGBAFormat; + break; + case QOpenGLTexture::RGB8_UNorm: + format = QAbstractTextureProvider::RGBFormat; + break; + default: + qWarning() << Q_FUNC_INFO << "could not find a matching OpenGL ES 2.0 unsized texture format"; + break; + } + } + + glTex->setFormat(format == QAbstractTextureProvider::Automatic ? QOpenGLTexture::NoFormat : - static_cast(m_format)); + static_cast(format)); glTex->setSize(m_width, m_height, m_depth); // Set layers count if texture array if (m_target == QAbstractTextureProvider::Target1DArray || @@ -240,11 +262,9 @@ QOpenGLTexture *RenderTexture::buildGLTexture() // FIXME : make this conditional on Qt version // work-around issue in QOpenGLTexture DSA emulaation which rasies // an Invalid Enum error - if (QOpenGLContext *ctx = QOpenGLContext::currentContext()) { - int err = ctx->functions()->glGetError(); - if (err) - qWarning() << Q_FUNC_INFO << err; - } + int err = ctx->functions()->glGetError(); + if (err) + qWarning() << Q_FUNC_INFO << err; return glTex; } -- cgit v1.2.3