1 /* 2 Copyright (C) 2003-2006 Andrey Nazarov 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 13 See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 */ 20 21 #ifdef SOFTWARE_RENDERER 22 #ifdef TRUECOLOR_RENDERER 23 #define VID_BPP 32 24 #define VID_BYTES 4 25 #define VID_SHIFT 2 26 #define VID_IS32BIT 1 27 #else 28 #define VID_BPP 8 29 #define VID_BYTES 1 30 #define VID_SHIFT 0 31 #define VID_IS32BIT 0 32 #endif 33 #endif 34 35 #ifdef USE_BGRA_FORMAT 36 #define MakeColor( r, g, b, a ) MakeLittleLong( b, g, r, a ) 37 #else 38 #define MakeColor( r, g, b, a ) MakeLittleLong( r, g, b, a ) 39 #endif 40 41 // absolute limit for OpenGL renderer 42 #define MAX_TEXTURE_SIZE 2048 43 44 /* 45 46 skins will be outline flood filled and mip mapped 47 pics and sprites with alpha will be outline flood filled 48 pic won't be mip mapped 49 50 model skin 51 sprite frame 52 wall texture 53 pic 54 55 */ 56 57 typedef enum { 58 if_transparent = ( 1 << 0 ), 59 if_paletted = ( 1 << 1 ), 60 if_scrap = ( 1 << 2 ), 61 if_replace_wal = ( 1 << 3 ), 62 if_replace_pcx = ( 1 << 4 ), 63 if_auto = ( 1 << 5 ), 64 if_charset = ( 1 << 6 ) 65 } imageflags_t; 66 67 typedef enum { 68 it_skin, 69 it_sprite, 70 it_wall, 71 it_pic, 72 it_sky, 73 it_lightmap, 74 it_charset 75 } imagetype_t; 76 77 #define EXTENSION_PNG MakeLittleLong( '.', 'p', 'n', 'g' ) 78 #define EXTENSION_TGA MakeLittleLong( '.', 't', 'g', 'a' ) 79 #define EXTENSION_JPG MakeLittleLong( '.', 'j', 'p', 'g' ) 80 #define EXTENSION_PCX MakeLittleLong( '.', 'p', 'c', 'x' ) 81 #define EXTENSION_WAL MakeLittleLong( '.', 'w', 'a', 'l' ) 82 83 typedef struct image_s { 84 listElem_t elem; 85 char name[MAX_QPATH]; // game path, without extension 86 int baselength; // length of the path without extension 87 imagetype_t type; 88 int width, height; // source image 89 int upload_width, upload_height; // after power of two and picmip 90 int registration_sequence; // 0 = free 91 #ifdef OPENGL_RENDERER 92 uint32 texnum; // gl texture binding 93 float sl, sh, tl, th; 94 #elif SOFTWARE_RENDERER 95 byte *pixels[4]; // mip levels 96 #else 97 #error Neither OPENGL_RENDERER nor SOFTWARE_RENDERER defined 98 #endif 99 imageflags_t flags; 100 } image_t; 101 102 103 #define MAX_RIMAGES 1024 104 #define RIMAGES_HASH 256 105 106 extern image_t r_images[MAX_RIMAGES]; 107 extern list_t r_imageHash[RIMAGES_HASH]; 108 extern int r_numImages; 109 110 extern uint32 d_8to24table[256]; 111 112 #define R_Malloc( size ) com.TagMalloc( size, TAG_RENDERER ) 113 114 /* these are implemented in r_images.c */ 115 image_t *R_FindImage( const char *name, imagetype_t type ); 116 image_t *R_AllocImage( const char *name ); 117 image_t *R_CreateImage( const char *name, byte *pic, int width, int height, 118 imagetype_t type, imageflags_t flags ); 119 void R_FreeUnusedImages( void ); 120 void R_FreeAllImages( void ); 121 void R_InitImageManager( void ); 122 void R_ShutdownImageManager( void ); 123 void R_ResampleTexture( const byte *in, int inwidth, int inheight, byte *out, 124 int outwidth, int outheight ); 125 void R_GetPalette( byte **dest ); 126 127 void Image_LoadPCX( const char *filename, byte **pic, byte *palette, int *width, int *height ); 128 void Image_LoadTGA( const char *filename, byte **pic, int *width, int *height ); 129 qboolean Image_WriteTGA( const char *filename, const byte *rgb, int width, int height ); 130 #ifdef USE_LIBJPEG 131 void Image_LoadJPG( const char *filename, byte **pic, int *width, int *height ); 132 qboolean Image_WriteJPG( const char *filename, const byte *rgb, int width, int height, int quality ); 133 #endif 134 135 /* these should be implemented by renderer library itself */ 136 void R_FreeImage( image_t *image ); 137 void R_LoadImage( image_t *image, byte *pic, int width, int height, imagetype_t type, imageflags_t flags ); 138 image_t *R_LoadWal( const char *name ); 139 140 extern int registration_sequence; 141 extern image_t *r_notexture; 142 143 // 144 // BSP MODELS 145 // 146 147 #ifdef SOFTWARE_RENDERER 148 149 // FIXME: differentiate from texinfo SURF_ flags 150 #define SURF_PLANEBACK 0x02 151 #define SURF_DRAWSKY 0x04 // sky brush face 152 #define SURF_FLOW 0x08 //PGM 153 #define SURF_DRAWTURB 0x10 154 #define SURF_DRAWBACKGROUND 0x40 155 #define SURF_DRAWSKYBOX 0x80 // sky box 156 157 #define EXTRA_SURFACES 6 158 #define EXTRA_VERTICES 8 159 #define EXTRA_EDGES 12 160 #define EXTRA_SURFEDGES 24 161 162 #else // SOFTWARE_RENDERER 163 164 #define EXTRA_SURFACES 0 165 #define EXTRA_VERTICES 0 166 #define EXTRA_EDGES 0 167 #define EXTRA_SURFEDGES 0 168 169 #endif // !SOFTWARE_RENDERER 170 171 typedef struct bspTexinfo_s { 172 char name[MAX_QPATH]; 173 uint32 contents; 174 uint32 flags; 175 vec3_t axis[2]; 176 #ifdef OPENGL_RENDERER 177 vec3_t normalizedAxis[2]; 178 #endif 179 vec2_t offset; 180 int numFrames; 181 struct bspTexinfo_s *animNext; 182 image_t *image; 183 } bspTexinfo_t; 184 185 #ifdef OPENGL_RENDERER 186 typedef enum { 187 DSURF_POLY, 188 DSURF_WARP, 189 DSURF_NOLM, 190 DSURF_MESH, 191 192 DSURF_NUM_TYPES 193 } drawSurfType_t; 194 #endif 195 196 typedef struct bspSurface_s { 197 #ifdef OPENGL_RENDERER 198 /* ======> */ 199 drawSurfType_t type; 200 /* <====== */ 201 #endif 202 203 int index; 204 205 vec3_t origin; 206 vec3_t mins; 207 vec3_t maxs; 208 209 bspTexinfo_t *texinfo; 210 byte *lightmap; 211 int *firstSurfEdge; 212 int numSurfEdges; 213 214 cplane_t *plane; 215 int side; 216 217 int texturemins[2]; 218 int extents[2]; 219 220 #ifdef OPENGL_RENDERER 221 struct tcoord_s *normalizedTC; 222 struct bspPoly_s *polys; 223 224 int lightmapnum; 225 226 int drawframe; 227 int dlightframe; 228 int dlightbits; 229 int testframe; 230 231 struct bspSurface_s *next; 232 #endif 233 } bspSurface_t; 234 235 typedef struct bspNode_s { 236 /* ======> */ 237 cplane_t *plane; /* should never be NULL for nodes */ 238 int index; 239 240 vec3_t mins; 241 vec3_t maxs; 242 243 int visframe; 244 245 struct bspNode_s *parent; 246 /* <====== */ 247 248 int numFaces; 249 bspSurface_t *firstFace; 250 251 struct bspNode_s *children[2]; 252 } bspNode_t; 253 254 typedef struct bspLeaf_s { 255 /* ======> */ 256 cplane_t *plane; /* should always be NULL for leafs */ 257 int index; 258 259 vec3_t mins; 260 vec3_t maxs; 261 262 int visframe; 263 264 struct bspNode_s *parent; 265 /* <====== */ 266 267 int cluster; 268 int area; 269 int contents; 270 271 int numLeafFaces; 272 bspSurface_t **firstLeafFace; 273 } bspLeaf_t; 274 275 typedef enum { 276 MODEL_NULL, 277 MODEL_BSP, 278 MODEL_ALIAS, 279 MODEL_SPRITE 280 } modelType_t; 281 282 typedef struct bspSubmodel_s { 283 modelType_t type; 284 285 vec3_t mins; 286 vec3_t maxs; 287 float radius; 288 289 vec3_t origin; 290 291 int numFaces; 292 bspSurface_t *firstFace; 293 294 bspNode_t *headnode; 295 } bspSubmodel_t; 296 297 typedef struct bspModel_s { 298 char name[MAX_QPATH]; 299 mempool_t pool; 300 301 bspSubmodel_t *submodels; 302 int numSubmodels; 303 304 bspTexinfo_t *texinfos; 305 int numTexinfos; 306 307 bspSurface_t *surfaces; 308 int numSurfaces; 309 310 bspSurface_t **leafFaces; 311 int numLeafFaces; 312 313 cplane_t *planes; 314 int numPlanes; 315 316 bspLeaf_t *leafs; 317 int numLeafs; 318 319 bspNode_t *nodes; 320 int numNodes; 321 322 byte *vis; 323 int numClusters; 324 int rowsize; 325 326 byte *lightmap; 327 uint32 lightmapSize; 328 329 // char *entityString; 330 331 dvertex_t *vertices; 332 int numVertices; 333 334 dedge_t *edges; 335 int numEdges; 336 337 int *surfEdges; 338 int numSurfEdges; 339 } bspModel_t; 340 341 342 extern bspModel_t r_world; 343 344 void Bsp_FreeWorld( void ); 345 qboolean Bsp_LoadWorld( const char *path ); 346 bspLeaf_t *Bsp_FindLeaf( vec3_t origin ); 347 byte *Bsp_ClusterPVS( int clusterNum ); 348 349 #ifdef OPENGL_RENDERER 350 extern bspTexinfo_t *upload_texinfo; 351 int GL_PostProcessSurface( bspSurface_t *surf ); 352 #endif 353 354 #ifdef BIGENDIAN_TARGET 355 #define LL(x) ( dst->x = LongSwap( src->x ) ) 356 #define LF(x) ( dst->x = FloatSwap( src->x ) ) 357 #define LV(x) ( dst->x[0] = FloatSwap( src->x[0] ), \ 358 dst->x[1] = FloatSwap( src->x[1] ), \ 359 dst->x[2] = FloatSwap( src->x[2] ) ) 360 #define LLV(x) ( dst->x[0] = LongSwap( src->x[0] ), \ 361 dst->x[1] = LongSwap( src->x[1] ), \ 362 dst->x[2] = LongSwap( src->x[2] ) ) 363 #define LSV(x) ( dst->x[0] = ShortSwap( src->x[0] ), \ 364 dst->x[1] = ShortSwap( src->x[1] ), \ 365 dst->x[2] = ShortSwap( src->x[2] ) ) 366 #else 367 #define LL(x) ( dst->x = src->x ) 368 #define LF(x) ( dst->x = src->x ) 369 #define LV(x) ( dst->x[0] = src->x[0], \ 370 dst->x[1] = src->x[1], \ 371 dst->x[2] = src->x[2] ) 372 #define LLV(x) ( dst->x[0] = src->x[0], \ 373 dst->x[1] = src->x[1], \ 374 dst->x[2] = src->x[2] ) 375 #define LSV(x) ( dst->x[0] = src->x[0], \ 376 dst->x[1] = src->x[1], \ 377 dst->x[2] = src->x[2] ) 378 #endif 379 380 381 382 383