add painting
authorDana Jansens <danakj@orodu.net>
Mon, 26 May 2003 20:13:42 +0000 (20:13 +0000)
committerDana Jansens <danakj@orodu.net>
Mon, 26 May 2003 20:13:42 +0000 (20:13 +0000)
render2/.cvsignore
render2/Makefile.am
render2/color.c
render2/instance.h
render2/paint.c [new file with mode: 0644]
render2/render.h
render2/surface.c
render2/surface.h
render2/texture.c

index 5a3f2d5a0c13872928cb5add2ee29fd485319623..da8adfca52fd35df3826d206b624284b67c5378e 100644 (file)
@@ -11,3 +11,5 @@ debug.lo
 color.lo
 font.lo
 surface.lo
+paint.lo
+texture.lo
index 8f9c4d21b23268703f149e027dc82c5f48825370..3e3fe1fb9cb3f9e1b9bb4d2c662cb9b7d19d313f 100644 (file)
@@ -22,7 +22,8 @@ libobrender2_la_SOURCES=\
        debug.c \
        font.c \
        surface.c \
-       texture.h
+       texture.c \
+       paint.c
 
 noinst_HEADERS=\
        render.h \
index fe14e0303fc2991e5a2df733947e40e4d84f290d..1458c0e51cfb91072c98d5abec13353898e33ac3 100644 (file)
@@ -13,10 +13,12 @@ int RrColorParse(struct RrInstance *inst, const char *colorname,
         ret->r = 0.0;
         ret->g = 0.0;
         ret->b = 0.0;
+        ret->a = 0.0;
         return 0;
     }
     ret->r = (xcol.red >> 8) / 255.0;
     ret->g = (xcol.green >> 8) / 255.0;
     ret->b = (xcol.blue >> 8) / 255.0;
+    ret->a = 0.0;
     return 1;
 }
index e386cc7043cfbaa0b4adb12a90e62429b229690e..da55fd81e287f73ae4fff6282f8ed66e806d6a94 100644 (file)
@@ -21,6 +21,10 @@ void RrInstanceFree(struct RrInstance *inst);
 
 #define RrDisplay(i)  ((i)->display)
 #define RrScreen(i)   ((i)->screen)
+#define RrScreenWidth(i) (WidthOfScreen(ScreenOfDisplay((i)->display, \
+                                                        (i)->screen)))
+#define RrScreenHeight(i) (HeightOfScreen(ScreenOfDisplay((i)->display, \
+                                                          (i)->screen)))
 #define RrDepth(i)    ((i)->visinfo.depth)
 #define RrVisual(i)   ((i)->visinfo.visual)
 #define RrColormap(i) ((i)->cmap)
