1848b8605Smrg/* 2848b8605Smrg * Mesa 3-D graphics library 3848b8605Smrg * 4848b8605Smrg * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 5848b8605Smrg * 6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7848b8605Smrg * copy of this software and associated documentation files (the "Software"), 8848b8605Smrg * to deal in the Software without restriction, including without limitation 9848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the 11848b8605Smrg * Software is furnished to do so, subject to the following conditions: 12848b8605Smrg * 13848b8605Smrg * The above copyright notice and this permission notice shall be included 14848b8605Smrg * in all copies or substantial portions of the Software. 15848b8605Smrg * 16848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20848b8605Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21848b8605Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22848b8605Smrg * OTHER DEALINGS IN THE SOFTWARE. 23848b8605Smrg */ 24848b8605Smrg 25848b8605Smrg/* 26848b8605Smrg * New (3.1) transformation code written by Keith Whitwell. 27848b8605Smrg */ 28848b8605Smrg 29848b8605Smrg 30848b8605Smrg#ifndef _M_VECTOR_H_ 31848b8605Smrg#define _M_VECTOR_H_ 32848b8605Smrg 33848b8605Smrg#include "main/glheader.h" 34848b8605Smrg 35848b8605Smrg 36848b8605Smrg#define VEC_DIRTY_0 0x1 37848b8605Smrg#define VEC_DIRTY_1 0x2 38848b8605Smrg#define VEC_DIRTY_2 0x4 39848b8605Smrg#define VEC_DIRTY_3 0x8 40848b8605Smrg#define VEC_MALLOC 0x10 /* storage field points to self-allocated mem*/ 41848b8605Smrg#define VEC_NOT_WRITEABLE 0x40 /* writable elements to hold clipped data */ 42848b8605Smrg#define VEC_BAD_STRIDE 0x100 /* matches tnl's prefered stride */ 43848b8605Smrg 44848b8605Smrg 45848b8605Smrg#define VEC_SIZE_1 VEC_DIRTY_0 46848b8605Smrg#define VEC_SIZE_2 (VEC_DIRTY_0|VEC_DIRTY_1) 47848b8605Smrg#define VEC_SIZE_3 (VEC_DIRTY_0|VEC_DIRTY_1|VEC_DIRTY_2) 48848b8605Smrg#define VEC_SIZE_4 (VEC_DIRTY_0|VEC_DIRTY_1|VEC_DIRTY_2|VEC_DIRTY_3) 49848b8605Smrg 50848b8605Smrg 51848b8605Smrg 52848b8605Smrg/** 53848b8605Smrg * Wrap all the information about vectors up in a struct. Has 54b8e80941Smrg * additional fields compared to the other vectors to help us track 55848b8605Smrg * different vertex sizes, and whether we need to clean columns out 56848b8605Smrg * because they contain non-(0,0,0,1) values. 57848b8605Smrg * 58848b8605Smrg * The start field is used to reserve data for copied vertices at the 59848b8605Smrg * end of _mesa_transform_vb, and avoids the need for a multiplication in 60848b8605Smrg * the transformation routines. 61848b8605Smrg */ 62848b8605Smrgtypedef struct { 63848b8605Smrg GLfloat (*data)[4]; /**< may be malloc'd or point to client data */ 64b8e80941Smrg GLfloat *start; /**< points somewhere inside of GLvector4f::data */ 65848b8605Smrg GLuint count; /**< size of the vector (in elements) */ 66848b8605Smrg GLuint stride; /**< stride from one element to the next (in bytes) */ 67848b8605Smrg GLuint size; /**< 2-4 for vertices and 1-4 for texcoords */ 68848b8605Smrg GLbitfield flags; /**< bitmask of VEC_x flags */ 69848b8605Smrg void *storage; /**< self-allocated storage */ 70848b8605Smrg GLuint storage_count; /**< storage size in elements */ 71848b8605Smrg} GLvector4f; 72848b8605Smrg 73848b8605Smrg 74848b8605Smrgextern void _mesa_vector4f_init( GLvector4f *v, GLbitfield flags, 75848b8605Smrg GLfloat (*storage)[4] ); 76848b8605Smrgextern void _mesa_vector4f_alloc( GLvector4f *v, GLbitfield flags, 77848b8605Smrg GLuint count, GLuint alignment ); 78848b8605Smrgextern void _mesa_vector4f_free( GLvector4f *v ); 79848b8605Smrgextern void _mesa_vector4f_print( const GLvector4f *v, const GLubyte *, GLboolean ); 80848b8605Smrgextern void _mesa_vector4f_clean_elem( GLvector4f *vec, GLuint nr, GLuint elt ); 81848b8605Smrg 82848b8605Smrg 83848b8605Smrg/** 84848b8605Smrg * Given vector <v>, return a pointer (cast to <type *> to the <i>-th element. 85848b8605Smrg * 86848b8605Smrg * End up doing a lot of slow imuls if not careful. 87848b8605Smrg */ 88848b8605Smrg#define VEC_ELT( v, type, i ) \ 89848b8605Smrg ( (type *) ( ((GLbyte *) ((v)->data)) + (i) * (v)->stride) ) 90848b8605Smrg 91848b8605Smrg 92848b8605Smrg#endif 93