i965: disable using immediate values for MOV instructions
[mesa.git] / src / mesa / vbo / vbo_context.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.3
4 *
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 *
24 * Authors:
25 * Keith Whitwell <keith@tungstengraphics.com>
26 */
27
28 #include "main/imports.h"
29 #include "main/mtypes.h"
30 #include "main/api_arrayelt.h"
31 #include "math/m_eval.h"
32 #include "vbo.h"
33 #include "vbo_context.h"
34
35 #if 0
36 /* Reach out and grab this to use as the default:
37 */
38 extern void _tnl_draw_prims( GLcontext *ctx,
39 const struct gl_client_array *arrays[],
40 const struct _mesa_prim *prims,
41 GLuint nr_prims,
42 const struct _mesa_index_buffer *ib,
43 GLuint min_index,
44 GLuint max_index );
45 #endif
46
47
48
49 #define NR_LEGACY_ATTRIBS 16
50 #define NR_GENERIC_ATTRIBS 16
51 #define NR_MAT_ATTRIBS 12
52
53 static GLuint check_size( const GLfloat *attr )
54 {
55 if (attr[3] != 1.0) return 4;
56 if (attr[2] != 0.0) return 3;
57 if (attr[1] != 0.0) return 2;
58 return 1;
59 }
60
61 static void init_legacy_currval(GLcontext *ctx)
62 {
63 struct vbo_context *vbo = vbo_context(ctx);
64 struct gl_client_array *arrays = vbo->legacy_currval;
65 GLuint i;
66
67 memset(arrays, 0, sizeof(*arrays) * NR_LEGACY_ATTRIBS);
68
69 /* Set up a constant (StrideB == 0) array for each current
70 * attribute:
71 */
72 for (i = 0; i < NR_LEGACY_ATTRIBS; i++) {
73 struct gl_client_array *cl = &arrays[i];
74
75 /* Size will have to be determined at runtime:
76 */
77 cl->Size = check_size(ctx->Current.Attrib[i]);
78 cl->Stride = 0;
79 cl->StrideB = 0;
80 cl->Enabled = 1;
81 cl->Type = GL_FLOAT;
82 cl->Format = GL_RGBA;
83 cl->Ptr = (const void *)ctx->Current.Attrib[i];
84 cl->BufferObj = ctx->Array.NullBufferObj;
85 }
86 }
87
88
89 static void init_generic_currval(GLcontext *ctx)
90 {
91 struct vbo_context *vbo = vbo_context(ctx);
92 struct gl_client_array *arrays = vbo->generic_currval;
93 GLuint i;
94
95 memset(arrays, 0, sizeof(*arrays) * NR_GENERIC_ATTRIBS);
96
97 for (i = 0; i < NR_GENERIC_ATTRIBS; i++) {
98 struct gl_client_array *cl = &arrays[i];
99
100 /* This will have to be determined at runtime:
101 */
102 cl->Size = 1;
103 cl->Type = GL_FLOAT;
104 cl->Format = GL_RGBA;
105 cl->Ptr = (const void *)ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + i];
106 cl->Stride = 0;
107 cl->StrideB = 0;
108 cl->Enabled = 1;
109 cl->BufferObj = ctx->Array.NullBufferObj;
110 }
111 }
112
113
114 static void init_mat_currval(GLcontext *ctx)
115 {
116 struct vbo_context *vbo = vbo_context(ctx);
117 struct gl_client_array *arrays = vbo->mat_currval;
118 GLuint i;
119
120 ASSERT(NR_MAT_ATTRIBS == MAT_ATTRIB_MAX);
121
122 memset(arrays, 0, sizeof(*arrays) * NR_MAT_ATTRIBS);
123
124 /* Set up a constant (StrideB == 0) array for each current
125 * attribute:
126 */
127 for (i = 0; i < NR_MAT_ATTRIBS; i++) {
128 struct gl_client_array *cl = &arrays[i];
129
130 /* Size is fixed for the material attributes, for others will
131 * be determined at runtime:
132 */
133 switch (i - VERT_ATTRIB_GENERIC0) {
134 case MAT_ATTRIB_FRONT_SHININESS:
135 case MAT_ATTRIB_BACK_SHININESS:
136 cl->Size = 1;
137 break;
138 case MAT_ATTRIB_FRONT_INDEXES:
139 case MAT_ATTRIB_BACK_INDEXES:
140 cl->Size = 3;
141 break;
142 default:
143 cl->Size = 4;
144 break;
145 }
146
147 cl->Ptr = (const void *)ctx->Light.Material.Attrib[i];
148 cl->Type = GL_FLOAT;
149 cl->Format = GL_RGBA;
150 cl->Stride = 0;
151 cl->StrideB = 0;
152 cl->Enabled = 1;
153 cl->BufferObj = ctx->Array.NullBufferObj;
154 }
155 }
156
157 #if 0
158
159 static void vbo_exec_current_init( struct vbo_exec_context *exec )
160 {
161 GLcontext *ctx = exec->ctx;
162 GLint i;
163
164 /* setup the pointers for the typical 16 vertex attributes */
165 for (i = 0; i < VBO_ATTRIB_FIRST_MATERIAL; i++)
166 exec->vtx.current[i] = ctx->Current.Attrib[i];
167
168 /* setup pointers for the 12 material attributes */
169 for (i = 0; i < MAT_ATTRIB_MAX; i++)
170 exec->vtx.current[VBO_ATTRIB_FIRST_MATERIAL + i] =
171 ctx->Light.Material.Attrib[i];
172 }
173 #endif
174
175 GLboolean _vbo_CreateContext( GLcontext *ctx )
176 {
177 struct vbo_context *vbo = CALLOC_STRUCT(vbo_context);
178
179 ctx->swtnl_im = (void *)vbo;
180
181 /* Initialize the arrayelt helper
182 */
183 if (!ctx->aelt_context &&
184 !_ae_create_context( ctx )) {
185 return GL_FALSE;
186 }
187
188 /* TODO: remove these pointers.
189 */
190 vbo->legacy_currval = &vbo->currval[VBO_ATTRIB_POS];
191 vbo->generic_currval = &vbo->currval[VBO_ATTRIB_GENERIC0];
192 vbo->mat_currval = &vbo->currval[VBO_ATTRIB_MAT_FRONT_AMBIENT];
193
194 init_legacy_currval( ctx );
195 init_generic_currval( ctx );
196 init_mat_currval( ctx );
197
198 /* Build mappings from VERT_ATTRIB -> VBO_ATTRIB depending on type
199 * of vertex program active.
200 */
201 {
202 GLuint i;
203
204 /* When no vertex program, pull in the material attributes in
205 * the 16..32 generic range.
206 */
207 for (i = 0; i < 16; i++)
208 vbo->map_vp_none[i] = i;
209 for (i = 0; i < 12; i++)
210 vbo->map_vp_none[16+i] = VBO_ATTRIB_MAT_FRONT_AMBIENT + i;
211 for (i = 0; i < 4; i++)
212 vbo->map_vp_none[28+i] = i;
213
214 for (i = 0; i < VERT_ATTRIB_MAX; i++)
215 vbo->map_vp_arb[i] = i;
216 }
217
218
219 /* By default:
220 */
221 #if 0 /* dead - see vbo_set_draw_func() */
222 vbo->draw_prims = _tnl_draw_prims;
223 #endif
224
225 /* Hook our functions into exec and compile dispatch tables. These
226 * will pretty much be permanently installed, which means that the
227 * vtxfmt mechanism can be removed now.
228 */
229 vbo_exec_init( ctx );
230 #if FEATURE_dlist
231 vbo_save_init( ctx );
232 #endif
233
234 _math_init_eval();
235
236 return GL_TRUE;
237 }
238
239 void _vbo_InvalidateState( GLcontext *ctx, GLuint new_state )
240 {
241 _ae_invalidate_state(ctx, new_state);
242 vbo_exec_invalidate_state(ctx, new_state);
243 }
244
245
246 void _vbo_DestroyContext( GLcontext *ctx )
247 {
248 if (ctx->aelt_context) {
249 _ae_destroy_context( ctx );
250 ctx->aelt_context = NULL;
251 }
252
253 if (vbo_context(ctx)) {
254 vbo_exec_destroy(ctx);
255 #if FEATURE_dlist
256 vbo_save_destroy(ctx);
257 #endif
258 FREE(vbo_context(ctx));
259 ctx->swtnl_im = NULL;
260 }
261 }
262
263
264 void vbo_set_draw_func(GLcontext *ctx, vbo_draw_func func)
265 {
266 struct vbo_context *vbo = vbo_context(ctx);
267 vbo->draw_prims = func;
268 }
269