diff --git a/libs/video/renderer/sw/sw_ralias.c b/libs/video/renderer/sw/sw_ralias.c index 9437602a2..0768dd707 100644 --- a/libs/video/renderer/sw/sw_ralias.c +++ b/libs/video/renderer/sw/sw_ralias.c @@ -40,6 +40,8 @@ static const char rcsid[] = #include "d_ifacea.h" #include "r_local.h" +#include "stdlib.h" + #define LIGHT_MIN 5 // lowest light value we'll allow, to // avoid the need for inner-loop light // clamping @@ -667,24 +669,34 @@ R_AliasSetupFrame (void) ((byte *) paliashdr + paliasgroup->frames[i].frame); } -#define MAXALIASVERTS 1024 +finalvert_t *finalverts; +auxvert_t *auxverts; +int maxaliasverts = 0; + void R_AliasDrawModel (alight_t *plighting) { - finalvert_t finalverts[MAXALIASVERTS + - ((CACHE_SIZE - 1) / sizeof (finalvert_t)) + 1]; - auxvert_t auxverts[MAXALIASVERTS]; - r_amodels_drawn++; + paliashdr = Cache_Get (¤tentity->model->cache); + pmdl = (mdl_t *) ((byte *) paliashdr + paliashdr->model); + + if (pmdl->numverts > maxaliasverts) + { + finalverts = realloc (finalverts, (CACHE_SIZE - 1) + + sizeof (finalvert_t) * (pmdl->numverts + 1)); + auxverts = realloc (auxverts, + sizeof (auxvert_t) * pmdl->numverts); + if (!finalverts || !auxverts) + Sys_Error ("R_AliasDrawModel: out of memory"); + maxaliasverts = pmdl->numverts; + } + // cache align pfinalverts = (finalvert_t *) (((long) &finalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1)); pauxverts = &auxverts[0]; - paliashdr = Cache_Get (¤tentity->model->cache); - pmdl = (mdl_t *) ((byte *) paliashdr + paliashdr->model); - R_AliasSetupSkin (); R_AliasSetUpTransform (currententity->trivial_accept); R_AliasSetupLighting (plighting); diff --git a/libs/video/renderer/sw32/sw32_ralias.c b/libs/video/renderer/sw32/sw32_ralias.c index 296e44446..6716ac179 100644 --- a/libs/video/renderer/sw32/sw32_ralias.c +++ b/libs/video/renderer/sw32/sw32_ralias.c @@ -40,6 +40,8 @@ static const char rcsid[] = #include "d_ifacea.h" #include "r_local.h" +#include "stdlib.h" + #define LIGHT_MIN 5 // lowest light value we'll allow, to // avoid the need for inner-loop light // clamping @@ -659,24 +661,34 @@ R_AliasSetupFrame (void) } -#define MAXALIASVERTS 1024 +finalvert_t *finalverts; +auxvert_t *auxverts; +int maxaliasverts = 0; + void R_AliasDrawModel (alight_t *plighting) { - finalvert_t finalverts[MAXALIASVERTS + - ((CACHE_SIZE - 1) / sizeof (finalvert_t)) + 1]; - auxvert_t auxverts[MAXALIASVERTS]; - r_amodels_drawn++; + paliashdr = Cache_Get (¤tentity->model->cache); + pmdl = (mdl_t *) ((byte *) paliashdr + paliashdr->model); + + if (pmdl->numverts > maxaliasverts) + { + finalverts = realloc (finalverts, (CACHE_SIZE - 1) + + sizeof (finalvert_t) * (pmdl->numverts + 1)); + auxverts = realloc (auxverts, + sizeof (auxvert_t) * pmdl->numverts); + if (!finalverts || !auxverts) + Sys_Error ("R_AliasDrawModel: out of memory"); + maxaliasverts = pmdl->numverts; + } + // cache align pfinalverts = (finalvert_t *) (((long) &finalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1)); pauxverts = &auxverts[0]; - paliashdr = Cache_Get (¤tentity->model->cache); - pmdl = (mdl_t *) ((byte *) paliashdr + paliashdr->model); - R_AliasSetupSkin (); R_AliasSetUpTransform (currententity->trivial_accept); R_AliasSetupLighting (plighting);