Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChristophHaag/fd469c353bbd015975b53d493800236f to your computer and use it in GitHub Desktop.
Save ChristophHaag/fd469c353bbd015975b53d493800236f to your computer and use it in GitHub Desktop.
kwin uninitialized texture patch
From 060728102335dbdd5541a34fec5e70f0d9122b13 Mon Sep 17 00:00:00 2001
From: Christoph Haag <christoph.haag@collabora.com>
Date: Mon, 19 Aug 2019 16:54:02 +0200
Subject: [PATCH] Make it possible to create an uninitialized GLTexture
This can be useful if the caller wants to use already existing texture memory.
For example, memory might be imported with GL_EXT_memory_object.
---
libkwineffects/kwingltexture.cpp | 20 +++++++++++++-------
libkwineffects/kwingltexture.h | 2 +-
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/libkwineffects/kwingltexture.cpp b/libkwineffects/kwingltexture.cpp
index 3818fe242..1ed512fef 100644
--- a/libkwineffects/kwingltexture.cpp
+++ b/libkwineffects/kwingltexture.cpp
@@ -190,7 +190,7 @@ GLTexture::GLTexture(const QString& fileName)
{
}
-GLTexture::GLTexture(GLenum internalFormat, int width, int height, int levels)
+GLTexture::GLTexture(GLenum internalFormat, int width, int height, int levels, bool initialize)
: d_ptr(new GLTexturePrivate())
{
Q_D(GLTexture);
@@ -210,12 +210,16 @@ GLTexture::GLTexture(GLenum internalFormat, int width, int height, int levels)
if (!GLPlatform::instance()->isGLES()) {
if (d->s_supportsTextureStorage) {
- glTexStorage2D(d->m_target, levels, internalFormat, width, height);
- d->m_immutable = true;
+ if (initialize) {
+ glTexStorage2D(d->m_target, levels, internalFormat, width, height);
+ d->m_immutable = true;
+ }
} else {
glTexParameteri(d->m_target, GL_TEXTURE_MAX_LEVEL, levels - 1);
- glTexImage2D(d->m_target, 0, internalFormat, width, height, 0,
- GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, nullptr);
+ if (initialize) {
+ glTexImage2D(d->m_target, 0, internalFormat, width, height, 0,
+ GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, nullptr);
+ }
}
d->m_internalFormat = internalFormat;
} else {
@@ -223,8 +227,10 @@ GLTexture::GLTexture(GLenum internalFormat, int width, int height, int levels)
// of the texture, so it's important that we allocate the texture with
// the format that will be used in update() and clear().
const GLenum format = d->s_supportsARGB32 ? GL_BGRA_EXT : GL_RGBA;
- glTexImage2D(d->m_target, 0, format, width, height, 0,
- format, GL_UNSIGNED_BYTE, nullptr);
+ if (initialize) {
+ glTexImage2D(d->m_target, 0, format, width, height, 0,
+ format, GL_UNSIGNED_BYTE, nullptr);
+ }
// This is technically not true, but it means that code that calls
// internalFormat() won't need to be specialized for GLES2.
diff --git a/libkwineffects/kwingltexture.h b/libkwineffects/kwingltexture.h
index 98b409848..37b2fb202 100644
--- a/libkwineffects/kwingltexture.h
+++ b/libkwineffects/kwingltexture.h
@@ -57,7 +57,7 @@ public:
explicit GLTexture(const QImage& image, GLenum target = GL_TEXTURE_2D);
explicit GLTexture(const QPixmap& pixmap, GLenum target = GL_TEXTURE_2D);
explicit GLTexture(const QString& fileName);
- GLTexture(GLenum internalFormat, int width, int height, int levels = 1);
+ GLTexture(GLenum internalFormat, int width, int height, int levels = 1, bool initialize = true);
explicit GLTexture(GLenum internalFormat, const QSize &size, int levels = 1);
virtual ~GLTexture();
--
2.23.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment