1 /* $Id: ac_context.c,v 1.6 2001/12/14 02:50:57 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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
.Attrib
[VERT_ATTRIB_NORMAL
];
51 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
53 cl
= &ac
->Fallback
.Color
;
58 cl
->Ptr
= (void *) ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
];
60 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
62 cl
= &ac
->Fallback
.SecondaryColor
;
67 cl
->Ptr
= (void *) ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
];
69 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
71 cl
= &ac
->Fallback
.FogCoord
;
76 cl
->Ptr
= (void *) &ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
];
78 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
80 cl
= &ac
->Fallback
.Index
;
82 cl
->Type
= GL_UNSIGNED_INT
;
85 cl
->Ptr
= (void *) &ctx
->Current
.Index
;
87 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
89 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++) {
90 cl
= &ac
->Fallback
.TexCoord
[i
];
95 cl
->Ptr
= (void *) ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ i
];
97 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
100 cl
= &ac
->Fallback
.EdgeFlag
;
102 cl
->Type
= GL_UNSIGNED_BYTE
;
105 cl
->Ptr
= (void *) &ctx
->Current
.EdgeFlag
;
107 cl
->Flags
= CA_CLIENT_DATA
; /* hack */
111 static void _ac_cache_init( GLcontext
*ctx
)
113 ACcontext
*ac
= AC_CONTEXT(ctx
);
114 struct gl_client_array
*cl
;
115 GLuint size
= ctx
->Const
.MaxArrayLockSize
+ MAX_CLIPPED_VERTICES
;
118 cl
= &ac
->Cache
.Vertex
;
122 cl
->StrideB
= 4 * sizeof(GLfloat
);
123 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
127 cl
= &ac
->Cache
.Normal
;
131 cl
->StrideB
= 3 * sizeof(GLfloat
);
132 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
136 cl
= &ac
->Cache
.Color
;
140 cl
->StrideB
= 4 * sizeof(GLfloat
);
141 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
145 cl
= &ac
->Cache
.SecondaryColor
;
149 cl
->StrideB
= 4 * sizeof(GLfloat
);
150 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
154 cl
= &ac
->Cache
.FogCoord
;
158 cl
->StrideB
= sizeof(GLfloat
);
159 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
163 cl
= &ac
->Cache
.Index
;
165 cl
->Type
= GL_UNSIGNED_INT
;
167 cl
->StrideB
= sizeof(GLuint
);
168 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
172 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++) {
173 cl
= &ac
->Cache
.TexCoord
[i
];
177 cl
->StrideB
= 4 * sizeof(GLfloat
);
178 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
183 cl
= &ac
->Cache
.EdgeFlag
;
185 cl
->Type
= GL_UNSIGNED_BYTE
;
187 cl
->StrideB
= sizeof(GLubyte
);
188 cl
->Ptr
= MALLOC( cl
->StrideB
* size
);
194 /* This storage used to hold translated client data if type or stride
197 static void _ac_elts_init( GLcontext
*ctx
)
199 ACcontext
*ac
= AC_CONTEXT(ctx
);
202 ac
->Elts
= (GLuint
*)MALLOC( sizeof(GLuint
) * size
);
206 static void _ac_raw_init( GLcontext
*ctx
)
208 ACcontext
*ac
= AC_CONTEXT(ctx
);
211 ac
->Raw
.Color
= ac
->Fallback
.Color
;
212 ac
->Raw
.EdgeFlag
= ac
->Fallback
.EdgeFlag
;
213 ac
->Raw
.FogCoord
= ac
->Fallback
.FogCoord
;
214 ac
->Raw
.Index
= ac
->Fallback
.Index
;
215 ac
->Raw
.Normal
= ac
->Fallback
.Normal
;
216 ac
->Raw
.SecondaryColor
= ac
->Fallback
.SecondaryColor
;
217 ac
->Raw
.Vertex
= ctx
->Array
.Vertex
;
219 ac
->IsCached
.Color
= GL_FALSE
;
220 ac
->IsCached
.EdgeFlag
= GL_FALSE
;
221 ac
->IsCached
.FogCoord
= GL_FALSE
;
222 ac
->IsCached
.Index
= GL_FALSE
;
223 ac
->IsCached
.Normal
= GL_FALSE
;
224 ac
->IsCached
.SecondaryColor
= GL_FALSE
;
225 ac
->IsCached
.Vertex
= GL_FALSE
;
227 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++) {
228 ac
->Raw
.TexCoord
[i
] = ac
->Fallback
.TexCoord
[i
];
229 ac
->IsCached
.TexCoord
[i
] = GL_FALSE
;
234 GLboolean
_ac_CreateContext( GLcontext
*ctx
)
236 ctx
->acache_context
= CALLOC(sizeof(ACcontext
));
237 if (ctx
->acache_context
) {
238 _ac_cache_init( ctx
);
239 _ac_fallbacks_init( ctx
);
241 _ac_elts_init( ctx
);
247 void _ac_DestroyContext( GLcontext
*ctx
)
249 ACcontext
*ac
= AC_CONTEXT(ctx
);
252 if (ac
->Cache
.Vertex
.Ptr
) FREE( ac
->Cache
.Vertex
.Ptr
);
253 if (ac
->Cache
.Normal
.Ptr
) FREE( ac
->Cache
.Normal
.Ptr
);
254 if (ac
->Cache
.Color
.Ptr
) FREE( ac
->Cache
.Color
.Ptr
);
255 if (ac
->Cache
.SecondaryColor
.Ptr
) FREE( ac
->Cache
.SecondaryColor
.Ptr
);
256 if (ac
->Cache
.EdgeFlag
.Ptr
) FREE( ac
->Cache
.EdgeFlag
.Ptr
);
257 if (ac
->Cache
.Index
.Ptr
) FREE( ac
->Cache
.Index
.Ptr
);
258 if (ac
->Cache
.FogCoord
.Ptr
) FREE( ac
->Cache
.FogCoord
.Ptr
);
260 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
261 if (ac
->Cache
.TexCoord
[i
].Ptr
)
262 FREE( ac
->Cache
.TexCoord
[i
].Ptr
);
265 if (ac
->Elts
) FREE( ac
->Elts
);
267 /* Free the context structure itself */
269 ctx
->acache_context
= NULL
;
272 void _ac_InvalidateState( GLcontext
*ctx
, GLuint new_state
)
274 AC_CONTEXT(ctx
)->NewState
|= new_state
;
275 AC_CONTEXT(ctx
)->NewArrayState
|= ctx
->Array
.NewState
;