]> icculus.org git repositories - dana/openbox.git/blob - loco/paint.c
grab the server during composite rendering
[dana/openbox.git] / loco / paint.c
1 #include "paint.h"
2 #include "screen.h"
3 #include "list.h"
4 #include "window.h"
5 #include "glerror.h"
6
7 #include "obt/display.h"
8
9 #include <GL/glx.h>
10 #include <GL/glext.h>
11 #include <GL/glxext.h>
12 #include <GL/glxtokens.h>
13
14 static int context_visual_config[] = {
15     GLX_DEPTH_SIZE, 1,
16     GLX_DOUBLEBUFFER,
17     GLX_RGBA,
18     None
19 };
20
21 gboolean paint_setup(LocoScreen *sc)
22 {
23     XVisualInfo *vi;
24     GLXContext context;
25     gint w, h;
26     
27     w = WidthOfScreen(ScreenOfDisplay(obt_display, sc->number));
28     h = HeightOfScreen(ScreenOfDisplay(obt_display, sc->number));
29
30     vi = glXChooseVisual(obt_display, sc->number, context_visual_config);
31     context = glXCreateContext(obt_display, vi, NULL, GL_TRUE);
32     if (context == NULL) {
33         g_print("context creation failed\n");
34         return FALSE;
35     }
36     glXMakeCurrent(obt_display, sc->overlay, context);
37
38     glViewport(0, 0, w, h);
39     glMatrixMode(GL_PROJECTION);
40     glLoadIdentity();
41     g_print("Setting up an orthographic projection of %dx%d\n", w, h);
42     glOrtho(0, w, h, 0.0, -1.0, 100.0);
43     glMatrixMode(GL_MODELVIEW);
44     glLoadIdentity();
45     glClear(GL_COLOR_BUFFER_BIT);
46     glEnable(GL_TEXTURE_2D);
47 glError();
48     glXSwapBuffers(obt_display, sc->overlay);
49     glClearColor(0.4, 0.4, 0.4, 1.0);
50 /*
51     glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
52     glEnable(GL_BLEND);
53 */
54     return TRUE;
55 }
56
57 void paint_everything(LocoScreen *sc)
58 {
59     int ret;
60     LocoList *it;
61
62     XGrabServer(obt_display);
63     XSync(obt_display, FALSE);
64
65     /* XXX if (full_redraw_required) */
66         glClear(GL_COLOR_BUFFER_BIT);
67
68     for (it = sc->stacking_bottom; it != NULL; it = it->prev) {
69         if (it->window->id == sc->overlay) continue;
70         if (it->window->input_only) continue;
71         if (!it->window->visible)   continue;
72         /* XXX if (!full_redraw_required && !it->window->damaged) continue; */
73
74         /* XXX if (!full_redraw_required) {
75            /\* XXX if the window is transparent, then clear the background
76            behind it *\/
77         }*/
78
79         /* get the window's updated contents
80            XXX if animating the window, then don't do this, depending
81         */
82         loco_window_update_pixmap(it->window);
83
84         glBindTexture(GL_TEXTURE_2D, it->window->texname);
85         if (ret) {
86             glBegin(GL_QUADS);
87             glColor3f(1.0, 1.0, 1.0);
88             glVertex2i(it->window->x, it->window->y);
89             glTexCoord2f(1, 0);
90             glVertex2i(it->window->x + it->window->w, it->window->y);
91             glTexCoord2f(1, 1);
92             glVertex2i(it->window->x + it->window->w,
93                        it->window->y + it->window->h);
94             glTexCoord2f(0, 1);
95             glVertex2i(it->window->x, it->window->y + it->window->h);
96             glTexCoord2f(0, 0);
97             glEnd();
98         }
99
100         it->window->damaged = FALSE;
101     }
102     glXSwapBuffers(obt_display, sc->overlay);
103
104     XUngrabServer(obt_display);
105
106     loco_screen_redraw_done(sc);
107 }