add a new render2 lib, which has a proper API and uses only OpenGL to render.
authorDana Jansens <danakj@orodu.net>
Mon, 26 May 2003 12:47:09 +0000 (12:47 +0000)
committerDana Jansens <danakj@orodu.net>
Mon, 26 May 2003 12:47:09 +0000 (12:47 +0000)
Makefile.am
configure.ac
render2/.cvsignore [new file with mode: 0644]
render2/Makefile.am [new file with mode: 0644]
render2/init.c [new file with mode: 0644]
render2/instance.c [new file with mode: 0644]
render2/instance.h [new file with mode: 0644]
render2/render.h [new file with mode: 0644]
render2/test.c [new file with mode: 0644]

index 433af840f589441e36f502da4f5f2c8c09592b91..d2e92479416a0fb587563a7ff791862ed5c368f2 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = po themes data render parser kernel plugins tools
+SUBDIRS = po themes data render render2 parser kernel plugins tools
 MAINTAINERCLEANFILES = aclocal.m4 config.h.in configure Makefile.in stamp-h.in
 
 doc:
index c7545137b275d0ebabeedc0f420a8f9360002713..480efb2847f59c37cd90717df35e332a41f87f20 100644 (file)
@@ -53,6 +53,12 @@ PKG_CHECK_MODULES(FC, [fontconfig])
 AC_SUBST(FC_CFLAGS)
 AC_SUBST(FC_LIBS)
 
+## XXX REMOVE ME PLS XXX ##
+PKG_CHECK_MODULES(XFT, [xft])
+AC_SUBST(XFT_CFLAGS)
+AC_SUBST(XFT_LIBS)
+## XXX REMOVE ME PLS XXX ##
+
 PKG_CHECK_MODULES(XML, [libxml-2.0])
 AC_SUBST(XML_CFLAGS)
 AC_SUBST(XML_LIBS)
