1 /* $Id: m_vector.h,v 1.6 2001/03/12 00:48:41 gareth Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
28 * New (3.1) transformation code written by Keith Whitwell.
36 #include "mtypes.h" /* hack for GLchan */
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 */
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)
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.
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.
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 */
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
);
84 /* Could use a single vector type for normals and vertices, but
85 * this way avoids some casts.
96 extern void _mesa_vector3f_init( GLvector3f
*v
, GLuint flags
, GLfloat (*)[3] );
97 extern void _mesa_vector3f_alloc( GLvector3f
*v
, GLuint flags
, GLuint count
,
99 extern void _mesa_vector3f_free( GLvector3f
*v
);
100 extern void _mesa_vector3f_print( GLvector3f
*v
, GLubyte
*, GLboolean
);
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
,
118 /* For 4ub rgba values.
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
,
133 extern void _mesa_vector4ub_free( GLvector4ub
* );
136 /* For 4 * GLchan values.
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
,
151 extern void _mesa_vector4chan_free( GLvector4chan
* );
156 /* For 4 * GLushort rgba values.
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
,
171 extern void _mesa_vector4us_free( GLvector4us
* );
176 /* For 1ub values, eg edgeflag.
187 extern void _mesa_vector1ub_init( GLvector1ub
*v
, GLuint flags
, GLubyte
*storage
);
188 extern void _mesa_vector1ub_alloc( GLvector1ub
*v
, GLuint flags
, GLuint count
,
190 extern void _mesa_vector1ub_free( GLvector1ub
* );
195 /* For, eg Index, Array element.
206 extern void _mesa_vector1ui_init( GLvector1ui
*v
, GLuint flags
, GLuint
*storage
);
207 extern void _mesa_vector1ui_alloc( GLvector1ui
*v
, GLuint flags
, GLuint count
,
209 extern void _mesa_vector1ui_free( GLvector1ui
* );
214 * Given vector <v>, return a pointer (cast to <type *> to the <i>-th element.
216 * End up doing a lot of slow imuls if not careful.
218 #define VEC_ELT( v, type, i ) \
219 ( (type *) ( ((GLbyte *) ((v)->data)) + (i) * (v)->stride) )