This repository has been archived on 2022-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Xash3DArchive/render/gl_local.h

539 lines
14 KiB
C
Raw Normal View History

2007-06-21 22:00:00 +02:00
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
2007-10-29 22:00:00 +01:00
#include <windows.h>
2007-06-21 22:00:00 +02:00
#include <stdio.h>
#include "basetypes.h"
2007-11-27 22:00:00 +01:00
#include "mathlib.h"
2007-06-21 22:00:00 +02:00
2007-06-22 22:00:00 +02:00
#define RENDERPASS_SOLID 1
#define RENDERPASS_ALPHA 2
2007-06-21 22:00:00 +02:00
#define Q_ftol( f ) ( long ) (f)
#define SOLID_FORMAT 3
#define ALPHA_FORMAT 4
#define WINDOW_STYLE (WS_OVERLAPPED|WS_BORDER|WS_CAPTION|WS_VISIBLE)
#include "r_opengl.h"
/*
===========================================
memory manager
===========================================
*/
//z_malloc-free
2007-07-28 22:00:00 +02:00
#define Z_Malloc(size) Mem_Alloc(r_temppool, size)
#define Z_Free(data) Mem_Free(data)
2007-06-21 22:00:00 +02:00
extern byte *r_temppool;
2007-11-30 22:00:00 +01:00
extern stdlib_api_t com;
2007-06-21 22:00:00 +02:00
2007-11-11 22:00:00 +01:00
// r_utils.c
2007-06-21 22:00:00 +02:00
void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees );
void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal );
void PerpendicularVector( vec3_t dst, const vec3_t src );
void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3]);
void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4]);
2007-11-30 22:00:00 +01:00
#define Sys_Error com.error
2007-06-21 22:00:00 +02:00
2007-11-04 22:00:00 +01:00
#define MAX_RADAR_ENTS 1024
typedef struct radar_ent_s
{
vec4_t color;
vec3_t org;
vec3_t ang;
} radar_ent_t;
int numRadarEnts;
extern radar_ent_t RadarEnts[MAX_RADAR_ENTS];
2007-06-21 22:00:00 +02:00
typedef struct rect_s
{
int left;
int right;
int top;
int bottom;
}wrect_t;
/*
skins will be outline flood filled and mip mapped
pics and sprites with alpha will be outline flood filled
pic won't be mip mapped
model skin
sprite frame
wall texture
pic
*/
typedef enum
{
it_skin,
it_sprite,
it_wall,
it_pic,
2007-07-12 22:00:00 +02:00
it_sky,
it_cubemap,
2007-06-21 22:00:00 +02:00
} imagetype_t;
2007-08-23 22:00:00 +02:00
// texnum cubemap order
// 0 = ft or normal image
2007-07-12 22:00:00 +02:00
// 1 = bk
2007-08-23 22:00:00 +02:00
// 2 = rt
// 3 = lf
2007-07-12 22:00:00 +02:00
// 4 = up
// 5 = dn
2007-06-21 22:00:00 +02:00
typedef struct image_s
{
char name[MAX_QPATH]; // game path, including extension
imagetype_t type; // image type
int width, height; // source image
int registration_sequence; // 0 = free
struct msurface_s *texturechain; // for sort-by-texture world drawing
2007-07-12 22:00:00 +02:00
int texnum[6]; // gl texture binding
2007-06-21 22:00:00 +02:00
bool paletted;
2007-09-21 22:00:00 +02:00
int texorder[6]; // drawing order pattern
2007-08-19 22:00:00 +02:00
};
2007-06-21 22:00:00 +02:00
#define TEXNUM_LIGHTMAPS 1024
2007-07-12 22:00:00 +02:00
#define TEXNUM_IMAGES 1152
#define MAX_GLTEXTURES 1024
2007-06-21 22:00:00 +02:00
//===================================================================
typedef enum
{
rserr_ok,
rserr_invalid_fullscreen,
rserr_invalid_mode,
rserr_unknown
} rserr_t;
#include "gl_model.h"
void GL_BeginRendering (int *x, int *y, int *width, int *height);
void GL_EndRendering (void);
void GL_SetDefaultState( void );
void GL_UpdateSwapInterval( void );
extern float gldepthmin, gldepthmax;
typedef struct
{
float x, y, z;
float s, t;
float r, g, b;
} glvert_t;
#define MAX_LBM_HEIGHT 480
#define BACKFACE_EPSILON 0.01
//====================================================
extern image_t gltextures[MAX_GLTEXTURES];
2007-11-04 22:00:00 +01:00
extern int numgltextures;
2007-11-06 22:00:00 +01:00
extern byte *r_framebuffer;
2007-06-21 22:00:00 +02:00
2007-11-04 22:00:00 +01:00
extern image_t *r_notexture;
extern image_t *r_particletexture;
extern image_t *r_radarmap;
extern image_t *r_around;
2007-06-21 22:00:00 +02:00
extern entity_t *currententity;
extern model_t *currentmodel;
extern int r_visframecount;
extern int r_framecount;
extern cplane_t frustum[4];
2007-09-14 22:00:00 +02:00
extern int c_brush_polys;
2007-06-21 22:00:00 +02:00
extern int gl_filter_min, gl_filter_max;
//
// view origin
//
extern vec3_t vup;
extern vec3_t vright;
extern vec3_t vforward;
extern vec3_t r_origin;
//
// screen size info
//
extern refdef_t r_newrefdef;
2007-11-18 22:00:00 +01:00
extern int r_viewcluster, r_viewcluster2, r_oldviewcluster, r_oldviewcluster2;
2007-06-21 22:00:00 +02:00
extern cvar_t *r_norefresh;
extern cvar_t *r_lefthand;
extern cvar_t *r_drawentities;
extern cvar_t *r_drawworld;
extern cvar_t *r_speeds;
extern cvar_t *r_fullbright;
extern cvar_t *r_novis;
extern cvar_t *r_nocull;
extern cvar_t *r_lerpmodels;
2007-11-08 22:00:00 +01:00
extern cvar_t *r_loading;
2007-10-14 22:00:00 +02:00
extern cvar_t *r_pause;
2007-11-18 22:00:00 +01:00
extern cvar_t *r_width;
extern cvar_t *r_height;
extern cvar_t *r_mode;
2007-06-21 22:00:00 +02:00
extern cvar_t *r_lightlevel; // FIXME: This is a HACK to get the client's light level
extern cvar_t *gl_vertex_arrays;
extern cvar_t *gl_ext_swapinterval;
extern cvar_t *gl_ext_multitexture;
extern cvar_t *gl_ext_pointparameters;
extern cvar_t *gl_ext_compiled_vertex_array;
extern cvar_t *gl_particle_min_size;
extern cvar_t *gl_particle_max_size;
extern cvar_t *gl_particle_size;
extern cvar_t *gl_particle_att_a;
extern cvar_t *gl_particle_att_b;
extern cvar_t *gl_particle_att_c;
2007-11-04 22:00:00 +01:00
extern cvar_t *r_minimap;
extern cvar_t *r_minimap_size;
extern cvar_t *r_minimap_zoom;
extern cvar_t *r_minimap_style;
2007-06-21 22:00:00 +02:00
extern cvar_t *r_bloom;
extern cvar_t *r_bloom_alpha;
extern cvar_t *r_bloom_diamond_size;
extern cvar_t *r_bloom_intensity;
extern cvar_t *r_bloom_darken;
extern cvar_t *r_bloom_sample_size;
extern cvar_t *r_bloom_fast_sample;
2007-07-12 22:00:00 +02:00
extern cvar_t *r_emboss_bump;
2007-06-21 22:00:00 +02:00
extern cvar_t *r_motionblur_intens;
extern cvar_t *r_motionblur;
extern cvar_t *gl_nosubimage;
extern cvar_t *gl_bitdepth;
extern cvar_t *gl_log;
extern cvar_t *gl_lightmap;
extern cvar_t *gl_shadows;
extern cvar_t *gl_dynamic;
extern cvar_t *gl_nobind;
extern cvar_t *gl_round_down;
extern cvar_t *gl_skymip;
extern cvar_t *gl_showtris;
extern cvar_t *gl_finish;
extern cvar_t *gl_ztrick;
extern cvar_t *gl_clear;
extern cvar_t *gl_cull;
extern cvar_t *gl_poly;
extern cvar_t *gl_texsort;
extern cvar_t *gl_polyblend;
extern cvar_t *gl_flashblend;
extern cvar_t *gl_lightmaptype;
extern cvar_t *gl_modulate;
extern cvar_t *gl_playermip;
extern cvar_t *gl_drawbuffer;
extern cvar_t *gl_3dlabs_broken;
extern cvar_t *gl_swapinterval;
extern cvar_t *gl_texturemode;
extern cvar_t *gl_texturealphamode;
extern cvar_t *gl_texturesolidmode;
extern cvar_t *gl_saturatelighting;
extern cvar_t *gl_lockpvs;
2007-11-17 22:00:00 +01:00
extern cvar_t *r_fullscreen;
2007-06-21 22:00:00 +02:00
extern cvar_t *vid_gamma;
extern cvar_t *intensity;
extern int gl_lightmap_format;
extern int gl_tex_solid_format;
extern int gl_tex_alpha_format;
extern int c_visible_lightmaps;
extern int c_visible_textures;
extern float r_world_matrix[16];
void R_TranslatePlayerSkin (int playernum);
void GL_Bind (int texnum);
void GL_MBind( GLenum target, int texnum );
void GL_TexEnv( GLenum value );
void GL_EnableMultitexture( bool enable );
void GL_SelectTexture( GLenum );
2007-07-07 22:00:00 +02:00
void GL_TexFilter( GLboolean mipmap );
2007-11-04 22:00:00 +01:00
void GL_SetColor( const void *data );
void R_SetGL2D ( void );
2007-06-21 22:00:00 +02:00
void R_LightPoint (vec3_t p, vec3_t color);
void R_PushDlights (void);
2007-11-06 22:00:00 +01:00
bool VID_ScreenShot( const char *filename, bool force_gamma );
void VID_BuildGammaTable( void );
void VID_ImageLightScale (uint *in, int inwidth, int inheight );
void VID_ImageBaseScale (uint *in, int inwidth, int inheight );
2007-06-21 22:00:00 +02:00
//====================================================================
extern model_t *r_worldmodel;
extern unsigned d_8to24table[256];
extern int registration_sequence;
void V_AddBlend (float r, float g, float b, float a, float *v_blend);
int R_Init( void *hinstance, void *hWnd );
void R_Shutdown( void );
void R_RenderView (refdef_t *fd);
2007-06-22 22:00:00 +02:00
void R_DrawStudioModel( int passnum );
void R_DrawBrushModel( int passnum );
2007-08-11 22:00:00 +02:00
void R_DrawSpriteModel( int passnum );
2007-06-21 22:00:00 +02:00
void R_StudioLoadModel (model_t *mod, void *buffer );
void R_SpriteLoadModel( model_t *mod, void *buffer );
2007-10-14 22:00:00 +02:00
void R_DrawPauseScreen( void );
2007-06-21 22:00:00 +02:00
char *R_ExtName( model_t *mod );
void R_DrawBeam( entity_t *e );
void R_DrawWorld (void);
void R_RenderDlights (void);
void R_DrawAlphaSurfaces (void);
void R_RenderBrushPoly (msurface_t *fa);
void R_InitParticleTexture (void);
void Draw_InitLocal (void);
void GL_SubdivideSurface (msurface_t *fa);
bool R_CullBox (vec3_t mins, vec3_t maxs);
void R_RotateForEntity (entity_t *e);
void R_MarkLeaves (void);
2007-11-04 22:00:00 +01:00
void GL_DrawRadar( void );
2007-06-21 22:00:00 +02:00
void R_BloomBlend ( refdef_t *fd );
void R_Bloom_InitTextures( void );
glpoly_t *WaterWarpPolyVerts (glpoly_t *p);
void EmitWaterPolys (msurface_t *fa);
void R_AddSkySurface (msurface_t *fa);
void R_ClearSkyBox (void);
void R_DrawSkyBox (void);
void R_MarkLights (dlight_t *light, int bit, mnode_t *node);
2007-11-18 22:00:00 +01:00
void R_RoundImageDimensions(int *scaled_width, int *scaled_height);
2007-06-21 22:00:00 +02:00
#if 0
short LittleShort (short l);
short BigShort (short l);
int LittleLong (int l);
float LittleFloat (float f);
char *va(char *format, ...);
// does a varargs printf into a temp buffer
#endif
void COM_StripExtension (char *in, char *out);
void COM_FileBase (char *in, char *out);
void Draw_GetPicSize (int *w, int *h, char *name);
void Draw_Pic (int x, int y, char *name);
2007-11-04 22:00:00 +01:00
void Draw_StretchPic(float x, float y, float w, float h, float s1, float t1, float s2, float t2, char *pic);
2007-09-02 22:00:00 +02:00
void Draw_Char (float x, float y, int c);
2007-06-21 22:00:00 +02:00
void Draw_String (int x, int y, char *str);
void Draw_TileClear (int x, int y, int w, int h, char *name);
2007-11-04 22:00:00 +01:00
void Draw_Fill(float x, float y, float w, float h );
2007-06-21 22:00:00 +02:00
void Draw_FadeScreen (void);
2007-11-01 22:00:00 +01:00
void Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *data, bool dirty );
2007-06-21 22:00:00 +02:00
2007-11-05 22:00:00 +01:00
void R_BeginFrame( void );
2007-06-21 22:00:00 +02:00
void R_SwapBuffers( int );
void R_SetPalette ( const unsigned char *palette);
void R_GetPalette (void);
2007-08-19 22:00:00 +02:00
image_t *R_RegisterSkin (char *name);
2007-06-21 22:00:00 +02:00
void R_ImageList_f (void);
2007-06-29 22:00:00 +02:00
image_t *R_LoadImage(char *name, rgbdata_t *pic, imagetype_t type );
2007-06-21 22:00:00 +02:00
image_t *R_FindImage (char *name, char *buffer, int size, imagetype_t type);
void R_InitTextures( void );
void R_ShutdownTextures (void);
void R_ImageFreeUnused(void);
//backend funcs
void GL_TextureMode( char *string );
void GL_TextureAlphaMode( char *string );
void GL_TextureSolidMode( char *string );
void GL_EnableTexGen( void );
void GL_DisableTexGen( void );
void GL_EnableBlend( void );
void GL_DisableBlend( void );
void GL_EnableAlphaTest ( void );
void GL_DisableAlphaTest ( void );
2007-11-06 22:00:00 +01:00
void GL_EnableDepthTest( void );
void GL_DisableDepthTest( void );
2007-06-21 22:00:00 +02:00
/*
** GL extension emulation functions
*/
void GL_DrawParticles( int n, const particle_t particles[], const unsigned colortable[768] );
/*
** GL config stuff
*/
#define GL_RENDERER_VOODOO 0x00000001
#define GL_RENDERER_ATI 0x00000002
#define GL_RENDERER_NVIDIA 0x00000004
#define GL_RENDERER_DEFAULT 0x80000000
typedef struct
{
int renderer;
const char *renderer_string;
const char *vendor_string;
const char *version_string;
const char *extensions_string;
bool allow_cds;
2007-07-07 22:00:00 +02:00
bool arb_compressed_teximage;
2007-06-21 22:00:00 +02:00
} glconfig_t;
typedef struct
{
float inverse_intensity;
bool fullscreen;
2007-11-18 22:00:00 +01:00
int prev_mode;
byte *d_16to8table;
2007-06-21 22:00:00 +02:00
int lightmap_textures;
int currenttextures[2];
2007-11-04 22:00:00 +01:00
int currenttmu;
2007-06-21 22:00:00 +02:00
bool alpha_test;
2007-11-06 22:00:00 +01:00
bool depth_test;
2007-06-21 22:00:00 +02:00
bool blend;
bool texgen;
bool reg_combiners;
bool texshaders;
bool sgis_mipmap;
dword dst_texture;
bool gammaramp;
int tex_rectangle_type;
int stencil_warp;
int stencil_two_side;
int ati_separate_stencil;
bool nv_tex_rectangle;
bool ati_tex_rectangle;
2007-11-04 22:00:00 +01:00
vec4_t draw_color; // using with Draw_* functions
2007-06-21 22:00:00 +02:00
} glstate_t;
extern glconfig_t gl_config;
extern glstate_t gl_state;
/*
====================================================================
VERTEX ARRAYS
====================================================================
*/
2007-11-14 22:00:00 +01:00
#define MAX_ARRAY MAX_INPUTLINE // sorry ...
2007-06-21 22:00:00 +02:00
#define VA_SetElem2(v, a, b) ((v)[0]=(a),(v)[1]=(b))
#define VA_SetElem3(v, a, b, c) ((v)[0]=(a),(v)[1]=(b),(v)[2]=(c))
#define VA_SetElem4(v, a, b, c, d) ((v)[0]=(a),(v)[1]=(b),(v)[2]=(c),(v)[3]=(d))
extern float tex_array [MAX_ARRAY][2];
extern float vert_array[MAX_ARRAY][3];
extern float col_array [MAX_ARRAY][4];
void GL_LockArrays( int count );
void GL_UnlockArrays( void );
/*
====================================================================
STUDIO FUNCTIONS
====================================================================
*/
void R_StudioInit( void );
void R_StudioShutdown( void );
/*
====================================================================
IMPORTED FUNCTIONS
====================================================================
*/
2007-09-13 22:00:00 +02:00
extern render_imp_t ri;
2007-06-21 22:00:00 +02:00
/*
====================================================================
IMPLEMENTATION SPECIFIC FUNCTIONS
====================================================================
*/
2007-11-05 22:00:00 +01:00
void GLimp_BeginFrame( void );
2007-06-21 22:00:00 +02:00
void GLimp_EndFrame( void );
int GLimp_Init( void *hinstance, void *hWnd );
void GLimp_Shutdown( void );
2007-11-18 22:00:00 +01:00
int GLimp_SetMode( int vid_mode, bool fullscreen );
2007-06-21 22:00:00 +02:00
void GLimp_AppActivate( bool active );
void GLimp_EnableLogging( bool enable );
void GLimp_LogNewFrame( void );
/*
====================================================================
BUILT-IN MATHLIB FUNCTIONS
====================================================================
*/
void VectorTransform (const vec3_t in1, matrix3x4 in2, vec3_t out);
void AngleQuaternion( float *angles, vec4_t quaternion );
void QuaternionMatrix( vec4_t quaternion, float (*matrix)[4] );
void QuaternionSlerp( vec4_t p, vec4_t q, float t, vec4_t qt );
void AngleMatrix (const float *angles, float (*matrix)[4] );
2007-07-07 22:00:00 +02:00
void MatrixCopy( matrix3x4 in, matrix3x4 out );
uint ShortToFloat( word y );
void R_DXTReadColor(word data, color32* out);
void R_DXTReadColors(const byte* data, color32* out);
void R_GetBitsFromMask(uint Mask, uint *ShiftLeft, uint *ShiftRight);