3
* Mesa 3-D graphics library
6
* Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8
* Permission is hereby granted, free of charge, to any person obtaining a
9
* copy of this software and associated documentation files (the "Software"),
10
* to deal in the Software without restriction, including without limitation
11
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
* and/or sell copies of the Software, and to permit persons to whom the
13
* Software is furnished to do so, subject to the following conditions:
15
* The above copyright notice and this permission notice shall be included
16
* in all copies or substantial portions of the Software.
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
* New (3.1) transformation code written by Keith Whitwell.
40
* Given a vector [count][4] of floats, set all the [][elt] values
41
* to 0 (if elt = 0, 1, 2) or 1.0 (if elt = 3).
43
void _mesa_vector4f_clean_elem( GLvector4f *vec, GLuint count, GLuint elt )
45
static const GLubyte elem_bits[4] = {
51
static const GLfloat clean[4] = { 0, 0, 0, 1 };
52
const GLfloat v = clean[elt];
53
GLfloat (*data)[4] = (GLfloat (*)[4])vec->start;
56
for (i = 0 ; i < count ; i++)
59
vec->flags &= ~elem_bits[elt];
62
static const GLubyte size_bits[5] = {
73
* Initialize GLvector objects.
74
* Input: v - the vector object to initialize.
75
* flags - bitwise-OR of VEC_* flags
76
* storage - pointer to storage for the vector's data
80
void _mesa_vector4f_init( GLvector4f *v, GLuint flags, GLfloat (*storage)[4] )
82
v->stride = 4 * sizeof(GLfloat);
83
v->size = 2; /* may change: 2-4 for vertices and 1-4 for texcoords */
85
v->start = (GLfloat *) storage;
87
v->flags = size_bits[4] | flags ;
90
void _mesa_vector3f_init( GLvector3f *v, GLuint flags, GLfloat (*storage)[3] )
92
v->stride = 3 * sizeof(GLfloat);
94
v->start = (GLfloat *) storage;
99
void _mesa_vector1f_init( GLvector1f *v, GLuint flags, GLfloat *storage )
101
v->stride = 1*sizeof(GLfloat);
103
v->start = (GLfloat *)storage;
108
void _mesa_vector4ub_init( GLvector4ub *v, GLuint flags, GLubyte (*storage)[4] )
110
v->stride = 4 * sizeof(GLubyte);
112
v->start = (GLubyte *) storage;
117
void _mesa_vector4chan_init( GLvector4chan *v, GLuint flags, GLchan (*storage)[4] )
119
v->stride = 4 * sizeof(GLchan);
121
v->start = (GLchan *) storage;
126
void _mesa_vector4us_init( GLvector4us *v, GLuint flags, GLushort (*storage)[4] )
128
v->stride = 4 * sizeof(GLushort);
130
v->start = (GLushort *) storage;
135
void _mesa_vector1ub_init( GLvector1ub *v, GLuint flags, GLubyte *storage )
137
v->stride = 1 * sizeof(GLubyte);
139
v->start = (GLubyte *) storage;
144
void _mesa_vector1ui_init( GLvector1ui *v, GLuint flags, GLuint *storage )
146
v->stride = 1 * sizeof(GLuint);
148
v->start = (GLuint *) storage;
155
* Initialize GLvector objects and allocate storage.
156
* Input: v - the vector object
158
* flags - bitwise-OR of VEC_* flags
159
* count - number of elements to allocate in vector
160
* alignment - desired memory alignment for the data (in bytes)
164
void _mesa_vector4f_alloc( GLvector4f *v, GLuint flags, GLuint count,
167
v->stride = 4 * sizeof(GLfloat);
169
v->storage = ALIGN_MALLOC( count * 4 * sizeof(GLfloat), alignment );
170
v->start = (GLfloat *) v->storage;
171
v->data = (GLfloat (*)[4]) v->storage;
173
v->flags = size_bits[4] | flags | VEC_MALLOC ;
176
void _mesa_vector3f_alloc( GLvector3f *v, GLuint flags, GLuint count,
179
v->stride = 3 * sizeof(GLfloat);
180
v->storage = ALIGN_MALLOC( count * 3 * sizeof(GLfloat), alignment );
181
v->start = (GLfloat *) v->storage;
182
v->data = (GLfloat (*)[3]) v->storage;
184
v->flags = flags | VEC_MALLOC ;
187
void _mesa_vector1f_alloc( GLvector1f *v, GLuint flags, GLuint count,
190
v->stride = sizeof(GLfloat);
191
v->storage = v->start = (GLfloat *)
192
ALIGN_MALLOC( count * sizeof(GLfloat), alignment );
195
v->flags = flags | VEC_MALLOC ;
198
void _mesa_vector4ub_alloc( GLvector4ub *v, GLuint flags, GLuint count,
201
v->stride = 4 * sizeof(GLubyte);
202
v->storage = ALIGN_MALLOC( count * 4 * sizeof(GLubyte), alignment );
203
v->start = (GLubyte *) v->storage;
204
v->data = (GLubyte (*)[4]) v->storage;
206
v->flags = flags | VEC_MALLOC ;
209
void _mesa_vector4chan_alloc( GLvector4chan *v, GLuint flags, GLuint count,
212
v->stride = 4 * sizeof(GLchan);
213
v->storage = ALIGN_MALLOC( count * 4 * sizeof(GLchan), alignment );
214
v->start = (GLchan *) v->storage;
215
v->data = (GLchan (*)[4]) v->storage;
217
v->flags = flags | VEC_MALLOC ;
220
void _mesa_vector4us_alloc( GLvector4us *v, GLuint flags, GLuint count,
223
v->stride = 4 * sizeof(GLushort);
224
v->storage = ALIGN_MALLOC( count * 4 * sizeof(GLushort), alignment );
225
v->start = (GLushort *) v->storage;
226
v->data = (GLushort (*)[4]) v->storage;
228
v->flags = flags | VEC_MALLOC ;
231
void _mesa_vector1ub_alloc( GLvector1ub *v, GLuint flags, GLuint count,
234
v->stride = 1 * sizeof(GLubyte);
235
v->storage = ALIGN_MALLOC( count * sizeof(GLubyte), alignment );
236
v->start = (GLubyte *) v->storage;
237
v->data = (GLubyte *) v->storage;
239
v->flags = flags | VEC_MALLOC ;
242
void _mesa_vector1ui_alloc( GLvector1ui *v, GLuint flags, GLuint count,
245
v->stride = 1 * sizeof(GLuint);
246
v->storage = ALIGN_MALLOC( count * sizeof(GLuint), alignment );
247
v->start = (GLuint *) v->storage;
248
v->data = (GLuint *) v->storage;
250
v->flags = flags | VEC_MALLOC ;
256
* Vector deallocation. Free whatever memory is pointed to by the
257
* vector's storage field if the VEC_MALLOC flag is set.
258
* DO NOT free the GLvector object itself, though.
262
void _mesa_vector4f_free( GLvector4f *v )
264
if (v->flags & VEC_MALLOC) {
265
ALIGN_FREE( v->storage );
269
v->flags &= ~VEC_MALLOC;
273
void _mesa_vector3f_free( GLvector3f *v )
275
if (v->flags & VEC_MALLOC) {
276
ALIGN_FREE( v->storage );
280
v->flags &= ~VEC_MALLOC;
284
void _mesa_vector1f_free( GLvector1f *v )
286
if (v->flags & VEC_MALLOC) {
287
ALIGN_FREE( v->storage );
291
v->flags &= ~VEC_MALLOC;
295
void _mesa_vector4ub_free( GLvector4ub *v )
297
if (v->flags & VEC_MALLOC) {
298
ALIGN_FREE( v->storage );
302
v->flags &= ~VEC_MALLOC;
306
void _mesa_vector4chan_free( GLvector4chan *v )
308
if (v->flags & VEC_MALLOC) {
309
ALIGN_FREE( v->storage );
313
v->flags &= ~VEC_MALLOC;
317
void _mesa_vector4us_free( GLvector4us *v )
319
if (v->flags & VEC_MALLOC) {
320
ALIGN_FREE( v->storage );
324
v->flags &= ~VEC_MALLOC;
328
void _mesa_vector1ub_free( GLvector1ub *v )
330
if (v->flags & VEC_MALLOC) {
331
ALIGN_FREE( v->storage );
335
v->flags &= ~VEC_MALLOC;
339
void _mesa_vector1ui_free( GLvector1ui *v )
341
if (v->flags & VEC_MALLOC) {
342
ALIGN_FREE( v->storage );
346
v->flags &= ~VEC_MALLOC;
354
void _mesa_vector4f_print( GLvector4f *v, GLubyte *cullmask, GLboolean culling )
356
GLfloat c[4] = { 0, 0, 0, 1 };
357
const char *templates[5] = {
359
"%d:\t%f, 0, 0, 1\n",
360
"%d:\t%f, %f, 0, 1\n",
361
"%d:\t%f, %f, %f, 1\n",
362
"%d:\t%f, %f, %f, %f\n"
365
const char *t = templates[v->size];
366
GLfloat *d = (GLfloat *)v->data;
367
GLuint j, i = 0, count;
369
printf("data-start\n");
370
for ( ; d != v->start ; STRIDE_F(d, v->stride), i++)
371
printf( t, i, d[0], d[1], d[2], d[3]);
373
printf("start-count(%u)\n", v->count);
374
count = i + v->count;
377
for ( ; i < count ; STRIDE_F(d, v->stride), i++)
379
printf( t, i, d[0], d[1], d[2], d[3]);
382
for ( ; i < count ; STRIDE_F(d, v->stride), i++)
383
printf( t, i, d[0], d[1], d[2], d[3]);
386
for (j = v->size ; j < 4; j++) {
387
if ((v->flags & (1<<j)) == 0) {
389
printf("checking col %u is clean as advertised ", j);
391
for (i = 0, d = (GLfloat *) v->data ;
392
i < count && d[j] == c[j] ;
393
i++, STRIDE_F(d, v->stride)) {};
398
printf(" --> Failed at %u ******\n", i);
407
void _mesa_vector3f_print( GLvector3f *v, GLubyte *cullmask, GLboolean culling )
409
GLfloat *d = (GLfloat *)v->data;
412
printf("data-start\n");
413
for ( ; d != v->start ; STRIDE_F(d,v->stride), i++)
414
printf( "%u:\t%f, %f, %f\n", i, d[0], d[1], d[2]);
416
printf("start-count(%u)\n", v->count);
417
count = i + v->count;
420
for ( ; i < count ; STRIDE_F(d,v->stride), i++)
422
printf( "%u:\t%f, %f, %f\n", i, d[0], d[1], d[2]);
425
for ( ; i < count ; STRIDE_F(d,v->stride), i++)
426
printf( "%u:\t%f, %f, %f\n", i, d[0], d[1], d[2]);