~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/extras/Mesa/src/math/m_vector.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * Mesa 3-D graphics library
 
4
 * Version:  3.5
 
5
 *
 
6
 * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
 
7
 *
 
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:
 
14
 *
 
15
 * The above copyright notice and this permission notice shall be included
 
16
 * in all copies or substantial portions of the Software.
 
17
 *
 
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.
 
24
 */
 
25
 
 
26
/*
 
27
 * New (3.1) transformation code written by Keith Whitwell.
 
28
 */
 
29
 
 
30
 
 
31
#include "glheader.h"
 
32
#include "macros.h"
 
33
#include "mem.h"
 
34
 
 
35
#include "m_vector.h"
 
36
 
 
37
 
 
38
 
 
39
/*
 
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).
 
42
 */
 
43
void _mesa_vector4f_clean_elem( GLvector4f *vec, GLuint count, GLuint elt )
 
44
{
 
45
   static const GLubyte elem_bits[4] = {
 
46
      VEC_DIRTY_0,
 
47
      VEC_DIRTY_1,
 
48
      VEC_DIRTY_2,
 
49
      VEC_DIRTY_3
 
50
   };
 
51
   static const GLfloat clean[4] = { 0, 0, 0, 1 };
 
52
   const GLfloat v = clean[elt];
 
53
   GLfloat (*data)[4] = (GLfloat (*)[4])vec->start;
 
54
   GLuint i;
 
55
 
 
56
   for (i = 0 ; i < count ; i++)
 
57
      data[i][elt] = v;
 
58
 
 
59
   vec->flags &= ~elem_bits[elt];
 
60
}
 
61
 
 
62
static const GLubyte size_bits[5] = {
 
63
   0,
 
64
   VEC_SIZE_1,
 
65
   VEC_SIZE_2,
 
66
   VEC_SIZE_3,
 
67
   VEC_SIZE_4,
 
68
};
 
69
 
 
70
 
 
71
 
 
72
/*
 
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
 
77
 */
 
78
 
 
79
 
 
80
void _mesa_vector4f_init( GLvector4f *v, GLuint flags, GLfloat (*storage)[4] )
 
81
{
 
82
   v->stride = 4 * sizeof(GLfloat);
 
83
   v->size = 2;   /* may change: 2-4 for vertices and 1-4 for texcoords */
 
84
   v->data = storage;
 
85
   v->start = (GLfloat *) storage;
 
86
   v->count = 0;
 
87
   v->flags = size_bits[4] | flags ;
 
88
}
 
89
 
 
90
void _mesa_vector3f_init( GLvector3f *v, GLuint flags, GLfloat (*storage)[3] )
 
91
{
 
92
   v->stride = 3 * sizeof(GLfloat);
 
93
   v->data = storage;
 
94
   v->start = (GLfloat *) storage;
 
95
   v->count = 0;
 
96
   v->flags = flags ;
 
97
}
 
98
 
 
99
void _mesa_vector1f_init( GLvector1f *v, GLuint flags, GLfloat *storage )
 
100
{
 
101
   v->stride = 1*sizeof(GLfloat);
 
102
   v->data = storage;
 
103
   v->start = (GLfloat *)storage;
 
104
   v->count = 0;
 
105
   v->flags = flags ;
 
106
}
 
107
 
 
108
void _mesa_vector4ub_init( GLvector4ub *v, GLuint flags, GLubyte (*storage)[4] )
 
109
{
 
110
   v->stride = 4 * sizeof(GLubyte);
 
111
   v->data = storage;
 
112
   v->start = (GLubyte *) storage;
 
113
   v->count = 0;
 
114
   v->flags = flags ;
 
115
}
 
116
 
 
117
void _mesa_vector4chan_init( GLvector4chan *v, GLuint flags, GLchan (*storage)[4] )
 
118
{
 
119
   v->stride = 4 * sizeof(GLchan);
 
120
   v->data = storage;
 
121
   v->start = (GLchan *) storage;
 
122
   v->count = 0;
 
123
   v->flags = flags ;
 
124
}
 
125
 
 
126
void _mesa_vector4us_init( GLvector4us *v, GLuint flags, GLushort (*storage)[4] )
 
127
{
 
128
   v->stride = 4 * sizeof(GLushort);
 
129
   v->data = storage;
 
130
   v->start = (GLushort *) storage;
 
131
   v->count = 0;
 
132
   v->flags = flags ;
 
133
}
 
134
 
 
135
void _mesa_vector1ub_init( GLvector1ub *v, GLuint flags, GLubyte *storage )
 
136
{
 
137
   v->stride = 1 * sizeof(GLubyte);
 
138
   v->data = storage;
 
139
   v->start = (GLubyte *) storage;
 
140
   v->count = 0;
 
141
   v->flags = flags ;
 
142
}
 
