From 523b6b69049c0545e1a73e5278024186c60365cb Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 26 May 2003 12:47:09 +0000 Subject: [PATCH] add a new render2 lib, which has a proper API and uses only OpenGL to render. --- Makefile.am | 2 +- configure.ac | 9 ++++- render2/.cvsignore | 9 +++++ render2/Makefile.am | 26 +++++++++++++ render2/init.c | 89 +++++++++++++++++++++++++++++++++++++++++++++ render2/instance.c | 30 +++++++++++++++ render2/instance.h | 29 +++++++++++++++ render2/render.h | 28 ++++++++++++++ render2/test.c | 63 ++++++++++++++++++++++++++++++++ 9 files changed, 283 insertions(+), 2 deletions(-) create mode 100644 render2/.cvsignore create mode 100644 render2/Makefile.am create mode 100644 render2/init.c create mode 100644 render2/instance.c create mode 100644 render2/instance.h create mode 100644 render2/render.h create mode 100644 render2/test.c diff --git a/Makefile.am b/Makefile.am index 433af840..d2e92479 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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: diff --git a/configure.ac b/configure.ac index c7545137..480efb28 100644 --- a/configure.ac +++ b/configure.ac @@ -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 index 00000000..806b58af --- /dev/null +++ b/render2/.cvsignore @@ -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 index 00000000..8219a3c0 --- /dev/null +++ b/render2/Makefile.am @@ -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 index 00000000..c3eec1b2 --- /dev/null +++ b/render2/init.c @@ -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 index 00000000..4acb036f --- /dev/null +++ b/render2/instance.c @@ -0,0 +1,30 @@ +#include "instance.h" +#include + +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 index 00000000..a27518c7 --- /dev/null +++ b/render2/instance.h @@ -0,0 +1,29 @@ +#ifndef __instance_h +#define __instance_h + +#include +#include +#include + +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 index 00000000..3eed8a7c --- /dev/null +++ b/render2/render.h @@ -0,0 +1,28 @@ +#ifndef __render_h__ +#define __render_h__ + +#include +#include + +/* +#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 index 00000000..44e660b9 --- /dev/null +++ b/render2/test.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include "render.h" +#include + +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; +} -- 2.34.1