Paste P472

Masterwork From Distant Lands
ActivePublic

Authored by davidedmundson on Sep 24 2019, 9:11 PM.
commit 3a00be096b983eee3c6b699d4387883f5b1ed5cd
Author: David Edmundson <kde@davidedmundson.co.uk>
Date: Tue Sep 24 13:00:34 2019 +0100
KWinGLTexture support externally generated textures
diff --git a/libkwineffects/kwingltexture.cpp b/libkwineffects/kwingltexture.cpp
index 3818fe242..e4c6b57a3 100644
--- a/libkwineffects/kwingltexture.cpp
+++ b/libkwineffects/kwingltexture.cpp
@@ -239,6 +239,24 @@ GLTexture::GLTexture(GLenum internalFormat, const QSize &size, int levels)
{
}
+GLTexture::GLTexture(GLuint textureId, GLenum internalFormat, const QSize &size, int levels)
+ : d_ptr(new GLTexturePrivate())
+{
+ Q_D(GLTexture);
+ d->m_foreign = true;
+ d->m_texture = textureId;
+ d->m_target = GL_TEXTURE_2D;
+ d->m_scale.setWidth(1.0 / size.width());
+ d->m_scale.setHeight(1.0 / size.height());
+ d->m_size = size;
+ d->m_canUseMipmaps = levels > 1;
+ d->m_mipLevels = levels;
+ d->m_filter = levels > 1 ? GL_NEAREST_MIPMAP_LINEAR : GL_NEAREST;
+ d->m_internalFormat = internalFormat;
+
+ d->updateMatrix();
+}
+
GLTexture::~GLTexture()
{
}
@@ -261,6 +279,7 @@ GLTexturePrivate::GLTexturePrivate()
, m_filterChanged(true)
, m_wrapModeChanged(false)
, m_immutable(false)
+ , m_foreign(false)
, m_mipLevels(1)
, m_unnormalizeActive(0)
, m_normalizeActive(0)
@@ -272,7 +291,7 @@ GLTexturePrivate::GLTexturePrivate()
GLTexturePrivate::~GLTexturePrivate()
{
delete m_vbo;
- if (m_texture != 0) {
+ if (m_texture != 0 && !m_foreign) {
glDeleteTextures(1, &m_texture);
}
// Delete the FBO if this is the last Texture
@@ -333,6 +352,7 @@ void GLTexture::update(const QImage &image, const QPoint &offset, const QRect &s
return;
Q_D(GLTexture);
+ Q_ASSERT(!d->m_foreign);
bool useUnpack = !src.isNull() && d->s_supportsUnpack && d->s_supportsARGB32 && image.format() == QImage::Format_ARGB32_Premultiplied;
@@ -510,6 +530,7 @@ GLenum GLTexture::internalFormat() const
void GLTexture::clear()
{
Q_D(GLTexture);
+ Q_ASSERT(!d->m_foreign);
if (!GLTexturePrivate::s_fbo && GLRenderTarget::supported() &&
GLPlatform::instance()->driver() != Driver_Catalyst) // fail. -> bug #323065
glGenFramebuffers(1, &GLTexturePrivate::s_fbo);
diff --git a/libkwineffects/kwingltexture.h b/libkwineffects/kwingltexture.h
index 98b409848..6009c29e5 100644
--- a/libkwineffects/kwingltexture.h
+++ b/libkwineffects/kwingltexture.h
@@ -59,6 +59,10 @@ public:
explicit GLTexture(const QString& fileName);
GLTexture(GLenum internalFormat, int width, int height, int levels = 1);
explicit GLTexture(GLenum internalFormat, const QSize &size, int levels = 1);
+ /** Create a GLTexture wrapper round an existing texture
+ * Management of the textureID remains the responsibility of the caller
+ */
+ explicit GLTexture(GLuint textureId, GLenum internalFormat, const QSize &size, int levels = 1);
virtual ~GLTexture();
GLTexture & operator = (const GLTexture& tex);
diff --git a/libkwineffects/kwingltexture_p.h b/libkwineffects/kwingltexture_p.h
index 0eaca55b0..68d0847e0 100644
--- a/libkwineffects/kwingltexture_p.h
+++ b/libkwineffects/kwingltexture_p.h
@@ -63,6 +63,7 @@ public:
bool m_filterChanged;
bool m_wrapModeChanged;
bool m_immutable;
+ bool m_foreign;
int m_mipLevels;
int m_unnormalizeActive; // 0 - no, otherwise refcount
davidedmundson edited the content of this paste. (Show Details)Sep 24 2019, 9:11 PM
davidedmundson changed the title of this paste from untitled to Masterwork From Distant Lands.
davidedmundson edited the content of this paste. (Show Details)Sep 24 2019, 9:12 PM