summaryrefslogtreecommitdiffstats
path: root/src/render/backend/rendertexture.cpp
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-02-04 16:24:54 +0100
committerSean Harmer <sean.harmer@kdab.com>2015-02-08 15:02:45 +0000
commitf22c6e2df892cbc0aff51ca0e7053c4164758f10 (patch)
tree26a0002d5d407a8b47c496509da57a0db7ae773b /src/render/backend/rendertexture.cpp
parent19ec465ede900f2e1f13dd45527e12ac9bc44fd6 (diff)
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 <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/backend/rendertexture.cpp')
-rw-r--r--src/render/backend/rendertexture.cpp34
1 files changed, 27 insertions, 7 deletions
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<QOpenGLTexture::Target>(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<QOpenGLTexture::TextureFormat>(m_format));
+ static_cast<QOpenGLTexture::TextureFormat>(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;
}