aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/util/qsgtexture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/scenegraph/util/qsgtexture.cpp')
-rw-r--r--src/quick/scenegraph/util/qsgtexture.cpp79
1 files changed, 9 insertions, 70 deletions
diff --git a/src/quick/scenegraph/util/qsgtexture.cpp b/src/quick/scenegraph/util/qsgtexture.cpp
index d33bdffe74..042eee19f5 100644
--- a/src/quick/scenegraph/util/qsgtexture.cpp
+++ b/src/quick/scenegraph/util/qsgtexture.cpp
@@ -49,6 +49,7 @@
# include <qopenglfunctions.h>
# include <QtGui/qopenglcontext.h>
# include <QtGui/qopenglfunctions.h>
+# include <QtGui/private/qopengltextureuploader_p.h>
# include <private/qsgdefaultrendercontext_p.h>
#endif
#include <private/qsgmaterialshader_p.h>
@@ -89,7 +90,7 @@ static const bool qsg_leak_check = !qEnvironmentVariableIsEmpty("QML_LEAK_CHECK"
QT_BEGIN_NAMESPACE
-#if QT_CONFIG(opengl)
+#if QT_CONFIG(opengl) && !defined(QT_NO_DEBUG)
inline static bool isPowerOfTwo(int x)
{
// Assumption: x >= 1
@@ -755,9 +756,7 @@ void QSGPlainTexture::bind()
// ### TODO: check for out-of-memory situations...
- QImage tmp = (m_image.format() == QImage::Format_RGB32 || m_image.format() == QImage::Format_ARGB32_Premultiplied)
- ? m_image
- : m_image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
+ QOpenGLTextureUploader::BindOptions options = QOpenGLTextureUploader::PremultipliedAlphaBindOption;
// Downscale the texture to fit inside the max texture limit if it is too big.
// It would be better if the image was already downscaled to the right size,
@@ -771,75 +770,19 @@ void QSGPlainTexture::bind()
max = rc->maxTextureSize();
else
funcs->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
- if (tmp.width() > max || tmp.height() > max) {
- tmp = tmp.scaled(qMin(max, tmp.width()), qMin(max, tmp.height()), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
- m_texture_size = tmp.size();
- }
+
+ m_texture_size = m_texture_size.boundedTo(QSize(max, max));
// Scale to a power of two size if mipmapping is requested and the
// texture is npot and npot textures are not properly supported.
if (mipmapFiltering() != QSGTexture::None
- && (!isPowerOfTwo(m_texture_size.width()) || !isPowerOfTwo(m_texture_size.height()))
&& !funcs->hasOpenGLFeature(QOpenGLFunctions::NPOTTextures)) {
- tmp = tmp.scaled(qNextPowerOfTwo(m_texture_size.width()), qNextPowerOfTwo(m_texture_size.height()),
- Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
- m_texture_size = tmp.size();
+ options |= QOpenGLTextureUploader::PowerOfTwoBindOption;
}
- if (tmp.width() * 4 != tmp.bytesPerLine())
- tmp = tmp.copy();
-
- qint64 convertTime = 0;
- if (profileFrames)
- convertTime = qsg_renderer_timer.nsecsElapsed();
- Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphTexturePrepare,
- QQuickProfiler::SceneGraphTexturePrepareConvert);
-
updateBindOptions(m_dirty_bind_options);
- GLenum externalFormat = GL_RGBA;
- GLenum internalFormat = GL_RGBA;
-
-#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
- QString *deviceName =
- static_cast<QString *>(QGuiApplication::platformNativeInterface()->nativeResourceForIntegration("AndroidDeviceName"));
- static bool wrongfullyReportsBgra8888Support = deviceName != 0
- && (deviceName->compare(QLatin1String("samsung SM-T211"), Qt::CaseInsensitive) == 0
- || deviceName->compare(QLatin1String("samsung SM-T210"), Qt::CaseInsensitive) == 0
- || deviceName->compare(QLatin1String("samsung SM-T215"), Qt::CaseInsensitive) == 0);
-#else
- static bool wrongfullyReportsBgra8888Support = false;
-#endif
-
- if (context->hasExtension(QByteArrayLiteral("GL_EXT_bgra"))) {
- externalFormat = GL_BGRA;
-#ifdef QT_OPENGL_ES
- internalFormat = GL_BGRA;
-#else
- if (context->isOpenGLES())
- internalFormat = GL_BGRA;
-#endif // QT_OPENGL_ES
- } else if (!wrongfullyReportsBgra8888Support
- && (context->hasExtension(QByteArrayLiteral("GL_EXT_texture_format_BGRA8888"))
- || context->hasExtension(QByteArrayLiteral("GL_IMG_texture_format_BGRA8888")))) {
- externalFormat = GL_BGRA;
- internalFormat = GL_BGRA;
-#if defined(Q_OS_DARWIN) && !defined(Q_OS_OSX)
- } else if (context->hasExtension(QByteArrayLiteral("GL_APPLE_texture_format_BGRA8888"))) {
- externalFormat = GL_BGRA;
- internalFormat = GL_RGBA;
-#endif
- } else {
- tmp = std::move(tmp).convertToFormat(QImage::Format_RGBA8888_Premultiplied);
- }
-
- qint64 swizzleTime = 0;
- if (profileFrames)
- swizzleTime = qsg_renderer_timer.nsecsElapsed();
- Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphTexturePrepare,
- QQuickProfiler::SceneGraphTexturePrepareSwizzle);
-
- funcs->glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, m_texture_size.width(), m_texture_size.height(), 0, externalFormat, GL_UNSIGNED_BYTE, tmp.constBits());
+ QOpenGLTextureUploader::textureImage(GL_TEXTURE_2D, m_image, options, QSize(max, max));
qint64 uploadTime = 0;
if (profileFrames)
@@ -856,15 +799,11 @@ void QSGPlainTexture::bind()
if (profileFrames) {
mipmapTime = qsg_renderer_timer.nsecsElapsed();
qCDebug(QSG_LOG_TIME_TEXTURE,
- "plain texture uploaded in: %dms (%dx%d), bind=%d, convert=%d, swizzle=%d (%s->%s), upload=%d, mipmap=%d%s",
+ "plain texture uploaded in: %dms (%dx%d), bind=%d, upload=%d, mipmap=%d%s",
int(mipmapTime / 1000000),
m_texture_size.width(), m_texture_size.height(),
int(bindTime / 1000000),
- int((convertTime - bindTime)/1000000),
- int((swizzleTime - convertTime)/1000000),
- (externalFormat == GL_BGRA ? "BGRA" : "RGBA"),
- (internalFormat == GL_BGRA ? "BGRA" : "RGBA"),
- int((uploadTime - swizzleTime)/1000000),
+ int((uploadTime - bindTime)/1000000),
int((mipmapTime - uploadTime)/1000000),
m_texture_size != m_image.size() ? " (scaled to GL_MAX_TEXTURE_SIZE)" : "");
}