head 3.13; access; symbols merge-1:3.12.2.4 autoconf:3.12.0.4 experimental-1:3.12.0.2 mesa-3-1-with-kw3:3.5 mesa-3-1-prior-to-kw3:3.4; locks; strict; comment @ * @; 3.13 date 99.07.12.12.05.24; author keithw; state Exp; branches; next 3.12; 3.12 date 99.05.08.01.35.42; author joshv; state Exp; branches 3.12.2.1; next 3.11; 3.11 date 99.05.06.03.44.47; author joshv; state Exp; branches; next 3.10; 3.10 date 99.04.16.00.44.29; author brianp; state Exp; branches; next 3.9; 3.9 date 99.04.16.00.37.52; author brianp; state Exp; branches; next 3.8; 3.8 date 99.04.06.00.50.33; author brianp; state Exp; branches; next 3.7; 3.7 date 99.03.31.20.18.39; author keithw; state Exp; branches; next 3.6; 3.6 date 99.03.17.12.08.22; author keithw; state Exp; branches; next 3.5; 3.5 date 99.02.25.14.12.31; author keithw; state Exp; branches; next 3.4; 3.4 date 99.02.14.03.46.34; author brianp; state Exp; branches; next 3.3; 3.3 date 98.10.23.00.26.55; author brianp; state Exp; branches; next 3.2; 3.2 date 98.10.23.00.21.55; author brianp; state Exp; branches; next 3.1; 3.1 date 98.04.18.05.00.14; author brianp; state Exp; branches; next 3.0; 3.0 date 98.01.31.20.59.27; author brianp; state Exp; branches; next ; 3.12.2.1 date 99.05.21.21.29.26; author keithw; state Exp; branches; next 3.12.2.2; 3.12.2.2 date 99.05.24.02.13.39; author keithw; state Exp; branches; next 3.12.2.3; 3.12.2.3 date 99.05.27.20.52.32; author keithw; state Exp; branches; next 3.12.2.4; 3.12.2.4 date 99.06.10.15.20.14; author tanner; state Exp; branches; next ; desc @Mesa math functions @ 3.13 log @merge from experimental branch upto merge-1 tag @ text @/* $Id: mmath.h,v 3.12.2.4 1999/06/10 15:20:14 tanner Exp $ */ /* * Mesa 3-D graphics library * Version: 3.1 * * Copyright (C) 1999 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * Faster arithmetic functions. If the FAST_MATH preprocessor symbol is * defined on the command line (-DFAST_MATH) then we'll use some (hopefully) * faster functions for sqrt(), etc. */ #ifndef MMATH_H #define MMATH_H #ifdef HAVE_CONFIG_H #include "conf.h" #endif #include /* * Set the x86 FPU control word to guarentee only 32 bits of presision * are stored in registers. Allowing the FPU to store more introduces * differences between situations where numbers are pulled out of memory * vs. situations where the compiler is able to optimize register usage. * * In the worst case, we force the compiler to use a memory access to * truncate the float, by specifying the 'volatile' keyword. */ #if defined(__linux__) && defined(__i386__) #include #if !defined(_FPU_SETCW) #define _FPU_SETCW __setfpucw typedef unsigned short fpu_control_t; #endif #define START_FAST_MATH \ { \ static fpu_control_t mask = _FPU_SINGLE | _FPU_MASK_IM \ | _FPU_MASK_DM | _FPU_MASK_ZM | _FPU_MASK_OM \ | _FPU_MASK_UM | _FPU_MASK_PM; \ _FPU_SETCW( mask ); \ } #define END_FAST_MATH \ { \ static fpu_control_t mask = _FPU_DEFAULT; \ _FPU_SETCW( mask ); \ } #define HAVE_FAST_MATH #else #define START_FAST_MATH #define END_FAST_MATH /* The mac float really is a float, with the same precision as a * single precision 387 float. */ #if defined(macintosh) #define HAVE_FAST_MATH #endif #endif /* * Float -> Int conversion */ #if defined(USE_X86_ASM) #if defined(__GNUC__) && defined(__i386__) static __inline__ int FloatToInt(float f) { int r; __asm__ ("fistpl %0" : "=m" (r) : "t" (f) : "st"); return r; } #elif defined(__MSC__) && defined(__WIN32__) static __inline int FloatToInt(float f) { int r; _asm { fld f fistp r } return r; } #endif #else #define FloatToInt(F) ((int) (F)) #endif /* * Square root */ extern float gl_sqrt(float x); #ifdef FAST_MATH # define GL_SQRT(X) gl_sqrt(X) #else # define GL_SQRT(X) sqrt(X) #endif /* * Normalize a 3-element vector to unit length. */ #define NORMALIZE_3FV( V ) \ do { \ GLdouble len = LEN_SQUARED_3FV(V); \ if (len > 1e-50) { \ len = 1.0 / GL_SQRT(len); \ V[0] *= len; \ V[1] *= len; \ V[2] *= len; \ } \ } while(0) #define LEN_3FV( V ) (GL_SQRT(V[0]*V[0]+V[1]*V[1]+V[2]*V[2])) #define LEN_SQUARED_3FV( V ) (V[0]*V[0]+V[1]*V[1]+V[2]*V[2]) /* * Optimization for: * GLfloat f; * GLubyte b = FloatToInt(CLAMP(f, 0, 1) * 255) */ #if defined(__i386__) || defined(__sparc__) #define USE_IEEE #endif #if defined(USE_IEEE) && !defined(DEBUG) #define IEEE_ONE 0x3f7f0000 #define CLAMP_FLOAT_COLOR(f) \ do { \ if (*(GLuint *)&f >= IEEE_ONE) \ f = (*(GLint *)&f < 0) ? 0 : 1; \ } while(0) #define CLAMP_FLOAT_COLOR_VALUE(f) \ ( (*(GLuint *)&f >= IEEE_ONE) \ ? ((*(GLint *)&f < 0) ? 0 : 1) \ : f ) /* * This function/macro is sensitive to precision. Test carefully * if you change it. */ #define FLOAT_COLOR_TO_UBYTE_COLOR(b, f) \ do { \ union { GLfloat r; GLuint i; } tmp; \ tmp.r = f; \ b = ((tmp.i >= IEEE_ONE) \ ? ((GLint)tmp.i < 0) ? (GLubyte)0 : (GLubyte)255 \ : (tmp.r = tmp.r*(255.0F/256.0F) + 32768.0F, \ (GLubyte)tmp.i)); \ } while (0) #define CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(b,f) \ FLOAT_COLOR_TO_UBYTE_COLOR(b, f) #else #define CLAMP_FLOAT_COLOR(f) \ (void) CLAMP_SELF(f,0,1) #define CLAMP_FLOAT_COLOR_VALUE(f) \ CLAMP(f,0,1) #define FLOAT_COLOR_TO_UBYTE_COLOR(b, f) \ b = FloatToInt(CLAMP(f, 0.0F, 1.0F) * 255.0F) #define CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(b,f) \ b = FloatToInt(f * 255.0F) #endif extern float gl_ubyte_to_float_color_tab[256]; extern float gl_ubyte_to_float_255_color_tab[256]; #define UBYTE_COLOR_TO_FLOAT_COLOR(c) gl_ubyte_to_float_color_tab[c] #define UBYTE_COLOR_TO_FLOAT_255_COLOR(c) gl_ubyte_to_float_255_color_tab[c] #define UBYTE_COLOR_TO_FLOAT_255_COLOR2(f,c) \ (*(int *)&(f)) = ((int *)gl_ubyte_to_float_255_color_tab)[c] #define UBYTE_RGBA_TO_FLOAT_RGBA(f,b) \ do { \ f[0] = UBYTE_COLOR_TO_FLOAT_COLOR(b[0]); \ f[1] = UBYTE_COLOR_TO_FLOAT_COLOR(b[1]); \ f[2] = UBYTE_COLOR_TO_FLOAT_COLOR(b[2]); \ f[3] = UBYTE_COLOR_TO_FLOAT_COLOR(b[3]); \ } while(0) #define UBYTE_RGBA_TO_FLOAT_255_RGBA(f,b) \ do { \ f[0] = UBYTE_COLOR_TO_FLOAT_255_COLOR(b[0]); \ f[1] = UBYTE_COLOR_TO_FLOAT_255_COLOR(b[1]); \ f[2] = UBYTE_COLOR_TO_FLOAT_255_COLOR(b[2]); \ f[3] = UBYTE_COLOR_TO_FLOAT_255_COLOR(b[3]); \ } while(0) #define FLOAT_RGBA_TO_UBYTE_RGBA(b,f) \ do { \ FLOAT_COLOR_TO_UBYTE_COLOR((b[0]),(f[0])); \ FLOAT_COLOR_TO_UBYTE_COLOR((b[1]),(f[1])); \ FLOAT_COLOR_TO_UBYTE_COLOR((b[2]),(f[2])); \ FLOAT_COLOR_TO_UBYTE_COLOR((b[3]),(f[3])); \ } while(0) #define FLOAT_RGB_TO_UBYTE_RGB(b,f) \ do { \ FLOAT_COLOR_TO_UBYTE_COLOR(b[0],f[0]); \ FLOAT_COLOR_TO_UBYTE_COLOR(b[1],f[1]); \ FLOAT_COLOR_TO_UBYTE_COLOR(b[2],f[2]); \ } while(0) extern void gl_init_math(void); #endif @ 3.12 log @Define _FPU_SETCW for Linux libc 5. Check for gcc for FloatToInt. @ text @d1 1 a1 1 /* $Id: mmath.h,v 3.11 1999/05/06 03:44:47 joshv Exp $ */ d41 3 a46 2 d77 2 d82 8 d223 3 d235 9 d246 4 a249 4 FLOAT_COLOR_TO_UBYTE_COLOR(b[0],f[0]); \ FLOAT_COLOR_TO_UBYTE_COLOR(b[1],f[1]); \ FLOAT_COLOR_TO_UBYTE_COLOR(b[2],f[2]); \ FLOAT_COLOR_TO_UBYTE_COLOR(b[3],f[3]); \ @ 3.12.2.1 log @Quake3 inspired optimizations @ text @d1 1 a1 1 /* $Id: mmath.h,v 3.12 1999/05/08 01:35:42 joshv Exp $ */ d44 2 a220 9 #define UBYTE_RGBA_TO_FLOAT_255_RGBA(f,b) \ do { \ f[0] = UBYTE_COLOR_TO_FLOAT_255_COLOR(b[0]); \ f[1] = UBYTE_COLOR_TO_FLOAT_255_COLOR(b[1]); \ f[2] = UBYTE_COLOR_TO_FLOAT_255_COLOR(b[2]); \ f[3] = UBYTE_COLOR_TO_FLOAT_255_COLOR(b[3]); \ } while(0) d223 4 a226 4 FLOAT_COLOR_TO_UBYTE_COLOR((b[0]),(f[0])); \ FLOAT_COLOR_TO_UBYTE_COLOR((b[1]),(f[1])); \ FLOAT_COLOR_TO_UBYTE_COLOR((b[2]),(f[2])); \ FLOAT_COLOR_TO_UBYTE_COLOR((b[3]),(f[3])); \ @ 3.12.2.2 log @new, experimental fast path for quake 3 precalc pipeline @ text @d1 1 a1 1 /* $Id: mmath.h,v 3.12.2.1 1999/05/21 21:29:26 keithw Exp $ */ a208 3 #define UBYTE_COLOR_TO_FLOAT_255_COLOR2(f,c) \ (*(int *)&(f)) = ((int *)gl_ubyte_to_float_255_color_tab)[c] @ 3.12.2.3 log @Faux multitexturing for voodoo-1 @ text @d1 1 a1 1 /* $Id: mmath.h,v 3.12.2.2 1999/05/24 02:13:39 keithw Exp $ */ a73 2 #define HAVE_FAST_MATH a76 8 /* The mac float really is a float, with the same precision as a * single precision 387 float. */ #if defined(macintosh) #define HAVE_FAST_MATH #endif @ 3.12.2.4 log @ autoconf updates, added .cvsignore @ text @d1 1 a1 1 /* $Id: mmath.h,v 3.12.2.3 1999/05/27 20:52:32 keithw Exp $ */ a40 3 #ifdef HAVE_CONFIG_H #include "conf.h" #endif @ 3.11 log @alias safe FLOAT_COLOR_TO_UBYTE_COLOR @ text @d1 1 a1 1 /* $Id: mmath.h,v 3.10 1999/04/16 00:44:29 brianp Exp $ */ d57 4 a62 1 #if defined(_FPU_SETCW) d75 1 d88 1 d105 1 @ 3.10 log @new FLOAT_COLOR_TO_UBYTE_COLOR from Josh Vanderhoof @ text @d1 1 a1 1 /* $Id: mmath.h,v 3.9 1999/04/16 00:37:52 brianp Exp $ */ d171 6 a176 5 GLfloat tmp; \ b = ((*(GLuint *)&f >= IEEE_ONE) \ ? (*(GLint *)&f < 0) ? (GLubyte)0 : (GLubyte)255 \ : (tmp = f*(255.0F/256.0F) + 32768.0F, \ (GLubyte)*(GLuint *)&tmp)); \ @ 3.9 log @new START/END_FAST_MATH macros for glibc 2.1 @ text @d1 1 a1 1 /* $Id: mmath.h,v 3.8 1999/04/06 00:50:33 brianp Exp $ */ d165 12 a176 9 /* KW: slight optimization of this macro. */ #define FLOAT_COLOR_TO_UBYTE_COLOR(b, f) \ do { \ GLfloat tmp; \ b = ((*(GLuint *)&f >= IEEE_ONE) \ ? (*(GLint *)&f < 0) ? (GLubyte)0 : (GLubyte)255 \ : (tmp = f + 32768.0F, (GLubyte)*(GLuint *)&tmp)); \ } while (0) @ 3.8 log @enable IEEE on sparc - David Miller @ text @d1 1 a1 1 /* $Id: mmath.h,v 3.7 1999/03/31 20:18:39 keithw Exp $ */ d57 15 a71 3 #define START_FAST_MATH __setfpucw(_FPU_SINGLE | _FPU_MASK_IM | _FPU_MASK_DM \ | _FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM | _FPU_MASK_PM); #define END_FAST_MATH __setfpucw( _FPU_DEFAULT ); @ 3.7 log @Compiled vertex arrays @ text @d1 1 a1 1 /* $Id: mmath.h,v 3.6 1999/03/17 12:08:22 keithw Exp $ */ d134 1 a134 1 #if defined(__i386__) @ 3.6 log @Removed CLIP_4D_BIT, added CLIP_CULLED_BIT. Clipmask is now used to drive culling in vertex transformation, allowing us to skip both clipped and culled vertices with a single test. @ text @d1 1 a1 1 /* $Id: mmath.h,v 3.5 1999/02/25 14:12:31 keithw Exp $ */ d165 1 a165 3 do { GLfloat tmp = f + 32768.0F; \ b = (GLubyte)*(GLuint *)&tmp; \ } while(0) @ 3.5 log @Merged in kw3 patch @ text @d1 1 a1 1 /* $Id: mmath.h,v 3.4 1999/02/14 03:46:34 brianp Exp $ */ d59 1 a59 2 #define END_FAST_MATH __setfpucw(_FPU_EXTENDED | _FPU_MASK_IM | _FPU_MASK_DM \ | _FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM | _FPU_MASK_PM); @ 3.4 log @new copyright @ text @d1 1 a1 1 /* $Id: mmath.h,v 3.3 1998/10/23 00:26:55 brianp Exp brianp $ */ d28 1 a28 15 /* * $Log: mmath.h,v $ * Revision 3.3 1998/10/23 00:26:55 brianp * added FloatToInt macro for Win32 (Eero Pajarre) * * Revision 3.2 1998/10/23 00:21:55 brianp * patched with Keith Whitwell's changes * * Revision 3.1 1998/04/18 05:00:14 brianp * added FLOAT_COLOR_TO_UBYTE_COLOR macro * * Revision 3.0 1998/01/31 20:59:27 brianp * initial rev * */ d47 7 a53 1 * Set the x86 FPU control word to less precision for more speed: d55 2 a56 2 #if defined(__linux__) && defined(__i386__) && defined(FAST_MATH) #include d95 2 d142 27 a168 7 #define FLOAT_COLOR_TO_UBYTE_COLOR(b, f) \ { \ GLfloat tmp = f + 32768.0F; \ b = ((*(GLuint *)&f >= IEEE_ONE) \ ? (*(GLint *)&f < 0) ? (GLubyte)0 : (GLubyte)255 \ : (GLubyte)*(GLuint *)&tmp); \ } d172 6 d181 3 d186 30 @ 3.3 log @added FloatToInt macro for Win32 (Eero Pajarre) @ text @d1 1 a1 1 /* $Id: mmath.h,v 3.2 1998/10/23 00:21:55 brianp Exp brianp $ */ d6 19 a24 15 * Copyright (C) 1995-1998 Brian Paul * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. d30 3 @ 3.2 log @patched with Keith Whitwell's changes @ text @d1 1 a1 1 /* $Id: mmath.h,v 3.1 1998/04/18 05:00:14 brianp Exp brianp $ */ d26 3 d78 10 @ 3.1 log @added FLOAT_COLOR_TO_UBYTE_COLOR macro @ text @d1 1 a1 1 /* $Id: mmath.h,v 3.0 1998/01/31 20:59:27 brianp Exp brianp $ */ d5 1 a5 1 * Version: 3.0 d26 3 d100 10 a109 11 #define NORMALIZE_3FV( V ) \ { \ GLfloat len; \ len = GL_SQRT(V[0]*V[0]+V[1]*V[1]+V[2]*V[2]); \ if (len>0.0001F) { \ len = 1.0F / len; \ V[0] *= len; \ V[1] *= len; \ V[2] *= len; \ } \ } d111 1 d113 1 @ 3.0 log @initial rev @ text @d1 1 a1 1 /* $Id$ */ d25 4 a28 1 * $Log$ d46 1 d63 5 a67 1 #if defined(USE_ASM) d80 4 a85 1 d93 4 a96 1 /* Normalize a 3-element vector to unit length */ d108 31 @