diff --git a/render2/paint.c b/render2/paint.c
new file mode 100644 (file)
index 0000000..2443c5c
--- /dev/null
@@ -0,0 +1,338 @@
+#include "render.h"
+#include "surface.h"
+#include "instance.h"
+#include "debug.h"
+#include <assert.h>
+#include <GL/glx.h>
+
+void planar_copy_parent(struct RrSurface *sur)
+{
+    int ncols;
+    int copy;
+
+    switch (RrPlanarColorType(sur)) {
+    case RR_SURFACE_NONE:
+        return;
+    case RR_SURFACE_SOLID:
+        ncols = 1;
+        break;
+    case RR_SURFACE_HORIZONTAL:
+        ncols = 2;
+        break;
+    case RR_SURFACE_VERTICAL:
+        ncols = 2;
+        break;
+    case RR_SURFACE_DIAGONAL:
+        ncols = 2;
+        break;
+    case RR_SURFACE_CROSSDIAGONAL:
+        ncols = 2;
+        break;
+    case RR_SURFACE_PYRAMID:
+        ncols = 2;
+        break;
+    case RR_SURFACE_PIPECROSS:
+        ncols = 2;
+        break;
+    case RR_SURFACE_RECTANGLE:
+        ncols = 2;
+        break;
+    }
+
+    copy = 0;
+    if (ncols >= 1 && RrColorHasAlpha(RrPlanarPrimaryColor(sur)))
+        copy = 1;
+    if (ncols >= 1 && RrColorHasAlpha(RrPlanarSecondaryColor(sur)))
+        copy = 1;
+    if (copy) {
+        /*
+        struct RrSurface *parent = RrSurfaceParent(sur);
+
+        XXX COPY PARENT PLS
+        */
+    }
+}
+
+void paint_planar(struct RrSurface *sur, int x, int y, int w, int h)
+{   
+    float pr,pg,pb;
+    float sr, sg, sb;
+    float ar, ag, ab;
+
+    pr = RrColorRed(RrPlanarPrimaryColor(sur));
+    pg = RrColorGreen(RrPlanarPrimaryColor(sur));
+    pb = RrColorBlue(RrPlanarPrimaryColor(sur));
+    sr = RrColorRed(RrPlanarSecondaryColor(sur));
+    sg = RrColorGreen(RrPlanarSecondaryColor(sur));
+    sb = RrColorBlue(RrPlanarSecondaryColor(sur));
+    switch (RrPlanarColorType(sur)) {
+    case RR_SURFACE_NONE:
+        return;
+    case RR_SURFACE_SOLID:
+        glBegin(GL_TRIANGLES);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x, y);
+        glVertex2i(x+w, y);
+        glVertex2i(x+w, y+h);
+
+        glVertex2i(x+w, y+h);
+        glVertex2i(x, y+h);
+        glVertex2i(x, y);
+        glEnd();
+        break;
+    case RR_SURFACE_HORIZONTAL:
+        glBegin(GL_TRIANGLES);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x, y);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w, y);
+        glVertex2i(x+w, y+h);
+
+        glVertex2i(x+w, y+h);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x, y+h);
+        glVertex2i(x, y);
+        glEnd();
+        break;
+    case RR_SURFACE_VERTICAL:
+        glBegin(GL_TRIANGLES);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x, y);
+        glVertex2i(x+w, y);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w, y+h);
+
+        glVertex2i(x+w, y+h);
+        glVertex2i(x, y+h);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x, y);
+        glEnd();
+        break;
+    case RR_SURFACE_DIAGONAL:
+        ar = (pr + sr) / 2.0;
+        ag = (pg + sg) / 2.0;
+        ab = (pb + sb) / 2.0;
+        glBegin(GL_TRIANGLES);
+        glColor3f(ar, ag, ab);
+        glVertex2i(x, y);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x+w, y);
+        glColor3f(ar, ag, ab);
+        glVertex2i(x+w, y+h);
+
+        glColor3f(ar, ag, ab);
+        glVertex2i(x+w, y+h);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x, y+h);
+        glColor3f(ar, ag, ab);
+        glVertex2i(x, y);
+        glEnd();
+        break;
+    case RR_SURFACE_CROSSDIAGONAL:
+        ar = (pr + sr) / 2.0;
+        ag = (pg + sg) / 2.0;
+        ab = (pb + sb) / 2.0;
+        glBegin(GL_TRIANGLES);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x, y);
+        glColor3f(ar, ag, ab);
+        glVertex2i(x+w, y);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w, y+h);
+
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w, y+h);
+        glColor3f(ar, ag, ab);
+        glVertex2i(x, y+h);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x, y);
+        glEnd();
+        break;
+    case RR_SURFACE_PYRAMID:
+        ar = (pr + sr) / 2.0;
+        ag = (pg + sg) / 2.0;
+        ab = (pb + sb) / 2.0;
+        glBegin(GL_TRIANGLES);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x, y);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w/2, y+h/2);
+        glColor3f(ar, ag, ab);
+        glVertex2i(x, y+h/2);
+
+        glVertex2i(x, y+h/2);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w/2, y+h/2);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x, y+h);
+
+        glVertex2i(x, y+h);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w/2, y+h/2);
+        glColor3f(ar, ag, ab);
+        glVertex2i(x+w/2, y+h);
+
+        glVertex2i(x+w/2, y+h);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w/2, y+h/2);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x+w, y+h);
+
+        glVertex2i(x+w, y+h);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w/2, y+h/2);
+        glColor3f(ar, ag, ab);
+        glVertex2i(x+w, y+h/2);
+
+        glVertex2i(x+w, y+h/2);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w/2, y+h/2);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x+w, y);
+
+        glVertex2i(x+w, y);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w/2, y+h/2);
+        glColor3f(ar, ag, ab);
+        glVertex2i(x+w/2, y);
+
+        glVertex2i(x+w/2, y);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w/2, y+h/2);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x, y);
+        glEnd();
+        break;
+    case RR_SURFACE_PIPECROSS:
+        glBegin(GL_TRIANGLES);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x, y);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w/2, y+h/2);
+        glVertex2i(x, y+h/2);
+
+        glVertex2i(x, y+h/2);
+        glVertex2i(x+w/2, y+h/2);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x, y+h);
+
+        glVertex2i(x, y+h);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w/2, y+h/2);
+        glVertex2i(x+w/2, y+h);
+
+        glVertex2i(x+w/2, y+h);
+        glVertex2i(x+w/2, y+h/2);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x+w, y+h);
+
+        glVertex2i(x+w, y+h);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w/2, y+h/2);
+        glVertex2i(x+w, y+h/2);
+
+        glVertex2i(x+w, y+h/2);
+        glVertex2i(x+w/2, y+h/2);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x+w, y);
+
+        glVertex2i(x+w, y);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w/2, y+h/2);
+        glVertex2i(x+w/2, y);
+
+        glVertex2i(x+w/2, y);
+        glVertex2i(x+w/2, y+h/2);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x, y);
+        glEnd();
+        break;
+    case RR_SURFACE_RECTANGLE:
+        glBegin(GL_TRIANGLES);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x, y);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w/2, y+h/2);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x, y+h);
+
+        glVertex2i(x, y+h);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w/2, y+h/2);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x+w, y+h);
+
+        glVertex2i(x+w, y+h);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w/2, y+h/2);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x+w, y);
+
+        glVertex2i(x+w, y);
+        glColor3f(sr, sg, sb);
+        glVertex2i(x+w/2, y+h/2);
+        glColor3f(pr, pg, pb);
+        glVertex2i(x, y);
+
+        glEnd();
+        break;
+    }
+}
+
+/*! Paints the surface, and all its children */
+void RrSurfacePaint(struct RrSurface *sur)
+{
+    RrSurfacePaintArea(sur, 0, 0, RrSurfaceWidth(sur), RrSurfaceHeight(sur));
+}
+
+/*! Paints the surface, and all its children, but only in the given area. */
+void RrSurfacePaintArea(struct RrSurface *sur,
+                        int x,
+                        int y,
+                        int w,
+                        int h)
+{
+    struct RrInstance *inst;
+    int ok;
+
+    inst = RrSurfaceInstance(sur);
+
+    /* can't paint a prototype! */
+    assert(inst);
+    if (!inst) return;
+
+    assert(x >= 0 && y >= 0);
+    if (!(x >= 0 && y >= 0)) return;
+    assert(x + w < RrSurfaceWidth(sur) && y + h < RrSurfaceHeight(sur));
+    if (!(x + w < RrSurfaceWidth(sur) && y + h < RrSurfaceHeight(sur))) return;
+
+    RrDebug("making %p, %p, %p current\n",
+            RrDisplay(inst), RrSurfaceWindow(sur), RrContext(inst));
+
+    ok = glXMakeCurrent(RrDisplay(inst), RrSurfaceWindow(sur),RrContext(inst));
+    assert(ok);
+
+    glMatrixMode(GL_MODELVIEW);
+    glLoadIdentity();
+    glMatrixMode(GL_PROJECTION);
+    glLoadIdentity();
+
+    glOrtho(0, RrScreenWidth(inst), RrScreenHeight(inst), 0, 0, 10);
+    glViewport(0, 0, RrScreenWidth(inst), RrScreenHeight(inst));
+    glMatrixMode(GL_MODELVIEW);
+    glTranslatef(-RrSurfaceX(sur),
+                 RrScreenHeight(inst)-RrSurfaceHeight(sur)-RrSurfaceY(sur), 0);
+    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+    switch (RrSurfaceType(sur)) {
+    case RR_SURFACE_PLANAR:
+        planar_copy_parent(sur);
+        paint_planar(sur, x, y, w, h);
+        break;
+    case RR_SURFACE_NONPLANAR:
+        assert(0);
+        break;
+    }
+
+    glXSwapBuffers(RrDisplay(inst), RrSurfaceWindow(sur));
+}
index 90a5b56e4e1ba83c83068bd11e7d92d6f29ccb85..4151b0b0fb2d3005b14fc31ef99073d937ae65a4 100644 (file)
@@ -40,13 +40,15 @@ struct RrColor {
 };
 
 /*! Returns the red component for an RrColor */
