ref: fix glpoly_t definition so it has true standard flexible array member
This commit is contained in:
parent
257312ad7c
commit
a9dec51e59
5 changed files with 25 additions and 17 deletions
|
@ -127,13 +127,22 @@ typedef struct
|
|||
int flags; // sky or slime, no lightmap or 256 subdivision
|
||||
} mtexinfo_t;
|
||||
|
||||
// a1ba: changed size to avoid undefined behavior. Check your allocations if you take this header!
|
||||
// For example:
|
||||
// before: malloc( sizeof( glpoly_t ) + ( numverts - 4 ) * VERTEXSIZE * sizeof( float ))
|
||||
// after (C): malloc( sizeof( glpoly_t ) + numverts * VERTEXSIZE * sizeof( float ))
|
||||
// after (C++): malloc( sizeof( glpoly_t ) + ( numverts - 1 ) * VERTEXSIZE * sizeof( float ))
|
||||
typedef struct glpoly_s
|
||||
{
|
||||
struct glpoly_s *next;
|
||||
struct glpoly_s *chain;
|
||||
int numverts;
|
||||
int flags; // for SURF_UNDERWATER
|
||||
float verts[4][VERTEXSIZE]; // variable sized (xyz s1t1 s2t2)
|
||||
#ifdef __cplusplus
|
||||
float verts[1][VERTEXSIZE]; // variable sized (xyz s1t1 s2t2)
|
||||
#else
|
||||
float verts[][VERTEXSIZE]; // variable sized (xyz s1t1 s2t2)
|
||||
#endif
|
||||
} glpoly_t;
|
||||
|
||||
typedef struct mnode_s
|
||||
|
|
|
@ -507,7 +507,7 @@ static glpoly_t *R_DecalCreatePoly( decalinfo_t *decalinfo, decal_t *pdecal, msu
|
|||
|
||||
// allocate glpoly
|
||||
// REFTODO: com_studiocache pool!
|
||||
poly = Mem_Calloc( r_temppool, sizeof( glpoly_t ) + ( lnumverts - 4 ) * VERTEXSIZE * sizeof( float ));
|
||||
poly = Mem_Calloc( r_temppool, sizeof( glpoly_t ) + lnumverts * VERTEXSIZE * sizeof( float ));
|
||||
poly->next = pdecal->polys;
|
||||
poly->flags = surf->flags;
|
||||
pdecal->polys = poly;
|
||||
|
|
|
@ -196,7 +196,7 @@ static void SubdividePolygon_r( model_t *loadmodel, msurface_t *warpface, int nu
|
|||
ClearBits( warpface->flags, SURF_DRAWTURB_QUADS );
|
||||
|
||||
// add a point in the center to help keep warp valid
|
||||
poly = Mem_Calloc( loadmodel->mempool, sizeof( glpoly_t ) + (numverts - 4) * VERTEXSIZE * sizeof( float ));
|
||||
poly = Mem_Calloc( loadmodel->mempool, sizeof( glpoly_t ) + numverts * VERTEXSIZE * sizeof( float ));
|
||||
poly->next = warpface->polys;
|
||||
poly->flags = warpface->flags;
|
||||
warpface->polys = poly;
|
||||
|
@ -328,7 +328,7 @@ void GL_BuildPolygonFromSurface( model_t *mod, msurface_t *fa )
|
|||
fa->polys = NULL;
|
||||
|
||||
// quake simple models (healthkits etc) need to be reconstructed their polys because LM coords has changed after the map change
|
||||
poly = Mem_Realloc( mod->mempool, poly, sizeof( glpoly_t ) + ( lnumverts - 4 ) * VERTEXSIZE * sizeof( float ));
|
||||
poly = Mem_Realloc( mod->mempool, poly, sizeof( glpoly_t ) + lnumverts * VERTEXSIZE * sizeof( float ));
|
||||
poly->next = fa->polys;
|
||||
poly->flags = fa->flags;
|
||||
fa->polys = poly;
|
||||
|
|
|
@ -415,7 +415,7 @@ static void R_CloudVertex( float s, float t, int axis, vec3_t v )
|
|||
R_CloudTexCoord
|
||||
=============
|
||||
*/
|
||||
static void R_CloudTexCoord( vec3_t v, float speed, float *s, float *t )
|
||||
static void R_CloudTexCoord( const vec3_t v, float speed, float *s, float *t )
|
||||
{
|
||||
float length, speedscale;
|
||||
vec3_t dir;
|
||||
|
@ -438,17 +438,17 @@ static void R_CloudTexCoord( vec3_t v, float speed, float *s, float *t )
|
|||
R_CloudDrawPoly
|
||||
===============
|
||||
*/
|
||||
static void R_CloudDrawPoly( glpoly_t *p )
|
||||
static void R_CloudDrawPoly( const float *verts )
|
||||
{
|
||||
const float *v;
|
||||
float s, t;
|
||||
float *v;
|
||||
int i;
|
||||
|
||||
GL_SetRenderMode( kRenderNormal );
|
||||
GL_Bind( XASH_TEXTURE0, tr.solidskyTexture );
|
||||
|
||||
pglBegin( GL_QUADS );
|
||||
for( i = 0, v = p->verts[0]; i < 4; i++, v += VERTEXSIZE )
|
||||
for( i = 0, v = verts; i < 4; i++, v += VERTEXSIZE )
|
||||
{
|
||||
R_CloudTexCoord( v, 8.0f, &s, &t );
|
||||
pglTexCoord2f( s, t );
|
||||
|
@ -460,7 +460,7 @@ static void R_CloudDrawPoly( glpoly_t *p )
|
|||
GL_Bind( XASH_TEXTURE0, tr.alphaskyTexture );
|
||||
|
||||
pglBegin( GL_QUADS );
|
||||
for( i = 0, v = p->verts[0]; i < 4; i++, v += VERTEXSIZE )
|
||||
for( i = 0, v = verts; i < 4; i++, v += VERTEXSIZE )
|
||||
{
|
||||
R_CloudTexCoord( v, 16.0f, &s, &t );
|
||||
pglTexCoord2f( s, t );
|
||||
|
@ -479,10 +479,10 @@ R_CloudRenderSide
|
|||
static void R_CloudRenderSide( int axis )
|
||||
{
|
||||
vec3_t verts[4];
|
||||
float final_verts[4][VERTEXSIZE];
|
||||
float di, qi, dj, qj;
|
||||
vec3_t vup, vright;
|
||||
vec3_t temp, temp2;
|
||||
glpoly_t p[1];
|
||||
int i, j;
|
||||
|
||||
R_CloudVertex( -1.0f, -1.0f, axis, verts[0] );
|
||||
|
@ -493,7 +493,6 @@ static void R_CloudRenderSide( int axis )
|
|||
VectorSubtract( verts[2], verts[3], vup );
|
||||
VectorSubtract( verts[2], verts[1], vright );
|
||||
|
||||
p->numverts = 4;
|
||||
di = SKYCLOUDS_QUALITY;
|
||||
qi = 1.0f / di;
|
||||
dj = (axis < 4) ? di * 2 : di; //subdivide vertically more than horizontally on skybox sides
|
||||
|
@ -512,17 +511,17 @@ static void R_CloudRenderSide( int axis )
|
|||
VectorScale( vright, qi * i, temp );
|
||||
VectorScale( vup, qj * j, temp2 );
|
||||
VectorAdd( temp, temp2, temp );
|
||||
VectorAdd( verts[0], temp, p->verts[0] );
|
||||
VectorAdd( verts[0], temp, final_verts[0] );
|
||||
|
||||
VectorScale( vup, qj, temp );
|
||||
VectorAdd( p->verts[0], temp, p->verts[1] );
|
||||
VectorAdd( final_verts[0], temp, final_verts[1] );
|
||||
|
||||
VectorScale( vright, qi, temp );
|
||||
VectorAdd( p->verts[1], temp, p->verts[2] );
|
||||
VectorAdd( final_verts[1], temp, final_verts[2] );
|
||||
|
||||
VectorAdd( p->verts[0], temp, p->verts[3] );
|
||||
VectorAdd( final_verts[0], temp, final_verts[3] );
|
||||
|
||||
R_CloudDrawPoly( p );
|
||||
R_CloudDrawPoly( final_verts[0] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -527,7 +527,7 @@ static glpoly_t *R_DecalCreatePoly( decalinfo_t *decalinfo, decal_t *pdecal, msu
|
|||
|
||||
// allocate glpoly
|
||||
// REFTODO: com_studiocache pool!
|
||||
poly = Mem_Calloc( r_temppool, sizeof( glpoly_t ) + ( lnumverts - 4 ) * VERTEXSIZE * sizeof( float ));
|
||||
poly = Mem_Calloc( r_temppool, sizeof( glpoly_t ) + lnumverts * VERTEXSIZE * sizeof( float ));
|
||||
poly->next = pdecal->polys;
|
||||
poly->flags = surf->flags;
|
||||
pdecal->polys = poly;
|
||||
|
|
Loading…
Add table
Reference in a new issue