2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * New (3.1) transformation code written by Keith Whitwell.
30 #include "main/glheader.h"
31 #include "main/imports.h"
32 #include "main/macros.h"
39 * Given a vector [count][4] of floats, set all the [][elt] values
40 * to 0 (if elt = 0, 1, 2) or 1.0 (if elt = 3).
43 _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
];
63 static const GLubyte size_bits
[5] = {
73 * Initialize GLvector objects.
74 * \param v the vector object to initialize.
75 * \param flags bitwise-OR of VEC_* flags
76 * \param storage pointer to storage for the vector's data
79 _mesa_vector4f_init( GLvector4f
*v
, GLbitfield flags
, GLfloat (*storage
)[4] )
81 v
->stride
= 4 * sizeof(GLfloat
);
82 v
->size
= 2; /* may change: 2-4 for vertices and 1-4 for texcoords */
84 v
->start
= (GLfloat
*) storage
;
86 v
->flags
= size_bits
[4] | flags
;
91 * Initialize GLvector objects and allocate storage.
92 * \param v the vector object
93 * \param flags bitwise-OR of VEC_* flags
94 * \param count number of elements to allocate in vector
95 * \param alignment desired memory alignment for the data (in bytes)
98 _mesa_vector4f_alloc( GLvector4f
*v
, GLbitfield flags
, GLuint count
,
101 v
->stride
= 4 * sizeof(GLfloat
);
103 v
->storage
= _mesa_align_malloc( count
* 4 * sizeof(GLfloat
), alignment
);
104 v
->storage_count
= count
;
105 v
->start
= (GLfloat
*) v
->storage
;
106 v
->data
= (GLfloat (*)[4]) v
->storage
;
108 v
->flags
= size_bits
[4] | flags
| VEC_MALLOC
;
113 * Vector deallocation. Free whatever memory is pointed to by the
114 * vector's storage field if the VEC_MALLOC flag is set.
115 * DO NOT free the GLvector object itself, though.
118 _mesa_vector4f_free( GLvector4f
*v
)
120 if (v
->flags
& VEC_MALLOC
) {
121 _mesa_align_free( v
->storage
);
125 v
->flags
&= ~VEC_MALLOC
;
134 _mesa_vector4f_print( const GLvector4f
*v
, const GLubyte
*cullmask
,
137 static const GLfloat c
[4] = { 0, 0, 0, 1 };
138 static const char *templates
[5] = {
140 "%d:\t%f, 0, 0, 1\n",
141 "%d:\t%f, %f, 0, 1\n",
142 "%d:\t%f, %f, %f, 1\n",
143 "%d:\t%f, %f, %f, %f\n"
146 const char *t
= templates
[v
->size
];
147 GLfloat
*d
= (GLfloat
*)v
->data
;
148 GLuint j
, i
= 0, count
;
150 printf("data-start\n");
151 for (; d
!= v
->start
; STRIDE_F(d
, v
->stride
), i
++)
152 printf(t
, i
, d
[0], d
[1], d
[2], d
[3]);
154 printf("start-count(%u)\n", v
->count
);
155 count
= i
+ v
->count
;
158 for (; i
< count
; STRIDE_F(d
, v
->stride
), i
++)
160 printf(t
, i
, d
[0], d
[1], d
[2], d
[3]);
163 for (; i
< count
; STRIDE_F(d
, v
->stride
), i
++)
164 printf(t
, i
, d
[0], d
[1], d
[2], d
[3]);
167 for (j
= v
->size
; j
< 4; j
++) {
168 if ((v
->flags
& (1<<j
)) == 0) {
170 printf("checking col %u is clean as advertised ", j
);
172 for (i
= 0, d
= (GLfloat
*) v
->data
;
173 i
< count
&& d
[j
] == c
[j
];
174 i
++, STRIDE_F(d
, v
->stride
)) {
181 printf(" --> Failed at %u ******\n", i
);