#include "glheader.h"
#include "imports.h"
#include "mtypes.h"
#include "t_imm_alloc.h"
static int id = 0;
static struct immediate *real_alloc_immediate( GLcontext *ctx )
{
struct immediate *IM = ALIGN_CALLOC_STRUCT( immediate, 32 );
if (!IM)
return 0;
IM->id = id++;
IM->ref_count = 0;
IM->FlushElt = 0;
IM->LastPrimitive = IMM_MAX_COPIED_VERTS;
IM->Count = IMM_MAX_COPIED_VERTS;
IM->Start = IMM_MAX_COPIED_VERTS;
IM->Material = 0;
IM->MaterialMask = 0;
IM->MaxTextureUnits = ctx->Const.MaxTextureUnits;
IM->TexSize = 0;
IM->NormalLengthPtr = 0;
IM->CopyTexSize = 0;
IM->CopyStart = IM->Start;
return IM;
}
static void real_free_immediate( struct immediate *IM )
{
static int freed = 0;
if (IM->Material) {
FREE( IM->Material );
FREE( IM->MaterialMask );
IM->Material = 0;
IM->MaterialMask = 0;
}
if (IM->NormalLengthPtr)
ALIGN_FREE( IM->NormalLengthPtr );
ALIGN_FREE( IM );
freed++;
}
struct immediate *_tnl_alloc_immediate( GLcontext *ctx )
{
TNLcontext *tnl = TNL_CONTEXT(ctx);
struct immediate *tmp = tnl->freed_immediate;
if (tmp) {
tnl->freed_immediate = 0;
return tmp;
}
else
return real_alloc_immediate( ctx );
}
void _tnl_free_immediate( GLcontext *ctx, struct immediate *IM )
{
TNLcontext *tnl = TNL_CONTEXT(ctx);
ASSERT(IM->ref_count == 0);
if (IM->NormalLengthPtr) {
ALIGN_FREE(IM->NormalLengthPtr);
IM->NormalLengthPtr = NULL;
}
if (!tnl) {
real_free_immediate( IM );
}
else {
if (tnl->freed_immediate)
real_free_immediate( tnl->freed_immediate );
tnl->freed_immediate = IM;
}
}