xref: /third_party/mesa3d/src/mesa/math/m_vector.h (revision bf215546)
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#define MATH_ASM_PTR_SIZE sizeof(void *)
35#include "math/m_vector_asm.h"
36
37#define VEC_MALLOC         0x10 /* storage field points to self-allocated mem*/
38#define VEC_NOT_WRITEABLE  0x40	/* writable elements to hold clipped data */
39#define VEC_BAD_STRIDE     0x100 /* matches tnl's prefered stride */
40
41
42
43
44
45/**
46 * Wrap all the information about vectors up in a struct.  Has
47 * additional fields compared to the other vectors to help us track
48 * different vertex sizes, and whether we need to clean columns out
49 * because they contain non-(0,0,0,1) values.
50 *
51 * The start field is used to reserve data for copied vertices at the
52 * end of _mesa_transform_vb, and avoids the need for a multiplication in
53 * the transformation routines.
54 */
55typedef struct {
56   GLfloat (*data)[4];	/**< may be malloc'd or point to client data */
57   GLfloat *start;	/**< points somewhere inside of GLvector4f::data */
58   GLuint count;	/**< size of the vector (in elements) */
59   GLuint stride;	/**< stride from one element to the next (in bytes) */
60   GLuint size;		/**< 2-4 for vertices and 1-4 for texcoords */
61   GLbitfield flags;	/**< bitmask of VEC_x flags */
62   void *storage;	/**< self-allocated storage */
63   GLuint storage_count; /**< storage size in elements */
64} GLvector4f;
65
66
67extern void _mesa_vector4f_init( GLvector4f *v, GLbitfield flags,
68			      GLfloat (*storage)[4] );
69extern void _mesa_vector4f_alloc( GLvector4f *v, GLbitfield flags,
70			       GLuint count, GLuint alignment );
71extern void _mesa_vector4f_free( GLvector4f *v );
72extern void _mesa_vector4f_print( const GLvector4f *v, const GLubyte *, GLboolean );
73extern void _mesa_vector4f_clean_elem( GLvector4f *vec, GLuint nr, GLuint elt );
74
75
76/**
77 * Given vector <v>, return a pointer (cast to <type *> to the <i>-th element.
78 *
79 * End up doing a lot of slow imuls if not careful.
80 */
81#define VEC_ELT( v, type, i ) \
82       ( (type *)  ( ((GLbyte *) ((v)->data)) + (i) * (v)->stride) )
83
84
85#endif
86