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
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 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 */
62typedef 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   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
74extern void _mesa_vector4f_init( GLvector4f *v, GLbitfield flags,
75			      GLfloat (*storage)[4] );
76extern void _mesa_vector4f_alloc( GLvector4f *v, GLbitfield flags,
77			       GLuint count, GLuint alignment );
78extern void _mesa_vector4f_free( GLvector4f *v );
79extern void _mesa_vector4f_print( const GLvector4f *v, const GLubyte *, GLboolean );
80extern 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