8 static int glft_init = 0;
10 static int glx_rating(Display *display, XVisualInfo *v)
14 RrDebug("evaluating visual %d\n", (int)v->visualid);
15 glXGetConfig(display, v, GLX_BUFFER_SIZE, &val);
16 RrDebug("buffer size %d\n", val);
30 glXGetConfig(display, v, GLX_LEVEL, &val);
31 RrDebug("level %d\n", val);
35 glXGetConfig(display, v, GLX_DEPTH_SIZE, &val);
36 RrDebug("depth size %d\n", val);
51 glXGetConfig(display, v, GLX_DOUBLEBUFFER, &val);
52 RrDebug("double buffer %d\n", val);
58 struct RrInstance *RrInstanceNew(Display *display, int screen)
60 int count, i = 0, val, best = 0, rate = 0, temp, ok;
61 XVisualInfo vimatch, *vilist;
63 vimatch.screen = screen;
64 vimatch.class = TrueColor;
65 vilist = XGetVisualInfo(display, VisualScreenMask | VisualClassMask,
69 RrDebug("looking for a GL visual in %d visuals\n", count);
70 for (i = 0; i < count; i++) {
71 glXGetConfig(display, &vilist[i], GLX_USE_GL, &val);
73 temp = glx_rating(display, &vilist[i]);
82 struct RrInstance *inst;
84 RrDebug("picked visual %d with rating %d\n", best, rate);
92 inst = malloc(sizeof(struct RrInstance));
93 inst->display = display;
94 inst->screen = screen;
95 inst->visinfo = vilist[best];
96 inst->cmap = XCreateColormap(display, RootWindow(display, screen),
97 RrVisual(inst), AllocNone);
98 inst->glx_context = glXCreateContext(display, &vilist[best],
100 inst->shape_window = XCreateWindow(display,RootWindow(display, screen),
102 RrInstanceDepth(inst), InputOutput,
103 RrInstanceVisual(inst), 0, NULL);
104 /* make the context current on anything we can so we can dl
107 ok = glXMakeCurrent(display, inst->shape_window, inst->glx_context);
109 inst->surface_map = g_hash_table_new(g_int_hash, g_int_equal);
111 assert(inst->glx_context);
113 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
115 glMatrixMode(GL_PROJECTION);
117 glOrtho(0, RrScreenWidth(inst), 0, RrScreenHeight(inst), 0, 10);
119 glMatrixMode(GL_MODELVIEW);
125 RrDebug("unable to find a suitable GL visual\n");
129 void RrInstanceFree(struct RrInstance *inst)
132 g_hash_table_destroy(inst->surface_map);
133 glXDestroyContext(inst->display, inst->glx_context);
134 XFreeColormap(inst->display, inst->cmap);
139 int RrInstanceDepth(struct RrInstance *inst)
141 return inst->visinfo.depth;
144 Colormap RrInstanceColormap(struct RrInstance *inst)
149 Visual *RrInstanceVisual(struct RrInstance *inst)
151 return inst->visinfo.visual;
154 void RrInstaceAddSurface(struct RrSurface *sur)
156 g_hash_table_replace(RrSurfaceInstance(sur)->surface_map, &sur->win, sur);
159 void RrInstaceRemoveSurface(struct RrSurface *sur)
161 g_hash_table_remove(RrSurfaceInstance(sur)->surface_map, &sur->win);
164 struct RrSurface *RrInstaceLookupSurface(struct RrInstance *inst, Window win)
166 return g_hash_table_lookup(inst->surface_map, &win);