aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Draxinger <code@datenwolf.net>2020-12-31 17:43:05 +0100
committerWolfgang Draxinger <code@datenwolf.net>2020-12-31 17:43:05 +0100
commit6e51b002dba2b88383ff88c5e62a32f563760ece (patch)
tree59f9fa09e34e73c379a044bd14d4a6b503d8f2e0
parenta94861b09ae9e7e8edce1eb518cb5e5f20e328a3 (diff)
downloadcopy_pixels_swap_hack-master.tar.gz
copy_pixels_swap_hack-master.tar.bz2
copy back front buffer to back buffer after swap to replicate behavior of copy back to frontHEADmaster
-rw-r--r--copy_pixels_swap_hack.c74
1 files changed, 44 insertions, 30 deletions
diff --git a/copy_pixels_swap_hack.c b/copy_pixels_swap_hack.c
index 653eeaf..2aff551 100644
--- a/copy_pixels_swap_hack.c
+++ b/copy_pixels_swap_hack.c
@@ -15,53 +15,67 @@
#include <dlfcn.h>
#include <GL/gl.h>
#include <GL/glx.h>
+#include <X11/Xlib.h>
void glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type)
{
static int first = 1;
- static Display* (*glx_get_current_display)(void) = NULL;
- static GLXDrawable (*glx_get_current_drawable)(void) = NULL;
- static void (*glx_swap_buffers)(Display*,GLXDrawable) = NULL;
- static void (*gl_copy_pixels)(GLint,GLint,GLsizei,GLsizei,GLenum) = NULL;
- static void (*gl_get_integerv)(GLenum,GLint*) = NULL;
- static void (*gl_draw_buffer)(GLenum) = NULL;
- static void (*gl_read_buffer)(GLenum) = NULL;
+ static Display* (*glX_GetCurrentDisplay)(void) = NULL;
+ static GLXDrawable (*glX_GetCurrentDrawable)(void) = NULL;
+ static Status (*X_GetGeometry)(Display*,Drawable,Window*,int*,int*,unsigned*,unsigned*,unsigned*,unsigned*);
+ static void (*glX_SwapBuffers)(Display*,GLXDrawable) = NULL;
+ static void (*gl_WindowPos3i)(GLint,GLint,GLint) = NULL;
+ static void (*gl_CopyPixels)(GLint,GLint,GLsizei,GLsizei,GLenum) = NULL;
+ static void (*gl_GetIntegerv)(GLenum,GLint*) = NULL;
+ static void (*gl_DrawBuffer)(GLenum) = NULL;
+ static void (*gl_ReadBuffer)(GLenum) = NULL;
if( first ){
- *(void**)(&glx_get_current_display) = dlsym(RTLD_NEXT, "glXGetCurrentDisplay");
- *(void**)(&glx_get_current_drawable) = dlsym(RTLD_NEXT, "glXGetCurrentDrawable");
- *(void**)(&glx_swap_buffers) = dlsym(RTLD_NEXT, "glXSwapBuffers");
- *(void**)(&gl_copy_pixels) = dlsym(RTLD_NEXT, "glCopyPixels");
- *(void**)(&gl_get_integerv) = dlsym(RTLD_NEXT, "glGetIntegerv");
- *(void**)(&gl_draw_buffer) = dlsym(RTLD_NEXT, "glDrawBuffer");
- *(void**)(&gl_read_buffer) = dlsym(RTLD_NEXT, "glReadBuffer");
+ *(void**)(&glX_GetCurrentDisplay) = dlsym(RTLD_NEXT, "glXGetCurrentDisplay");
+ *(void**)(&glX_GetCurrentDrawable) = dlsym(RTLD_NEXT, "glXGetCurrentDrawable");
+ *(void**)(&glX_SwapBuffers) = dlsym(RTLD_NEXT, "glXSwapBuffers");
+ *(void**)(&X_GetGeometry) = dlsym(RTLD_NEXT, "XGetGeometry");
+ *(void**)(&gl_WindowPos3i) = dlsym(RTLD_NEXT, "glWindowPos3i");
+ *(void**)(&gl_CopyPixels) = dlsym(RTLD_NEXT, "glCopyPixels");
+ *(void**)(&gl_GetIntegerv) = dlsym(RTLD_NEXT, "glGetIntegerv");
+ *(void**)(&gl_DrawBuffer) = dlsym(RTLD_NEXT, "glDrawBuffer");
+ *(void**)(&gl_ReadBuffer) = dlsym(RTLD_NEXT, "glReadBuffer");
first = 0;
}
Display *dpy;
GLXDrawable drw;
- if( !glx_get_current_display || !glx_get_current_drawable
- || !gl_get_integerv || !gl_copy_pixels || !glx_swap_buffers
- || !gl_draw_buffer || !gl_read_buffer
- || !(dpy = glx_get_current_display())
- || !(drw = glx_get_current_drawable())
+ if( !glX_GetCurrentDisplay || !glX_GetCurrentDrawable || !glX_SwapBuffers
+ || !gl_GetIntegerv || !gl_WindowPos3i || !gl_CopyPixels
+ || !gl_DrawBuffer || !gl_ReadBuffer
+ || !(dpy = glX_GetCurrentDisplay())
+ || !(drw = glX_GetCurrentDrawable())
){
return;
}
GLint buffer_draw = 0;
GLint buffer_read = ~0;
- gl_get_integerv(GL_DRAW_BUFFER, &buffer_draw);
- gl_get_integerv(GL_READ_BUFFER, &buffer_read);
+ gl_GetIntegerv(GL_DRAW_BUFFER, &buffer_draw);
+ gl_GetIntegerv(GL_READ_BUFFER, &buffer_read);
if( GL_COLOR == type
- && buffer_draw == GL_FRONT
- && buffer_read == GL_BACK
+ && GL_FRONT == buffer_draw
+ && GL_BACK == buffer_read
){
- glx_swap_buffers(dpy, drw);
- gl_draw_buffer(GL_BACK);
- gl_read_buffer(GL_FRONT);
- gl_copy_pixels(x,y,width,height,type);
- gl_draw_buffer(GL_FRONT);
- gl_read_buffer(GL_BACK);
+ GLint rp[4] = {0,0,0,0};
+ Window root;
+ int geom_x, geom_y;
+ unsigned geom_width, geom_height, border, depth;
+ gl_GetIntegerv(GL_CURRENT_RASTER_POSITION, rp);
+ X_GetGeometry(dpy, drw, &root, &geom_x, &geom_y, &geom_width, &geom_height, &border, &depth);
+
+ glX_SwapBuffers(dpy, drw);
+ gl_DrawBuffer(GL_BACK);
+ gl_ReadBuffer(GL_FRONT);
+ gl_WindowPos3i(0,0,0);
+ gl_CopyPixels(0, 0, geom_width, geom_height, type);
+ gl_DrawBuffer(GL_FRONT);
+ gl_ReadBuffer(GL_BACK);
+ gl_WindowPos3i(rp[0],rp[1],rp[2]);
} else {
- gl_copy_pixels(x,y,width,height,type);
+ gl_CopyPixels(x,y,width,height,type);
}
}