f25b7b20642df81f8c105c6e6b7650eeccbd0fcf
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.
32 #include "main/glheader.h"
33 #include "main/imports.h"
34 #include "main/macros.h"
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).
45 _mesa_vector4f_clean_elem( GLvector4f
*vec
, GLuint count
, GLuint elt
)
47 static const GLubyte elem_bits
[4] = {
53 static const GLfloat clean
[4] = { 0, 0, 0, 1 };
54 const GLfloat v
= clean
[elt
];
55 GLfloat (*data
)[4] = (GLfloat (*)[4])vec
->start
;
58 for (i
= 0; i
< count
; i
++)
61 vec
->flags
&= ~elem_bits
[elt
];
65 static const GLubyte size_bits
[5] = {
75 * Initialize GLvector objects.
76 * \param v the vector object to initialize.
77 * \param flags bitwise-OR of VEC_* flags
78 * \param storage pointer to storage for the vector's data
81 _mesa_vector4f_init( GLvector4f
*v
, GLbitfield flags
, GLfloat (*storage
)[4] )
83 STATIC_ASSERT(V4F_DATA
== offsetof(GLvector4f
, data
));
84 STATIC_ASSERT(V4F_START
== offsetof(GLvector4f
, start
));
85 STATIC_ASSERT(V4F_COUNT
== offsetof(GLvector4f
, count
));
86 STATIC_ASSERT(V4F_STRIDE
== offsetof(GLvector4f
, stride
));
87 STATIC_ASSERT(V4F_SIZE
== offsetof(GLvector4f
, size
));
88 STATIC_ASSERT(V4F_FLAGS
== offsetof(GLvector4f
, flags
));
90 v
->stride
= 4 * sizeof(GLfloat
);
91 v
->size
= 2; /* may change: 2-4 for vertices and 1-4 for texcoords */
93 v
->start
= (GLfloat
*) storage
;
95 v
->flags
= size_bits
[4] | flags
;
100 * Initialize GLvector objects and allocate storage.
101 * \param v the vector object
102 * \param flags bitwise-OR of VEC_* flags
103 * \param count number of elements to allocate in vector
104 * \param alignment desired memory alignment for the data (in bytes)
107 _mesa_vector4f_alloc( GLvector4f
*v
, GLbitfield flags
, GLuint count
,
110 v
->stride
= 4 * sizeof(GLfloat
);
112 v
->storage
= _mesa_align_malloc( count
* 4 * sizeof(GLfloat
), alignment
);
113 v
->storage_count
= count
;
114 v
->start
= (GLfloat
*) v
->storage
;
115 v
->data
= (GLfloat (*)[4]) v
->storage
;
117 v
->flags
= size_bits
[4] | flags
| VEC_MALLOC
;
122 * Vector deallocation. Free whatever memory is pointed to by the
123 * vector's storage field if the VEC_MALLOC flag is set.
124 * DO NOT free the GLvector object itself, though.
127 _mesa_vector4f_free( GLvector4f
*v
)
129 if (v
->flags
& VEC_MALLOC
) {
130 _mesa_align_free( v
->storage
);
134 v
->flags
&= ~VEC_MALLOC
;
143 _mesa_vector4f_print( const GLvector4f
*v
, const GLubyte
*cullmask
,
146 static const GLfloat c
[4] = { 0, 0, 0, 1 };
147 static const char *templates
[5] = {
149 "%d:\t%f, 0, 0, 1\n",
150 "%d:\t%f, %f, 0, 1\n",
151 "%d:\t%f, %f, %f, 1\n",
152 "%d:\t%f, %f, %f, %f\n"
155 const char *t
= templates
[v
->size
];
156 GLfloat
*d
= (GLfloat
*)v
->data
;
157 GLuint j
, i
= 0, count
;
159 printf("data-start\n");
160 for (; d
!= v
->start
; STRIDE_F(d
, v
->stride
), i
++)
161 printf(t
, i
, d
[0], d
[1], d
[2], d
[3]);
163 printf("start-count(%u)\n", v
->count
);
164 count
= i
+ v
->count
;
167 for (; i
< count
; STRIDE_F(d
, v
->stride
), i
++)
169 printf(t
, i
, d
[0], d
[1], d
[2], d
[3]);
172 for (; i
< count
; STRIDE_F(d
, v
->stride
), i
++)
173 printf(t
, i
, d
[0], d
[1], d
[2], d
[3]);
176 for (j
= v
->size
; j
< 4; j
++) {
177 if ((v
->flags
& (1<<j
)) == 0) {
179 printf("checking col %u is clean as advertised ", j
);
181 for (i
= 0, d
= (GLfloat
*) v
->data
;
182 i
< count
&& d
[j
] == c
[j
];
183 i
++, STRIDE_F(d
, v
->stride
)) {
190 printf(" --> Failed at %u ******\n", i
);