2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
26 * New (3.1) transformation code written by Keith Whitwell.
31 #include "main/glheader.h"
32 #include "main/imports.h"
33 #include "main/macros.h"
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).
44 _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
];
64 static const GLubyte size_bits
[5] = {
74 * Initialize GLvector objects.
75 * \param v the vector object to initialize.
76 * \param flags bitwise-OR of VEC_* flags
77 * \param storage pointer to storage for the vector's data
80 _mesa_vector4f_init( GLvector4f
*v
, GLbitfield flags
, GLfloat (*storage
)[4] )
82 STATIC_ASSERT(V4F_DATA
== offsetof(GLvector4f
, data
));
83 STATIC_ASSERT(V4F_START
== offsetof(GLvector4f
, start
));
84 STATIC_ASSERT(V4F_COUNT
== offsetof(GLvector4f
, count
));
85 STATIC_ASSERT(V4F_STRIDE
== offsetof(GLvector4f
, stride
));
86 STATIC_ASSERT(V4F_SIZE
== offsetof(GLvector4f
, size
));
87 STATIC_ASSERT(V4F_FLAGS
== offsetof(GLvector4f
, flags
));
89 v
->stride
= 4 * sizeof(GLfloat
);
90 v
->size
= 2; /* may change: 2-4 for vertices and 1-4 for texcoords */
92 v
->start
= (GLfloat
*) storage
;
94 v
->flags
= size_bits
[4] | flags
;
99 * Initialize GLvector objects and allocate storage.
100 * \param v the vector object
101 * \param flags bitwise-OR of VEC_* flags
102 * \param count number of elements to allocate in vector
103 * \param alignment desired memory alignment for the data (in bytes)
106 _mesa_vector4f_alloc( GLvector4f
*v
, GLbitfield flags
, GLuint count
,
109 v
->stride
= 4 * sizeof(GLfloat
);
111 v
->storage
= _mesa_align_malloc( count
* 4 * sizeof(GLfloat
), alignment
);
112 v
->storage_count
= count
;
113 v
->start
= (GLfloat
*) v
->storage
;
114 v
->data
= (GLfloat (*)[4]) v
->storage
;
116 v
->flags
= size_bits
[4] | flags
| VEC_MALLOC
;
121 * Vector deallocation. Free whatever memory is pointed to by the
122 * vector's storage field if the VEC_MALLOC flag is set.
123 * DO NOT free the GLvector object itself, though.
126 _mesa_vector4f_free( GLvector4f
*v
)
128 if (v
->flags
& VEC_MALLOC
) {
129 _mesa_align_free( v
->storage
);
133 v
->flags
&= ~VEC_MALLOC
;
142 _mesa_vector4f_print( const GLvector4f
*v
, const GLubyte
*cullmask
,
145 static const GLfloat c
[4] = { 0, 0, 0, 1 };
146 static const char *templates
[5] = {
148 "%d:\t%f, 0, 0, 1\n",
149 "%d:\t%f, %f, 0, 1\n",
150 "%d:\t%f, %f, %f, 1\n",
151 "%d:\t%f, %f, %f, %f\n"
154 const char *t
= templates
[v
->size
];
155 GLfloat
*d
= (GLfloat
*)v
->data
;
156 GLuint j
, i
= 0, count
;
158 printf("data-start\n");
159 for (; d
!= v
->start
; STRIDE_F(d
, v
->stride
), i
++)
160 printf(t
, i
, d
[0], d
[1], d
[2], d
[3]);
162 printf("start-count(%u)\n", v
->count
);
163 count
= i
+ v
->count
;
166 for (; i
< count
; STRIDE_F(d
, v
->stride
), i
++)
168 printf(t
, i
, d
[0], d
[1], d
[2], d
[3]);
171 for (; i
< count
; STRIDE_F(d
, v
->stride
), i
++)
172 printf(t
, i
, d
[0], d
[1], d
[2], d
[3]);
175 for (j
= v
->size
; j
< 4; j
++) {
176 if ((v
->flags
& (1<<j
)) == 0) {
178 printf("checking col %u is clean as advertised ", j
);
180 for (i
= 0, d
= (GLfloat
*) v
->data
;
181 i
< count
&& d
[j
] == c
[j
];
182 i
++, STRIDE_F(d
, v
->stride
)) {
189 printf(" --> Failed at %u ******\n", i
);