/* Copyright (C) 1996-1997 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. */ // refresh.h -- public interface to refresh functions // default soldier colors #define TOP_DEFAULT 1 #define BOTTOM_DEFAULT 6 #define TOP_RANGE (TOP_DEFAULT<<4) #define BOTTOM_RANGE (BOTTOM_DEFAULT<<4) extern int r_framecount; struct msurface_s; struct batch_s; struct model_s; struct texnums_s; struct texture_s; static const texid_t r_nulltex = NULL; //GLES2 requires GL_UNSIGNED_SHORT //geforce4 only does shorts. gffx can do ints, but with a performance hit (like most things on that gpu) //ati is generally more capable, but generally also has a smaller market share //desktop-gl will generally cope with ints, but expect a performance hit from that with old gpus (so we don't bother) //vulkan+dx10 can cope with ints, but might be 24bit //either way, all renderers in the same build need to use the same thing. #if (defined(GLQUAKE) && defined(HAVE_LEGACY)) || defined(MINIMAL) || defined(D3D8QUAKE) || defined(D3D9QUAKE) || defined(ANDROID) || defined(FTE_TARGET_WEB) #define sizeof_index_t 2 #endif #if sizeof_index_t == 2 #define GL_INDEX_TYPE GL_UNSIGNED_SHORT #define D3DFMT_QINDEX D3DFMT_INDEX16 #define DXGI_FORMAT_INDEX_UINT DXGI_FORMAT_R16_UINT #define VK_INDEX_TYPE VK_INDEX_TYPE_UINT16 typedef unsigned short index_t; #define MAX_INDICIES 0xffffu #else #define GL_INDEX_TYPE GL_UNSIGNED_INT #define D3DFMT_QINDEX D3DFMT_INDEX32 #define DXGI_FORMAT_INDEX_UINT DXGI_FORMAT_R32_UINT #define VK_INDEX_TYPE VK_INDEX_TYPE_UINT32 typedef unsigned int index_t; #define MAX_INDICIES 0x00ffffffu #endif //============================================================================= //the eye doesn't see different colours in the same proportion. //must add to slightly less than 1 #define NTSC_RED 0.299 #define NTSC_GREEN 0.587 #define NTSC_BLUE 0.114 #define NTSC_SUM (NTSC_RED + NTSC_GREEN + NTSC_BLUE) typedef enum { RT_MODEL, RT_POLY, RT_SPRITE, RT_BEAM, RT_RAIL_CORE, RT_RAIL_RINGS, RT_LIGHTNING, RT_PORTALSURFACE, // doesn't draw anything, just info for portals //q3 ones stop here. //fte ones start here RT_PORTALCAMERA, // an alternative to RT_PORTALSURFACE. RT_MAX_REF_ENTITY_TYPE } refEntityType_t; typedef unsigned int skinid_t; //skin 0 is 'unused' struct dlight_s; typedef struct entity_s { //FIXME: instancing somehow. separate visentity+visinstance. only viable with full glsl though. //will need to generate a vbo somehow for the instances. int keynum; // for matching entities in different frames vec3_t origin; vec3_t angles; // fixme: should be redundant. vec3_t axis[3]; vec4_t shaderRGBAf; /*colormod+alpha, available for shaders to mix*/ float shaderTime; /*timestamp, for syncing shader times to spawns*/ vec3_t glowmod; /*meant to be a multiplier for the fullbrights*/ int light_known; /*bsp lighting has been calced*/ vec3_t light_avg; /*midpoint level*/ vec3_t light_range; /*avg + this = max, avg - this = min*/ vec3_t light_dir; vec3_t oldorigin; /*for q2/q3 beams*/ struct model_s *model; // NULL = no model int skinnum; // for Alias models skinid_t customskin; // quake3 style skins int playerindex; //for qw skins int topcolour; //colourmapping int bottomcolour; //colourmapping #ifdef HEXEN2 int h2playerclass; //hexen2's quirky colourmapping #endif // struct efrag_s *efrag; // linked list of efrags (FIXME) // int visframe; // last frame this entity was // found in an active leaf // only used for static objects // int dlightframe; // dynamic lighting // dlightbitmask_t dlightbits; // FIXME: could turn these into a union // int trivial_accept; // struct mnode_s *topnode; // for bmodels, first world node // that splits bmodel, or NULL if // not split framestate_t framestate; int flags; refEntityType_t rtype; float rotation; struct shader_s *forcedshader; pvscache_t pvscache; //for culling of csqc ents. #ifdef PEXT_SCALE float scale; #endif #ifdef PEXT_FATNESS float fatness; #endif #ifdef HEXEN2 int drawflags; int abslight; #endif } entity_t; #define MAX_GEOMSETS 32 #define Q1UNSPECIFIED 0x00ffffff //0xffRRGGBB or 0x0000000V are both valid values. so this is an otherwise-illegal value to say its not been set. typedef struct { int refcount; char skinname[MAX_QPATH]; int nummappings; int maxmappings; qbyte geomset[MAX_GEOMSETS]; //allows selecting a single set of geometry from alternatives. this might be a can of worms. #ifdef QWSKINS char qwskinname[MAX_QPATH]; struct qwskin_s *qwskin; unsigned int q1upper; //Q1UNSPECIFIED unsigned int q1lower; //Q1UNSPECIFIED #endif struct { char surface[MAX_QPATH]; shader_t *shader; texnums_t texnums; int needsfree; //which textures need to be freed. } mappings[1]; } skinfile_t; // plane_t structure typedef struct mplane_s { vec3_t normal; float dist; qbyte type; // for texture axis selection and fast side tests qbyte signbits; // signx + signy<<1 + signz<<1 qbyte pad[2]; } mplane_t; #define MAXFRUSTUMPLANES 7 //4 side, 1 near, 1 far (fog), 1 water plane. typedef struct { //note: uniforms expect specific padding/ordering. be really careful with reordering this vec3_t colour; //w_fog[0].xyz float alpha; //w_fog[0].w scales clamped fog value float density; //w_fog[1].x egads, everyone has a different opinion. float depthbias; //w_fog[1].y distance until the fog actually starts float glslpad1; //w_fog[1].z float glslpad2; //w_fog[1].w // float start; // float end; // float height; // float fadedepth; float time; //timestamp for when its current. } fogstate_t; void CL_BlendFog(fogstate_t *result, fogstate_t *oldf, float time, fogstate_t *newf); void CL_ResetFog(int fogtype); typedef enum { STEREO_OFF, STEREO_QUAD, STEREO_RED_CYAN, STEREO_RED_BLUE, STEREO_RED_GREEN, STEREO_CROSSEYED, #ifdef FTE_TARGET_WEB STEREO_WEBVR, #endif //these are internal methods and do not form part of any public API STEREO_LEFTONLY, STEREO_RIGHTONLY } stereomethod_t; typedef enum { PROJ_STANDARD = 0, PROJ_STEREOGRAPHIC = 1, //aka panini PROJ_FISHEYE = 2, //standard fisheye PROJ_PANORAMA = 3, //for nice panoramas PROJ_LAEA = 4, //lambert azimuthal equal-area PROJ_EQUIRECTANGULAR = 5 //projects a sphere into 2d. used by vr screenshots. } qprojection_t; typedef struct { char texname[MAX_QPATH]; } rtname_t; #define R_MAX_RENDERTARGETS 8 #ifndef R_MAX_RECURSE #define R_MAX_RECURSE 6 #endif #define RDFD_FOV 1 typedef struct { vrect_t grect; // game rectangle. fullscreen except for csqc/splitscreen/hud. vrect_t vrect; // subwindow in grect for 3d view. equal to grect if no hud. vec3_t pvsorigin; /*render the view using this point for pvs (useful for mirror views)*/ vec3_t vieworg; /*logical view center*/ vec3_t viewangles; vec3_t viewaxis[3]; /*forward, left, up (NOT RIGHT)*/ vec3_t headaxis[3]; /*this is for head mounted displays. this is relative to the view*/ vec3_t eyeoffset; /*world space, for vr screenies*/ vec2_t projectionoffset; /*for off-centre rendering*/ float fov_x, fov_y, afov; float fovv_x, fovv_y; //viewmodel fovs float mindist, maxdist; //maxdist may be 0, for 'infinite', in which case mindist probably isn't valid either. qboolean drawsbar; qboolean drawcrosshair; int flags; //(Q2)RDF_ flags int dirty; playerview_t *playerview; // int currentplayernum; float time; // float waterheight; //updated by the renderer. stuff sitting at this height generate ripple effects float m_projection_std[16]; //projection matrix for normal stuff float m_projection_view[16]; //projection matrix for the viewmodel. because people are weird. float m_view[16]; qbyte *scenevis; /*this is the vis that's currently being draw*/ int *sceneareas; /*this is the area info for the camera (should normally be count+one area, but could be two areas near an opaque water plane)*/ mplane_t frustum[MAXFRUSTUMPLANES]; int frustum_numworldplanes; //all but far, which isn't culled because this wouldn't cover the entire screen. int frustum_numplanes; //includes far plane (which is reduced with fog). fogstate_t globalfog; float hdr_value; vec3_t skyroom_pos; /*the camera position for sky rooms*/ vec4_t skyroom_spin; /*the camera spin for sky rooms*/ qboolean skyroom_enabled; /*whether a skyroom position is defined*/ int firstvisedict; /*so we can skip visedicts in skies*/ pxrect_t pxrect; /*vrect, but in pixels rather than virtual coords*/ qboolean externalview; /*draw external models and not viewmodels*/ int recurse; /*in a mirror/portal/half way through drawing something else*/ qboolean forcevis; /*if true, vis comes from the forcedvis field instead of recalculated*/ unsigned int flipcull; /*reflected/flipped view, requires inverted culling (should be set to SHADER_CULL_FLIPPED or 0 - its implemented as a xor)*/ qboolean useperspective; /*not orthographic*/ stereomethod_t stereomethod; rtname_t rt_destcolour[R_MAX_RENDERTARGETS]; /*used for 2d. written by 3d*/ rtname_t rt_sourcecolour; /*read by 2d. not used for 3d. */ rtname_t rt_depth; /*read by 2d. used by 3d (renderbuffer used if not set)*/ rtname_t rt_ripplemap; /*read by 2d. used by 3d (internal ripplemap buffer used if not set)*/ rtname_t nearenvmap; /*provides a fallback endmap cubemap to render with*/ qbyte *forcedvis; /*set if forcevis is set*/ qboolean areabitsknown; qbyte areabits[MAX_MAP_AREA_BYTES]; vec4_t userdata[16]; /*for custom glsl*/ qboolean warndraw; /*buggy gamecode likes drawing outside of te drawing logic*/ } refdef_t; extern refdef_t r_refdef; extern vec3_t r_origin, vpn, vright, vup; extern struct texture_s *r_notexture_mip; extern entity_t r_worldentity; void BE_GenModelBatches(struct batch_s **batches, const struct dlight_s *dl, unsigned int bemode, const qbyte *worldpvs, const int *worldareas); //if dl, filters based upon the dlight. //gl_alias.c void R_GAliasFlushSkinCache(qboolean final); void R_GAlias_DrawBatch(struct batch_s *batch); void R_GAlias_GenerateBatches(entity_t *e, struct batch_s **batches); void R_LightArraysByte_BGR(const entity_t *entity, vecV_t *coords, byte_vec4_t *colours, int vertcount, vec3_t *normals, qboolean colormod); void R_LightArrays(const entity_t *entity, vecV_t *coords, avec4_t *colours, int vertcount, vec3_t *normals, float scale, qboolean colormod); qboolean R_DrawSkyChain (struct batch_s *batch); /*called from the backend, and calls back into it*/ void R_InitSky (shader_t *shader, const char *skyname, uploadfmt_t fmt, qbyte *src, unsigned int width, unsigned int height); /*generate q1 sky texnums*/ void R_Clutter_Emit(struct batch_s **batches); void R_Clutter_Purge(void); //r_surf.c void Surf_NewMap (void); void Surf_PreNewMap(void); void Surf_SetupFrame(void); //determine pvs+viewcontents void Surf_DrawWorld(void); void Surf_GenBrushBatches(struct batch_s **batches, entity_t *ent); void Surf_StainSurf(struct msurface_s *surf, float *parms); void Surf_AddStain(vec3_t org, float red, float green, float blue, float radius); void Surf_LessenStains(void); void Surf_WipeStains(void); void Surf_DeInit(void); void Surf_Clear(struct model_s *mod); void Surf_BuildLightmaps(void); //enables Surf_BuildModelLightmaps, calls it for each bsp. void Surf_ClearLightmaps(void); //stops Surf_BuildModelLightmaps from working. void Surf_BuildModelLightmaps (struct model_s *m); //rebuild lightmaps for a single bsp. beware of submodels. void Surf_RenderDynamicLightmaps (struct msurface_s *fa); void Surf_RenderAmbientLightmaps (struct msurface_s *fa, int ambient); int Surf_LightmapShift (struct model_s *model); #define LMBLOCK_SIZE_MAX 2048 //single axis typedef struct glRect_s { unsigned short l,t,r,b; } glRect_t; typedef unsigned char stmap; struct mesh_s; typedef struct { texid_t lightmap_texture; qboolean modified; //data was changed. consult rectchange to see the bounds. qboolean external; //the data was loaded from a file (q3bsp feature where we shouldn't be blending lightmaps at all) qboolean hasdeluxe; //says that the next lightmap index contains deluxemap info uploadfmt_t fmt; //texture format that we're using qbyte pixbytes; //yes, this means no compressed formats. int width; int height; glRect_t rectchange; qbyte *lightmaps; //[pixbytes*LMBLOCK_WIDTH*LMBLOCK_HEIGHT]; stmap *stainmaps; //[3*LMBLOCK_WIDTH*LMBLOCK_HEIGHT]; //rgb no a. added to lightmap for added (hopefully) speed. #ifdef GLQUAKE int pbo_handle; //when set, lightmaps is a persistently mapped write-only pbo for us to scribble data into, ready to be copied to the actual texture without waiting for glTexSubImage to complete. #endif } lightmapinfo_t; extern lightmapinfo_t **lightmap; extern int numlightmaps; void QDECL Surf_RebuildLightmap_Callback (struct cvar_s *var, char *oldvalue); void R_SkyShutdown(void); void R_SetSky(const char *skyname); texid_t R_GetDefaultEnvmap(void); #if defined(GLQUAKE) void GLR_Init (void); void GLR_InitTextures (void); void GLR_InitEfrags (void); void GLR_RenderView (void); // must set r_refdef first // called whenever r_refdef or vid change void GLR_DrawPortal(struct batch_s *batch, struct batch_s **blist, struct batch_s *depthmasklist[2], int portaltype); void GLR_PushDlights (void); void GLR_DrawWaterSurfaces (void); void GLVID_DeInit (void); void GLR_DeInit (void); void GLSCR_DeInit (void); void GLVID_Console_Resize(void); #endif int R_LightPoint (vec3_t p); void R_RenderDlights (void); typedef struct { int allocated[LMBLOCK_SIZE_MAX]; int firstlm; int lmnum; unsigned int width; unsigned int height; qboolean deluxe; } lmalloc_t; void Mod_LightmapAllocInit(lmalloc_t *lmallocator, qboolean hasdeluxe, unsigned int width, unsigned int height, int firstlm); //firstlm is for debugging stray lightmap indexes //void Mod_LightmapAllocDone(lmalloc_t *lmallocator, model_t *mod); void Mod_LightmapAllocBlock(lmalloc_t *lmallocator, int w, int h, unsigned short *x, unsigned short *y, int *tnum); enum imageflags { /*warning: many of these flags only apply the first time it is requested*/ IF_CLAMP = 1<<0, //disable texture coord wrapping. IF_NOMIPMAP = 1<<1, //disable mipmaps. IF_NEAREST = 1<<2, //force nearest IF_LINEAR = 1<<3, //force linear IF_UIPIC = 1<<4, //subject to texturemode2d //IF_DEPTHCMD = 1<<5, //Reserved for d3d11 IF_SRGB = 1<<6, //texture data is srgb (read-as-linear) /*WARNING: If the above are changed, be sure to change shader pass flags*/ IF_NOPICMIP = 1<<7, IF_NOALPHA = 1<<8, /*hint rather than requirement*/ IF_NOGAMMA = 1<<9, /*do not apply texture-based gamma*/ IF_TEXTYPEMASK = (1<<10) | (1<<11) | (1<<12), /*0=2d, 1=3d, 2=cubeface, 3=2d array texture*/ #define IF_TEXTYPESHIFT 10 #define IF_TEXTYPE_2D (PTI_2D<1)?Sys_DoubleTime()*1000000:0 #define RSpeedRemark() rsp = (r_speeds.ival>1)?Sys_DoubleTime()*1000000:0 #if defined(_WIN32) && defined(GLQUAKE) extern void (_stdcall *qglFinish) (void); #define RSpeedEnd(spt) do {if(r_speeds.ival > 1){if(r_speeds.ival > 2 && qglFinish)qglFinish(); rspeeds[spt] += (double)(Sys_DoubleTime()*1000000) - rsp;}}while (0) #else #define RSpeedEnd(spt) rspeeds[spt] += (r_speeds.ival>1)?Sys_DoubleTime()*1000000 - rsp:0 #endif #endif