Analyzing the FitzQuake texture manager

Discuss programming topics for the various GPL'd game engine sources.
Post Reply
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Analyzing the FitzQuake texture manager

Post by Baker »

This is just a pure knowledge mental exercise ...

The detail and the perfectionist nature of the remastering of the texture management code in FitzQuake has been a very educational experience in seeing all the pitfalls and perils involved.
static byte *TexMgr_PadImageH (byte *in, int width, int height, byte padbyte) // I think this merely pads the image, but didn't check to see
static byte *TexMgr_PadImageW (byte *in, int width, int height, byte padbyte) // I think this merely pads the image, but didn't check to see
static gltexture_t *TexMgr_FindTexture (model_t *owner, char *name) // Returns the texture info structure (including glnum) for a model where the name matches
static gltexture_t *TexMgr_NewTexture (void) // Generates a new texture (glgentexture) and returns the new texture structure
static int TexMgr_Pad (int s) // Returns smallest power of 2 texture size for a given texture (OpenGL 1.2 only supports power of 2 sized textures without an extension)
static int TexMgr_SafeTextureSize (int s) // Returns safe texture size based on hardware and the user preferences (gl_maxsize)
static unsigned *TexMgr_8to32 (byte *in, int pixels, unsigned int *usepal) // converts bytes to GL_RGBA (ie 8-bit to 32 bit rgb plus alpha)
static unsigned *TexMgr_MipMapH (unsigned *data, int width, int height) // Mipmaps a texture, only done by TexMgr_LoadImage32, which as expected is called by TexMgr_LoadImage8
static unsigned *TexMgr_MipMapW (unsigned *data, int width, int height) // Mipmaps a texture, only done by TexMgr_LoadImage32, which as expected is called by TexMgr_LoadImage8
static unsigned *TexMgr_ResampleTexture (unsigned *in, int inwidth, int inheight, qboolean alpha) // resamples the texture to specified desired size (the bytes of data)
static void GL_SelectTexture (GLenum target)
static void TexMgr_AlphaEdgeFix (byte *data, int width, int height) // "eliminate pink edges on sprites and etc" Probably a finishing touch to fix resampling issues
static void TexMgr_Anisotropy_f (void) // on all the textures
static void TexMgr_DescribeTextureModes_f (void) // prints the texturemode constants to the console
static void TexMgr_FreeTextures (int flags, int mask) // probably frees the world textures and leaves the 2d textures as is
static void TexMgr_Imagelist_f (void) // command that prints texture (and lightmap) information (image x by y, type of texture (map, model, sprite owner and frame, etc.) and texture name
static void TexMgr_LoadImage32 (gltexture_t *glt, unsigned *data)
static void TexMgr_LoadImage8 (gltexture_t *glt, byte *data)
static void TexMgr_LoadLightmap (gltexture_t *glt, byte *data)
static void TexMgr_LoadPalette (void)
static void TexMgr_PadEdgeFixH (byte *data, int width, int height)
static void TexMgr_PadEdgeFixW (byte *data, int width, int height)
static void TexMgr_SetFilterModes (gltexture_t *glt) // Sets the filtermode for a specific texture (but is always run against several in a for loop except for individual lightmaps)
static void TexMgr_TextureMode_f (void) // Sets the texture mode, which then runs setfiltermode against all textures
void GL_Bind (gltexture_t *texture) // used a lot, tells OpenGL (via glBindTexture) which 2d texture to work with/draw with
void GL_DisableMultitexture(void) // used a lot
void GL_EnableMultitexture(void) // used a lot
void TexMgr_FreeTexture (gltexture_t *kill) // deletes the texture (glDeleteTextures) and does the supporting removal finessing
void TexMgr_FreeTexturesForOwner (model_t *owner) // Called by TexMgr_NewGame, which is called on a gamedir change (but not on initialization)
void TexMgr_Init (void) // called by host_init
void TexMgr_NewGame (void) // called only on gamedir change, not initialization
void TexMgr_RecalcWarpImageSize (void) // warp image size recalc for the actual 2d screen resolution of the gl window (NOT the 2d graphics width), called by init and vid_restart
void TexMgr_ReloadImage (gltexture_t *glt, int shirt, int pants) // Looks like it recolorizes the texture
void TexMgr_ReloadImages (void) // Reloads all the (active) texture images, only called by vid_restart
float TexMgr_FrameUsage (void) // r_speeds 2, prints texture memory usage
gltexture_t *TexMgr_LoadImage (model_t *owner, char *name, int width, int height, enum srcformat format, byte *data, char *source_file, unsigned source_offset, unsigned flags) // single entry point for all textures
int TexMgr_PadConditional (int s) // Pads a texture if it needs it
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Post by Baker »

And looking at the GL rendering code in FitzQuake in general. Most of the "static" were supplied by me, trying to make it clear what interacts with the outside code versus within an individual source file so I can see entry points.

