7bb208cf72555d06cf676dc9354e9a4b726c3435
1 /* $Id: t_array_import.c,v 1.13 2001/04/26 14:53:48 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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
= (GLfloat (*)[4]) 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
= (GLfloat (*)[3]) 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 /* fprintf(stderr, "%s\n", __FUNCTION__); */
104 tmp
= _ac_import_color(ctx
,
106 stride
? 4*sizeof(GLubyte
) : 0,
111 inputs
->Color
.data
= (GLchan (*)[4]) tmp
->Ptr
;
112 inputs
->Color
.start
= (GLchan
*) tmp
->Ptr
;
113 inputs
->Color
.stride
= tmp
->StrideB
;
114 inputs
->Color
.flags
&= ~(VEC_BAD_STRIDE
|VEC_NOT_WRITEABLE
);
115 if (inputs
->Color
.stride
!= 4*sizeof(GLchan
))
116 inputs
->Color
.flags
|= VEC_BAD_STRIDE
;
118 inputs
->Color
.flags
|= VEC_NOT_WRITEABLE
;
122 static void _tnl_import_secondarycolor( GLcontext
*ctx
,
126 struct gl_client_array
*tmp
;
127 GLboolean is_writeable
= 0;
128 struct vertex_arrays
*inputs
= &TNL_CONTEXT(ctx
)->array_inputs
;
130 tmp
= _ac_import_secondarycolor(ctx
, GL_UNSIGNED_BYTE
,
131 stride
? 4*sizeof(GLubyte
) : 0,
136 inputs
->SecondaryColor
.data
= (GLchan (*)[4]) tmp
->Ptr
;
137 inputs
->SecondaryColor
.start
= (GLchan
*) tmp
->Ptr
;
138 inputs
->SecondaryColor
.stride
= tmp
->StrideB
;
139 inputs
->SecondaryColor
.flags
&= ~(VEC_BAD_STRIDE
|VEC_NOT_WRITEABLE
);
140 if (inputs
->SecondaryColor
.stride
!= 4*sizeof(GLubyte
))
141 inputs
->SecondaryColor
.flags
|= VEC_BAD_STRIDE
;
143 inputs
->SecondaryColor
.flags
|= VEC_NOT_WRITEABLE
;
146 static void _tnl_import_fogcoord( GLcontext
*ctx
,
150 struct vertex_arrays
*inputs
= &TNL_CONTEXT(ctx
)->array_inputs
;
151 struct gl_client_array
*tmp
;
152 GLboolean is_writeable
= 0;
154 tmp
= _ac_import_fogcoord(ctx
, GL_FLOAT
,
155 stride
? sizeof(GLfloat
) : 0, writeable
,
158 inputs
->FogCoord
.data
= (GLfloat
*) tmp
->Ptr
;
159 inputs
->FogCoord
.start
= (GLfloat
*) tmp
->Ptr
;
160 inputs
->FogCoord
.stride
= tmp
->StrideB
;
161 inputs
->FogCoord
.flags
&= ~(VEC_BAD_STRIDE
|VEC_NOT_WRITEABLE
);
162 if (inputs
->FogCoord
.stride
!= sizeof(GLfloat
))
163 inputs
->FogCoord
.flags
|= VEC_BAD_STRIDE
;
165 inputs
->FogCoord
.flags
|= VEC_NOT_WRITEABLE
;
168 static void _tnl_import_index( GLcontext
*ctx
,
172 struct vertex_arrays
*inputs
= &TNL_CONTEXT(ctx
)->array_inputs
;
173 struct gl_client_array
*tmp
;
174 GLboolean is_writeable
= 0;
176 tmp
= _ac_import_index(ctx
, GL_UNSIGNED_INT
,
177 stride
? sizeof(GLuint
) : 0, writeable
,
180 inputs
->Index
.data
= (GLuint
*) tmp
->Ptr
;
181 inputs
->Index
.start
= (GLuint
*) tmp
->Ptr
;
182 inputs
->Index
.stride
= tmp
->StrideB
;
183 inputs
->Index
.flags
&= ~(VEC_BAD_STRIDE
|VEC_NOT_WRITEABLE
);
184 if (inputs
->Index
.stride
!= sizeof(GLuint
))
185 inputs
->Index
.flags
|= VEC_BAD_STRIDE
;
187 inputs
->Index
.flags
|= VEC_NOT_WRITEABLE
;
191 static void _tnl_import_texcoord( GLcontext
*ctx
,
196 struct vertex_arrays
*inputs
= &TNL_CONTEXT(ctx
)->array_inputs
;
197 struct gl_client_array
*tmp
;
198 GLboolean is_writeable
= 0;
200 tmp
= _ac_import_texcoord(ctx
, i
, GL_FLOAT
,
201 stride
? 4*sizeof(GLfloat
) : 0,
206 inputs
->TexCoord
[i
].data
= (GLfloat (*)[4]) tmp
->Ptr
;
207 inputs
->TexCoord
[i
].start
= (GLfloat
*) tmp
->Ptr
;
208 inputs
->TexCoord
[i
].stride
= tmp
->StrideB
;
209 inputs
->TexCoord
[i
].size
= tmp
->Size
;
210 inputs
->TexCoord
[i
].flags
&= ~(VEC_BAD_STRIDE
|VEC_NOT_WRITEABLE
);
211 if (inputs
->TexCoord
[i
].stride
!= 4*sizeof(GLfloat
))
212 inputs
->TexCoord
[i
].flags
|= VEC_BAD_STRIDE
;
214 inputs
->TexCoord
[i
].flags
|= VEC_NOT_WRITEABLE
;
218 static void _tnl_import_edgeflag( GLcontext
*ctx
,
222 struct vertex_arrays
*inputs
= &TNL_CONTEXT(ctx
)->array_inputs
;
223 struct gl_client_array
*tmp
;
224 GLboolean is_writeable
= 0;
226 tmp
= _ac_import_edgeflag(ctx
, GL_UNSIGNED_BYTE
,
227 stride
? sizeof(GLubyte
) : 0,
231 inputs
->EdgeFlag
.data
= (GLubyte
*) tmp
->Ptr
;
232 inputs
->EdgeFlag
.start
= (GLubyte
*) tmp
->Ptr
;
233 inputs
->EdgeFlag
.stride
= tmp
->StrideB
;
234 inputs
->EdgeFlag
.flags
&= ~(VEC_BAD_STRIDE
|VEC_NOT_WRITEABLE
);
235 if (inputs
->EdgeFlag
.stride
!= sizeof(GLubyte
))
236 inputs
->EdgeFlag
.flags
|= VEC_BAD_STRIDE
;
238 inputs
->EdgeFlag
.flags
|= VEC_NOT_WRITEABLE
;
243 /* Callback for VB stages that need to improve the quality of arrays
244 * bound to the VB. This is only necessary for client arrays which
245 * have not been transformed at any point in the pipeline.
247 static void _tnl_upgrade_client_data( GLcontext
*ctx
,
252 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
253 GLboolean writeable
= (flags
& VEC_NOT_WRITEABLE
) != 0;
254 GLboolean stride
= (flags
& VEC_BAD_STRIDE
) != 0;
255 struct vertex_arrays
*inputs
= &TNL_CONTEXT(ctx
)->array_inputs
;
258 if ((required
& VERT_CLIP
) && VB
->ClipPtr
== VB
->ObjPtr
)
259 required
|= VERT_OBJ
;
261 /* _tnl_print_vert_flags("_tnl_upgrade_client_data", required); */
263 if ((required
& VERT_OBJ
) && (VB
->ObjPtr
->flags
& flags
)) {
264 ASSERT(VB
->ObjPtr
== &inputs
->Obj
);
265 _tnl_import_vertex( ctx
, writeable
, stride
);
266 VB
->importable_data
&= ~(VERT_OBJ
|VERT_CLIP
);
269 if ((required
& VERT_NORM
) && (VB
->NormalPtr
->flags
& flags
)) {
270 ASSERT(VB
->NormalPtr
== &inputs
->Normal
);
271 _tnl_import_normal( ctx
, writeable
, stride
);
272 VB
->importable_data
&= ~VERT_NORM
;
275 if ((required
& VERT_RGBA
) && (VB
->ColorPtr
[0]->flags
& flags
)) {
276 ASSERT(VB
->ColorPtr
[0] == &inputs
->Color
);
277 _tnl_import_color( ctx
, writeable
, stride
);
278 VB
->importable_data
&= ~VERT_RGBA
;
281 if ((required
& VERT_SPEC_RGB
) && (VB
->SecondaryColorPtr
[0]->flags
&flags
)) {
282 ASSERT(VB
->SecondaryColorPtr
[0] == &inputs
->SecondaryColor
);
283 _tnl_import_secondarycolor( ctx
, writeable
, stride
);
284 VB
->importable_data
&= ~VERT_SPEC_RGB
;
287 if ((required
& VERT_FOG_COORD
) && (VB
->FogCoordPtr
->flags
& flags
)) {
288 ASSERT(VB
->FogCoordPtr
== &inputs
->FogCoord
);
289 _tnl_import_fogcoord( ctx
, writeable
, stride
);
290 VB
->importable_data
&= ~VERT_FOG_COORD
;
293 if ((required
& VERT_INDEX
) && (VB
->IndexPtr
[0]->flags
& flags
)) {
294 ASSERT(VB
->IndexPtr
[0] == &inputs
->Index
);
295 _tnl_import_index( ctx
, writeable
, stride
);
296 VB
->importable_data
&= ~VERT_INDEX
;
299 if (required
& VERT_TEX_ANY
)
300 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++)
301 if ((required
& VERT_TEX(i
)) && (VB
->TexCoordPtr
[i
]->flags
& flags
)) {
302 ASSERT(VB
->TexCoordPtr
[i
] == &inputs
->TexCoord
[i
]);
303 _tnl_import_texcoord( ctx
, i
, writeable
, stride
);
304 VB
->importable_data
&= ~VERT_TEX(i
);
313 void _tnl_vb_bind_arrays( GLcontext
*ctx
, GLint start
, GLsizei count
)
315 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
316 struct vertex_buffer
*VB
= &tnl
->vb
;
317 GLuint inputs
= tnl
->pipeline
.inputs
;
319 struct vertex_arrays
*tmp
= &tnl
->array_inputs
;
321 /* fprintf(stderr, "_tnl_vb_bind_arrays %d..%d // %d..%d\n", */
322 /* start, count, ctx->Array.LockFirst, ctx->Array.LockCount); */
324 if (ctx
->Array
.LockCount
) {
325 ASSERT(start
== (GLint
) ctx
->Array
.LockFirst
);
326 ASSERT(count
== (GLint
) ctx
->Array
.LockCount
);
329 imports
= tnl
->pipeline
.inputs
;
331 _ac_import_range( ctx
, start
, count
);
333 VB
->Count
= count
- start
;
334 VB
->FirstClipped
= VB
->Count
;
337 VB
->MaterialMask
= 0;
341 /* _tnl_print_vert_flags("_tnl_vb_bind_arrays: inputs", inputs); */
342 /* _tnl_print_vert_flags("_tnl_vb_bind_arrays: imports", imports); */
343 /* _tnl_print_vert_flags("_tnl_vb_bind_arrays: _Enabled", ctx->Array._Enabled); */
345 if (inputs
& VERT_OBJ
) {
346 if (imports
& VERT_OBJ
) {
347 _tnl_import_vertex( ctx
, 0, 0 );
348 tmp
->Obj
.count
= VB
->Count
;
350 VB
->ObjPtr
= &tmp
->Obj
;
353 if (inputs
& VERT_NORM
) {
354 if (imports
& VERT_NORM
) {
355 _tnl_import_normal( ctx
, 0, 0 );
356 tmp
->Normal
.count
= VB
->Count
;
358 VB
->NormalPtr
= &tmp
->Normal
;
361 if (inputs
& VERT_RGBA
) {
362 if (imports
& VERT_RGBA
) {
363 _tnl_import_color( ctx
, 0, 0 );
364 tmp
->Color
.count
= VB
->Count
;
366 VB
->ColorPtr
[0] = &tmp
->Color
;
370 if (inputs
& VERT_INDEX
) {
371 if (imports
& VERT_INDEX
) {
372 _tnl_import_index( ctx
, 0, 0 );
373 tmp
->Index
.count
= VB
->Count
;
375 VB
->IndexPtr
[0] = &tmp
->Index
;
380 if (inputs
& VERT_FOG_COORD
) {
381 if (imports
& VERT_FOG_COORD
) {
382 _tnl_import_fogcoord( ctx
, 0, 0 );
383 tmp
->FogCoord
.count
= VB
->Count
;
385 VB
->FogCoordPtr
= &tmp
->FogCoord
;
388 if (inputs
& VERT_EDGE
) {
389 _tnl_import_edgeflag( ctx
, GL_TRUE
, sizeof(GLboolean
) );
390 VB
->EdgeFlag
= (GLboolean
*) tmp
->EdgeFlag
.data
;
393 if (inputs
& VERT_SPEC_RGB
) {
394 if (imports
& VERT_SPEC_RGB
) {
395 _tnl_import_secondarycolor( ctx
, 0, 0 );
396 tmp
->SecondaryColor
.count
= VB
->Count
;
398 VB
->SecondaryColorPtr
[0] = &tmp
->SecondaryColor
;
399 VB
->SecondaryColorPtr
[1] = 0;
402 if (inputs
& VERT_TEX_ANY
) {
404 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++)
405 if (inputs
& VERT_TEX(i
)) {
406 if (imports
& VERT_TEX(i
)) {
407 _tnl_import_texcoord( ctx
, i
, 0, 0 );
408 tmp
->TexCoord
[i
].count
= VB
->Count
;
410 VB
->TexCoordPtr
[i
] = &tmp
->TexCoord
[i
];
414 VB
->Primitive
= tnl
->tmp_primitive
;
415 VB
->PrimitiveLength
= tnl
->tmp_primitive_length
;
416 VB
->import_data
= _tnl_upgrade_client_data
;
417 VB
->importable_data
= imports
& VERT_FIXUP
;
418 /* _tnl_print_vert_flags("_tnl_vb_bind_arrays: importable", VB->importable_data); */
425 /* Function to fill an immediate struct with the effects of
426 * consecutive calls to ArrayElement with consecutive indices.
428 void _tnl_fill_immediate_drawarrays( GLcontext
*ctx
, struct immediate
*IM
,
429 GLuint start
, GLuint count
)
431 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
432 GLuint required
= ctx
->Array
._Enabled
;
433 GLuint n
= count
- start
;
436 if (!ctx
->CompileFlag
)
437 required
&= tnl
->pipeline
.inputs
;
439 if (MESA_VERBOSE
&VERBOSE_IMMEDIATE
)
440 fprintf(stderr
, "exec_full_array_elements %d .. %d\n", start
, count
);
442 _math_trans_4f( IM
->Obj
+ IM
->Start
,
443 ctx
->Array
.Vertex
.Ptr
,
444 ctx
->Array
.Vertex
.StrideB
,
445 ctx
->Array
.Vertex
.Type
,
446 ctx
->Array
.Vertex
.Size
,
449 if (ctx
->Array
.Vertex
.Size
== 4)
450 required
|= VERT_OBJ_234
;
451 else if (ctx
->Array
.Vertex
.Size
== 3)
452 required
|= VERT_OBJ_23
;
455 if (required
& VERT_NORM
) {
456 _math_trans_3f( IM
->Normal
+ IM
->Start
,
457 ctx
->Array
.Normal
.Ptr
,
458 ctx
->Array
.Normal
.StrideB
,
459 ctx
->Array
.Normal
.Type
,
463 if (required
& VERT_EDGE
) {
464 _math_trans_1ub( IM
->EdgeFlag
+ IM
->Start
,
465 ctx
->Array
.EdgeFlag
.Ptr
,
466 ctx
->Array
.EdgeFlag
.StrideB
,
467 ctx
->Array
.EdgeFlag
.Type
,
471 if (required
& VERT_RGBA
) {
472 _math_trans_4chan( IM
->Color
+ IM
->Start
,
473 ctx
->Array
.Color
.Ptr
,
474 ctx
->Array
.Color
.StrideB
,
475 ctx
->Array
.Color
.Type
,
476 ctx
->Array
.Color
.Size
,
480 if (required
& VERT_SPEC_RGB
) {
481 _math_trans_4chan( IM
->SecondaryColor
+ IM
->Start
,
482 ctx
->Array
.SecondaryColor
.Ptr
,
483 ctx
->Array
.SecondaryColor
.StrideB
,
484 ctx
->Array
.SecondaryColor
.Type
,
485 ctx
->Array
.SecondaryColor
.Size
,
489 if (required
& VERT_FOG_COORD
) {
490 _math_trans_1f( IM
->FogCoord
+ IM
->Start
,
491 ctx
->Array
.FogCoord
.Ptr
,
492 ctx
->Array
.FogCoord
.StrideB
,
493 ctx
->Array
.FogCoord
.Type
,
497 if (required
& VERT_INDEX
) {
498 _math_trans_1ui( IM
->Index
+ IM
->Start
,
499 ctx
->Array
.Index
.Ptr
,
500 ctx
->Array
.Index
.StrideB
,
501 ctx
->Array
.Index
.Type
,
505 if (required
& VERT_TEX_ANY
) {
506 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
507 if (required
& VERT_TEX(i
)) {
508 _math_trans_4f( IM
->TexCoord
[i
] + IM
->Start
,
509 ctx
->Array
.TexCoord
[i
].Ptr
,
510 ctx
->Array
.TexCoord
[i
].StrideB
,
511 ctx
->Array
.TexCoord
[i
].Type
,
512 ctx
->Array
.TexCoord
[i
].Size
,
515 if (ctx
->Array
.TexCoord
[i
].Size
== 4)
516 IM
->TexSize
|= TEX_SIZE_4(i
);
517 else if (ctx
->Array
.TexCoord
[i
].Size
== 3)
518 IM
->TexSize
|= TEX_SIZE_3(i
);
523 IM
->Count
= IM
->Start
+ n
;
524 IM
->Flag
[IM
->Start
] |= required
;
525 for (i
= IM
->Start
+1 ; i
< IM
->Count
; i
++)
526 IM
->Flag
[i
] = required
;