1 /* $Id: ac_context.c,v 1.9 2002/10/29 20:28:58 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>
36 #include "array_cache/ac_context.h"
40 * Initialize the array fallbacks. That is, by default the fallback arrays
41 * point into the current vertex attribute values in ctx->Current.Attrib[]
43 static void _ac_fallbacks_init( GLcontext
*ctx
)
45 ACcontext
*ac
= AC_CONTEXT(ctx
);
46 struct gl_client_array
*cl
;
49 cl
= &ac
->Fallback
.Normal
;
54 cl
->Ptr
= (void *) ctx
->Current
.Attrib
[VERT_ATTRIB_NORMAL
];
56 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
58 cl
= &ac
->Fallback
.Color
;
63 cl
->Ptr
= (void *) ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
];
65 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
67 cl
= &ac
->Fallback
.SecondaryColor
;
72 cl
->Ptr
= (void *) ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
];
74 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
76 cl
= &ac
->Fallback
.FogCoord
;
81 cl
->Ptr
= (void *) &ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
];
83 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
85 cl
= &ac
->Fallback
.Index
;
87 cl
->Type
= GL_UNSIGNED_INT
;
90 cl
->Ptr
= (void *) &ctx
->Current
.Index
;
92 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
94 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++) {
95 cl
= &ac
->Fallback
.TexCoord
[i
];
100 cl
->Ptr
= (void *) ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ i
];
102 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
105 cl
= &ac
->Fallback
.EdgeFlag
;
107 cl
->Type
= GL_UNSIGNED_BYTE
;
110 cl
->Ptr
= (void *) &ctx
->Current
.EdgeFlag
;
112 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
114 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
115 cl
= &ac
->Fallback
.Attrib
[i
];
120 cl
->Ptr
= (void *) ctx
->Current
.Attrib
[i
];
122 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
128 * Initialize the array cache pointers, types, strides, etc.
130 static void _ac_cache_init( GLcontext
*ctx
)
132 ACcontext
*ac
= AC_CONTEXT(ctx
);
133 struct gl_client_array
*cl
;
134 GLuint size
= ctx
->Const
.MaxArrayLockSize
+ MAX_CLIPPED_VERTICES
;
137 cl
= &ac
->Cache
.Vertex
;
141 cl
->StrideB
= 4 * sizeof(GLfloat
);
142 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
146 cl
= &ac
->Cache
.Normal
;
150 cl
->StrideB
= 3 * sizeof(GLfloat
);
151 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
155 cl
= &ac
->Cache
.Color
;
159 cl
->StrideB
= 4 * sizeof(GLfloat
);
160 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
164 cl
= &ac
->Cache
.SecondaryColor
;
168 cl
->StrideB
= 4 * sizeof(GLfloat
);
169 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
173 cl
= &ac
->Cache
.FogCoord
;
177 cl
->StrideB
= sizeof(GLfloat
);
178 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
182 cl
= &ac
->Cache
.Index
;
184 cl
->Type
= GL_UNSIGNED_INT
;
186 cl
->StrideB
= sizeof(GLuint
);
187 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
191 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
192 cl
= &ac
->Cache
.TexCoord
[i
];
196 cl
->StrideB
= 4 * sizeof(GLfloat
);
197 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
202 cl
= &ac
->Cache
.EdgeFlag
;
204 cl
->Type
= GL_UNSIGNED_BYTE
;
206 cl
->StrideB
= sizeof(GLubyte
);
207 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
211 for (i
= 0 ; i
< VERT_ATTRIB_MAX
; i
++) {
212 cl
= &ac
->Cache
.Attrib
[i
];
216 cl
->StrideB
= 4 * sizeof(GLfloat
);
217 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
224 /* This storage used to hold translated client data if type or stride
227 static void _ac_elts_init( GLcontext
*ctx
)
229 ACcontext
*ac
= AC_CONTEXT(ctx
);
232 ac
->Elts
= (GLuint
*)MALLOC( sizeof(GLuint
) * size
);
236 static void _ac_raw_init( GLcontext
*ctx
)
238 ACcontext
*ac
= AC_CONTEXT(ctx
);
241 ac
->Raw
.Color
= ac
->Fallback
.Color
;
242 ac
->Raw
.EdgeFlag
= ac
->Fallback
.EdgeFlag
;
243 ac
->Raw
.FogCoord
= ac
->Fallback
.FogCoord
;
244 ac
->Raw
.Index
= ac
->Fallback
.Index
;
245 ac
->Raw
.Normal
= ac
->Fallback
.Normal
;
246 ac
->Raw
.SecondaryColor
= ac
->Fallback
.SecondaryColor
;
247 ac
->Raw
.Vertex
= ctx
->Array
.Vertex
;
249 ac
->IsCached
.Color
= GL_FALSE
;
250 ac
->IsCached
.EdgeFlag
= GL_FALSE
;
251 ac
->IsCached
.FogCoord
= GL_FALSE
;
252 ac
->IsCached
.Index
= GL_FALSE
;
253 ac
->IsCached
.Normal
= GL_FALSE
;
254 ac
->IsCached
.SecondaryColor
= GL_FALSE
;
255 ac
->IsCached
.Vertex
= GL_FALSE
;
257 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++) {
258 ac
->Raw
.TexCoord
[i
] = ac
->Fallback
.TexCoord
[i
];
259 ac
->IsCached
.TexCoord
[i
] = GL_FALSE
;
262 for (i
= 0 ; i
< VERT_ATTRIB_MAX
; i
++) {
263 ac
->Raw
.Attrib
[i
] = ac
->Fallback
.Attrib
[i
];
264 ac
->IsCached
.Attrib
[i
] = GL_FALSE
;
268 GLboolean
_ac_CreateContext( GLcontext
*ctx
)
270 ctx
->acache_context
= CALLOC(sizeof(ACcontext
));
271 if (ctx
->acache_context
) {
272 _ac_cache_init( ctx
);
273 _ac_fallbacks_init( ctx
);
275 _ac_elts_init( ctx
);
281 void _ac_DestroyContext( GLcontext
*ctx
)
283 ACcontext
*ac
= AC_CONTEXT(ctx
);
286 if (ac
->Cache
.Vertex
.Ptr
) FREE( ac
->Cache
.Vertex
.Ptr
);
287 if (ac
->Cache
.Normal
.Ptr
) FREE( ac
->Cache
.Normal
.Ptr
);
288 if (ac
->Cache
.Color
.Ptr
) FREE( ac
->Cache
.Color
.Ptr
);
289 if (ac
->Cache
.SecondaryColor
.Ptr
) FREE( ac
->Cache
.SecondaryColor
.Ptr
);
290 if (ac
->Cache
.EdgeFlag
.Ptr
) FREE( ac
->Cache
.EdgeFlag
.Ptr
);
291 if (ac
->Cache
.Index
.Ptr
) FREE( ac
->Cache
.Index
.Ptr
);
292 if (ac
->Cache
.FogCoord
.Ptr
) FREE( ac
->Cache
.FogCoord
.Ptr
);
294 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
295 if (ac
->Cache
.TexCoord
[i
].Ptr
)
296 FREE( ac
->Cache
.TexCoord
[i
].Ptr
);
299 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
300 if (ac
->Cache
.Attrib
[i
].Ptr
)
301 FREE( ac
->Cache
.Attrib
[i
].Ptr
);
304 if (ac
->Elts
) FREE( ac
->Elts
);
306 /* Free the context structure itself */
308 ctx
->acache_context
= NULL
;
311 void _ac_InvalidateState( GLcontext
*ctx
, GLuint new_state
)
313 AC_CONTEXT(ctx
)->NewState
|= new_state
;
314 AC_CONTEXT(ctx
)->NewArrayState
|= ctx
->Array
.NewState
;