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.
This commit is contained in:
Denis Pauk 2022-10-24 22:38:37 +03:00
parent c2dc8debb6
commit 9fb4480948
8 changed files with 41 additions and 49 deletions

View file

@ -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 */

View file

@ -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 {

View file

@ -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 */

View file

@ -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

View file

@ -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);

View file

@ -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 ; i<MAXLIGHTMAPS ; i++)
{
out->styles[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;

View file

@ -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;

View file

@ -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--;