From 9fb44809487b14e2a3ebe5e099d95824ce89e22e Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Mon, 24 Oct 2022 22:38:37 +0300 Subject: [PATCH] Share SURF_* values between renders Reuse DRAWSKY value in soft render instead unused DRAWSKYBOX and SURF_FLOW. Move mipadjust calculation to usage place in soft render. --- src/client/refresh/gl1/header/model.h | 9 --------- src/client/refresh/gl3/header/model.h | 14 -------------- src/client/refresh/ref_shared.h | 16 +++++++++++++++- src/client/refresh/soft/header/model.h | 9 --------- src/client/refresh/soft/sw_edge.c | 16 +++++++++++++--- src/client/refresh/soft/sw_model.c | 16 ++++++---------- src/client/refresh/soft/sw_rast.c | 8 ++++++-- src/client/refresh/soft/sw_surf.c | 2 +- 8 files changed, 41 insertions(+), 49 deletions(-) diff --git a/src/client/refresh/gl1/header/model.h b/src/client/refresh/gl1/header/model.h index 733049f5..2da1e9f7 100644 --- a/src/client/refresh/gl1/header/model.h +++ b/src/client/refresh/gl1/header/model.h @@ -27,15 +27,6 @@ #ifndef REF_MODEL_H #define REF_MODEL_H -#define SIDE_FRONT 0 -#define SIDE_BACK 1 -#define SIDE_ON 2 - -#define SURF_PLANEBACK 2 -#define SURF_DRAWSKY 4 -#define SURF_DRAWTURB 0x10 -#define SURF_DRAWBACKGROUND 0x40 -#define SURF_UNDERWATER 0x80 #define VERTEXSIZE 7 /* in memory representation */ diff --git a/src/client/refresh/gl3/header/model.h b/src/client/refresh/gl3/header/model.h index 54509172..3c67c4be 100644 --- a/src/client/refresh/gl3/header/model.h +++ b/src/client/refresh/gl3/header/model.h @@ -27,20 +27,6 @@ #ifndef SRC_CLIENT_REFRESH_GL3_HEADER_MODEL_H_ #define SRC_CLIENT_REFRESH_GL3_HEADER_MODEL_H_ -enum { - SIDE_FRONT = 0, - SIDE_BACK = 1, - SIDE_ON = 2 -}; - -enum { - SURF_PLANEBACK = 2, - SURF_DRAWSKY = 4, - SURF_DRAWTURB = 0x10, - SURF_DRAWBACKGROUND = 0x40, - SURF_UNDERWATER = 0x80 -}; - // used for vertex array elements when drawing brushes, sprites, sky and more // (ok, it has the layout used for rendering brushes, but is not used there) typedef struct gl3_3D_vtx_s { diff --git a/src/client/refresh/ref_shared.h b/src/client/refresh/ref_shared.h index be6c8330..c689308f 100644 --- a/src/client/refresh/ref_shared.h +++ b/src/client/refresh/ref_shared.h @@ -102,6 +102,21 @@ extern const byte* Mod_DecompressVis(const byte *in, int row); /* Shared models struct */ +enum { + SIDE_FRONT = 0, + SIDE_BACK = 1, + SIDE_ON = 2 +}; + +// FIXME: differentiate from texinfo SURF_ flags +enum { + SURF_PLANEBACK = 0x02, + SURF_DRAWSKY = 0x04, // sky brush face + SURF_DRAWTURB = 0x10, + SURF_DRAWBACKGROUND = 0x40, + SURF_UNDERWATER = 0x80 +}; + typedef struct mvertex_s { vec3_t position; @@ -116,7 +131,6 @@ typedef struct medge_s typedef struct mtexinfo_s { float vecs[2][4]; - float mipadjust; /* FIXME: Used only by soft render */ int flags; int numframes; struct mtexinfo_s *next; /* animation chain */ diff --git a/src/client/refresh/soft/header/model.h b/src/client/refresh/soft/header/model.h index 71e50994..33f2ee6c 100644 --- a/src/client/refresh/soft/header/model.h +++ b/src/client/refresh/soft/header/model.h @@ -41,15 +41,6 @@ BRUSH MODELS // in memory representation // -// FIXME: differentiate from texinfo SURF_ flags -#define SURF_PLANEBACK 0x02 -#define SURF_DRAWSKY 0x04 // sky brush face -#define SURF_DRAWTURB 0x10 -#define SURF_DRAWBACKGROUND 0x40 -#define SURF_DRAWSKYBOX 0x80 // sky box - -#define SURF_FLOW 0x100 - typedef struct msurface_s { int visframe; // should be drawn when node is crossed diff --git a/src/client/refresh/soft/sw_edge.c b/src/client/refresh/soft/sw_edge.c index 592a0ae0..07db4c88 100644 --- a/src/client/refresh/soft/sw_edge.c +++ b/src/client/refresh/soft/sw_edge.c @@ -937,6 +937,8 @@ Normal surface cached, texture mapped surface static void D_SolidSurf (entity_t *currententity, surf_t *s) { + float len1, len2, mipadjust; + if (s->insubmodel) { vec3_t local_modelorg; @@ -952,7 +954,15 @@ D_SolidSurf (entity_t *currententity, surf_t *s) } pface = s->msurf; - miplevel = D_MipLevelForScale(s->nearzi * scale_for_mip * pface->texinfo->mipadjust); + + len1 = VectorLength (pface->texinfo->vecs[0]); + len2 = VectorLength (pface->texinfo->vecs[1]); + mipadjust = sqrt(len1*len1 + len2*len2); + if (mipadjust < 0.01) + { + mipadjust = 0.01; + } + miplevel = D_MipLevelForScale(s->nearzi * scale_for_mip * mipadjust); // FIXME: make this passed in to D_CacheSurface pcurrentcache = D_CacheSurface (currententity, pface, miplevel); @@ -1035,9 +1045,9 @@ D_DrawSurfaces (entity_t *currententity, surf_t *surface) r_drawnpolycount++; - if (! (s->flags & (SURF_DRAWSKYBOX|SURF_DRAWBACKGROUND|SURF_DRAWTURB) ) ) + if (! (s->flags & (SURF_DRAWSKY|SURF_DRAWBACKGROUND|SURF_DRAWTURB) ) ) D_SolidSurf (currententity, s); - else if (s->flags & SURF_DRAWSKYBOX) + else if (s->flags & SURF_DRAWSKY) D_SkySurf (s); else if (s->flags & SURF_DRAWBACKGROUND) D_BackgroundSurf (s); diff --git a/src/client/refresh/soft/sw_model.c b/src/client/refresh/soft/sw_model.c index 4f5f0a0d..44818884 100644 --- a/src/client/refresh/soft/sw_model.c +++ b/src/client/refresh/soft/sw_model.c @@ -505,18 +505,12 @@ Mod_LoadTexinfo (model_t *loadmodel, byte *mod_base, lump_t *l) { image_t *image; int j, next; - float len1, len2; for (j = 0; j < 4; j++) { out->vecs[0][j] = LittleFloat(in->vecs[0][j]); out->vecs[1][j] = LittleFloat(in->vecs[1][j]); } - len1 = VectorLength (out->vecs[0]); - len2 = VectorLength (out->vecs[1]); - out->mipadjust = sqrt(len1*len1 + len2*len2); - if (out->mipadjust < 0.01) - out->mipadjust = 0.01; out->flags = LittleLong (in->flags); @@ -663,9 +657,12 @@ Mod_LoadFaces (model_t *loadmodel, byte *mod_base, lump_t *l) CalcSurfaceExtents (loadmodel, out); - // lighting info is converted from 24 bit on disk to 8 bit + // lighting is saved as its with 24 bit color for (i=0 ; istyles[i] = in->styles[i]; + } + i = LittleLong(in->lightofs); if (i == -1) { @@ -702,11 +699,10 @@ Mod_LoadFaces (model_t *loadmodel, byte *mod_base, lump_t *l) } //============== - // this marks flowing surfaces as turbulent, but with the new - // SURF_FLOW flag. + // this marks flowing surfaces as turbulent. if (out->texinfo->flags & SURF_FLOWING) { - out->flags |= SURF_DRAWTURB | SURF_FLOW; + out->flags |= SURF_DRAWTURB; for (i=0 ; i<2 ; i++) { out->extents[i] = 16384; diff --git a/src/client/refresh/soft/sw_rast.c b/src/client/refresh/soft/sw_rast.c index 15a58687..d964058b 100644 --- a/src/client/refresh/soft/sw_rast.c +++ b/src/client/refresh/soft/sw_rast.c @@ -67,7 +67,11 @@ static const int box_surfedges[24] = { 1,2,3,4, -1,5,6,7, 8,9,-6,10, -2,-7,-9 12,-3,-11,-8, -12,-10,-5,-4}; static const int box_edges[24] = { 1,2, 2,3, 3,4, 4,1, 1,5, 5,6, 6,2, 7,8, 8,6, 5,7, 8,3, 7,4}; -static const int box_faces[6] = {0,0,2,2,2,0}; +static const int box_faces[6] = { + 0, 0, + SURF_PLANEBACK, SURF_PLANEBACK, + SURF_PLANEBACK, 0 +}; static const vec3_t box_vecs[6][2] = { { {0,-1,0}, {-1,0,0} }, @@ -127,7 +131,7 @@ R_InitSkyBox (model_t *loadmodel) r_skyfaces[i].plane = &r_skyplanes[i]; r_skyfaces[i].numedges = 4; - r_skyfaces[i].flags = box_faces[i] | SURF_DRAWSKYBOX; + r_skyfaces[i].flags = box_faces[i] | SURF_DRAWSKY; r_skyfaces[i].firstedge = loadmodel->numsurfedges-24+i*4; r_skyfaces[i].texinfo = &r_skytexinfo[i]; r_skyfaces[i].texturemins[0] = -128; diff --git a/src/client/refresh/soft/sw_surf.c b/src/client/refresh/soft/sw_surf.c index 403fd328..28cec1e7 100644 --- a/src/client/refresh/soft/sw_surf.c +++ b/src/client/refresh/soft/sw_surf.c @@ -55,7 +55,7 @@ R_TextureAnimation (const entity_t *currententity, mtexinfo_t *tex) return tex->image; c = currententity->frame % tex->numframes; - while (c) + while (c && tex) { tex = tex->next; c--;