1 /* $Id: t_array_import.c,v 1.9 2001/02/20 18:28:52 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 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>
38 #include "array_cache/acache.h"
39 #include "math/m_translate.h"
41 #include "t_array_import.h"
42 #include "t_context.h"
45 static void _tnl_import_vertex( GLcontext
*ctx
,
49 struct gl_client_array
*tmp
;
50 GLboolean is_writeable
= 0;
51 struct vertex_arrays
*inputs
= &TNL_CONTEXT(ctx
)->array_inputs
;
53 tmp
= _ac_import_vertex(ctx
,
55 stride
? 4*sizeof(GLfloat
) : 0,
60 inputs
->Obj
.data
= tmp
->Ptr
;
61 inputs
->Obj
.start
= (GLfloat
*)tmp
->Ptr
;
62 inputs
->Obj
.stride
= tmp
->StrideB
;
63 inputs
->Obj
.size
= tmp
->Size
;
64 inputs
->Obj
.flags
&= ~(VEC_BAD_STRIDE
|VEC_NOT_WRITEABLE
);
65 if (inputs
->Obj
.stride
!= 4*sizeof(GLfloat
))
66 inputs
->Obj
.flags
|= VEC_BAD_STRIDE
;
68 inputs
->Obj
.flags
|= VEC_NOT_WRITEABLE
;
71 static void _tnl_import_normal( GLcontext
*ctx
,
75 struct gl_client_array
*tmp
;
76 GLboolean is_writeable
= 0;
77 struct vertex_arrays
*inputs
= &TNL_CONTEXT(ctx
)->array_inputs
;
79 tmp
= _ac_import_normal(ctx
, GL_FLOAT
,
80 stride
? 3*sizeof(GLfloat
) : 0, writeable
,
83 inputs
->Normal
.data
= tmp
->Ptr
;
84 inputs
->Normal
.start
= (GLfloat
*)tmp
->Ptr
;
85 inputs
->Normal
.stride
= tmp
->StrideB
;
86 inputs
->Normal
.flags
&= ~(VEC_BAD_STRIDE
|VEC_NOT_WRITEABLE
);
87 if (inputs
->Normal
.stride
!= 3*sizeof(GLfloat
))
88 inputs
->Normal
.flags
|= VEC_BAD_STRIDE
;
90 inputs
->Normal
.flags
|= VEC_NOT_WRITEABLE
;
94 static void _tnl_import_color( GLcontext
*ctx
,
98 struct gl_client_array
*tmp
;
99 GLboolean is_writeable
= 0;
100 struct vertex_arrays
*inputs
= &TNL_CONTEXT(ctx
)->array_inputs
;
102 tmp
= _ac_import_color(ctx
,
104 stride
? 4*sizeof(GLubyte
) : 0,
109 inputs
->Color
.data
= tmp
->Ptr
;
110 inputs
->Color
.start
= (GLchan
*)tmp
->Ptr
;
111 inputs
->Color
.stride
= tmp
->StrideB
;
112 inputs
->Color
.flags
&= ~(VEC_BAD_STRIDE
|VEC_NOT_WRITEABLE
);
113 if (inputs
->Color
.stride
!= 4*sizeof(GLchan
))
114 inputs
->Color
.flags
|= VEC_BAD_STRIDE
;
116 inputs
->Color
.flags
|= VEC_NOT_WRITEABLE
;
120 static void _tnl_import_secondarycolor( GLcontext
*ctx
,
124 struct gl_client_array
*tmp
;
125 GLboolean is_writeable
= 0;
126 struct vertex_arrays
*inputs
= &TNL_CONTEXT(ctx
)->array_inputs
;
128 tmp
= _ac_import_secondarycolor(ctx
, GL_UNSIGNED_BYTE
,
129 stride
? 4*sizeof(GLubyte
) : 0,
134 inputs
->SecondaryColor
.data
= tmp
->Ptr
;
135 inputs
->SecondaryColor
.start
= (GLchan
*)tmp
->Ptr
;
136 inputs
->SecondaryColor
.stride
= tmp
->StrideB
;
137 inputs
->SecondaryColor
.flags
&= ~(VEC_BAD_STRIDE
|VEC_NOT_WRITEABLE
);
138 if (inputs
->SecondaryColor
.stride
!= 4*sizeof(GLubyte
))
139 inputs
->SecondaryColor
.flags
|= VEC_BAD_STRIDE
;
141 inputs
->SecondaryColor
.flags
|= VEC_NOT_WRITEABLE
;
144 static void _tnl_import_fogcoord( GLcontext
*ctx
,
148 struct vertex_arrays
*inputs
= &TNL_CONTEXT(ctx
)->array_inputs
;
149 struct gl_client_array
*tmp
;
150 GLboolean is_writeable
= 0;
152 tmp
= _ac_import_fogcoord(ctx
, GL_FLOAT
,
153 stride
? sizeof(GLfloat
) : 0, writeable
,
156 inputs
->FogCoord
.data
= tmp
->Ptr
;
157 inputs
->FogCoord
.start
= (GLfloat
*)tmp
->Ptr
;
158 inputs
->FogCoord
.stride
= tmp
->StrideB
;
159 inputs
->FogCoord
.flags
&= ~(VEC_BAD_STRIDE
|VEC_NOT_WRITEABLE
);
160 if (inputs
->FogCoord
.stride
!= sizeof(GLfloat
))
161 inputs
->FogCoord
.flags
|= VEC_BAD_STRIDE
;
163 inputs
->FogCoord
.flags
|= VEC_NOT_WRITEABLE
;
166 static void _tnl_import_index( GLcontext
*ctx
,
170 struct vertex_arrays
*inputs
= &TNL_CONTEXT(ctx
)->array_inputs
;
171 struct gl_client_array
*tmp
;
172 GLboolean is_writeable
= 0;
174 tmp
= _ac_import_index(ctx
, GL_UNSIGNED_INT
,
175 stride
? sizeof(GLuint
) : 0, writeable
,
178 inputs
->Index
.data
= tmp
->Ptr
;
179 inputs
->Index
.start
= (GLuint
*)tmp
->Ptr
;
180 inputs
->Index
.stride
= tmp
->StrideB
;
181 inputs
->Index
.flags
&= ~(VEC_BAD_STRIDE
|VEC_NOT_WRITEABLE
);
182 if (inputs
->Index
.stride
!= sizeof(GLuint
))
183 inputs
->Index
.flags
|= VEC_BAD_STRIDE
;
185 inputs
->Index
.flags
|= VEC_NOT_WRITEABLE
;
189 static void _tnl_import_texcoord( GLcontext
*ctx
,
194 struct vertex_arrays
*inputs
= &TNL_CONTEXT(ctx
)->array_inputs
;
195 struct gl_client_array
*tmp
;
196 GLboolean is_writeable
= 0;
198 tmp
= _ac_import_texcoord(ctx
, i
, GL_FLOAT
,
199 stride
? 4*sizeof(GLfloat
) : 0,
204 inputs
->TexCoord
[i
].data
= tmp
->Ptr
;
205 inputs
->TexCoord
[i
].start
= (GLfloat
*)tmp
->Ptr
;
206 inputs
->TexCoord
[i
].stride
= tmp
->StrideB
;
207 inputs
->TexCoord
[i
].size
= tmp
->Size
;
208 inputs
->TexCoord
[i
].flags
&= ~(VEC_BAD_STRIDE
|VEC_NOT_WRITEABLE
);
209 if (inputs
->TexCoord
[i
].stride
!= 4*sizeof(GLfloat
))
210 inputs
->TexCoord
[i
].flags
|= VEC_BAD_STRIDE
;
212 inputs
->TexCoord
[i
].flags
|= VEC_NOT_WRITEABLE
;
216 static void _tnl_import_edgeflag( GLcontext
*ctx
,
220 struct vertex_arrays
*inputs
= &TNL_CONTEXT(ctx
)->array_inputs
;
221 struct gl_client_array
*tmp
;
222 GLboolean is_writeable
= 0;
224 tmp
= _ac_import_edgeflag(ctx
, GL_UNSIGNED_BYTE
,
225 stride
? sizeof(GLubyte
) : 0,
229 inputs
->EdgeFlag
.data
= tmp
->Ptr
;
230 inputs
->EdgeFlag
.start
= (GLubyte
*)tmp
->Ptr
;
231 inputs
->EdgeFlag
.stride
= tmp
->StrideB
;
232 inputs
->EdgeFlag
.flags
&= ~(VEC_BAD_STRIDE
|VEC_NOT_WRITEABLE
);
233 if (inputs
->EdgeFlag
.stride
!= sizeof(GLubyte
))
234 inputs
->EdgeFlag
.flags
|= VEC_BAD_STRIDE
;
236 inputs
->EdgeFlag
.flags
|= VEC_NOT_WRITEABLE
;
241 /* Callback for VB stages that need to improve the quality of arrays
242 * bound to the VB. This is only necessary for client arrays which
243 * have not been transformed at any point in the pipeline.
245 static void _tnl_upgrade_client_data( GLcontext
*ctx
,
250 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
251 GLboolean writeable
= (flags
& VEC_NOT_WRITEABLE
) != 0;
252 GLboolean stride
= (flags
& VEC_BAD_STRIDE
) != 0;
253 struct vertex_arrays
*inputs
= &TNL_CONTEXT(ctx
)->array_inputs
;
256 if ((required
& VERT_CLIP
) && VB
->ClipPtr
== VB
->ObjPtr
)
257 required
|= VERT_OBJ
;
259 /* _tnl_print_vert_flags("_tnl_upgrade_client_data", required); */
261 if ((required
& VERT_OBJ
) && (VB
->ObjPtr
->flags
& flags
)) {
262 ASSERT(VB
->ObjPtr
== &inputs
->Obj
);
263 _tnl_import_vertex( ctx
, writeable
, stride
);
264 VB
->importable_data
&= ~(VERT_OBJ
|VERT_CLIP
);
267 if ((required
& VERT_NORM
) && (VB
->NormalPtr
->flags
& flags
)) {
268 ASSERT(VB
->NormalPtr
== &inputs
->Normal
);
269 _tnl_import_normal( ctx
, writeable
, stride
);
270 VB
->importable_data
&= ~VERT_NORM
;
273 if ((required
& VERT_RGBA
) && (VB
->ColorPtr
[0]->flags
& flags
)) {
274 ASSERT(VB
->ColorPtr
[0] == &inputs
->Color
);
275 _tnl_import_color( ctx
, writeable
, stride
);
276 VB
->importable_data
&= ~VERT_RGBA
;
279 if ((required
& VERT_SPEC_RGB
) && (VB
->SecondaryColorPtr
[0]->flags
&flags
)) {
280 ASSERT(VB
->SecondaryColorPtr
[0] == &inputs
->SecondaryColor
);
281 _tnl_import_secondarycolor( ctx
, writeable
, stride
);
282 VB
->importable_data
&= ~VERT_SPEC_RGB
;
285 if ((required
& VERT_FOG_COORD
) && (VB
->FogCoordPtr
->flags
& flags
)) {
286 ASSERT(VB
->FogCoordPtr
== &inputs
->FogCoord
);
287 _tnl_import_fogcoord( ctx
, writeable
, stride
);
288 VB
->importable_data
&= ~VERT_FOG_COORD
;
291 if ((required
& VERT_INDEX
) && (VB
->IndexPtr
[0]->flags
& flags
)) {
292 ASSERT(VB
->IndexPtr
[0] == &inputs
->Index
);
293 _tnl_import_index( ctx
, writeable
, stride
);
294 VB
->importable_data
&= ~VERT_INDEX
;
297 if (required
& VERT_TEX_ANY
)
298 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++)
299 if ((required
& VERT_TEX(i
)) && (VB
->TexCoordPtr
[i
]->flags
& flags
)) {
300 ASSERT(VB
->TexCoordPtr
[i
] == &inputs
->TexCoord
[i
]);
301 _tnl_import_texcoord( ctx
, i
, writeable
, stride
);
302 VB
->importable_data
&= ~VERT_TEX(i
);
311 void _tnl_vb_bind_arrays( GLcontext
*ctx
, GLint start
, GLsizei count
)
313 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
314 struct vertex_buffer
*VB
= &tnl
->vb
;
315 GLuint inputs
= tnl
->pipeline
.inputs
;
317 struct vertex_arrays
*tmp
= &tnl
->array_inputs
;
319 /* fprintf(stderr, "_tnl_vb_bind_arrays %d..%d // %d..%d\n", */
320 /* start, count, ctx->Array.LockFirst, ctx->Array.LockCount); */
322 if (ctx
->Array
.LockCount
) {
323 ASSERT(start
== ctx
->Array
.LockFirst
);
324 ASSERT(count
== ctx
->Array
.LockCount
);
327 imports
= tnl
->pipeline
.inputs
;
329 _ac_import_range( ctx
, start
, count
);
331 VB
->Count
= count
- start
;
332 VB
->FirstClipped
= VB
->Count
;
335 VB
->MaterialMask
= 0;
339 /* _tnl_print_vert_flags("_tnl_vb_bind_arrays: inputs", inputs); */
340 /* _tnl_print_vert_flags("_tnl_vb_bind_arrays: imports", imports); */
341 /* _tnl_print_vert_flags("_tnl_vb_bind_arrays: _Enabled", ctx->Array._Enabled); */
343 if (inputs
& VERT_OBJ
) {
344 if (imports
& VERT_OBJ
) {
345 _tnl_import_vertex( ctx
, 0, 0 );
346 tmp
->Obj
.count
= VB
->Count
;
348 VB
->ObjPtr
= &tmp
->Obj
;
351 if (inputs
& VERT_NORM
) {
352 if (imports
& VERT_NORM
) {
353 _tnl_import_normal( ctx
, 0, 0 );
354 tmp
->Normal
.count
= VB
->Count
;
356 VB
->NormalPtr
= &tmp
->Normal
;
359 if (inputs
& VERT_RGBA
) {
360 if (imports
& VERT_RGBA
) {
361 _tnl_import_color( ctx
, 0, 0 );
362 tmp
->Color
.count
= VB
->Count
;
364 VB
->ColorPtr
[0] = &tmp
->Color
;
368 if (inputs
& VERT_INDEX
) {
369 if (imports
& VERT_INDEX
) {
370 _tnl_import_index( ctx
, 0, 0 );
371 tmp
->Index
.count
= VB
->Count
;
373 VB
->IndexPtr
[0] = &tmp
->Index
;
378 if (inputs
& VERT_FOG_COORD
) {
379 if (imports
& VERT_FOG_COORD
) {
380 _tnl_import_fogcoord( ctx
, 0, 0 );
381 tmp
->FogCoord
.count
= VB
->Count
;
383 VB
->FogCoordPtr
= &tmp
->FogCoord
;
386 if (inputs
& VERT_EDGE
) {
387 _tnl_import_edgeflag( ctx
, GL_TRUE
, sizeof(GLboolean
) );
388 VB
->EdgeFlag
= (GLboolean
*) tmp
->EdgeFlag
.data
;
391 if (inputs
& VERT_SPEC_RGB
) {
392 if (imports
& VERT_SPEC_RGB
) {
393 _tnl_import_secondarycolor( ctx
, 0, 0 );
394 tmp
->SecondaryColor
.count
= VB
->Count
;
396 VB
->SecondaryColorPtr
[0] = &tmp
->SecondaryColor
;
397 VB
->SecondaryColorPtr
[1] = 0;
400 if (inputs
& VERT_TEX_ANY
) {
402 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++)
403 if (inputs
& VERT_TEX(i
)) {
404 if (imports
& VERT_TEX(i
)) {
405 _tnl_import_texcoord( ctx
, i
, 0, 0 );
406 tmp
->TexCoord
[i
].count
= VB
->Count
;
408 VB
->TexCoordPtr
[i
] = &tmp
->TexCoord
[i
];
412 VB
->Primitive
= tnl
->tmp_primitive
;
413 VB
->PrimitiveLength
= tnl
->tmp_primitive_length
;
414 VB
->import_data
= _tnl_upgrade_client_data
;
415 VB
->importable_data
= imports
& VERT_FIXUP
;
416 /* _tnl_print_vert_flags("_tnl_vb_bind_arrays: importable", VB->importable_data); */
423 /* Function to fill an immediate struct with the effects of
424 * consecutive calls to ArrayElement with consecutive indices.
426 void _tnl_fill_immediate_drawarrays( GLcontext
*ctx
, struct immediate
*IM
,
427 GLuint start
, GLuint count
)
429 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
430 GLuint required
= ctx
->Array
._Enabled
;
431 GLuint n
= count
- start
;
434 if (!ctx
->CompileFlag
)
435 required
&= tnl
->pipeline
.inputs
;
437 if (MESA_VERBOSE
&VERBOSE_IMMEDIATE
)
438 fprintf(stderr
, "exec_full_array_elements %d .. %d\n", start
, count
);
440 _math_trans_4f( IM
->Obj
+ IM
->Start
,
441 ctx
->Array
.Vertex
.Ptr
,
442 ctx
->Array
.Vertex
.StrideB
,
443 ctx
->Array
.Vertex
.Type
,
444 ctx
->Array
.Vertex
.Size
,
447 if (ctx
->Array
.Vertex
.Size
== 4)
448 required
|= VERT_OBJ_234
;
449 else if (ctx
->Array
.Vertex
.Size
== 3)
450 required
|= VERT_OBJ_23
;
453 if (required
& VERT_NORM
) {
454 _math_trans_3f( IM
->Normal
+ IM
->Start
,
455 ctx
->Array
.Normal
.Ptr
,
456 ctx
->Array
.Normal
.StrideB
,
457 ctx
->Array
.Normal
.Type
,
461 if (required
& VERT_EDGE
) {
462 _math_trans_1ub( IM
->EdgeFlag
+ IM
->Start
,
463 ctx
->Array
.EdgeFlag
.Ptr
,
464 ctx
->Array
.EdgeFlag
.StrideB
,
465 ctx
->Array
.EdgeFlag
.Type
,
469 if (required
& VERT_RGBA
) {
470 _math_trans_4chan( IM
->Color
+ IM
->Start
,
471 ctx
->Array
.Color
.Ptr
,
472 ctx
->Array
.Color
.StrideB
,
473 ctx
->Array
.Color
.Type
,
474 ctx
->Array
.Color
.Size
,
478 if (required
& VERT_SPEC_RGB
) {
479 _math_trans_4chan( IM
->SecondaryColor
+ IM
->Start
,
480 ctx
->Array
.SecondaryColor
.Ptr
,
481 ctx
->Array
.SecondaryColor
.StrideB
,
482 ctx
->Array
.SecondaryColor
.Type
,
483 ctx
->Array
.SecondaryColor
.Size
,
487 if (required
& VERT_FOG_COORD
) {
488 _math_trans_1f( IM
->FogCoord
+ IM
->Start
,
489 ctx
->Array
.FogCoord
.Ptr
,
490 ctx
->Array
.FogCoord
.StrideB
,
491 ctx
->Array
.FogCoord
.Type
,
495 if (required
& VERT_INDEX
) {
496 _math_trans_1ui( IM
->Index
+ IM
->Start
,
497 ctx
->Array
.Index
.Ptr
,
498 ctx
->Array
.Index
.StrideB
,
499 ctx
->Array
.Index
.Type
,
503 if (required
& VERT_TEX_ANY
) {
504 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
505 if (required
& VERT_TEX(i
)) {
506 _math_trans_4f( IM
->TexCoord
[i
] + IM
->Start
,
507 ctx
->Array
.TexCoord
[i
].Ptr
,
508 ctx
->Array
.TexCoord
[i
].StrideB
,
509 ctx
->Array
.TexCoord
[i
].Size
,
510 ctx
->Array
.TexCoord
[i
].Type
,
513 if (ctx
->Array
.TexCoord
[i
].Size
== 4)
514 IM
->TexSize
|= TEX_SIZE_4(i
);
515 else if (ctx
->Array
.TexCoord
[i
].Size
== 3)
516 IM
->TexSize
|= TEX_SIZE_3(i
);
521 IM
->Count
= IM
->Start
+ n
;
522 IM
->Flag
[IM
->Start
] |= required
;
523 for (i
= IM
->Start
+1 ; i
< IM
->Count
; i
++)
524 IM
->Flag
[i
] = required
;