fixed a bunch of g++ warnings/errors. Compiling with g++ can help find lots of poten...
[mesa.git] / src / mesa / tnl / t_imm_alloc.c
1 /* $Id: t_imm_alloc.c,v 1.4 2001/03/07 05:06:13 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 *
26 * Authors:
27 * Keith Whitwell <keithw@valinux.com>
28 */
29
30 #include "glheader.h"
31 #include "mem.h"
32 #include "mtypes.h"
33
34 #include "t_imm_alloc.h"
35
36
37 static int id = 0;
38
39 struct immediate *_tnl_alloc_immediate( GLcontext *ctx )
40 {
41 struct immediate *IM = ALIGN_MALLOC_STRUCT( immediate, 32 );
42 GLuint j;
43
44 if (!IM)
45 return 0;
46
47 IM->id = id++;
48 IM->ref_count = 0;
49 IM->backref = ctx;
50 IM->FlushElt = 0;
51 IM->LastPrimitive = IMM_MAX_COPIED_VERTS;
52 IM->Count = IMM_MAX_COPIED_VERTS;
53 IM->Start = IMM_MAX_COPIED_VERTS;
54 IM->Material = 0;
55 IM->MaterialMask = 0;
56 IM->MaxTextureUnits = ctx->Const.MaxTextureUnits;
57 IM->TexSize = 0;
58
59 IM->CopyTexSize = 0;
60 IM->CopyStart = IM->Start;
61
62
63 /* TexCoord0 is special.
64 */
65 IM->TexCoord[0] = IM->TexCoord0;
66
67 for (j = 1; j < ctx->Const.MaxTextureUnits; j++) {
68 IM->TexCoord[j] = (GLfloat (*)[4])
69 ALIGN_MALLOC( IMM_SIZE * sizeof(GLfloat) * 4, 32 );
70 }
71
72 /* KW: Removed initialization of normals as these are now treated
73 * identically to all other data types.
74 */
75
76 MEMSET(IM->Flag, 0, sizeof(IM->Flag));
77
78 return IM;
79 }
80
81
82 void _tnl_free_immediate( struct immediate *IM )
83 {
84 static int freed = 0;
85 GLuint j;
86
87 if (IM->Material) {
88 FREE( IM->Material );
89 FREE( IM->MaterialMask );
90 IM->Material = 0;
91 IM->MaterialMask = 0;
92 }
93
94 for (j = 1; j < IM->MaxTextureUnits; j++)
95 ALIGN_FREE( IM->TexCoord[j] );
96
97
98 ALIGN_FREE( IM );
99 freed++;
100 /* printf("outstanding %d\n", id - freed); */
101 }
102
103
104