aboutsummaryrefslogtreecommitdiff
path: root/src/mgl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mgl.c')
-rw-r--r--src/mgl.c51
1 files changed, 37 insertions, 14 deletions
diff --git a/src/mgl.c b/src/mgl.c
index dd5cccd..1fcbb4a 100644
--- a/src/mgl.c
+++ b/src/mgl.c
@@ -1,6 +1,7 @@
#include "../include/mgl/mgl.h"
#include <X11/Xutil.h>
#include <X11/XKBlib.h>
+#include <X11/extensions/Xrender.h>
#include <stdio.h>
#ifndef NDEBUG
#include <stdlib.h>
@@ -24,25 +25,47 @@ static int ignore_xioerror(Display *display) {
static int glx_context_init() {
const int attr[] = {
- GLX_RGBA,
- GLX_BUFFER_SIZE, 24,
- GLX_DEPTH_SIZE, 0,
- GLX_STENCIL_SIZE, 0,
+ GLX_RENDER_TYPE, GLX_RGBA_BIT,
+ GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
+ GLX_DOUBLEBUFFER, True,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
- GLX_ALPHA_SIZE, 0,
- GLX_ACCUM_RED_SIZE, 0,
- GLX_ACCUM_GREEN_SIZE, 0,
- GLX_ACCUM_BLUE_SIZE, 0,
- GLX_ACCUM_ALPHA_SIZE, 0,
- GLX_DOUBLEBUFFER, /* TODO: Add option to turn this off? */
+ GLX_ALPHA_SIZE, 8,
+ GLX_DEPTH_SIZE, 0,
None
};
- context.visual_info = context.gl.glXChooseVisual(context.connection, DefaultScreen(context.connection), (int*)attr);
+ context.visual_info = NULL;
+ context.fbconfig = NULL;
+
+ int numfbconfigs = 0;
+ GLXFBConfig *fbconfigs = context.gl.glXChooseFBConfig(context.connection, DefaultScreen(context.connection), attr, &numfbconfigs);
+ for(int i = 0; i < numfbconfigs; i++) {
+ context.visual_info = context.gl.glXGetVisualFromFBConfig(context.connection, fbconfigs[i]);
+ if(!context.visual_info)
+ continue;
+
+ XRenderPictFormat *pict_format = XRenderFindVisualFormat(context.connection, ((XVisualInfo*)context.visual_info)->visual);
+ if(!pict_format) {
+ XFree(context.visual_info);
+ context.visual_info = NULL;
+ continue;
+ }
+
+ context.fbconfig = fbconfigs[i];
+ if(pict_format->direct.alphaMask > 0)
+ break;
+
+ XFree(context.visual_info);
+ context.visual_info = NULL;
+ }
+
+ if(fbconfigs)
+ XFree(fbconfigs);
+
if(!context.visual_info) {
- fprintf(stderr, "glXChooseVisual failed, no appropriate visual found\n");
+ fprintf(stderr, "mgl error: no appropriate visual found\n");
return -1;
}
@@ -61,7 +84,7 @@ int mgl_init(void) {
if(init_count == 1) {
context.connection = XOpenDisplay(NULL);
if(!context.connection) {
- fprintf(stderr, "XOpenDisplay(NULL) failed\n");
+ fprintf(stderr, "mgl error:XOpenDisplay(NULL) failed\n");
mgl_deinit();
return -1;
}
@@ -120,7 +143,7 @@ void mgl_deinit(void) {
mgl_context* mgl_get_context(void) {
#ifndef NDEBUG
if(init_count == 0) {
- fprintf(stderr, "Error: mgl_get_context was called before mgl_init\n");
+ fprintf(stderr, "mgl error: mgl_get_context was called before mgl_init\n");
abort();
}
#endif