diff options
Diffstat (limited to 'source/r_shared.h')
-rw-r--r-- | source/r_shared.h | 418 |
1 files changed, 96 insertions, 322 deletions
diff --git a/source/r_shared.h b/source/r_shared.h index 2ec2e2d..59ea32e 100644 --- a/source/r_shared.h +++ b/source/r_shared.h @@ -18,28 +18,38 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifdef SOFTWARE_RENDERER -#ifdef TRUECOLOR_RENDERER -#define VID_BPP 32 -#define VID_BYTES 4 -#define VID_SHIFT 2 -#define VID_IS32BIT 1 +/* +============================================================================= + +IMAGE MANAGER + +============================================================================= +*/ + +#if USE_BGRA +#define MakeColor( r, g, b, a ) MakeLong( b, g, r, a ) #else -#define VID_BPP 8 -#define VID_BYTES 1 -#define VID_SHIFT 0 -#define VID_IS32BIT 0 -#endif +#define MakeColor( r, g, b, a ) MakeLong( r, g, b, a ) #endif -#ifdef USE_BGRA_FORMAT -#define MakeColor( r, g, b, a ) MakeLong( b, g, r, a ) +#define R_Malloc( size ) Z_TagMalloc( size, TAG_RENDERER ) +#define R_Mallocz( size ) Z_TagMallocz( size, TAG_RENDERER ) + +#if USE_REF == REF_GL +#define IMG_AllocPixels( x ) FS_AllocTempMem( x ) +#define IMG_FreePixels( x ) FS_FreeFile( x ) #else -#define MakeColor( r, g, b, a ) MakeLong( r, g, b, a ) +#define IMG_AllocPixels( x ) R_Malloc( x ) +#define IMG_FreePixels( x ) Z_Free( x ) #endif + // absolute limit for OpenGL renderer -#define MAX_TEXTURE_SIZE 2048 +#if USE_REF == REF_GL +#define MAX_TEXTURE_SIZE 2048 +#else +#define MAX_TEXTURE_SIZE 512 +#endif /* @@ -55,336 +65,100 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ typedef enum { - if_transparent = ( 1 << 0 ), - if_paletted = ( 1 << 1 ), - if_scrap = ( 1 << 2 ), - if_replace_wal = ( 1 << 3 ), - if_replace_pcx = ( 1 << 4 ), - if_auto = ( 1 << 5 ) + if_transparent = ( 1 << 0 ), + if_paletted = ( 1 << 1 ), + if_scrap = ( 1 << 2 ), + if_replace_wal = ( 1 << 3 ), + if_replace_pcx = ( 1 << 4 ), + if_auto = ( 1 << 5 ) } imageflags_t; typedef enum { - it_skin, - it_sprite, - it_wall, - it_pic, - it_sky, - it_charset, + it_skin, + it_sprite, + it_wall, + it_pic, + it_sky, + it_charset, it_tmp } imagetype_t; -#define EXTENSION_PNG MakeLong( '.', 'p', 'n', 'g' ) -#define EXTENSION_TGA MakeLong( '.', 't', 'g', 'a' ) -#define EXTENSION_JPG MakeLong( '.', 'j', 'p', 'g' ) -#define EXTENSION_PCX MakeLong( '.', 'p', 'c', 'x' ) -#define EXTENSION_WAL MakeLong( '.', 'w', 'a', 'l' ) +#define EXTENSION_PNG MakeLong( '.', 'p', 'n', 'g' ) +#define EXTENSION_TGA MakeLong( '.', 't', 'g', 'a' ) +#define EXTENSION_JPG MakeLong( '.', 'j', 'p', 'g' ) +#define EXTENSION_PCX MakeLong( '.', 'p', 'c', 'x' ) +#define EXTENSION_WAL MakeLong( '.', 'w', 'a', 'l' ) typedef struct image_s { - list_t entry; - char name[MAX_QPATH]; // game path, without extension - int baselength; // length of the path without extension - imagetype_t type; - int width, height; // source image - int upload_width, upload_height; // after power of two and picmip - int registration_sequence; // 0 = free -#ifdef OPENGL_RENDERER - unsigned texnum; // gl texture binding - float sl, sh, tl, th; -#elif SOFTWARE_RENDERER - byte *pixels[4]; // mip levels + list_t entry; + char name[MAX_QPATH]; // game path, without extension + int baselength; // length of the path without extension + imagetype_t type; + int width, height; // source image + int upload_width, upload_height; // after power of two and picmip + int registration_sequence; // 0 = free +#if USE_REF == REF_GL + unsigned texnum; // gl texture binding + float sl, sh, tl, th; #else -#error Neither OPENGL_RENDERER nor SOFTWARE_RENDERER defined + byte *pixels[4]; // mip levels #endif - imageflags_t flags; + imageflags_t flags; } image_t; +#define MAX_RIMAGES 1024 -#define MAX_RIMAGES 1024 -#define RIMAGES_HASH 256 - -extern image_t r_images[MAX_RIMAGES]; -extern list_t r_imageHash[RIMAGES_HASH]; -extern int r_numImages; - -extern uint32_t d_8to24table[256]; - -#define R_Malloc( size ) com.TagMalloc( size, TAG_RENDERER ) - -/* these are implemented in r_images.c */ -image_t *R_FindImage( const char *name, imagetype_t type ); -image_t *R_AllocImage( const char *name ); -image_t *R_CreateImage( const char *name, byte *pic, int width, int height, - imagetype_t type, imageflags_t flags ); -void R_FreeUnusedImages( void ); -void R_FreeAllImages( void ); -void R_InitImageManager( void ); -void R_ShutdownImageManager( void ); -void R_ResampleTexture( const byte *in, int inwidth, int inheight, byte *out, - int outwidth, int outheight ); -void R_GetPalette( byte **dest ); - -void Image_LoadPCX( const char *filename, byte **pic, byte *palette, int *width, int *height ); -void Image_LoadTGA( const char *filename, byte **pic, int *width, int *height ); -qboolean Image_WriteTGA( const char *filename, const byte *rgb, int width, int height ); -#if USE_JPEG -void Image_LoadJPG( const char *filename, byte **pic, int *width, int *height ); -qboolean Image_WriteJPG( const char *filename, const byte *rgb, int width, int height, int quality ); -#endif -#if USE_PNG -void Image_LoadPNG( const char *filename, byte **pic, int *width, int *height ); -qboolean Image_WritePNG( const char *filename, const byte *rgb, int width, int height, int compression ); -#endif - -/* these should be implemented by renderer library itself */ -void R_FreeImage( image_t *image ); -void R_LoadImage( image_t *image, byte *pic, int width, int height, imagetype_t type, imageflags_t flags ); -image_t *R_LoadWal( const char *name ); +extern image_t r_images[MAX_RIMAGES]; +extern int r_numImages; extern int registration_sequence; -extern image_t *r_notexture; -// -// BSP MODELS -// - -#ifdef SOFTWARE_RENDERER - -// FIXME: differentiate from texinfo SURF_ flags -#define SURF_PLANEBACK 0x02 -#define SURF_DRAWSKY 0x04 // sky brush face -#define SURF_FLOW 0x08 //PGM -#define SURF_DRAWTURB 0x10 -#define SURF_DRAWBACKGROUND 0x40 -#define SURF_DRAWSKYBOX 0x80 // sky box - -#define EXTRA_SURFACES 6 -#define EXTRA_VERTICES 8 -#define EXTRA_EDGES 12 -#define EXTRA_SURFEDGES 24 - -#else // SOFTWARE_RENDERER - -#define EXTRA_SURFACES 0 -#define EXTRA_VERTICES 0 -#define EXTRA_EDGES 0 -#define EXTRA_SURFEDGES 0 - -#endif // !SOFTWARE_RENDERER - -typedef struct bspTexinfo_s { - char name[MAX_QPATH]; - int contents; - int flags; - vec3_t axis[2]; -#ifdef OPENGL_RENDERER -// vec3_t normalizedAxis[2]; -#endif - vec2_t offset; - int numFrames; - struct bspTexinfo_s *animNext; - image_t *image; -} bspTexinfo_t; - -#ifdef OPENGL_RENDERER -typedef enum { - DSURF_POLY, - DSURF_WARP, - DSURF_NOLM, - DSURF_SKY, +extern image_t *r_notexture; - DSURF_NUM_TYPES -} drawSurfType_t; +extern uint32_t d_8to24table[256]; + +// these are implemented in r_images.c +image_t *IMG_Alloc( const char *name ); +image_t *IMG_Find( const char *name, imagetype_t type ); +image_t *IMG_Create( const char *name, byte *pic, int width, int height, + imagetype_t type, imageflags_t flags ); +void IMG_FreeUnused( void ); +void IMG_FreeAll( void ); +void IMG_Init( void ); +void IMG_Shutdown( void ); +void IMG_GetPalette( byte **dest ); + +image_t *IMG_ForHandle( qhandle_t h ); +qhandle_t R_RegisterSkin( const char *name ); +qhandle_t R_RegisterPic( const char *name ); +qhandle_t R_RegisterFont( const char *name ); + +qboolean IMG_LoadPCX( const char *filename, byte **pic, byte *palette, + int *width, int *height ); + +#if USE_TGA +void IMG_LoadTGA( const char *filename, byte **pic, int *width, int *height ); +qboolean IMG_WriteTGA( const char *filename, const byte *rgb, + int width, int height ); #endif -typedef struct bspSurface_s { -#ifdef OPENGL_RENDERER -/* ======> */ - drawSurfType_t type; -/* <====== */ -#endif - - int index; - - vec3_t origin; - vec3_t mins; - vec3_t maxs; - - bspTexinfo_t *texinfo; - byte *lightmap; - int *firstSurfEdge; - int numSurfEdges; - - cplane_t *plane; - int side; - - int texturemins[2]; - int extents[2]; - -#ifdef OPENGL_RENDERER - int texnum[2]; - int texflags; - - int firstVert; - int numVerts; // FIXME: duplicates numSurfEdges - int numIndices; - - int drawframe; - int dlightframe; - int dlightbits; - - vec_t *vertices; // used for sky surfaces only - - struct bspSurface_s *next; +#if USE_JPG +void IMG_LoadJPG( const char *filename, byte **pic, int *width, int *height ); +qboolean IMG_WriteJPG( const char *filename, const byte *rgb, + int width, int height, int quality ); #endif -} bspSurface_t; - -typedef struct bspNode_s { -/* ======> */ - cplane_t *plane; // never NULL - int index; - - vec3_t mins; - vec3_t maxs; - - int visframe; - - struct bspNode_s *parent; -/* <====== */ - - int numFaces; - bspSurface_t *firstFace; - - struct bspNode_s *children[2]; -} bspNode_t; - -typedef struct bspLeaf_s { -/* ======> */ - cplane_t *plane; // always NULL - int index; - - vec3_t mins; - vec3_t maxs; - - int visframe; - - struct bspNode_s *parent; -/* <====== */ - - int cluster; - int area; - int contents; - - int numLeafFaces; - bspSurface_t **firstLeafFace; -} bspLeaf_t; - -typedef enum { - MODEL_NULL, - MODEL_BSP, - MODEL_ALIAS, - MODEL_SPRITE -} modelType_t; - -typedef struct bspSubmodel_s { - modelType_t type; - vec3_t mins; - vec3_t maxs; - float radius; - - vec3_t origin; - - int numFaces; - bspSurface_t *firstFace; - - bspNode_t *headnode; -} bspSubmodel_t; - -typedef struct bspModel_s { - char name[MAX_QPATH]; - mempool_t pool; - - bspSubmodel_t *submodels; - int numSubmodels; - - bspTexinfo_t *texinfos; - int numTexinfos; - - bspSurface_t *surfaces; - int numSurfaces; - - bspSurface_t **leafFaces; - int numLeafFaces; - - cplane_t *planes; - int numPlanes; - - bspLeaf_t *leafs; - int numLeafs; - - bspNode_t *nodes; - int numNodes; - - byte *vis; - int numClusters; - int rowsize; - - byte *lightmap; - unsigned lightmapSize; - -// char *entityString; - - dvertex_t *vertices; - int numVertices; - - dedge_t *edges; - int numEdges; - - int *surfEdges; - int numSurfEdges; -} bspModel_t; - - -extern bspModel_t r_world; - -void Bsp_FreeWorld( void ); -void Bsp_LoadWorld( const char *path ); -bspLeaf_t *Bsp_FindLeaf( vec3_t origin ); -byte *Bsp_ClusterPVS( int clusterNum ); - -#ifdef OPENGL_RENDERER -extern bspTexinfo_t *upload_texinfo; -void GL_BeginPostProcessing( void ); -void GL_EndPostProcessing( void ); +#if USE_PNG +void IMG_LoadPNG( const char *filename, byte **pic, int *width, int *height ); +qboolean IMG_WritePNG( const char *filename, const byte *rgb, + int width, int height, int compression ); #endif -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define LL(x) ( dst->x = src->x ) -#define LF(x) ( dst->x = src->x ) -#define LV(x) ( dst->x[0] = src->x[0], \ - dst->x[1] = src->x[1], \ - dst->x[2] = src->x[2] ) -#define LLV(x) ( dst->x[0] = src->x[0], \ - dst->x[1] = src->x[1], \ - dst->x[2] = src->x[2] ) -#define LSV(x) ( dst->x[0] = src->x[0], \ - dst->x[1] = src->x[1], \ - dst->x[2] = src->x[2] ) -#elif __BYTE_ORDER == __BIG_ENDIAN -#define LL(x) ( dst->x = LongSwap( src->x ) ) -#define LF(x) ( dst->x = FloatSwap( src->x ) ) -#define LV(x) ( dst->x[0] = FloatSwap( src->x[0] ), \ - dst->x[1] = FloatSwap( src->x[1] ), \ - dst->x[2] = FloatSwap( src->x[2] ) ) -#define LLV(x) ( dst->x[0] = LongSwap( src->x[0] ), \ - dst->x[1] = LongSwap( src->x[1] ), \ - dst->x[2] = LongSwap( src->x[2] ) ) -#define LSV(x) ( dst->x[0] = ( signed short )ShortSwap( src->x[0] ), \ - dst->x[1] = ( signed short )ShortSwap( src->x[1] ), \ - dst->x[2] = ( signed short )ShortSwap( src->x[2] ) ) -#else -#error Unknown byte order -#endif +// these are implemented in [gl,sw]_images.c +void IMG_Unload( image_t *image ); +void IMG_Load( image_t *image, byte *pic, int width, int height, + imagetype_t type, imageflags_t flags ); +image_t *IMG_LoadWAL( const char *name ); |