]> icculus.org git repositories - dana/openbox.git/blob - render2/init.c
lots of API additions that I didn't forsee until putting it into use.
[dana/openbox.git] / render2 / init.c
1 #include "instance.h"
2 #include "render.h"
3 #include "debug.h"
4 #include "glft/glft.h"
5
6 static int glXRating(Display *display, XVisualInfo *v)
7 {
8     int rating = 0;
9     int val;
10     RrDebug("evaluating visual %d\n", (int)v->visualid);
11     glXGetConfig(display, v, GLX_BUFFER_SIZE, &val);
12     RrDebug("buffer size %d\n", val);
13
14     switch (val) {
15     case 32:
16         rating += 300;
17     break;
18     case 24:
19         rating += 200;
20     break;
21     case 16:
22         rating += 100;
23     break;
24     }
25
26     glXGetConfig(display, v, GLX_LEVEL, &val);
27     RrDebug("level %d\n", val);
28     if (val != 0)
29         rating = -10000;
30
31     glXGetConfig(display, v, GLX_DEPTH_SIZE, &val);
32     RrDebug("depth size %d\n", val);
33     switch (val) {
34     case 32:
35         rating += 30;
36     break;
37     case 24:
38         rating += 20;
39     break;
40     case 16:
41         rating += 10;
42     break;
43     case 0:
44         rating -= 10000;
45     }
46
47     glXGetConfig(display, v, GLX_DOUBLEBUFFER, &val);
48     RrDebug("double buffer %d\n", val);
49     if (val)
50         rating++;
51     return rating;
52 }
53
54 struct RrInstance *RrInit(Display *display,
55                           int screen)
56 {
57     int count, i = 0, val, best = 0, rate = 0, temp;
58     XVisualInfo vimatch, *vilist;
59     struct RrInstance *ret = NULL;
60
61     vimatch.screen = screen;
62     vimatch.class = TrueColor;
63     vilist = XGetVisualInfo(display, VisualScreenMask | VisualClassMask,
64                             &vimatch, &count);
65
66     if (vilist) {
67         RrDebug("looking for a GL visual in %d visuals\n", count);
68         for (i = 0; i < count; i++) {
69             glXGetConfig(display, &vilist[i], GLX_USE_GL, &val);
70             if (val) {
71                 temp = glXRating(display, &vilist[i]);
72                 if (temp > rate) {
73                     best = i;
74                     rate = temp;
75                 }
76             }
77         }
78     }
79     if (rate > 0) {
80         RrDebug("picked visual %d with rating %d\n", best, rate);
81         ret = RrInstanceNew(display, screen, vilist[best]);
82     
83         GlftInit();
84     }
85
86     return ret;
87 }
88
89 void RrDestroy(struct RrInstance *inst)
90 {
91     if (inst) {
92         RrInstanceFree(inst);
93     }
94 }