use only allocated finalverts

This commit is contained in:
Denis Pauk 2018-07-23 16:51:16 +03:00
parent 1a5a0922c8
commit 789cd0128a
4 changed files with 49 additions and 33 deletions

View file

@ -160,6 +160,7 @@ extern oldrefdef_t r_refdef;
#define NUMSTACKEDGES 3072
#define NUMSTACKSURFACES 2048
#define MAXALIASVERTS 2048 // TODO: tune this
// flags in finalvert_t.flags
#define ALIAS_LEFT_CLIP 0x0001
@ -183,8 +184,6 @@ extern oldrefdef_t r_refdef;
#define NEAR_CLIP 0.01
#define MAXALIASVERTS 2048 // TODO: tune this
#define ALIAS_Z_CLIP_PLANE 4
// turbulence stuff
@ -519,16 +518,18 @@ extern spanpackage_t *triangle_spans;
extern byte **warp_rowptr;
extern int *warp_column;
extern espan_t *edge_basespans;
extern finalvert_t *finalverts;
extern int r_numallocatedverts;
extern finalvert_t *finalverts, *finalverts_max;
extern int r_aliasblendcolor;
extern float aliasxscale, aliasyscale, aliasxcenter, aliasycenter;
extern float aliasxscale, aliasyscale, aliasxcenter, aliasycenter;
extern int r_outofsurfaces;
extern int r_outofedges;
extern int r_outofsurfaces;
extern int r_outofedges;
extern int r_outofverts;
extern mvertex_t *r_pcurrentvertbase;
extern mvertex_t *r_pcurrentvertbase;
typedef struct
{

View file

@ -221,16 +221,7 @@ R_AliasPreparePoints
General clipped case
================
*/
typedef struct
{
int num_points;
dtrivertx_t *last_verts; // verts from the last frame
dtrivertx_t *this_verts; // verts from this frame
finalvert_t *dest_verts; // destination for transformed verts
} aliasbatchedtransformdata_t;
static aliasbatchedtransformdata_t aliasbatchedtransformdata;
finalvert_t *finalverts;
finalvert_t *finalverts, *finalverts_max;
static void
R_AliasPreparePoints (void)
@ -244,15 +235,11 @@ R_AliasPreparePoints (void)
// put work vertexes on stack, cache aligned
pfinalverts = finalverts;
aliasbatchedtransformdata.num_points = s_pmdl->num_xyz;
aliasbatchedtransformdata.last_verts = r_lastframe->verts;
aliasbatchedtransformdata.this_verts = r_thisframe->verts;
aliasbatchedtransformdata.dest_verts = pfinalverts;
R_AliasTransformFinalVerts( aliasbatchedtransformdata.num_points,
aliasbatchedtransformdata.dest_verts,
aliasbatchedtransformdata.last_verts,
aliasbatchedtransformdata.this_verts );
R_AliasTransformFinalVerts( s_pmdl->num_xyz,
pfinalverts, // destination for transformed verts
r_lastframe->verts, // verts from the last frame
r_thisframe->verts // verts from this frame
);
// clip and draw all triangles
//
@ -267,6 +254,11 @@ R_AliasPreparePoints (void)
pfv[1] = &pfinalverts[ptri->index_xyz[1]];
pfv[2] = &pfinalverts[ptri->index_xyz[2]];
if ( pfv[0] >= finalverts_max ||
pfv[1] >= finalverts_max ||
pfv[2] >= finalverts_max )
continue; // not enough verts
if ( pfv[0]->flags & pfv[1]->flags & pfv[2]->flags )
continue; // completely clipped
@ -302,6 +294,11 @@ R_AliasPreparePoints (void)
pfv[1] = &pfinalverts[ptri->index_xyz[1]];
pfv[2] = &pfinalverts[ptri->index_xyz[2]];
if ( pfv[0] >= finalverts_max ||
pfv[1] >= finalverts_max ||
pfv[2] >= finalverts_max )
continue; // not enough verts
if ( pfv[0]->flags & pfv[1]->flags & pfv[2]->flags )
continue; // completely clipped
@ -417,6 +414,11 @@ R_AliasTransformFinalVerts( int numpoints, finalvert_t *fv, dtrivertx_t *oldv, d
float lightcos, *plightnormal;
vec3_t lerped_vert;
if (fv >= finalverts_max) {
r_outofverts ++;
continue;
}
lerped_vert[0] = r_lerp_move[0] + oldv->v[0]*r_lerp_backv[0] + newv->v[0]*r_lerp_frontv[0];
lerped_vert[1] = r_lerp_move[1] + oldv->v[1]*r_lerp_backv[1] + newv->v[1]*r_lerp_frontv[1];
lerped_vert[2] = r_lerp_move[2] + oldv->v[2]*r_lerp_backv[2] + newv->v[2]*r_lerp_frontv[2];

View file

@ -55,12 +55,14 @@ pixel_t *r_warpbuffer;
static swstate_t sw_state;
void *colormap;
float r_time1;
int r_numallocatededges;
float r_aliasuvscale = 1.0;
int r_outofsurfaces;
int r_outofedges;
void *colormap;
float r_time1;
int r_numallocatededges;
int r_numallocatedverts;
float r_aliasuvscale = 1.0;
int r_outofsurfaces;
int r_outofedges;
int r_outofverts;
qboolean r_dowarp;
@ -431,10 +433,16 @@ void R_NewMap (void)
r_edges = malloc (r_numallocatededges * sizeof(edge_t));
r_numallocatedverts = MAXALIASVERTS;
finalverts = malloc(r_numallocatedverts * sizeof(finalvert_t));
finalverts_max = &finalverts[r_numallocatedverts];
R_Printf(PRINT_ALL, "%s: Allocated %d edges\n",
__func__, r_numallocatededges);
R_Printf(PRINT_ALL, "%s: Allocated %d surfaces\n",
__func__, r_cnumsurfs);
R_Printf(PRINT_ALL, "%s: Allocated %d verts\n",
__func__, r_numallocatedverts);
}
@ -1069,6 +1077,10 @@ RE_RenderFrame (refdef_t *fd)
else if (r_outofedges)
R_Printf(PRINT_ALL, "%s: not enough %d(+%d) edges\n",
__func__, r_numallocatededges, r_outofedges * 2 / 3);
if (r_outofverts)
R_Printf(PRINT_ALL, "%s: not enough %d(+%d) finalverts\n",
__func__, r_numallocatedverts, r_outofverts);
}
/*
@ -1891,7 +1903,7 @@ SWimp_InitGraphics(int fullscreen, int *pwidth, int *pheight)
warp_column = malloc((vid.width+AMP2*2) * sizeof(int));
edge_basespans = malloc((vid.width*2) * sizeof(espan_t));
finalverts = malloc((MAXALIASVERTS + 3) * sizeof(finalvert_t));
r_warpbuffer = malloc(vid.height * vid.width * sizeof(pixel_t));
if ((vid.width >= 2048) && (sizeof(shift20_t) == 4)) // 2k+ resolution and 32 == shift20_t

View file

@ -389,6 +389,7 @@ void R_SetupFrame (void)
r_drawnpolycount = 0;
r_amodels_drawn = 0;
r_outofsurfaces = 0;
r_outofverts = 0;
r_outofedges = 0;
// d_setup