• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Mesa 3-D graphics library
3  *
4  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
5  *
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:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
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.
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 
35 
36 #define VEC_DIRTY_0        0x1
37 #define VEC_DIRTY_1        0x2
38 #define VEC_DIRTY_2        0x4
39 #define VEC_DIRTY_3        0x8
40 #define VEC_MALLOC         0x10 /* storage field points to self-allocated mem*/
41 #define VEC_NOT_WRITEABLE  0x40	/* writable elements to hold clipped data */
42 #define VEC_BAD_STRIDE     0x100 /* matches tnl's prefered stride */
43 
44 
45 #define VEC_SIZE_1   VEC_DIRTY_0
46 #define VEC_SIZE_2   (VEC_DIRTY_0|VEC_DIRTY_1)
47 #define VEC_SIZE_3   (VEC_DIRTY_0|VEC_DIRTY_1|VEC_DIRTY_2)
48 #define VEC_SIZE_4   (VEC_DIRTY_0|VEC_DIRTY_1|VEC_DIRTY_2|VEC_DIRTY_3)
49 
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
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 GLvector4f::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    GLbitfield flags;	/**< bitmask of VEC_x flags */
69    void *storage;	/**< self-allocated storage */
70    GLuint storage_count; /**< storage size in elements */
71 } GLvector4f;
72 
73 
74 extern void _mesa_vector4f_init( GLvector4f *v, GLbitfield flags,
75 			      GLfloat (*storage)[4] );
76 extern void _mesa_vector4f_alloc( GLvector4f *v, GLbitfield flags,
77 			       GLuint count, GLuint alignment );
78 extern void _mesa_vector4f_free( GLvector4f *v );
79 extern void _mesa_vector4f_print( const GLvector4f *v, const GLubyte *, GLboolean );
80 extern void _mesa_vector4f_clean_elem( GLvector4f *vec, GLuint nr, GLuint elt );
81 
82 
83 /**
84  * Given vector <v>, return a pointer (cast to <type *> to the <i>-th element.
85  *
86  * End up doing a lot of slow imuls if not careful.
87  */
88 #define VEC_ELT( v, type, i ) \
89        ( (type *)  ( ((GLbyte *) ((v)->data)) + (i) * (v)->stride) )
90 
91 
92 #endif
93