gl_local.h 11 KB

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