3ad81d468b2f5bf5961b5a1f32315f62fd38b509
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.
41 * Given a vector [count][4] of floats, set all the [][elt] values
42 * to 0 (if elt = 0, 1, 2) or 1.0 (if elt = 3).
44 void _mesa_vector4f_clean_elem( GLvector4f
*vec
, GLuint count
, GLuint elt
)
46 static const GLubyte elem_bits
[4] = {
52 static const GLfloat clean
[4] = { 0, 0, 0, 1 };
53 const GLfloat v
= clean
[elt
];
54 GLfloat (*data
)[4] = (GLfloat (*)[4])vec
->start
;
57 for (i
= 0 ; i
< count
; i
++)
60 vec
->flags
&= ~elem_bits
[elt
];
63 static const GLubyte size_bits
[5] = {
74 * Initialize GLvector objects.
75 * Input: v - the vector object to initialize.
76 * flags - bitwise-OR of VEC_* flags
77 * storage - pointer to storage for the vector's data
81 void _mesa_vector4f_init( GLvector4f
*v
, GLuint flags
, GLfloat (*storage
)[4] )
83 v
->stride
= 4 * sizeof(GLfloat
);
84 v
->size
= 2; /* may change: 2-4 for vertices and 1-4 for texcoords */
86 v
->start
= (GLfloat
*) storage
;
88 v
->flags
= size_bits
[4] | flags
;
95 * Initialize GLvector objects and allocate storage.
96 * Input: v - the vector object
98 * flags - bitwise-OR of VEC_* flags
99 * count - number of elements to allocate in vector
100 * alignment - desired memory alignment for the data (in bytes)
104 void _mesa_vector4f_alloc( GLvector4f
*v
, GLuint flags
, GLuint count
,
107 v
->stride
= 4 * sizeof(GLfloat
);
109 v
->storage
= ALIGN_MALLOC( count
* 4 * sizeof(GLfloat
), alignment
);
110 v
->start
= (GLfloat
*) v
->storage
;
111 v
->data
= (GLfloat (*)[4]) v
->storage
;
113 v
->flags
= size_bits
[4] | flags
| VEC_MALLOC
;
120 * Vector deallocation. Free whatever memory is pointed to by the
121 * vector's storage field if the VEC_MALLOC flag is set.
122 * DO NOT free the GLvector object itself, though.
126 void _mesa_vector4f_free( GLvector4f
*v
)
128 if (v
->flags
& VEC_MALLOC
) {
129 ALIGN_FREE( v
->storage
);
133 v
->flags
&= ~VEC_MALLOC
;
141 void _mesa_vector4f_print( GLvector4f
*v
, GLubyte
*cullmask
, GLboolean culling
)
143 GLfloat c
[4] = { 0, 0, 0, 1 };
144 const char *templates
[5] = {
146 "%d:\t%f, 0, 0, 1\n",
147 "%d:\t%f, %f, 0, 1\n",
148 "%d:\t%f, %f, %f, 1\n",
149 "%d:\t%f, %f, %f, %f\n"
152 const char *t
= templates
[v
->size
];
153 GLfloat
*d
= (GLfloat
*)v
->data
;
154 GLuint j
, i
= 0, count
;
156 _mesa_printf("data-start\n");
157 for ( ; d
!= v
->start
; STRIDE_F(d
, v
->stride
), i
++)
158 _mesa_printf(t
, i
, d
[0], d
[1], d
[2], d
[3]);
160 _mesa_printf("start-count(%u)\n", v
->count
);
161 count
= i
+ v
->count
;
164 for ( ; i
< count
; STRIDE_F(d
, v
->stride
), i
++)
166 _mesa_printf(t
, i
, d
[0], d
[1], d
[2], d
[3]);
169 for ( ; i
< count
; STRIDE_F(d
, v
->stride
), i
++)
170 _mesa_printf(t
, i
, d
[0], d
[1], d
[2], d
[3]);
173 for (j
= v
->size
; j
< 4; j
++) {
174 if ((v
->flags
& (1<<j
)) == 0) {
176 _mesa_printf("checking col %u is clean as advertised ", j
);
178 for (i
= 0, d
= (GLfloat
*) v
->data
;
179 i
< count
&& d
[j
] == c
[j
] ;
180 i
++, STRIDE_F(d
, v
->stride
)) {};
183 _mesa_printf(" --> ok\n");
185 _mesa_printf(" --> Failed at %u ******\n", i
);