diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-11-20 10:04:28 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-12-12 22:26:49 +0000 |
commit | fc2ec95587c431b1916ec5590b7ef634be96c985 (patch) | |
tree | 37e38ef0fbf21af77001bc97f1080dd6ae92edef /src/gui/opengl/qopengltextureuploader.cpp | |
parent | d20c9805763ab3dc504ebf2cefd33499d89ef22c (diff) |
Add Grayscale16 Image Format
[ChangeLog][QtGui][QImage] Added support for 16-bit grayscale format.
Together-with: Aaron Linville<aaron@linville.org>
Task-number: QTBUG-41176
Change-Id: I5fe4f54a55ebe1413aa71b882c19627fe22362ac
Reviewed-by: Nick D'Ademo <nickdademo@gmail.com>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/gui/opengl/qopengltextureuploader.cpp')
-rw-r--r-- | src/gui/opengl/qopengltextureuploader.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/gui/opengl/qopengltextureuploader.cpp b/src/gui/opengl/qopengltextureuploader.cpp index 42e309b733..90253546c8 100644 --- a/src/gui/opengl/qopengltextureuploader.cpp +++ b/src/gui/opengl/qopengltextureuploader.cpp @@ -104,7 +104,7 @@ qsizetype QOpenGLTextureUploader::textureImage(GLenum target, const QImage &imag const bool isOpenGLES3orBetter = context->isOpenGLES() && context->format().majorVersion() >= 3; const bool sRgbBinding = (options & SRgbBindOption); Q_ASSERT(isOpenGL12orBetter || context->isOpenGLES()); - Q_ASSERT((options & (SRgbBindOption | UseRedFor8BitBindOption)) != (SRgbBindOption | UseRedFor8BitBindOption)); + Q_ASSERT((options & (SRgbBindOption | UseRedForAlphaAndLuminanceBindOption)) != (SRgbBindOption | UseRedForAlphaAndLuminanceBindOption)); switch (image.format()) { case QImage::Format_RGB32: @@ -213,7 +213,7 @@ qsizetype QOpenGLTextureUploader::textureImage(GLenum target, const QImage &imag if (sRgbBinding) { // Always needs conversion break; - } else if (options & UseRedFor8BitBindOption) { + } else if (options & UseRedForAlphaAndLuminanceBindOption) { externalFormat = internalFormat = GL_RED; pixelType = GL_UNSIGNED_BYTE; targetFormat = image.format(); @@ -223,7 +223,7 @@ qsizetype QOpenGLTextureUploader::textureImage(GLenum target, const QImage &imag if (sRgbBinding) { // Always needs conversion break; - } else if (options & UseRedFor8BitBindOption) { + } else if (options & UseRedForAlphaAndLuminanceBindOption) { externalFormat = internalFormat = GL_RED; pixelType = GL_UNSIGNED_BYTE; targetFormat = image.format(); @@ -243,7 +243,7 @@ qsizetype QOpenGLTextureUploader::textureImage(GLenum target, const QImage &imag if (sRgbBinding) { // Always needs conversion break; - } else if (options & UseRedFor8BitBindOption) { + } else if (options & UseRedForAlphaAndLuminanceBindOption) { externalFormat = internalFormat = GL_RED; pixelType = GL_UNSIGNED_BYTE; targetFormat = image.format(); @@ -259,6 +259,26 @@ qsizetype QOpenGLTextureUploader::textureImage(GLenum target, const QImage &imag targetFormat = image.format(); } break; + case QImage::Format_Grayscale16: + if (sRgbBinding) { + // Always needs conversion + break; + } else if (options & UseRedForAlphaAndLuminanceBindOption) { + externalFormat = internalFormat = GL_RED; + pixelType = GL_UNSIGNED_SHORT; + targetFormat = image.format(); + } else if (context->isOpenGLES() || context->format().profile() != QSurfaceFormat::CoreProfile) { + externalFormat = internalFormat = GL_LUMINANCE; + pixelType = GL_UNSIGNED_SHORT; + targetFormat = image.format(); + } else if (funcs->hasOpenGLExtension(QOpenGLExtensions::TextureSwizzle)) { + GLint swizzle[4] = { GL_RED, GL_RED, GL_RED, GL_ONE }; + funcs->glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle); + externalFormat = internalFormat = GL_RED; + pixelType = GL_UNSIGNED_SHORT; + targetFormat = image.format(); + } + break; default: break; } |