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/macros.h"
37
#include "util/u_memory.h"
42
* Given a vector [count][4] of floats, set all the [][elt] values
43
* to 0 (if elt = 0, 1, 2) or 1.0 (if elt = 3).
46
_mesa_vector4f_clean_elem( GLvector4f *vec, GLuint count, GLuint elt )
48
static const GLubyte elem_bits[4] = {
54
static const GLfloat clean[4] = { 0, 0, 0, 1 };
55
const GLfloat v = clean[elt];
56
GLfloat (*data)[4] = (GLfloat (*)[4])vec->start;
59
for (i = 0; i < count; i++)
62
vec->flags &= ~elem_bits[elt];
66
static const GLubyte size_bits[5] = {
76
* Initialize GLvector objects.
77
* \param v the vector object to initialize.
78
* \param flags bitwise-OR of VEC_* flags
79
* \param storage pointer to storage for the vector's data
82
_mesa_vector4f_init( GLvector4f *v, GLbitfield flags, GLfloat (*storage)[4] )
84
STATIC_ASSERT(V4F_DATA == offsetof(GLvector4f, data));
85
STATIC_ASSERT(V4F_START == offsetof(GLvector4f, start));
86
STATIC_ASSERT(V4F_COUNT == offsetof(GLvector4f, count));
87
STATIC_ASSERT(V4F_STRIDE == offsetof(GLvector4f, stride));
88
STATIC_ASSERT(V4F_SIZE == offsetof(GLvector4f, size));
89
STATIC_ASSERT(V4F_FLAGS == offsetof(GLvector4f, flags));
91
v->stride = 4 * sizeof(GLfloat);
92
v->size = 2; /* may change: 2-4 for vertices and 1-4 for texcoords */
94
v->start = (GLfloat *) storage;
96
v->flags = size_bits[4] | flags;
101
* Initialize GLvector objects and allocate storage.
102
* \param v the vector object
103
* \param flags bitwise-OR of VEC_* flags
104
* \param count number of elements to allocate in vector
105
* \param alignment desired memory alignment for the data (in bytes)
108
_mesa_vector4f_alloc( GLvector4f *v, GLbitfield flags, GLuint count,
111
v->stride = 4 * sizeof(GLfloat);
113
v->storage = align_malloc( count * 4 * sizeof(GLfloat), alignment );
114
v->storage_count = count;
115
v->start = (GLfloat *) v->storage;
116
v->data = (GLfloat (*)[4]) v->storage;
118
v->flags = size_bits[4] | flags | VEC_MALLOC;
123
* Vector deallocation. Free whatever memory is pointed to by the
124
* vector's storage field if the VEC_MALLOC flag is set.
125
* DO NOT free the GLvector object itself, though.
128
_mesa_vector4f_free( GLvector4f *v )
130
if (v->flags & VEC_MALLOC) {
131
align_free( v->storage );
135
v->flags &= ~VEC_MALLOC;
144
_mesa_vector4f_print( const GLvector4f *v, const GLubyte *cullmask,
147
static const GLfloat c[4] = { 0, 0, 0, 1 };
148
static const char *templates[5] = {
150
"%d:\t%f, 0, 0, 1\n",
151
"%d:\t%f, %f, 0, 1\n",
152
"%d:\t%f, %f, %f, 1\n",
153
"%d:\t%f, %f, %f, %f\n"
156
const char *t = templates[v->size];
157
GLfloat *d = (GLfloat *)v->data;
158
GLuint j, i = 0, count;
160
printf("data-start\n");
161
for (; d != v->start; STRIDE_F(d, v->stride), i++)
162
printf(t, i, d[0], d[1], d[2], d[3]);
164
printf("start-count(%u)\n", v->count);
165
count = i + v->count;
168
for (; i < count; STRIDE_F(d, v->stride), i++)
170
printf(t, i, d[0], d[1], d[2], d[3]);
173
for (; i < count; STRIDE_F(d, v->stride), i++)
174
printf(t, i, d[0], d[1], d[2], d[3]);
177
for (j = v->size; j < 4; j++) {
178
if ((v->flags & (1<<j)) == 0) {
180
printf("checking col %u is clean as advertised ", j);
182
for (i = 0, d = (GLfloat *) v->data;
183
i < count && d[j] == c[j];
184
i++, STRIDE_F(d, v->stride)) {
191
printf(" --> Failed at %u ******\n", i);