Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenm_vector.c
Go to the documentation of this file.
00001 00002 /* 00003 * Mesa 3-D graphics library 00004 * Version: 3.5 00005 * 00006 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining a 00009 * copy of this software and associated documentation files (the "Software"), 00010 * to deal in the Software without restriction, including without limitation 00011 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00012 * and/or sell copies of the Software, and to permit persons to whom the 00013 * Software is furnished to do so, subject to the following conditions: 00014 * 00015 * The above copyright notice and this permission notice shall be included 00016 * in all copies or substantial portions of the Software. 00017 * 00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00019 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00020 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00021 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 00022 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00023 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00024 */ 00025 00026 /* 00027 * New (3.1) transformation code written by Keith Whitwell. 00028 */ 00029 00030 00031 #include "main/glheader.h" 00032 #include "main/imports.h" 00033 #include "main/macros.h" 00034 #include "main/imports.h" 00035 00036 #include "m_vector.h" 00037 00038 00039 00040 /* 00041 * Given a vector [count][4] of floats, set all the [][elt] values 00042 * to 0 (if elt = 0, 1, 2) or 1.0 (if elt = 3). 00043 */ 00044 void _mesa_vector4f_clean_elem( GLvector4f *vec, GLuint count, GLuint elt ) 00045 { 00046 static const GLubyte elem_bits[4] = { 00047 VEC_DIRTY_0, 00048 VEC_DIRTY_1, 00049 VEC_DIRTY_2, 00050 VEC_DIRTY_3 00051 }; 00052 static const GLfloat clean[4] = { 0, 0, 0, 1 }; 00053 const GLfloat v = clean[elt]; 00054 GLfloat (*data)[4] = (GLfloat (*)[4])vec->start; 00055 GLuint i; 00056 00057 for (i = 0 ; i < count ; i++) 00058 data[i][elt] = v; 00059 00060 vec->flags &= ~elem_bits[elt]; 00061 } 00062 00063 static const GLubyte size_bits[5] = { 00064 0, 00065 VEC_SIZE_1, 00066 VEC_SIZE_2, 00067 VEC_SIZE_3, 00068 VEC_SIZE_4, 00069 }; 00070 00071 00072 00073 /* 00074 * Initialize GLvector objects. 00075 * Input: v - the vector object to initialize. 00076 * flags - bitwise-OR of VEC_* flags 00077 * storage - pointer to storage for the vector's data 00078 */ 00079 00080 00081 void _mesa_vector4f_init( GLvector4f *v, GLuint flags, GLfloat (*storage)[4] ) 00082 { 00083 v->stride = 4 * sizeof(GLfloat); 00084 v->size = 2; /* may change: 2-4 for vertices and 1-4 for texcoords */ 00085 v->data = storage; 00086 v->start = (GLfloat *) storage; 00087 v->count = 0; 00088 v->flags = size_bits[4] | flags ; 00089 } 00090 00091 00092 00093 00094 /* 00095 * Initialize GLvector objects and allocate storage. 00096 * Input: v - the vector object 00097 * sz - unused???? 00098 * flags - bitwise-OR of VEC_* flags 00099 * count - number of elements to allocate in vector 00100 * alignment - desired memory alignment for the data (in bytes) 00101 */ 00102 00103 00104 void _mesa_vector4f_alloc( GLvector4f *v, GLuint flags, GLuint count, 00105 GLuint alignment ) 00106 { 00107 v->stride = 4 * sizeof(GLfloat); 00108 v->size = 2; 00109 v->storage = ALIGN_MALLOC( count * 4 * sizeof(GLfloat), alignment ); 00110 v->start = (GLfloat *) v->storage; 00111 v->data = (GLfloat (*)[4]) v->storage; 00112 v->count = 0; 00113 v->flags = size_bits[4] | flags | VEC_MALLOC ; 00114 } 00115 00116 00117 00118 00119 /* 00120 * Vector deallocation. Free whatever memory is pointed to by the 00121 * vector's storage field if the VEC_MALLOC flag is set. 00122 * DO NOT free the GLvector object itself, though. 00123 */ 00124 00125 00126 void _mesa_vector4f_free( GLvector4f *v ) 00127 { 00128 if (v->flags & VEC_MALLOC) { 00129 ALIGN_FREE( v->storage ); 00130 v->data = NULL; 00131 v->start = NULL; 00132 v->storage = NULL; 00133 v->flags &= ~VEC_MALLOC; 00134 } 00135 } 00136 00137 00138 /* 00139 * For debugging 00140 */ 00141 void _mesa_vector4f_print( GLvector4f *v, GLubyte *cullmask, GLboolean culling ) 00142 { 00143 GLfloat c[4] = { 0, 0, 0, 1 }; 00144 const char *templates[5] = { 00145 "%d:\t0, 0, 0, 1\n", 00146 "%d:\t%f, 0, 0, 1\n", 00147 "%d:\t%f, %f, 0, 1\n", 00148 "%d:\t%f, %f, %f, 1\n", 00149 "%d:\t%f, %f, %f, %f\n" 00150 }; 00151 00152 const char *t = templates[v->size]; 00153 GLfloat *d = (GLfloat *)v->data; 00154 GLuint j, i = 0, count; 00155 00156 _mesa_printf("data-start\n"); 00157 for ( ; d != v->start ; STRIDE_F(d, v->stride), i++) 00158 _mesa_printf(t, i, d[0], d[1], d[2], d[3]); 00159 00160 _mesa_printf("start-count(%u)\n", v->count); 00161 count = i + v->count; 00162 00163 if (culling) { 00164 for ( ; i < count ; STRIDE_F(d, v->stride), i++) 00165 if (cullmask[i]) 00166 _mesa_printf(t, i, d[0], d[1], d[2], d[3]); 00167 } 00168 else { 00169 for ( ; i < count ; STRIDE_F(d, v->stride), i++) 00170 _mesa_printf(t, i, d[0], d[1], d[2], d[3]); 00171 } 00172 00173 for (j = v->size ; j < 4; j++) { 00174 if ((v->flags & (1<<j)) == 0) { 00175 00176 _mesa_printf("checking col %u is clean as advertised ", j); 00177 00178 for (i = 0, d = (GLfloat *) v->data ; 00179 i < count && d[j] == c[j] ; 00180 i++, STRIDE_F(d, v->stride)) {}; 00181 00182 if (i == count) 00183 _mesa_printf(" --> ok\n"); 00184 else 00185 _mesa_printf(" --> Failed at %u ******\n", i); 00186 } 00187 } 00188 } 00189 00190 Generated on Mon May 28 2012 04:20:15 for ReactOS by
1.7.6.1
|