1 /* Emacs style mode select -*- C++ -*- 2 *----------------------------------------------------------------------------- 3 * 4 * 5 * PrBoom: a Doom port merged with LxDoom and LSDLDoom 6 * based on BOOM, a modified and improved DOOM engine 7 * Copyright (C) 1999 by 8 * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman 9 * Copyright (C) 1999-2000 by 10 * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze 11 * Copyright 2005, 2006 by 12 * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko 13 * 14 * This program is free software; you can redistribute it and/or 15 * modify it under the terms of the GNU General Public License 16 * as published by the Free Software Foundation; either version 2 17 * of the License, or (at your option) any later version. 18 * 19 * This program is distributed in the hope that it will be useful, 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 * GNU General Public License for more details. 23 * 24 * You should have received a copy of the GNU General Public License 25 * along with this program; if not, write to the Free Software 26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 27 * 02111-1307, USA. 28 * 29 * DESCRIPTION: 30 * 31 *--------------------------------------------------------------------- 32 */ 33 34 #ifndef _GL_INTERN_H 35 #define _GL_INTERN_H 36 37 #include "v_video.h" 38 39 #define MAP_COEFF 128.0f 40 #define MAP_SCALE (MAP_COEFF*(float)FRACUNIT) 41 #define MAXCOORD (32767.0f / MAP_COEFF) 42 43 #define SMALLDELTA 0.001f 44 45 typedef enum 46 { 47 GLDT_UNREGISTERED, 48 GLDT_BROKEN, 49 GLDT_PATCH, 50 GLDT_TEXTURE, 51 GLDT_FLAT 52 } GLTexType; 53 54 typedef enum 55 { 56 MIP_TEXTURE, 57 MIP_SPRITE, 58 MIP_PATCH, 59 60 MIP_COUNT 61 } GLMipType; 62 63 typedef struct tex_filter_s 64 { 65 int mipmap; 66 int mag_filter; 67 int min_filter; 68 } tex_filter_t; 69 70 typedef enum 71 { 72 GLTEXTURE_SPRITE = 0x00000002, 73 GLTEXTURE_HASHOLES = 0x00000004, 74 GLTEXTURE_SKY = 0x00000008, 75 GLTEXTURE_HIRES = 0x00000010, 76 GLTEXTURE_HASNOHIRES= 0x00000020, 77 GLTEXTURE_CLAMPX = 0x00000040, 78 GLTEXTURE_CLAMPY = 0x00000080, 79 GLTEXTURE_CLAMPXY = (GLTEXTURE_CLAMPX | GLTEXTURE_CLAMPY), 80 GLTEXTURE_MIPMAP = 0x00000100, 81 } GLTexture_flag_t; 82 83 typedef struct gl_strip_coords_s 84 { 85 GLfloat v[4][3]; 86 87 GLfloat t[4][2]; 88 } gl_strip_coords_t; 89 90 #define PLAYERCOLORMAP_COUNT (3) 91 92 typedef struct detail_s 93 { 94 GLuint texid; 95 int texture_num; 96 float width, height; 97 float offsetx, offsety; 98 } detail_t; 99 100 typedef struct 101 { 102 int index; 103 int width,height; 104 int leftoffset,topoffset; 105 int tex_width,tex_height; 106 int realtexwidth, realtexheight; 107 int buffer_width,buffer_height; 108 int buffer_size; 109 110 //e6y: support for Boom colormaps 111 GLuint ***glTexExID; 112 unsigned int texflags[CR_LIMIT+MAXPLAYERS][PLAYERCOLORMAP_COUNT]; 113 GLuint *texid_p; 114 unsigned int *texflags_p; 115 116 int cm; 117 int player_cm; 118 119 GLTexType textype; 120 unsigned int flags; 121 float scalexfac, scaleyfac; //e6y: right/bottom UV coordinates for patch drawing 122 123 //detail 124 detail_t *detail; 125 float detail_width, detail_height; 126 } GLTexture; 127 128 typedef struct 129 { 130 float x1,x2; 131 float z1,z2; 132 dboolean fracleft, fracright; //e6y 133 } GLSeg; 134 135 typedef struct 136 { 137 GLSeg *glseg; 138 float ytop,ybottom; 139 float ul,ur,vt,vb; 140 float light; 141 float fogdensity; 142 float alpha; 143 float skyymid; 144 float skyyaw; 145 GLTexture *gltexture; 146 byte flag; 147 seg_t *seg; 148 } GLWall; 149 150 typedef enum 151 { 152 GLFLAT_CEILING = 0x00000001, 153 GLFLAT_HAVE_OFFSET = 0x00000002, 154 } GLFlat_flag_t; 155 156 typedef struct 157 { 158 int sectornum; 159 float light; // the lightlevel of the flat 160 float fogdensity; 161 float uoffs,voffs; // the texture coordinates 162 float z; // the z position of the flat (height) 163 GLTexture *gltexture; 164 unsigned int flags; 165 float alpha; 166 } GLFlat; 167 168 /* GLLoopDef is the struct for one loop. A loop is a list of vertexes 169 * for triangles, which is calculated by the gluTesselator in gld_PrecalculateSector 170 * and in gld_PreprocessCarvedFlat 171 */ 172 typedef struct 173 { 174 int index; // subsector index 175 GLenum mode; // GL_TRIANGLES, GL_TRIANGLE_STRIP or GL_TRIANGLE_FAN 176 int vertexcount; // number of vertexes in this loop 177 int vertexindex; // index into vertex list 178 } GLLoopDef; 179 180 // GLSector is the struct for a sector with a list of loops. 181 182 #define SECTOR_CLAMPXY 0x00000001 183 typedef struct 184 { 185 int loopcount; // number of loops for this sector 186 GLLoopDef *loops; // the loops itself 187 unsigned int flags; 188 } GLSector; 189 190 typedef struct 191 { 192 int loopcount; // number of loops for this sector 193 GLLoopDef *loops; // the loops itself 194 } GLMapSubsector; 195 196 typedef struct 197 { 198 GLfloat x; 199 GLfloat y; 200 GLfloat z; 201 } GLVertex; 202 203 typedef struct 204 { 205 GLfloat u; 206 GLfloat v; 207 } GLTexcoord; 208 209 typedef struct 210 { 211 GLLoopDef loop; // the loops itself 212 } GLSubSector; 213 214 typedef struct 215 { 216 float x, y, z; 217 float radius; 218 float light; 219 } GLShadow; 220 221 extern GLSeg *gl_segs; 222 extern GLSeg *gl_lines; 223 224 #define GLDWF_TOP 1 225 #define GLDWF_M1S 2 226 #define GLDWF_M2S 3 227 #define GLDWF_BOT 4 228 #define GLDWF_TOPFLUD 5 //e6y: project the ceiling plane into the gap 229 #define GLDWF_BOTFLUD 6 //e6y: project the floor plane into the gap 230 #define GLDWF_SKY 7 231 #define GLDWF_SKYFLIP 8 232 233 typedef struct 234 { 235 int cm; 236 float x,y,z; 237 float vt,vb; 238 float ul,ur; 239 float x1,y1; 240 float x2,y2; 241 float light; 242 float fogdensity; 243 fixed_t scale; 244 GLTexture *gltexture; 245 uint_64_t flags; 246 int index; 247 int xy; 248 } GLSprite; 249 250 typedef enum 251 { 252 GLDIT_NONE, 253 254 GLDIT_WALL, // opaque wall 255 GLDIT_MWALL, // opaque mid wall 256 GLDIT_FWALL, // projected wall 257 GLDIT_TWALL, // transparent walls 258 GLDIT_SWALL, // sky walls 259 260 GLDIT_AWALL, // animated wall 261 GLDIT_FAWALL, // animated projected wall 262 263 GLDIT_CEILING, // ceiling 264 GLDIT_FLOOR, // floor 265 266 GLDIT_ACEILING, // animated ceiling 267 GLDIT_AFLOOR, // animated floor 268 269 GLDIT_SPRITE, // opaque sprite 270 GLDIT_TSPRITE, // transparent sprites 271 GLDIT_ASPRITE, 272 273 GLDIT_SHADOW, 274 275 GLDIT_TYPES 276 } GLDrawItemType; 277 278 typedef struct GLDrawItem_s 279 { 280 union 281 { 282 void *item; 283 GLWall *wall; 284 GLFlat *flat; 285 GLSprite *sprite; 286 GLShadow *shadow; 287 } item; 288 } GLDrawItem; 289 290 typedef struct GLDrawDataItem_s 291 { 292 byte *data; 293 int maxsize; 294 int size; 295 } GLDrawDataItem_t; 296 297 typedef struct 298 { 299 GLDrawDataItem_t *data; 300 int maxsize; 301 int size; 302 303 GLDrawItem *items[GLDIT_TYPES]; 304 int num_items[GLDIT_TYPES]; 305 int max_items[GLDIT_TYPES]; 306 } GLDrawInfo; 307 308 void gld_AddDrawItem(GLDrawItemType itemtype, void *itemdata); 309 310 void gld_DrawTriangleStrip(GLWall *wall, gl_strip_coords_t *c); 311 void gld_DrawTriangleStripARB(GLWall *wall, gl_strip_coords_t *c1, gl_strip_coords_t *c2); 312 313 extern float roll; 314 extern float yaw; 315 extern float inv_yaw; 316 extern float pitch; 317 318 extern int gl_compatibility; 319 extern int gl_ztrick; 320 321 extern int gl_preprocessed; //e6y 322 323 extern GLDrawInfo gld_drawinfo; 324 void gld_FreeDrawInfo(void); 325 void gld_ResetDrawInfo(void); 326 327 extern GLSector *sectorloops; 328 extern GLMapSubsector *subsectorloops; 329 330 extern const char *gl_tex_format_string; 331 extern int gl_tex_format; 332 extern int gl_texture_filter_anisotropic; 333 extern int transparent_pal_index; 334 extern unsigned char gld_palmap[256]; 335 extern tex_filter_t tex_filter[]; 336 void gld_SetTexFilters(GLTexture *gltexture); 337 338 extern float xCamera,yCamera,zCamera; 339 340 // 341 //detail 342 // 343 344 int gld_IsDetailVisible(float x0, float y0, float x1, float y1, float x2, float y2); 345 void gld_InitDetail(void); 346 void gld_InitFrameDetails(void); 347 void gld_ParseDetail(void); 348 void gld_SetTexDetail(GLTexture *gltexture); 349 350 void gld_PreprocessDetail(void); 351 void gld_DrawDetail_NoARB(void); 352 void gld_EnableDetail(int enable); 353 void gld_DrawWallWithDetail(GLWall *wall); 354 void gld_BindDetail(GLTexture *gltexture, int enable); 355 void gld_BindDetailARB(GLTexture *gltexture, int enable); 356 void gld_DrawItemsSortByDetail(GLDrawItemType itemtype); 357 void gld_DrawWallDetail_NoARB(GLWall *wall); 358 359 extern int render_usedetail; 360 extern int scene_has_details; 361 extern detail_t *details; 362 extern int details_count; 363 364 extern int scene_has_wall_details; 365 extern int scene_has_flat_details; 366 367 extern GLuint* last_glTexID; 368 GLTexture *gld_RegisterTexture(int texture_num, dboolean mipmap, dboolean force); 369 void gld_BindTexture(GLTexture *gltexture, unsigned int flags); 370 GLTexture *gld_RegisterPatch(int lump, int cm); 371 void gld_BindPatch(GLTexture *gltexture, int cm); 372 GLTexture *gld_RegisterFlat(int lump, dboolean mipmap); 373 void gld_BindFlat(GLTexture *gltexture, unsigned int flags); 374 void gld_InitPalettedTextures(void); 375 int gld_GetTexDimension(int value); 376 void gld_SetTexturePalette(GLenum target); 377 void gld_Precache(void); 378 379 //gamma 380 void gld_ResetGammaRamp(void); 381 382 //gl_vertex 383 void gld_SplitLeftEdge(const GLWall *wall, dboolean detail); 384 void gld_SplitRightEdge(const GLWall *wall, dboolean detail); 385 void gld_RecalcVertexHeights(const vertex_t *v); 386 387 //e6y 388 void gld_InitGLVersion(void); 389 void gld_ResetLastTexture(void); 390 391 unsigned char* gld_GetTextureBuffer(GLuint texid, int miplevel, int *width, int *height); 392 393 int gld_BuildTexture(GLTexture *gltexture, void *data, dboolean readonly, int width, int height); 394 395 //hires 396 extern unsigned int gl_has_hires; 397 int gld_HiRes_BuildTables(void); 398 void gld_InitHiRes(void); 399 int gld_LoadHiresTex(GLTexture *gltexture, int cm); 400 void gld_GetTextureTexID(GLTexture *gltexture, int cm); 401 GLuint CaptureScreenAsTexID(void); 402 void gld_ProgressUpdate(const char * text, int progress, int total); 403 int gld_ProgressStart(void); 404 int gld_ProgressEnd(void); 405 406 //FBO 407 #define INVUL_CM 0x00000001 408 #define INVUL_INV 0x00000002 409 #define INVUL_BW 0x00000004 410 extern GLuint glSceneImageFBOTexID; 411 extern GLuint glSceneImageTextureFBOTexID; 412 413 extern unsigned int invul_method; 414 extern float bw_red; 415 extern float bw_green; 416 extern float bw_blue; 417 extern int SceneInTexture; 418 extern int gl_invul_bw_method; 419 void gld_InitFBO(void); 420 void gld_FreeScreenSizeFBO(void); 421 422 //motion bloor 423 extern int gl_motionblur; 424 extern int gl_use_motionblur; 425 extern const char *gl_motionblur_minspeed; 426 extern char *gl_motionblur_linear_k; 427 extern char *gl_motionblur_linear_b; 428 extern int MotionBlurOn; 429 extern int gl_motionblur_minspeed_pow2; 430 extern float gl_motionblur_a; 431 extern float gl_motionblur_b; 432 extern float gl_motionblur_c; 433 434 extern int imageformats[]; 435 436 //missing flats (fake floors and ceilings) 437 438 void gld_PreprocessFakeSectors(void); 439 440 void gld_SetupFloodStencil(GLWall *wall); 441 void gld_ClearFloodStencil(GLWall *wall); 442 443 void gld_SetupFloodedPlaneCoords(GLWall *wall, gl_strip_coords_t *c); 444 void gld_SetupFloodedPlaneLight(GLWall *wall); 445 446 //light 447 extern int gl_rellight; 448 void gld_StaticLightAlpha(float light, float alpha); 449 #define gld_StaticLight(light) gld_StaticLightAlpha(light, 1.0f) 450 void gld_InitLightTable(void); 451 typedef float (*gld_CalcLightLevel_f)(int lightlevel); 452 typedef float (*gld_Calc2DLightLevel_f)(int lightlevel); 453 extern gld_CalcLightLevel_f gld_CalcLightLevel; 454 extern gld_Calc2DLightLevel_f gld_Calc2DLightLevel; 455 456 //fog 457 extern int gl_fog; 458 extern int gl_use_fog; 459 void gl_EnableFog(int on); 460 void gld_SetFog(float fogdensity); 461 typedef float (*gld_CalcFogDensity_f)(sector_t *sector, int lightlevel, GLDrawItemType type); 462 extern gld_CalcFogDensity_f gld_CalcFogDensity; 463 464 //HQ resize 465 unsigned char* gld_HQResize(GLTexture *gltexture, unsigned char *inputBuffer, int inWidth, int inHeight, int *outWidth, int *outHeight); 466 467 // SkyBox 468 #define SKY_NONE 0 469 #define SKY_CEILING 1 470 #define SKY_FLOOR 2 471 typedef struct PalEntry_s 472 { 473 unsigned char r, g, b; 474 } PalEntry_t; 475 typedef struct SkyBoxParams_s 476 { 477 int index; 478 unsigned int type; 479 GLWall wall; 480 float x_scale, y_scale; 481 float x_offset, y_offset; 482 // 0 - no colormap; 1 - INVUL inverse colormap 483 PalEntry_t FloorSkyColor[2]; 484 PalEntry_t CeilingSkyColor[2]; 485 // for BoxSkybox 486 side_t *side; 487 } SkyBoxParams_t; 488 extern SkyBoxParams_t SkyBox; 489 extern GLfloat gl_whitecolor[]; 490 void gld_InitSky(void); 491 void gld_AddSkyTexture(GLWall *wall, int sky1, int sky2, int skytype); 492 void gld_GetSkyCapColors(void); 493 void gld_InitFrameSky(void); 494 void gld_DrawStripsSky(void); 495 void gld_DrawScreenSkybox(void); 496 void gld_GetScreenSkyScale(GLWall *wall, float *scale_x, float *scale_y); 497 void gld_DrawDomeSkyBox(void); 498 void gld_DrawSkyCaps(void); 499 int gld_DrawBoxSkyBox(void); 500 501 // shadows 502 void gld_InitShadows(void); 503 void gld_ProcessThingShadow(mobj_t *mo); 504 void gld_RenderShadows(void); 505 506 // VBO 507 typedef struct vbo_vertex_s 508 { 509 float x, y, z; 510 float u, v; 511 unsigned char r, g, b, a; 512 } vbo_vertex_t; 513 #define NULL_VBO_VERTEX ((vbo_vertex_t*)NULL) 514 #define sky_vbo_x (gl_ext_arb_vertex_buffer_object ? &NULL_VBO_VERTEX->x : &vbo->data[0].x) 515 #define sky_vbo_u (gl_ext_arb_vertex_buffer_object ? &NULL_VBO_VERTEX->u : &vbo->data[0].u) 516 #define sky_vbo_r (gl_ext_arb_vertex_buffer_object ? &NULL_VBO_VERTEX->r : &vbo->data[0].r) 517 518 typedef struct vbo_xyz_uv_s 519 { 520 float x, y, z; 521 float u, v; 522 } vbo_xyz_uv_t; 523 extern vbo_xyz_uv_t *flats_vbo; 524 #define NULL_VBO_XYZ_UV ((vbo_xyz_uv_t*)NULL) 525 #define flats_vbo_x (gl_ext_arb_vertex_buffer_object ? &NULL_VBO_XYZ_UV->x : &flats_vbo[0].x) 526 #define flats_vbo_u (gl_ext_arb_vertex_buffer_object ? &NULL_VBO_XYZ_UV->u : &flats_vbo[0].u) 527 528 //BoxSkybox 529 typedef struct box_skybox_s 530 { 531 char name[9]; 532 int fliptop; 533 char faces[6][9]; 534 GLTexture texture[6]; 535 } box_skybox_t; 536 box_skybox_t* R_GetBoxSkybox(int index); 537 void gld_ParseSkybox(void); 538 extern box_skybox_t *BoxSkybox_default; 539 540 // display lists 541 void gld_InitDisplayLists(void); 542 void gld_CleanDisplayLists(void); 543 extern int flats_display_list; 544 545 // preprocessing 546 extern byte *segrendered; // true if sector rendered (only here for malloc) 547 extern byte *linerendered[2]; // true if linedef rendered (only here for malloc) 548 extern GLuint flats_vbo_id; 549 550 #endif // _GL_INTERN_H 551