1 /* Copyright (C) 1992-1998 The Geometry Center 2 * Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips 3 * 4 * This file is part of Geomview. 5 * 6 * Geomview is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU Lesser General Public License as published 8 * by the Free Software Foundation; either version 2, or (at your option) 9 * any later version. 10 * 11 * Geomview is distributed in the hope that it will be useful, but 12 * WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with Geomview; see the file COPYING. If not, write 18 * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, 19 * USA, or visit http://www.gnu.org. 20 */ 21 #include <X11/Xlib.h> 22 #include <X11/Xutil.h> 23 24 #ifndef NO_SHM 25 #include <sys/ipc.h> 26 #include <sys/shm.h> 27 #include <X11/extensions/XShm.h> 28 #endif /*!NO_SHM*/ 29 30 #include "mgx11.h" 31 32 typedef struct { 33 Pt3Coord x, y, z, w; /* Point coordinates */ 34 ColorA vcol; /* Color of vertex */ 35 int drawnext; /* draw the next line segment? */ 36 } CPoint3; 37 38 #include "mgbufrender.h" 39 #include "mgx11render1.h" 40 #include "mgx11render8.h" 41 #include "mgx11render16.h" 42 #include "mgbufrender24.h" 43 44 typedef struct _mgx11win { 45 int mgwinid;/* mg window id */ 46 Window window; /* real X window structure */ 47 Window parent; /* parent X windows */ 48 XImage *image; /* image for double buffering */ 49 unsigned char *buf; /* convience ptr */ 50 int width, height; /* actual size of shm seg */ 51 int zwidth; 52 GC gc; /* real X graphics context */ 53 XSizeHints xsh; /* X size hints */ 54 XWindowAttributes xwa; /* X window attributes */ 55 XSetWindowAttributes xswa; 56 XEvent event; /* X event structure for window */ 57 struct _mgx11win *next; /* next in list */ 58 #ifndef NO_SHM 59 XShmSegmentInfo shminf; /* book-keeping for shm */ 60 #endif 61 } mgx11win; 62 63 /* Display List Structure */ 64 /*****************************************************************************/ 65 66 typedef struct _mgx11prim { 67 int mykind; /* kind of primitive */ 68 int index; /* index into array of vertices */ 69 int numvts; /* number of vertices */ 70 float depth; /* z value for sorting (at least for now) */ 71 int color[3]; /* rgb color of polygon */ 72 int ecolor[3]; /* edge color of polygon */ 73 int ewidth; /* edge width */ 74 } mgx11prim; 75 76 typedef struct _mgx11_sort 77 { 78 vvec primsort; /* pointers to mgx11prim array elements*/ 79 vvec prims; /* array of mgx11prim structures */ 80 int primnum; /* number of primitives */ 81 int cprim; /* current primitive being stored */ 82 83 vvec pverts; /* array of vertices */ 84 int pvertnum; 85 int cvert; /* current vertex being stored */ 86 int maxverts; /* maximum number of vertices */ 87 88 } mgx11_sort; 89 90 #define MGX_NULL 0 91 #define MGX_END 0 92 #define MGX_BGNLINE 1 93 #define MGX_BGNPOLY 2 94 #define MGX_BGNEPOLY 3 95 #define MGX_BGNSLINE 4 96 #define MGX_BGNSPOLY 5 97 #define MGX_BGNSEPOLY 6 98 #define MGX_VERTEX 7 99 #define MGX_CVERTEX 8 100 #define MGX_COLOR 9 101 #define MGX_ECOLOR 10 102 103 #define PRIM_LINE 1 104 #define PRIM_POLYGON 2 105 #define PRIM_EPOLYGON 3 106 #define PRIM_SLINE 4 /* smooth shaded primitives */ 107 #define PRIM_SPOLYGON 5 108 #define PRIM_SEPOLYGON 6 109 #define PRIM_INVIS 7 110 111 /* End of Display List Structure */ 112 /*****************************************************************************/ 113 114 typedef struct mgx11context { 115 struct mgcontext mgctx; /* The mgcontext */ 116 int visible; /* has window been displayed on screen yet? */ 117 int win; /* 1 if window is created */ 118 int pix; /* 1 is window is a pixmap */ 119 int znudge; /* znudge for drawing lines closer */ 120 float znudgeby; /* how much of a nudge ? */ 121 long znear, zfar; /* Current Z-buffer limits */ 122 enum sortmethod sortmethod; /* MG_NONE, MG_DEPTH, MG_ZBUFFER */ 123 int dither; /* Should we dither? */ 124 int bitdepth; /* what bit depth ... 24, 8, or 1? */ 125 Visual *visual; /* visual for window */ 126 int shm; /* Do we use shared memory? */ 127 int xmin, xmax, ymin, ymax; 128 int oxmin, oxmax, oymin, oymax; 129 int exposed; 130 int noclear; 131 vvec room; /* Scratch space */ 132 133 Display *mgx11display; /* pointer to X-display */ 134 Colormap cmap; /* Our colormap */ 135 int cmapset; /* is colormap set or not? */ 136 mgx11win *myxwin; /* pointer to mgx11window structure */ 137 mgx11_sort *mysort; /* sorting structure */ 138 int sizelock; /* for prohibiting size change from within mg 139 when the cam window is part of a larger 140 hierarchy of windows as with Widgets */ 141 142 void (*deleted)(Window); 143 /* callback for when I'm deleted */ 144 /* pass back parent window */ 145 146 } mgx11context; 147 148 #define MAXZNUDGE 8 /* Max depth of mgx11_closer()/farther() */ 149 150 #define _mgx11c ((mgx11context*)_mgc) 151