1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
/* $Id: t_array_import.c,v 1.25 2002/06/29 19:48:17 brianp Exp $ */
/*
* Mesa 3-D graphics library
* Version: 4.1
*
* Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Authors:
* Keith Whitwell <keithw@valinux.com>
*/
#include "glheader.h"
#include "context.h"
#include "macros.h"
#include "mem.h"
#include "mmath.h"
#include "state.h"
#include "mtypes.h"
#include "array_cache/acache.h"
#include "math/m_translate.h"
#include "t_array_import.h"
#include "t_context.h"
#include "t_imm_debug.h"
static void _tnl_import_vertex( GLcontext *ctx,
GLboolean writeable,
GLboolean stride )
{
struct gl_client_array *tmp;
GLboolean is_writeable = 0;
struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
tmp = _ac_import_vertex(ctx,
GL_FLOAT,
stride ? 4*sizeof(GLfloat) : 0,
0,
writeable,
&is_writeable);
inputs->Obj.data = (GLfloat (*)[4]) tmp->Ptr;
inputs->Obj.start = (GLfloat *) tmp->Ptr;
inputs->Obj.stride = tmp->StrideB;
inputs->Obj.size = tmp->Size;
inputs->Obj.flags &= ~(VEC_BAD_STRIDE|VEC_NOT_WRITEABLE);
if (inputs->Obj.stride != 4*sizeof(GLfloat))
inputs->Obj.flags |= VEC_BAD_STRIDE;
if (!is_writeable)
inputs->Obj.flags |= VEC_NOT_WRITEABLE;
}
static void _tnl_import_normal( GLcontext *ctx,
GLboolean writeable,
GLboolean stride )
{
struct gl_client_array *tmp;
GLboolean is_writeable = 0;
struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
tmp = _ac_import_normal(ctx, GL_FLOAT,
stride ? 3*sizeof(GLfloat) : 0, writeable,
&is_writeable);
inputs->Normal.data = (GLfloat (*)[4]) tmp->Ptr;
inputs->Normal.start = (GLfloat *) tmp->Ptr;
inputs->Normal.stride = tmp->StrideB;
inputs->Normal.flags &= ~(VEC_BAD_STRIDE|VEC_NOT_WRITEABLE);
if (inputs->Normal.stride != 3*sizeof(GLfloat))
inputs->Normal.flags |= VEC_BAD_STRIDE;
if (!is_writeable)
inputs->Normal.flags |= VEC_NOT_WRITEABLE;
}
static void _tnl_import_color( GLcontext *ctx,
GLenum type,
GLboolean writeable,
GLboolean stride )
{
struct gl_client_array *tmp;
GLboolean is_writeable = 0;
struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
tmp = _ac_import_color(ctx,
type,
stride ? 4*sizeof(GLfloat) : 0,
4,
writeable,
&is_writeable);
inputs->Color = *tmp;
}
static void _tnl_import_secondarycolor( GLcontext *ctx,
GLenum type,
GLboolean writeable,
GLboolean stride )
{
struct gl_client_array *tmp;
GLboolean is_writeable = 0;
struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
tmp = _ac_import_secondarycolor(ctx,
type,
stride ? 4*sizeof(GLfloat) : 0,
4,
writeable,
&is_writeable);
inputs->SecondaryColor = *tmp;
}
static void _tnl_import_fogcoord( GLcontext *ctx,
GLboolean writeable,
GLboolean stride )
{
struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
struct gl_client_array *tmp;
GLboolean is_writeable = 0;
tmp = _ac_import_fogcoord(ctx, GL_FLOAT,
stride ? sizeof(GLfloat) : 0, writeable,
&is_writeable);
inputs->FogCoord.data = (GLfloat (*)[4]) tmp->Ptr;
inputs->FogCoord.start = (GLfloat *) tmp->Ptr;
inputs->FogCoord.stride = tmp->StrideB;
inputs->FogCoord.flags &= ~(VEC_BAD_STRIDE|VEC_NOT_WRITEABLE);
if (inputs->FogCoord.stride != sizeof(GLfloat))
inputs->FogCoord.flags |= VEC_BAD_STRIDE;
if (!is_writeable)
inputs->FogCoord.flags |= VEC_NOT_WRITEABLE;
}
static void _tnl_import_index( GLcontext *ctx,
GLboolean writeable,
GLboolean stride )
{
struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
struct gl_client_array *tmp;
GLboolean is_writeable = 0;
tmp = _ac_import_index(ctx, GL_UNSIGNED_INT,
stride ? sizeof(GLuint) : 0, writeable,
&is_writeable);
inputs->Index.data = (GLuint *) tmp->Ptr;
inputs->Index.start = (GLuint *) tmp->Ptr;
inputs->Index.stride = tmp->StrideB;
inputs->Index.flags &= ~(VEC_BAD_STRIDE|VEC_NOT_WRITEABLE);
if (inputs->Index.stride != sizeof(GLuint))
inputs->Index.flags |= VEC_BAD_STRIDE;
if (!is_writeable)
inputs->Index.flags |= VEC_NOT_WRITEABLE;
}
static void _tnl_import_texcoord( GLcontext *ctx,
GLuint unit,
GLboolean writeable,
GLboolean stride )
{
struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
struct gl_client_array *tmp;
GLboolean is_writeable = 0;
tmp = _ac_import_texcoord(ctx, unit, GL_FLOAT,
stride ? 4 * sizeof(GLfloat) : 0,
0,
writeable,
&is_writeable);
inputs->TexCoord[unit].data = (GLfloat (*)[4]) tmp->Ptr;
inputs->TexCoord[unit].start = (GLfloat *) tmp->Ptr;
inputs->TexCoord[unit].stride = tmp->StrideB;
inputs->TexCoord[unit].size = tmp->Size;
inputs->TexCoord[unit].flags &= ~(VEC_BAD_STRIDE|VEC_NOT_WRITEABLE);
if (inputs->TexCoord[unit].stride != 4*sizeof(GLfloat))
inputs->TexCoord[unit].flags |= VEC_BAD_STRIDE;
if (!is_writeable)
inputs->TexCoord[unit].flags |= VEC_NOT_WRITEABLE;
}
static void _tnl_import_edgeflag( GLcontext *ctx,
GLboolean writeable,
GLboolean stride )
{
struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
struct gl_client_array *tmp;
GLboolean is_writeable = 0;
tmp = _ac_import_edgeflag(ctx, GL_UNSIGNED_BYTE,
stride ? sizeof(GLubyte) : 0,
0,
&is_writeable);
inputs->EdgeFlag.data = (GLubyte *) tmp->Ptr;
inputs->EdgeFlag.start = (GLubyte *) tmp->Ptr;
inputs->EdgeFlag.stride = tmp->StrideB;
inputs->EdgeFlag.flags &= ~(VEC_BAD_STRIDE|VEC_NOT_WRITEABLE);
if (inputs->EdgeFlag.stride != sizeof(GLubyte))
inputs->EdgeFlag.flags |= VEC_BAD_STRIDE;
if (!is_writeable)
inputs->EdgeFlag.flags |= VEC_NOT_WRITEABLE;
}
static void _tnl_import_attrib( GLcontext *ctx,
GLuint index,
GLboolean writeable,
GLboolean stride )
{
struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
struct gl_client_array *tmp;
GLboolean is_writeable = 0;
tmp = _ac_import_attrib(ctx, index, GL_FLOAT,
stride ? 4 * sizeof(GLfloat) : 0,
4, /* want GLfloat[4] */
writeable,
&is_writeable);
inputs->Attribs[index].data = (GLfloat (*)[4]) tmp->Ptr;
inputs->Attribs[index].start = (GLfloat *) tmp->Ptr;
inputs->Attribs[index].stride = tmp->StrideB;
inputs->Attribs[index].size = tmp->Size;
inputs->Attribs[index].flags &= ~(VEC_BAD_STRIDE|VEC_NOT_WRITEABLE);
if (inputs->Attribs[index].stride != 4 * sizeof(GLfloat))
inputs->Attribs[index].flags |= VEC_BAD_STRIDE;
if (!is_writeable)
inputs->Attribs[index].flags |= VEC_NOT_WRITEABLE;
}
/**
* Callback for VB stages that need to improve the quality of arrays
* bound to the VB. This is only necessary for client arrays which
* have not been transformed at any point in the pipeline.
* \param required - bitmask of VERT_*_BIT flags
* \param flags - bitmask of VEC_* flags (ex: VEC_NOT_WRITABLE)
*/
static void _tnl_upgrade_client_data( GLcontext *ctx,
GLuint required,
GLuint flags )
{
GLuint i;
struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
GLboolean writeable = (flags & VEC_NOT_WRITEABLE) != 0;
GLboolean stride = (flags & VEC_BAD_STRIDE) != 0;
struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs;
GLuint ca_flags = 0;
(void) inputs;
if (writeable || stride) ca_flags |= CA_CLIENT_DATA;
if ((required & VERT_BIT_CLIP) && VB->ClipPtr == VB->ObjPtr)
required |= VERT_BIT_POS;
/* _tnl_print_vert_flags("_tnl_upgrade_client_data", required); */
if ((required & VERT_BIT_POS) && (VB->ObjPtr->flags & flags)) {
ASSERT(VB->ObjPtr == &inputs->Obj);
_tnl_import_vertex( ctx, writeable, stride );
VB->importable_data &= ~(VERT_BIT_POS|VERT_BIT_CLIP);
}
if ((required & VERT_BIT_NORMAL) && (VB->NormalPtr->flags & flags)) {
ASSERT(VB->NormalPtr == &inputs->Normal);
_tnl_import_normal( ctx, writeable, stride );
VB->importable_data &= ~VERT_BIT_NORMAL;
}
if ((required & VERT_BIT_COLOR0) && (VB->ColorPtr[0]->Flags & ca_flags)) {
ASSERT(VB->ColorPtr[0] == &inputs->Color);
_tnl_import_color( ctx, GL_FLOAT, writeable, stride );
VB->importable_data &= ~VERT_BIT_COLOR0;
}
if ((required & VERT_BIT_COLOR1) &&
(VB->SecondaryColorPtr[0]->Flags & ca_flags)) {
ASSERT(VB->SecondaryColorPtr[0] == &inputs->SecondaryColor);
_tnl_import_secondarycolor( ctx, GL_FLOAT, writeable, stride );
VB->importable_data &= ~VERT_BIT_COLOR1;
}
if ((required & VERT_BIT_FOG)
&& (VB->FogCoordPtr->flags & flags)) {
ASSERT(VB->FogCoordPtr == &inputs->FogCoord);
_tnl_import_fogcoord( ctx, writeable, stride );
VB->importable_data &= ~VERT_BIT_FOG;
}
if ((required & VERT_BIT_INDEX) && (VB->IndexPtr[0]->flags & flags)) {
ASSERT(VB->IndexPtr[0] == &inputs->Index);
_tnl_import_index( ctx, writeable, stride );
VB->importable_data &= ~VERT_BIT_INDEX;
}
if (required & VERT_BITS_TEX_ANY)
for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++)
if ((required & VERT_BIT_TEX(i)) && (VB->TexCoordPtr[i]->flags & flags)) {
ASSERT(VB->TexCoordPtr[i] == &inputs->TexCoord[i]);
_tnl_import_texcoord( ctx, i, writeable, stride );
VB->importable_data &= ~VERT_BIT_TEX(i);
}
/* XXX not sure what to do here for vertex program arrays */
}
void _tnl_vb_bind_arrays( GLcontext *ctx, GLint start, GLsizei count )
{
TNLcontext *tnl = TNL_CONTEXT(ctx);
struct vertex_buffer *VB = &tnl->vb;
GLuint inputs = tnl->pipeline.inputs;
struct vertex_arrays *tmp = &tnl->array_inputs;
/* _mesa_debug(ctx, "%s %d..%d // %d..%d\n", __FUNCTION__, */
/* start, count, ctx->Array.LockFirst, ctx->Array.LockCount); */
/* _tnl_print_vert_flags(" inputs", inputs); */
/* _tnl_print_vert_flags(" _Enabled", ctx->Array._Enabled); */
/* _tnl_print_vert_flags(" importable", inputs & VERT_BITS_FIXUP); */
VB->Count = count - start;
VB->FirstClipped = VB->Count;
VB->Elts = NULL;
VB->MaterialMask = NULL;
VB->Material = NULL;
VB->Flag = NULL;
VB->Primitive = tnl->tmp_primitive;
VB->PrimitiveLength = tnl->tmp_primitive_length;
VB->import_data = _tnl_upgrade_client_data;
VB->importable_data = inputs & VERT_BITS_FIXUP;
if (ctx->Array.LockCount) {
ASSERT(start == (GLint) ctx->Array.LockFirst);
ASSERT(count == (GLint) ctx->Array.LockCount);
}
_ac_import_range( ctx, start, count );
if (inputs & VERT_BIT_POS) {
_tnl_import_vertex( ctx, 0, 0 );
tmp->Obj.count = VB->Count;
VB->ObjPtr = &tmp->Obj;
}
if (inputs & VERT_BIT_NORMAL) {
_tnl_import_normal( ctx, 0, 0 );
tmp->Normal.count = VB->Count;
VB->NormalPtr = &tmp->Normal;
}
if (inputs & VERT_BIT_COLOR0) {
_tnl_import_color( ctx, 0, 0, 0 );
VB->ColorPtr[0] = &tmp->Color;
VB->ColorPtr[1] = 0;
}
if (inputs & VERT_BITS_TEX_ANY) {
GLuint unit;
for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
if (inputs & VERT_BIT_TEX(unit)) {
_tnl_import_texcoord( ctx, unit, GL_FALSE, GL_FALSE );
tmp->TexCoord[unit].count = VB->Count;
VB->TexCoordPtr[unit] = &tmp->TexCoord[unit];
}
}
}
if (inputs & (VERT_BIT_INDEX | VERT_BIT_FOG |
VERT_BIT_EDGEFLAG | VERT_BIT_COLOR1)) {
if (inputs & VERT_BIT_INDEX) {
_tnl_import_index( ctx, 0, 0 );
tmp->Index.count = VB->Count;
VB->IndexPtr[0] = &tmp->Index;
VB->IndexPtr[1] = 0;
}
if (inputs & VERT_BIT_FOG) {
_tnl_import_fogcoord( ctx, 0, 0 );
tmp->FogCoord.count = VB->Count;
VB->FogCoordPtr = &tmp->FogCoord;
}
if (inputs & VERT_BIT_EDGEFLAG) {
_tnl_import_edgeflag( ctx, GL_TRUE, sizeof(GLboolean) );
VB->EdgeFlag = (GLboolean *) tmp->EdgeFlag.data;
}
if (inputs & VERT_BIT_COLOR1) {
_tnl_import_secondarycolor( ctx, 0, 0, 0 );
VB->SecondaryColorPtr[0] = &tmp->SecondaryColor;
VB->SecondaryColorPtr[1] = 0;
}
}
/* XXX not 100% sure this is finished. Keith should probably inspect. */
if (ctx->VertexProgram.Enabled) {
GLuint index;
for (index = 0; index < VERT_ATTRIB_MAX; index++) {
/* XXX check program->InputsRead to reduce work here */
_tnl_import_attrib( ctx, index, GL_FALSE, GL_TRUE );
VB->AttribPtr[index] = &tmp->Attribs[index];
}
}
}
|