m_xform.c revision 08836341788a9f9d638d9dc8328510ccd18ddeb5
108836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul/* $Id: m_xform.c,v 1.9 2001/03/03 20:33:30 brianp Exp $ */
223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/*
423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Mesa 3-D graphics library
523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Version:  3.5
623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *
723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Copyright (C) 1999-2000  Brian Paul   All Rights Reserved.
823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *
923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
1023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * copy of this software and associated documentation files (the "Software"),
1123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * to deal in the Software without restriction, including without limitation
1223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * and/or sell copies of the Software, and to permit persons to whom the
1423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Software is furnished to do so, subject to the following conditions:
1523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *
1623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * The above copyright notice and this permission notice shall be included
1723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * in all copies or substantial portions of the Software.
1823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *
1923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
2223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
2323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
2623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
2723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
2823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/*
2923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Matrix/vertex/vector transformation stuff
3023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *
3123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *
3223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * NOTES:
3323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * 1. 4x4 transformation matrices are stored in memory in column major order.
3423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * 2. Points/vertices are to be thought of as column vectors.
3523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * 3. Transformation of a point p by a matrix M is: p' = M * p
3623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
3723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
38912d3a04c191b835be07b8f104eed240d6cf0adaJon Taylor#include <math.h>
3923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
4023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "glheader.h"
4123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "macros.h"
4223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "mmath.h"
4323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
44cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#include "m_eval.h"
4523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_matrix.h"
465a9026c65d260dc185e072163999f5d810015108Brian Paul#include "m_translate.h"
4723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_xform.h"
48b980b2eeb62dc48101a7481d02d196c80b9da397Keith Whitwell#include "mathmod.h"
4923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
5023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
5123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#ifdef DEBUG
52fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes#include "m_debug.h"
5323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#endif
5423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
5523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#ifdef USE_X86_ASM
5623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "X86/common_x86_asm.h"
5723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#endif
5823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
5923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellclip_func gl_clip_tab[5];
60321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwellclip_func gl_clip_np_tab[5];
6123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwelldotprod_func gl_dotprod_tab[2][5];
6208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paulvec_copy_func _mesa_copy_tab[2][0x10];
6323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellnormal_func gl_normal_tab[0xf][0x4];
6408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paultransform_func **(_mesa_transform_tab[2]);
6523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellstatic transform_func *cull_transform_tab[5];
6623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellstatic transform_func *raw_transform_tab[5];
6723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
6823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
6923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/* Raw data format used for:
7023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *    - Object-to-eye transform prior to culling, although this too
7123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *      could be culled under some circumstances.
7223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *    - Eye-to-clip transform (via the function above).
7323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *    - Cliptesting
7423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *    - And everything else too, if culling happens to be disabled.
7523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
7623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define TAG(x) x##_raw
7723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define TAG2(x,y) x##y##_raw
7823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define IDX 0
7923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define STRIDE_LOOP for (i=0;i<count;i++, STRIDE_F(from, stride))
8023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define LOOP for (i=0;i<n;i++)
8123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define CULL_CHECK
8223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define CLIP_CHECK
8323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define ARGS
8423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_xform_tmp.h"
8523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_clip_tmp.h"
8623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_norm_tmp.h"
8723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_dotprod_tmp.h"
8823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_copy_tmp.h"
8923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef TAG
9023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef TAG2
9123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef LOOP
9223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef CULL_CHECK
9323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef CLIP_CHECK
9423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef ARGS
9523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef IDX
9623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
9723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/* Culled data used for:
9823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *    - texture transformations
9923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *    - viewport map transformation
10023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *    - normal transformations prior to lighting
10123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *    - user cliptests
10223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
10323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define TAG(x) x##_masked
10423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define TAG2(x,y) x##y##_masked
10523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define IDX 1
10623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define STRIDE_LOOP for (i=0;i<count;i++, STRIDE_F(from, stride))
10723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define LOOP for (i=0;i<n;i++)
10823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define CULL_CHECK if (mask[i])
10923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define CLIP_CHECK if ((mask[i] & flag) == 0)
11023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define ARGS , const GLubyte mask[]
11123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_xform_tmp.h"
11223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_norm_tmp.h"
11323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_dotprod_tmp.h"
11423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_copy_tmp.h"
11523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef TAG
11623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef TAG2
11723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef LOOP
11823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef CULL_CHECK
11923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef CLIP_CHECK
12023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef ARGS
12123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef IDX
12223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
12323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
12423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
12523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
12623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
12723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
12808836341788a9f9d638d9dc8328510ccd18ddeb5Brian PaulGLvector4f *_mesa_project_points( GLvector4f *proj_vec,
12923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell			       const GLvector4f *clip_vec )
13023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell{
13123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   const GLuint stride = clip_vec->stride;
13223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   const GLfloat *from = (GLfloat *)clip_vec->start;
13323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   const GLuint count = clip_vec->count;
13423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   GLfloat (*vProj)[4] = (GLfloat (*)[4])proj_vec->start;
13523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   GLuint i;
13623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
13723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   for (i = 0 ; i < count ; i++, STRIDE_F(from, stride))
13823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   {
13923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell	 GLfloat oow = 1.0F / from[3];
14023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell	 vProj[i][3] = oow;
14123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell	 vProj[i][0] = from[0] * oow;
14223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell	 vProj[i][1] = from[1] * oow;
14323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell	 vProj[i][2] = from[2] * oow;
14423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   }
14523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
14623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   proj_vec->flags |= VEC_SIZE_4;
14723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   proj_vec->size = 3;
14823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   proj_vec->count = clip_vec->count;
14923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   return proj_vec;
15023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell}
15123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
15223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
15323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
15423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
15523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
15623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
15723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/*
15823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Transform a 4-element row vector (1x4 matrix) by a 4x4 matrix.  This
15923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * function is used for transforming clipping plane equations and spotlight
16023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * directions.
16123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Mathematically,  u = v * m.
16223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Input:  v - input vector
16323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *         m - transformation matrix
16423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Output:  u - transformed vector
16523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
16608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paulvoid _mesa_transform_vector( GLfloat u[4], const GLfloat v[4], const GLfloat m[16] )
16723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell{
16823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   GLfloat v0=v[0], v1=v[1], v2=v[2], v3=v[3];
16923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define M(row,col)  m[row + col*4]
17023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   u[0] = v0 * M(0,0) + v1 * M(1,0) + v2 * M(2,0) + v3 * M(3,0);
17123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   u[1] = v0 * M(0,1) + v1 * M(1,1) + v2 * M(2,1) + v3 * M(3,1);
17223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   u[2] = v0 * M(0,2) + v1 * M(1,2) + v2 * M(2,2) + v3 * M(3,2);
17323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   u[3] = v0 * M(0,3) + v1 * M(1,3) + v2 * M(2,3) + v3 * M(3,3);
17423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef M
17523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell}
17623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
17723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
17823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/* Useful for one-off point transformations, as in clipping.
179ad2ac216fa0cbebc36530bf9e5256e902710b892Keith Whitwell * Note that because the matrix isn't analysed we do too many
18023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * multiplies, and that the result is always 4-clean.
18123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
18208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paulvoid _mesa_transform_point_sz( GLfloat Q[4], const GLfloat M[16],
18323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell			    const GLfloat P[4], GLuint sz )
18423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell{
18523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   if (Q == P)
18623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell      return;
18723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
18823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   if (sz == 4)
18923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   {
19023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell      Q[0] = M[0] * P[0] + M[4] * P[1] + M[8] *  P[2] + M[12] * P[3];
19123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell      Q[1] = M[1] * P[0] + M[5] * P[1] + M[9] *  P[2] + M[13] * P[3];
19223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell      Q[2] = M[2] * P[0] + M[6] * P[1] + M[10] * P[2] + M[14] * P[3];
19323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell      Q[3] = M[3] * P[0] + M[7] * P[1] + M[11] * P[2] + M[15] * P[3];
19423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   }
19523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   else if (sz == 3)
19623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   {
19723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell      Q[0] = M[0] * P[0] + M[4] * P[1] + M[8] *  P[2] + M[12];
19823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell      Q[1] = M[1] * P[0] + M[5] * P[1] + M[9] *  P[2] + M[13];
19923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell      Q[2] = M[2] * P[0] + M[6] * P[1] + M[10] * P[2] + M[14];
20023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell      Q[3] = M[3] * P[0] + M[7] * P[1] + M[11] * P[2] + M[15];
20123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   }
20223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   else if (sz == 2)
20323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   {
20423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell      Q[0] = M[0] * P[0] + M[4] * P[1] +                M[12];
20523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell      Q[1] = M[1] * P[0] + M[5] * P[1] +                M[13];
20623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell      Q[2] = M[2] * P[0] + M[6] * P[1] +                M[14];
20723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell      Q[3] = M[3] * P[0] + M[7] * P[1] +                M[15];
20823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   }
20923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   else if (sz == 1)
21023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   {
21123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell      Q[0] = M[0] * P[0] +                              M[12];
21223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell      Q[1] = M[1] * P[0] +                              M[13];
21323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell      Q[2] = M[2] * P[0] +                              M[14];
21423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell      Q[3] = M[3] * P[0] +                              M[15];
21523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   }
21623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell}
21723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
21823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
21923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/*
22023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * This is called only once.  It initializes several tables with pointers
22123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * to optimized transformation functions.  This is where we can test for
22223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * AMD 3Dnow! capability, Intel Katmai, etc. and hook in the right code.
22323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
224fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughesvoid
22523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell_math_init_transformation( void )
22623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell{
22708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul   _mesa_transform_tab[0] = raw_transform_tab;
22808836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul   _mesa_transform_tab[1] = cull_transform_tab;
22923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
23023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   init_c_transformations_raw();
23123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   init_c_transformations_masked();
23223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   init_c_norm_transform_raw();
23323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   init_c_norm_transform_masked();
23423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   init_c_cliptest_raw();
23523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   init_copy0_raw();
23623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   init_copy0_masked();
23723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   init_dotprod_raw();
23823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   init_dotprod_masked();
23923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
24023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#ifdef DEBUG
241fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes   _math_test_all_transform_functions( "default" );
242fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes   _math_test_all_normal_transform_functions( "default" );
24323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#endif
24423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
24523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#ifdef USE_X86_ASM
24608836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul   _mesa_init_all_x86_transform_asm();
24723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#endif
24823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell}
24923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
25023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellvoid
25123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell_math_init( void )
25223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell{
25323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   _math_init_transformation();
25423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   _math_init_translate();
25523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell   _math_init_vertices();
256cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   _math_init_eval();
25723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell}
258