From 58af4c84ff9517105eba38d20b0c69928982f995 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 19 Sep 2021 10:44:32 +0300 Subject: [PATCH 01/22] gl3: Scale 8bit images with retexturing=2 --- src/client/refresh/gl3/gl3_image.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/client/refresh/gl3/gl3_image.c b/src/client/refresh/gl3/gl3_image.c index f5dfc161..bd6c52cc 100644 --- a/src/client/refresh/gl3/gl3_image.c +++ b/src/client/refresh/gl3/gl3_image.c @@ -225,7 +225,7 @@ GL3_Upload32(unsigned *data, int width, int height, qboolean mipmap) qboolean GL3_Upload8(byte *data, int width, int height, qboolean mipmap, qboolean is_sky) { - unsigned trans[512 * 256]; + unsigned trans[1024 * 1024]; int i, s; int p; @@ -233,7 +233,7 @@ GL3_Upload8(byte *data, int width, int height, qboolean mipmap, qboolean is_sky) if (s > sizeof(trans) / 4) { - ri.Sys_Error(ERR_DROP, "GL3_Upload8: too large"); + ri.Sys_Error(ERR_DROP, "%s: too large", __func__); } for (i = 0; i < s; i++) @@ -429,9 +429,22 @@ GL3_LoadPic(char *name, byte *pic, int width, int realwidth, if (bits == 8) { - image->has_alpha = GL3_Upload8(pic, width, height, - (image->type != it_pic && image->type != it_sky), - image->type == it_sky); + // resize 8bit images only when we forced such logic + if (gl_retexturing->value >= 2) + { + byte *image_converted = malloc(width * height * 4); + scale2x(pic, image_converted, width, height); + image->has_alpha = GL3_Upload8(image_converted, width * 2, height * 2, + (image->type != it_pic && image->type != it_sky), + image->type == it_sky); + free(image_converted); + } + else + { + image->has_alpha = GL3_Upload8(pic, width, height, + (image->type != it_pic && image->type != it_sky), + image->type == it_sky); + } } else { From 0bbd65ebac769919829ac2027c35f9c864d18ef0 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 19 Sep 2021 13:07:17 +0300 Subject: [PATCH 02/22] gl1: Scale 8bit images with retexturing=2 --- src/client/refresh/gl1/gl1_image.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/client/refresh/gl1/gl1_image.c b/src/client/refresh/gl1/gl1_image.c index d06558f5..63f1eed2 100644 --- a/src/client/refresh/gl1/gl1_image.c +++ b/src/client/refresh/gl1/gl1_image.c @@ -761,7 +761,7 @@ R_Upload32(unsigned *data, int width, int height, qboolean mipmap) qboolean R_Upload8(byte *data, int width, int height, qboolean mipmap, qboolean is_sky) { - unsigned trans[512 * 256]; + unsigned trans[1024 * 1024]; int i, s; int p; @@ -769,7 +769,7 @@ R_Upload8(byte *data, int width, int height, qboolean mipmap, qboolean is_sky) if (s > sizeof(trans) / 4) { - ri.Sys_Error(ERR_DROP, "R_Upload8: too large"); + ri.Sys_Error(ERR_DROP, "%s: too large", __func__); } if (gl_config.palettedtexture && is_sky) @@ -926,9 +926,22 @@ R_LoadPic(char *name, byte *pic, int width, int realwidth, if (bits == 8) { - image->has_alpha = R_Upload8(pic, width, height, - (image->type != it_pic && image->type != it_sky), - image->type == it_sky); + // resize 8bit images only when we forced such logic + if (gl_retexturing->value >= 2) + { + byte *image_converted = malloc(width * height * 4); + scale2x(pic, image_converted, width, height); + image->has_alpha = R_Upload8(image_converted, width * 2, height * 2, + (image->type != it_pic && image->type != it_sky), + image->type == it_sky); + free(image_converted); + } + else + { + image->has_alpha = R_Upload8(pic, width, height, + (image->type != it_pic && image->type != it_sky), + image->type == it_sky); + } } else { From a9d693929712e07eb5bbc8058b99f8e8f4d778ec Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 19 Sep 2021 16:25:36 +0300 Subject: [PATCH 03/22] gl: use lower MSAA value on error --- src/client/vid/glimp_sdl.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/client/vid/glimp_sdl.c b/src/client/vid/glimp_sdl.c index 1be11894..c0cbfbb7 100755 --- a/src/client/vid/glimp_sdl.c +++ b/src/client/vid/glimp_sdl.c @@ -541,16 +541,26 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) { if((flags & SDL_WINDOW_OPENGL) && gl_msaa_samples->value) { + int msaa_samples = gl_msaa_samples->value; + + if (msaa_samples > 0) + { + msaa_samples /= 2; + } + Com_Printf("SDL SetVideoMode failed: %s\n", SDL_GetError()); - Com_Printf("Reverting to %s r_mode %i (%ix%i) without MSAA.\n", + Com_Printf("Reverting to %s r_mode %i (%ix%i) with %dx MSAA.\n", (flags & fs_flag) ? "fullscreen" : "windowed", - (int) Cvar_VariableValue("r_mode"), width, height); + (int) Cvar_VariableValue("r_mode"), width, height, + msaa_samples); /* Try to recover */ - Cvar_SetValue("r_msaa_samples", 0); + Cvar_SetValue("r_msaa_samples", msaa_samples); - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, + msaa_samples > 0 ? 1 : 0); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, + msaa_samples); } else if (width != 640 || height != 480 || (flags & fs_flag)) { From 34fb8d45b05c1cb1be17c37b61500528e254dcb4 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 19 Sep 2021 18:20:17 +0300 Subject: [PATCH 04/22] soft: Use common RadiusFromBounds --- src/client/refresh/soft/sw_model.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/client/refresh/soft/sw_model.c b/src/client/refresh/soft/sw_model.c index 0a82afe1..869f764c 100644 --- a/src/client/refresh/soft/sw_model.c +++ b/src/client/refresh/soft/sw_model.c @@ -408,25 +408,6 @@ Mod_LoadVertexes (model_t *loadmodel, byte *mod_base, lump_t *l) } } -/* -================= -RadiusFromBounds -================= -*/ -static float -RadiusFromBounds (vec3_t mins, vec3_t maxs) -{ - int i; - vec3_t corner; - - for (i=0 ; i<3 ; i++) - { - corner[i] = fabs(mins[i]) > fabs(maxs[i]) ? fabs(mins[i]) : fabs(maxs[i]); - } - - return VectorLength (corner); -} - /* ================= Mod_LoadSubmodels @@ -474,7 +455,7 @@ Mod_LoadSubmodels (model_t *loadmodel, byte *mod_base, lump_t *l) out->origin[j] = LittleFloat (in->origin[j]); } - out->radius = RadiusFromBounds (out->mins, out->maxs); + out->radius = Mod_RadiusFromBounds (out->mins, out->maxs); out->firstnode = LittleLong (in->headnode); out->firstmodelsurface = LittleLong (in->firstface); out->nummodelsurfaces = LittleLong (in->numfaces); From d8eb64cdcda4d0ce3783111a79da7eb5c4b2aa53 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 19 Sep 2021 18:58:18 +0300 Subject: [PATCH 05/22] gl1: port submodel load code from vk render(8bd39ad5) --- src/client/refresh/gl1/gl1_model.c | 83 +++++++++++---------------- src/client/refresh/gl1/header/model.h | 6 +- 2 files changed, 38 insertions(+), 51 deletions(-) diff --git a/src/client/refresh/gl1/gl1_model.c b/src/client/refresh/gl1/gl1_model.c index 5e83d3e8..8a4fc9d3 100644 --- a/src/client/refresh/gl1/gl1_model.c +++ b/src/client/refresh/gl1/gl1_model.c @@ -44,9 +44,6 @@ void LM_CreateSurfaceLightmap(msurface_t *surf); void LM_EndBuildingLightmaps(void); void LM_BeginBuildingLightmaps(model_t *m); -/* the inline * models from the current map are kept seperate */ -model_t mod_inline[MAX_MOD_KNOWN]; - mleaf_t * Mod_PointInLeaf(vec3_t p, model_t *model) { @@ -130,8 +127,8 @@ Mod_Init(void) /* * Loads in a model for the given name */ -model_t * -Mod_ForName(char *name, qboolean crash) +static model_t * +Mod_ForName (char *name, model_t *parent_model, qboolean crash) { model_t *mod; unsigned *buf; @@ -143,17 +140,17 @@ Mod_ForName(char *name, qboolean crash) } /* inline models are grabbed only from worldmodel */ - if (name[0] == '*') + if (name[0] == '*' && parent_model) { i = (int)strtol(name + 1, (char **)NULL, 10); - if ((i < 1) || !r_worldmodel || (i >= r_worldmodel->numsubmodels)) + if (i < 1 || i >= parent_model->numsubmodels) { ri.Sys_Error(ERR_DROP, "%s: bad inline model number", __func__); } - return &mod_inline[i]; + return &parent_model->submodels[i]; } /* search the currently loaded models */ @@ -302,10 +299,10 @@ Mod_LoadVertexes(lump_t *l) } void -Mod_LoadSubmodels(lump_t *l) +Mod_LoadSubmodels (model_t *loadmodel, byte *mod_base, lump_t *l) { dmodel_t *in; - mmodel_t *out; + model_t *out; int i, j, count; in = (void *)(mod_base + l->fileofs); @@ -324,6 +321,19 @@ Mod_LoadSubmodels(lump_t *l) for (i = 0; i < count; i++, in++, out++) { + if (i == 0) + { + // copy parent as template for first model + memcpy(out, loadmodel, sizeof(*out)); + } + else + { + // copy first as template for model + memcpy(out, loadmodel->submodels, sizeof(*out)); + } + + Com_sprintf (out->name, sizeof(out->name), "*%d", i); + for (j = 0; j < 3; j++) { /* spread the mins / maxs by a pixel */ @@ -333,9 +343,17 @@ Mod_LoadSubmodels(lump_t *l) } out->radius = Mod_RadiusFromBounds(out->mins, out->maxs); - out->headnode = LittleLong(in->headnode); - out->firstface = LittleLong(in->firstface); - out->numfaces = LittleLong(in->numfaces); + out->firstnode = LittleLong (in->headnode); + out->firstmodelsurface = LittleLong (in->firstface); + out->nummodelsurfaces = LittleLong (in->numfaces); + // visleafs + out->numleafs = 0; + // check limits + if (out->firstnode >= loadmodel->numnodes) + { + ri.Sys_Error(ERR_DROP, "%s: Inline model %i has bad firstnode", + __func__, i); + } } } @@ -938,7 +956,6 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen) { int i; dheader_t *header; - mmodel_t *bm; if (loadmodel != mod_known) { @@ -995,40 +1012,8 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen) Mod_LoadVisibility(&header->lumps[LUMP_VISIBILITY]); Mod_LoadLeafs(&header->lumps[LUMP_LEAFS]); Mod_LoadNodes(&header->lumps[LUMP_NODES]); - Mod_LoadSubmodels(&header->lumps[LUMP_MODELS]); + Mod_LoadSubmodels (loadmodel, mod_base, &header->lumps[LUMP_MODELS]); mod->numframes = 2; /* regular and alternate animation */ - - /* set up the submodels */ - for (i = 0; i < mod->numsubmodels; i++) - { - model_t *starmod; - - bm = &mod->submodels[i]; - starmod = &mod_inline[i]; - - *starmod = *loadmodel; - - starmod->firstmodelsurface = bm->firstface; - starmod->nummodelsurfaces = bm->numfaces; - starmod->firstnode = bm->headnode; - - if (starmod->firstnode >= loadmodel->numnodes) - { - ri.Sys_Error(ERR_DROP, "%s: Inline model %i has bad firstnode", - __func__, i); - } - - VectorCopy(bm->maxs, starmod->maxs); - VectorCopy(bm->mins, starmod->mins); - starmod->radius = bm->radius; - - if (i == 0) - { - *loadmodel = *starmod; - } - - starmod->numleafs = bm->visleafs; - } } void @@ -1076,7 +1061,7 @@ RI_BeginRegistration(char *model) Mod_Free(&mod_known[0]); } - r_worldmodel = Mod_ForName(fullname, true); + r_worldmodel = Mod_ForName(fullname, NULL, true); r_viewcluster = -1; } @@ -1089,7 +1074,7 @@ RI_RegisterModel(char *name) dsprite_t *sprout; dmdl_t *pheader; - mod = Mod_ForName(name, false); + mod = Mod_ForName(name, r_worldmodel, false); if (mod) { diff --git a/src/client/refresh/gl1/header/model.h b/src/client/refresh/gl1/header/model.h index eb77636a..0c8be2b2 100644 --- a/src/client/refresh/gl1/header/model.h +++ b/src/client/refresh/gl1/header/model.h @@ -172,7 +172,7 @@ typedef struct model_s int lightmap; /* only for submodels */ int numsubmodels; - mmodel_t *submodels; + struct model_s *submodels; int numplanes; cplane_t *planes; @@ -211,11 +211,13 @@ typedef struct model_s int extradatasize; void *extradata; + + // submodules + vec3_t origin; // for sounds or lights } model_t; void Mod_Init(void); void Mod_ClearAll(void); -model_t *Mod_ForName(char *name, qboolean crash); mleaf_t *Mod_PointInLeaf(vec3_t p, model_t *model); byte *Mod_ClusterPVS(int cluster, model_t *model); From 2c942d83f11419b8149a75561422ff42ad8e2cd9 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 19 Sep 2021 18:57:14 +0300 Subject: [PATCH 06/22] gl: use local model on load(35d598bc) --- src/client/refresh/gl1/gl1_model.c | 101 +++++++++++++------------- src/client/refresh/gl1/gl1_warp.c | 7 +- src/client/refresh/gl1/header/local.h | 2 +- 3 files changed, 53 insertions(+), 57 deletions(-) diff --git a/src/client/refresh/gl1/gl1_model.c b/src/client/refresh/gl1/gl1_model.c index 8a4fc9d3..7a5c76ad 100644 --- a/src/client/refresh/gl1/gl1_model.c +++ b/src/client/refresh/gl1/gl1_model.c @@ -28,16 +28,14 @@ #define MAX_MOD_KNOWN 512 -model_t *loadmodel; int modfilelen; YQ2_ALIGNAS_TYPE(int) byte mod_novis[MAX_MAP_LEAFS / 8]; model_t mod_known[MAX_MOD_KNOWN]; int mod_numknown; int registration_sequence; -byte *mod_base; void LoadSP2(model_t *mod, void *buffer, int modfilelen); -void Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen); +static void Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen); void LoadMD2(model_t *mod, void *buffer, int modfilelen); void LM_BuildPolygonFromSurface(msurface_t *fa); void LM_CreateSurfaceLightmap(msurface_t *surf); @@ -203,8 +201,6 @@ Mod_ForName (char *name, model_t *parent_model, qboolean crash) return NULL; } - loadmodel = mod; - /* call the apropriate loader */ switch (LittleLong(*(unsigned *)buf)) { @@ -226,15 +222,15 @@ Mod_ForName (char *name, model_t *parent_model, qboolean crash) break; } - loadmodel->extradatasize = Hunk_End(); + mod->extradatasize = Hunk_End(); ri.FS_FreeFile(buf); return mod; } -void -Mod_LoadLighting(lump_t *l) +static void +Mod_LoadLighting(model_t *loadmodel, byte *mod_base, lump_t *l) { if (!l->filelen) { @@ -246,8 +242,8 @@ Mod_LoadLighting(lump_t *l) memcpy(loadmodel->lightdata, mod_base + l->fileofs, l->filelen); } -void -Mod_LoadVisibility(lump_t *l) +static void +Mod_LoadVisibility(model_t *loadmodel, byte *mod_base, lump_t *l) { int i; @@ -269,8 +265,8 @@ Mod_LoadVisibility(lump_t *l) } } -void -Mod_LoadVertexes(lump_t *l) +static void +Mod_LoadVertexes(model_t *loadmodel, byte *mod_base, lump_t *l) { dvertex_t *in; mvertex_t *out; @@ -298,7 +294,7 @@ Mod_LoadVertexes(lump_t *l) } } -void +static void Mod_LoadSubmodels (model_t *loadmodel, byte *mod_base, lump_t *l) { dmodel_t *in; @@ -357,8 +353,8 @@ Mod_LoadSubmodels (model_t *loadmodel, byte *mod_base, lump_t *l) } } -void -Mod_LoadEdges(lump_t *l) +static void +Mod_LoadEdges(model_t *loadmodel, byte *mod_base, lump_t *l) { dedge_t *in; medge_t *out; @@ -385,8 +381,8 @@ Mod_LoadEdges(lump_t *l) } } -void -Mod_LoadTexinfo(lump_t *l) +static void +Mod_LoadTexinfo(model_t *loadmodel, byte *mod_base, lump_t *l) { texinfo_t *in; mtexinfo_t *out, *step; @@ -461,8 +457,8 @@ Mod_LoadTexinfo(lump_t *l) /* * Fills in s->texturemins[] and s->extents[] */ -void -Mod_CalcSurfaceExtents(msurface_t *s) +static void +Mod_CalcSurfaceExtents(model_t *loadmodel, msurface_t *s) { float mins[2], maxs[2], val; int i, j, e; @@ -517,7 +513,7 @@ Mod_CalcSurfaceExtents(msurface_t *s) } } -static int calcTexinfoAndFacesSize(const lump_t *fl, const lump_t *tl) +static int calcTexinfoAndFacesSize(byte *mod_base, const lump_t *fl, const lump_t *tl) { dface_t* face_in = (void *)(mod_base + fl->fileofs); texinfo_t* texinfo_in = (void *)(mod_base + tl->fileofs); @@ -592,8 +588,8 @@ static int calcTexinfoAndFacesSize(const lump_t *fl, const lump_t *tl) return ret; } -void -Mod_LoadFaces(lump_t *l) +static void +Mod_LoadFaces(model_t *loadmodel, byte *mod_base, lump_t *l) { dface_t *in; msurface_t *out; @@ -646,7 +642,7 @@ Mod_LoadFaces(lump_t *l) out->texinfo = loadmodel->texinfo + ti; - Mod_CalcSurfaceExtents(out); + Mod_CalcSurfaceExtents(loadmodel, out); /* lighting info */ for (i = 0; i < MAXLIGHTMAPS; i++) @@ -676,7 +672,7 @@ Mod_LoadFaces(lump_t *l) out->texturemins[i] = -8192; } - R_SubdivideSurface(out); /* cut up polygon for warps */ + R_SubdivideSurface(loadmodel, out); /* cut up polygon for warps */ } if (r_fixsurfsky->value) @@ -702,7 +698,7 @@ Mod_LoadFaces(lump_t *l) LM_EndBuildingLightmaps(); } -void +static void Mod_SetParent(mnode_t *node, mnode_t *parent) { node->parent = parent; @@ -716,8 +712,8 @@ Mod_SetParent(mnode_t *node, mnode_t *parent) Mod_SetParent(node->children[1], node); } -void -Mod_LoadNodes(lump_t *l) +static void +Mod_LoadNodes(model_t *loadmodel, byte *mod_base, lump_t *l) { int i, j, count, p; dnode_t *in; @@ -770,8 +766,8 @@ Mod_LoadNodes(lump_t *l) Mod_SetParent(loadmodel->nodes, NULL); /* sets nodes and leafs */ } -void -Mod_LoadLeafs(lump_t *l) +static void +Mod_LoadLeafs(model_t *loadmodel, byte *mod_base, lump_t *l) { dleaf_t *in; mleaf_t *out; @@ -820,8 +816,8 @@ Mod_LoadLeafs(lump_t *l) } } -void -Mod_LoadMarksurfaces(lump_t *l) +static void +Mod_LoadMarksurfaces(model_t *loadmodel, byte *mod_base, lump_t *l) { int i, j, count; short *in; @@ -855,8 +851,8 @@ Mod_LoadMarksurfaces(lump_t *l) } } -void -Mod_LoadSurfedges(lump_t *l) +static void +Mod_LoadSurfedges(model_t *loadmodel, byte *mod_base, lump_t *l) { int i, count; int *in, *out; @@ -888,8 +884,8 @@ Mod_LoadSurfedges(lump_t *l) } } -void -Mod_LoadPlanes(lump_t *l) +static void +Mod_LoadPlanes(model_t *loadmodel, byte *mod_base, lump_t *l) { int i, j; cplane_t *out; @@ -951,13 +947,14 @@ static int calcLumpHunkSize(const lump_t *l, int inSize, int outSize) return size; } -void +static void Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen) { int i; dheader_t *header; + byte *mod_base; - if (loadmodel != mod_known) + if (mod != mod_known) { ri.Sys_Error(ERR_DROP, "Loaded a brush model after the world"); } @@ -990,29 +987,29 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen) hunkSize += calcLumpHunkSize(&header->lumps[LUMP_SURFEDGES], sizeof(int), sizeof(int)); hunkSize += calcLumpHunkSize(&header->lumps[LUMP_LIGHTING], 1, 1); hunkSize += calcLumpHunkSize(&header->lumps[LUMP_PLANES], sizeof(dplane_t), sizeof(cplane_t)*2); - hunkSize += calcTexinfoAndFacesSize(&header->lumps[LUMP_FACES], &header->lumps[LUMP_TEXINFO]); + hunkSize += calcTexinfoAndFacesSize(mod_base, &header->lumps[LUMP_FACES], &header->lumps[LUMP_TEXINFO]); hunkSize += calcLumpHunkSize(&header->lumps[LUMP_LEAFFACES], sizeof(short), sizeof(msurface_t *)); // yes, out is indeeed a pointer! hunkSize += calcLumpHunkSize(&header->lumps[LUMP_VISIBILITY], 1, 1); hunkSize += calcLumpHunkSize(&header->lumps[LUMP_LEAFS], sizeof(dleaf_t), sizeof(mleaf_t)); hunkSize += calcLumpHunkSize(&header->lumps[LUMP_NODES], sizeof(dnode_t), sizeof(mnode_t)); hunkSize += calcLumpHunkSize(&header->lumps[LUMP_MODELS], sizeof(dmodel_t), sizeof(mmodel_t)); - loadmodel->extradata = Hunk_Begin(hunkSize); - loadmodel->type = mod_brush; + mod->extradata = Hunk_Begin(hunkSize); + mod->type = mod_brush; /* load into heap */ - Mod_LoadVertexes(&header->lumps[LUMP_VERTEXES]); - Mod_LoadEdges(&header->lumps[LUMP_EDGES]); - Mod_LoadSurfedges(&header->lumps[LUMP_SURFEDGES]); - Mod_LoadLighting(&header->lumps[LUMP_LIGHTING]); - Mod_LoadPlanes(&header->lumps[LUMP_PLANES]); - Mod_LoadTexinfo(&header->lumps[LUMP_TEXINFO]); - Mod_LoadFaces(&header->lumps[LUMP_FACES]); - Mod_LoadMarksurfaces(&header->lumps[LUMP_LEAFFACES]); - Mod_LoadVisibility(&header->lumps[LUMP_VISIBILITY]); - Mod_LoadLeafs(&header->lumps[LUMP_LEAFS]); - Mod_LoadNodes(&header->lumps[LUMP_NODES]); - Mod_LoadSubmodels (loadmodel, mod_base, &header->lumps[LUMP_MODELS]); + Mod_LoadVertexes(mod, mod_base, &header->lumps[LUMP_VERTEXES]); + Mod_LoadEdges(mod, mod_base, &header->lumps[LUMP_EDGES]); + Mod_LoadSurfedges(mod, mod_base, &header->lumps[LUMP_SURFEDGES]); + Mod_LoadLighting(mod, mod_base, &header->lumps[LUMP_LIGHTING]); + Mod_LoadPlanes(mod, mod_base, &header->lumps[LUMP_PLANES]); + Mod_LoadTexinfo(mod, mod_base, &header->lumps[LUMP_TEXINFO]); + Mod_LoadFaces(mod, mod_base, &header->lumps[LUMP_FACES]); + Mod_LoadMarksurfaces(mod, mod_base, &header->lumps[LUMP_LEAFFACES]); + Mod_LoadVisibility(mod, mod_base, &header->lumps[LUMP_VISIBILITY]); + Mod_LoadLeafs(mod, mod_base, &header->lumps[LUMP_LEAFS]); + Mod_LoadNodes(mod, mod_base, &header->lumps[LUMP_NODES]); + Mod_LoadSubmodels (mod, mod_base, &header->lumps[LUMP_MODELS]); mod->numframes = 2; /* regular and alternate animation */ } diff --git a/src/client/refresh/gl1/gl1_warp.c b/src/client/refresh/gl1/gl1_warp.c index 1253d673..a940d75b 100644 --- a/src/client/refresh/gl1/gl1_warp.c +++ b/src/client/refresh/gl1/gl1_warp.c @@ -31,19 +31,18 @@ #define ON_EPSILON 0.1 /* point on plane side epsilon */ #define MAX_CLIP_VERTS 64 -extern model_t *loadmodel; char skyname[MAX_QPATH]; float skyrotate; vec3_t skyaxis; image_t *sky_images[6]; msurface_t *warpface; int skytexorder[6] = {0, 2, 1, 3, 4, 5}; - + GLfloat vtx_sky[12]; GLfloat tex_sky[8]; unsigned int index_vtx = 0; unsigned int index_tex = 0; - + /* 3dstudio environment map names */ char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"}; @@ -243,7 +242,7 @@ R_SubdividePolygon(int numverts, float *verts) * can be done reasonably. */ void -R_SubdivideSurface(msurface_t *fa) +R_SubdivideSurface(model_t *loadmodel, msurface_t *fa) { vec3_t verts[64]; int numverts; diff --git a/src/client/refresh/gl1/header/local.h b/src/client/refresh/gl1/header/local.h index 5e893375..5758a976 100644 --- a/src/client/refresh/gl1/header/local.h +++ b/src/client/refresh/gl1/header/local.h @@ -265,7 +265,7 @@ void R_DrawAlphaSurfaces(void); void R_RenderBrushPoly(msurface_t *fa); void R_InitParticleTexture(void); void Draw_InitLocal(void); -void R_SubdivideSurface(msurface_t *fa); +void R_SubdivideSurface(model_t *loadmodel, msurface_t *fa); qboolean R_CullBox(vec3_t mins, vec3_t maxs); void R_RotateForEntity(entity_t *e); void R_MarkLeaves(void); From 2d1a090feb194c16d0669ade5aabd8dbdb596ab5 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 19 Sep 2021 19:17:53 +0300 Subject: [PATCH 07/22] gl: use local currentmodel --- src/client/refresh/gl1/gl1_lightmap.c | 2 +- src/client/refresh/gl1/gl1_main.c | 19 ++++++++------- src/client/refresh/gl1/gl1_mesh.c | 10 ++++---- src/client/refresh/gl1/gl1_model.c | 6 ++--- src/client/refresh/gl1/gl1_surf.c | 33 ++++++++++++++------------- src/client/refresh/gl1/header/local.h | 8 +++---- 6 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/client/refresh/gl1/gl1_lightmap.c b/src/client/refresh/gl1/gl1_lightmap.c index d8158209..5e81fc4e 100644 --- a/src/client/refresh/gl1/gl1_lightmap.c +++ b/src/client/refresh/gl1/gl1_lightmap.c @@ -137,7 +137,7 @@ LM_AllocBlock(int w, int h, int *x, int *y) } void -LM_BuildPolygonFromSurface(msurface_t *fa) +LM_BuildPolygonFromSurface(model_t *currentmodel, msurface_t *fa) { int i, lindex, lnumverts; medge_t *pedges, *r_pedge; diff --git a/src/client/refresh/gl1/gl1_main.c b/src/client/refresh/gl1/gl1_main.c index 478a0c85..09de0b19 100644 --- a/src/client/refresh/gl1/gl1_main.c +++ b/src/client/refresh/gl1/gl1_main.c @@ -40,7 +40,6 @@ image_t *r_notexture; /* use for bad textures */ image_t *r_particletexture; /* little dot for particles */ entity_t *currententity; -model_t *currentmodel; cplane_t frustum[4]; @@ -176,7 +175,7 @@ R_RotateForEntity(entity_t *e) } void -R_DrawSpriteModel(entity_t *e) +R_DrawSpriteModel(entity_t *e, const model_t *currentmodel) { float alpha = 1.0F; vec3_t point[4]; @@ -343,7 +342,7 @@ R_DrawEntitiesOnList(void) } else { - currentmodel = currententity->model; + const model_t *currentmodel = currententity->model; if (!currentmodel) { @@ -354,13 +353,13 @@ R_DrawEntitiesOnList(void) switch (currentmodel->type) { case mod_alias: - R_DrawAliasModel(currententity); + R_DrawAliasModel(currententity, currentmodel); break; case mod_brush: - R_DrawBrushModel(currententity); + R_DrawBrushModel(currententity, currentmodel); break; case mod_sprite: - R_DrawSpriteModel(currententity); + R_DrawSpriteModel(currententity, currentmodel); break; default: ri.Sys_Error(ERR_DROP, "Bad modeltype"); @@ -389,7 +388,7 @@ R_DrawEntitiesOnList(void) } else { - currentmodel = currententity->model; + const model_t *currentmodel = currententity->model; if (!currentmodel) { @@ -400,13 +399,13 @@ R_DrawEntitiesOnList(void) switch (currentmodel->type) { case mod_alias: - R_DrawAliasModel(currententity); + R_DrawAliasModel(currententity, currentmodel); break; case mod_brush: - R_DrawBrushModel(currententity); + R_DrawBrushModel(currententity, currentmodel); break; case mod_sprite: - R_DrawSpriteModel(currententity); + R_DrawSpriteModel(currententity, currentmodel); break; default: ri.Sys_Error(ERR_DROP, "Bad modeltype"); diff --git a/src/client/refresh/gl1/gl1_mesh.c b/src/client/refresh/gl1/gl1_mesh.c index 91069521..e0ea4b62 100644 --- a/src/client/refresh/gl1/gl1_mesh.c +++ b/src/client/refresh/gl1/gl1_mesh.c @@ -285,7 +285,7 @@ R_DrawAliasShadow(dmdl_t *paliashdr, int posenum) if (count < 0) { count = -count; - + type = GL_TRIANGLE_FAN; } else @@ -330,7 +330,7 @@ R_DrawAliasShadow(dmdl_t *paliashdr, int posenum) } static qboolean -R_CullAliasModel(vec3_t bbox[8], entity_t *e) +R_CullAliasModel(const model_t *currentmodel, vec3_t bbox[8], entity_t *e) { int i; vec3_t mins, maxs; @@ -482,7 +482,7 @@ R_CullAliasModel(vec3_t bbox[8], entity_t *e) } void -R_DrawAliasModel(entity_t *e) +R_DrawAliasModel(entity_t *e, const model_t *currentmodel) { int i; dmdl_t *paliashdr; @@ -492,7 +492,7 @@ R_DrawAliasModel(entity_t *e) if (!(e->flags & RF_WEAPONMODEL)) { - if (R_CullAliasModel(bbox, e)) + if (R_CullAliasModel(currentmodel, bbox, e)) { return; } @@ -631,7 +631,7 @@ R_DrawAliasModel(entity_t *e) shadelight[i] *= gl1_overbrightbits->value; } } - + /* ir goggles color override */ diff --git a/src/client/refresh/gl1/gl1_model.c b/src/client/refresh/gl1/gl1_model.c index 7a5c76ad..38b666e7 100644 --- a/src/client/refresh/gl1/gl1_model.c +++ b/src/client/refresh/gl1/gl1_model.c @@ -37,7 +37,7 @@ int registration_sequence; void LoadSP2(model_t *mod, void *buffer, int modfilelen); static void Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen); void LoadMD2(model_t *mod, void *buffer, int modfilelen); -void LM_BuildPolygonFromSurface(msurface_t *fa); +void LM_BuildPolygonFromSurface(model_t *currentmodel, msurface_t *fa); void LM_CreateSurfaceLightmap(msurface_t *surf); void LM_EndBuildingLightmaps(void); void LM_BeginBuildingLightmaps(model_t *m); @@ -611,8 +611,6 @@ Mod_LoadFaces(model_t *loadmodel, byte *mod_base, lump_t *l) loadmodel->surfaces = out; loadmodel->numsurfaces = count; - currentmodel = loadmodel; - LM_BeginBuildingLightmaps(loadmodel); for (surfnum = 0; surfnum < count; surfnum++, in++, out++) @@ -691,7 +689,7 @@ Mod_LoadFaces(model_t *loadmodel, byte *mod_base, lump_t *l) if (!(out->texinfo->flags & SURF_WARP)) { - LM_BuildPolygonFromSurface(out); + LM_BuildPolygonFromSurface(loadmodel, out); } } diff --git a/src/client/refresh/gl1/gl1_surf.c b/src/client/refresh/gl1/gl1_surf.c index 0c33850c..f8afc648 100644 --- a/src/client/refresh/gl1/gl1_surf.c +++ b/src/client/refresh/gl1/gl1_surf.c @@ -45,7 +45,7 @@ void R_BuildLightMap(msurface_t *surf, byte *dest, int stride); /* * Returns the proper texture for a given time and base texture */ -image_t * +static image_t * R_TextureAnimation(mtexinfo_t *tex) { int c; @@ -66,7 +66,7 @@ R_TextureAnimation(mtexinfo_t *tex) return tex->image; } -void +static void R_DrawGLPoly(glpoly_t *p) { float *v; @@ -84,7 +84,7 @@ R_DrawGLPoly(glpoly_t *p) glDisableClientState( GL_TEXTURE_COORD_ARRAY ); } -void +static void R_DrawGLFlowingPoly(msurface_t *fa) { int i; @@ -124,7 +124,7 @@ R_DrawGLFlowingPoly(msurface_t *fa) glDisableClientState( GL_TEXTURE_COORD_ARRAY ); } -void +static void R_DrawTriangleOutlines(void) { int i, j; @@ -179,7 +179,7 @@ R_DrawTriangleOutlines(void) glEnable(GL_TEXTURE_2D); } -void +static void R_DrawGLPolyChain(glpoly_t *p, float soffset, float toffset) { if ((soffset == 0) && (toffset == 0)) @@ -238,8 +238,8 @@ R_DrawGLPolyChain(glpoly_t *p, float soffset, float toffset) * This routine takes all the given light mapped surfaces * in the world and blends them into the framebuffer. */ -void -R_BlendLightmaps(void) +static void +R_BlendLightmaps(const model_t *currentmodel) { int i; msurface_t *surf, *newdrawsurf = 0; @@ -420,7 +420,7 @@ R_BlendLightmaps(void) glDepthMask(1); } -void +static void R_RenderBrushPoly(msurface_t *fa) { int maps; @@ -604,7 +604,7 @@ R_DrawAlphaSurfaces(void) r_alpha_surfaces = NULL; } -void +static void R_DrawTextureChains(void) { int i; @@ -640,8 +640,8 @@ R_DrawTextureChains(void) R_TexEnv(GL_REPLACE); } -void -R_DrawInlineBModel(void) +static void +R_DrawInlineBModel(const model_t *currentmodel) { int i, k; cplane_t *pplane; @@ -697,7 +697,7 @@ R_DrawInlineBModel(void) if (!(currententity->flags & RF_TRANSLUCENT)) { - R_BlendLightmaps(); + R_BlendLightmaps(currentmodel); } else { @@ -708,7 +708,7 @@ R_DrawInlineBModel(void) } void -R_DrawBrushModel(entity_t *e) +R_DrawBrushModel(entity_t *e, const model_t *currentmodel) { vec3_t mins, maxs; int i; @@ -784,7 +784,7 @@ R_DrawBrushModel(entity_t *e) R_TexEnv(GL_MODULATE); } - R_DrawInlineBModel(); + R_DrawInlineBModel(currentmodel); glPopMatrix(); @@ -794,7 +794,7 @@ R_DrawBrushModel(entity_t *e) } } -void +static void R_RecursiveWorldNode(mnode_t *node) { int c, side, sidebit; @@ -927,6 +927,7 @@ void R_DrawWorld(void) { entity_t ent; + const model_t *currentmodel; if (!r_drawworld->value) { @@ -955,7 +956,7 @@ R_DrawWorld(void) R_ClearSkyBox(); R_RecursiveWorldNode(r_worldmodel->nodes); R_DrawTextureChains(); - R_BlendLightmaps(); + R_BlendLightmaps(currentmodel); R_DrawSkyBox(); R_DrawTriangleOutlines(); diff --git a/src/client/refresh/gl1/header/local.h b/src/client/refresh/gl1/header/local.h index 5758a976..d53b28d6 100644 --- a/src/client/refresh/gl1/header/local.h +++ b/src/client/refresh/gl1/header/local.h @@ -146,7 +146,6 @@ extern int numgltextures; extern image_t *r_notexture; extern image_t *r_particletexture; extern entity_t *currententity; -extern model_t *currentmodel; extern int r_visframecount; extern int r_framecount; extern cplane_t frustum[4]; @@ -255,14 +254,13 @@ void V_AddBlend(float r, float g, float b, float a, float *v_blend); void R_RenderView(refdef_t *fd); void R_ScreenShot(void); -void R_DrawAliasModel(entity_t *e); -void R_DrawBrushModel(entity_t *e); -void R_DrawSpriteModel(entity_t *e); +void R_DrawAliasModel(entity_t *e, const model_t *currentmodel); +void R_DrawBrushModel(entity_t *e, const model_t *currentmodel); +void R_DrawSpriteModel(entity_t *e, const model_t *currentmodel); 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 R_SubdivideSurface(model_t *loadmodel, msurface_t *fa); From 083cfca30591be27e2c988009a86ccf522d13671 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 19 Sep 2021 20:05:38 +0300 Subject: [PATCH 08/22] gl1: make currententity local --- src/client/refresh/gl1/gl1_light.c | 2 +- src/client/refresh/gl1/gl1_main.c | 48 ++++++++++----------- src/client/refresh/gl1/gl1_mesh.c | 38 ++++++++--------- src/client/refresh/gl1/gl1_surf.c | 60 +++++++++++++-------------- src/client/refresh/gl1/header/local.h | 10 ++--- 5 files changed, 75 insertions(+), 83 deletions(-) diff --git a/src/client/refresh/gl1/gl1_light.c b/src/client/refresh/gl1/gl1_light.c index ac362518..fdd30355 100644 --- a/src/client/refresh/gl1/gl1_light.c +++ b/src/client/refresh/gl1/gl1_light.c @@ -326,7 +326,7 @@ R_RecursiveLightPoint(mnode_t *node, vec3_t start, vec3_t end) } void -R_LightPoint(vec3_t p, vec3_t color) +R_LightPoint(entity_t *currententity, vec3_t p, vec3_t color) { vec3_t end; float r; diff --git a/src/client/refresh/gl1/gl1_main.c b/src/client/refresh/gl1/gl1_main.c index 09de0b19..f55579db 100644 --- a/src/client/refresh/gl1/gl1_main.c +++ b/src/client/refresh/gl1/gl1_main.c @@ -39,8 +39,6 @@ glstate_t gl_state; image_t *r_notexture; /* use for bad textures */ image_t *r_particletexture; /* little dot for particles */ -entity_t *currententity; - cplane_t frustum[4]; int r_visframecount; /* bumped when going to a new PVS */ @@ -175,7 +173,7 @@ R_RotateForEntity(entity_t *e) } void -R_DrawSpriteModel(entity_t *e, const model_t *currentmodel) +R_DrawSpriteModel(entity_t *currententity, const model_t *currentmodel) { float alpha = 1.0F; vec3_t point[4]; @@ -187,16 +185,16 @@ R_DrawSpriteModel(entity_t *e, const model_t *currentmodel) a single polygon without a surface cache */ psprite = (dsprite_t *)currentmodel->extradata; - e->frame %= psprite->numframes; - frame = &psprite->frames[e->frame]; + currententity->frame %= psprite->numframes; + frame = &psprite->frames[currententity->frame]; /* normal sprite */ up = vup; right = vright; - if (e->flags & RF_TRANSLUCENT) + if (currententity->flags & RF_TRANSLUCENT) { - alpha = e->alpha; + alpha = currententity->alpha; } if (alpha != 1.0F) @@ -206,7 +204,7 @@ R_DrawSpriteModel(entity_t *e, const model_t *currentmodel) glColor4f(1, 1, 1, alpha); - R_Bind(currentmodel->skins[e->frame]->texnum); + R_Bind(currentmodel->skins[currententity->frame]->texnum); R_TexEnv(GL_MODULATE); @@ -226,16 +224,16 @@ R_DrawSpriteModel(entity_t *e, const model_t *currentmodel) 1, 1 }; - VectorMA( e->origin, -frame->origin_y, up, point[0] ); + VectorMA( currententity->origin, -frame->origin_y, up, point[0] ); VectorMA( point[0], -frame->origin_x, right, point[0] ); - VectorMA( e->origin, frame->height - frame->origin_y, up, point[1] ); + VectorMA( currententity->origin, frame->height - frame->origin_y, up, point[1] ); VectorMA( point[1], -frame->origin_x, right, point[1] ); - VectorMA( e->origin, frame->height - frame->origin_y, up, point[2] ); + VectorMA( currententity->origin, frame->height - frame->origin_y, up, point[2] ); VectorMA( point[2], frame->width - frame->origin_x, right, point[2] ); - VectorMA( e->origin, -frame->origin_y, up, point[3] ); + VectorMA( currententity->origin, -frame->origin_y, up, point[3] ); VectorMA( point[3], frame->width - frame->origin_x, right, point[3] ); glEnableClientState( GL_VERTEX_ARRAY ); @@ -260,7 +258,7 @@ R_DrawSpriteModel(entity_t *e, const model_t *currentmodel) } void -R_DrawNullModel(void) +R_DrawNullModel(entity_t *currententity) { vec3_t shadelight; @@ -270,7 +268,7 @@ R_DrawNullModel(void) } else { - R_LightPoint(currententity->origin, shadelight); + R_LightPoint(currententity, currententity->origin, shadelight); } glPushMatrix(); @@ -329,7 +327,7 @@ R_DrawEntitiesOnList(void) /* draw non-transparent first */ for (i = 0; i < r_newrefdef.num_entities; i++) { - currententity = &r_newrefdef.entities[i]; + entity_t *currententity = &r_newrefdef.entities[i]; if (currententity->flags & RF_TRANSLUCENT) { @@ -346,7 +344,7 @@ R_DrawEntitiesOnList(void) if (!currentmodel) { - R_DrawNullModel(); + R_DrawNullModel(currententity); continue; } @@ -375,7 +373,7 @@ R_DrawEntitiesOnList(void) for (i = 0; i < r_newrefdef.num_entities; i++) { - currententity = &r_newrefdef.entities[i]; + entity_t *currententity = &r_newrefdef.entities[i]; if (!(currententity->flags & RF_TRANSLUCENT)) { @@ -392,7 +390,7 @@ R_DrawEntitiesOnList(void) if (!currentmodel) { - R_DrawNullModel(); + R_DrawNullModel(currententity); continue; } @@ -951,7 +949,7 @@ R_SetGL2D(void) /* * r_newrefdef must be set before the first call */ -void +static void R_RenderView(refdef_t *fd) { if ((gl_state.stereo_mode != STEREO_MODE_NONE) && gl_state.camera_separation) { @@ -1072,7 +1070,7 @@ R_RenderView(refdef_t *fd) if (!r_worldmodel && !(r_newrefdef.rdflags & RDF_NOWORLDMODEL)) { - ri.Sys_Error(ERR_DROP, "R_RenderView: NULL worldmodel"); + ri.Sys_Error(ERR_DROP, "%s: NULL worldmodel", __func__); } if (r_speeds->value) @@ -1149,8 +1147,8 @@ GL_GetSpecialBufferModeForStereoMode(enum stereo_modes stereo_mode) { return OPENGL_SPECIAL_BUFFER_MODE_NONE; } -void -R_SetLightLevel(void) +static void +R_SetLightLevel(entity_t *currententity) { vec3_t shadelight; @@ -1160,7 +1158,7 @@ R_SetLightLevel(void) } /* save off light value for server to look at */ - R_LightPoint(r_newrefdef.vieworg, shadelight); + R_LightPoint(currententity, r_newrefdef.vieworg, shadelight); /* pick the greatest component, which should be the * same as the mono value returned by software */ @@ -1188,11 +1186,11 @@ R_SetLightLevel(void) } } -void +static void RI_RenderFrame(refdef_t *fd) { R_RenderView(fd); - R_SetLightLevel(); + R_SetLightLevel (NULL); R_SetGL2D(); } diff --git a/src/client/refresh/gl1/gl1_mesh.c b/src/client/refresh/gl1/gl1_mesh.c index e0ea4b62..69e06dbd 100644 --- a/src/client/refresh/gl1/gl1_mesh.c +++ b/src/client/refresh/gl1/gl1_mesh.c @@ -45,8 +45,8 @@ float shadelight[3]; float *shadedots = r_avertexnormal_dots[0]; extern vec3_t lightspot; -void -R_LerpVerts(int nverts, dtrivertx_t *v, dtrivertx_t *ov, +static void +R_LerpVerts(entity_t *currententity, int nverts, dtrivertx_t *v, dtrivertx_t *ov, dtrivertx_t *verts, float *lerp, float move[3], float frontv[3], float backv[3]) { @@ -83,8 +83,8 @@ R_LerpVerts(int nverts, dtrivertx_t *v, dtrivertx_t *ov, /* * Interpolates between two frames and origins */ -void -R_DrawAliasFrameLerp(dmdl_t *paliashdr, float backlerp) +static void +R_DrawAliasFrameLerp(entity_t *currententity, dmdl_t *paliashdr, float backlerp) { unsigned short total; GLenum type; @@ -152,7 +152,7 @@ R_DrawAliasFrameLerp(dmdl_t *paliashdr, float backlerp) lerp = s_lerped[0]; - R_LerpVerts(paliashdr->num_xyz, v, ov, verts, lerp, move, frontv, backv); + R_LerpVerts(currententity, paliashdr->num_xyz, v, ov, verts, lerp, move, frontv, backv); while (1) { @@ -250,8 +250,8 @@ R_DrawAliasFrameLerp(dmdl_t *paliashdr, float backlerp) } } -void -R_DrawAliasShadow(dmdl_t *paliashdr, int posenum) +static void +R_DrawAliasShadow(entity_t *currententity, dmdl_t *paliashdr, int posenum) { unsigned short total; GLenum type; @@ -482,7 +482,7 @@ R_CullAliasModel(const model_t *currentmodel, vec3_t bbox[8], entity_t *e) } void -R_DrawAliasModel(entity_t *e, const model_t *currentmodel) +R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel) { int i; dmdl_t *paliashdr; @@ -490,15 +490,15 @@ R_DrawAliasModel(entity_t *e, const model_t *currentmodel) vec3_t bbox[8]; image_t *skin; - if (!(e->flags & RF_WEAPONMODEL)) + if (!(currententity->flags & RF_WEAPONMODEL)) { - if (R_CullAliasModel(currentmodel, bbox, e)) + if (R_CullAliasModel(currentmodel, bbox, currententity)) { return; } } - if (e->flags & RF_WEAPONMODEL) + if (currententity->flags & RF_WEAPONMODEL) { if (gl_lefthand->value == 2) { @@ -552,7 +552,7 @@ R_DrawAliasModel(entity_t *e, const model_t *currentmodel) } else { - R_LightPoint(currententity->origin, shadelight); + R_LightPoint(currententity, currententity->origin, shadelight); /* player lighting hack for communication back to server */ if (currententity->flags & RF_WEAPONMODEL) @@ -695,9 +695,9 @@ R_DrawAliasModel(entity_t *e, const model_t *currentmodel) } glPushMatrix(); - e->angles[PITCH] = -e->angles[PITCH]; - R_RotateForEntity(e); - e->angles[PITCH] = -e->angles[PITCH]; + currententity->angles[PITCH] = -currententity->angles[PITCH]; + R_RotateForEntity(currententity); + currententity->angles[PITCH] = -currententity->angles[PITCH]; /* select skin */ if (currententity->skin) @@ -761,7 +761,7 @@ R_DrawAliasModel(entity_t *e, const model_t *currentmodel) currententity->backlerp = 0; } - R_DrawAliasFrameLerp(paliashdr, currententity->backlerp); + R_DrawAliasFrameLerp(currententity, paliashdr, currententity->backlerp); R_TexEnv(GL_REPLACE); glShadeModel(GL_FLAT); @@ -811,13 +811,13 @@ R_DrawAliasModel(entity_t *e, const model_t *currentmodel) glPushMatrix(); /* don't rotate shadows on ungodly axes */ - glTranslatef(e->origin[0], e->origin[1], e->origin[2]); - glRotatef(e->angles[1], 0, 0, 1); + glTranslatef(currententity->origin[0], currententity->origin[1], currententity->origin[2]); + glRotatef(currententity->angles[1], 0, 0, 1); glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); glColor4f(0, 0, 0, 0.5f); - R_DrawAliasShadow(paliashdr, currententity->frame); + R_DrawAliasShadow(currententity, paliashdr, currententity->frame); glEnable(GL_TEXTURE_2D); glDisable(GL_BLEND); glPopMatrix(); diff --git a/src/client/refresh/gl1/gl1_surf.c b/src/client/refresh/gl1/gl1_surf.c index f8afc648..7acd6aac 100644 --- a/src/client/refresh/gl1/gl1_surf.c +++ b/src/client/refresh/gl1/gl1_surf.c @@ -46,7 +46,7 @@ void R_BuildLightMap(msurface_t *surf, byte *dest, int stride); * Returns the proper texture for a given time and base texture */ static image_t * -R_TextureAnimation(mtexinfo_t *tex) +R_TextureAnimation(entity_t *currententity, mtexinfo_t *tex) { int c; @@ -421,7 +421,7 @@ R_BlendLightmaps(const model_t *currentmodel) } static void -R_RenderBrushPoly(msurface_t *fa) +R_RenderBrushPoly(entity_t *currententity, msurface_t *fa) { int maps; image_t *image; @@ -429,7 +429,7 @@ R_RenderBrushPoly(msurface_t *fa) c_brush_polys++; - image = R_TextureAnimation(fa->texinfo); + image = R_TextureAnimation(currententity, fa->texinfo); if (fa->flags & SURF_DRAWTURB) { @@ -605,7 +605,7 @@ R_DrawAlphaSurfaces(void) } static void -R_DrawTextureChains(void) +R_DrawTextureChains(entity_t *currententity) { int i; msurface_t *s; @@ -631,7 +631,7 @@ R_DrawTextureChains(void) for ( ; s; s = s->texturechain) { - R_RenderBrushPoly(s); + R_RenderBrushPoly(currententity, s); } image->texturechain = NULL; @@ -641,7 +641,7 @@ R_DrawTextureChains(void) } static void -R_DrawInlineBModel(const model_t *currentmodel) +R_DrawInlineBModel(entity_t *currententity, const model_t *currentmodel) { int i, k; cplane_t *pplane; @@ -689,7 +689,7 @@ R_DrawInlineBModel(const model_t *currentmodel) } else { - R_RenderBrushPoly(psurf); + R_RenderBrushPoly(currententity, psurf); } } } @@ -708,7 +708,7 @@ R_DrawInlineBModel(const model_t *currentmodel) } void -R_DrawBrushModel(entity_t *e, const model_t *currentmodel) +R_DrawBrushModel(entity_t *currententity, const model_t *currentmodel) { vec3_t mins, maxs; int i; @@ -719,24 +719,23 @@ R_DrawBrushModel(entity_t *e, const model_t *currentmodel) return; } - currententity = e; gl_state.currenttextures[0] = gl_state.currenttextures[1] = -1; - if (e->angles[0] || e->angles[1] || e->angles[2]) + if (currententity->angles[0] || currententity->angles[1] || currententity->angles[2]) { rotated = true; for (i = 0; i < 3; i++) { - mins[i] = e->origin[i] - currentmodel->radius; - maxs[i] = e->origin[i] + currentmodel->radius; + mins[i] = currententity->origin[i] - currentmodel->radius; + maxs[i] = currententity->origin[i] + currentmodel->radius; } } else { rotated = false; - VectorAdd(e->origin, currentmodel->mins, mins); - VectorAdd(e->origin, currentmodel->maxs, maxs); + VectorAdd(currententity->origin, currentmodel->mins, mins); + VectorAdd(currententity->origin, currentmodel->maxs, maxs); } if (R_CullBox(mins, maxs)) @@ -752,7 +751,7 @@ R_DrawBrushModel(entity_t *e, const model_t *currentmodel) glColor4f(1, 1, 1, 1); memset(gl_lms.lightmap_surfaces, 0, sizeof(gl_lms.lightmap_surfaces)); - VectorSubtract(r_newrefdef.vieworg, e->origin, modelorg); + VectorSubtract(r_newrefdef.vieworg, currententity->origin, modelorg); if (rotated) { @@ -760,18 +759,18 @@ R_DrawBrushModel(entity_t *e, const model_t *currentmodel) vec3_t forward, right, up; VectorCopy(modelorg, temp); - AngleVectors(e->angles, forward, right, up); + AngleVectors(currententity->angles, forward, right, up); modelorg[0] = DotProduct(temp, forward); modelorg[1] = -DotProduct(temp, right); modelorg[2] = DotProduct(temp, up); } glPushMatrix(); - e->angles[0] = -e->angles[0]; - e->angles[2] = -e->angles[2]; - R_RotateForEntity(e); - e->angles[0] = -e->angles[0]; - e->angles[2] = -e->angles[2]; + currententity->angles[0] = -currententity->angles[0]; + currententity->angles[2] = -currententity->angles[2]; + R_RotateForEntity(currententity); + currententity->angles[0] = -currententity->angles[0]; + currententity->angles[2] = -currententity->angles[2]; R_TexEnv(GL_REPLACE); @@ -784,7 +783,7 @@ R_DrawBrushModel(entity_t *e, const model_t *currentmodel) R_TexEnv(GL_MODULATE); } - R_DrawInlineBModel(currentmodel); + R_DrawInlineBModel(currententity, currentmodel); glPopMatrix(); @@ -795,7 +794,7 @@ R_DrawBrushModel(entity_t *e, const model_t *currentmodel) } static void -R_RecursiveWorldNode(mnode_t *node) +R_RecursiveWorldNode(entity_t *currententity, mnode_t *node) { int c, side, sidebit; cplane_t *plane; @@ -881,7 +880,7 @@ R_RecursiveWorldNode(mnode_t *node) } /* recurse down the children, front side first */ - R_RecursiveWorldNode(node->children[side]); + R_RecursiveWorldNode(currententity, node->children[side]); /* draw stuff */ for (c = node->numsurfaces, @@ -908,19 +907,19 @@ R_RecursiveWorldNode(mnode_t *node) /* add to the translucent chain */ surf->texturechain = r_alpha_surfaces; r_alpha_surfaces = surf; - r_alpha_surfaces->texinfo->image = R_TextureAnimation(surf->texinfo); + r_alpha_surfaces->texinfo->image = R_TextureAnimation(currententity, surf->texinfo); } else { /* the polygon is visible, so add it to the texture sorted chain */ - image = R_TextureAnimation(surf->texinfo); + image = R_TextureAnimation(currententity, surf->texinfo); surf->texturechain = image->texturechain; image->texturechain = surf; } } /* recurse down the back side */ - R_RecursiveWorldNode(node->children[!side]); + R_RecursiveWorldNode(currententity, node->children[!side]); } void @@ -946,7 +945,6 @@ R_DrawWorld(void) /* auto cycle the world frame for texture animation */ memset(&ent, 0, sizeof(ent)); ent.frame = (int)(r_newrefdef.time * 2); - currententity = &ent; gl_state.currenttextures[0] = gl_state.currenttextures[1] = -1; @@ -954,13 +952,11 @@ R_DrawWorld(void) memset(gl_lms.lightmap_surfaces, 0, sizeof(gl_lms.lightmap_surfaces)); R_ClearSkyBox(); - R_RecursiveWorldNode(r_worldmodel->nodes); - R_DrawTextureChains(); + R_RecursiveWorldNode(&ent, r_worldmodel->nodes); + R_DrawTextureChains(&ent); R_BlendLightmaps(currentmodel); R_DrawSkyBox(); R_DrawTriangleOutlines(); - - currententity = NULL; } /* diff --git a/src/client/refresh/gl1/header/local.h b/src/client/refresh/gl1/header/local.h index d53b28d6..3ed11750 100644 --- a/src/client/refresh/gl1/header/local.h +++ b/src/client/refresh/gl1/header/local.h @@ -145,7 +145,6 @@ extern int numgltextures; extern image_t *r_notexture; extern image_t *r_particletexture; -extern entity_t *currententity; extern int r_visframecount; extern int r_framecount; extern cplane_t frustum[4]; @@ -243,7 +242,7 @@ void R_Bind(int texnum); void R_TexEnv(GLenum value); -void R_LightPoint(vec3_t p, vec3_t color); +void R_LightPoint(entity_t *currententity, vec3_t p, vec3_t color); void R_PushDlights(void); extern model_t *r_worldmodel; @@ -252,11 +251,10 @@ extern int registration_sequence; void V_AddBlend(float r, float g, float b, float a, float *v_blend); -void R_RenderView(refdef_t *fd); void R_ScreenShot(void); -void R_DrawAliasModel(entity_t *e, const model_t *currentmodel); -void R_DrawBrushModel(entity_t *e, const model_t *currentmodel); -void R_DrawSpriteModel(entity_t *e, const model_t *currentmodel); +void R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel); +void R_DrawBrushModel(entity_t *currententity, const model_t *currentmodel); +void R_DrawSpriteModel(entity_t *currententity, const model_t *currentmodel); void R_DrawBeam(entity_t *e); void R_DrawWorld(void); void R_RenderDlights(void); From f3f8c9a1f649f530f47d5c30e8b54218accd7969 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 19 Sep 2021 21:37:30 +0300 Subject: [PATCH 09/22] soft: make r_worldentity local --- src/client/refresh/soft/header/local.h | 5 ++--- src/client/refresh/soft/sw_bsp.c | 8 ++++---- src/client/refresh/soft/sw_edge.c | 18 +++++++----------- src/client/refresh/soft/sw_main.c | 11 +++++------ src/client/refresh/soft/sw_model.c | 2 +- 5 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/client/refresh/soft/header/local.h b/src/client/refresh/soft/header/local.h index e26f207a..c092a9da 100644 --- a/src/client/refresh/soft/header/local.h +++ b/src/client/refresh/soft/header/local.h @@ -443,7 +443,7 @@ extern int *pfrustum_indexes[4]; //============================================================================= -void R_RenderWorld(void); +void R_RenderWorld(entity_t *currententity); //============================================================================= @@ -451,7 +451,6 @@ extern cplane_t screenedge[4]; extern vec3_t r_origin; -extern entity_t r_worldentity; extern vec3_t modelorg; extern vec3_t r_entorigin; @@ -477,7 +476,7 @@ void R_DrawSolidClippedSubmodelPolygons(entity_t *currententity, const model_t * void R_AliasDrawModel(entity_t *currententity, const model_t *currentmodel); void R_BeginEdgeFrame(void); -void R_ScanEdges(surf_t *surface); +void R_ScanEdges(entity_t *currententity, surf_t *surface); void R_PushDlights(const model_t *model); void R_RotateBmodel(const entity_t *currententity); diff --git a/src/client/refresh/soft/sw_bsp.c b/src/client/refresh/soft/sw_bsp.c index 6b04c6f5..064a155c 100644 --- a/src/client/refresh/soft/sw_bsp.c +++ b/src/client/refresh/soft/sw_bsp.c @@ -587,7 +587,7 @@ R_RecursiveWorldNode (entity_t *currententity, const model_t *currentmodel, mnod { msurface_t *surf; - surf = r_worldmodel->surfaces + node->firstsurface; + surf = currentmodel->surfaces + node->firstsurface; if (dot < -BACKFACE_EPSILON) { @@ -631,7 +631,7 @@ R_RenderWorld ================ */ void -R_RenderWorld (void) +R_RenderWorld (entity_t *currententity) { const model_t *currentmodel = r_worldmodel; @@ -643,10 +643,10 @@ R_RenderWorld (void) c_drawnode=0; // auto cycle the world frame for texture animation - r_worldentity.frame = (int)(r_newrefdef.time*2); + currententity->frame = (int)(r_newrefdef.time*2); VectorCopy (r_origin, modelorg); r_pcurrentvertbase = currentmodel->vertexes; - R_RecursiveWorldNode (&r_worldentity, currentmodel, currentmodel->nodes, ALIAS_XY_CLIP_MASK, false); + R_RecursiveWorldNode (currententity, currentmodel, currentmodel->nodes, ALIAS_XY_CLIP_MASK, false); } diff --git a/src/client/refresh/soft/sw_edge.c b/src/client/refresh/soft/sw_edge.c index 640d15de..ea0db8a1 100644 --- a/src/client/refresh/soft/sw_edge.c +++ b/src/client/refresh/soft/sw_edge.c @@ -581,7 +581,7 @@ R_GenerateSpansBackward (void) R_CleanupSpan (); } -static void D_DrawSurfaces (surf_t *surface); +static void D_DrawSurfaces (entity_t *currententity, surf_t *surface); /* ============== @@ -597,7 +597,7 @@ Each surface has a linked list of its visible spans ============== */ void -R_ScanEdges (surf_t *surface) +R_ScanEdges (entity_t *currententity, surf_t *surface) { shift20_t iv, bottom; surf_t *s; @@ -672,7 +672,7 @@ R_ScanEdges (surf_t *surface) if (span_p + r_refdef.vrect.width >= max_span_p) { // Draw stuff on screen - D_DrawSurfaces (surface); + D_DrawSurfaces (currententity, surface); // clear the surface span pointers for (s = &surfaces[1] ; sinsubmodel) { vec3_t local_modelorg; @@ -952,8 +950,6 @@ D_SolidSurf (surf_t *s) R_RotateBmodel(currententity); // FIXME: don't mess with the frustum, // make entity passed in } - else - currententity = &r_worldentity; pface = s->msurf; miplevel = D_MipLevelForScale(s->nearzi * scale_for_mip * pface->texinfo->mipadjust); @@ -1022,7 +1018,7 @@ May be called more than once a frame if the surf list overflows (higher res) ============== */ static void -D_DrawSurfaces (surf_t *surface) +D_DrawSurfaces (entity_t *currententity, surf_t *surface) { VectorSubtract (r_origin, vec3_origin, modelorg); TransformVector (modelorg, transformed_modelorg); @@ -1040,7 +1036,7 @@ D_DrawSurfaces (surf_t *surface) r_drawnpolycount++; if (! (s->flags & (SURF_DRAWSKYBOX|SURF_DRAWBACKGROUND|SURF_DRAWTURB) ) ) - D_SolidSurf (s); + D_SolidSurf (currententity, s); else if (s->flags & SURF_DRAWSKYBOX) D_SkySurf (s); else if (s->flags & SURF_DRAWBACKGROUND) diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index b4db7d32..04379c4f 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -53,8 +53,6 @@ refimport_t ri; static unsigned d_8to24table[256]; -entity_t r_worldentity; - char skyname[MAX_QPATH]; vec3_t skyaxis; @@ -1163,7 +1161,7 @@ Render the map ================ */ static void -R_EdgeDrawing (void) +R_EdgeDrawing (entity_t *currententity) { if ( r_newrefdef.rdflags & RDF_NOWORLDMODEL ) return; @@ -1181,7 +1179,7 @@ R_EdgeDrawing (void) // Build the Global Edget Table // Also populate the surface stack and count # surfaces to render (surf_max is the max) - R_RenderWorld (); + R_RenderWorld (currententity); if (r_dspeeds->value) { @@ -1199,7 +1197,7 @@ R_EdgeDrawing (void) // Use the Global Edge Table to maintin the Active Edge Table: Draw the world as scanlines // Write the Z-Buffer (but no read) - R_ScanEdges (surface_p); + R_ScanEdges (currententity, surface_p); } //======================================================================= @@ -1300,6 +1298,7 @@ static void RE_RenderFrame (refdef_t *fd) { r_newrefdef = *fd; + entity_t r_worldentity; if (!r_worldmodel && !( r_newrefdef.rdflags & RDF_NOWORLDMODEL ) ) { @@ -1342,7 +1341,7 @@ RE_RenderFrame (refdef_t *fd) // Build the Global Edge Table and render it via the Active Edge Table // Render the map - R_EdgeDrawing (); + R_EdgeDrawing (&r_worldentity); if (r_dspeeds->value) { diff --git a/src/client/refresh/soft/sw_model.c b/src/client/refresh/soft/sw_model.c index 869f764c..ac9bc2d4 100644 --- a/src/client/refresh/soft/sw_model.c +++ b/src/client/refresh/soft/sw_model.c @@ -230,7 +230,7 @@ Mod_PointInLeaf =============== */ mleaf_t * -Mod_PointInLeaf (vec3_t p, model_t *model) +Mod_PointInLeaf (vec3_t p, const model_t *model) { mnode_t *node; From e3a83c6b32943b5968f5117f9a8768718ff63e3d Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 19 Sep 2021 21:45:49 +0300 Subject: [PATCH 10/22] add const to Mod_ClusterPVS --- src/client/refresh/files/pvs.c | 4 ++-- src/client/refresh/gl1/gl1_model.c | 4 ++-- src/client/refresh/gl1/gl1_surf.c | 2 +- src/client/refresh/gl1/header/model.h | 2 +- src/client/refresh/gl3/gl3_model.c | 4 ++-- src/client/refresh/gl3/gl3_surf.c | 2 +- src/client/refresh/gl3/header/local.h | 2 +- src/client/refresh/ref_shared.h | 2 +- src/client/refresh/soft/header/model.h | 4 ++-- src/client/refresh/soft/sw_main.c | 2 +- src/client/refresh/soft/sw_model.c | 4 ++-- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/client/refresh/files/pvs.c b/src/client/refresh/files/pvs.c index f8748d20..75409104 100644 --- a/src/client/refresh/files/pvs.c +++ b/src/client/refresh/files/pvs.c @@ -32,8 +32,8 @@ Mod_DecompressVis =================== */ -byte * -Mod_DecompressVis(byte *in, int row) +const byte * +Mod_DecompressVis(const byte *in, int row) { YQ2_ALIGNAS_TYPE(int) static byte decompressed[MAX_MAP_LEAFS / 8]; int c; diff --git a/src/client/refresh/gl1/gl1_model.c b/src/client/refresh/gl1/gl1_model.c index 38b666e7..135073cd 100644 --- a/src/client/refresh/gl1/gl1_model.c +++ b/src/client/refresh/gl1/gl1_model.c @@ -79,8 +79,8 @@ Mod_PointInLeaf(vec3_t p, model_t *model) return NULL; /* never reached */ } -byte * -Mod_ClusterPVS(int cluster, model_t *model) +const byte * +Mod_ClusterPVS(int cluster, const model_t *model) { if ((cluster == -1) || !model->vis) { diff --git a/src/client/refresh/gl1/gl1_surf.c b/src/client/refresh/gl1/gl1_surf.c index 7acd6aac..541693f3 100644 --- a/src/client/refresh/gl1/gl1_surf.c +++ b/src/client/refresh/gl1/gl1_surf.c @@ -966,7 +966,7 @@ R_DrawWorld(void) void R_MarkLeaves(void) { - byte *vis; + const byte *vis; YQ2_ALIGNAS_TYPE(int) byte fatvis[MAX_MAP_LEAFS / 8]; mnode_t *node; int i, c; diff --git a/src/client/refresh/gl1/header/model.h b/src/client/refresh/gl1/header/model.h index 0c8be2b2..22c245d7 100644 --- a/src/client/refresh/gl1/header/model.h +++ b/src/client/refresh/gl1/header/model.h @@ -219,7 +219,7 @@ typedef struct model_s void Mod_Init(void); void Mod_ClearAll(void); mleaf_t *Mod_PointInLeaf(vec3_t p, model_t *model); -byte *Mod_ClusterPVS(int cluster, model_t *model); +const byte *Mod_ClusterPVS(int cluster, const model_t *model); void Mod_Modellist_f(void); diff --git a/src/client/refresh/gl3/gl3_model.c b/src/client/refresh/gl3/gl3_model.c index dad93465..88fe3df4 100644 --- a/src/client/refresh/gl3/gl3_model.c +++ b/src/client/refresh/gl3/gl3_model.c @@ -76,8 +76,8 @@ GL3_Mod_PointInLeaf(vec3_t p, gl3model_t *model) return NULL; /* never reached */ } -byte* -GL3_Mod_ClusterPVS(int cluster, gl3model_t *model) +const byte* +GL3_Mod_ClusterPVS(int cluster, const gl3model_t *model) { if ((cluster == -1) || !model->vis) { diff --git a/src/client/refresh/gl3/gl3_surf.c b/src/client/refresh/gl3/gl3_surf.c index a9351c71..e3ae6d38 100644 --- a/src/client/refresh/gl3/gl3_surf.c +++ b/src/client/refresh/gl3/gl3_surf.c @@ -851,7 +851,7 @@ GL3_DrawWorld(void) void GL3_MarkLeaves(void) { - byte *vis; + const byte *vis; YQ2_ALIGNAS_TYPE(int) byte fatvis[MAX_MAP_LEAFS / 8]; mnode_t *node; int i, c; diff --git a/src/client/refresh/gl3/header/local.h b/src/client/refresh/gl3/header/local.h index 5ae4200a..cea68108 100644 --- a/src/client/refresh/gl3/header/local.h +++ b/src/client/refresh/gl3/header/local.h @@ -381,7 +381,7 @@ extern void GL3_BeginRegistration(char *model); extern struct model_s * GL3_RegisterModel(char *name); extern void GL3_EndRegistration(void); extern void GL3_Mod_Modellist_f(void); -extern byte* GL3_Mod_ClusterPVS(int cluster, gl3model_t *model); +extern const byte* GL3_Mod_ClusterPVS(int cluster, const gl3model_t *model); extern mleaf_t* GL3_Mod_PointInLeaf(vec3_t p, gl3model_t *model); // gl3_draw.c diff --git a/src/client/refresh/ref_shared.h b/src/client/refresh/ref_shared.h index b1b232e5..194b13c1 100644 --- a/src/client/refresh/ref_shared.h +++ b/src/client/refresh/ref_shared.h @@ -74,5 +74,5 @@ extern void GetWalInfo(char *name, int *width, int *height); extern void GetM8Info(char *name, int *width, int *height); extern float Mod_RadiusFromBounds(const vec3_t mins, const vec3_t maxs); -extern byte* Mod_DecompressVis(byte *in, int row); +extern const byte* Mod_DecompressVis(const byte *in, int row); #endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */ diff --git a/src/client/refresh/soft/header/model.h b/src/client/refresh/soft/header/model.h index 4beebe95..4bb58fcc 100644 --- a/src/client/refresh/soft/header/model.h +++ b/src/client/refresh/soft/header/model.h @@ -222,8 +222,8 @@ typedef struct model_s void Mod_Init(void); -mleaf_t *Mod_PointInLeaf(vec3_t p, model_t *model); -byte *Mod_ClusterPVS(int cluster, model_t *model); +mleaf_t *Mod_PointInLeaf(vec3_t p, const model_t *model); +const byte *Mod_ClusterPVS(int cluster, const model_t *model); void Mod_Modellist_f(void); void Mod_FreeAll(void); diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index 04379c4f..e7c98a12 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -742,7 +742,7 @@ cluster static void R_MarkLeaves (void) { - byte *vis; + const byte *vis; mnode_t *node; int i; mleaf_t *leaf; diff --git a/src/client/refresh/soft/sw_model.c b/src/client/refresh/soft/sw_model.c index ac9bc2d4..83e8acf0 100644 --- a/src/client/refresh/soft/sw_model.c +++ b/src/client/refresh/soft/sw_model.c @@ -263,8 +263,8 @@ Mod_PointInLeaf (vec3_t p, const model_t *model) Mod_ClusterPVS ============== */ -byte * -Mod_ClusterPVS (int cluster, model_t *model) +const byte * +Mod_ClusterPVS (int cluster, const model_t *model) { if (cluster == -1 || !model->vis) return mod_novis; From 330830fc380d089a479c245075247641a099bcc1 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Mon, 20 Sep 2021 11:22:08 +0300 Subject: [PATCH 11/22] gl1: preserve cache on free slots in image and models list(aa6032f0) --- src/client/refresh/gl1/gl1_image.c | 48 +++++++++++++++++++-- src/client/refresh/gl1/gl1_model.c | 60 ++++++++++++++++++++++++--- src/client/refresh/gl1/header/local.h | 1 + src/client/refresh/soft/sw_image.c | 1 + 4 files changed, 101 insertions(+), 9 deletions(-) diff --git a/src/client/refresh/gl1/gl1_image.c b/src/client/refresh/gl1/gl1_image.c index 63f1eed2..17bffcb5 100644 --- a/src/client/refresh/gl1/gl1_image.c +++ b/src/client/refresh/gl1/gl1_image.c @@ -28,6 +28,7 @@ image_t gltextures[MAX_GLTEXTURES]; int numgltextures; +static int image_max = 0; int base_textureid; /* gltextures[i] = base_textureid+i */ extern qboolean scrap_dirty; extern byte scrap_texels[MAX_SCRAPS][BLOCK_WIDTH * BLOCK_HEIGHT]; @@ -292,9 +293,9 @@ R_TextureSolidMode(char *string) void R_ImageList_f(void) { - int i; + int i, used, texels; image_t *image; - int texels; + qboolean freeup; const char *palstrings[2] = { "RGB", "PAL" @@ -302,14 +303,23 @@ R_ImageList_f(void) R_Printf(PRINT_ALL, "------------------\n"); texels = 0; + used = 0; for (i = 0, image = gltextures; i < numgltextures; i++, image++) { + char *in_use = ""; + if (image->texnum <= 0) { continue; } + if (image->registration_sequence == registration_sequence) + { + in_use = "*"; + used++; + } + texels += image->upload_width * image->upload_height; switch (image->type) @@ -331,14 +341,16 @@ R_ImageList_f(void) break; } - R_Printf(PRINT_ALL, " %3i %3i %s: %s\n", + R_Printf(PRINT_ALL, " %3i %3i %s: %s %s\n", image->upload_width, image->upload_height, - palstrings[image->paletted], image->name); + palstrings[image->paletted], image->name, in_use); } R_Printf(PRINT_ALL, "Total texel count (not counting mipmaps): %i\n", texels); + freeup = R_ImageHasFreeSpace(); + R_Printf(PRINT_ALL, "Used %d of %d images%s.\n", used, image_max, freeup ? ", has free space" : ""); } /* @@ -1367,12 +1379,40 @@ R_FreeUnusedImages(void) } } +qboolean +R_ImageHasFreeSpace(void) +{ + int i, used; + image_t *image; + + used = 0; + + for (i = 0, image = gltextures; i < numgltextures; i++, image++) + { + if (!image->name[0]) + continue; + if (image->registration_sequence == registration_sequence) + { + used ++; + } + } + + if (image_max < used) + { + image_max = used; + } + + // should same size of free slots as currently used + return (numgltextures + used) < MAX_GLTEXTURES; +} + void R_InitImages(void) { int i, j; registration_sequence = 1; + image_max = 0; /* init intensity conversions */ intensity = ri.Cvar_Get("gl1_intensity", "2", CVAR_ARCHIVE); diff --git a/src/client/refresh/gl1/gl1_model.c b/src/client/refresh/gl1/gl1_model.c index 135073cd..a1f4c3e7 100644 --- a/src/client/refresh/gl1/gl1_model.c +++ b/src/client/refresh/gl1/gl1_model.c @@ -30,8 +30,9 @@ int modfilelen; YQ2_ALIGNAS_TYPE(int) byte mod_novis[MAX_MAP_LEAFS / 8]; -model_t mod_known[MAX_MOD_KNOWN]; -int mod_numknown; +static model_t mod_known[MAX_MOD_KNOWN]; +static int mod_numknown; +static int mod_max = 0; int registration_sequence; void LoadSP2(model_t *mod, void *buffer, int modfilelen); @@ -42,6 +43,35 @@ void LM_CreateSurfaceLightmap(msurface_t *surf); void LM_EndBuildingLightmaps(void); void LM_BeginBuildingLightmaps(model_t *m); +//=============================================================================== + +static qboolean +Mod_HasFreeSpace(void) +{ + int i, used; + model_t *mod; + + used = 0; + + for (i=0, mod=mod_known ; i < mod_numknown ; i++, mod++) + { + if (!mod->name[0]) + continue; + if (mod->registration_sequence == registration_sequence) + { + used ++; + } + } + + if (mod_max < used) + { + mod_max = used; + } + + // should same size of free slots as currently used + return (mod_numknown + mod_max) < MAX_MOD_KNOWN; +} + mleaf_t * Mod_PointInLeaf(vec3_t p, model_t *model) { @@ -95,30 +125,44 @@ Mod_ClusterPVS(int cluster, const model_t *model) void Mod_Modellist_f(void) { - int i; + int i, total, used; model_t *mod; - int total; + qboolean freeup; total = 0; + used = 0; R_Printf(PRINT_ALL, "Loaded models:\n"); for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++) { + char *in_use = ""; + + if (mod->registration_sequence == registration_sequence) + { + in_use = "*"; + used ++; + } + if (!mod->name[0]) { continue; } - R_Printf(PRINT_ALL, "%8i : %s\n", mod->extradatasize, mod->name); + R_Printf(PRINT_ALL, "%8i : %s %s\n", + mod->extradatasize, mod->name, in_use); total += mod->extradatasize; } R_Printf(PRINT_ALL, "Total resident: %i\n", total); + // update statistics + freeup = Mod_HasFreeSpace(); + R_Printf(PRINT_ALL, "Used %d of %d models%s.\n", used, mod_max, freeup ? ", has free space" : ""); } void Mod_Init(void) { + mod_max = 0; memset(mod_novis, 0xff, sizeof(mod_novis)); } @@ -1116,6 +1160,12 @@ RI_EndRegistration(void) int i; model_t *mod; + if (Mod_HasFreeSpace() && R_ImageHasFreeSpace()) + { + // should be enough space for load next maps + return; + } + for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++) { if (!mod->name[0]) diff --git a/src/client/refresh/gl1/header/local.h b/src/client/refresh/gl1/header/local.h index 3ed11750..f0257eca 100644 --- a/src/client/refresh/gl1/header/local.h +++ b/src/client/refresh/gl1/header/local.h @@ -291,6 +291,7 @@ void R_InitImages(void); void R_ShutdownImages(void); void R_FreeUnusedImages(void); +qboolean R_ImageHasFreeSpace(void); void R_TextureAlphaMode(char *string); void R_TextureSolidMode(char *string); diff --git a/src/client/refresh/soft/sw_image.c b/src/client/refresh/soft/sw_image.c index 7d7eecc6..80fbf45e 100644 --- a/src/client/refresh/soft/sw_image.c +++ b/src/client/refresh/soft/sw_image.c @@ -810,6 +810,7 @@ R_InitImages (void) { unsigned char * table16to8; registration_sequence = 1; + image_max = 0; d_16to8table = NULL; ri.FS_LoadFile("pics/16to8.dat", (void **)&table16to8); From 423c3fa2990dc620f9d278ab980cf41153b318c7 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Mon, 20 Sep 2021 11:50:44 +0300 Subject: [PATCH 12/22] gl3: preserve cache on free slots in image and models list(aa6032f0) --- src/client/refresh/gl3/gl3_image.c | 49 +++++++++++++++++++++-- src/client/refresh/gl3/gl3_model.c | 56 +++++++++++++++++++++++++-- src/client/refresh/gl3/header/local.h | 1 + 3 files changed, 99 insertions(+), 7 deletions(-) diff --git a/src/client/refresh/gl3/gl3_image.c b/src/client/refresh/gl3/gl3_image.c index bd6c52cc..c9ff9364 100644 --- a/src/client/refresh/gl3/gl3_image.c +++ b/src/client/refresh/gl3/gl3_image.c @@ -46,7 +46,8 @@ int gl_filter_min = GL_LINEAR_MIPMAP_NEAREST; int gl_filter_max = GL_LINEAR; gl3image_t gl3textures[MAX_GL3TEXTURES]; -int numgl3textures; +int numgl3textures = 0; +static int image_max = 0; void GL3_TextureMode(char *string) @@ -948,6 +949,33 @@ GL3_FreeUnusedImages(void) } } +qboolean +GL3_ImageHasFreeSpace(void) +{ + int i, used; + gl3image_t *image; + + used = 0; + + for (i = 0, image = gl3textures; i < numgl3textures; i++, image++) + { + if (!image->name[0]) + continue; + if (image->registration_sequence == registration_sequence) + { + used ++; + } + } + + if (image_max < used) + { + image_max = used; + } + + // should same size of free slots as currently used + return (numgl3textures + used) < MAX_GL3TEXTURES; +} + void GL3_ShutdownImages(void) { @@ -986,7 +1014,8 @@ static qboolean IsNPOT(int v) void GL3_ImageList_f(void) { - int i, texels=0; + int i, used, texels; + qboolean freeup; gl3image_t *image; const char *formatstrings[2] = { "RGB ", @@ -998,15 +1027,25 @@ GL3_ImageList_f(void) }; R_Printf(PRINT_ALL, "------------------\n"); + texels = 0; + used = 0; for (i = 0, image = gl3textures; i < numgl3textures; i++, image++) { int w, h; + char *in_use = ""; qboolean isNPOT = false; if (image->texnum == 0) { continue; } + + if (image->registration_sequence == registration_sequence) + { + in_use = "*"; + used++; + } + w = image->width; h = image->height; @@ -1036,9 +1075,11 @@ GL3_ImageList_f(void) break; } - R_Printf(PRINT_ALL, " %3i %3i %s %s: %s\n", w, h, - formatstrings[image->has_alpha], potstrings[isNPOT], image->name); + R_Printf(PRINT_ALL, " %3i %3i %s %s: %s %s\n", w, h, + formatstrings[image->has_alpha], potstrings[isNPOT], image->name, in_use); } R_Printf(PRINT_ALL, "Total texel count (not counting mipmaps): %i\n", texels); + freeup = GL3_ImageHasFreeSpace(); + R_Printf(PRINT_ALL, "Used %d of %d images%s.\n", used, image_max, freeup ? ", has free space" : ""); } diff --git a/src/client/refresh/gl3/gl3_model.c b/src/client/refresh/gl3/gl3_model.c index 88fe3df4..0ae51e25 100644 --- a/src/client/refresh/gl3/gl3_model.c +++ b/src/client/refresh/gl3/gl3_model.c @@ -33,12 +33,42 @@ static gl3model_t *loadmodel; YQ2_ALIGNAS_TYPE(int) static byte mod_novis[MAX_MAP_LEAFS / 8]; gl3model_t mod_known[MAX_MOD_KNOWN]; static int mod_numknown; +static int mod_max = 0; int registration_sequence; static byte *mod_base; /* the inline * models from the current map are kept seperate */ gl3model_t mod_inline[MAX_MOD_KNOWN]; +//=============================================================================== + +static qboolean +Mod_HasFreeSpace(void) +{ + int i, used; + gl3model_t *mod; + + used = 0; + + for (i=0, mod=mod_known ; i < mod_numknown ; i++, mod++) + { + if (!mod->name[0]) + continue; + if (mod->registration_sequence == registration_sequence) + { + used ++; + } + } + + if (mod_max < used) + { + mod_max = used; + } + + // should same size of free slots as currently used + return (mod_numknown + mod_max) < MAX_MOD_KNOWN; +} + mleaf_t * GL3_Mod_PointInLeaf(vec3_t p, gl3model_t *model) { @@ -92,30 +122,44 @@ GL3_Mod_ClusterPVS(int cluster, const gl3model_t *model) void GL3_Mod_Modellist_f(void) { - int i; + int i, total, used; gl3model_t *mod; - int total; + qboolean freeup; total = 0; + used = 0; R_Printf(PRINT_ALL, "Loaded models:\n"); for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++) { + char *in_use = ""; + + if (mod->registration_sequence == registration_sequence) + { + in_use = "*"; + used ++; + } + if (!mod->name[0]) { continue; } - R_Printf(PRINT_ALL, "%8i : %s\n", mod->extradatasize, mod->name); + R_Printf(PRINT_ALL, "%8i : %s %s\n", + mod->extradatasize, mod->name, in_use); total += mod->extradatasize; } R_Printf(PRINT_ALL, "Total resident: %i\n", total); + // update statistics + freeup = Mod_HasFreeSpace(); + R_Printf(PRINT_ALL, "Used %d of %d models%s.\n", used, mod_max, freeup ? ", has free space" : ""); } void GL3_Mod_Init(void) { + mod_max = 0; memset(mod_novis, 0xff, sizeof(mod_novis)); } @@ -1133,6 +1177,12 @@ GL3_EndRegistration(void) int i; gl3model_t *mod; + if (Mod_HasFreeSpace() && GL3_ImageHasFreeSpace()) + { + // should be enough space for load next maps + return; + } + for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++) { if (!mod->name[0]) diff --git a/src/client/refresh/gl3/header/local.h b/src/client/refresh/gl3/header/local.h index cea68108..1b9a77b8 100644 --- a/src/client/refresh/gl3/header/local.h +++ b/src/client/refresh/gl3/header/local.h @@ -421,6 +421,7 @@ extern gl3image_t *GL3_FindImage(char *name, imagetype_t type); extern gl3image_t *GL3_RegisterSkin(char *name); extern void GL3_ShutdownImages(void); extern void GL3_FreeUnusedImages(void); +extern qboolean GL3_ImageHasFreeSpace(void); extern void GL3_ImageList_f(void); // gl3_light.c From 84773d7d79ce1f1b6d3b2bc5ed633afb122a9c3e Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Mon, 20 Sep 2021 12:19:01 +0300 Subject: [PATCH 13/22] gl3: use local model on load(35d598bc) --- src/client/refresh/gl3/gl3_model.c | 73 ++++++++++++++---------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/src/client/refresh/gl3/gl3_model.c b/src/client/refresh/gl3/gl3_model.c index 0ae51e25..dada5f33 100644 --- a/src/client/refresh/gl3/gl3_model.c +++ b/src/client/refresh/gl3/gl3_model.c @@ -29,13 +29,11 @@ enum { MAX_MOD_KNOWN = 512 }; -static gl3model_t *loadmodel; YQ2_ALIGNAS_TYPE(int) static byte mod_novis[MAX_MAP_LEAFS / 8]; gl3model_t mod_known[MAX_MOD_KNOWN]; static int mod_numknown; static int mod_max = 0; int registration_sequence; -static byte *mod_base; /* the inline * models from the current map are kept seperate */ gl3model_t mod_inline[MAX_MOD_KNOWN]; @@ -164,7 +162,7 @@ GL3_Mod_Init(void) } static void -Mod_LoadLighting(lump_t *l) +Mod_LoadLighting(gl3model_t *loadmodel, byte *mod_base, lump_t *l) { if (!l->filelen) { @@ -177,7 +175,7 @@ Mod_LoadLighting(lump_t *l) } static void -Mod_LoadVisibility(lump_t *l) +Mod_LoadVisibility(gl3model_t *loadmodel, byte *mod_base, lump_t *l) { int i; @@ -200,7 +198,7 @@ Mod_LoadVisibility(lump_t *l) } static void -Mod_LoadVertexes(lump_t *l) +Mod_LoadVertexes(gl3model_t *loadmodel, byte *mod_base, lump_t *l) { dvertex_t *in; mvertex_t *out; @@ -229,7 +227,7 @@ Mod_LoadVertexes(lump_t *l) } static void -Mod_LoadSubmodels(lump_t *l) +Mod_LoadSubmodels(gl3model_t *loadmodel, byte *mod_base, lump_t *l) { dmodel_t *in; mmodel_t *out; @@ -267,7 +265,7 @@ Mod_LoadSubmodels(lump_t *l) } static void -Mod_LoadEdges(lump_t *l) +Mod_LoadEdges(gl3model_t *loadmodel, byte *mod_base, lump_t *l) { dedge_t *in; medge_t *out; @@ -295,7 +293,7 @@ Mod_LoadEdges(lump_t *l) } static void -Mod_LoadTexinfo(lump_t *l) +Mod_LoadTexinfo(gl3model_t *loadmodel, byte *mod_base, lump_t *l) { texinfo_t *in; mtexinfo_t *out, *step; @@ -371,7 +369,7 @@ Mod_LoadTexinfo(lump_t *l) * Fills in s->texturemins[] and s->extents[] */ static void -Mod_CalcSurfaceExtents(msurface_t *s) +Mod_CalcSurfaceExtents(gl3model_t *loadmodel, msurface_t *s) { float mins[2], maxs[2], val; int i, j, e; @@ -429,7 +427,7 @@ Mod_CalcSurfaceExtents(msurface_t *s) extern void GL3_SubdivideSurface(msurface_t *fa, gl3model_t* loadmodel); -static int calcTexinfoAndFacesSize(const lump_t *fl, const lump_t *tl) +static int calcTexinfoAndFacesSize(byte *mod_base, const lump_t *fl, const lump_t *tl) { dface_t* face_in = (void *)(mod_base + fl->fileofs); texinfo_t* texinfo_in = (void *)(mod_base + tl->fileofs); @@ -505,7 +503,7 @@ static int calcTexinfoAndFacesSize(const lump_t *fl, const lump_t *tl) } static void -Mod_LoadFaces(lump_t *l) +Mod_LoadFaces(gl3model_t *loadmodel, byte *mod_base, lump_t *l) { dface_t *in; msurface_t *out; @@ -558,7 +556,7 @@ Mod_LoadFaces(lump_t *l) out->texinfo = loadmodel->texinfo + ti; - Mod_CalcSurfaceExtents(out); + Mod_CalcSurfaceExtents(loadmodel, out); /* lighting info */ for (i = 0; i < MAX_LIGHTMAPS_PER_SURFACE; i++) @@ -629,7 +627,7 @@ Mod_SetParent(mnode_t *node, mnode_t *parent) } static void -Mod_LoadNodes(lump_t *l) +Mod_LoadNodes(gl3model_t *loadmodel, byte *mod_base, lump_t *l) { int i, j, count, p; dnode_t *in; @@ -683,7 +681,7 @@ Mod_LoadNodes(lump_t *l) } static void -Mod_LoadLeafs(lump_t *l) +Mod_LoadLeafs(gl3model_t *loadmodel, byte *mod_base, lump_t *l) { dleaf_t *in; mleaf_t *out; @@ -733,7 +731,7 @@ Mod_LoadLeafs(lump_t *l) } static void -Mod_LoadMarksurfaces(lump_t *l) +Mod_LoadMarksurfaces(gl3model_t *loadmodel, byte *mod_base, lump_t *l) { int i, j, count; short *in; @@ -767,7 +765,7 @@ Mod_LoadMarksurfaces(lump_t *l) } static void -Mod_LoadSurfedges(lump_t *l) +Mod_LoadSurfedges(gl3model_t *loadmodel, byte *mod_base, lump_t *l) { int i, count; int *in, *out; @@ -800,7 +798,7 @@ Mod_LoadSurfedges(lump_t *l) } static void -Mod_LoadPlanes(lump_t *l) +Mod_LoadPlanes(gl3model_t *loadmodel, byte *mod_base, lump_t *l) { int i, j; cplane_t *out; @@ -863,11 +861,12 @@ static int calcLumpHunkSize(const lump_t *l, int inSize, int outSize) } static void -Mod_LoadBrushModel(gl3model_t *mod, void *buffer, int modfilelen) +Mod_LoadBrushModel(gl3model_t *loadmodel, void *buffer, int modfilelen) { int i; dheader_t *header; mmodel_t *bm; + byte *mod_base; if (loadmodel != mod_known) { @@ -881,7 +880,7 @@ Mod_LoadBrushModel(gl3model_t *mod, void *buffer, int modfilelen) if (i != BSPVERSION) { ri.Sys_Error(ERR_DROP, "%s: %s has wrong version number (%i should be %i)", - __func__, mod->name, i, BSPVERSION); + __func__, loadmodel->name, i, BSPVERSION); } /* swap all the lumps */ @@ -902,7 +901,7 @@ Mod_LoadBrushModel(gl3model_t *mod, void *buffer, int modfilelen) hunkSize += calcLumpHunkSize(&header->lumps[LUMP_SURFEDGES], sizeof(int), sizeof(int)); hunkSize += calcLumpHunkSize(&header->lumps[LUMP_LIGHTING], 1, 1); hunkSize += calcLumpHunkSize(&header->lumps[LUMP_PLANES], sizeof(dplane_t), sizeof(cplane_t)*2); - hunkSize += calcTexinfoAndFacesSize(&header->lumps[LUMP_FACES], &header->lumps[LUMP_TEXINFO]); + hunkSize += calcTexinfoAndFacesSize(mod_base, &header->lumps[LUMP_FACES], &header->lumps[LUMP_TEXINFO]); hunkSize += calcLumpHunkSize(&header->lumps[LUMP_LEAFFACES], sizeof(short), sizeof(msurface_t *)); // yes, out is indeeed a pointer! hunkSize += calcLumpHunkSize(&header->lumps[LUMP_VISIBILITY], 1, 1); hunkSize += calcLumpHunkSize(&header->lumps[LUMP_LEAFS], sizeof(dleaf_t), sizeof(mleaf_t)); @@ -913,26 +912,26 @@ Mod_LoadBrushModel(gl3model_t *mod, void *buffer, int modfilelen) loadmodel->type = mod_brush; /* load into heap */ - Mod_LoadVertexes(&header->lumps[LUMP_VERTEXES]); - Mod_LoadEdges(&header->lumps[LUMP_EDGES]); - Mod_LoadSurfedges(&header->lumps[LUMP_SURFEDGES]); - Mod_LoadLighting(&header->lumps[LUMP_LIGHTING]); - Mod_LoadPlanes(&header->lumps[LUMP_PLANES]); - Mod_LoadTexinfo(&header->lumps[LUMP_TEXINFO]); - Mod_LoadFaces(&header->lumps[LUMP_FACES]); - Mod_LoadMarksurfaces(&header->lumps[LUMP_LEAFFACES]); - Mod_LoadVisibility(&header->lumps[LUMP_VISIBILITY]); - Mod_LoadLeafs(&header->lumps[LUMP_LEAFS]); - Mod_LoadNodes(&header->lumps[LUMP_NODES]); - Mod_LoadSubmodels(&header->lumps[LUMP_MODELS]); - mod->numframes = 2; /* regular and alternate animation */ + Mod_LoadVertexes(loadmodel, mod_base, &header->lumps[LUMP_VERTEXES]); + Mod_LoadEdges(loadmodel, mod_base, &header->lumps[LUMP_EDGES]); + Mod_LoadSurfedges(loadmodel, mod_base, &header->lumps[LUMP_SURFEDGES]); + Mod_LoadLighting(loadmodel, mod_base, &header->lumps[LUMP_LIGHTING]); + Mod_LoadPlanes(loadmodel, mod_base, &header->lumps[LUMP_PLANES]); + Mod_LoadTexinfo(loadmodel, mod_base, &header->lumps[LUMP_TEXINFO]); + Mod_LoadFaces(loadmodel, mod_base, &header->lumps[LUMP_FACES]); + Mod_LoadMarksurfaces(loadmodel, mod_base, &header->lumps[LUMP_LEAFFACES]); + Mod_LoadVisibility(loadmodel, mod_base, &header->lumps[LUMP_VISIBILITY]); + Mod_LoadLeafs(loadmodel, mod_base, &header->lumps[LUMP_LEAFS]); + Mod_LoadNodes(loadmodel, mod_base, &header->lumps[LUMP_NODES]); + Mod_LoadSubmodels(loadmodel, mod_base, &header->lumps[LUMP_MODELS]); + loadmodel->numframes = 2; /* regular and alternate animation */ /* set up the submodels */ - for (i = 0; i < mod->numsubmodels; i++) + for (i = 0; i < loadmodel->numsubmodels; i++) { gl3model_t *starmod; - bm = &mod->submodels[i]; + bm = &loadmodel->submodels[i]; starmod = &mod_inline[i]; *starmod = *loadmodel; @@ -1063,8 +1062,6 @@ Mod_ForName(char *name, qboolean crash) return NULL; } - loadmodel = mod; - /* call the apropriate loader */ switch (LittleLong(*(unsigned *)buf)) { @@ -1086,7 +1083,7 @@ Mod_ForName(char *name, qboolean crash) break; } - loadmodel->extradatasize = Hunk_End(); + mod->extradatasize = Hunk_End(); ri.FS_FreeFile(buf); From 93ab5896e987881f35265d6180924dd68ae490e8 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Mon, 20 Sep 2021 12:41:06 +0300 Subject: [PATCH 14/22] gl3: port submodel load code from vk render(8bd39ad5) --- src/client/refresh/gl3/gl3_model.c | 113 +++++++++++--------------- src/client/refresh/gl3/header/model.h | 5 +- 2 files changed, 53 insertions(+), 65 deletions(-) diff --git a/src/client/refresh/gl3/gl3_model.c b/src/client/refresh/gl3/gl3_model.c index dada5f33..7e332ec7 100644 --- a/src/client/refresh/gl3/gl3_model.c +++ b/src/client/refresh/gl3/gl3_model.c @@ -35,9 +35,6 @@ static int mod_numknown; static int mod_max = 0; int registration_sequence; -/* the inline * models from the current map are kept seperate */ -gl3model_t mod_inline[MAX_MOD_KNOWN]; - //=============================================================================== static qboolean @@ -230,7 +227,7 @@ static void Mod_LoadSubmodels(gl3model_t *loadmodel, byte *mod_base, lump_t *l) { dmodel_t *in; - mmodel_t *out; + gl3model_t *out; int i, j, count; in = (void *)(mod_base + l->fileofs); @@ -249,6 +246,19 @@ Mod_LoadSubmodels(gl3model_t *loadmodel, byte *mod_base, lump_t *l) for (i = 0; i < count; i++, in++, out++) { + if (i == 0) + { + // copy parent as template for first model + memcpy(out, loadmodel, sizeof(*out)); + } + else + { + // copy first as template for model + memcpy(out, loadmodel->submodels, sizeof(*out)); + } + + Com_sprintf (out->name, sizeof(out->name), "*%d", i); + for (j = 0; j < 3; j++) { /* spread the mins / maxs by a pixel */ @@ -258,9 +268,17 @@ Mod_LoadSubmodels(gl3model_t *loadmodel, byte *mod_base, lump_t *l) } out->radius = Mod_RadiusFromBounds(out->mins, out->maxs); - out->headnode = LittleLong(in->headnode); - out->firstface = LittleLong(in->firstface); - out->numfaces = LittleLong(in->numfaces); + out->firstnode = LittleLong(in->headnode); + out->firstmodelsurface = LittleLong(in->firstface); + out->nummodelsurfaces = LittleLong(in->numfaces); + // visleafs + out->numleafs = 0; + // check limits + if (out->firstnode >= loadmodel->numnodes) + { + ri.Sys_Error(ERR_DROP, "%s: Inline model %i has bad firstnode", + __func__, i); + } } } @@ -861,14 +879,13 @@ static int calcLumpHunkSize(const lump_t *l, int inSize, int outSize) } static void -Mod_LoadBrushModel(gl3model_t *loadmodel, void *buffer, int modfilelen) +Mod_LoadBrushModel(gl3model_t *mod, void *buffer, int modfilelen) { int i; dheader_t *header; - mmodel_t *bm; byte *mod_base; - if (loadmodel != mod_known) + if (mod != mod_known) { ri.Sys_Error(ERR_DROP, "Loaded a brush model after the world"); } @@ -880,7 +897,7 @@ Mod_LoadBrushModel(gl3model_t *loadmodel, void *buffer, int modfilelen) if (i != BSPVERSION) { ri.Sys_Error(ERR_DROP, "%s: %s has wrong version number (%i should be %i)", - __func__, loadmodel->name, i, BSPVERSION); + __func__, mod->name, i, BSPVERSION); } /* swap all the lumps */ @@ -908,55 +925,23 @@ Mod_LoadBrushModel(gl3model_t *loadmodel, void *buffer, int modfilelen) hunkSize += calcLumpHunkSize(&header->lumps[LUMP_NODES], sizeof(dnode_t), sizeof(mnode_t)); hunkSize += calcLumpHunkSize(&header->lumps[LUMP_MODELS], sizeof(dmodel_t), sizeof(mmodel_t)); - loadmodel->extradata = Hunk_Begin(hunkSize); - loadmodel->type = mod_brush; + mod->extradata = Hunk_Begin(hunkSize); + mod->type = mod_brush; /* load into heap */ - Mod_LoadVertexes(loadmodel, mod_base, &header->lumps[LUMP_VERTEXES]); - Mod_LoadEdges(loadmodel, mod_base, &header->lumps[LUMP_EDGES]); - Mod_LoadSurfedges(loadmodel, mod_base, &header->lumps[LUMP_SURFEDGES]); - Mod_LoadLighting(loadmodel, mod_base, &header->lumps[LUMP_LIGHTING]); - Mod_LoadPlanes(loadmodel, mod_base, &header->lumps[LUMP_PLANES]); - Mod_LoadTexinfo(loadmodel, mod_base, &header->lumps[LUMP_TEXINFO]); - Mod_LoadFaces(loadmodel, mod_base, &header->lumps[LUMP_FACES]); - Mod_LoadMarksurfaces(loadmodel, mod_base, &header->lumps[LUMP_LEAFFACES]); - Mod_LoadVisibility(loadmodel, mod_base, &header->lumps[LUMP_VISIBILITY]); - Mod_LoadLeafs(loadmodel, mod_base, &header->lumps[LUMP_LEAFS]); - Mod_LoadNodes(loadmodel, mod_base, &header->lumps[LUMP_NODES]); - Mod_LoadSubmodels(loadmodel, mod_base, &header->lumps[LUMP_MODELS]); - loadmodel->numframes = 2; /* regular and alternate animation */ - - /* set up the submodels */ - for (i = 0; i < loadmodel->numsubmodels; i++) - { - gl3model_t *starmod; - - bm = &loadmodel->submodels[i]; - starmod = &mod_inline[i]; - - *starmod = *loadmodel; - - starmod->firstmodelsurface = bm->firstface; - starmod->nummodelsurfaces = bm->numfaces; - starmod->firstnode = bm->headnode; - - if (starmod->firstnode >= loadmodel->numnodes) - { - ri.Sys_Error(ERR_DROP, "%s: Inline model %i has bad firstnode", - __func__, i); - } - - VectorCopy(bm->maxs, starmod->maxs); - VectorCopy(bm->mins, starmod->mins); - starmod->radius = bm->radius; - - if (i == 0) - { - *loadmodel = *starmod; - } - - starmod->numleafs = bm->visleafs; - } + Mod_LoadVertexes(mod, mod_base, &header->lumps[LUMP_VERTEXES]); + Mod_LoadEdges(mod, mod_base, &header->lumps[LUMP_EDGES]); + Mod_LoadSurfedges(mod, mod_base, &header->lumps[LUMP_SURFEDGES]); + Mod_LoadLighting(mod, mod_base, &header->lumps[LUMP_LIGHTING]); + Mod_LoadPlanes(mod, mod_base, &header->lumps[LUMP_PLANES]); + Mod_LoadTexinfo(mod, mod_base, &header->lumps[LUMP_TEXINFO]); + Mod_LoadFaces(mod, mod_base, &header->lumps[LUMP_FACES]); + Mod_LoadMarksurfaces(mod, mod_base, &header->lumps[LUMP_LEAFFACES]); + Mod_LoadVisibility(mod, mod_base, &header->lumps[LUMP_VISIBILITY]); + Mod_LoadLeafs(mod, mod_base, &header->lumps[LUMP_LEAFS]); + Mod_LoadNodes(mod, mod_base, &header->lumps[LUMP_NODES]); + Mod_LoadSubmodels (mod, mod_base, &header->lumps[LUMP_MODELS]); + mod->numframes = 2; /* regular and alternate animation */ } static void @@ -987,7 +972,7 @@ extern void GL3_LoadSP2(gl3model_t *mod, void *buffer, int modfilelen); * Loads in a model for the given name */ static gl3model_t * -Mod_ForName(char *name, qboolean crash) +Mod_ForName (char *name, gl3model_t *parent_model, qboolean crash) { gl3model_t *mod; unsigned *buf; @@ -999,17 +984,17 @@ Mod_ForName(char *name, qboolean crash) } /* inline models are grabbed only from worldmodel */ - if (name[0] == '*') + if (name[0] == '*' && parent_model) { i = (int)strtol(name + 1, (char **)NULL, 10); - if ((i < 1) || !gl3_worldmodel || (i >= gl3_worldmodel->numsubmodels)) + if (i < 1 || i >= parent_model->numsubmodels) { ri.Sys_Error(ERR_DROP, "%s: bad inline model number", __func__); } - return &mod_inline[i]; + return &parent_model->submodels[i]; } /* search the currently loaded models */ @@ -1116,7 +1101,7 @@ GL3_BeginRegistration(char *model) Mod_Free(&mod_known[0]); } - gl3_worldmodel = Mod_ForName(fullname, true); + gl3_worldmodel = Mod_ForName(fullname, NULL, true); gl3_viewcluster = -1; } @@ -1129,7 +1114,7 @@ GL3_RegisterModel(char *name) dsprite_t *sprout; dmdl_t *pheader; - mod = Mod_ForName(name, false); + mod = Mod_ForName(name, gl3_worldmodel, false); if (mod) { diff --git a/src/client/refresh/gl3/header/model.h b/src/client/refresh/gl3/header/model.h index c54a509b..277ab1b6 100644 --- a/src/client/refresh/gl3/header/model.h +++ b/src/client/refresh/gl3/header/model.h @@ -195,7 +195,7 @@ typedef struct model_s int lightmap; /* only for submodels */ int numsubmodels; - mmodel_t *submodels; + struct model_s *submodels; int numplanes; cplane_t *planes; @@ -234,6 +234,9 @@ typedef struct model_s int extradatasize; void *extradata; + + // submodules + vec3_t origin; // for sounds or lights } gl3model_t; #endif /* SRC_CLIENT_REFRESH_GL3_HEADER_MODEL_H_ */ From 46c654b3797d3ed1e757ad027a583761afdd3057 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Mon, 20 Sep 2021 12:56:18 +0300 Subject: [PATCH 15/22] gl1: use local currentmodel --- src/client/refresh/gl3/gl3_lightmap.c | 2 +- src/client/refresh/gl3/gl3_main.c | 15 +++++++-------- src/client/refresh/gl3/gl3_model.c | 4 +--- src/client/refresh/gl3/gl3_surf.c | 8 +++----- src/client/refresh/gl3/header/local.h | 5 ++--- 5 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/client/refresh/gl3/gl3_lightmap.c b/src/client/refresh/gl3/gl3_lightmap.c index 9a95c4dd..80d93b62 100644 --- a/src/client/refresh/gl3/gl3_lightmap.c +++ b/src/client/refresh/gl3/gl3_lightmap.c @@ -118,7 +118,7 @@ GL3_LM_AllocBlock(int w, int h, int *x, int *y) } void -GL3_LM_BuildPolygonFromSurface(msurface_t *fa) +GL3_LM_BuildPolygonFromSurface(gl3model_t *currentmodel, msurface_t *fa) { int i, lindex, lnumverts; medge_t *pedges, *r_pedge; diff --git a/src/client/refresh/gl3/gl3_main.c b/src/client/refresh/gl3/gl3_main.c index 4696c97d..d10b284e 100644 --- a/src/client/refresh/gl3/gl3_main.c +++ b/src/client/refresh/gl3/gl3_main.c @@ -50,7 +50,6 @@ refdef_t gl3_newrefdef; viddef_t vid; gl3model_t *gl3_worldmodel; -gl3model_t *currentmodel; entity_t *currententity; float gl3depthmin=0.0f, gl3depthmax=1.0f; @@ -773,7 +772,7 @@ GL3_DrawBeam(entity_t *e) } static void -GL3_DrawSpriteModel(entity_t *e) +GL3_DrawSpriteModel(entity_t *e, gl3model_t *currentmodel) { float alpha = 1.0F; gl3_3D_vtx_t verts[4]; @@ -990,7 +989,7 @@ GL3_DrawEntitiesOnList(void) } else { - currentmodel = currententity->model; + gl3model_t *currentmodel = currententity->model; if (!currentmodel) { @@ -1004,10 +1003,10 @@ GL3_DrawEntitiesOnList(void) GL3_DrawAliasModel(currententity); break; case mod_brush: - GL3_DrawBrushModel(currententity); + GL3_DrawBrushModel(currententity, currentmodel); break; case mod_sprite: - GL3_DrawSpriteModel(currententity); + GL3_DrawSpriteModel(currententity, currentmodel); break; default: ri.Sys_Error(ERR_DROP, "Bad modeltype"); @@ -1036,7 +1035,7 @@ GL3_DrawEntitiesOnList(void) } else { - currentmodel = currententity->model; + gl3model_t *currentmodel = currententity->model; if (!currentmodel) { @@ -1050,10 +1049,10 @@ GL3_DrawEntitiesOnList(void) GL3_DrawAliasModel(currententity); break; case mod_brush: - GL3_DrawBrushModel(currententity); + GL3_DrawBrushModel(currententity, currentmodel); break; case mod_sprite: - GL3_DrawSpriteModel(currententity); + GL3_DrawSpriteModel(currententity, currentmodel); break; default: ri.Sys_Error(ERR_DROP, "Bad modeltype"); diff --git a/src/client/refresh/gl3/gl3_model.c b/src/client/refresh/gl3/gl3_model.c index 7e332ec7..4694e90e 100644 --- a/src/client/refresh/gl3/gl3_model.c +++ b/src/client/refresh/gl3/gl3_model.c @@ -543,8 +543,6 @@ Mod_LoadFaces(gl3model_t *loadmodel, byte *mod_base, lump_t *l) loadmodel->surfaces = out; loadmodel->numsurfaces = count; - currentmodel = loadmodel; - GL3_LM_BeginBuildingLightmaps(loadmodel); for (surfnum = 0; surfnum < count; surfnum++, in++, out++) @@ -623,7 +621,7 @@ Mod_LoadFaces(gl3model_t *loadmodel, byte *mod_base, lump_t *l) if (!(out->texinfo->flags & SURF_WARP)) { - GL3_LM_BuildPolygonFromSurface(out); + GL3_LM_BuildPolygonFromSurface(loadmodel, out); } } diff --git a/src/client/refresh/gl3/gl3_surf.c b/src/client/refresh/gl3/gl3_surf.c index e3ae6d38..8f22d646 100644 --- a/src/client/refresh/gl3/gl3_surf.c +++ b/src/client/refresh/gl3/gl3_surf.c @@ -526,7 +526,7 @@ RenderLightmappedPoly(msurface_t *surf) } static void -DrawInlineBModel(void) +DrawInlineBModel(gl3model_t *currentmodel) { int i, k; cplane_t *pplane; @@ -590,7 +590,7 @@ DrawInlineBModel(void) } void -GL3_DrawBrushModel(entity_t *e) +GL3_DrawBrushModel(entity_t *e, gl3model_t *currentmodel) { vec3_t mins, maxs; int i; @@ -656,7 +656,7 @@ GL3_DrawBrushModel(entity_t *e) e->angles[0] = -e->angles[0]; e->angles[2] = -e->angles[2]; - DrawInlineBModel(); + DrawInlineBModel(currentmodel); // glPopMatrix(); gl3state.uni3DData.transModelMat4 = oldMat; @@ -824,8 +824,6 @@ GL3_DrawWorld(void) return; } - currentmodel = gl3_worldmodel; - VectorCopy(gl3_newrefdef.vieworg, modelorg); /* auto cycle the world frame for texture animation */ diff --git a/src/client/refresh/gl3/header/local.h b/src/client/refresh/gl3/header/local.h index 1b9a77b8..b5bee801 100644 --- a/src/client/refresh/gl3/header/local.h +++ b/src/client/refresh/gl3/header/local.h @@ -300,7 +300,6 @@ typedef struct } gl3lightmapstate_t; extern gl3model_t *gl3_worldmodel; -extern gl3model_t *currentmodel; extern entity_t *currententity; extern float gl3depthmin, gl3depthmax; @@ -436,7 +435,7 @@ extern void GL3_BuildLightMap(msurface_t *surf, int offsetInLMbuf, int stride); extern void GL3_LM_InitBlock(void); extern void GL3_LM_UploadBlock(void); extern qboolean GL3_LM_AllocBlock(int w, int h, int *x, int *y); -extern void GL3_LM_BuildPolygonFromSurface(msurface_t *fa); +extern void GL3_LM_BuildPolygonFromSurface(gl3model_t *currentmodel, msurface_t *fa); extern void GL3_LM_CreateSurfaceLightmap(msurface_t *surf); extern void GL3_LM_BeginBuildingLightmaps(gl3model_t *m); extern void GL3_LM_EndBuildingLightmaps(void); @@ -458,7 +457,7 @@ extern void GL3_DrawGLPoly(msurface_t *fa); extern void GL3_DrawGLFlowingPoly(msurface_t *fa); extern void GL3_DrawTriangleOutlines(void); extern void GL3_DrawAlphaSurfaces(void); -extern void GL3_DrawBrushModel(entity_t *e); +extern void GL3_DrawBrushModel(entity_t *e, gl3model_t *currentmodel); extern void GL3_DrawWorld(void); extern void GL3_MarkLeaves(void); From 7576d2d3001c7124ae3a196f4c7c78bdd83f823b Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Mon, 20 Sep 2021 13:14:08 +0300 Subject: [PATCH 16/22] gl3: make currententity local --- src/client/refresh/gl3/gl3_light.c | 2 +- src/client/refresh/gl3/gl3_main.c | 19 ++++++------- src/client/refresh/gl3/gl3_mesh.c | 2 +- src/client/refresh/gl3/gl3_surf.c | 40 ++++++++++++--------------- src/client/refresh/gl3/header/local.h | 3 +- 5 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/client/refresh/gl3/gl3_light.c b/src/client/refresh/gl3/gl3_light.c index 3f45322d..6b08e52f 100644 --- a/src/client/refresh/gl3/gl3_light.c +++ b/src/client/refresh/gl3/gl3_light.c @@ -252,7 +252,7 @@ RecursiveLightPoint(mnode_t *node, vec3_t start, vec3_t end) } void -GL3_LightPoint(vec3_t p, vec3_t color) +GL3_LightPoint(entity_t *currententity, vec3_t p, vec3_t color) { vec3_t end; float r; diff --git a/src/client/refresh/gl3/gl3_main.c b/src/client/refresh/gl3/gl3_main.c index d10b284e..f6d10a67 100644 --- a/src/client/refresh/gl3/gl3_main.c +++ b/src/client/refresh/gl3/gl3_main.c @@ -50,7 +50,6 @@ refdef_t gl3_newrefdef; viddef_t vid; gl3model_t *gl3_worldmodel; -entity_t *currententity; float gl3depthmin=0.0f, gl3depthmax=1.0f; @@ -851,7 +850,7 @@ GL3_DrawSpriteModel(entity_t *e, gl3model_t *currentmodel) } static void -GL3_DrawNullModel(void) +GL3_DrawNullModel(entity_t *currententity) { vec3_t shadelight; @@ -861,7 +860,7 @@ GL3_DrawNullModel(void) } else { - GL3_LightPoint(currententity->origin, shadelight); + GL3_LightPoint(currententity, currententity->origin, shadelight); } hmm_mat4 origModelMat = gl3state.uni3DData.transModelMat4; @@ -976,7 +975,7 @@ GL3_DrawEntitiesOnList(void) /* draw non-transparent first */ for (i = 0; i < gl3_newrefdef.num_entities; i++) { - currententity = &gl3_newrefdef.entities[i]; + entity_t *currententity = &gl3_newrefdef.entities[i]; if (currententity->flags & RF_TRANSLUCENT) { @@ -993,7 +992,7 @@ GL3_DrawEntitiesOnList(void) if (!currentmodel) { - GL3_DrawNullModel(); + GL3_DrawNullModel(currententity); continue; } @@ -1022,7 +1021,7 @@ GL3_DrawEntitiesOnList(void) for (i = 0; i < gl3_newrefdef.num_entities; i++) { - currententity = &gl3_newrefdef.entities[i]; + entity_t *currententity = &gl3_newrefdef.entities[i]; if (!(currententity->flags & RF_TRANSLUCENT)) { @@ -1039,7 +1038,7 @@ GL3_DrawEntitiesOnList(void) if (!currentmodel) { - GL3_DrawNullModel(); + GL3_DrawNullModel(currententity); continue; } @@ -1579,7 +1578,7 @@ GL3_GetSpecialBufferModeForStereoMode(enum stereo_modes stereo_mode) { #endif // 0 static void -GL3_SetLightLevel(void) +GL3_SetLightLevel(entity_t *currententity) { vec3_t shadelight = {0}; @@ -1589,7 +1588,7 @@ GL3_SetLightLevel(void) } /* save off light value for server to look at */ - GL3_LightPoint(gl3_newrefdef.vieworg, shadelight); + GL3_LightPoint(currententity, gl3_newrefdef.vieworg, shadelight); /* pick the greatest component, which should be the * same as the mono value returned by software */ @@ -1621,7 +1620,7 @@ static void GL3_RenderFrame(refdef_t *fd) { GL3_RenderView(fd); - GL3_SetLightLevel(); + GL3_SetLightLevel(NULL); GL3_SetGL2D(); if(v_blend[3] != 0.0f) diff --git a/src/client/refresh/gl3/gl3_mesh.c b/src/client/refresh/gl3/gl3_mesh.c index 8b60f776..d25eb67e 100644 --- a/src/client/refresh/gl3/gl3_mesh.c +++ b/src/client/refresh/gl3/gl3_mesh.c @@ -711,7 +711,7 @@ GL3_DrawAliasModel(entity_t *entity) } else { - GL3_LightPoint(entity->origin, shadelight); + GL3_LightPoint(entity, entity->origin, shadelight); /* player lighting hack for communication back to server */ if (entity->flags & RF_WEAPONMODEL) diff --git a/src/client/refresh/gl3/gl3_surf.c b/src/client/refresh/gl3/gl3_surf.c index 8f22d646..0ebf9bd8 100644 --- a/src/client/refresh/gl3/gl3_surf.c +++ b/src/client/refresh/gl3/gl3_surf.c @@ -159,7 +159,7 @@ CullBox(vec3_t mins, vec3_t maxs) * Returns the proper texture for a given time and base texture */ static gl3image_t * -TextureAnimation(mtexinfo_t *tex) +TextureAnimation(entity_t *currententity, mtexinfo_t *tex) { int c; @@ -337,14 +337,14 @@ UpdateLMscales(const hmm_vec4 lmScales[MAX_LIGHTMAPS_PER_SURFACE], gl3ShaderInfo } static void -RenderBrushPoly(msurface_t *fa) +RenderBrushPoly(entity_t *currententity, msurface_t *fa) { int map; gl3image_t *image; c_brush_polys++; - image = TextureAnimation(fa->texinfo); + image = TextureAnimation(currententity, fa->texinfo); if (fa->flags & SURF_DRAWTURB) { @@ -449,7 +449,7 @@ GL3_DrawAlphaSurfaces(void) } static void -DrawTextureChains(void) +DrawTextureChains(entity_t *currententity) { int i; msurface_t *s; @@ -476,7 +476,7 @@ DrawTextureChains(void) for ( ; s; s = s->texturechain) { SetLightFlags(s); - RenderBrushPoly(s); + RenderBrushPoly(currententity, s); } image->texturechain = NULL; @@ -486,10 +486,10 @@ DrawTextureChains(void) } static void -RenderLightmappedPoly(msurface_t *surf) +RenderLightmappedPoly(entity_t *currententity, msurface_t *surf) { int map; - gl3image_t *image = TextureAnimation(surf->texinfo); + gl3image_t *image = TextureAnimation(currententity, surf->texinfo); hmm_vec4 lmScales[MAX_LIGHTMAPS_PER_SURFACE] = {0}; lmScales[0] = HMM_Vec4(1.0f, 1.0f, 1.0f, 1.0f); @@ -526,7 +526,7 @@ RenderLightmappedPoly(msurface_t *surf) } static void -DrawInlineBModel(gl3model_t *currentmodel) +DrawInlineBModel(entity_t *currententity, gl3model_t *currentmodel) { int i, k; cplane_t *pplane; @@ -574,11 +574,11 @@ DrawInlineBModel(gl3model_t *currentmodel) else if(!(psurf->flags & SURF_DRAWTURB)) { SetAllLightFlags(psurf); - RenderLightmappedPoly(psurf); + RenderLightmappedPoly(currententity, psurf); } else { - RenderBrushPoly(psurf); + RenderBrushPoly(currententity, psurf); } } } @@ -601,7 +601,6 @@ GL3_DrawBrushModel(entity_t *e, gl3model_t *currentmodel) return; } - currententity = e; gl3state.currenttexture = -1; if (e->angles[0] || e->angles[1] || e->angles[2]) @@ -656,7 +655,7 @@ GL3_DrawBrushModel(entity_t *e, gl3model_t *currentmodel) e->angles[0] = -e->angles[0]; e->angles[2] = -e->angles[2]; - DrawInlineBModel(currentmodel); + DrawInlineBModel(e, currentmodel); // glPopMatrix(); gl3state.uni3DData.transModelMat4 = oldMat; @@ -669,7 +668,7 @@ GL3_DrawBrushModel(entity_t *e, gl3model_t *currentmodel) } static void -RecursiveWorldNode(mnode_t *node) +RecursiveWorldNode(entity_t *currententity, mnode_t *node) { int c, side, sidebit; cplane_t *plane; @@ -755,7 +754,7 @@ RecursiveWorldNode(mnode_t *node) } /* recurse down the children, front side first */ - RecursiveWorldNode(node->children[side]); + RecursiveWorldNode(currententity, node->children[side]); /* draw stuff */ for (c = node->numsurfaces, @@ -782,7 +781,7 @@ RecursiveWorldNode(mnode_t *node) /* add to the translucent chain */ surf->texturechain = gl3_alpha_surfaces; gl3_alpha_surfaces = surf; - gl3_alpha_surfaces->texinfo->image = TextureAnimation(surf->texinfo); + gl3_alpha_surfaces->texinfo->image = TextureAnimation(currententity, surf->texinfo); } else { @@ -798,7 +797,7 @@ RecursiveWorldNode(mnode_t *node) #endif // 0 { /* the polygon is visible, so add it to the texture sorted chain */ - image = TextureAnimation(surf->texinfo); + image = TextureAnimation(currententity, surf->texinfo); surf->texturechain = image->texturechain; image->texturechain = surf; } @@ -806,7 +805,7 @@ RecursiveWorldNode(mnode_t *node) } /* recurse down the back side */ - RecursiveWorldNode(node->children[!side]); + RecursiveWorldNode(currententity, node->children[!side]); } void @@ -829,17 +828,14 @@ GL3_DrawWorld(void) /* auto cycle the world frame for texture animation */ memset(&ent, 0, sizeof(ent)); ent.frame = (int)(gl3_newrefdef.time * 2); - currententity = &ent; gl3state.currenttexture = -1; GL3_ClearSkyBox(); - RecursiveWorldNode(gl3_worldmodel->nodes); - DrawTextureChains(); + RecursiveWorldNode(&ent, gl3_worldmodel->nodes); + DrawTextureChains(&ent); GL3_DrawSkyBox(); DrawTriangleOutlines(); - - currententity = NULL; } /* diff --git a/src/client/refresh/gl3/header/local.h b/src/client/refresh/gl3/header/local.h index b5bee801..2ba06dc9 100644 --- a/src/client/refresh/gl3/header/local.h +++ b/src/client/refresh/gl3/header/local.h @@ -300,7 +300,6 @@ typedef struct } gl3lightmapstate_t; extern gl3model_t *gl3_worldmodel; -extern entity_t *currententity; extern float gl3depthmin, gl3depthmax; @@ -426,7 +425,7 @@ extern void GL3_ImageList_f(void); // gl3_light.c extern void GL3_MarkLights(dlight_t *light, int bit, mnode_t *node); extern void GL3_PushDlights(void); -extern void GL3_LightPoint(vec3_t p, vec3_t color); +extern void GL3_LightPoint(entity_t *currententity, vec3_t p, vec3_t color); extern void GL3_BuildLightMap(msurface_t *surf, int offsetInLMbuf, int stride); // gl3_lightmap.c From 11bb96401fbe0e2953899f95b48fc05b41e863ab Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Mon, 20 Sep 2021 13:41:10 +0300 Subject: [PATCH 17/22] soft: set current frame before use worldentity --- src/client/refresh/soft/sw_main.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index e7c98a12..8c56ec1d 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -1298,7 +1298,7 @@ static void RE_RenderFrame (refdef_t *fd) { r_newrefdef = *fd; - entity_t r_worldentity; + entity_t ent; if (!r_worldmodel && !( r_newrefdef.rdflags & RDF_NOWORLDMODEL ) ) { @@ -1339,9 +1339,14 @@ RE_RenderFrame (refdef_t *fd) // For each dlight_t* passed via r_newrefdef.dlights, mark polygons affected by a light. R_PushDlights (r_worldmodel); + // TODO: rearange code same as in GL*_DrawWorld? + /* auto cycle the world frame for texture animation */ + memset(&ent, 0, sizeof(ent)); + ent.frame = (int)(r_newrefdef.time * 2); + // Build the Global Edge Table and render it via the Active Edge Table // Render the map - R_EdgeDrawing (&r_worldentity); + R_EdgeDrawing (&ent); if (r_dspeeds->value) { @@ -1376,10 +1381,10 @@ RE_RenderFrame (refdef_t *fd) dp_time2 = SDL_GetTicks(); // Perform pixel palette blending ia the pics/colormap.pcx lower part lookup table. - R_DrawAlphaSurfaces(&r_worldentity); + R_DrawAlphaSurfaces(&ent); // Save off light value for server to look at (BIG HACK!) - R_SetLightLevel (&r_worldentity); + R_SetLightLevel (&ent); if (r_dowarp) D_WarpScreen (); From 012862b58d84511c68c0c8325f11e31e225a51db Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sat, 16 Oct 2021 14:09:22 +0300 Subject: [PATCH 18/22] set currtime before Qcommon_Frame once Make Qcommon_Frame and Qcommon_Mainloop static and minimize calls for get current time, it takes 7% in some profiling cases. We get current time twice before Qcommon_Frame(as Sys_Microseconds) and inside it(as Sys_Milliseconds), and we can do it once. --- src/common/frame.c | 21 +++++++++------------ src/common/header/common.h | 1 - 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/common/frame.c b/src/common/frame.c index 6d1c9571..ca4a14ed 100644 --- a/src/common/frame.c +++ b/src/common/frame.c @@ -81,6 +81,8 @@ char userGivenGame[MAX_QPATH]; // Hack for the signal handlers. qboolean quitnextframe; +static void Qcommon_Frame(int usec); + // ---- static void @@ -130,7 +132,7 @@ Qcommon_Buildstring(void) printf("Architecture: %s\n", YQ2ARCH); } -void +static void Qcommon_Mainloop(void) { long long newtime; @@ -173,6 +175,10 @@ Qcommon_Mainloop(void) #endif newtime = Sys_Microseconds(); + + // Save global time for network- und input code. + curtime = (int)(newtime / 1000ll); + Qcommon_Frame(newtime - oldtime); oldtime = newtime; } @@ -392,7 +398,7 @@ Qcommon_Init(int argc, char **argv) } #ifndef DEDICATED_ONLY -void +static void Qcommon_Frame(int usec) { // Used for the dedicated server console. @@ -523,11 +529,6 @@ Qcommon_Frame(int usec) Cvar_SetValue("cl_maxfps", 60); } - - // Save global time for network- und input code. - curtime = Sys_Milliseconds(); - - // Calculate target and renderframerate. if (R_IsVSyncActive()) { @@ -668,7 +669,7 @@ Qcommon_Frame(int usec) } } #else -void +static void Qcommon_Frame(int usec) { // For the dedicated server terminal console. @@ -720,10 +721,6 @@ Qcommon_Frame(int usec) } - // Save global time for network- und input code. - curtime = Sys_Milliseconds(); - - // Target framerate. pfps = (int)cl_maxfps->value; diff --git a/src/common/header/common.h b/src/common/header/common.h index 24134095..6cd5692b 100644 --- a/src/common/header/common.h +++ b/src/common/header/common.h @@ -780,7 +780,6 @@ void Z_FreeTags(int tag); void Qcommon_Init(int argc, char **argv); void Qcommon_ExecConfigs(qboolean addEarlyCmds); const char* Qcommon_GetInitialGame(void); -void Qcommon_Frame(int msec); void Qcommon_Shutdown(void); #define NUMVERTEXNORMALS 162 From fa1f5c2c84b285926fdbed54cb53ebf8a55b20c7 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sat, 16 Oct 2021 14:38:11 +0300 Subject: [PATCH 19/22] Never sleep between frames with timedemo --- src/common/frame.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/common/frame.c b/src/common/frame.c index ca4a14ed..15cf550d 100644 --- a/src/common/frame.c +++ b/src/common/frame.c @@ -142,33 +142,36 @@ Qcommon_Mainloop(void) while (1) { #ifndef DEDICATED_ONLY - // Throttle the game a little bit. - if (busywait->value) + if (!cl_timedemo->value) { - long long spintime = Sys_Microseconds(); - - while (1) + // Throttle the game a little bit. + if (busywait->value) { - /* Give the CPU a hint that this is a very tight - spinloop. One PAUSE instruction each loop is - enough to reduce power consumption and head - dispersion a lot, it's 95°C against 67°C on - a Kaby Lake laptop. */ + long long spintime = Sys_Microseconds(); + + while (1) + { + /* Give the CPU a hint that this is a very tight + spinloop. One PAUSE instruction each loop is + enough to reduce power consumption and head + dispersion a lot, it's 95°C against 67°C on + a Kaby Lake laptop. */ #if defined (__GNUC__) && (__i386 || __x86_64__) - asm("pause"); + asm("pause"); #elif defined(__aarch64__) || (defined(__ARM_ARCH) && __ARM_ARCH >= 7) || defined(__ARM_ARCH_6K__) - asm("yield"); + asm("yield"); #endif - if (Sys_Microseconds() - spintime >= 5) - { - break; + if (Sys_Microseconds() - spintime >= 5) + { + break; + } } } - } - else - { - Sys_Nanosleep(5000); + else + { + Sys_Nanosleep(5000); + } } #else Sys_Nanosleep(850000); From 4eb2d95ccd7b6389b3121bf6b93d1e1b9b8e5d16 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sat, 16 Oct 2021 18:28:37 +0300 Subject: [PATCH 20/22] limit timedemo to vid_maxfps * 5 --- src/common/frame.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/common/frame.c b/src/common/frame.c index 15cf550d..95f43246 100644 --- a/src/common/frame.c +++ b/src/common/frame.c @@ -602,9 +602,15 @@ Qcommon_Frame(int usec) } } } - else if (clienttimedelta < 1000 || servertimedelta < 1000) + else { - return; + /* minimal frame time in timedemo fps * 5 ~ 5000 */ + int minframetime; + + minframetime = 1000 * 1000 / 5 / vid_maxfps->value; + + if (clienttimedelta < minframetime || servertimedelta < minframetime) + return; } From c280c408b14fc9c2dc9f452d3706022bd9e42f09 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sat, 16 Oct 2021 21:00:07 +0300 Subject: [PATCH 21/22] dont collect statistics with cl_showfps=0 --- src/client/cl_screen.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/client/cl_screen.c b/src/client/cl_screen.c index 00e9cd18..69e84e1d 100644 --- a/src/client/cl_screen.c +++ b/src/client/cl_screen.c @@ -1422,6 +1422,10 @@ SCR_Framecounter(void) { static int frametimes[60] = {0}; static long long oldtime; + /* skip statistics without show fps */ + if (cl_showfps->value < 1) + return; + newtime = Sys_Microseconds(); frametimes[frame] = (int)(newtime - oldtime); From 1e0d75857ba64b60d6a68d6e78fd542a6f429cd1 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 17 Oct 2021 11:11:05 +0300 Subject: [PATCH 22/22] Use separate r_scale8bittextures for image scale Rename {sw,gl}_retexturing variables to r_retexturing in code. --- doc/040_cvarlist.md | 3 ++- src/client/refresh/gl1/gl1_image.c | 6 +++--- src/client/refresh/gl1/gl1_main.c | 6 ++++-- src/client/refresh/gl1/header/local.h | 3 ++- src/client/refresh/gl3/gl3_image.c | 6 +++--- src/client/refresh/gl3/gl3_main.c | 8 +++++--- src/client/refresh/gl3/header/local.h | 3 ++- src/client/refresh/soft/header/local.h | 3 ++- src/client/refresh/soft/sw_draw.c | 4 ++-- src/client/refresh/soft/sw_image.c | 4 ++-- src/client/refresh/soft/sw_main.c | 6 ++++-- 11 files changed, 31 insertions(+), 21 deletions(-) diff --git a/doc/040_cvarlist.md b/doc/040_cvarlist.md index 5847ff9f..d4951091 100644 --- a/doc/040_cvarlist.md +++ b/doc/040_cvarlist.md @@ -281,7 +281,8 @@ it's `+set busywait 0` (setting the `busywait` cvar) and `-portable` * **r_retexturing**: If set to `1` (the default) and a retexturing pack is installed, the high resolution textures are used. - If set to `2` and vulkan render is used, scale up all 8bit textures. + +* **r_scale8bittextures**: If set to `1`, scale up all 8bit textures. * **r_shadows**: Enables rendering of shadows. Quake IIs shadows are very simple and are prone to render errors. diff --git a/src/client/refresh/gl1/gl1_image.c b/src/client/refresh/gl1/gl1_image.c index 17bffcb5..d3240f5f 100644 --- a/src/client/refresh/gl1/gl1_image.c +++ b/src/client/refresh/gl1/gl1_image.c @@ -939,7 +939,7 @@ R_LoadPic(char *name, byte *pic, int width, int realwidth, if (bits == 8) { // resize 8bit images only when we forced such logic - if (gl_retexturing->value >= 2) + if (r_scale8bittextures->value) { byte *image_converted = malloc(width * height * 4); scale2x(pic, image_converted, width, height); @@ -1173,7 +1173,7 @@ R_FindImage(char *name, imagetype_t type) if (strcmp(ext, "pcx") == 0) { - if (gl_retexturing->value) + if (r_retexturing->value) { GetPCXInfo(name, &realwidth, &realheight); if(realwidth == 0) @@ -1220,7 +1220,7 @@ R_FindImage(char *name, imagetype_t type) } else if (strcmp(ext, "wal") == 0 || strcmp(ext, "m8") == 0) { - if (gl_retexturing->value) + if (r_retexturing->value) { /* Get size of the original texture */ if (strcmp(ext, "m8") == 0) diff --git a/src/client/refresh/gl1/gl1_main.c b/src/client/refresh/gl1/gl1_main.c index f55579db..6417f15f 100644 --- a/src/client/refresh/gl1/gl1_main.c +++ b/src/client/refresh/gl1/gl1_main.c @@ -100,7 +100,8 @@ cvar_t *r_fixsurfsky; cvar_t *r_customwidth; cvar_t *r_customheight; -cvar_t *gl_retexturing; +cvar_t *r_retexturing; +cvar_t *r_scale8bittextures; cvar_t *gl_nolerp_list; @@ -1260,7 +1261,8 @@ R_Register(void) r_customheight = ri.Cvar_Get("r_customheight", "768", CVAR_ARCHIVE); gl_msaa_samples = ri.Cvar_Get ( "r_msaa_samples", "0", CVAR_ARCHIVE ); - gl_retexturing = ri.Cvar_Get("r_retexturing", "1", CVAR_ARCHIVE); + r_retexturing = ri.Cvar_Get("r_retexturing", "1", CVAR_ARCHIVE); + r_scale8bittextures = ri.Cvar_Get("r_scale8bittextures", "0", CVAR_ARCHIVE); /* don't bilerp characters and crosshairs */ gl_nolerp_list = ri.Cvar_Get("r_nolerp_list", "pics/conchars.pcx pics/ch1.pcx pics/ch2.pcx pics/ch3.pcx", 0); diff --git a/src/client/refresh/gl1/header/local.h b/src/client/refresh/gl1/header/local.h index f0257eca..da7ed17a 100644 --- a/src/client/refresh/gl1/header/local.h +++ b/src/client/refresh/gl1/header/local.h @@ -191,7 +191,8 @@ extern cvar_t *r_mode; extern cvar_t *r_customwidth; extern cvar_t *r_customheight; -extern cvar_t *gl_retexturing; +extern cvar_t *r_retexturing; +extern cvar_t *r_scale8bittextures; extern cvar_t *gl_nolerp_list; diff --git a/src/client/refresh/gl3/gl3_image.c b/src/client/refresh/gl3/gl3_image.c index c9ff9364..f8e6d286 100644 --- a/src/client/refresh/gl3/gl3_image.c +++ b/src/client/refresh/gl3/gl3_image.c @@ -431,7 +431,7 @@ GL3_LoadPic(char *name, byte *pic, int width, int realwidth, if (bits == 8) { // resize 8bit images only when we forced such logic - if (gl_retexturing->value >= 2) + if (r_scale8bittextures->value) { byte *image_converted = malloc(width * height * 4); scale2x(pic, image_converted, width, height); @@ -746,7 +746,7 @@ GL3_FindImage(char *name, imagetype_t type) if (strcmp(ext, "pcx") == 0) { - if (gl_retexturing->value) + if (r_retexturing->value) { GetPCXInfo(name, &realwidth, &realheight); if(realwidth == 0) @@ -793,7 +793,7 @@ GL3_FindImage(char *name, imagetype_t type) } else if (strcmp(ext, "wal") == 0 || strcmp(ext, "m8") == 0) { - if (gl_retexturing->value) + if (r_retexturing->value) { /* Get size of the original texture */ if (strcmp(ext, "m8") == 0) diff --git a/src/client/refresh/gl3/gl3_main.c b/src/client/refresh/gl3/gl3_main.c index f6d10a67..7cef6bec 100644 --- a/src/client/refresh/gl3/gl3_main.c +++ b/src/client/refresh/gl3/gl3_main.c @@ -79,7 +79,8 @@ const hmm_mat4 gl3_identityMat4 = {{ cvar_t *gl_msaa_samples; cvar_t *r_vsync; -cvar_t *gl_retexturing; +cvar_t *r_retexturing; +cvar_t *r_scale8bittextures; cvar_t *vid_fullscreen; cvar_t *r_mode; cvar_t *r_customwidth; @@ -197,7 +198,8 @@ GL3_Register(void) gl_drawbuffer = ri.Cvar_Get("gl_drawbuffer", "GL_BACK", 0); r_vsync = ri.Cvar_Get("r_vsync", "1", CVAR_ARCHIVE); gl_msaa_samples = ri.Cvar_Get ( "r_msaa_samples", "0", CVAR_ARCHIVE ); - gl_retexturing = ri.Cvar_Get("r_retexturing", "1", CVAR_ARCHIVE); + r_retexturing = ri.Cvar_Get("r_retexturing", "1", CVAR_ARCHIVE); + r_scale8bittextures = ri.Cvar_Get("r_scale8bittextures", "0", CVAR_ARCHIVE); gl3_debugcontext = ri.Cvar_Get("gl3_debugcontext", "0", 0); r_mode = ri.Cvar_Get("r_mode", "4", CVAR_ARCHIVE); r_customwidth = ri.Cvar_Get("r_customwidth", "1024", CVAR_ARCHIVE); @@ -299,7 +301,7 @@ GL3_Register(void) //r_customheight = ri.Cvar_Get("r_customheight", "768", CVAR_ARCHIVE); //gl_msaa_samples = ri.Cvar_Get ( "r_msaa_samples", "0", CVAR_ARCHIVE ); - //gl_retexturing = ri.Cvar_Get("r_retexturing", "1", CVAR_ARCHIVE); + //r_retexturing = ri.Cvar_Get("r_retexturing", "1", CVAR_ARCHIVE); gl1_stereo = ri.Cvar_Get( "gl1_stereo", "0", CVAR_ARCHIVE ); diff --git a/src/client/refresh/gl3/header/local.h b/src/client/refresh/gl3/header/local.h index 2ba06dc9..be02fa62 100644 --- a/src/client/refresh/gl3/header/local.h +++ b/src/client/refresh/gl3/header/local.h @@ -480,7 +480,8 @@ extern void GL3_UpdateUBOLights(void); extern cvar_t *gl_msaa_samples; extern cvar_t *r_vsync; -extern cvar_t *gl_retexturing; +extern cvar_t *r_retexturing; +extern cvar_t *r_scale8bittextures; extern cvar_t *vid_fullscreen; extern cvar_t *r_mode; extern cvar_t *r_customwidth; diff --git a/src/client/refresh/soft/header/local.h b/src/client/refresh/soft/header/local.h index c092a9da..89aa59ab 100644 --- a/src/client/refresh/soft/header/local.h +++ b/src/client/refresh/soft/header/local.h @@ -424,7 +424,8 @@ extern cvar_t *sw_stipplealpha; extern cvar_t *sw_surfcacheoverride; extern cvar_t *sw_waterwarp; extern cvar_t *sw_gunzposition; -extern cvar_t *sw_retexturing; +extern cvar_t *r_retexturing; +extern cvar_t *r_scale8bittextures; extern cvar_t *r_fullbright; extern cvar_t *r_lefthand; diff --git a/src/client/refresh/soft/sw_draw.c b/src/client/refresh/soft/sw_draw.c index 08f55f23..d078236c 100644 --- a/src/client/refresh/soft/sw_draw.c +++ b/src/client/refresh/soft/sw_draw.c @@ -339,7 +339,7 @@ RE_Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *data) // we have only one image size pic.mip_levels = 1; - if (sw_retexturing->value) + if (r_retexturing->value) { if (cols < (w / 3) || rows < (h / 3)) { @@ -373,7 +373,7 @@ RE_Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *data) RE_Draw_StretchPicImplementation (x, y, w, h, &pic); - if (sw_retexturing->value) + if (r_retexturing->value) { free(image_scaled); } diff --git a/src/client/refresh/soft/sw_image.c b/src/client/refresh/soft/sw_image.c index 80fbf45e..5c15ee24 100644 --- a/src/client/refresh/soft/sw_image.c +++ b/src/client/refresh/soft/sw_image.c @@ -581,7 +581,7 @@ R_LoadImage(char *name, const char* namewe, const char *ext, imagetype_t type) image_t *image = NULL; // with retexturing and not skin - if (sw_retexturing->value) + if (r_retexturing->value) { image = R_LoadHiColorImage(name, namewe, ext, type); } @@ -598,7 +598,7 @@ R_LoadImage(char *name, const char* namewe, const char *ext, imagetype_t type) if (!pic) return NULL; - if (sw_retexturing->value == 2 && type == it_pic) + if (r_scale8bittextures->value && type == it_pic) { byte *scaled = NULL; int realwidth, realheight; diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index 8c56ec1d..e5db71b5 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -146,7 +146,8 @@ static cvar_t *sw_overbrightbits; cvar_t *sw_custom_particles; static cvar_t *sw_anisotropic; cvar_t *sw_texture_filtering; -cvar_t *sw_retexturing; +cvar_t *r_retexturing; +cvar_t *r_scale8bittextures; cvar_t *sw_gunzposition; static cvar_t *sw_partialrefresh; @@ -375,7 +376,8 @@ R_RegisterVariables (void) sw_custom_particles = ri.Cvar_Get("sw_custom_particles", "0", CVAR_ARCHIVE); sw_texture_filtering = ri.Cvar_Get("sw_texture_filtering", "0", CVAR_ARCHIVE); sw_anisotropic = ri.Cvar_Get("r_anisotropic", "0", CVAR_ARCHIVE); - sw_retexturing = ri.Cvar_Get("r_retexturing", "1", CVAR_ARCHIVE); + r_retexturing = ri.Cvar_Get("r_retexturing", "1", CVAR_ARCHIVE); + r_scale8bittextures = ri.Cvar_Get("r_scale8bittextures", "0", CVAR_ARCHIVE); sw_gunzposition = ri.Cvar_Get("sw_gunzposition", "8", CVAR_ARCHIVE); // On MacOS texture is cleaned up after render and code have to copy a whole