143
 
 
144
void _mesa_vector1ui_init( GLvector1ui *v, GLuint flags, GLuint *storage )
 
145
{
 
146
   v->stride = 1 * sizeof(GLuint);
 
147
   v->data = storage;
 
148
   v->start = (GLuint *) storage;
 
149
   v->count = 0;
 
150
   v->flags = flags ;
 
151
}
 
152
 
 
153
 
 
154
/*
 
155
 * Initialize GLvector objects and allocate storage.
 
156
 * Input: v - the vector object
 
157
 *        sz - unused????
 
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)
 
161
 */
 
162
 
 
163
 
 
164
void _mesa_vector4f_alloc( GLvector4f *v, GLuint flags, GLuint count,
 
165
                        GLuint alignment )
 
166
{
 
167
   v->stride = 4 * sizeof(GLfloat);
 
168
   v->size = 2;
 
169
   v->storage = ALIGN_MALLOC( count * 4 * sizeof(GLfloat), alignment );
 
170
   v->start = (GLfloat *) v->storage;
 
171
   v->data = (GLfloat (*)[4]) v->storage;
 
172
   v->count = 0;
 
173
   v->flags = size_bits[4] | flags | VEC_MALLOC ;
 
174
}
 
175
 
 
176
void _mesa_vector3f_alloc( GLvector3f *v, GLuint flags, GLuint count,
 
177
                        GLuint alignment )
 
178
{
 
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;
 
183
   v->count = 0;
 
184
   v->flags = flags | VEC_MALLOC ;
 
185
}
 
186
 
 
187
void _mesa_vector1f_alloc( GLvector1f *v, GLuint flags, GLuint count,
 
188
                        GLuint alignment )
 
189
{
 
190
   v->stride = sizeof(GLfloat);
 
191
   v->storage = v->start = (GLfloat *)
 
192
      ALIGN_MALLOC( count * sizeof(GLfloat), alignment );
 
193
   v->data = v->start;
 
194
   v->count = 0;
 
195
   v->flags = flags | VEC_MALLOC ;
 
196
}
 
197
 
 
198
void _mesa_vector4ub_alloc( GLvector4ub *v, GLuint flags, GLuint count,
 
199
                         GLuint alignment )
 
200
{
 
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;
 
205
   v->count = 0;
 
206
   v->flags = flags | VEC_MALLOC ;
 
207
}
 
208
 
 
209
void _mesa_vector4chan_alloc( GLvector4chan *v, GLuint flags, GLuint count,
 
210
                           GLuint alignment )
 
211
{
 
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;
 
216
   v->count = 0;
 
217
   v->flags = flags | VEC_MALLOC ;
 
218
}
 
219
 
 
220
void _mesa_vector4us_alloc( GLvector4us *v, GLuint flags, GLuint count,
 
221
                         GLuint alignment )
 
222
{
 
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;
 
227
   v->count = 0;
 
228
   v->flags = flags | VEC_MALLOC ;
 
229
}
 
230
 
 
231
void _mesa_vector1ub_alloc( GLvector1ub *v, GLuint flags, GLuint count,
 
232
                         GLuint alignment )
 
233
{
 
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;
 
238
   v->count = 0;
 
239
   v->flags = flags | VEC_MALLOC ;
 
240
}
 
241
 
 
242
void _mesa_vector1ui_alloc( GLvector1ui *v, GLuint flags, GLuint count,
 
243
                         GLuint alignment )
 
244
{
 
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;
 
249
   v->count = 0;
 
250
   v->flags = flags | VEC_MALLOC ;
 
251
}
 
252
 
 
253
 
 
254
 
 
255
/*
 
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.
 
259
 */
 
260
 
 
261
 
 
262
void _mesa_vector4f_free( GLvector4f *v )
 
263
{
 
264
   if (v->flags & VEC_MALLOC) {
 
265
      ALIGN_FREE( v->storage );
 
266
      v->data = NULL;
 
267
      v->start = NULL;
 
268
      v->storage = NULL;
 
269
      v->flags &= ~VEC_MALLOC;
 
270
   }
 
271
}
 
272
 
 
273
void _mesa_vector3f_free( GLvector3f *v )
 
274
{
 
275
   if (v->flags & VEC_MALLOC) {
 
276
      ALIGN_FREE( v->storage );
 
277
      v->data = 0;
 
278
      v->start = 0;
 
279
      v->storage = 0;
 
280
      v->flags &= ~VEC_MALLOC;
 
281
   }
 
282
}
 
283
 
 
284
void _mesa_vector1f_free( GLvector1f *v )
 
285
{
 
286
   if (v->flags & VEC_MALLOC) {
 
287
      ALIGN_FREE( v->storage );
 
288
      v->data = NULL;
 
289
      v->start = NULL;
 
290
      v->storage = NULL;
 
291
      v->flags &= ~VEC_MALLOC;
 
292
   }
 
293
}
 
