28d4b225feb7318c01b13a1be73e89e2b3754133
1 /* $Id: ac_context.c,v 1.11 2003/03/01 01:50:24 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>
35 #include "array_cache/ac_context.h"
39 * Initialize the array fallbacks. That is, by default the fallback arrays
40 * point into the current vertex attribute values in ctx->Current.Attrib[]
42 static void _ac_fallbacks_init( GLcontext
*ctx
)
44 ACcontext
*ac
= AC_CONTEXT(ctx
);
45 struct gl_client_array
*cl
;
48 cl
= &ac
->Fallback
.Normal
;
53 cl
->Ptr
= (void *) ctx
->Current
.Attrib
[VERT_ATTRIB_NORMAL
];
55 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
57 cl
= &ac
->Fallback
.Color
;
62 cl
->Ptr
= (void *) ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
];
64 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
66 cl
= &ac
->Fallback
.SecondaryColor
;
71 cl
->Ptr
= (void *) ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
];
73 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
75 cl
= &ac
->Fallback
.FogCoord
;
80 cl
->Ptr
= (void *) &ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
];
82 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
84 cl
= &ac
->Fallback
.Index
;
86 cl
->Type
= GL_UNSIGNED_INT
;
89 cl
->Ptr
= (void *) &ctx
->Current
.Index
;
91 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
93 for (i
= 0 ; i
< MAX_TEXTURE_COORD_UNITS
; i
++) {
94 cl
= &ac
->Fallback
.TexCoord
[i
];
99 cl
->Ptr
= (void *) ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ i
];
101 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
104 cl
= &ac
->Fallback
.EdgeFlag
;
106 cl
->Type
= GL_UNSIGNED_BYTE
;
109 cl
->Ptr
= (void *) &ctx
->Current
.EdgeFlag
;
111 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
113 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
114 cl
= &ac
->Fallback
.Attrib
[i
];
119 cl
->Ptr
= (void *) ctx
->Current
.Attrib
[i
];
121 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
127 * Initialize the array cache pointers, types, strides, etc.
129 static void _ac_cache_init( GLcontext
*ctx
)
131 ACcontext
*ac
= AC_CONTEXT(ctx
);
132 struct gl_client_array
*cl
;
133 GLuint size
= ctx
->Const
.MaxArrayLockSize
+ MAX_CLIPPED_VERTICES
;
136 cl
= &ac
->Cache
.Vertex
;
140 cl
->StrideB
= 4 * sizeof(GLfloat
);
141 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
145 cl
= &ac
->Cache
.Normal
;
149 cl
->StrideB
= 3 * sizeof(GLfloat
);
150 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
154 cl
= &ac
->Cache
.Color
;
158 cl
->StrideB
= 4 * sizeof(GLfloat
);
159 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
163 cl
= &ac
->Cache
.SecondaryColor
;
167 cl
->StrideB
= 4 * sizeof(GLfloat
);
168 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
172 cl
= &ac
->Cache
.FogCoord
;
176 cl
->StrideB
= sizeof(GLfloat
);
177 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
181 cl
= &ac
->Cache
.Index
;
183 cl
->Type
= GL_UNSIGNED_INT
;
185 cl
->StrideB
= sizeof(GLuint
);
186 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
190 for (i
= 0; i
< MAX_TEXTURE_COORD_UNITS
; i
++) {
191 cl
= &ac
->Cache
.TexCoord
[i
];
195 cl
->StrideB
= 4 * sizeof(GLfloat
);
196 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
201 cl
= &ac
->Cache
.EdgeFlag
;
203 cl
->Type
= GL_UNSIGNED_BYTE
;
205 cl
->StrideB
= sizeof(GLubyte
);
206 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
210 for (i
= 0 ; i
< VERT_ATTRIB_MAX
; i
++) {
211 cl
= &ac
->Cache
.Attrib
[i
];
215 cl
->StrideB
= 4 * sizeof(GLfloat
);
216 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
223 /* This storage used to hold translated client data if type or stride
226 static void _ac_elts_init( GLcontext
*ctx
)
228 ACcontext
*ac
= AC_CONTEXT(ctx
);
231 ac
->Elts
= (GLuint
*)MALLOC( sizeof(GLuint
) * size
);
235 static void _ac_raw_init( GLcontext
*ctx
)
237 ACcontext
*ac
= AC_CONTEXT(ctx
);
240 ac
->Raw
.Color
= ac
->Fallback
.Color
;
241 ac
->Raw
.EdgeFlag
= ac
->Fallback
.EdgeFlag
;
242 ac
->Raw
.FogCoord
= ac
->Fallback
.FogCoord
;
243 ac
->Raw
.Index
= ac
->Fallback
.Index
;
244 ac
->Raw
.Normal
= ac
->Fallback
.Normal
;
245 ac
->Raw
.SecondaryColor
= ac
->Fallback
.SecondaryColor
;
246 ac
->Raw
.Vertex
= ctx
->Array
.Vertex
;
248 ac
->IsCached
.Color
= GL_FALSE
;
249 ac
->IsCached
.EdgeFlag
= GL_FALSE
;
250 ac
->IsCached
.FogCoord
= GL_FALSE
;
251 ac
->IsCached
.Index
= GL_FALSE
;
252 ac
->IsCached
.Normal
= GL_FALSE
;
253 ac
->IsCached
.SecondaryColor
= GL_FALSE
;
254 ac
->IsCached
.Vertex
= GL_FALSE
;
256 for (i
= 0 ; i
< MAX_TEXTURE_COORD_UNITS
; i
++) {
257 ac
->Raw
.TexCoord
[i
] = ac
->Fallback
.TexCoord
[i
];
258 ac
->IsCached
.TexCoord
[i
] = GL_FALSE
;
261 for (i
= 0 ; i
< VERT_ATTRIB_MAX
; i
++) {
262 ac
->Raw
.Attrib
[i
] = ac
->Fallback
.Attrib
[i
];
263 ac
->IsCached
.Attrib
[i
] = GL_FALSE
;
267 GLboolean
_ac_CreateContext( GLcontext
*ctx
)
269 ctx
->acache_context
= CALLOC(sizeof(ACcontext
));
270 if (ctx
->acache_context
) {
271 _ac_cache_init( ctx
);
272 _ac_fallbacks_init( ctx
);
274 _ac_elts_init( ctx
);
280 void _ac_DestroyContext( GLcontext
*ctx
)
282 ACcontext
*ac
= AC_CONTEXT(ctx
);
285 if (ac
->Cache
.Vertex
.Ptr
) FREE( ac
->Cache
.Vertex
.Ptr
);
286 if (ac
->Cache
.Normal
.Ptr
) FREE( ac
->Cache
.Normal
.Ptr
);
287 if (ac
->Cache
.Color
.Ptr
) FREE( ac
->Cache
.Color
.Ptr
);
288 if (ac
->Cache
.SecondaryColor
.Ptr
) FREE( ac
->Cache
.SecondaryColor
.Ptr
);
289 if (ac
->Cache
.EdgeFlag
.Ptr
) FREE( ac
->Cache
.EdgeFlag
.Ptr
);
290 if (ac
->Cache
.Index
.Ptr
) FREE( ac
->Cache
.Index
.Ptr
);
291 if (ac
->Cache
.FogCoord
.Ptr
) FREE( ac
->Cache
.FogCoord
.Ptr
);
293 for (i
= 0; i
< MAX_TEXTURE_COORD_UNITS
; i
++) {
294 if (ac
->Cache
.TexCoord
[i
].Ptr
)
295 FREE( ac
->Cache
.TexCoord
[i
].Ptr
);
298 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
299 if (ac
->Cache
.Attrib
[i
].Ptr
)
300 FREE( ac
->Cache
.Attrib
[i
].Ptr
);
303 if (ac
->Elts
) FREE( ac
->Elts
);
305 /* Free the context structure itself */
307 ctx
->acache_context
= NULL
;
310 void _ac_InvalidateState( GLcontext
*ctx
, GLuint new_state
)
312 AC_CONTEXT(ctx
)->NewState
|= new_state
;
313 AC_CONTEXT(ctx
)->NewArrayState
|= ctx
->Array
.NewState
;