1 /* $Id: t_imm_alloc.c,v 1.17 2002/10/29 20:29:01 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * Keith Whitwell <keith@tungstengraphics.com>
34 #include "t_imm_alloc.h"
37 static int id
= 0; /* give each struct immediate a unique ID number */
39 static struct immediate
*real_alloc_immediate( GLcontext
*ctx
)
41 struct immediate
*IM
= ALIGN_CALLOC_STRUCT( immediate
, 32 );
46 /* memset(IM, 0, sizeof(*IM)); */
51 IM
->LastPrimitive
= IMM_MAX_COPIED_VERTS
;
52 IM
->Count
= IMM_MAX_COPIED_VERTS
;
53 IM
->Start
= IMM_MAX_COPIED_VERTS
;
56 IM
->MaxTextureUnits
= ctx
->Const
.MaxTextureUnits
;
58 IM
->NormalLengthPtr
= 0;
61 IM
->CopyStart
= IM
->Start
;
67 static void real_free_immediate( struct immediate
*IM
)
73 FREE( IM
->MaterialMask
);
78 if (IM
->NormalLengthPtr
)
79 ALIGN_FREE( IM
->NormalLengthPtr
);
83 /* printf("outstanding %d\n", id - freed); */
87 /* Cache a single allocated immediate struct.
89 struct immediate
*_tnl_alloc_immediate( GLcontext
*ctx
)
91 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
92 struct immediate
*tmp
= tnl
->freed_immediate
;
95 tnl
->freed_immediate
= 0;
99 return real_alloc_immediate( ctx
);
102 /* May be called after tnl is destroyed.
104 void _tnl_free_immediate( GLcontext
*ctx
, struct immediate
*IM
)
106 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
108 ASSERT(IM
->ref_count
== 0);
110 if (IM
->NormalLengthPtr
) {
111 ALIGN_FREE(IM
->NormalLengthPtr
);
112 IM
->NormalLengthPtr
= NULL
;
116 real_free_immediate( IM
);
119 if (tnl
->freed_immediate
)
120 real_free_immediate( tnl
->freed_immediate
);
122 tnl
->freed_immediate
= IM
;