Home | History | Annotate | Download | only in math
      1 /*
      2  * Mesa 3-D graphics library
      3  *
      4  * Copyright (C) 1999-2003  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 /*
     27  * Matrix/vertex/vector transformation stuff
     28  *
     29  *
     30  * NOTES:
     31  * 1. 4x4 transformation matrices are stored in memory in column major order.
     32  * 2. Points/vertices are to be thought of as column vectors.
     33  * 3. Transformation of a point p by a matrix M is: p' = M * p
     34  */
     35 
     36 #include "c99_math.h"
     37 #include "main/glheader.h"
     38 #include "main/macros.h"
     39 
     40 #include "m_eval.h"
     41 #include "m_matrix.h"
     42 #include "m_translate.h"
     43 #include "m_xform.h"
     44 
     45 
     46 #ifdef DEBUG_MATH
     47 #include "m_debug.h"
     48 #endif
     49 
     50 #ifdef USE_X86_ASM
     51 #include "x86/common_x86_asm.h"
     52 #endif
     53 
     54 #ifdef USE_X86_64_ASM
     55 #include "x86-64/x86-64.h"
     56 #endif
     57 
     58 #ifdef USE_SPARC_ASM
     59 #include "sparc/sparc.h"
     60 #endif
     61 
     62 clip_func _mesa_clip_tab[5];
     63 clip_func _mesa_clip_np_tab[5];
     64 dotprod_func _mesa_dotprod_tab[5];
     65 vec_copy_func _mesa_copy_tab[0x10];
     66 normal_func _mesa_normal_tab[0xf];
     67 transform_func *_mesa_transform_tab[5];
     68 
     69 
     70 /* Raw data format used for:
     71  *    - Object-to-eye transform prior to culling, although this too
     72  *      could be culled under some circumstances.
     73  *    - Eye-to-clip transform (via the function above).
     74  *    - Cliptesting
     75  *    - And everything else too, if culling happens to be disabled.
     76  *
     77  * GH: It's used for everything now, as clipping/culling is done
     78  *     elsewhere (most often by the driver itself).
     79  */
     80 #define TAG(x) x
     81 #define TAG2(x,y) x##y
     82 #define STRIDE_LOOP for ( i = 0 ; i < count ; i++, STRIDE_F(from, stride) )
     83 #define LOOP for ( i = 0 ; i < n ; i++ )
     84 #define ARGS
     85 #include "m_xform_tmp.h"
     86 #include "m_clip_tmp.h"
     87 #include "m_norm_tmp.h"
     88 #include "m_dotprod_tmp.h"
     89 #include "m_copy_tmp.h"
     90 #undef TAG
     91 #undef TAG2
     92 #undef LOOP
     93 #undef ARGS
     94 
     95 
     96 /*
     97  * This is called only once.  It initializes several tables with pointers
     98  * to optimized transformation functions.  This is where we can test for
     99  * AMD 3Dnow! capability, Intel SSE, etc. and hook in the right code.
    100  */
    101 void
    102 _math_init_transformation( void )
    103 {
    104    init_c_transformations();
    105    init_c_norm_transform();
    106    init_c_cliptest();
    107    init_copy0();
    108    init_dotprod();
    109 
    110 #ifdef DEBUG_MATH
    111    _math_test_all_transform_functions( "default" );
    112    _math_test_all_normal_transform_functions( "default" );
    113    _math_test_all_cliptest_functions( "default" );
    114 #endif
    115 
    116 #ifdef USE_X86_ASM
    117    _mesa_init_all_x86_transform_asm();
    118 #elif defined( USE_SPARC_ASM )
    119    _mesa_init_all_sparc_transform_asm();
    120 #elif defined( USE_X86_64_ASM )
    121    _mesa_init_all_x86_64_transform_asm();
    122 #endif
    123 }
    124