Quake-2

Quake 2 GPL Source Release
Log | Files | Refs

gl_local.h (11299B)


      1 /*
      2 Copyright (C) 1997-2001 Id Software, Inc.
      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 // disable data conversion warnings
     21 
     22 #if 0
     23 #pragma warning(disable : 4244)     // MIPS
     24 #pragma warning(disable : 4136)     // X86
     25 #pragma warning(disable : 4051)     // ALPHA
     26 #endif
     27 
     28 #ifdef _WIN32
     29 #  include <windows.h>
     30 #endif
     31 
     32 #include <stdio.h>
     33 
     34 #include <GL/gl.h>
     35 #include <GL/glu.h>
     36 #include <math.h>
     37 
     38 #ifndef GL_COLOR_INDEX8_EXT
     39 #define GL_COLOR_INDEX8_EXT GL_COLOR_INDEX
     40 #endif
     41 
     42 #include "../client/ref.h"
     43 
     44 #include "qgl.h"
     45 
     46 #define	REF_VERSION	"GL 0.01"
     47 
     48 // up / down
     49 #define	PITCH	0
     50 
     51 // left / right
     52 #define	YAW		1
     53 
     54 // fall over
     55 #define	ROLL	2
     56 
     57 
     58 typedef struct
     59 {
     60 	unsigned		width, height;			// coordinates from main game
     61 } viddef_t;
     62 
     63 extern	viddef_t	vid;
     64 
     65 
     66 /*
     67 
     68   skins will be outline flood filled and mip mapped
     69   pics and sprites with alpha will be outline flood filled
     70   pic won't be mip mapped
     71 
     72   model skin
     73   sprite frame
     74   wall texture
     75   pic
     76 
     77 */
     78 
     79 typedef enum 
     80 {
     81 	it_skin,
     82 	it_sprite,
     83 	it_wall,
     84 	it_pic,
     85 	it_sky
     86 } imagetype_t;
     87 
     88 typedef struct image_s
     89 {
     90 	char	name[MAX_QPATH];			// game path, including extension
     91 	imagetype_t	type;
     92 	int		width, height;				// source image
     93 	int		upload_width, upload_height;	// after power of two and picmip
     94 	int		registration_sequence;		// 0 = free
     95 	struct msurface_s	*texturechain;	// for sort-by-texture world drawing
     96 	int		texnum;						// gl texture binding
     97 	float	sl, tl, sh, th;				// 0,0 - 1,1 unless part of the scrap
     98 	qboolean	scrap;
     99 	qboolean	has_alpha;
    100 
    101 	qboolean paletted;
    102 } image_t;
    103 
    104 #define	TEXNUM_LIGHTMAPS	1024
    105 #define	TEXNUM_SCRAPS		1152
    106 #define	TEXNUM_IMAGES		1153
    107 
    108 #define		MAX_GLTEXTURES	1024
    109 
    110 //===================================================================
    111 
    112 typedef enum
    113 {
    114 	rserr_ok,
    115 
    116 	rserr_invalid_fullscreen,
    117 	rserr_invalid_mode,
    118 
    119 	rserr_unknown
    120 } rserr_t;
    121 
    122 #include "gl_model.h"
    123 
    124 void GL_BeginRendering (int *x, int *y, int *width, int *height);
    125 void GL_EndRendering (void);
    126 
    127 void GL_SetDefaultState( void );
    128 void GL_UpdateSwapInterval( void );
    129 
    130 extern	float	gldepthmin, gldepthmax;
    131 
    132 typedef struct
    133 {
    134 	float	x, y, z;
    135 	float	s, t;
    136 	float	r, g, b;
    137 } glvert_t;
    138 
    139 
    140 #define	MAX_LBM_HEIGHT		480
    141 
    142 #define BACKFACE_EPSILON	0.01
    143 
    144 
    145 //====================================================
    146 
    147 extern	image_t		gltextures[MAX_GLTEXTURES];
    148 extern	int			numgltextures;
    149 
    150 
    151 extern	image_t		*r_notexture;
    152 extern	image_t		*r_particletexture;
    153 extern	entity_t	*currententity;
    154 extern	model_t		*currentmodel;
    155 extern	int			r_visframecount;
    156 extern	int			r_framecount;
    157 extern	cplane_t	frustum[4];
    158 extern	int			c_brush_polys, c_alias_polys;
    159 
    160 
    161 extern	int			gl_filter_min, gl_filter_max;
    162 
    163 //
    164 // view origin
    165 //
    166 extern	vec3_t	vup;
    167 extern	vec3_t	vpn;
    168 extern	vec3_t	vright;
    169 extern	vec3_t	r_origin;
    170 
    171 //
    172 // screen size info
    173 //
    174 extern	refdef_t	r_newrefdef;
    175 extern	int		r_viewcluster, r_viewcluster2, r_oldviewcluster, r_oldviewcluster2;
    176 
    177 extern	cvar_t	*r_norefresh;
    178 extern	cvar_t	*r_lefthand;
    179 extern	cvar_t	*r_drawentities;
    180 extern	cvar_t	*r_drawworld;
    181 extern	cvar_t	*r_speeds;
    182 extern	cvar_t	*r_fullbright;
    183 extern	cvar_t	*r_novis;
    184 extern	cvar_t	*r_nocull;
    185 extern	cvar_t	*r_lerpmodels;
    186 
    187 extern	cvar_t	*r_lightlevel;	// FIXME: This is a HACK to get the client's light level
    188 
    189 extern cvar_t	*gl_vertex_arrays;
    190 
    191 extern cvar_t	*gl_ext_swapinterval;
    192 extern cvar_t	*gl_ext_palettedtexture;
    193 extern cvar_t	*gl_ext_multitexture;
    194 extern cvar_t	*gl_ext_pointparameters;
    195 extern cvar_t	*gl_ext_compiled_vertex_array;
    196 
    197 extern cvar_t	*gl_particle_min_size;
    198 extern cvar_t	*gl_particle_max_size;
    199 extern cvar_t	*gl_particle_size;
    200 extern cvar_t	*gl_particle_att_a;
    201 extern cvar_t	*gl_particle_att_b;
    202 extern cvar_t	*gl_particle_att_c;
    203 
    204 extern	cvar_t	*gl_nosubimage;
    205 extern	cvar_t	*gl_bitdepth;
    206 extern	cvar_t	*gl_mode;
    207 extern	cvar_t	*gl_log;
    208 extern	cvar_t	*gl_lightmap;
    209 extern	cvar_t	*gl_shadows;
    210 extern	cvar_t	*gl_dynamic;
    211 extern  cvar_t  *gl_monolightmap;
    212 extern	cvar_t	*gl_nobind;
    213 extern	cvar_t	*gl_round_down;
    214 extern	cvar_t	*gl_picmip;
    215 extern	cvar_t	*gl_skymip;
    216 extern	cvar_t	*gl_showtris;
    217 extern	cvar_t	*gl_finish;
    218 extern	cvar_t	*gl_ztrick;
    219 extern	cvar_t	*gl_clear;
    220 extern	cvar_t	*gl_cull;
    221 extern	cvar_t	*gl_poly;
    222 extern	cvar_t	*gl_texsort;
    223 extern	cvar_t	*gl_polyblend;
    224 extern	cvar_t	*gl_flashblend;
    225 extern	cvar_t	*gl_lightmaptype;
    226 extern	cvar_t	*gl_modulate;
    227 extern	cvar_t	*gl_playermip;
    228 extern	cvar_t	*gl_drawbuffer;
    229 extern	cvar_t	*gl_3dlabs_broken;
    230 extern  cvar_t  *gl_driver;
    231 extern	cvar_t	*gl_swapinterval;
    232 extern	cvar_t	*gl_texturemode;
    233 extern	cvar_t	*gl_texturealphamode;
    234 extern	cvar_t	*gl_texturesolidmode;
    235 extern  cvar_t  *gl_saturatelighting;
    236 extern  cvar_t  *gl_lockpvs;
    237 
    238 extern	cvar_t	*vid_fullscreen;
    239 extern	cvar_t	*vid_gamma;
    240 
    241 extern	cvar_t		*intensity;
    242 
    243 extern	int		gl_lightmap_format;
    244 extern	int		gl_solid_format;
    245 extern	int		gl_alpha_format;
    246 extern	int		gl_tex_solid_format;
    247 extern	int		gl_tex_alpha_format;
    248 
    249 extern	int		c_visible_lightmaps;
    250 extern	int		c_visible_textures;
    251 
    252 extern	float	r_world_matrix[16];
    253 
    254 void R_TranslatePlayerSkin (int playernum);
    255 void GL_Bind (int texnum);
    256 void GL_MBind( GLenum target, int texnum );
    257 void GL_TexEnv( GLenum value );
    258 void GL_EnableMultitexture( qboolean enable );
    259 void GL_SelectTexture( GLenum );
    260 
    261 void R_LightPoint (vec3_t p, vec3_t color);
    262 void R_PushDlights (void);
    263 
    264 //====================================================================
    265 
    266 extern	model_t	*r_worldmodel;
    267 
    268 extern	unsigned	d_8to24table[256];
    269 
    270 extern	int		registration_sequence;
    271 
    272 
    273 void V_AddBlend (float r, float g, float b, float a, float *v_blend);
    274 
    275 int 	R_Init( void *hinstance, void *hWnd );
    276 void	R_Shutdown( void );
    277 
    278 void R_RenderView (refdef_t *fd);
    279 void GL_ScreenShot_f (void);
    280 void R_DrawAliasModel (entity_t *e);
    281 void R_DrawBrushModel (entity_t *e);
    282 void R_DrawSpriteModel (entity_t *e);
    283 void R_DrawBeam( entity_t *e );
    284 void R_DrawWorld (void);
    285 void R_RenderDlights (void);
    286 void R_DrawAlphaSurfaces (void);
    287 void R_RenderBrushPoly (msurface_t *fa);
    288 void R_InitParticleTexture (void);
    289 void Draw_InitLocal (void);
    290 void GL_SubdivideSurface (msurface_t *fa);
    291 qboolean R_CullBox (vec3_t mins, vec3_t maxs);
    292 void R_RotateForEntity (entity_t *e);
    293 void R_MarkLeaves (void);
    294 
    295 glpoly_t *WaterWarpPolyVerts (glpoly_t *p);
    296 void EmitWaterPolys (msurface_t *fa);
    297 void R_AddSkySurface (msurface_t *fa);
    298 void R_ClearSkyBox (void);
    299 void R_DrawSkyBox (void);
    300 void R_MarkLights (dlight_t *light, int bit, mnode_t *node);
    301 
    302 #if 0
    303 short LittleShort (short l);
    304 short BigShort (short l);
    305 int	LittleLong (int l);
    306 float LittleFloat (float f);
    307 
    308 char	*va(char *format, ...);
    309 // does a varargs printf into a temp buffer
    310 #endif
    311 
    312 void COM_StripExtension (char *in, char *out);
    313 
    314 void	Draw_GetPicSize (int *w, int *h, char *name);
    315 void	Draw_Pic (int x, int y, char *name);
    316 void	Draw_StretchPic (int x, int y, int w, int h, char *name);
    317 void	Draw_Char (int x, int y, int c);
    318 void	Draw_TileClear (int x, int y, int w, int h, char *name);
    319 void	Draw_Fill (int x, int y, int w, int h, int c);
    320 void	Draw_FadeScreen (void);
    321 void	Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *data);
    322 
    323 void	R_BeginFrame( float camera_separation );
    324 void	R_SwapBuffers( int );
    325 void	R_SetPalette ( const unsigned char *palette);
    326 
    327 int		Draw_GetPalette (void);
    328 
    329 void GL_ResampleTexture (unsigned *in, int inwidth, int inheight, unsigned *out,  int outwidth, int outheight);
    330 
    331 struct image_s *R_RegisterSkin (char *name);
    332 
    333 void LoadPCX (char *filename, byte **pic, byte **palette, int *width, int *height);
    334 image_t *GL_LoadPic (char *name, byte *pic, int width, int height, imagetype_t type, int bits);
    335 image_t	*GL_FindImage (char *name, imagetype_t type);
    336 void	GL_TextureMode( char *string );
    337 void	GL_ImageList_f (void);
    338 
    339 void	GL_SetTexturePalette( unsigned palette[256] );
    340 
    341 void	GL_InitImages (void);
    342 void	GL_ShutdownImages (void);
    343 
    344 void	GL_FreeUnusedImages (void);
    345 
    346 void GL_TextureAlphaMode( char *string );
    347 void GL_TextureSolidMode( char *string );
    348 
    349 /*
    350 ** GL extension emulation functions
    351 */
    352 void GL_DrawParticles( int n, const particle_t particles[], const unsigned colortable[768] );
    353 
    354 /*
    355 ** GL config stuff
    356 */
    357 #define GL_RENDERER_VOODOO		0x00000001
    358 #define GL_RENDERER_VOODOO2   	0x00000002
    359 #define GL_RENDERER_VOODOO_RUSH	0x00000004
    360 #define GL_RENDERER_BANSHEE		0x00000008
    361 #define		GL_RENDERER_3DFX		0x0000000F
    362 
    363 #define GL_RENDERER_PCX1		0x00000010
    364 #define GL_RENDERER_PCX2		0x00000020
    365 #define GL_RENDERER_PMX			0x00000040
    366 #define		GL_RENDERER_POWERVR		0x00000070
    367 
    368 #define GL_RENDERER_PERMEDIA2	0x00000100
    369 #define GL_RENDERER_GLINT_MX	0x00000200
    370 #define GL_RENDERER_GLINT_TX	0x00000400
    371 #define GL_RENDERER_3DLABS_MISC	0x00000800
    372 #define		GL_RENDERER_3DLABS	0x00000F00
    373 
    374 #define GL_RENDERER_REALIZM		0x00001000
    375 #define GL_RENDERER_REALIZM2	0x00002000
    376 #define		GL_RENDERER_INTERGRAPH	0x00003000
    377 
    378 #define GL_RENDERER_3DPRO		0x00004000
    379 #define GL_RENDERER_REAL3D		0x00008000
    380 #define GL_RENDERER_RIVA128		0x00010000
    381 #define GL_RENDERER_DYPIC		0x00020000
    382 
    383 #define GL_RENDERER_V1000		0x00040000
    384 #define GL_RENDERER_V2100		0x00080000
    385 #define GL_RENDERER_V2200		0x00100000
    386 #define		GL_RENDERER_RENDITION	0x001C0000
    387 
    388 #define GL_RENDERER_O2          0x00100000
    389 #define GL_RENDERER_IMPACT      0x00200000
    390 #define GL_RENDERER_RE			0x00400000
    391 #define GL_RENDERER_IR			0x00800000
    392 #define		GL_RENDERER_SGI			0x00F00000
    393 
    394 #define GL_RENDERER_MCD			0x01000000
    395 #define GL_RENDERER_OTHER		0x80000000
    396 
    397 typedef struct
    398 {
    399 	int         renderer;
    400 	const char *renderer_string;
    401 	const char *vendor_string;
    402 	const char *version_string;
    403 	const char *extensions_string;
    404 
    405 	qboolean	allow_cds;
    406 } glconfig_t;
    407 
    408 typedef struct
    409 {
    410 	float inverse_intensity;
    411 	qboolean fullscreen;
    412 
    413 	int     prev_mode;
    414 
    415 	unsigned char *d_16to8table;
    416 
    417 	int lightmap_textures;
    418 
    419 	int	currenttextures[2];
    420 	int currenttmu;
    421 
    422 	float camera_separation;
    423 	qboolean stereo_enabled;
    424 
    425 	unsigned char originalRedGammaTable[256];
    426 	unsigned char originalGreenGammaTable[256];
    427 	unsigned char originalBlueGammaTable[256];
    428 } glstate_t;
    429 
    430 extern glconfig_t  gl_config;
    431 extern glstate_t   gl_state;
    432 
    433 /*
    434 ====================================================================
    435 
    436 IMPORTED FUNCTIONS
    437 
    438 ====================================================================
    439 */
    440 
    441 extern	refimport_t	ri;
    442 
    443 
    444 /*
    445 ====================================================================
    446 
    447 IMPLEMENTATION SPECIFIC FUNCTIONS
    448 
    449 ====================================================================
    450 */
    451 
    452 void		GLimp_BeginFrame( float camera_separation );
    453 void		GLimp_EndFrame( void );
    454 int 		GLimp_Init( void *hinstance, void *hWnd );
    455 void		GLimp_Shutdown( void );
    456 int     	GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen );
    457 void		GLimp_AppActivate( qboolean active );
    458 void		GLimp_EnableLogging( qboolean enable );
    459 void		GLimp_LogNewFrame( void );
    460