Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
57 pj 1
/* $Id: ac_context.c,v 1.1 2003-02-28 11:49:40 pj Exp $ */
2
 
3
/*
4
 * Mesa 3-D graphics library
5
 * Version:  4.1
6
 *
7
 * Copyright (C) 1999-2002  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 <keith@tungstengraphics.com>
28
 */
29
 
30
#include "glheader.h"
31
#include "macros.h"
32
#include "imports.h"
33
#include "mmath.h"
34
#include "mtypes.h"
35
 
36
#include "array_cache/ac_context.h"
37
 
38
 
39
/*
40
 * Initialize the array fallbacks.  That is, by default the fallback arrays
41
 * point into the current vertex attribute values in ctx->Current.Attrib[]
42
 */
43
static void _ac_fallbacks_init( GLcontext *ctx )
44
{
45
   ACcontext *ac = AC_CONTEXT(ctx);
46
   struct gl_client_array *cl;
47
   GLuint i;
48
 
49
   cl = &ac->Fallback.Normal;
50
   cl->Size = 3;
51
   cl->Type = GL_FLOAT;
52
   cl->Stride = 0;
53
   cl->StrideB = 0;
54
   cl->Ptr = (void *) ctx->Current.Attrib[VERT_ATTRIB_NORMAL];
55
   cl->Enabled = 1;
56
   cl->Flags = CA_CLIENT_DATA;  /* hack */
57
 
58
   cl = &ac->Fallback.Color;
59
   cl->Size = 4;
60
   cl->Type = GL_FLOAT;
61
   cl->Stride = 0;
62
   cl->StrideB = 0;
63
   cl->Ptr = (void *) ctx->Current.Attrib[VERT_ATTRIB_COLOR0];
64
   cl->Enabled = 1;
65
   cl->Flags = CA_CLIENT_DATA;  /* hack */
66
 
67
   cl = &ac->Fallback.SecondaryColor;
68
   cl->Size = 3;
69
   cl->Type = GL_FLOAT;
70
   cl->Stride = 0;
71
   cl->StrideB = 0;
72
   cl->Ptr = (void *) ctx->Current.Attrib[VERT_ATTRIB_COLOR1];
73
   cl->Enabled = 1;
74
   cl->Flags = CA_CLIENT_DATA;  /* hack */
75
 
76
   cl = &ac->Fallback.FogCoord;
77
   cl->Size = 1;
78
   cl->Type = GL_FLOAT;
79
   cl->Stride = 0;
80
   cl->StrideB = 0;
81
   cl->Ptr = (void *) &ctx->Current.Attrib[VERT_ATTRIB_FOG];
82
   cl->Enabled = 1;
83
   cl->Flags = CA_CLIENT_DATA;  /* hack */
84
 
85
   cl = &ac->Fallback.Index;
86
   cl->Size = 1;
87
   cl->Type = GL_UNSIGNED_INT;
88
   cl->Stride = 0;
89
   cl->StrideB = 0;
90
   cl->Ptr = (void *) &ctx->Current.Index;
91
   cl->Enabled = 1;
92
   cl->Flags = CA_CLIENT_DATA;  /* hack */
93
 
94
   for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
95
      cl = &ac->Fallback.TexCoord[i];
96
      cl->Size = 4;
97
      cl->Type = GL_FLOAT;
98
      cl->Stride = 0;
99
      cl->StrideB = 0;
100
      cl->Ptr = (void *) ctx->Current.Attrib[VERT_ATTRIB_TEX0 + i];
101
      cl->Enabled = 1;
102
      cl->Flags = CA_CLIENT_DATA;       /* hack */
103
   }
104
 
105
   cl = &ac->Fallback.EdgeFlag;
106
   cl->Size = 1;
107
   cl->Type = GL_UNSIGNED_BYTE;
108
   cl->Stride = 0;
109
   cl->StrideB = 0;
110
   cl->Ptr = (void *) &ctx->Current.EdgeFlag;
111
   cl->Enabled = 1;
112
   cl->Flags = CA_CLIENT_DATA;  /* hack */
113
 
114
   for (i = 0; i < VERT_ATTRIB_MAX; i++) {
115
      cl = &ac->Fallback.Attrib[i];
116
      cl->Size = 4;
117
      cl->Type = GL_FLOAT;
118
      cl->Stride = 0;
119
      cl->StrideB = 0;
120
      cl->Ptr = (void *) ctx->Current.Attrib[i];
121
      cl->Enabled = 1;
122
      cl->Flags = CA_CLIENT_DATA; /* hack */
123
   }
124
}
125
 
126
 
127
/*
128
 * Initialize the array cache pointers, types, strides, etc.
129
 */
