]> icculus.org git repositories - dana/openbox.git/blob - render2/paint.c
add ability to set a texture to None
[dana/openbox.git] / render2 / paint.c
1 #include "render.h"
2 #include "surface.h"
3 #include "instance.h"
4 #include "debug.h"
5 #include <assert.h>
6 #include <GL/glx.h>
7
8 /*! Paints the surface, and all its children */
9 void RrPaint(struct RrSurface *sur)
10 {
11     RrPaintArea(sur, 0, 0, RrSurfaceWidth(sur), RrSurfaceHeight(sur));
12 }
13
14 /*! Paints the surface, and all its children, but only in the given area. */
15 void RrPaintArea(struct RrSurface *sur, int x, int y, int w, int h)
16 {
17     struct RrInstance *inst;
18     struct RrSurface *p;
19     int ok;
20     int surx, sury;
21
22     inst = RrSurfaceInstance(sur);
23
24     /* can't paint a prototype! */
25     assert(inst);
26     if (!inst) return;
27
28     /* bounds checking */
29     assert(x >= 0 && y >= 0);
30     if (!(x >= 0 && y >= 0)) return;
31     assert(x + w <= RrSurfaceWidth(sur) && y + h <= RrSurfaceHeight(sur));
32     if (!(x + w <= RrSurfaceWidth(sur) && y + h <= RrSurfaceHeight(sur)))
33         return;
34
35     /* XXX recurse and paint children */
36
37     if (!RrSurfaceVisible(sur)) return;
38
39     RrDebug("making %p, %p, %p current\n",
40             RrDisplay(inst), RrSurfaceWindow(sur), RrContext(inst));
41
42     ok = glXMakeCurrent(RrDisplay(inst), RrSurfaceWindow(sur),RrContext(inst));
43     assert(ok);
44
45     glMatrixMode(GL_MODELVIEW);
46     glLoadIdentity();
47     glMatrixMode(GL_PROJECTION);
48     glLoadIdentity();
49
50     glOrtho(0, RrScreenWidth(inst), RrScreenHeight(inst), 0, 0, 10);
51     glViewport(0, 0, RrScreenWidth(inst), RrScreenHeight(inst));
52     glMatrixMode(GL_MODELVIEW);
53     glTranslatef(-RrSurfaceX(sur),
54                  RrScreenHeight(inst)-RrSurfaceHeight(sur)-RrSurfaceY(sur), 0);
55     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
56
57     p = sur;
58     surx = sury = 0;
59     while (p) {
60         surx += RrSurfaceX(p);
61         sury += RrSurfaceY(p);
62         p = p->parent;
63     }
64
65     switch (RrSurfaceType(sur)) {
66     case RR_SURFACE_PLANAR:
67         RrPlanarPaint(sur, surx + x, sury + y, w, h);
68         break;
69     case RR_SURFACE_NONPLANAR:
70         assert(0);
71         break;
72     case RR_SURFACE_NONE:
73         break;
74     }
75
76     glXSwapBuffers(RrDisplay(inst), RrSurfaceWindow(sur));
77 }