Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenm_norm_tmp.h
Go to the documentation of this file.
00001 00002 /* 00003 * Mesa 3-D graphics library 00004 * Version: 5.1 00005 * 00006 * Copyright (C) 1999-2003 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 /* Functions to tranform a vector of normals. This includes applying 00031 * the transformation matrix, rescaling and normalization. 00032 */ 00033 00034 /* 00035 * mat - the 4x4 transformation matrix 00036 * scale - uniform scale factor of the transformation matrix (not always used) 00037 * in - the source vector of normals 00038 * lengths - length of each incoming normal (may be NULL) (a display list 00039 * optimization) 00040 * dest - the destination vector of normals 00041 */ 00042 static void _XFORMAPI 00043 TAG(transform_normalize_normals)( const GLmatrix *mat, 00044 GLfloat scale, 00045 const GLvector4f *in, 00046 const GLfloat *lengths, 00047 GLvector4f *dest ) 00048 { 00049 GLfloat (*out)[4] = (GLfloat (*)[4])dest->start; 00050 const GLfloat *from = in->start; 00051 const GLuint stride = in->stride; 00052 const GLuint count = in->count; 00053 const GLfloat *m = mat->inv; 00054 GLfloat m0 = m[0], m4 = m[4], m8 = m[8]; 00055 GLfloat m1 = m[1], m5 = m[5], m9 = m[9]; 00056 GLfloat m2 = m[2], m6 = m[6], m10 = m[10]; 00057 GLuint i; 00058 00059 if (!lengths) { 00060 STRIDE_LOOP { 00061 GLfloat tx, ty, tz; 00062 { 00063 const GLfloat ux = from[0], uy = from[1], uz = from[2]; 00064 tx = ux * m0 + uy * m1 + uz * m2; 00065 ty = ux * m4 + uy * m5 + uz * m6; 00066 tz = ux * m8 + uy * m9 + uz * m10; 00067 } 00068 { 00069 GLdouble len = tx*tx + ty*ty + tz*tz; 00070 if (len > 1e-20) { 00071 GLfloat scale = INV_SQRTF(len); 00072 out[i][0] = tx * scale; 00073 out[i][1] = ty * scale; 00074 out[i][2] = tz * scale; 00075 } 00076 else { 00077 out[i][0] = out[i][1] = out[i][2] = 0; 00078 } 00079 } 00080 } 00081 } 00082 else { 00083 if (scale != 1.0) { 00084 m0 *= scale, m4 *= scale, m8 *= scale; 00085 m1 *= scale, m5 *= scale, m9 *= scale; 00086 m2 *= scale, m6 *= scale, m10 *= scale; 00087 } 00088 00089 STRIDE_LOOP { 00090 GLfloat tx, ty, tz; 00091 { 00092 const GLfloat ux = from[0], uy = from[1], uz = from[2]; 00093 tx = ux * m0 + uy * m1 + uz * m2; 00094 ty = ux * m4 + uy * m5 + uz * m6; 00095 tz = ux * m8 + uy * m9 + uz * m10; 00096 } 00097 { 00098 GLfloat len = lengths[i]; 00099 out[i][0] = tx * len; 00100 out[i][1] = ty * len; 00101 out[i][2] = tz * len; 00102 } 00103 } 00104 } 00105 dest->count = in->count; 00106 } 00107 00108 00109 static void _XFORMAPI 00110 TAG(transform_normalize_normals_no_rot)( const GLmatrix *mat, 00111 GLfloat scale, 00112 const GLvector4f *in, 00113 const GLfloat *lengths, 00114 GLvector4f *dest ) 00115 { 00116 GLfloat (*out)[4] = (GLfloat (*)[4])dest->start; 00117 const GLfloat *from = in->start; 00118 const GLuint stride = in->stride; 00119 const GLuint count = in->count; 00120 const GLfloat *m = mat->inv; 00121 GLfloat m0 = m[0]; 00122 GLfloat m5 = m[5]; 00123 GLfloat m10 = m[10]; 00124 GLuint i; 00125 00126 if (!lengths) { 00127 STRIDE_LOOP { 00128 GLfloat tx, ty, tz; 00129 { 00130 const GLfloat ux = from[0], uy = from[1], uz = from[2]; 00131 tx = ux * m0 ; 00132 ty = uy * m5 ; 00133 tz = uz * m10; 00134 } 00135 { 00136 GLdouble len = tx*tx + ty*ty + tz*tz; 00137 if (len > 1e-20) { 00138 GLfloat scale = INV_SQRTF(len); 00139 out[i][0] = tx * scale; 00140 out[i][1] = ty * scale; 00141 out[i][2] = tz * scale; 00142 } 00143 else { 00144 out[i][0] = out[i][1] = out[i][2] = 0; 00145 } 00146 } 00147 } 00148 } 00149 else { 00150 m0 *= scale; 00151 m5 *= scale; 00152 m10 *= scale; 00153 00154 STRIDE_LOOP { 00155 GLfloat tx, ty, tz; 00156 { 00157 const GLfloat ux = from[0], uy = from[1], uz = from[2]; 00158 tx = ux * m0 ; 00159 ty = uy * m5 ; 00160 tz = uz * m10; 00161 } 00162 { 00163 GLfloat len = lengths[i]; 00164 out[i][0] = tx * len; 00165 out[i][1] = ty * len; 00166 out[i][2] = tz * len; 00167 } 00168 } 00169 } 00170 dest->count = in->count; 00171 } 00172 00173 00174 static void _XFORMAPI 00175 TAG(transform_rescale_normals_no_rot)( const GLmatrix *mat, 00176 GLfloat scale, 00177 const GLvector4f *in, 00178 const GLfloat *lengths, 00179 GLvector4f *dest ) 00180 { 00181 GLfloat (*out)[4] = (GLfloat (*)[4])dest->start; 00182 const GLfloat *from = in->start; 00183 const GLuint stride = in->stride; 00184 const GLuint count = in->count; 00185 const GLfloat *m = mat->inv; 00186 const GLfloat m0 = scale*m[0]; 00187 const GLfloat m5 = scale*m[5]; 00188 const GLfloat m10 = scale*m[10]; 00189 GLuint i; 00190 00191 (void) lengths; 00192 00193 STRIDE_LOOP { 00194 GLfloat ux = from[0], uy = from[1], uz = from[2]; 00195 out[i][0] = ux * m0; 00196 out[i][1] = uy * m5; 00197 out[i][2] = uz * m10; 00198 } 00199 dest->count = in->count; 00200 } 00201 00202 00203 static void _XFORMAPI 00204 TAG(transform_rescale_normals)( const GLmatrix *mat, 00205 GLfloat scale, 00206 const GLvector4f *in, 00207 const GLfloat *lengths, 00208 GLvector4f *dest ) 00209 { 00210 GLfloat (*out)[4] = (GLfloat (*)[4])dest->start; 00211 const GLfloat *from = in->start; 00212 const GLuint stride = in->stride; 00213 const GLuint count = in->count; 00214 /* Since we are unlikely to have < 3 vertices in the buffer, 00215 * it makes sense to pre-multiply by scale. 00216 */ 00217 const GLfloat *m = mat->inv; 00218 const GLfloat m0 = scale*m[0], m4 = scale*m[4], m8 = scale*m[8]; 00219 const GLfloat m1 = scale*m[1], m5 = scale*m[5], m9 = scale*m[9]; 00220 const GLfloat m2 = scale*m[2], m6 = scale*m[6], m10 = scale*m[10]; 00221 GLuint i; 00222 00223 (void) lengths; 00224 00225 STRIDE_LOOP { 00226 GLfloat ux = from[0], uy = from[1], uz = from[2]; 00227 out[i][0] = ux * m0 + uy * m1 + uz * m2; 00228 out[i][1] = ux * m4 + uy * m5 + uz * m6; 00229 out[i][2] = ux * m8 + uy * m9 + uz * m10; 00230 } 00231 dest->count = in->count; 00232 } 00233 00234 00235 static void _XFORMAPI 00236 TAG(transform_normals_no_rot)( const GLmatrix *mat, 00237 GLfloat scale, 00238 const GLvector4f *in, 00239 const GLfloat *lengths, 00240 GLvector4f *dest ) 00241 { 00242 GLfloat (*out)[4] = (GLfloat (*)[4])dest->start; 00243 const GLfloat *from = in->start; 00244 const GLuint stride = in->stride; 00245 const GLuint count = in->count; 00246 const GLfloat *m = mat->inv; 00247 const GLfloat m0 = m[0]; 00248 const GLfloat m5 = m[5]; 00249 const GLfloat m10 = m[10]; 00250 GLuint i; 00251 00252 (void) scale; 00253 (void) lengths; 00254 00255 STRIDE_LOOP { 00256 GLfloat ux = from[0], uy = from[1], uz = from[2]; 00257 out[i][0] = ux * m0; 00258 out[i][1] = uy * m5; 00259 out[i][2] = uz * m10; 00260 } 00261 dest->count = in->count; 00262 } 00263 00264 00265 static void _XFORMAPI 00266 TAG(transform_normals)( const GLmatrix *mat, 00267 GLfloat scale, 00268 const GLvector4f *in, 00269 const GLfloat *lengths, 00270 GLvector4f *dest ) 00271 { 00272 GLfloat (*out)[4] = (GLfloat (*)[4])dest->start; 00273 const GLfloat *from = in->start; 00274 const GLuint stride = in->stride; 00275 const GLuint count = in->count; 00276 const GLfloat *m = mat->inv; 00277 const GLfloat m0 = m[0], m4 = m[4], m8 = m[8]; 00278 const GLfloat m1 = m[1], m5 = m[5], m9 = m[9]; 00279 const GLfloat m2 = m[2], m6 = m[6], m10 = m[10]; 00280 GLuint i; 00281 00282 (void) scale; 00283 (void) lengths; 00284 00285 STRIDE_LOOP { 00286 GLfloat ux = from[0], uy = from[1], uz = from[2]; 00287 out[i][0] = ux * m0 + uy * m1 + uz * m2; 00288 out[i][1] = ux * m4 + uy * m5 + uz * m6; 00289 out[i][2] = ux * m8 + uy * m9 + uz * m10; 00290 } 00291 dest->count = in->count; 00292 } 00293 00294 00295 static void _XFORMAPI 00296 TAG(normalize_normals)( const GLmatrix *mat, 00297 GLfloat scale, 00298 const GLvector4f *in, 00299 const GLfloat *lengths, 00300 GLvector4f *dest ) 00301 { 00302 GLfloat (*out)[4] = (GLfloat (*)[4])dest->start; 00303 const GLfloat *from = in->start; 00304 const GLuint stride = in->stride; 00305 const GLuint count = in->count; 00306 GLuint i; 00307 00308 (void) mat; 00309 (void) scale; 00310 00311 if (lengths) { 00312 STRIDE_LOOP { 00313 const GLfloat x = from[0], y = from[1], z = from[2]; 00314 GLfloat invlen = lengths[i]; 00315 out[i][0] = x * invlen; 00316 out[i][1] = y * invlen; 00317 out[i][2] = z * invlen; 00318 } 00319 } 00320 else { 00321 STRIDE_LOOP { 00322 const GLfloat x = from[0], y = from[1], z = from[2]; 00323 GLdouble len = x * x + y * y + z * z; 00324 if (len > 1e-50) { 00325 len = INV_SQRTF(len); 00326 out[i][0] = (GLfloat)(x * len); 00327 out[i][1] = (GLfloat)(y * len); 00328 out[i][2] = (GLfloat)(z * len); 00329 } 00330 else { 00331 out[i][0] = x; 00332 out[i][1] = y; 00333 out[i][2] = z; 00334 } 00335 } 00336 } 00337 dest->count = in->count; 00338 } 00339 00340 00341 static void _XFORMAPI 00342 TAG(rescale_normals)( const GLmatrix *mat, 00343 GLfloat scale, 00344 const GLvector4f *in, 00345 const GLfloat *lengths, 00346 GLvector4f *dest ) 00347 { 00348 GLfloat (*out)[4] = (GLfloat (*)[4])dest->start; 00349 const GLfloat *from = in->start; 00350 const GLuint stride = in->stride; 00351 const GLuint count = in->count; 00352 GLuint i; 00353 00354 (void) mat; 00355 (void) lengths; 00356 00357 STRIDE_LOOP { 00358 SCALE_SCALAR_3V( out[i], scale, from ); 00359 } 00360 dest->count = in->count; 00361 } 00362 00363 00364 static void _XFORMAPI 00365 TAG(init_c_norm_transform)( void ) 00366 { 00367 _mesa_normal_tab[NORM_TRANSFORM_NO_ROT] = 00368 TAG(transform_normals_no_rot); 00369 00370 _mesa_normal_tab[NORM_TRANSFORM_NO_ROT | NORM_RESCALE] = 00371 TAG(transform_rescale_normals_no_rot); 00372 00373 _mesa_normal_tab[NORM_TRANSFORM_NO_ROT | NORM_NORMALIZE] = 00374 TAG(transform_normalize_normals_no_rot); 00375 00376 _mesa_normal_tab[NORM_TRANSFORM] = 00377 TAG(transform_normals); 00378 00379 _mesa_normal_tab[NORM_TRANSFORM | NORM_RESCALE] = 00380 TAG(transform_rescale_normals); 00381 00382 _mesa_normal_tab[NORM_TRANSFORM | NORM_NORMALIZE] = 00383 TAG(transform_normalize_normals); 00384 00385 _mesa_normal_tab[NORM_RESCALE] = 00386 TAG(rescale_normals); 00387 00388 _mesa_normal_tab[NORM_NORMALIZE] = 00389 TAG(normalize_normals); 00390 } Generated on Sat May 26 2012 04:19:18 for ReactOS by
1.7.6.1
|