diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-12-01 00:47:30 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-12-20 15:32:42 +0100 |
commit | 4e6fc174fe02d3ddb0d3dfe5894a31502df9b1ed (patch) | |
tree | 033dca81f26edf5f662406b902ca6fe6e2fd4f5e /src/window_texture.c | |
parent | 6a6bb703bce2d844175950ede4bda5d06dc5a8ae (diff) |
follow focused
Diffstat (limited to 'src/window_texture.c')
-rw-r--r-- | src/window_texture.c | 67 |
1 files changed, 24 insertions, 43 deletions
diff --git a/src/window_texture.c b/src/window_texture.c index cea77d7..d30ef61 100644 --- a/src/window_texture.c +++ b/src/window_texture.c @@ -1,6 +1,9 @@ #include "../include/window_texture.h" #include <X11/extensions/Xcomposite.h> -#include <stdio.h> + +#define EGL_TRUE 1 +#define EGL_IMAGE_PRESERVED_KHR 0x30D2 +#define EGL_NATIVE_PIXMAP_KHR 0x30B0 static int x11_supports_composite_named_window_pixmap(Display *display) { int extension_major; @@ -18,9 +21,6 @@ int window_texture_init(WindowTexture *window_texture, Display *display, Window window_texture->window = window; window_texture->pixmap = None; window_texture->texture_id = 0; - window_texture->target_texture_id = 0; - window_texture->texture_width = 0; - window_texture->texture_height = 0; window_texture->redirected = 0; window_texture->egl = egl; @@ -38,11 +38,6 @@ static void window_texture_cleanup(WindowTexture *self, int delete_texture) { self->texture_id = 0; } - if(delete_texture && self->target_texture_id) { - self->egl->glDeleteTextures(1, &self->target_texture_id); - self->target_texture_id = 0; - } - if(self->pixmap) { XFreePixmap(self->display, self->pixmap); self->pixmap = None; @@ -57,11 +52,6 @@ void window_texture_deinit(WindowTexture *self) { window_texture_cleanup(self, 1); } - -#define EGL_TRUE 1 -#define EGL_IMAGE_PRESERVED_KHR 0x30D2 -#define EGL_NATIVE_PIXMAP_KHR 0x30B0 - int window_texture_on_resize(WindowTexture *self) { window_texture_cleanup(self, 0); @@ -84,7 +74,7 @@ int window_texture_on_resize(WindowTexture *self) { if(self->texture_id == 0) { self->egl->glGenTextures(1, &texture_id); if(texture_id == 0) { - result = 4; + result = 3; goto cleanup; } self->egl->glBindTexture(GL_TEXTURE_2D, texture_id); @@ -93,48 +83,39 @@ int window_texture_on_resize(WindowTexture *self) { texture_id = self->texture_id; } + self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + image = self->egl->eglCreateImage(self->egl->egl_display, NULL, EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer)pixmap, pixmap_attrs); if(!image) { - fprintf(stderr, "eglCreateImage failed\n"); - return -1; + result = 4; + goto cleanup; } - fprintf(stderr, "gl error: %d\n", self->egl->glGetError()); - fprintf(stderr, "image: %p\n", image); self->egl->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image); if(self->egl->glGetError() != 0) { - fprintf(stderr, "glEGLImageTargetTexture2DOES failed\n"); + result = 5; + goto cleanup; } - self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - - self->egl->glBindTexture(GL_TEXTURE_2D, 0); - self->pixmap = pixmap; - if(texture_id != 0) { - self->texture_id = texture_id; + self->texture_id = texture_id; - self->egl->glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &self->texture_width); - self->egl->glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &self->texture_height); + cleanup: + self->egl->glBindTexture(GL_TEXTURE_2D, 0); - fprintf(stderr, "texture width: %d, height: %d\n", self->texture_width, self->texture_height); + if(image) + self->egl->eglDestroyImage(self->egl->egl_display, image); - self->egl->glGenTextures(1, &self->target_texture_id); - self->egl->glBindTexture(GL_TEXTURE_2D, self->target_texture_id); - self->egl->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, self->texture_width, self->texture_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); - fprintf(stderr, "gl error: %d\n", self->egl->glGetError()); - self->egl->glBindTexture(GL_TEXTURE_2D, 0); + if(result != 0) { + if(texture_id != 0) + self->egl->glDeleteTextures(1, &texture_id); + if(pixmap) + XFreePixmap(self->display, pixmap); } - // TODO: destroyImage(image) - return 0; - - cleanup: - if(texture_id != 0) self->egl->glDeleteTextures(1, &texture_id); - if(pixmap) XFreePixmap(self->display, pixmap); return result; } |