@@ -106,7 +112,8 @@ AC_CONFIG_FILES([Makefile
                  po/Makefile.in
                  themes/Makefile
                 data/Makefile
-                 render/Makefile
+                 render/Makefile       
+                 render2/Makefile
                 parser/Makefile
                  kernel/Makefile
                 plugins/Makefile
diff --git a/render2/.cvsignore b/render2/.cvsignore
new file mode 100644 (file)
index 0000000..806b58a
--- /dev/null
@@ -0,0 +1,9 @@
+rendertest
+librender.a
+.libs
+Makefile.in
+.deps
+Makefile
+libobrender2.la
+instance.lo
+init.lo
diff --git a/render2/Makefile.am b/render2/Makefile.am
new file mode 100644 (file)
index 0000000..8219a3c
--- /dev/null
@@ -0,0 +1,26 @@
+themedir=$(datadir)/openbox/themes
+
+theme=operation
+
+CPPFLAGS=$(FC_CFLAGS) $(GLIB_CFLAGS) $(GL_CFLAGS) @CPPFLAGS@ \
+         -DG_LOG_DOMAIN=\"Render\" \
+         -DDEFAULT_THEME=\"$(theme)\" \
+         -DTHEMEDIR=\"$(themedir)\"
+
+INCLUDES=-I..
+LIBS=$(FC_LIBS) $(GLIB_LIBS) $(GL_LIBS) @LIBS@
+
+noinst_PROGRAMS=rendertest
+rendertest_LDFLAGS=-lobrender2 -L.
+rendertest_SOURCES=test.c
+
+lib_LTLIBRARIES=libobrender2.la
+libobrender2_la_SOURCES=init.c instance.c
+
+
+noinst_HEADERS=render.h instance.h
+
+MAINTAINERCLEANFILES=Makefile.in
+
+distclean-local:
+       $(RM) *\~ *.orig *.rej .\#*
diff --git a/render2/init.c b/render2/init.c
new file mode 100644 (file)
index 0000000..c3eec1b
--- /dev/null
@@ -0,0 +1,89 @@
+#include "instance.h"
+#include "render.h"
+
+static int glXRating(Display *display, XVisualInfo *v)
+{
+    int rating = 0;
+    int val;
+    g_print("evaluating visual %d\n", (int)v->visualid);
+    glXGetConfig(display, v, GLX_BUFFER_SIZE, &val);
+    g_print("buffer size %d\n", val);
+
+    switch (val) {
+    case 32:
+        rating += 300;
+    break;
+    case 24:
+        rating += 200;
+    break;
+    case 16:
+        rating += 100;
+    break;
+    }
+
+    glXGetConfig(display, v, GLX_LEVEL, &val);
+    g_print("level %d\n", val);
+    if (val != 0)
+        rating = -10000;
+
+    glXGetConfig(display, v, GLX_DEPTH_SIZE, &val);
+    g_print("depth size %d\n", val);
+    switch (val) {
+    case 32:
+        rating += 30;
+    break;
+    case 24:
+        rating += 20;
+    break;
+    case 16:
+        rating += 10;
+    break;
+    case 0:
+        rating -= 10000;
+    }
+
+    glXGetConfig(display, v, GLX_DOUBLEBUFFER, &val);
+    g_print("double buffer %d\n", val);
+    if (val)
+        rating++;
+    return rating;
+}
+
+struct RrInstance *RrInit(Display *display,
+                          int screen)
+{
+    int count, i = 0, val, best = 0, rate = 0, temp;
+    XVisualInfo vimatch, *vilist;
+    struct RrInstance *ret = NULL;
+
+    vimatch.screen = screen;
+    vimatch.class = TrueColor;
+    vilist = XGetVisualInfo(display, VisualScreenMask | VisualClassMask,
+                            &vimatch, &count);
+
+    if (vilist) {
+        g_print("looking for a GL visual in %d visuals\n", count);
+        for (i = 0; i < count; i++) {
+            glXGetConfig(display, &vilist[i], GLX_USE_GL, &val);
+            if (val) {
+                temp = glXRating(display, &vilist[i]);
+                if (temp > rate) {
+                    best = i;
+                    rate = temp;
+                }
+            }
+        }
+    }
+    if (rate > 0) {
+        g_print("picked visual %d with rating %d\n", best, rate);
+        ret = RrInstanceNew(display, screen, vilist[best]);
+    } else {
+        g_print("no valid GL visual was found\n");
+    }
+    return ret;
+}
+
+void RrDestroy(struct RrInstance *inst)
+{
+    RrInstanceFree(inst);
+}
diff --git a/render2/instance.c b/render2/instance.c
new file mode 100644 (file)
index 0000000..4acb036
--- /dev/null
@@ -0,0 +1,30 @@
+#include "instance.h"
+#include <glib.h>
+
+struct RrInstance *RrInstanceNew(Display *display,
+                                 int screen,
+                                 XVisualInfo visinfo)
+{
+    struct RrInstance *inst;
+
+    inst = g_new(struct RrInstance, 1);
+    inst->display = display;
+    inst->screen = screen;
+    inst->visinfo = visinfo;
+    inst->cmap = XCreateColormap(display, RootWindow(display, screen),
+                                 RrVisual(inst), AllocNone);
+    inst->glx_context = glXCreateContext(display, &visinfo, NULL, TRUE);
+
+    g_assert(inst->glx_context);
+
+    return inst;
+}
+
+void RrInstanceFree(struct RrInstance *inst)
+{
+    if (inst) {
+        glXDestroyContext(inst->display, inst->glx_context);
+        XFreeColormap(inst->display, inst->cmap);
+        g_free(inst);
+    }
+}
diff --git a/render2/instance.h b/render2/instance.h
new file mode 100644 (file)
index 0000000..a27518c
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef __instance_h
+#define __instance_h
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <GL/glx.h>
+
+struct RrInstance {
+    Display *display;
+    int screen;
+    XVisualInfo visinfo;
+    Colormap cmap;
+    GLXContext glx_context;
+};
+
+struct RrInstance *RrInstanceNew(Display *display,
+                                 int screen,
+                                 XVisualInfo visinfo);
+void RrInstanceFree(struct RrInstance *inst);
+
+
+#define RrDisplay(i)  ((i)->display)
+#define RrScreen(i)   ((i)->screen)
+#define RrDepth(i)    ((i)->visinfo.depth)
+#define RrVisual(i)   ((i)->visinfo.visual)
+#define RrColormap(i) ((i)->cmap)
+#define RrContext(i)  ((i)->glx_context)
+
+#endif
diff --git a/render2/render.h b/render2/render.h
new file mode 100644 (file)
index 0000000..3eed8a7
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef __render_h__
+#define __render_h__
+
+#include <glib.h>
+#include <X11/Xlib.h>
+
+/*
+#define RrBool gboolean
+#define RrTrue 1
+#define RrFalse 0
+*/
+
+struct RrInstance;
+
+/*! Returns a struct to be used when calling members of the library.
+  If the library fails to initialize, NULL is returned.
+  @param display The X Display to use.
+  @param screen The number of the screen to use.
+*/
+struct RrInstance *RrInit(Display *display,
+                          int screen);
+
+/*! Destroys an instance of the library.
+  @param inst The instance to destroy.
+*/
+void RrDestroy(struct RrInstance *inst);
+
+#endif
diff --git a/render2/test.c b/render2/test.c
new file mode 100644 (file)
index 0000000..44e660b
--- /dev/null
@@ -0,0 +1,63 @@
+#include <stdio.h>
+#include <X11/Xlib.h>
+#include <X11/extensions/shape.h>
+#include <string.h>
+#include <stdlib.h>
+#include "render.h"
+#include <glib.h>
+
+static int x_error_handler(Display * disp, XErrorEvent * error)
+{
+    char buf[1024];
+    XGetErrorText(disp, error->error_code, buf, 1024);
+    printf("%s\n", buf);
+    return 0;
+}
+
+int main()
+{
+    Display *display;
+    Window win;
+    struct RrInstance *inst;
+    XEvent report;
+    XClassHint chint;
+
+    if (!(display = XOpenDisplay(NULL))) {
+        fprintf(stderr, "couldn't connect to X server in DISPLAY\n");
+        return EXIT_FAILURE;
+    }
+    XSetErrorHandler(x_error_handler);
+    win = XCreateWindow(display, RootWindow(display, DefaultScreen(display)),
+                        10, 10, 100, 100, 0, 
+                        CopyFromParent,   /* depth */
+                        CopyFromParent,   /* class */
+                        CopyFromParent,   /* visual */
+                        0,                /* valuemask */
+                        0);               /* attributes */
+    XMapWindow(display, win);
+    XSelectInput(display, win, ExposureMask | StructureNotifyMask);
+
+    chint.res_name = "rendertest";
+    chint.res_class = "Rendertest";
+    XSetClassHint(display, win, &chint);
+
+    /* init Render */
+    inst = RrInit(display, DefaultScreen(display));
+
+    /*paint(win, look);*/
+    while (1) {
+        XNextEvent(display, &report);
+        switch (report.type) {
+        case Expose:
+            break;
+        case ConfigureNotify:
+            /*look->area.width = report.xconfigure.width;
+            look->area.height = report.xconfigure.height;
+            paint(win, look);*/
+            break;
+        }
+
+    }
+
+    return 1;
+}