-#define RrColorRed(c) (c)->r
+#define RrColorRed(c) (c).r
 /*! Returns the green component for an RrColor */
-#define RrColorGreen(c) (c)->g
+#define RrColorGreen(c) (c).g
 /*! Returns the blue component for an RrColor */
-#define RrColorBlue(c) (c)->b
+#define RrColorBlue(c) (c).b
 /*! Returns the alpha component for an RrColor */
-#define RrColorAlpha(c) (c)->a
+#define RrColorAlpha(c) (c).a
+/*! Returns if an RrColor is non-opaque */
+#define RrColorHasAlpha(c) ((c).a > 0.0000001)
 
 /*! Sets the values of all components for an RrColor */
 #define RrColorSet(c, w, x, y, z) (c)->r = (w), (c)->g = (x), \
@@ -127,6 +129,12 @@ struct RrSurface *RrSurfaceCopyChild(struct RrSurface *sur,
                                      struct RrSurface *parent);
 void RrSurfaceFree(struct RrSurface *sur);
 
+void RrSurfaceSetArea(struct RrSurface *sur,
+                      int x,
+                      int y,
+                      int w,
+                      int h);
+
 Window RrSurfaceWindow(struct RrSurface *sur);
 
 /* textures */
@@ -162,4 +170,15 @@ void RrTextureSetText(struct RrSurface *sur,
                       enum RrLayout layout,
                       const char *text);
 
