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 22 23 /* Authors: Charlie Gunn, Stuart Levy, Tamara Munzner, Mark Phillips */ 24 25 #ifndef _MG_PDEFS_ 26 #define _MG_PDEFS_ 27 28 /* 29 * Private, but machine-independent, declarations for mg library. 30 */ 31 #include <stdlib.h> 32 #include "mg.h" 33 34 #define MGCONTEXTMAGIC OOGLMagic('m', 'c'<<8 | 1) 35 36 /* struct mgcontext changed bits */ 37 #define MC_WIN 0x01 /* window changed (reshaped, &c) */ 38 #define MC_CAM 0x02 /* Camera changed */ 39 #define MC_AP 0x04 /* Appearance changed */ 40 #define MC_MAT 0x08 /* Material changed */ 41 #define MC_LIGHT 0x10 /* Lighting changed */ 42 #define MC_TRANS 0x20 /* Transformation changed */ 43 #define MC_OPT 0x40 /* Options changed */ 44 #define MC_USED 0x80 /* worldbegin called (used by mg_textureclock) */ 45 46 /* flags for mgastk->flags */ 47 #define MGASTK_TAGGED 0x01 /* sticky */ 48 #define MGASTK_ACTIVE 0x02 /* in use */ 49 #define MGASTK_SHADER 0x04 /* software shader */ 50 51 /* 52 * Appearance portion of state. 53 * We have a global stack of these which represent the user-specified values, 54 * with a stack push at every mgpushappearance(). 55 */ 56 struct mgastk { 57 REFERENCEFIELDS; /* use count for sticky elements */ 58 struct mgastk *next; /* stack link */ 59 mgcontext *tag_ctx;/* back-pointer for ap_tagged list */ 60 unsigned short flags; /* sticky flag */ 61 unsigned short changed; 62 short ap_seq, mat_seq, light_seq; 63 Appearance ap; /* Shallow copy of appearance -- don't delete */ 64 Material mat; /* Ditto, Material */ 65 LmLighting lighting;/* Ditto, Lighting */ 66 67 mgshadefunc shader; /* Software shading function, or NULL if none */ 68 void *shaderdata; /* Data which shader might use */ 69 }; 70 71 /* 72 * Transform stack, pushed by mgpushtransform(). 73 */ 74 struct mgxstk { 75 struct mgxstk *next; /* stack link */ 76 Transform T; /* Current object->world xform */ 77 short xfm_seq; 78 short hasinv; /* Flag: Tinv is valid */ 79 Transform Tinv; 80 }; 81 82 /* 83 * Texture transform stack. Needed to paste textured stuff together 84 * with INSTs, but allowing for a texture which covers the entire 85 * object. cH, 2007. 86 */ 87 struct mgtxstk 88 { 89 struct mgtxstk *next; /* stack link */ 90 Transform T; 91 /* No need for an inverse. Sequence count? Probably not. */ 92 }; 93 94 struct mgcontext { 95 REFERENCEFIELDS; 96 struct mgfuncs *devfuncs; /* Pointers to devices */ 97 short devno; /* Device index -- MGD_GL, MGD_X11, ... */ 98 99 unsigned short changed; /* flags: Must update device state because...*/ 100 101 WnWindow *win; /* Window */ 102 Camera *cam; /* Camera */ 103 mgcontext *parent; /* Parent mg window, if any */ 104 mgcontext *next; /* Link in list of all mg contexts */ 105 struct mgxstk *xstk; /* Top of transform stack */ 106 struct mgtxstk *txstk; /* Top of texture transform stack */ 107 struct mgastk *astk; /* Top of appearance stack */ 108 struct mgastk *ap_tagged;/* Tagged (persistent) appearances */ 109 short ap_min_tag, ap_max_tag; /* excluded seq. regions */ 110 short mat_min_tag, mat_max_tag; 111 short light_min_tag, light_max_tag; 112 int shown; /* Is window 'visible'? */ 113 ColorA background; /* Background color */ 114 Image *bgimage; 115 116 int opts; /* MG_SETOPTIONS flag mask */ 117 118 Transform W2C; /* World->camera transform */ 119 Transform C2W; /* Camera->world transform */ 120 121 float zfnudge; /* fraction of Z-range by which lines are 122 * nudged closer than surfaces. 123 */ 124 int space; /* space in which objects being drawn 125 * live; should be TM_EUCLIDEAN, 126 * TM_HYPERBOLIC, or TM_SPHERICAL 127 */ 128 129 130 Transform W2S, S2W; /* world-to-screen, screen-to-world xfms */ 131 132 int has; /* Flag bits, set when cached values valid */ 133 #define HAS_CPOS 0x1 /* Camera position (cpos, camZ) */ 134 #define HAS_S2O 0x2 /* S2O, O2S */ 135 #define HAS_POINT 0x4 /* Outline for generic fat point */ 136 137 /* Cached values, computed when needed: */ 138 HPoint3 cpos; /* Location of camera in object coordinates */ 139 Point3 camZ; /* Direction of camera +Z vector */ 140 Transform O2S, S2O; /* object-to-screen, screen-to-object xfms */ 141 vvec point; /* outline for fat points */ 142 143 mgNDctx *NDctx;/* pointer to caller-defined ND closure */ 144 145 mgwinchfunc winchange; /* Callback function for mg Window etc. changes */ 146 void *winchangeinfo; /* We call (*winchange)(ctx, winchangeinfo, win, changemask) */ 147 }; 148 149 #define next_ap_seq(ctx, astk) \ 150 ((((astk)->ap_seq + 1) >= (ctx)->ap_min_tag && \ 151 ((astk)->ap_seq + 1) <= (ctx)->ap_max_tag) \ 152 ? (ctx)->ap_max_tag+1 : (astk)->ap_seq + 1) 153 154 #define next_mat_seq(ctx, astk) \ 155 ((((astk)->mat_seq + 1) >= (ctx)->mat_min_tag && \ 156 ((astk)->mat_seq + 1) <= (ctx)->mat_max_tag) \ 157 ? (ctx)->mat_max_tag+1 : (astk)->mat_seq + 1) 158 159 #define next_light_seq(ctx, astk) \ 160 ((((astk)->light_seq + 1) >= (ctx)->light_min_tag && \ 161 ((astk)->light_seq + 1) <= (ctx)->light_max_tag) \ 162 ? (ctx)->light_max_tag+1 : (astk)->light_seq + 1) 163 164 /* 165 * Pointer to the current mg context. 166 */ 167 extern mgcontext *_mgc; 168 169 /* 170 * List of all extant mg contexts. 171 */ 172 extern mgcontext *_mgclist; 173 174 /* 175 * Declarations of common mg routines, accessible to other mg packages 176 * (but not intended to be public): 177 */ 178 179 /* geometry transform */ 180 extern void mg_identity(void); 181 extern void mg_transform(Transform T); 182 extern void mg_settransform(Transform T); 183 extern void mg_gettransform(Transform T); 184 extern int mg_pushtransform(void); 185 extern int mg_poptransform(void); 186 187 /* texture transform */ 188 extern void mg_txidentity(void); 189 extern void mg_txtransform(Transform T); 190 extern void mg_settxtransform(Transform T); 191 extern void mg_gettxtransform(Transform T); 192 extern int mg_pushtxtransform(void); 193 extern int mg_poptxtransform(void); 194 195 extern void mg_quads(int nquads, HPoint3 *v, Point3 *n, ColorA *c, int qflags); 196 extern void mg_bezier(int du, int dv, int dimn, float *ctrlpts, TxST *txmapst, 197 ColorA *c); 198 extern void mg_bsptree(struct BSPTree *bsptree); 199 extern void mg_findcam(); 200 extern void mg_findS2O(); 201 extern void mg_findO2S(); 202 extern void mg_makepoint(); 203 204 extern int mg_pushappearance(void); 205 extern int mg_popappearance(void); 206 extern void mg_reshapeviewport(void); 207 extern const Appearance *mg_getappearance(void); 208 extern const Appearance *mg_setappearance(const Appearance *ap, int mergeflag); 209 210 extern mgcontext *mg_newcontext(struct mgcontext *); 211 extern int mg_appearancebits( Appearance *ap, int merge, int *valid, int *flag ); 212 213 extern void mg_ctxdelete( struct mgcontext * ); 214 extern int mg_ctxselect( struct mgcontext * ); 215 extern void mg_findO2S( void ); 216 extern void mg_findS2O( void ); 217 extern void mg_findcam( void ); 218 extern void mg_makepoint( void ); 219 extern void mg_worldbegin( void ); 220 221 extern int mg_inhaletexture( Texture *tx, int rgba ); 222 223 extern TxUser *mg_find_shared_texture(Texture *tx, int mgtype); 224 extern bool mg_same_texture(Texture *tx1, Texture *tx2, bool really); 225 extern void mg_reassign_shared_textures(mgcontext *ctx, int mgtype); 226 extern int mg_find_free_shared_texture_id(int mgtype); 227 228 extern void mg_remove_txuser(TxUser *tu); 229 230 extern const void *mg_tagappearance(void); 231 extern void mg_untagappearance(const void *tag); 232 extern void mg_taggedappearance(const void *tag); 233 234 #endif /*_MG_PDEFS_*/ 235 236 /* 237 * Local Variables: *** 238 * mode: c *** 239 * c-basic-offset: 8 *** 240 * End: *** 241 */ 242