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/common/render_api.h

245 lines
11 KiB
C

/*
render_api.h - Xash3D extension for client interface
Copyright (C) 2011 Uncle Mike
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 3 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.
*/
#ifndef RENDER_API_H
#define RENDER_API_H
#include "lightstyle.h"
#include "dlight.h"
// changes for version 28
// replace decal_t from software declaration to hardware (matched to normal HL)
// mextrasurf_t->increased limit of reserved fields (up from 7 to 32)
// replace R_StoreEfrags with him extended version
// formed group for BSP decal manipulating
// move misc functions at end of the interface
// added new export for clearing studio decals
#define CL_RENDER_INTERFACE_VERSION 30
#define MAX_STUDIO_DECALS 4096 // + unused space of BSP decals
#define SURF_INFO( surf, mod ) ((mextrasurf_t *)mod->cache.data + (surf - mod->surfaces))
#define INFO_SURF( surf, mod ) (mod->surfaces + (surf - (mextrasurf_t *)mod->cache.data))
// render info parms
#define PARM_TEX_WIDTH 1 // all parms with prefix 'TEX_' receive arg as texnum
#define PARM_TEX_HEIGHT 2 // otherwise it's not used
#define PARM_TEX_SRC_WIDTH 3
#define PARM_TEX_SRC_HEIGHT 4
#define PARM_TEX_SKYBOX 5 // second arg as skybox ordering num
#define PARM_TEX_SKYTEXNUM 6 // skytexturenum for quake sky
#define PARM_TEX_LIGHTMAP 7 // second arg as number 0 - 128
#define PARM_SKY_SPHERE 8 // sky is quake sphere ?
#define PARM_WORLD_VERSION 9 // return the version of bsp
#define PARM_WORLD_LOADING 10 // usefully in callback GL_LoadTexture to determine world or external bmodel
#define PARM_WIDESCREEN 11
#define PARM_FULLSCREEN 12
#define PARM_SCREEN_WIDTH 13
#define PARM_SCREEN_HEIGHT 14
#define PARM_MAP_HAS_MIRRORS 15 // current map has mirorrs
#define PARM_CLIENT_INGAME 16
#define PARM_MAX_ENTITIES 17
#define PARM_TEX_TARGET 18
#define PARM_TEX_TEXNUM 19
#define PARM_TEX_FLAGS 20
#define PARM_FEATURES 21 // same as movevars->features
#define PARM_ACTIVE_TMU 22 // for debug
enum
{
// skybox ordering
SKYBOX_RIGHT = 0,
SKYBOX_BACK,
SKYBOX_LEFT,
SKYBOX_FORWARD,
SKYBOX_UP,
SKYBOX_DOWN,
};
typedef enum
{
TEX_INVALID = 0, // free slot
TEX_SYSTEM, // generated by engine
TEX_NOMIP, // hud pics, menu etc
TEX_BRUSH, // a map texture
TEX_SPRITE, // sprite frames
TEX_STUDIO, // studio skins
TEX_LIGHTMAP, // lightmap textures
TEX_DECAL, // decals
TEX_VGUI, // vgui fonts or images
TEX_CUBEMAP, // cubemap textures (sky)
TEX_DETAIL, // detail textures
TEX_REMAP, // local copy of remap texture
TEX_SCREENCOPY, // keep screen copy e.g. for mirror
TEX_CUSTOM, // user created texture
TEX_DEPTHMAP // shadowmap texture
} texType_t;
typedef enum
{
TF_NEAREST = (1<<0), // disable texfilter
TF_KEEP_RGBDATA = (1<<1), // some images keep source
TF_NOFLIP_TGA = (1<<2), // Steam background completely ignore tga attribute 0x20
TF_KEEP_8BIT = (1<<3), // keep original 8-bit image (if present)
TF_NOPICMIP = (1<<4), // ignore r_picmip resample rules
TF_UNCOMPRESSED = (1<<5), // don't compress texture in video memory
TF_CUBEMAP = (1<<6), // it's cubemap texture
TF_DEPTHMAP = (1<<7), // custom texture filter used
TF_INTENSITY = (1<<8),
TF_LUMINANCE = (1<<9), // force image to grayscale
TF_SKYSIDE = (1<<10),
TF_CLAMP = (1<<11),
TF_NOMIPMAP = (1<<12),
TF_HAS_LUMA = (1<<13), // sets by GL_UploadTexture
TF_MAKELUMA = (1<<14), // create luma from quake texture
TF_NORMALMAP = (1<<15), // is a normalmap
TF_HAS_ALPHA = (1<<16), // image has alpha (used only for GL_CreateTexture)
TF_FORCE_COLOR = (1<<17), // force upload monochrome textures as RGB (detail textures)
TF_TEXTURE_1D = (1<<18), // this is GL_TEXTURE_1D
TF_BORDER = (1<<19),
TF_TEXTURE_3D = (1<<20), // this is GL_TEXTURE_3D
TF_FLOAT = (1<<21), // use GL_FLOAT instead of GL_UNSIGNED_BYTE
TF_TEXTURE_RECTANGLE= (1<<22), // this is GL_TEXTURE_RECTANGLE
} texFlags_t;
typedef struct beam_s BEAM;
typedef struct particle_s particle_t;
typedef struct wadlist_s
{
char wadnames[256][32];
int count;
} wadlist_t;
// 12 bytes here
typedef struct modelstate_s
{
short sequence;
short frame; // 10 bits multiple by 4, should be enough
byte blending[2];
byte controller[4];
byte body;
byte skin;
} modelstate_t;
typedef struct decallist_s
{
vec3_t position;
char name[64];
short entityIndex;
byte depth;
byte flags;
float scale;
// this is the surface plane that we hit so that
// we can move certain decals across
// transitions if they hit similar geometry
vec3_t impactPlaneNormal;
modelstate_t studio_state; // studio decals only
} decallist_t;
typedef struct render_api_s
{
// Get renderer info (doesn't changes engine state at all)
int (*RenderGetParm)( int parm, int arg ); // generic
void (*GetDetailScaleForTexture)( int texture, float *xScale, float *yScale );
void (*GetExtraParmsForTexture)( int texture, byte *red, byte *green, byte *blue, byte *alpha );
lightstyle_t* (*GetLightStyle)( int number );
dlight_t* (*GetDynamicLight)( int number );
dlight_t* (*GetEntityLight)( int number );
byte (*TextureToTexGamma)( byte color ); // software gamma support
void (*GetBeamChains)( BEAM ***active_beams, BEAM ***free_beams, particle_t ***free_trails );
// Set renderer info (tell engine about changes)
void (*R_SetCurrentEntity)( struct cl_entity_s *ent ); // tell engine about both currententity and currentmodel
void (*R_SetCurrentModel)( struct model_s *mod ); // change currentmodel but leave currententity unchanged
void (*GL_SetWorldviewProjectionMatrix)( const float *glmatrix ); // update viewprojection matrix (tracers uses it)
void (*R_StoreEfrags)( struct efrag_s **ppefrag, int framecount );// store efrags for static entities
// Texture tools
int (*GL_FindTexture)( const char *name );
const char* (*GL_TextureName)( unsigned int texnum );
int (*GL_LoadTexture)( const char *name, const byte *buf, size_t size, int flags, void *filter );
int (*GL_CreateTexture)( const char *name, int width, int height, const void *buffer, int flags );
void (*GL_SetTextureType)( unsigned int texnum, unsigned int type );
void (*GL_FreeTexture)( unsigned int texnum );
// Decals manipulating (draw & remove)
void (*DrawSingleDecal)( struct decal_s *pDecal, struct msurface_s *fa );
float *(*R_DecalSetupVerts)( struct decal_s *pDecal, struct msurface_s *surf, int texture, int *outCount );
void (*R_EntityRemoveDecals)( struct model_s *mod ); // remove all the decals from specified entity (BSP only)
// AVIkit support
void *(*AVI_LoadVideo)( const char *filename, int load_audio, int ignore_hwgamma );
int (*AVI_GetVideoInfo)( void *Avi, long *xres, long *yres, float *duration );
int (*AVI_GetAudioInfo)( void *Avi, void *snd_info );
long (*AVI_GetAudioChunk)( void *Avi, char *audiodata, long offset, long length );
long (*AVI_GetVideoFrameNumber)( void *Avi, float time );
byte *(*AVI_GetVideoFrame)( void *Avi, long frame );
void (*AVI_UploadRawFrame)( int texture, int cols, int rows, int width, int height, const byte *data );
void (*AVI_FreeVideo)( void *Avi );
int (*AVI_IsActive)( void *Avi );
// glState related calls (must use this instead of normal gl-calls to prevent de-synchornize local states between engine and the client)
void (*GL_Bind)( unsigned int tmu, unsigned int texnum );
void (*GL_SelectTexture)( unsigned int texture );
void (*GL_LoadTextureMatrix)( const float *glmatrix );
void (*GL_TexMatrixIdentity)( void );
void (*GL_CleanUpTextureUnits)( int last ); // pass 0 for clear all the texture units
void (*GL_TexGen)( unsigned int coord, unsigned int mode );
void (*GL_TextureTarget)( unsigned int target ); // change texture unit mode without bind texture
// Misc renderer functions
void (*GL_DrawParticles)( const float *vieworg, const float *fwd, const float *rt, const float *up, unsigned int clipFlags );
void (*EnvShot)( const float *vieworg, const char *name, qboolean skyshot ); // creates a cubemap or skybox into gfx\env folder
int (*COM_CompareFileTime)( const char *filename1, const char *filename2, int *iCompare );
void (*Host_Error)( const char *error, ... ); // cause Host Error
int (*SPR_LoadExt)( const char *szPicName, unsigned int texFlags ); // extended version of SPR_Load
struct mstudiotex_s *( *StudioGetTexture )( struct cl_entity_s *e );
const struct ref_overview_s *( *GetOverviewParms )( void );
void (*R_InitQuakeSky)( struct mip_s *mt, struct texture_s *tx );
void *(*R_FindTexFilter)( const char *texname ); // only for internal use by imagelib. No acess to private fields
void (*S_FadeMusicVolume)( float fadePercent ); // fade background track (0-100 percents)
void (*SetRandomSeed)( long lSeed ); // set custom seed for RANDOM_FLOAT\RANDOM_LONG for predictable random
wadlist_t *(*COM_GetWadsList)( void ); // returns a wadlist for the given map
// ONLY ADD NEW FUNCTIONS TO THE END OF THIS STRUCT. INTERFACE VERSION IS FROZEN AT 30
} render_api_t;
// render callbacks
typedef struct render_interface_s
{
int version;
// passed through R_RenderFrame (0 - use engine renderer, 1 - use custom client renderer)
int (*GL_RenderFrame)( const struct ref_params_s *pparams, qboolean drawWorld );
// build all the lightmaps on new level or when gamma is changed
void (*GL_BuildLightmaps)( void );
// setup map bounds for ortho-projection when we in dev_overview mode
void (*GL_OrthoBounds)( const float *mins, const float *maxs );
// handle decals which hit mod_studio or mod_sprite
void (*R_StudioDecalShoot)( int decalTexture, struct cl_entity_s *ent, const float *start, const float *pos, int flags, modelstate_t *state );
// prepare studio decals for save
int (*R_CreateStudioDecalList)( decallist_t *pList, int count, qboolean changelevel );
// clear decals by engine request (e.g. for demo recording or vid_restart)
void (*R_ClearStudioDecals)( void );
// grab r_speeds message
qboolean (*R_SpeedsMessage)( char *out, size_t size );
// replace with built-in R_DrawCubemapView for make skyshots or envshots
qboolean (*R_DrawCubemapView)( const float *origin, const float *angles, int size );
// custom texture loader for worldmodel and bsp-models (as a part of implementation Quake3 shader system)
qboolean (*GL_LoadTextures)( const void *in, model_t *out, int *sky1, int *sky2 );
} render_interface_t;
#endif//RENDER_API_H