1 // Emacs style mode select -*- C++ -*- 2 //----------------------------------------------------------------------------- 3 // 4 // $Id: r_data.h 1558 2020-11-17 23:36:10Z wesleyjohnson $ 5 // 6 // Copyright (C) 1993-1996 by id Software, Inc. 7 // Portions Copyright (C) 1998-2000 by DooM Legacy Team. 8 // 9 // This program is free software; you can redistribute it and/or 10 // modify it under the terms of the GNU General Public License 11 // as published by the Free Software Foundation; either version 2 12 // of the License, or (at your option) any later version. 13 // 14 // This program is distributed in the hope that it will be useful, 15 // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 // GNU General Public License for more details. 18 // 19 // 20 // $Log: r_data.h,v $ 21 // Revision 1.6 2001/03/13 22:14:20 stroggonmeth 22 // Long time no commit. 3D floors, FraggleScript, portals, ect. 23 // 24 // Revision 1.5 2000/11/02 17:50:09 stroggonmeth 25 // Big 3Dfloors & FraggleScript commit!! 26 // 27 // Revision 1.4 2000/04/13 23:47:47 stroggonmeth 28 // See logs 29 // 30 // Revision 1.3 2000/04/04 00:32:47 stroggonmeth 31 // Initial Boom compatability plus few misc changes all around. 32 // 33 // Revision 1.2 2000/02/27 00:42:10 hurdler 34 // Revision 1.1.1.1 2000/02/22 20:32:32 hurdler 35 // Initial import into CVS (v1.29 pr3) 36 // 37 // 38 // DESCRIPTION: 39 // Refresh module, data I/O, caching, retrieval of graphics 40 // by name. 41 // 42 //----------------------------------------------------------------------------- 43 44 45 #ifndef R_DATA_H 46 #define R_DATA_H 47 48 #include "doomdef.h" 49 // ENABLE_DRAWxx 50 #include "doomtype.h" 51 // RBGA_t 52 #include "r_defs.h" 53 #include "r_state.h" 54 #include "command.h" 55 // CV_PossibleValue_t 56 57 #ifdef __GNUG__ 58 #pragma interface 59 #endif 60 61 62 // moved here for r_sky.c (texture_t is used) 63 64 // 65 // Texture definition. 66 // Each texture is composed of one or more patches, 67 // with patches being lumps stored in the WAD. 68 // The lumps are referenced by number, and patched 69 // into the rectangular texture space using origin 70 // and possibly other attributes. 71 // 72 // Used to read texture patch info from wad, sizes must be correct. 73 typedef struct 74 { 75 // The patches leftoffset and topoffset are ignored. 76 int16_t originx; // from top left of texture area 77 int16_t originy; 78 uint16_t patchnum; // index [0..] of the entry in PNAMES 79 int16_t stepdir; // 1 80 uint16_t colormap; // 0 81 } mappatch_t; 82 83 84 85 // 86 // Texture definition. 87 // A DOOM wall texture is a list of patches 88 // which are to be combined in a predefined order. 89 // 90 // Used to read texture lump from wad, sizes must be correct. 91 // UDS is unclear on the exact size of some of these fields. 92 typedef struct 93 { 94 char name[8]; 95 uint32_t masked; // [8] must be 4 bytes 96 // boolean size cannot be trusted 97 uint16_t width; // [12] 98 uint16_t height; // [14] 99 char columndirectory[4]; //void **columndirectory; // OBSOLETE 100 uint16_t patchcount; // [20] 101 mappatch_t patches[1]; // [22] array 102 } maptexture_t; 103 104 // A single patch from a texture definition, 105 // basically a rectangular area within the texture rectangle. 106 // Used only in internal texture struct. Wad read uses mappatch_t, which has more fields. 107 // There is clipping code for originx<0 and originy<0, which occur in doom wads. 108 // The original doom has a clipping bug when originy < 0. 109 typedef struct 110 { 111 int32_t originx; 112 int32_t originy; 113 lumpnum_t lumpnum; 114 } texpatch_t; 115 116 // [WDJ] 2/8/2010 117 typedef enum { 118 TM_none, 119 TM_patch, // original single patch texture (has draw) 120 TM_picture, // drawn into picture buffer (has draw) 121 TM_combine_patch, // transparent combined multi-patch texture (has draw) 122 TM_multi_patch, // original multi-patch texture 123 TM_column_image, // raw image, (column x row) 124 TM_row_image, // raw image, (row x column) 125 TM_masked, // detect masked flag (hint) 126 TM_picture_column, // force column with no posts (hint) 127 TM_invalid // disabled for some internal reason 128 } texture_model_e; 129 130 typedef enum { 131 TD_hole = 0x01, // holes in patch 132 TD_post = 0x02, // posts 133 TD_solid_column = 0x08, // one post of texture height 134 TD_masked = 0x10, // used as masked 135 TD_odd_width = 0x20, // not power of 2 136 TD_message = 0x80 137 } texture_detect_e; 138 139 140 141 // texture_t describes a rectangular texture, which is composed of 142 // one or more graphic patches in texpatch_t structures. 143 // Used internally only. 144 typedef struct 145 { 146 // Keep name for switch changing, etc. 147 char name[8]; 148 uint16_t width; 149 uint16_t height; 150 byte detect; // texture detects 151 152 // All the patches[patchcount] 153 // are drawn back to front into the cached texture. 154 uint16_t patchcount; 155 texpatch_t patches[1]; 156 } texture_t; 157 158 159 // All loaded and prepared textures from the start of the game, 160 // Contains info from the TEXTURE1 and TEXTURE2 lumps. 161 // [WDJ] Original Doom bug: conflict between texture[0] and 0=no-texture. 162 // Their solution was to not use the first texture. 163 // See BUGFIX_TEXTURE0 in r_data.c. 164 // array[ 0.. numtextures-1 ] of texture_t*, 165 // but [0] is unusable because it conflicts with 0=no-texture. 166 167 extern int numtextures; 168 extern texture_t** textures; 169 170 // [WDJ] To reduce the repeated indexing using texture id num, better locality of reference in cache. 171 // To allow creating a texture that was not loaded from textures[]. 172 // Holds all the software render information. 173 typedef struct 174 { 175 byte * cache; // graphics data generated full-size texture (maybe TM_patch, or TM_picture) 176 uint32_t * columnofs; // column offset lookup table for this texture 177 uint16_t width_tile_mask; // mask that tiles the texture 178 uint16_t width; 179 #ifdef DEBUG_WINDOWED 180 texture_model_e texture_model; // drawing and storage models 181 #else 182 byte texture_model; // drawing and storage models 183 #endif 184 byte detect; // texture_detect_e flags 185 byte pixel_data_offset; // to add to columnofs[] 186 #ifdef RENDER_TEXTURE_EXTRA_FULL 187 byte extra_index; // additional texture_render for same texture 188 #endif 189 } texture_render_t; 190 191 // Array [ num_textures ] 192 extern texture_render_t * texture_render; 193 194 texture_render_t * R_Get_extra_texren( int texture_num, texture_render_t * base_texren, byte model ); 195 196 197 // textureheight is not used in the same locality as the other texture arrays. 198 // Array [ num_textures ] 199 extern fixed_t* textureheight; // needed for texture pegging 200 // [WDJ] Future consideration, as a render struct field. 201 // fixed_t heightz; // world coord. height, for texture pegging 202 203 //extern lighttable_t *colormaps; 204 extern CV_PossibleValue_t Color_cons_t[]; 205 206 // Load TEXTURE1/TEXTURE2/PNAMES definitions, create lookup tables 207 void R_Load_Textures (void); 208 void R_Flush_Texture_Cache (void); 209 210 // R_Create_Patch flags 211 enum { 212 CPO_blank_trim = 0x20, // trim blank columns 213 }; 214 215 // src_type : TM_row_image (pic_t), TM_column_image (patch, picture) 216 // src_data : source data 217 // bytepp : source pixel size in bytes 218 // sel_offset : offset into pixel, 0..3 219 // blank_value : pixel value that is blank space, >255 = no blank pixel value 220 // out_type : TM_patch, TM_picture, TM_column_image 221 // out_flags : in created patch 222 // CPO_blank_trim : trim blank columns 223 // out_header : temp patch header for width and offset 224 byte * R_Create_Patch( unsigned int width, unsigned int height, 225 /*SRC*/ byte src_type, byte * src_data, byte bytepp, byte sel_offset, uint16_t blank_value, 226 /*DEST*/ byte out_type, byte out_flags, patch_t * out_header ); 227 228 #if 0 229 void R_Set_Texture_Patch( int texnum, patch_t * patch ); 230 #endif 231 232 // Generate a texture from texture desc. and patches. 233 byte* R_GenerateTexture ( texture_render_t * texren, byte texture_req ); 234 byte* R_GenerateTexture2 ( int texnum, texture_render_t * texren, byte texture_req ); 235 236 237 byte* R_GetFlat (int flatnum); 238 239 // I/O, setting up the stuff. 240 void R_Load_Data (void); 241 void R_PrecacheLevel (void); 242 243 void R_Init_rdata(void); 244 // Upon change in rendermode. 245 void R_rdata_setup_rendermode( void ); 246 247 // Retrieval. 248 // Floor/ceiling opaque texture tiles, 249 // lookup by name. For animation? 250 lumpnum_t R_FlatNumForName (const char *name); 251 252 253 // Called by P_Ticker for switches and animations, 254 // returns the texture number for the texture name. 255 int R_TextureNumForName (const char *name); 256 int R_CheckTextureNumForName (const char *name); 257 258 259 void R_Clear_Colormaps(); 260 int R_ColormapNumForName(const char *name); 261 262 // The colorstr is the toptexture name. 263 // The ctrlstr is the midtexture name. 264 // The fadestr is the bottomtexture name. 265 int R_Create_Colormap_str(char *colorstr, char *ctrlstr, char *fadestr); 266 267 // [WDJ] Analyze an extra colormap to derive some GL parameters 268 void R_Colormap_Analyze( int mapnum ); 269 270 char *R_ColormapNameForNum(int num); 271 272 // [WDJ] 2012-02-06 shared for DRAW15, DRAW16, DRAW24, DRAW32 273 // hicolor tables, vid dependent 274 union color8_u { 275 #if defined( ENABLE_DRAW15 ) || defined( ENABLE_DRAW16 ) 276 uint16_t to16[256]; 277 #endif 278 #if defined( ENABLE_DRAW24 ) || defined( ENABLE_DRAW32 ) 279 uint32_t to32[256]; 280 #endif 281 byte dummy; // prevent errors when only 8bpp 282 }; 283 extern union color8_u color8; 284 void R_Init_color8_translate ( RGBA_t * palette ); 285 #ifdef ENABLE_DRAW8_USING_12 286 extern byte color12_to_8[ 0x1000 ]; 287 void R_Init_color12_translate( RGBA_t * palette ); 288 #endif 289 290 byte NearestColor(byte r, byte g, byte b); 291 292 // translucency tables 293 294 // TODO: add another asm routine which use the fg and bg indexes in the 295 // inverse order so the 20-80 becomes 80-20 translucency, no need 296 // for other tables (thus 1090,2080,5050,8020,9010, and fire special) 297 298 typedef enum 299 { 300 // 0 is not translucent 301 TRANSLU_med=1, //sprite 50 backg 50 most shots 302 TRANSLU_more=2, // 20 80 puffs 303 TRANSLU_hi=3, // 10 90 blur effect 304 TRANSLU_fire=4, // 50 50 but brighter for fireballs, shots.. 305 TRANSLU_fx1=5, // 50 50 brighter some colors, else opaque for torches 306 TRANSLU_75=6, // 75 25 307 TRANSLU_ext=7 // Boom external transparency table 308 } translucent_e; 309 310 // Translucent table is 256x256, 311 // To overlay a translucent source on an existing dest: 312 // *dest = table[source][*dest]; 313 // *dest = table[ (source<<8) + (*dest) ]; 314 315 // 0 code does not have a table, so must subtract 1, (or one table size). 316 // Table size is 0x10000, = 1<<FF_TRANSSHIFT. 317 #define TRANSLU_TABLE_INDEX( trans ) (((trans)-1)<<FF_TRANSSHIFT) 318 319 typedef enum 320 { 321 TRANSLU_TABLE_med = TRANSLU_TABLE_INDEX(TRANSLU_med), 322 TRANSLU_TABLE_more = TRANSLU_TABLE_INDEX(TRANSLU_more), 323 TRANSLU_TABLE_hi = TRANSLU_TABLE_INDEX(TRANSLU_hi), 324 TRANSLU_TABLE_fire = TRANSLU_TABLE_INDEX(TRANSLU_fire), 325 TRANSLU_TABLE_fx1 = TRANSLU_TABLE_INDEX(TRANSLU_fx1) 326 } translucent_table_index_e; 327 328 // Table of alpha = 0..255 to translucent tables to be used for DRAW8PAL 329 // index by alpha >> 4 330 extern const unsigned int translucent_alpha_table[16]; 331 // alpha where reversed translucent tables are used 332 #define TRANSLU_REV_ALPHA 144 333 334 335 typedef struct 336 { 337 uint32_t translu_lump_num; // translucent table lump 338 // byte * translu_map; // translucent tables [256][256] 339 // Analysis 340 byte alpha; // alpha 0..255 341 byte opaque, clear; // 0..100 342 // render aids 343 byte substitute_std_translucent; // from translucent_e 344 byte substitute_error; // 0..255, 0 is perfect 345 int PF_op; // hardware translucent operation 346 } translucent_map_t; 347 348 extern translucent_map_t * translu_store; // array 349 350 int R_setup_translu_store( int lump_num ); 351 352 353 // Fog data structure 354 typedef enum 355 { 356 FW_colormap, // use colormap fog (which only colors all sectors) 357 // water 358 FW_clear, // no fog (old WATER default) 359 FW_cast, // paint all surfaces with textures 360 FW_fogfluid, // outside, inside fluid, fogsheet 361 // fog 362 FW_inside, // render inside side, plane views (old FOG) 363 FW_foglite, // outside side, plane views, low alpha overall fog sheet 364 FW_fogdust, // outside, when in fog apply overall fog sheet (FOG default) 365 FW_fogsheet, // outside, inside, overall fog sheet, sector join fog sheet 366 FW_num 367 } fogwater_effect_e; 368 369 enum fogwater_flags_e { 370 // default index 371 FWF_water = 1, 372 FWF_fog = 2, 373 FWF_opaque_water = 3, 374 FWF_solid_floor = 4, 375 FWF_index = 0x03, 376 // flags 377 FWF_default_alpha = 0x40, 378 FWF_default_effect = 0x80, 379 }; 380 381 // fake floor fog and water effects 382 typedef struct 383 { 384 fogwater_effect_e effect; 385 byte alpha; // alpha 0..255 386 byte fsh_alpha; // fog sheet reduced alpha 387 byte flags; // FWF_ from fogwater_flags_e 388 } fogwater_t; 389 390 extern fogwater_t * fweff; // array 391 // 0 of the array is not used 392 393 // return index into fog_store 394 int R_Create_FW_effect( int special_linedef, char * tstr ); 395 void R_Clear_FW_effect( void ); 396 void R_FW_config_update( void ); // upon config change 397 398 #endif 399