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/f99493f373248d6ee69dd6994000a2f9 to your computer and use it in GitHub Desktop.
Save ChristophHaag/f99493f373248d6ee69dd6994000a2f9 to your computer and use it in GitHub Desktop.
From 5b369d50098db47eace62e76d86ac22f09d2f506 Mon Sep 17 00:00:00 2001
From: Christoph Haag <christoph.haag@collabora.com>
Date: Mon, 19 Aug 2019 17:31:11 +0200
Subject: [PATCH] Add constructor to GLTexture using GL_EXT_memory_object
Instead of allocating memory for the texture with OpenGL, import the memory from an FD.
---
libkwineffects/kwingltexture.cpp | 31 +++++++++++++++++++++++++++++++
libkwineffects/kwingltexture.h | 1 +
2 files changed, 32 insertions(+)
diff --git a/libkwineffects/kwingltexture.cpp b/libkwineffects/kwingltexture.cpp
index 3818fe242..e0e924cbf 100644
--- a/libkwineffects/kwingltexture.cpp
+++ b/libkwineffects/kwingltexture.cpp
@@ -234,6 +234,37 @@ GLTexture::GLTexture(GLenum internalFormat, int width, int height, int levels)
unbind();
}
+GLTexture::GLTexture(GLenum internalFormat, int width, int height, int fd, size_t size, int levels)
+ : d_ptr(new GLTexturePrivate())
+{
+ Q_D(GLTexture);
+
+ d->m_target = GL_TEXTURE_2D;
+ d->m_scale.setWidth(1.0 / width);
+ d->m_scale.setHeight(1.0 / height);
+ d->m_size = QSize(width, height);
+ d->m_canUseMipmaps = levels > 1;
+ d->m_mipLevels = levels;
+ d->m_filter = levels > 1 ? GL_NEAREST_MIPMAP_LINEAR : GL_NEAREST;
+
+ d->updateMatrix();
+
+ glGenTextures(1, &d->m_texture);
+ bind();
+
+ GLuint memObject = 0;
+ glCreateMemoryObjectsEXT(1, &memObject);
+
+ GLint dedicated = GL_TRUE;
+ glMemoryObjectParameterivEXT(memObject, GL_DEDICATED_MEMORY_OBJECT_EXT, &dedicated);
+ glGetMemoryObjectParameterivEXT(memObject, GL_DEDICATED_MEMORY_OBJECT_EXT, &dedicated);
+ glImportMemoryFdEXT(memObject, size, GL_HANDLE_TYPE_OPAQUE_FD_EXT, fd);
+ glTexStorageMem2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, width, height, memObject, 0);
+ glDeleteMemoryObjectsEXT(1, &memObject);
+
+ unbind();
+}
+
GLTexture::GLTexture(GLenum internalFormat, const QSize &size, int levels)
: GLTexture(internalFormat, size.width(), size.height(), levels)
{
diff --git a/libkwineffects/kwingltexture.h b/libkwineffects/kwingltexture.h
index 98b409848..48d7fc6f1 100644
--- a/libkwineffects/kwingltexture.h
+++ b/libkwineffects/kwingltexture.h
@@ -58,6 +58,7 @@ public:
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 fd, size_t size, int levels = 1);
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