Comment out __FUNCTION__ usage.
[mesa.git] / src / mesa / tnl / t_array_import.c
1 /* $Id: t_array_import.c,v 1.17 2001/05/17 11:33:33 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 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 <keithw@valinux.com>
28 */
29
30 #include "glheader.h"
31 #include "context.h"
32 #include "macros.h"
33 #include "mem.h"
34 #include "mmath.h"
35 #include "state.h"
36 #include "mtypes.h"
37
38 #include "array_cache/acache.h"
39 #include "math/m_translate.h"
40
41 #include "t_array_import.h"
42 #include "t_context.h"
43 #include "t_imm_debug.h"
44
45
46 static void _tnl_import_vertex( GLcontext *ctx,
47 GLboolean writeable,
48 GLboolean stride )
49 {
50 struct gl_client_array *tmp;
51 GLboolean is_writeable = 0;
52 struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
53
54 tmp = _ac_import_vertex(ctx,
55 GL_FLOAT,
56 stride ? 4*sizeof(GLfloat) : 0,
57 0,
58 writeable,
59 &is_writeable);
60
61 inputs->Obj.data = (GLfloat (*)[4]) tmp->Ptr;
62 inputs->Obj.start = (GLfloat *) tmp->Ptr;
63 inputs->Obj.stride = tmp->StrideB;
64 inputs->Obj.size = tmp->Size;
65 inputs->Obj.flags &= ~(VEC_BAD_STRIDE|VEC_NOT_WRITEABLE);
66 if (inputs->Obj.stride != 4*sizeof(GLfloat))
67 inputs->Obj.flags |= VEC_BAD_STRIDE;
68 if (!is_writeable)
69 inputs->Obj.flags |= VEC_NOT_WRITEABLE;
70 }
71
72 static void _tnl_import_normal( GLcontext *ctx,
73 GLboolean writeable,
74 GLboolean stride )
75 {
76 struct gl_client_array *tmp;
77 GLboolean is_writeable = 0;
78 struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
79
80 tmp = _ac_import_normal(ctx, GL_FLOAT,
81 stride ? 3*sizeof(GLfloat) : 0, writeable,
82 &is_writeable);
83
84 inputs->Normal.data = (GLfloat (*)[3]) tmp->Ptr;
85 inputs->Normal.start = (GLfloat *) tmp->Ptr;
86 inputs->Normal.stride = tmp->StrideB;
87 inputs->Normal.flags &= ~(VEC_BAD_STRIDE|VEC_NOT_WRITEABLE);
88 if (inputs->Normal.stride != 3*sizeof(GLfloat))
89 inputs->Normal.flags |= VEC_BAD_STRIDE;
90 if (!is_writeable)
91 inputs->Normal.flags |= VEC_NOT_WRITEABLE;
92 }
93
94
95 static void _tnl_import_color( GLcontext *ctx,
96 GLenum type,
97 GLboolean writeable,
98 GLboolean stride )
99 {
100 struct gl_client_array *tmp;
101 GLboolean is_writeable = 0;
102 struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
103
104 tmp = _ac_import_color(ctx,
105 type,
106 stride ? 4*sizeof(GLfloat) : 0,
107 4,
108 writeable,
109 &is_writeable);
110
111 inputs->Color = *tmp;
112 }
113
114
115 static void _tnl_import_secondarycolor( GLcontext *ctx,
116 GLenum type,
117 GLboolean writeable,
118 GLboolean stride )
119 {
120 struct gl_client_array *tmp;
121 GLboolean is_writeable = 0;
122 struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
123
124 tmp = _ac_import_secondarycolor(ctx,
125 type,
126 stride ? 4*sizeof(GLfloat) : 0,
127 4,
128 writeable,
129 &is_writeable);
130
131 inputs->SecondaryColor = *tmp;
132 }
133
134 static void _tnl_import_fogcoord( GLcontext *ctx,
135 GLboolean writeable,
136 GLboolean stride )
137 {
138 struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
139 struct gl_client_array *tmp;
140 GLboolean is_writeable = 0;
141
142 tmp = _ac_import_fogcoord(ctx, GL_FLOAT,
143 stride ? sizeof(GLfloat) : 0, writeable,
144 &is_writeable);
145
146 inputs->FogCoord.data = (GLfloat *) tmp->Ptr;
147 inputs->FogCoord.start = (GLfloat *) tmp->Ptr;
148 inputs->FogCoord.stride = tmp->StrideB;
149 inputs->FogCoord.flags &= ~(VEC_BAD_STRIDE|VEC_NOT_WRITEABLE);
150 if (inputs->FogCoord.stride != sizeof(GLfloat))
151 inputs->FogCoord.flags |= VEC_BAD_STRIDE;
152 if (!is_writeable)
153 inputs->FogCoord.flags |= VEC_NOT_WRITEABLE;
154 }
155
156 static void _tnl_import_index( GLcontext *ctx,
157 GLboolean writeable,
158 GLboolean stride )
159 {
160 struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
161 struct gl_client_array *tmp;
162 GLboolean is_writeable = 0;
163
164 tmp = _ac_import_index(ctx, GL_UNSIGNED_INT,
165 stride ? sizeof(GLuint) : 0, writeable,
166 &is_writeable);
167
168 inputs->Index.data = (GLuint *) tmp->Ptr;
169 inputs->Index.start = (GLuint *) tmp->Ptr;
170 inputs->Index.stride = tmp->StrideB;
171 inputs->Index.flags &= ~(VEC_BAD_STRIDE|VEC_NOT_WRITEABLE);
172 if (inputs->Index.stride != sizeof(GLuint))
173 inputs->Index.flags |= VEC_BAD_STRIDE;
174 if (!is_writeable)
175 inputs->Index.flags |= VEC_NOT_WRITEABLE;
176 }
177
178
179 static void _tnl_import_texcoord( GLcontext *ctx,
180 GLuint i,
181 GLboolean writeable,
182 GLboolean stride )
183 {
184 struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
185 struct gl_client_array *tmp;
186 GLboolean is_writeable = 0;
187
188 tmp = _ac_import_texcoord(ctx, i, GL_FLOAT,
189 stride ? 4*sizeof(GLfloat) : 0,
190 0,
191 writeable,
192 &is_writeable);
193
194 inputs->TexCoord[i].data = (GLfloat (*)[4]) tmp->Ptr;
195 inputs->TexCoord[i].start = (GLfloat *) tmp->Ptr;
196 inputs->TexCoord[i].stride = tmp->StrideB;
197 inputs->TexCoord[i].size = tmp->Size;
198 inputs->TexCoord[i].flags &= ~(VEC_BAD_STRIDE|VEC_NOT_WRITEABLE);
199 if (inputs->TexCoord[i].stride != 4*sizeof(GLfloat))
200 inputs->TexCoord[i].flags |= VEC_BAD_STRIDE;
201 if (!is_writeable)
202 inputs->TexCoord[i].flags |= VEC_NOT_WRITEABLE;
203 }
204
205
206 static void _tnl_import_edgeflag( GLcontext *ctx,
207 GLboolean writeable,
208 GLboolean stride )
209 {
210 struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
211 struct gl_client_array *tmp;
212 GLboolean is_writeable = 0;
213
214 tmp = _ac_import_edgeflag(ctx, GL_UNSIGNED_BYTE,
215 stride ? sizeof(GLubyte) : 0,
216 0,
217 &is_writeable);
218
219 inputs->EdgeFlag.data = (GLubyte *) tmp->Ptr;
220 inputs->EdgeFlag.start = (GLubyte *) tmp->Ptr;
221 inputs->EdgeFlag.stride = tmp->StrideB;
222 inputs->EdgeFlag.flags &= ~(VEC_BAD_STRIDE|VEC_NOT_WRITEABLE);
223 if (inputs->EdgeFlag.stride != sizeof(GLubyte))
224 inputs->EdgeFlag.flags |= VEC_BAD_STRIDE;
225 if (!is_writeable)
226 inputs->EdgeFlag.flags |= VEC_NOT_WRITEABLE;
227 }
228
229
230
231 /* Callback for VB stages that need to improve the quality of arrays
232 * bound to the VB. This is only necessary for client arrays which
233 * have not been transformed at any point in the pipeline.
234 */
235 static void _tnl_upgrade_client_data( GLcontext *ctx,
236 GLuint required,
237 GLuint flags )
238 {
239 GLuint i;
240 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
241 GLboolean writeable = (flags & VEC_NOT_WRITEABLE) != 0;
242 GLboolean stride = (flags & VEC_BAD_STRIDE) != 0;
243 struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
244 GLuint ca_flags = 0;
245 (void) inputs;
246
247 if (writeable || stride) ca_flags |= CA_CLIENT_DATA;
248
249 if ((required & VERT_CLIP) && VB->ClipPtr == VB->ObjPtr)
250 required |= VERT_OBJ;
251
252 /* _tnl_print_vert_flags("_tnl_upgrade_client_data", required); */
253
254 if ((required & VERT_OBJ) && (VB->ObjPtr->flags & flags)) {
255 ASSERT(VB->ObjPtr == &inputs->Obj);
256 _tnl_import_vertex( ctx, writeable, stride );
257 VB->importable_data &= ~(VERT_OBJ|VERT_CLIP);
258 }
259
260 if ((required & VERT_NORM) && (VB->NormalPtr->flags & flags)) {
261 ASSERT(VB->NormalPtr == &inputs->Normal);
262 _tnl_import_normal( ctx, writeable, stride );
263 VB->importable_data &= ~VERT_NORM;
264 }
265
266 if ((required & VERT_RGBA) && (VB->ColorPtr[0]->Flags & ca_flags)) {
267 ASSERT(VB->ColorPtr[0] == &inputs->Color);
268 _tnl_import_color( ctx, GL_FLOAT, writeable, stride );
269 VB->importable_data &= ~VERT_RGBA;
270 }
271
272 if ((required & VERT_SPEC_RGB) &&
273 (VB->SecondaryColorPtr[0]->Flags & ca_flags)) {
274 ASSERT(VB->SecondaryColorPtr[0] == &inputs->SecondaryColor);
275 _tnl_import_secondarycolor( ctx, GL_FLOAT, writeable, stride );
276 VB->importable_data &= ~VERT_SPEC_RGB;
277 }
278
279 if ((required & VERT_FOG_COORD) && (VB->FogCoordPtr->flags & flags)) {
280 ASSERT(VB->FogCoordPtr == &inputs->FogCoord);
281 _tnl_import_fogcoord( ctx, writeable, stride );
282 VB->importable_data &= ~VERT_FOG_COORD;
283 }
284
285 if ((required & VERT_INDEX) && (VB->IndexPtr[0]->flags & flags)) {
286 ASSERT(VB->IndexPtr[0] == &inputs->Index);
287 _tnl_import_index( ctx, writeable, stride );
288 VB->importable_data &= ~VERT_INDEX;
289 }
290
291 if (required & VERT_TEX_ANY)
292 for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++)
293 if ((required & VERT_TEX(i)) && (VB->TexCoordPtr[i]->flags & flags)) {
294 ASSERT(VB->TexCoordPtr[i] == &inputs->TexCoord[i]);
295 _tnl_import_texcoord( ctx, i, writeable, stride );
296 VB->importable_data &= ~VERT_TEX(i);
297 }
298
299 }
300
301
302
303 void _tnl_vb_bind_arrays( GLcontext *ctx, GLint start, GLsizei count )
304 {
305 TNLcontext *tnl = TNL_CONTEXT(ctx);
306 struct vertex_buffer *VB = &tnl->vb;
307 GLuint inputs = tnl->pipeline.inputs;
308 struct vertex_arrays *tmp = &tnl->array_inputs;
309 GLuint i;
310
311 /* fprintf(stderr, "%s %d..%d // %d..%d\n", __FUNCTION__, */
312 /* start, count, ctx->Array.LockFirst, ctx->Array.LockCount); */
313 /* _tnl_print_vert_flags(" inputs", inputs); */
314 /* _tnl_print_vert_flags(" _Enabled", ctx->Array._Enabled); */
315 /* _tnl_print_vert_flags(" importable", inputs & VERT_FIXUP); */
316
317 VB->Count = count - start;
318 VB->FirstClipped = VB->Count;
319 VB->Elts = 0;
320 VB->MaterialMask = 0;
321 VB->Material = 0;
322 VB->Flag = 0;
323 VB->Primitive = tnl->tmp_primitive;
324 VB->PrimitiveLength = tnl->tmp_primitive_length;
325 VB->import_data = _tnl_upgrade_client_data;
326 VB->importable_data = inputs & VERT_FIXUP;
327
328 if (ctx->Array.LockCount) {
329 ASSERT(start == (GLint) ctx->Array.LockFirst);
330 ASSERT(count == (GLint) ctx->Array.LockCount);
331 }
332
333 _ac_import_range( ctx, start, count );
334
335 if (inputs & VERT_OBJ) {
336 _tnl_import_vertex( ctx, 0, 0 );
337 tmp->Obj.count = VB->Count;
338 VB->ObjPtr = &tmp->Obj;
339 }
340
341 if (inputs & VERT_NORM) {
342 _tnl_import_normal( ctx, 0, 0 );
343 tmp->Normal.count = VB->Count;
344 VB->NormalPtr = &tmp->Normal;
345 }
346
347 if (inputs & VERT_RGBA) {
348 _tnl_import_color( ctx, 0, 0, 0 );
349 VB->ColorPtr[0] = &tmp->Color;
350 VB->ColorPtr[1] = 0;
351 }
352
353 if (inputs & VERT_TEX_ANY) {
354 for (i = 0; i < ctx->Const.MaxTextureUnits ; i++) {
355 if (inputs & VERT_TEX(i)) {
356 _tnl_import_texcoord( ctx, i, 0, 0 );
357 tmp->TexCoord[i].count = VB->Count;
358 VB->TexCoordPtr[i] = &tmp->TexCoord[i];
359 }
360 }
361 }
362
363 if (inputs & (VERT_INDEX|VERT_FOG_COORD|VERT_EDGE|VERT_SPEC_RGB)) {
364 if (inputs & VERT_INDEX) {
365 _tnl_import_index( ctx, 0, 0 );
366 tmp->Index.count = VB->Count;
367 VB->IndexPtr[0] = &tmp->Index;
368 VB->IndexPtr[1] = 0;
369 }
370
371 if (inputs & VERT_FOG_COORD) {
372 _tnl_import_fogcoord( ctx, 0, 0 );
373 tmp->FogCoord.count = VB->Count;
374 VB->FogCoordPtr = &tmp->FogCoord;
375 }
376
377 if (inputs & VERT_EDGE) {
378 _tnl_import_edgeflag( ctx, GL_TRUE, sizeof(GLboolean) );
379 VB->EdgeFlag = (GLboolean *) tmp->EdgeFlag.data;
380 }
381
382 if (inputs & VERT_SPEC_RGB) {
383 _tnl_import_secondarycolor( ctx, 0, 0, 0 );
384 VB->SecondaryColorPtr[0] = &tmp->SecondaryColor;
385 VB->SecondaryColorPtr[1] = 0;
386 }
387 }
388 }
389
390
391
392
393 /* Function to fill an immediate struct with the effects of
394 * consecutive calls to ArrayElement with consecutive indices. Used
395 * for display lists and very large fan-like primitives only.
396 */
397 void _tnl_fill_immediate_drawarrays( GLcontext *ctx, struct immediate *IM,
398 GLuint start, GLuint count )
399 {
400 TNLcontext *tnl = TNL_CONTEXT(ctx);
401 GLuint required = ctx->Array._Enabled;
402 GLuint n = count - start;
403 GLuint i;
404
405 if (!ctx->CompileFlag)
406 required &= tnl->pipeline.inputs;
407
408 if (MESA_VERBOSE&VERBOSE_IMMEDIATE)
409 fprintf(stderr, "exec_full_array_elements %d .. %d\n", start, count);
410
411 _math_trans_4f( IM->Obj + IM->Start,
412 ctx->Array.Vertex.Ptr,
413 ctx->Array.Vertex.StrideB,
414 ctx->Array.Vertex.Type,
415 ctx->Array.Vertex.Size,
416 start, n );
417
418 if (ctx->Array.Vertex.Size == 4)
419 required |= VERT_OBJ_234;
420 else if (ctx->Array.Vertex.Size == 3)
421 required |= VERT_OBJ_23;
422
423
424 if (required & VERT_NORM) {
425 _math_trans_3f( IM->Normal + IM->Start,
426 ctx->Array.Normal.Ptr,
427 ctx->Array.Normal.StrideB,
428 ctx->Array.Normal.Type,
429 start, n );
430 }
431
432 if (required & VERT_EDGE) {
433 _math_trans_1ub( IM->EdgeFlag + IM->Start,
434 ctx->Array.EdgeFlag.Ptr,
435 ctx->Array.EdgeFlag.StrideB,
436 ctx->Array.EdgeFlag.Type,
437 start, n );
438 }
439
440 if (required & VERT_RGBA) {
441 _math_trans_4f( IM->Color + IM->Start,
442 ctx->Array.Color.Ptr,
443 ctx->Array.Color.StrideB,
444 ctx->Array.Color.Type,
445 ctx->Array.Color.Size,
446 start, n );
447 }
448
449 if (required & VERT_SPEC_RGB) {
450 _math_trans_4f( IM->SecondaryColor + IM->Start,
451 ctx->Array.SecondaryColor.Ptr,
452 ctx->Array.SecondaryColor.StrideB,
453 ctx->Array.SecondaryColor.Type,
454 ctx->Array.SecondaryColor.Size,
455 start, n );
456 }
457
458 if (required & VERT_FOG_COORD) {
459 _math_trans_1f( IM->FogCoord + IM->Start,
460 ctx->Array.FogCoord.Ptr,
461 ctx->Array.FogCoord.StrideB,
462 ctx->Array.FogCoord.Type,
463 start, n );
464 }
465
466 if (required & VERT_INDEX) {
467 _math_trans_1ui( IM->Index + IM->Start,
468 ctx->Array.Index.Ptr,
469 ctx->Array.Index.StrideB,
470 ctx->Array.Index.Type,
471 start, n );
472 }
473
474 if (required & VERT_TEX_ANY) {
475 for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) {
476 if (required & VERT_TEX(i)) {
477 _math_trans_4f( IM->TexCoord[i] + IM->Start,
478 ctx->Array.TexCoord[i].Ptr,
479 ctx->Array.TexCoord[i].StrideB,
480 ctx->Array.TexCoord[i].Type,
481 ctx->Array.TexCoord[i].Size,
482 start, n );
483
484 if (ctx->Array.TexCoord[i].Size == 4)
485 IM->TexSize |= TEX_SIZE_4(i);
486 else if (ctx->Array.TexCoord[i].Size == 3)
487 IM->TexSize |= TEX_SIZE_3(i);
488 }
489 }
490 }
491
492 IM->Count = IM->Start + n;
493 IM->Flag[IM->Start] &= IM->ArrayEltFlags;
494 IM->Flag[IM->Start] |= required;
495 for (i = IM->Start+1 ; i < IM->Count ; i++)
496 IM->Flag[i] = required;
497 }