2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Keith Whitwell <keith@tungstengraphics.com>
29 #include "api_arrayelt.h"
38 #include "vbo_context.h"
41 #define NR_LEGACY_ATTRIBS 16
42 #define NR_GENERIC_ATTRIBS 16
43 #define NR_MAT_ATTRIBS 12
45 static void init_legacy_currval(GLcontext
*ctx
)
47 struct vbo_exec_context
*exec
= &vbo_context(ctx
)->exec
;
48 struct gl_client_array
*arrays
= exec
->legacy_currval
;
51 memset(arrays
, 0, sizeof(*arrays
) * NR_LEGACY_ATTRIBS
);
53 /* Set up a constant (StrideB == 0) array for each current
56 for (i
= 0; i
< NR_LEGACY_ATTRIBS
; i
++) {
57 struct gl_client_array
*cl
= &arrays
[i
];
60 case VBO_ATTRIB_EDGEFLAG
:
61 cl
->Type
= GL_UNSIGNED_BYTE
;
62 cl
->Ptr
= (const void *)&ctx
->Current
.EdgeFlag
;
64 case VBO_ATTRIB_INDEX
:
66 cl
->Ptr
= (const void *)&ctx
->Current
.Index
;
70 cl
->Ptr
= (const void *)ctx
->Current
.Attrib
[i
];
74 /* This will have to be determined at runtime:
80 cl
->BufferObj
= ctx
->Array
.NullBufferObj
;
85 static void init_generic_currval(GLcontext
*ctx
)
87 struct vbo_exec_context
*exec
= &vbo_context(ctx
)->exec
;
88 struct gl_client_array
*arrays
= exec
->generic_currval
;
91 memset(arrays
, 0, sizeof(*arrays
) * NR_GENERIC_ATTRIBS
);
93 for (i
= 0; i
< NR_GENERIC_ATTRIBS
; i
++) {
94 struct gl_client_array
*cl
= &arrays
[i
];
96 /* This will have to be determined at runtime:
101 cl
->Ptr
= (const void *)ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC0
+ i
];
105 cl
->BufferObj
= ctx
->Array
.NullBufferObj
;
110 static void init_mat_currval(GLcontext
*ctx
)
112 struct vbo_exec_context
*exec
= &vbo_context(ctx
)->exec
;
113 struct gl_client_array
*arrays
= exec
->mat_currval
;
116 memset(arrays
, 0, sizeof(*arrays
) * NR_GENERIC_ATTRIBS
);
118 /* Set up a constant (StrideB == 0) array for each current
121 for (i
= 0; i
< NR_GENERIC_ATTRIBS
; i
++) {
122 struct gl_client_array
*cl
= &arrays
[i
];
124 /* Size is fixed for the material attributes, for others will
125 * be determined at runtime:
127 switch (i
- VERT_ATTRIB_GENERIC0
) {
128 case MAT_ATTRIB_FRONT_SHININESS
:
129 case MAT_ATTRIB_BACK_SHININESS
:
132 case MAT_ATTRIB_FRONT_INDEXES
:
133 case MAT_ATTRIB_BACK_INDEXES
:
141 if (i
< MAT_ATTRIB_MAX
)
142 cl
->Ptr
= (const void *)ctx
->Light
.Material
.Attrib
[i
];
144 cl
->Ptr
= (const void *)ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC0
+ i
];
150 cl
->BufferObj
= ctx
->Array
.NullBufferObj
;
155 void vbo_exec_init( GLcontext
*ctx
)
157 struct vbo_exec_context
*exec
= &vbo_context(ctx
)->exec
;
161 /* Initialize the arrayelt helper
163 if (!ctx
->aelt_context
&&
164 !_ae_create_context( ctx
))
167 vbo_exec_vtx_init( exec
);
168 vbo_exec_array_init( exec
);
170 init_legacy_currval( ctx
);
171 init_generic_currval( ctx
);
172 init_mat_currval( ctx
);
174 ctx
->Driver
.NeedFlush
= 0;
175 ctx
->Driver
.CurrentExecPrimitive
= PRIM_OUTSIDE_BEGIN_END
;
176 ctx
->Driver
.FlushVertices
= vbo_exec_FlushVertices
;
178 exec
->eval
.recalculate_maps
= 1;
182 void vbo_exec_destroy( GLcontext
*ctx
)
184 struct vbo_exec_context
*exec
= &vbo_context(ctx
)->exec
;
186 if (ctx
->aelt_context
) {
187 _ae_destroy_context( ctx
);
188 ctx
->aelt_context
= NULL
;
191 vbo_exec_vtx_destroy( exec
);
192 vbo_exec_array_destroy( exec
);
195 /* Really want to install these callbacks to a central facility to be
196 * invoked according to the state flags. That will have to wait for a
199 void vbo_exec_invalidate_state( GLcontext
*ctx
, GLuint new_state
)
201 struct vbo_exec_context
*exec
= &vbo_context(ctx
)->exec
;
203 if (new_state
& (_NEW_PROGRAM
|_NEW_EVAL
))
204 exec
->eval
.recalculate_maps
= 1;
206 _ae_invalidate_state(ctx
, new_state
);
210 void vbo_exec_wakeup( GLcontext
*ctx
)
212 struct vbo_exec_context
*exec
= &vbo_context(ctx
)->exec
;
214 ctx
->Driver
.FlushVertices
= vbo_exec_FlushVertices
;
215 ctx
->Driver
.NeedFlush
|= FLUSH_UPDATE_CURRENT
;
217 /* Hook our functions into exec and compile dispatch tables.
219 _mesa_install_exec_vtxfmt( ctx
, &exec
->vtxfmt
);
221 /* Assume we haven't been getting state updates either:
223 vbo_exec_invalidate_state( ctx
, ~0 );