1 /* $Id: ac_context.c,v 1.2 2001/02/04 00:47:28 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 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 <keithw@valinux.com>
36 #include "array_cache/ac_context.h"
38 static void _ac_fallbacks_init( GLcontext
*ctx
)
40 ACcontext
*ac
= AC_CONTEXT(ctx
);
41 struct gl_client_array
*cl
;
44 cl
= &ac
->Fallback
.Normal
;
49 cl
->Ptr
= (void *) ctx
->Current
.Normal
;
52 cl
= &ac
->Fallback
.Color
;
54 cl
->Type
= GL_UNSIGNED_BYTE
;
57 cl
->Ptr
= (void *) ctx
->Current
.Color
;
60 cl
= &ac
->Fallback
.SecondaryColor
;
62 cl
->Type
= GL_UNSIGNED_BYTE
;
65 cl
->Ptr
= (void *) ctx
->Current
.SecondaryColor
;
68 cl
= &ac
->Fallback
.FogCoord
;
73 cl
->Ptr
= (void *) &ctx
->Current
.FogCoord
;
76 cl
= &ac
->Fallback
.Index
;
78 cl
->Type
= GL_UNSIGNED_INT
;
81 cl
->Ptr
= (void *) &ctx
->Current
.Index
;
84 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++) {
85 cl
= &ac
->Fallback
.TexCoord
[i
];
90 cl
->Ptr
= (void *) ctx
->Current
.Texcoord
[i
];
94 cl
= &ac
->Fallback
.EdgeFlag
;
96 cl
->Type
= GL_UNSIGNED_BYTE
;
99 cl
->Ptr
= (void *) &ctx
->Current
.EdgeFlag
;
104 static void _ac_cache_init( GLcontext
*ctx
)
106 ACcontext
*ac
= AC_CONTEXT(ctx
);
107 struct gl_client_array
*cl
;
108 GLuint size
= ctx
->Const
.MaxArrayLockSize
+ MAX_CLIPPED_VERTICES
;
111 cl
= &ac
->Cache
.Vertex
;
115 cl
->StrideB
= 4 * sizeof(GLfloat
);
116 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
119 cl
= &ac
->Cache
.Normal
;
123 cl
->StrideB
= 3 * sizeof(GLfloat
);
124 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
127 cl
= &ac
->Cache
.Color
;
129 cl
->Type
= GL_UNSIGNED_BYTE
;
131 cl
->StrideB
= 4 * sizeof(GLubyte
);
132 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
135 cl
= &ac
->Cache
.SecondaryColor
;
137 cl
->Type
= GL_UNSIGNED_BYTE
;
139 cl
->StrideB
= 4 * sizeof(GLubyte
);
140 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
143 cl
= &ac
->Cache
.FogCoord
;
147 cl
->StrideB
= sizeof(GLfloat
);
148 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
151 cl
= &ac
->Cache
.Index
;
153 cl
->Type
= GL_UNSIGNED_INT
;
155 cl
->StrideB
= sizeof(GLuint
);
156 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
159 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++) {
160 cl
= &ac
->Cache
.TexCoord
[i
];
164 cl
->StrideB
= 4 * sizeof(GLfloat
);
165 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
169 cl
= &ac
->Cache
.EdgeFlag
;
171 cl
->Type
= GL_UNSIGNED_BYTE
;
173 cl
->StrideB
= sizeof(GLubyte
);
174 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
179 /* This storage used to hold translated client data if type or stride
182 static void _ac_elts_init( GLcontext
*ctx
)
184 ACcontext
*ac
= AC_CONTEXT(ctx
);
187 ac
->Elts
= (GLuint
*)MALLOC( sizeof(GLuint
) * size
);
191 static void _ac_raw_init( GLcontext
*ctx
)
193 ACcontext
*ac
= AC_CONTEXT(ctx
);
196 ac
->Raw
.Color
= ac
->Fallback
.Color
;
197 ac
->Raw
.EdgeFlag
= ac
->Fallback
.EdgeFlag
;
198 ac
->Raw
.FogCoord
= ac
->Fallback
.FogCoord
;
199 ac
->Raw
.Index
= ac
->Fallback
.Index
;
200 ac
->Raw
.Normal
= ac
->Fallback
.Normal
;
201 ac
->Raw
.SecondaryColor
= ac
->Fallback
.SecondaryColor
;
202 ac
->Raw
.Vertex
= ctx
->Array
.Vertex
;
204 ac
->IsCached
.Color
= GL_FALSE
;
205 ac
->IsCached
.EdgeFlag
= GL_FALSE
;
206 ac
->IsCached
.FogCoord
= GL_FALSE
;
207 ac
->IsCached
.Index
= GL_FALSE
;
208 ac
->IsCached
.Normal
= GL_FALSE
;
209 ac
->IsCached
.SecondaryColor
= GL_FALSE
;
210 ac
->IsCached
.Vertex
= GL_FALSE
;
212 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++) {
213 ac
->Raw
.TexCoord
[i
] = ac
->Fallback
.TexCoord
[i
];
214 ac
->IsCached
.TexCoord
[i
] = GL_FALSE
;
219 GLboolean
_ac_CreateContext( GLcontext
*ctx
)
221 ctx
->acache_context
= CALLOC(sizeof(ACcontext
));
222 if (ctx
->acache_context
) {
223 _ac_cache_init( ctx
);
224 _ac_fallbacks_init( ctx
);
226 _ac_elts_init( ctx
);
232 void _ac_DestroyContext( GLcontext
*ctx
)
234 ACcontext
*ac
= AC_CONTEXT(ctx
);
237 if (ac
->Cache
.Vertex
.Ptr
) FREE( ac
->Cache
.Vertex
.Ptr
);
238 if (ac
->Cache
.Normal
.Ptr
) FREE( ac
->Cache
.Normal
.Ptr
);
239 if (ac
->Cache
.Color
.Ptr
) FREE( ac
->Cache
.Color
.Ptr
);
240 if (ac
->Cache
.SecondaryColor
.Ptr
) FREE( ac
->Cache
.SecondaryColor
.Ptr
);
241 if (ac
->Cache
.EdgeFlag
.Ptr
) FREE( ac
->Cache
.EdgeFlag
.Ptr
);
242 if (ac
->Cache
.Index
.Ptr
) FREE( ac
->Cache
.Index
.Ptr
);
243 if (ac
->Cache
.FogCoord
.Ptr
) FREE( ac
->Cache
.FogCoord
.Ptr
);
245 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
246 if (ac
->Cache
.TexCoord
[i
].Ptr
)
247 FREE( ac
->Cache
.TexCoord
[i
].Ptr
);
250 if (ac
->Elts
) FREE( ac
->Elts
);
253 void _ac_InvalidateState( GLcontext
*ctx
, GLuint new_state
)
255 AC_CONTEXT(ctx
)->NewState
|= new_state
;
256 AC_CONTEXT(ctx
)->NewArrayState
|= ctx
->Array
.NewState
;