diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-12-03 00:07:22 (GMT) |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-12-06 21:52:53 (GMT) |
commit | 147195bccfdf90924a1525398e9c7b3119c1e278 (patch) | |
tree | 1e75453e2952568a33083e2bd0f251c43c637431 /src/opengl/qpixmapdata_gl.cpp | |
parent | 76c415b586991d978d46a888fb40c631513407dc (diff) | |
download | Qt-147195bccfdf90924a1525398e9c7b3119c1e278.zip Qt-147195bccfdf90924a1525398e9c7b3119c1e278.tar.gz Qt-147195bccfdf90924a1525398e9c7b3119c1e278.tar.bz2 |
Compressed texture binding for QtOpenGL: ETC1 and PVRTC
The QGLContext::bindTexture(QString) function has been augmented
with support for ETC1, PVRTC2, and PVRTC4 compressed textures,
in addition to the existing DDS support.
The QGLPixmapData class has also been modified to recognize
compressed texture formats in fromFile() and fromData().
This change also fixes a bug in bindTexture() that prevented
the same compressed texture file from being bound in multiple
contexts. There is now a separate file cache for each context group.
Task-number: QT-2547
Reviewed-by: Trond
Diffstat (limited to 'src/opengl/qpixmapdata_gl.cpp')
-rw-r--r-- | src/opengl/qpixmapdata_gl.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/opengl/qpixmapdata_gl.cpp b/src/opengl/qpixmapdata_gl.cpp index ab17789..0299cea 100644 --- a/src/opengl/qpixmapdata_gl.cpp +++ b/src/opengl/qpixmapdata_gl.cpp @@ -53,6 +53,8 @@ #include <private/qpaintengineex_opengl2_p.h> #include <qdesktopwidget.h> +#include <qfile.h> +#include <qimagereader.h> QT_BEGIN_NAMESPACE @@ -407,6 +409,61 @@ void QGLPixmapData::fromImage(const QImage &image, } } +bool QGLPixmapData::fromFile(const QString &filename, const char *format, + Qt::ImageConversionFlags flags) +{ + if (pixelType() == QPixmapData::BitmapType) + return QPixmapData::fromFile(filename, format, flags); + QFile file(filename); + if (!file.open(QIODevice::ReadOnly)) + return false; + QByteArray data = file.peek(64); + bool alpha; + if (m_texture.canBindCompressedTexture + (data.constData(), data.size(), format, &alpha)) { + resize(0, 0); + data = file.readAll(); + file.close(); + QSize size = m_texture.bindCompressedTexture + (data.constData(), data.size(), format); + if (!size.isEmpty()) { + w = size.width(); + h = size.height(); + is_null = false; + d = 32; + m_hasAlpha = alpha; + m_source = QImage(); + m_dirty = isValid(); + return true; + } + return false; + } + fromImage(QImageReader(&file, format).read(), flags); + return !isNull(); +} + +bool QGLPixmapData::fromData(const uchar *buffer, uint len, const char *format, + Qt::ImageConversionFlags flags) +{ + bool alpha; + const char *buf = reinterpret_cast<const char *>(buffer); + if (m_texture.canBindCompressedTexture(buf, int(len), format, &alpha)) { + resize(0, 0); + QSize size = m_texture.bindCompressedTexture(buf, int(len), format); + if (!size.isEmpty()) { + w = size.width(); + h = size.height(); + is_null = false; + d = 32; + m_hasAlpha = alpha; + m_source = QImage(); + m_dirty = isValid(); + return true; + } + } + return QPixmapData::fromData(buffer, len, format, flags); +} + bool QGLPixmapData::scroll(int dx, int dy, const QRect &rect) { Q_UNUSED(dx); |