some small cleanups and things for gl
authorDana Jansens <danakj@orodu.net>
Sun, 16 Mar 2008 06:59:26 +0000 (02:59 -0400)
committerDana Jansens <danakj@orodu.net>
Sun, 16 Mar 2008 06:59:26 +0000 (02:59 -0400)
dcompmgr.c
glxrender.c

index d0ee687..3d73319 100644 (file)
@@ -446,6 +446,14 @@ setup_functions(d_display_t *dpy, d_options_t *opts)
         /* these can be plugins.. */
         id = 1;
 
+        if (opts->render == USE_OPENGL) {
+            if (!dpy->glx.present) {
+                printf("cannot use OpenGL rendering, no glX found\n");
+                printf("using XRender instead\n");
+                opts->render = USE_RENDER;
+            }
+        }
+
         if (opts->render == USE_RENDER)
             render_init(sc, id++);
         else
index 7a38442..4647d62 100644 (file)
@@ -10,6 +10,9 @@
 #include <assert.h>
 #include <stdlib.h>
 
+#include <X11/Xmd.h>
+#include <GL/glxproto.h>
+
 #include <GL/gl.h>
 #include <GL/glx.h>
 #include <GL/glxtokens.h>
@@ -131,15 +134,14 @@ glxrender_init(d_screen_t *sc, int id)
         exit(1);
     }
 
-    d->context = glXCreateContext(sc->dpy->xlib_dpy, vi, NULL, GL_TRUE);
-    glXMakeCurrent(sc->dpy->xlib_dpy, sc->overlay, d->context);
-
-
     if (!(glxrender_find_fb_config(sc, d))) {
         printf("unable to find FB configs\n");
         exit(1);
     }
 
+    d->context = glXCreateContext(sc->dpy->xlib_dpy, vi, NULL, GL_TRUE);
+    glXMakeCurrent(sc->dpy->xlib_dpy, sc->overlay, d->context);
+
     glViewport(0, 0, sc->super->width_in_pixels, sc->super->height_in_pixels);
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
@@ -149,6 +151,8 @@ glxrender_init(d_screen_t *sc, int id)
     glLoadIdentity();
     glEnable(GL_TEXTURE_2D);
     glEnable(GL_DEPTH_TEST);
+    //glEnable(GL_SCISSOR_TEST); ?? what is this, glxcompmgr enables it
+    //glEnable(GL_STENCIL_TEST); ?? what is this, glxcompmgr enables it
 
     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
     glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
@@ -156,6 +160,7 @@ glxrender_init(d_screen_t *sc, int id)
 
     glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
     glXSwapBuffers(sc->dpy->xlib_dpy, sc->overlay);
 
     d->bind_func = (BindEXTFunc)
@@ -200,7 +205,7 @@ glxrender_find_fb_config(d_screen_t *sc, data_t *d)
         stencil = 32767;
         depth = 32767;
 
-        printf("looking for depth %d\n", i);
+        //printf("looking for depth %d\n", i);
 
         tvis.depth = i;
         visinfo = XGetVisualInfo(sc->dpy->xlib_dpy, VisualDepthMask,
@@ -259,6 +264,7 @@ glxrender_free(d_screen_t *sc)
     data_t *d = screen_find_plugin_data(sc, plugin_id);
     if (d) {
         glxrender_free_root_pixmap(sc, d);
+        glXDestroyContext(sc->dpy->xlib_dpy, d->context);
         free(d);
     }
     screen_remove_plugin_data(sc, plugin_id);
@@ -342,7 +348,6 @@ glxrender_free_window_pixmap(d_window_t *w, data_t *d, window_data_t *wd)
                         wd->glpixmap, GLX_FRONT_LEFT_EXT);
         glBindTexture(GL_TEXTURE_2D, 0);
 
-        //xcb_glx_destroy_pixmap(w->sc->dpy->conn, wd->glpixmap);
         glXDestroyPixmap(w->sc->dpy->xlib_dpy, wd->glpixmap);
         wd->glpixmap = XCB_NONE;
 
@@ -371,7 +376,6 @@ glxrender_free_root_pixmap(d_screen_t *sc, data_t *d)
                         d->root_glpixmap, GLX_FRONT_LEFT_EXT);
         glBindTexture(GL_TEXTURE_2D, 0);
 
-        //xcb_glx_destroy_pixmap(w->sc->dpy->conn, wd->glpixmap);
         glXDestroyPixmap(sc->dpy->xlib_dpy, d->root_glpixmap);
         d->root_glpixmap = XCB_NONE;
     }
@@ -407,10 +411,55 @@ glxrender_update_window_pixmap(d_window_t *w, data_t *d, window_data_t *wd)
     wd->glpixmap = glXCreatePixmap(w->sc->dpy->xlib_dpy,
                                    d->fbconfig[depth],
                                    px, attrs);
+#if 0
+    wd->glpixmap = xcb_generate_id(w->sc->dpy->conn);
+    int v;
+    glXGetFBConfigAttrib(w->sc->dpy->xlib_dpy, d->fbconfig[depth],
+                         GLX_FBCONFIG_ID, &v);
+    xcb_void_cookie_t ck =
+        xcb_glx_create_pixmap_checked(w->sc->dpy->conn, w->sc->num,
+                                      v,
+                                      px, wd->glpixmap,
+                                      2,
+                                      attrs);
+    xcb_generic_error_t *err = xcb_request_check(w->sc->dpy->conn, ck);
+    if (err) {
+        display_error(w->sc->dpy, err);
+        free(err);
+        wd->glpixmap = XCB_NONE;
+        return;
+    }
+#endif
 
     glBindTexture(GL_TEXTURE_2D, wd->texname);
     d->bind_func(w->sc->dpy->xlib_dpy,
                  wd->glpixmap, GLX_FRONT_LEFT_EXT, NULL);
+#if 0
+    {
+        /*
+          BindTexImageEXT
+          1           CARD8                   opcode (X assigned)
+          1           16                      GLX opcode (glXVendorPrivate)
+          2           6+n                     request length
+          4           1330                    vendor specific opcode
+          4           CARD32                  context tag
+          4           GLX_DRAWABLE            drawable
+          4           INT32                   buffer
+          4           CARD32                  num_attributes
+          4*n         LISTofATTRIBUTE_PAIR    attribute, value pairs.
+        */
+        unsigned int len = 12;
+        uint32_t data[] = {
+            wd->glpixmap,
+            GLX_FRONT_LEFT_EXT,
+            0,
+        };
+        xcb_glx_vendor_private(w->sc->dpy->conn,
+                               X_GLXvop_BindTexImageEXT,
+                               1,
+                               len, (uint8_t*)data);
+    }
+#endif
 
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -676,7 +725,6 @@ glxrender_paint(d_screen_t *sc)
     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
     glDisable(GL_BLEND);
 
-    //xcb_glx_swap_buffers(sc->dpy->conn, d->context_tag, sc->overlay);
     glXSwapBuffers(sc->dpy->xlib_dpy, sc->overlay);
 
     /* call the function we replaced in the chain */