Merge commit 'origin/gallium-0.1' into gallium-0.2
[mesa.git] / src / mesa / math / m_vector.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.3
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /*
26 * New (3.1) transformation code written by Keith Whitwell.
27 */
28
29
30 #ifndef _M_VECTOR_H_
31 #define _M_VECTOR_H_
32
33 #include "main/glheader.h"
34 #include "main/mtypes.h" /* hack for GLchan */
35
36
37 #define VEC_DIRTY_0 0x1
38 #define VEC_DIRTY_1 0x2
39 #define VEC_DIRTY_2 0x4
40 #define VEC_DIRTY_3 0x8
41 #define VEC_MALLOC 0x10 /* storage field points to self-allocated mem*/
42 #define VEC_NOT_WRITEABLE 0x40 /* writable elements to hold clipped data */
43 #define VEC_BAD_STRIDE 0x100 /* matches tnl's prefered stride */
44
45
46 #define VEC_SIZE_1 VEC_DIRTY_0
47 #define VEC_SIZE_2 (VEC_DIRTY_0|VEC_DIRTY_1)
48 #define VEC_SIZE_3 (VEC_DIRTY_0|VEC_DIRTY_1|VEC_DIRTY_2)
49 #define VEC_SIZE_4 (VEC_DIRTY_0|VEC_DIRTY_1|VEC_DIRTY_2|VEC_DIRTY_3)
50
51
52
53 /* Wrap all the information about vectors up in a struct. Has
54 * additional fields compared to the other vectors to help us track of
55 * different vertex sizes, and whether we need to clean columns out
56 * because they contain non-(0,0,0,1) values.
57 *
58 * The start field is used to reserve data for copied vertices at the
59 * end of _mesa_transform_vb, and avoids the need for a multiplication in
60 * the transformation routines.
61 */
62 typedef struct {
63 GLfloat (*data)[4]; /* may be malloc'd or point to client data */
64 GLfloat *start; /* points somewhere inside of <data> */
65 GLuint count; /* size of the vector (in elements) */
66 GLuint stride; /* stride from one element to the next (in bytes) */
67 GLuint size; /* 2-4 for vertices and 1-4 for texcoords */
68 GLuint flags; /* which columns are dirty */
69 void *storage; /* self-allocated storage */
70 } GLvector4f;
71
72
73 extern void _mesa_vector4f_init( GLvector4f *v, GLuint flags,
74 GLfloat (*storage)[4] );
75 extern void _mesa_vector4f_alloc( GLvector4f *v, GLuint flags,
76 GLuint count, GLuint alignment );
77 extern void _mesa_vector4f_free( GLvector4f *v );
78 extern void _mesa_vector4f_print( GLvector4f *v, GLubyte *, GLboolean );
79 extern void _mesa_vector4f_clean_elem( GLvector4f *vec, GLuint nr, GLuint elt );
80
81
82
83
84
85 /*
86 * Given vector <v>, return a pointer (cast to <type *> to the <i>-th element.
87 *
88 * End up doing a lot of slow imuls if not careful.
89 */
90 #define VEC_ELT( v, type, i ) \
91 ( (type *) ( ((GLbyte *) ((v)->data)) + (i) * (v)->stride) )
92
93
94 #endif