i dunno, even the clear isn't working for gl right now
authorDana Jansens <danakj@orodu.net>
Tue, 11 Mar 2008 06:30:27 +0000 (02:30 -0400)
committerDana Jansens <danakj@orodu.net>
Tue, 11 Mar 2008 06:30:27 +0000 (02:30 -0400)
glxcompat.c
glxcompat.h
glxrender.c
screen.c

index 61cd93b..8d0bcac 100644 (file)
@@ -8,10 +8,13 @@
 #include <GL/glxtokens.h>
 #include <glib.h>
 
+#define DEBUG
+
 static uint32_t*
 code_to_ptr(d_glx_fb_config_t *fb, uint32_t code)
 {
     if (code == GLX_FBCONFIG_ID)  return &fb->fbconfig_id;
+    if (code == GLX_VISUAL_ID)    return &fb->visual_id;
     if (code == GLX_BUFFER_SIZE)  return &fb->buffer_size;
     if (code == GLX_LEVEL)        return &fb->level;
     if (code == GLX_DOUBLEBUFFER) return &fb->doublebuffer;
@@ -53,6 +56,7 @@ static const char*
 code_to_string(uint32_t code)
 {
     if (code == GLX_FBCONFIG_ID)  return "GLX_FBCONFIG_ID";
+    if (code == GLX_VISUAL_ID)    return "GLX_VISUAL_ID";
     if (code == GLX_BUFFER_SIZE)  return "GLX_BUFFER_SIZE";
     if (code == GLX_LEVEL)        return "GLX_LEVEL";
     if (code == GLX_DOUBLEBUFFER) return "GLX_DOUBLEBUFFER";
@@ -392,7 +396,15 @@ glxcompat_get_fb_config_attrib(d_glx_fb_config_t fb,
                                uint32_t *value)
 {
     uint32_t *ptr = code_to_ptr(&fb, name);
-    assert(ptr != NULL);
+    //assert(ptr != NULL);
     if (ptr) *value = *ptr;
+    else *value = 0;
     return !!ptr;
 }
+
+xcb_visualid_t
+glxcompat_choose_visual(xcb_connection_t *conn,
+                        int screen,
+                        const uint32_t *attrs)
+{
+}
index 1e42997..f52d34e 100644 (file)
@@ -8,6 +8,7 @@ typedef struct d_glx_fb_config d_glx_fb_config_t;
 
 struct d_glx_fb_config {
     uint32_t fbconfig_id;
+    uint32_t visual_id;
     uint32_t buffer_size;
     uint32_t level;
     uint32_t doublebuffer;
@@ -46,4 +47,9 @@ gboolean glxcompat_get_fb_config_attrib(d_glx_fb_config_t fb,
                                         uint32_t name,
                                         uint32_t *value);
 
+xcb_visualid_t glxcompat_choose_visual(xcb_connection_t *conn,
+                                       int screen,
+                                       const uint32_t *attrs);
+                                       
+
 #endif
index 8e89b00..7973fbc 100644 (file)
@@ -75,6 +75,7 @@ glxrender_init(d_screen_t *sc, int id)
     xcb_generic_error_t *err;
     xcb_glx_make_current_cookie_t curck;
     xcb_glx_make_current_reply_t *currep;
+    xcb_visualid_t vis;
 
     plugin_id = id;
 
@@ -110,8 +111,8 @@ glxrender_init(d_screen_t *sc, int id)
 
     d->context = xcb_generate_id(sc->dpy->conn);
     ck = xcb_glx_create_context_checked(sc->dpy->conn, d->context,
-                                        sc->overlay_visual, sc->num,
-                                        XCB_NONE, TRUE);
+                                        sc->overlay_visual,
+                                        sc->num, XCB_NONE, GL_TRUE);
     if ((err = xcb_request_check(sc->dpy->conn, ck))) {
         printf("context creation failed\n");
         display_error(sc->dpy, err);
@@ -145,6 +146,8 @@ glxrender_init(d_screen_t *sc, int id)
     xcb_glx_swap_buffers(sc->dpy->conn, d->context_tag, sc->overlay);
     glClearColor(0.4, 0.4, 0.4, 1.0);
 
+    //glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+    glDisable(GL_BLEND);
 /*
   glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);                          
   glEnable(GL_BLEND);
@@ -156,7 +159,7 @@ glxrender_visual_info(uint32_t *props, int vis, int numprops, uint32_t name)
 {
     int s;
 
-    assert(numprops > 14);
+    assert(numprops > 15);
 
     /*
     for (s = vis * numprops; s < vis*numprops + numprops; ++s)
@@ -193,15 +196,6 @@ glxrender_check_visual(d_screen_t *sc)
         uint32_t *props;
         unsigned int i, nprops;
 
-/*
-        static int config[] = {
-            GLX_DEPTH_SIZE, 1,
-            GLX_DOUBLEBUFFER,
-            GLX_RGBA,
-            XCB_NONE
-        };
-*/
-
         props = xcb_glx_get_visual_configs_property_list(rep);
         nprops = rep->num_properties;
 
@@ -231,88 +225,37 @@ glxrender_check_visual(d_screen_t *sc)
     return ok;
 }
 
-static uint32_t
-glxrender_fbconfig_info(uint32_t *props, int con, int numprops, uint32_t name)
-{
-    int i;
-
-    for (i = 0; i < numprops; ++i) {
-        if (props[i*2 + con*numprops*2] == name)
-            return props[i*2 + con*numprops*2 + 1];
-    }
-    return 0;
-}
-
 static gboolean
 glxrender_find_fb_config(d_screen_t *sc, data_t *d)
 {
-    xcb_glx_get_visual_configs_cookie_t vck;
-    xcb_glx_get_visual_configs_reply_t *vrep;
-    xcb_glx_get_fb_configs_cookie_t fbck;
-    xcb_glx_get_fb_configs_reply_t *fbrep;
+    static const uint32_t drawable_tfp_attrs[] = {
+        GLX_CONFIG_CAVEAT, GLX_NONE,
+        GLX_DOUBLEBUFFER, FALSE,
+        GLX_DEPTH_SIZE, 0,
+        GLX_RED_SIZE, 1,
+        GLX_GREEN_SIZE, 1,
+        GLX_BLUE_SIZE, 1,
+        GLX_ALPHA_SIZE, 1,
+        GLX_RENDER_TYPE, GLX_RGBA_BIT,
+        GLX_BIND_TO_TEXTURE_RGBA_EXT, TRUE, /* For TextureFromPixmap */
+        XCB_NONE
+    };
     xcb_depth_iterator_t depth_it;
-    unsigned int i, nvprops, nfbprops;
-    uint32_t *vprops, *fbprops;
-    uint32_t db, stencil, depthsize;
-
-    {
-        static const uint32_t drawable_tfp_attrs[] = {
-            GLX_CONFIG_CAVEAT, GLX_NONE,
-            GLX_DOUBLEBUFFER, FALSE,
-            GLX_DEPTH_SIZE, 0,
-            GLX_RED_SIZE, 1,
-            GLX_GREEN_SIZE, 1,
-            GLX_BLUE_SIZE, 1,
-            GLX_ALPHA_SIZE, 1,
-            GLX_RENDER_TYPE, GLX_RGBA_BIT,
-            GLX_BIND_TO_TEXTURE_RGBA_EXT, TRUE, /* For TextureFromPixmap */
-            XCB_NONE
-        };
-
-        d_glx_fb_config_t *fbcons;
-        int i, numfb;
-
-        fbcons = glxcompat_choose_fb_config(sc->dpy->conn, sc->num,
-                                            drawable_tfp_attrs, &numfb);
-        printf("found %d\n", numfb);
-        if (fbcons) {
-            for (i = 0; i < numfb; ++i) {
-                uint32_t v;
-                glxcompat_get_fb_config_attrib(fbcons[i], GLX_FBCONFIG_ID, &v);
-                printf("GLX_FBCONFIG_ID %x\n", v);
-            }
-            free(fbcons);
-        }
-        exit(0);
-    }
+    d_glx_fb_config_t *fbcons;
+    int numfb;
 
-    vck = xcb_glx_get_visual_configs_unchecked(sc->dpy->conn, sc->num);
-    vrep = xcb_glx_get_visual_configs_reply(sc->dpy->conn, vck, NULL);
-    if (!vrep) return FALSE;
-
-    fbck = xcb_glx_get_fb_configs(sc->dpy->conn, sc->num);
-    fbrep = xcb_glx_get_fb_configs_reply(sc->dpy->conn, fbck, NULL);
-    if (!fbrep) return FALSE;
-
-    vprops = xcb_glx_get_visual_configs_property_list(vrep);
-    nvprops = vrep->num_properties;
-    fbprops = xcb_glx_get_fb_configs_property_list(fbrep);
-    nfbprops = fbrep->num_properties;
+    fbcons = glxcompat_choose_fb_config(sc->dpy->conn, sc->num,
+                                        drawable_tfp_attrs, &numfb);
+    if (!fbcons) return FALSE;
 
     memset(d->fbconfig, 0, (MAX_DEPTH + 1) * sizeof(d->fbconfig[0]));
 
-    db = 32767;
-    stencil = 32767;
-    depthsize = 32767;
     depth_it = xcb_screen_allowed_depths_iterator(sc->super);
     for (; depth_it.rem; xcb_depth_next(&depth_it)) {
-        uint32_t vid;
-        int j;
-        unsigned int k;
+        int j, k;
         xcb_visualtype_t *visuals;
         int nvisuals;
 
-        vid = 0;
         if (depth_it.data->depth > MAX_DEPTH) continue;
 
         printf("looking for depth %d\n", depth_it.data->depth);
@@ -320,110 +263,37 @@ glxrender_find_fb_config(d_screen_t *sc, data_t *d)
         visuals = xcb_depth_visuals(depth_it.data);
         nvisuals = xcb_depth_visuals_length(depth_it.data);
 
-        /* pick the nicest visual for the depth */
-        for (j = 0; j < nvisuals; ++j) {
-            uint32_t val;
-            /* find the visual's properties */
-            for (k = 0; k < vrep->num_visuals; ++k)
-                if (glxrender_visual_info(vprops, k, nvprops, GLX_VISUAL_ID)
-                    == visuals[j].visual_id)
-                {
+        /* look for an fbconfig for this depth */
+        for (j = 0; j < numfb; ++j) {
+            uint32_t vid, fbid;
+            gboolean use;
+
+            //glxcompat_get_fb_config_attrib(fbcons[j], GLX_FBCONFIG_ID, &v);
+            //printf("trying fbconfig 0x%x\n", v);
+
+            glxcompat_get_fb_config_attrib(fbcons[j], GLX_VISUAL_ID, &vid);
+            glxcompat_get_fb_config_attrib(fbcons[j], GLX_FBCONFIG_ID, &fbid);
+
+            use = FALSE;
+            for (k = 0; k < nvisuals; ++k)
+                //if (vid == visuals[k].visual_id) {
+                if ((vid == 0x80 && depth_it.data->depth == 32) ||
+                    vid == 0x59) {
+                    use = TRUE;
                     break;
                 }
-            if (k == vrep->num_visuals) continue;
-
-            val = glxrender_visual_info(vprops, k, nvprops, GLX_USE_GL);
-            if (!val) continue;
-
-            val = glxrender_visual_info(vprops, k, nvprops, GLX_DOUBLEBUFFER);
-            if (!val > db) continue;
-            db = val;
-
-            val = glxrender_visual_info(vprops, k, nvprops, GLX_STENCIL_SIZE);
-            if (!val > stencil) continue;
-            stencil = val;
-
-            val = glxrender_visual_info(vprops, k, nvprops, GLX_DEPTH_SIZE);
-            if (!val > depthsize) continue;
-            depthsize = val;
-
-            /* try this visual */
-            vid = visuals[j].visual_id;
-
-            /* look for an fbconfig for this visual */
-            for (k = 0; k < fbrep->num_FB_configs; ++k) {
-                uint32_t val;
-
-                //printf("root visual 0x%x\n", sc->super.root_visual);
-                //printf("overlay visual 0x%x\n", sc->overlay_visual);
-
-                val = glxrender_fbconfig_info(fbprops, k, nfbprops,
-                                              GLX_VISUAL_ID);
-                //printf("x visual 0x%x\n", val);
-                if (val != vid) continue;
-
-                val = glxrender_fbconfig_info(fbprops, k, nfbprops,
-                                              GLX_BIND_TO_TEXTURE_TARGETS_EXT);
-                printf("BIND TO TARGETS %x\n", val);
-
-                val = glxrender_fbconfig_info(fbprops, k, nfbprops,
-                                              GLX_DOUBLEBUFFER);
-                printf("dbl buffer %s\n", val ? "yes" : "no");
-                if (val) continue;
-
-                val = glxrender_fbconfig_info(fbprops, k, nfbprops,
-                                              GLX_DEPTH_SIZE);
-                printf("depth size %d\n", val);
-
-                val = glxrender_fbconfig_info(fbprops, k, nfbprops,
-                                              GLX_RED_SIZE);
-                printf("red size %d\n", val);
-                if (!val) continue;
-
-                val = glxrender_fbconfig_info(fbprops, k, nfbprops,
-                                              GLX_GREEN_SIZE);
-                printf("green size %d\n", val);
-                if (!val) continue;
-
-                val = glxrender_fbconfig_info(fbprops, k, nfbprops,
-                                              GLX_BLUE_SIZE);
-                printf("blue size %d\n", val);
-                if (!val) continue;
-
-                val = glxrender_fbconfig_info(fbprops, k, nfbprops,
-                                              GLX_ALPHA_SIZE);
-                printf("alpha size %d\n", val);
-                //if (depth_it.data->depth == 32 && !val) continue;
-
-                val = glxrender_fbconfig_info(fbprops, j, nfbprops,
-                                              GLX_RENDER_TYPE);
-                printf("rgba bit %s\n", val & GLX_RGBA_BIT ? "yes" : "no");
-                if (!(val & GLX_RGBA_BIT)) continue;
-
-                val = glxrender_fbconfig_info(fbprops, j, nfbprops,
-                                              GLX_CONFIG_CAVEAT);
-                printf("caveat 0x%x\n", val);
-
-                val = glxrender_fbconfig_info(fbprops, j, nfbprops,
-                                              GLX_BIND_TO_TEXTURE_RGBA_EXT);
-                printf("bind ext %s\n", val ? "yes" : "no");
-                if (!val) continue;
-
-                d->fbconfig[depth_it.data->depth] =
-                    glxrender_fbconfig_info(fbprops, i, nfbprops,
-                                            GLX_FBCONFIG_ID);
-                break;
-            }
 
-            if (d->fbconfig[depth_it.data->depth])
+            if (use) {
+                d->fbconfig[depth_it.data->depth] = fbid;
+
                 printf("found visual 0x%x fbconfig 0x%x for depth %d\n",
-                       vid, d->fbconfig[depth_it.data->depth],
-                       depth_it.data->depth);
+                       vid, fbid, depth_it.data->depth);
+                break;
+            }
         }
     }
 
-    free(vrep);
-    free(fbrep);
+    free(fbcons);
     return TRUE;
 }
 
@@ -545,25 +415,20 @@ glxrender_update_window_pixmap(d_window_t *w, data_t *d, window_data_t *wd)
 
     px = window_get_pixmap(w);
     depth = window_get_depth(w);
-    if (px && d->fbconfig[depth]) {
+    //printf("%x %d %x\n", px, depth, d->fbconfig[depth]);
+    if (px && !d->fbconfig[depth])
+        printf("no GL visual for depth %d\n", depth);
+    else if (px) {
         wd->glpixmap = xcb_generate_id(w->sc->dpy->conn);
-        printf("creating pixmap fbcon 0x%x\n", d->fbconfig[depth]);
-
-        xcb_void_cookie_t ck =
-            xcb_glx_create_pixmap_checked(w->sc->dpy->conn, w->sc->num,
-                                          d->fbconfig[depth],
-                                          px, wd->glpixmap,
-                                          sizeof(attrs)/sizeof(attrs[0]),
-                                          attrs);
-        {
-            xcb_generic_error_t *err;
-            err = xcb_request_check(w->sc->dpy->conn, ck);
-            if (err) {
-                printf("error creating pixmap\n");
-                display_error(w->sc->dpy, err);
-                free(err);
-            }
-        }
+        printf("bind config 0x%x screen %d pixmap 0x%x glpixmap 0x%x "
+               "nattr %d\n",
+               d->fbconfig[depth], w->sc->num, px, wd->glpixmap,
+               sizeof(attrs)/sizeof(attrs[0]));
+        xcb_glx_create_pixmap(w->sc->dpy->conn, w->sc->num,
+                              d->fbconfig[depth],
+                              px, wd->glpixmap,
+                              sizeof(attrs)/sizeof(attrs[0]),
+                              attrs);
 
         glBindTexture(GL_TEXTURE_2D, wd->texname);
 
@@ -695,8 +560,8 @@ glxrender_paint(d_screen_t *sc)
 
             wd = window_find_plugin_data(w, plugin_id);
 
-            paint_shadow(w, d, wd, x, y, width, height, bwidth);
-            paint_window(w, d, wd, opaque, x, y, width, height, bwidth);
+            //paint_shadow(w, d, wd, x, y, width, height, bwidth);
+            //paint_window(w, d, wd, opaque, x, y, width, height, bwidth);
         }
     }
 
index 693c29c..6d454c3 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -156,7 +156,7 @@ screen_init(d_screen_t *sc)
         xcb_composite_redirect_subwindows(sc->dpy->conn, sc->super->root,
                                           XCB_COMPOSITE_REDIRECT_AUTOMATIC);
 
-#if 0
+#if 1
     redir_ck =
         xcb_composite_redirect_subwindows(sc->dpy->conn, sc->super->root,
                                           XCB_COMPOSITE_REDIRECT_MANUAL);