gl_draw.c
static int Scrap_AllocBlock (int w, int h, int *x, int *y)
static void Scrap_Upload (void)
qpic_t *Draw_PicFromWad (char *name)
qpic_t *Draw_CachePic (char *path)
static qpic_t *Draw_MakePic (char *name, int width, int height, byte *data)
static void Draw_LoadPics (void)
void Draw_NewGame (void) // hostcmd.c call this when gamedir is changed but is not called upon init
void Draw_Init (void) // host.c calls in host_init
static void Draw_CharacterQuad (int x, int y, char num)
void Draw_Character (int x, int y, int num) // called many places
void Draw_String (int x, int y, char *str) // called many places
void Draw_Pic (int x, int y, qpic_t *pic) // called many places
void Draw_TransPicTranslate (int x, int y, qpic_t *pic, int top, int bottom) //menu.c
void Draw_ConsoleBackground (void) // menu.c and console.c
void Draw_TileClear (int x, int y, int w, int h) // gl_screen.c and sbar.c
void Draw_Fill (int x, int y, int w, int h, int c) // many places in sbar.c
void Draw_FadeScreen (void) // gl_screen.c and menu.c
void Draw_BeginDisc (void) // common.c in COM_LoadFile calls this
void GL_SetCanvas (int canvastype) // called many places, controls viewport size
void GL_Set2D (void) // scr_updatescreen.c before
gl_fog.c
static void Fog_Update (float density, float red, float green, float blue, float time)
void Fog_ParseServerMessage (void) // cl_parse.c
static void Fog_FogCommand_f (void)
static void Fog_ParseWorldspawn (void)
void Fog_SetupFrame (void) // gl_rmain.c in r_setupview (actually it is the first thing going on)
float Fog_GetDensity (void)
void Fog_EnableGFog (void) // gl_rmain.c (R_Renderscene .. 2nd item and then turned off before drawing the view model) and gl_sky.c in Sky_DrawSky (called once per frame before drawing anything else; the fog is turned off before drawing the sky and then turned back on)
void Fog_DisableGFog (void)
void Fog_SetColorForSky (void) // called by gl_sky.c in sky_drawsky right after the fog is disabled
void Fog_NewMap (void) // called by r_newmap right after sky_newmap
void Fog_Init (void) // called by r_init
gl_mesh.c
static int StripLength (int starttri, int startv)
static int FanLength (int starttri, int startv)
static void BuildTris (void)
void GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr)
gl_efrag.c
void R_RemoveEfrags (entity_t *ent)
static void R_SplitEntityOnNode (mnode_t *node)
void R_AddEfrags (entity_t *ent)
void R_StoreEfrags (efrag_t **ppefrag)
gl_rlight.c
void R_AnimateLight (void) // r_scenesetup calls
static void AddLightBlend (float r, float g, float b, float a2)
static void R_RenderDlight (dlight_t *light)
void R_RenderDlights (void)
void R_MarkLights (dlight_t *light, int bit, mnode_t *node)
void R_PushDlights (void)
static int RecursiveLightPoint (vec3_t color, mnode_t *node, vec3_t start, vec3_t end)
int R_LightPoint (vec3_t p)
gl_rmain.c
void R_RenderView (void) // called by gl_rmisc a lot and view.c
qboolean R_CullBox (vec3_t emins, vec3_t emaxs)
void R_RotateForEntity (entity_t *e)
void GL_PolygonOffset (int offset)
static int SignbitsForPlane (mplane_t *out)
static void TurnVector (vec3_t out, const vec3_t forward, const vec3_t side, float angle)
static void R_SetFrustum (float fovx, float fovy)
static void GL_SetFrustum(float fovx, float fovy)
static void R_SetupGL (void) // in r_scenesetup
static void R_Clear (void) // static void R_SetupView (void)
static void R_SetupScene (void)
static void R_SetupView (void)
static void R_DrawEntitiesOnList (void)
static void R_DrawViewModel (void)
static void R_EmitWireBox (vec3_t mins, vec3_t maxs)
static void R_ShowBoundingBoxes (void)
static void R_ShowTris (void)
static void R_RenderScene (void)
gl_rmisc.c
static void GL_Overbright_f (void)
static void R_SetClearColor_f (void)
static void R_Novis_f (void)
static void R_OldSkyLeaf_f (void)
static void R_Envmap_f (void)
void R_Init (void) // host.c
void R_TranslatePlayerSkin (int playernum) // cl_parse.c and here
void R_TranslateNewPlayerSkin (int playernum) // cl_parse.c
void R_NewMap (void) // cl_parse.c
static void R_TimeRefresh_f (void)
void D_FlushCaches (void) // host.c in host_clearmemory which is mostly done for loading a new level
gl_screen.c
void SCR_CenterPrint (char *str) //update centerprint data
void SCR_DrawCenterString (void) //actually do the drawing
static void SCR_CheckDrawCenterString (void)
static float CalcFovy (float fov_x, float width, float height)
static void SCR_CalcRefdef (void)
static void SCR_SizeUp_f (void)
static void SCR_SizeDown_f (void)
static void SCR_Conwidth_f (void)
void SCR_LoadPics (void) // called by gl_draw.c in Draw_Newgame and here in scr_init
void SCR_Init (void) // host.c
static void SCR_DrawFPS (void)
static void SCR_DrawClock (void)
static void SCR_DrawRam (void)
static void SCR_DrawTurtle (void)
static void SCR_DrawNet (void)
static void SCR_DrawPause (void)
static void SCR_DrawLoading (void)
static void SCR_SetUpToDrawConsole (void)
static void SCR_DrawConsole (void)
static void SCR_ScreenShot_f (void)
void SCR_BeginLoadingPlaque (void)
void SCR_EndLoadingPlaque (void)
static void SCR_DrawNotifyString (void)
int SCR_ModalMessage (char *text, float timeout) //johnfitz -- timeout
static void SCR_TileClear (void)
void SCR_UpdateScreen (void) // the big dawg
gl_sky.c
void Sky_LoadTexture (texture_t *mt) // gl_model.c probably on new map load
void Sky_LoadSkyBox (char *name) // cl_parse.c
void Sky_NewMap (void) // r_newmap I bet, didn't look
static void Sky_SkyCommand_f (void)
void Sky_Init (void) // no doubt host.c
static void Sky_ProjectPoly (int nump, vec3_t vecs)
static void Sky_ClipPoly (int nump, vec3_t vecs, int stage)
static void Sky_ProcessPoly (glpoly_t *p)
static void Sky_ProcessTextureChains (void)
static void Sky_EmitSkyBoxVertex (float s, float t, int axis)
static void Sky_DrawSkyBox (void) // r_world.c
static void Sky_SetBoxVert (float s, float t, int axis, vec3_t v)
static void Sky_GetTexCoord (vec3_t v, float speed, float *s, float *t)
static void Sky_DrawFaceQuad (glpoly_t *p)
static void Sky_DrawFace (int axis)
void Sky_DrawSky (void) // I imagine by gl_rmain.c
gl_texture
static byte *TexMgr_PadImageH (byte *in, int width, int height, byte padbyte)
static byte *TexMgr_PadImageW (byte *in, int width, int height, byte padbyte)
static gltexture_t *TexMgr_FindTexture (model_t *owner, char *name)
static gltexture_t *TexMgr_NewTexture (void)
static int TexMgr_Pad (int s)
static int TexMgr_SafeTextureSize (int s)
static unsigned *TexMgr_8to32 (byte *in, int pixels, unsigned int *usepal)
static unsigned *TexMgr_MipMapH (unsigned *data, int width, int height)
static unsigned *TexMgr_MipMapW (unsigned *data, int width, int height)
static unsigned *TexMgr_ResampleTexture (unsigned *in, int inwidth, int inheight, qboolean alpha)
static void GL_SelectTexture (GLenum target)
static void TexMgr_AlphaEdgeFix (byte *data, int width, int height)
static void TexMgr_Anisotropy_f (void) // on all the textures
static void TexMgr_DescribeTextureModes_f (void) // prints the texturemode constants to the console
static void TexMgr_FreeTextures (int flags, int mask) // probably frees the world textures and leaves the 2d textures as is
static void TexMgr_Imagelist_f (void) // command that prints texture (and lightmap) information (image x by y, type of texture (map, model, sprite owner and frame, etc.) and texture name
static void TexMgr_LoadImage32 (gltexture_t *glt, unsigned *data)
static void TexMgr_LoadImage8 (gltexture_t *glt, byte *data)
static void TexMgr_LoadLightmap (gltexture_t *glt, byte *data)
static void TexMgr_LoadPalette (void)
static void TexMgr_PadEdgeFixH (byte *data, int width, int height)
static void TexMgr_PadEdgeFixW (byte *data, int width, int height)
static void TexMgr_SetFilterModes (gltexture_t *glt) // Sets the filtermode for a specific texture
static void TexMgr_TextureMode_f (void)
void GL_Bind (gltexture_t *texture)
void GL_DisableMultitexture(void)
void GL_EnableMultitexture(void)
void TexMgr_FreeTexture (gltexture_t *kill)
void TexMgr_FreeTexturesForOwner (model_t *owner)
void TexMgr_Init (void)
void TexMgr_NewGame (void)
void TexMgr_RecalcWarpImageSize (void)
void TexMgr_ReloadImage (gltexture_t *glt, int shirt, int pants)
void TexMgr_ReloadImages (void)
float TexMgr_FrameUsage (void) // r_speeds 2, prints texture memory usage
gltexture_t *TexMgr_LoadImage (model_t *owner, char *name, int width, int height, enum srcformat format, byte *data, char *source_file, unsigned source_offset, unsigned flags)
int TexMgr_PadConditional (int s)
Post Reply