From 67af7cdb7d0ac048b33be9bbd6cea93c5dc74e9b Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Thu, 2 Dec 2010 20:18:23 +0100 Subject: Get shader effect item working again with image sources --- src/adaptationlayers/adaptationinterfaces.cpp | 1 + src/adaptationlayers/adaptationinterfaces.h | 6 +++ .../default/default_texturemanager.cpp | 7 ++- src/effects/shadereffectitem.cpp | 55 +++++++++++----------- 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/adaptationlayers/adaptationinterfaces.cpp b/src/adaptationlayers/adaptationinterfaces.cpp index e68624d..b6e9355 100644 --- a/src/adaptationlayers/adaptationinterfaces.cpp +++ b/src/adaptationlayers/adaptationinterfaces.cpp @@ -51,6 +51,7 @@ TextureReference::TextureReference() , m_sub_rect(0, 0, 1, 1) , m_has_alpha(false) , m_owns_texture(false) + , m_mipmap(false) { } diff --git a/src/adaptationlayers/adaptationinterfaces.h b/src/adaptationlayers/adaptationinterfaces.h index 9012210..66dd75b 100644 --- a/src/adaptationlayers/adaptationinterfaces.h +++ b/src/adaptationlayers/adaptationinterfaces.h @@ -155,6 +155,9 @@ public: void setOwnsTexture(bool owns) { m_owns_texture = owns; } bool ownsTexture() const { return m_owns_texture; } + void setMipmaps(bool mipmapped) { m_mipmap = mipmapped; } + bool hasMipmaps() const { return m_mipmap; } + void setStatus(Status s); Status status() const { return m_status; } @@ -171,6 +174,7 @@ protected: uint m_has_alpha : 1; uint m_owns_texture : 1; + uint m_mipmap : 1; }; class TextureManager @@ -180,6 +184,8 @@ public: SynchronousUploadHint = 0x0001, CanUseAtlasUploadHint = 0x0002, + GenerateMipmapUploadHint = 0x0004, + DefaultUploadHints = 0 }; Q_DECLARE_FLAGS(UploadHints, UploadHint); diff --git a/src/adaptationlayers/default/default_texturemanager.cpp b/src/adaptationlayers/default/default_texturemanager.cpp index 58da9d5..6f854a9 100644 --- a/src/adaptationlayers/default/default_texturemanager.cpp +++ b/src/adaptationlayers/default/default_texturemanager.cpp @@ -48,10 +48,15 @@ DefaultTextureManager::DefaultTextureManager() TextureReference *DefaultTextureManager::requestUploadedTexture(const QImage &image, UploadHints hints) { QGLContext *context = const_cast(QGLContext::currentContext()); + + QGLContext::BindOptions options = QGLContext::PremultipliedAlphaBindOption; + if (hints & GenerateMipmapUploadHint) + options |= QGLContext::MipmapBindOption; + int id = context->bindTexture(image, GL_TEXTURE_2D, image.hasAlphaChannel() ? GL_RGBA : GL_RGB, - QGLContext::PremultipliedAlphaBindOption); + options); TextureReference *ref = new TextureReference(); ref->setTextureId(id); diff --git a/src/effects/shadereffectitem.cpp b/src/effects/shadereffectitem.cpp index eda7256..77483a0 100644 --- a/src/effects/shadereffectitem.cpp +++ b/src/effects/shadereffectitem.cpp @@ -259,12 +259,12 @@ void ShaderEffectSource::setMipmap(FilterMode mode) delete m_fbo; m_fbo = 0; } else if (m_texture) { - // ### gunnar: port properly -// Q_ASSERT(!m_sourceImage.isEmpty()); -// if (~m_texture->bindOptions() & QGLContext::MipmapBindOption) { -// m_texture.clear(); -// updateSizeAndTexture(); -// } + Q_ASSERT(!m_sourceImage.isEmpty()); + if (!m_texture->hasMipmaps()) { + delete m_texture; + m_texture = 0; + updateSizeAndTexture(); + } } m_dirtyTexture = true; } @@ -476,28 +476,27 @@ void ShaderEffectSource::updateSizeAndTexture() m_fbo = 0; } if (!m_sourceImage.isEmpty()) { - // ### gunnar: port properly -// m_texture = QGLTexture2DPtr(new QGLTexture2D); -// QGLContext::BindOption mipmap = m_mipmap != None -// ? QGLContext::MipmapBindOption : QGLContext::BindOption(0); -// m_texture->setBindOptions(QGLContext::InternalBindOption | mipmap); - -// // TODO: Implement async loading and loading over network. -// QImageReader reader(m_sourceImage.toLocalFile()); -// if (!m_textureSize.isEmpty()) -// reader.setScaledSize(m_textureSize); -// QImage image = reader.read(); -// if (image.isNull()) -// qWarning() << reader.errorString(); -// m_texture->setImage(image.mirrored()); -// if (m_size.width() != image.width()) { -// m_size.setWidth(image.width()); -// emit widthChanged(); -// } -// if (m_size.height() != image.height()) { -// m_size.setHeight(image.height()); -// emit heightChanged(); -// } + // TODO: Implement async loading and loading over network. + QImageReader reader(m_sourceImage.toLocalFile()); + if (!m_textureSize.isEmpty()) + reader.setScaledSize(m_textureSize); + QImage image = reader.read(); + if (image.isNull()) + qWarning() << reader.errorString(); + if (m_size.width() != image.width()) { + m_size.setWidth(image.width()); + emit widthChanged(); + } + if (m_size.height() != image.height()) { + m_size.setHeight(image.height()); + emit heightChanged(); + } + TextureManager *tm = qt_adaptation_layer()->textureManager(); + TextureManager::UploadHints hints = TextureManager::SynchronousUploadHint; + if (m_mipmap != None) + hints |= TextureManager::GenerateMipmapUploadHint; + m_texture = tm->requestUploadedTexture(image.mirrored(), hints); + } else { if (m_size.width() != 0) { m_size.setWidth(0); -- cgit v1.2.3