Avoid continuous texture alloc in Composition Modes example
There seems to be some confusion from back when the example were mass-ported to the QOpenGL stuff in Qt 5 times. Fixes: QTBUG-109119 Change-Id: Ic4bcd010df3fcf82e16385ce241b379f0c351788 Reviewed-by: Christian Strømme <christian.stromme@qt.io> (cherry picked from commit 919664b29a874e8cdc3d74427654cbaa2b61be29) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
6453d17a0a
commit
d2f3e3949f
@ -219,6 +219,7 @@ CompositionRenderer::CompositionRenderer(QWidget *parent)
|
|||||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
#if QT_CONFIG(opengl)
|
#if QT_CONFIG(opengl)
|
||||||
m_pbuffer_size = 1024;
|
m_pbuffer_size = 1024;
|
||||||
|
m_base_tex = 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,6 +315,7 @@ void CompositionRenderer::paint(QPainter *painter)
|
|||||||
{
|
{
|
||||||
#if QT_CONFIG(opengl)
|
#if QT_CONFIG(opengl)
|
||||||
if (usesOpenGL() && glWindow()->isValid()) {
|
if (usesOpenGL() && glWindow()->isValid()) {
|
||||||
|
auto *funcs = QOpenGLContext::currentContext()->functions();
|
||||||
|
|
||||||
if (!m_blitter.isCreated())
|
if (!m_blitter.isCreated())
|
||||||
m_blitter.create();
|
m_blitter.create();
|
||||||
@ -338,10 +340,13 @@ void CompositionRenderer::paint(QPainter *painter)
|
|||||||
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
||||||
drawBase(p);
|
drawBase(p);
|
||||||
p.end();
|
p.end();
|
||||||
|
if (m_base_tex)
|
||||||
|
funcs->glDeleteTextures(1, &m_base_tex);
|
||||||
m_base_tex = m_fbo->takeTexture();
|
m_base_tex = m_fbo->takeTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->beginNativePainting();
|
painter->beginNativePainting();
|
||||||
|
uint compositingTex;
|
||||||
{
|
{
|
||||||
QPainter p(m_fbo.get());
|
QPainter p(m_fbo.get());
|
||||||
p.beginNativePainting();
|
p.beginNativePainting();
|
||||||
@ -353,19 +358,18 @@ void CompositionRenderer::paint(QPainter *painter)
|
|||||||
p.endNativePainting();
|
p.endNativePainting();
|
||||||
drawSource(p);
|
drawSource(p);
|
||||||
p.end();
|
p.end();
|
||||||
m_compositing_tex = m_fbo->takeTexture();
|
compositingTex = m_fbo->texture();
|
||||||
}
|
}
|
||||||
painter->endNativePainting();
|
painter->endNativePainting();
|
||||||
|
|
||||||
painter->beginNativePainting();
|
painter->beginNativePainting();
|
||||||
auto *funcs = QOpenGLContext::currentContext()->functions();
|
|
||||||
funcs->glEnable(GL_BLEND);
|
funcs->glEnable(GL_BLEND);
|
||||||
funcs->glBlendEquation(GL_FUNC_ADD);
|
funcs->glBlendEquation(GL_FUNC_ADD);
|
||||||
funcs->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
funcs->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
m_blitter.bind();
|
m_blitter.bind();
|
||||||
const QRect targetRect(QPoint(0, 0), m_fbo->size());
|
const QRect targetRect(QPoint(0, 0), m_fbo->size());
|
||||||
const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, QRect(QPoint(0, 0), size()));
|
const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, QRect(QPoint(0, 0), size()));
|
||||||
m_blitter.blit(m_compositing_tex, target, QOpenGLTextureBlitter::OriginBottomLeft);
|
m_blitter.blit(compositingTex, target, QOpenGLTextureBlitter::OriginBottomLeft);
|
||||||
m_blitter.release();
|
m_blitter.release();
|
||||||
painter->endNativePainting();
|
painter->endNativePainting();
|
||||||
} else
|
} else
|
||||||
|
@ -148,7 +148,6 @@ private:
|
|||||||
std::unique_ptr<QFboPaintDevice> m_fbo;
|
std::unique_ptr<QFboPaintDevice> m_fbo;
|
||||||
int m_pbuffer_size; // width==height==size of pbuffer
|
int m_pbuffer_size; // width==height==size of pbuffer
|
||||||
uint m_base_tex;
|
uint m_base_tex;
|
||||||
uint m_compositing_tex;
|
|
||||||
QSize m_previous_size;
|
QSize m_previous_size;
|
||||||
QOpenGLTextureBlitter m_blitter;
|
QOpenGLTextureBlitter m_blitter;
|
||||||
#endif
|
#endif
|
||||||
|
@ -24,11 +24,13 @@ QFboPaintDevice::QFboPaintDevice(const QSize &size, bool flipped, bool clearOnIn
|
|||||||
context()->functions()->glClearColor(0, 0, 0, 0);
|
context()->functions()->glClearColor(0, 0, 0, 0);
|
||||||
context()->functions()->glClear(GL_COLOR_BUFFER_BIT);
|
context()->functions()->glClear(GL_COLOR_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
m_resolvedFbo = new QOpenGLFramebufferObject(m_framebufferObject->size(), m_framebufferObject->attachment());
|
||||||
}
|
}
|
||||||
|
|
||||||
QFboPaintDevice::~QFboPaintDevice()
|
QFboPaintDevice::~QFboPaintDevice()
|
||||||
{
|
{
|
||||||
delete m_framebufferObject;
|
delete m_framebufferObject;
|
||||||
|
delete m_resolvedFbo;
|
||||||
delete m_surface;
|
delete m_surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,12 +42,19 @@ void QFboPaintDevice::ensureActiveTarget()
|
|||||||
m_framebufferObject->bind();
|
m_framebufferObject->bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GLuint QFboPaintDevice::texture()
|
||||||
|
{
|
||||||
|
m_resolvedFbo->bind(); // to get the backing texture recreated if it was taken (in takeTexture) previously
|
||||||
|
QOpenGLFramebufferObject::blitFramebuffer(m_resolvedFbo, m_framebufferObject);
|
||||||
|
return m_resolvedFbo->texture();
|
||||||
|
}
|
||||||
|
|
||||||
GLuint QFboPaintDevice::takeTexture()
|
GLuint QFboPaintDevice::takeTexture()
|
||||||
{
|
{
|
||||||
// We have multisamples so we can't just forward takeTexture().
|
m_resolvedFbo->bind(); // to get the backing texture recreated if it was taken (in takeTexture) previously
|
||||||
QOpenGLFramebufferObject resolvedFbo(m_framebufferObject->size(), m_framebufferObject->attachment());
|
// We have multisamples so we can't just forward takeTexture(), have to resolve first.
|
||||||
QOpenGLFramebufferObject::blitFramebuffer(&resolvedFbo, m_framebufferObject);
|
QOpenGLFramebufferObject::blitFramebuffer(m_resolvedFbo, m_framebufferObject);
|
||||||
return resolvedFbo.takeTexture();
|
return m_resolvedFbo->takeTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage QFboPaintDevice::toImage() const
|
QImage QFboPaintDevice::toImage() const
|
||||||
|
@ -22,6 +22,7 @@ public:
|
|||||||
|
|
||||||
bool isValid() const { return m_framebufferObject->isValid(); }
|
bool isValid() const { return m_framebufferObject->isValid(); }
|
||||||
GLuint handle() const { return m_framebufferObject->handle(); }
|
GLuint handle() const { return m_framebufferObject->handle(); }
|
||||||
|
GLuint texture();
|
||||||
GLuint takeTexture();
|
GLuint takeTexture();
|
||||||
QImage toImage() const;
|
QImage toImage() const;
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QOpenGLFramebufferObject *m_framebufferObject;
|
QOpenGLFramebufferObject *m_framebufferObject;
|
||||||
|
QOpenGLFramebufferObject *m_resolvedFbo;
|
||||||
QSurface *m_surface;
|
QSurface *m_surface;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user