Consistent copyright info (version number, date) across all files.
[mesa.git] / src / mesa / math / m_vector.h
1 /* $Id: m_vector.h,v 1.6 2001/03/12 00:48:41 gareth Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27 /*
28 * New (3.1) transformation code written by Keith Whitwell.
29 */
30
31
32 #ifndef _M_VECTOR_H_
33 #define _M_VECTOR_H_
34
35 #include "glheader.h"
36 #include "mtypes.h" /* hack for GLchan */
37
38
39 #define VEC_DIRTY_0 0x1
40 #define VEC_DIRTY_1 0x2
41 #define VEC_DIRTY_2 0x4
42 #define VEC_DIRTY_3 0x8
43 #define VEC_MALLOC 0x10 /* storage field points to self-allocated mem*/
44 #define VEC_NOT_WRITEABLE 0x40 /* writable elements to hold clipped data */
45 #define VEC_BAD_STRIDE 0x100 /* matches tnl's prefered stride */
46
47
48 #define VEC_SIZE_1 VEC_DIRTY_0
49 #define VEC_SIZE_2 (VEC_DIRTY_0|VEC_DIRTY_1)
50 #define VEC_SIZE_3 (VEC_DIRTY_0|VEC_DIRTY_1|VEC_DIRTY_2)
51 #define VEC_SIZE_4 (VEC_DIRTY_0|VEC_DIRTY_1|VEC_DIRTY_2|VEC_DIRTY_3)
52
53
54
55 /* Wrap all the information about vectors up in a struct. Has
56 * additional fields compared to the other vectors to help us track of
57 * different vertex sizes, and whether we need to clean columns out
58 * because they contain non-(0,0,0,1) values.
59 *
60 * The start field is used to reserve data for copied vertices at the
61 * end of _mesa_transform_vb, and avoids the need for a multiplication in
62 * the transformation routines.
63 */
64 typedef struct {
65 GLfloat (*data)[4]; /* may be malloc'd or point to client data */
66 GLfloat *start; /* points somewhere inside of <data> */
67 GLuint count; /* size of the vector (in elements) */
68 GLuint stride; /* stride from one element to the next (in bytes) */
69 GLuint size; /* 2-4 for vertices and 1-4 for texcoords */
70 GLuint flags; /* which columns are dirty */
71 void *storage; /* self-allocated storage */
72 } GLvector4f;
73
74
75 extern void _mesa_vector4f_init( GLvector4f *v, GLuint flags,
76 GLfloat (*storage)[4] );
77 extern void _mesa_vector4f_alloc( GLvector4f *v, GLuint flags,
78 GLuint count, GLuint alignment );
79 extern void _mesa_vector4f_free( GLvector4f *v );
80 extern void _mesa_vector4f_print( GLvector4f *v, GLubyte *, GLboolean );
81 extern void _mesa_vector4f_clean_elem( GLvector4f *vec, GLuint nr, GLuint elt );
82
83
84 /* Could use a single vector type for normals and vertices, but
85 * this way avoids some casts.
86 */
87 typedef struct {
88 GLfloat (*data)[3];
89 GLfloat *start;
90 GLuint count;
91 GLuint stride;
92 GLuint flags;
93 void *storage;
94 } GLvector3f;
95
96 extern void _mesa_vector3f_init( GLvector3f *v, GLuint flags, GLfloat (*)[3] );
97 extern void _mesa_vector3f_alloc( GLvector3f *v, GLuint flags, GLuint count,
98 GLuint alignment );
99 extern void _mesa_vector3f_free( GLvector3f *v );
100 extern void _mesa_vector3f_print( GLvector3f *v, GLubyte *, GLboolean );
101
102
103 typedef struct {
104 GLfloat *data;
105 GLfloat *start;
106 GLuint count;
107 GLuint stride;
108 GLuint flags;
109 void *storage;
110 } GLvector1f;
111
112 extern void _mesa_vector1f_free( GLvector1f *v );
113 extern void _mesa_vector1f_init( GLvector1f *v, GLuint flags, GLfloat * );
114 extern void _mesa_vector1f_alloc( GLvector1f *v, GLuint flags, GLuint count,
115 GLuint alignment );
116
117
118 /* For 4ub rgba values.
119 */
120 typedef struct {
121 GLubyte (*data)[4];
122 GLubyte *start;
123 GLuint count;
124 GLuint stride;
125 GLuint flags;
126 void *storage;
127 } GLvector4ub;
128
129 extern void _mesa_vector4ub_init( GLvector4ub *v, GLuint flags,
130 GLubyte (*storage)[4] );
131 extern void _mesa_vector4ub_alloc( GLvector4ub *v, GLuint flags, GLuint count,
132 GLuint alignment );
133 extern void _mesa_vector4ub_free( GLvector4ub * );
134
135
136 /* For 4 * GLchan values.
137 */
138 typedef struct {
139 GLchan (*data)[4];
140 GLchan *start;
141 GLuint count;
142 GLuint stride;
143 GLuint flags;
144 void *storage;
145 } GLvector4chan;
146
147 extern void _mesa_vector4chan_init( GLvector4chan *v, GLuint flags,
148 GLchan (*storage)[4] );
149 extern void _mesa_vector4chan_alloc( GLvector4chan *v, GLuint flags, GLuint count,
150 GLuint alignment );
151 extern void _mesa_vector4chan_free( GLvector4chan * );
152
153
154
155
156 /* For 4 * GLushort rgba values.
157 */
158 typedef struct {
159 GLushort (*data)[4];
160 GLushort *start;
161 GLuint count;
162 GLuint stride;
163 GLuint flags;
164 void *storage;
165 } GLvector4us;
166
167 extern void _mesa_vector4us_init( GLvector4us *v, GLuint flags,
168 GLushort (*storage)[4] );
169 extern void _mesa_vector4us_alloc( GLvector4us *v, GLuint flags, GLuint count,
170 GLuint alignment );
171 extern void _mesa_vector4us_free( GLvector4us * );
172
173
174
175
176 /* For 1ub values, eg edgeflag.
177 */
178 typedef struct {
179 GLubyte *data;
180 GLubyte *start;
181 GLuint count;
182 GLuint stride;
183 GLuint flags;
184 void *storage;
185 } GLvector1ub;
186
187 extern void _mesa_vector1ub_init( GLvector1ub *v, GLuint flags, GLubyte *storage);
188 extern void _mesa_vector1ub_alloc( GLvector1ub *v, GLuint flags, GLuint count,
189 GLuint alignment );
190 extern void _mesa_vector1ub_free( GLvector1ub * );
191
192
193
194
195 /* For, eg Index, Array element.
196 */
197 typedef struct {
198 GLuint *data;
199 GLuint *start;
200 GLuint count;
201 GLuint stride;
202 GLuint flags;
203 void *storage;
204 } GLvector1ui;
205
206 extern void _mesa_vector1ui_init( GLvector1ui *v, GLuint flags, GLuint *storage );
207 extern void _mesa_vector1ui_alloc( GLvector1ui *v, GLuint flags, GLuint count,
208 GLuint alignment );
209 extern void _mesa_vector1ui_free( GLvector1ui * );
210
211
212
213 /*
214 * Given vector <v>, return a pointer (cast to <type *> to the <i>-th element.
215 *
216 * End up doing a lot of slow imuls if not careful.
217 */
218 #define VEC_ELT( v, type, i ) \
219 ( (type *) ( ((GLbyte *) ((v)->data)) + (i) * (v)->stride) )
220
221
222 #endif