294
 
 
295
void _mesa_vector4ub_free( GLvector4ub *v )
 
296
{
 
297
   if (v->flags & VEC_MALLOC) {
 
298
      ALIGN_FREE( v->storage );
 
299
      v->data = NULL;
 
300
      v->start = NULL;
 
301
      v->storage = NULL;
 
302
      v->flags &= ~VEC_MALLOC;
 
303
   }
 
304
}
 
305
 
 
306
void _mesa_vector4chan_free( GLvector4chan *v )
 
307
{
 
308
   if (v->flags & VEC_MALLOC) {
 
309
      ALIGN_FREE( v->storage );
 
310
      v->data = NULL;
 
311
      v->start = NULL;
 
312
      v->storage = NULL;
 
313
      v->flags &= ~VEC_MALLOC;
 
314
   }
 
315
}
 
316
 
 
317
void _mesa_vector4us_free( GLvector4us *v )
 
318
{
 
319
   if (v->flags & VEC_MALLOC) {
 
320
      ALIGN_FREE( v->storage );
 
321
      v->data = NULL;
 
322
      v->start = NULL;
 
323
      v->storage = NULL;
 
324
      v->flags &= ~VEC_MALLOC;
 
325
   }
 
326
}
 
327
 
 
328
void _mesa_vector1ub_free( GLvector1ub *v )
 
329
{
 
330
   if (v->flags & VEC_MALLOC) {
 
331
      ALIGN_FREE( v->storage );
 
332
      v->data = NULL;
 
333
      v->start = NULL;
 
334
      v->storage = NULL;
 
335
      v->flags &= ~VEC_MALLOC;
 
336
   }
 
337
}
 
338
 
 
339
void _mesa_vector1ui_free( GLvector1ui *v )
 
340
{
 
341
   if (v->flags & VEC_MALLOC) {
 
342
      ALIGN_FREE( v->storage );
 
343
      v->data = NULL;
 
344
      v->start = NULL;
 
345
      v->storage = NULL;
 
346
      v->flags &= ~VEC_MALLOC;
 
347
   }
 
348
}
 
349
 
 
350
 
 
351
/*
 
352
 * For debugging
 
353
 */
 
354
void _mesa_vector4f_print( GLvector4f *v, GLubyte *cullmask, GLboolean culling )
 
355
{
 
356
   GLfloat c[4] = { 0, 0, 0, 1 };
 
357
   const char *templates[5] = {
 
358
      "%d:\t0, 0, 0, 1\n",
 
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"
 
363
   };
 
364
 
 
365
   const char *t = templates[v->size];
 
366
   GLfloat *d = (GLfloat *)v->data;
 
367
   GLuint j, i = 0, count;
 
368
 
 
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]);
 
372
 
 
373
   printf("start-count(%u)\n", v->count);
 
374
   count = i + v->count;
 
375
 
 
376
   if (culling) {
 
377
      for ( ; i < count ; STRIDE_F(d, v->stride), i++)
 
378
         if (cullmask[i])
 
379
            printf( t, i, d[0], d[1], d[2], d[3]);
 
380
   }
 
381
   else {
 
382
      for ( ; i < count ; STRIDE_F(d, v->stride), i++)
 
383
         printf( t, i, d[0], d[1], d[2], d[3]);
 
384
   }
 
385
 
 
386
   for (j = v->size ; j < 4; j++) {
 
387
      if ((v->flags & (1<<j)) == 0) {
 
388
 
 
389
         printf("checking col %u is clean as advertised ", j);
 
390
 
 
391
         for (i = 0, d = (GLfloat *) v->data ;
 
392
              i < count && d[j] == c[j] ;
 
393
              i++, STRIDE_F(d, v->stride)) {};
 
394
 
 
395
         if (i == count)
 
396
            printf(" --> ok\n");
 
397
         else
 
398
            printf(" --> Failed at %u ******\n", i);
 
399
      }
 
400
   }
 
401
}
 
402
 
 
403
 
 
404
/*
 
405
 * For debugging
 
406
 */
 
407
void _mesa_vector3f_print( GLvector3f *v, GLubyte *cullmask, GLboolean culling )
 
408
{
 
409
   GLfloat *d = (GLfloat *)v->data;
 
410
   GLuint i = 0, count;
 
411
 
 
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]);
 
415
 
 
416
   printf("start-count(%u)\n", v->count);
 
417
   count = i + v->count;
 
418
 
 
419
   if (culling) {
 
420
      for ( ; i < count ; STRIDE_F(d,v->stride), i++)
 
421
         if (cullmask[i])
 
422
            printf( "%u:\t%f, %f, %f\n", i, d[0], d[1], d[2]);
 
423
   }
 
424
   else {
 
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]);
 
427
   }
 
428
}