+/* drawing */
+
+/*! Paints the surface, and all its children */
+void RrSurfacePaint(struct RrSurface *sur);
+/*! Paints the surface, and all its children, but only in the given area. */
+void RrSurfacePaintArea(struct RrSurface *sur,
+                        int x,
+                        int y,
+                        int w,
+                        int h);
+
 #endif
index ab265ef740432c582b0a10a9f2067c9eb5180da5..b436f6e1ef98034a26c09f1d7a75e81a811a997e 100644 (file)
@@ -18,6 +18,10 @@ static struct RrSurface *surface_new(enum RrSurfaceType type,
         memset(sur->texture, 0, sizeof(struct RrTexture) * numtex);
     } else
         sur->texture = NULL;
+    sur->x = 0;
+    sur->y = 0;
+    sur->w = 1;
+    sur->h = 1;
     return sur;
 }
 
@@ -70,8 +74,6 @@ struct RrSurface *RrSurfaceNewChild(enum RrSurfaceType type,
     sur->inst = parent->inst;
     sur->win = create_window(sur->inst, parent->win);
     sur->parent = parent;
-    sur->parentx = 0;
-    sur->parenty = 0;
     return sur;
 }
 
@@ -137,6 +139,18 @@ void RrSurfaceFree(struct RrSurface *sur)
     }
 }
 
+void RrSurfaceSetArea(struct RrSurface *sur,
+                      int x,
+                      int y,
+                      int w,
+                      int h)
+{
+    sur->x = x;
+    sur->y = y;
+    sur->w = w;
+    sur->h = h;
+}
+
 Window RrSurfaceWindow(struct RrSurface *sur)
 {
     /* can't get a window for a prototype */
index 9218b67c4ae09c36dadbe2e8562c5c5489ab1b83..6391beb935e443452092880cc407fac69356d7fd 100644 (file)
@@ -38,10 +38,27 @@ struct RrSurface {
     struct RrTexture *texture;
 
     struct RrSurface *parent;
-    int parentx;
-    int parenty;
+
+    int x;
+    int y;
+    int w;
+    int h;
 };
 
 struct RrTexture *RrSurfaceTexture(struct RrSurface *sur, int texnum);
 
+#define RrSurfaceInstance(sur) ((sur)->inst)
+#define RrSurfaceType(sur) ((sur)->type)
+
+#define RrSurfaceParent(sur) ((sur)->parent)
+
+#define RrSurfaceX(sur) ((sur)->x)
+#define RrSurfaceY(sur) ((sur)->y)
+#define RrSurfaceWidth(sur) ((sur)->w)
+#define RrSurfaceHeight(sur) ((sur)->h)
+
+#define RrPlanarColorType(sur) ((sur)->data.planar.colortype)
+#define RrPlanarPrimaryColor(sur) ((sur)->data.planar.primary)
+#define RrPlanarSecondaryColor(sur) ((sur)->data.planar.primary)
+
 #endif
index d2b6da61b4fcbb7700b639266954af7935d6be3b..24726d0b5fa840b33ae498a71b09e8810ed2bc51 100644 (file)
@@ -1,5 +1,7 @@
 #include "texture.h"
 #include "surface.h"
+#include <stdlib.h>
+#include <string.h>
 
 void texture_free(struct RrTexture *tex)
 {
@@ -9,7 +11,7 @@ void texture_free(struct RrTexture *tex)
     case RR_TEXTURE_TEXT:
         free(tex->data.text.string);
         break;
-    case RR_TEXTUER_RGBA:
+    case RR_TEXTURE_RGBA:
         break;
     }
     tex->type = RR_TEXTURE_NONE;