130
static void _ac_cache_init( GLcontext *ctx )
131
{
132
   ACcontext *ac = AC_CONTEXT(ctx);
133
   struct gl_client_array *cl;
134
   GLuint size = ctx->Const.MaxArrayLockSize + MAX_CLIPPED_VERTICES;
135
   GLuint i;
136
 
137
   cl = &ac->Cache.Vertex;
138
   cl->Size = 4;
139
   cl->Type = GL_FLOAT;
140
   cl->Stride = 0;
141
   cl->StrideB = 4 * sizeof(GLfloat);
142
   cl->Ptr = MALLOC( cl->StrideB * size );
143
   cl->Enabled = 1;
144
   cl->Flags = 0;
145
 
146
   cl = &ac->Cache.Normal;
147
   cl->Size = 3;
148
   cl->Type = GL_FLOAT;
149
   cl->Stride = 0;
150
   cl->StrideB = 3 * sizeof(GLfloat);
151
   cl->Ptr = MALLOC( cl->StrideB * size );
152
   cl->Enabled = 1;
153
   cl->Flags = 0;
154
 
155
   cl = &ac->Cache.Color;
156
   cl->Size = 4;
157
   cl->Type = GL_FLOAT;
158
   cl->Stride = 0;
159
   cl->StrideB = 4 * sizeof(GLfloat);
160
   cl->Ptr = MALLOC( cl->StrideB * size );
161
   cl->Enabled = 1;
162
   cl->Flags = 0;
163
 
164
   cl = &ac->Cache.SecondaryColor;
165
   cl->Size = 3;
166
   cl->Type = GL_FLOAT;
167
   cl->Stride = 0;
168
   cl->StrideB = 4 * sizeof(GLfloat);
169
   cl->Ptr = MALLOC( cl->StrideB * size );
170
   cl->Enabled = 1;
171
   cl->Flags = 0;
172
 
173
   cl = &ac->Cache.FogCoord;
174
   cl->Size = 1;
175
   cl->Type = GL_FLOAT;
176
   cl->Stride = 0;
177
   cl->StrideB = sizeof(GLfloat);
178
   cl->Ptr = MALLOC( cl->StrideB * size );
179
   cl->Enabled = 1;
180
   cl->Flags = 0;
181
 
182
   cl = &ac->Cache.Index;
183
   cl->Size = 1;
184
   cl->Type = GL_UNSIGNED_INT;
185
   cl->Stride = 0;
186
   cl->StrideB = sizeof(GLuint);
187
   cl->Ptr = MALLOC( cl->StrideB * size );
188
   cl->Enabled = 1;
189
   cl->Flags = 0;
190
 
191
   for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
192
      cl = &ac->Cache.TexCoord[i];
193
      cl->Size = 4;
194
      cl->Type = GL_FLOAT;
195
      cl->Stride = 0;
196
      cl->StrideB = 4 * sizeof(GLfloat);
197
      cl->Ptr = MALLOC( cl->StrideB * size );
198
      cl->Enabled = 1;
199
      cl->Flags = 0;
200
   }
201
 
202
   cl = &ac->Cache.EdgeFlag;
203
   cl->Size = 1;
204
   cl->Type = GL_UNSIGNED_BYTE;
205
   cl->Stride = 0;
206
   cl->StrideB = sizeof(GLubyte);
207
   cl->Ptr = MALLOC( cl->StrideB * size );
208
   cl->Enabled = 1;
209
   cl->Flags = 0;
210
 
211
   for (i = 0 ; i < VERT_ATTRIB_MAX; i++) {
212
      cl = &ac->Cache.Attrib[i];
213
      cl->Size = 4;
214
      cl->Type = GL_FLOAT;
215
      cl->Stride = 0;
216
      cl->StrideB = 4 * sizeof(GLfloat);
217
      cl->Ptr = MALLOC( cl->StrideB * size );
218
      cl->Enabled = 1;
219
      cl->Flags = 0;
220
   }
221
}
222
 
223
 
224
/* This storage used to hold translated client data if type or stride
225
 * need to be fixed.
226
 */
227
static void _ac_elts_init( GLcontext *ctx )
228
{
229
   ACcontext *ac = AC_CONTEXT(ctx);
230
   GLuint size = 1000;
231
 
232
   ac->Elts = (GLuint *)MALLOC( sizeof(GLuint) * size );
233
   ac->elt_size = size;
234
}
235
 
236
static void _ac_raw_init( GLcontext *ctx )
237
{
238
   ACcontext *ac = AC_CONTEXT(ctx);
239
   GLuint i;
240
 
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;
248
 
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;
256
 
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;
260
   }
261
 
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;
265
   }
266
}
267
 
268
GLboolean _ac_CreateContext( GLcontext *ctx )
269
{
270
   ctx->acache_context = CALLOC(sizeof(ACcontext));
271
   if (ctx->acache_context) {
272
      _ac_cache_init( ctx );
273
      _ac_fallbacks_init( ctx );
274
      _ac_raw_init( ctx );
275
      _ac_elts_init( ctx );
276
      return GL_TRUE;
277
   }
278
   return GL_FALSE;
279
}
280
 
281
void _ac_DestroyContext( GLcontext *ctx )
282
{
283
   ACcontext *ac = AC_CONTEXT(ctx);
284
   GLint i;
285
 
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 );
293
 
294
   for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
295
      if (ac->Cache.TexCoord[i].Ptr)
296
         FREE( ac->Cache.TexCoord[i].Ptr );
297
   }
298
 
299
   for (i = 0; i < VERT_ATTRIB_MAX; i++) {
300
      if (ac->Cache.Attrib[i].Ptr)
301
         FREE( ac->Cache.Attrib[i].Ptr );
302
   }
303
 
304
   if (ac->Elts) FREE( ac->Elts );
305
 
306
   /* Free the context structure itself */
307
   FREE(ac);
308
   ctx->acache_context = NULL;
309
}
310
 
311
void _ac_InvalidateState( GLcontext *ctx, GLuint new_state )
312
{
313
   AC_CONTEXT(ctx)->NewState |= new_state;
314
   AC_CONTEXT(ctx)->NewArrayState |= ctx->Array.NewState;
315
}