1 /* $Id: m_xform.c,v 1.17 2002/07/10 01:25:50 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * Matrix/vertex/vector transformation stuff
33 * 1. 4x4 transformation matrices are stored in memory in column major order.
34 * 2. Points/vertices are to be thought of as column vectors.
35 * 3. Transformation of a point p by a matrix M is: p' = M * p
46 #include "m_translate.h"
56 #include "X86/common_x86_asm.h"
60 #include "SPARC/sparc.h"
63 clip_func _mesa_clip_tab
[5];
64 clip_func _mesa_clip_np_tab
[5];
65 dotprod_func _mesa_dotprod_tab
[5];
66 vec_copy_func _mesa_copy_tab
[0x10];
67 normal_func _mesa_normal_tab
[0xf];
68 transform_func
*_mesa_transform_tab
[5];
71 /* Raw data format used for:
72 * - Object-to-eye transform prior to culling, although this too
73 * could be culled under some circumstances.
74 * - Eye-to-clip transform (via the function above).
76 * - And everything else too, if culling happens to be disabled.
78 * GH: It's used for everything now, as clipping/culling is done
79 * elsewhere (most often by the driver itself).
82 #define TAG2(x,y) x##y
83 #define STRIDE_LOOP for ( i = 0 ; i < count ; i++, STRIDE_F(from, stride) )
84 #define LOOP for ( i = 0 ; i < n ; i++ )
86 #include "m_xform_tmp.h"
87 #include "m_clip_tmp.h"
88 #include "m_norm_tmp.h"
89 #include "m_dotprod_tmp.h"
90 #include "m_copy_tmp.h"
99 GLvector4f
*_mesa_project_points( GLvector4f
*proj_vec
,
100 const GLvector4f
*clip_vec
)
102 const GLuint stride
= clip_vec
->stride
;
103 const GLfloat
*from
= (GLfloat
*)clip_vec
->start
;
104 const GLuint count
= clip_vec
->count
;
105 GLfloat (*vProj
)[4] = (GLfloat (*)[4])proj_vec
->start
;
108 for (i
= 0 ; i
< count
; i
++, STRIDE_F(from
, stride
))
110 GLfloat oow
= 1.0F
/ from
[3];
112 vProj
[i
][0] = from
[0] * oow
;
113 vProj
[i
][1] = from
[1] * oow
;
114 vProj
[i
][2] = from
[2] * oow
;
117 proj_vec
->flags
|= VEC_SIZE_4
;
119 proj_vec
->count
= clip_vec
->count
;
129 * Transform a 4-element row vector (1x4 matrix) by a 4x4 matrix. This
130 * function is used for transforming clipping plane equations and spotlight
132 * Mathematically, u = v * m.
133 * Input: v - input vector
134 * m - transformation matrix
135 * Output: u - transformed vector
137 void _mesa_transform_vector( GLfloat u
[4], const GLfloat v
[4], const GLfloat m
[16] )
139 GLfloat v0
=v
[0], v1
=v
[1], v2
=v
[2], v3
=v
[3];
140 #define M(row,col) m[row + col*4]
141 u
[0] = v0
* M(0,0) + v1
* M(1,0) + v2
* M(2,0) + v3
* M(3,0);
142 u
[1] = v0
* M(0,1) + v1
* M(1,1) + v2
* M(2,1) + v3
* M(3,1);
143 u
[2] = v0
* M(0,2) + v1
* M(1,2) + v2
* M(2,2) + v3
* M(3,2);
144 u
[3] = v0
* M(0,3) + v1
* M(1,3) + v2
* M(2,3) + v3
* M(3,3);
149 /* Useful for one-off point transformations, as in clipping.
150 * Note that because the matrix isn't analysed we do too many
151 * multiplies, and that the result is always 4-clean.
153 void _mesa_transform_point_sz( GLfloat Q
[4], const GLfloat M
[16],
154 const GLfloat P
[4], GLuint sz
)
161 Q
[0] = M
[0] * P
[0] + M
[4] * P
[1] + M
[8] * P
[2] + M
[12] * P
[3];
162 Q
[1] = M
[1] * P
[0] + M
[5] * P
[1] + M
[9] * P
[2] + M
[13] * P
[3];
163 Q
[2] = M
[2] * P
[0] + M
[6] * P
[1] + M
[10] * P
[2] + M
[14] * P
[3];
164 Q
[3] = M
[3] * P
[0] + M
[7] * P
[1] + M
[11] * P
[2] + M
[15] * P
[3];
168 Q
[0] = M
[0] * P
[0] + M
[4] * P
[1] + M
[8] * P
[2] + M
[12];
169 Q
[1] = M
[1] * P
[0] + M
[5] * P
[1] + M
[9] * P
[2] + M
[13];
170 Q
[2] = M
[2] * P
[0] + M
[6] * P
[1] + M
[10] * P
[2] + M
[14];
171 Q
[3] = M
[3] * P
[0] + M
[7] * P
[1] + M
[11] * P
[2] + M
[15];
175 Q
[0] = M
[0] * P
[0] + M
[4] * P
[1] + M
[12];
176 Q
[1] = M
[1] * P
[0] + M
[5] * P
[1] + M
[13];
177 Q
[2] = M
[2] * P
[0] + M
[6] * P
[1] + M
[14];
178 Q
[3] = M
[3] * P
[0] + M
[7] * P
[1] + M
[15];
182 Q
[0] = M
[0] * P
[0] + M
[12];
183 Q
[1] = M
[1] * P
[0] + M
[13];
184 Q
[2] = M
[2] * P
[0] + M
[14];
185 Q
[3] = M
[3] * P
[0] + M
[15];
191 * This is called only once. It initializes several tables with pointers
192 * to optimized transformation functions. This is where we can test for
193 * AMD 3Dnow! capability, Intel Katmai, etc. and hook in the right code.
196 _math_init_transformation( void )
198 init_c_transformations();
199 init_c_norm_transform();
205 _math_test_all_transform_functions( "default" );
206 _math_test_all_normal_transform_functions( "default" );
207 _math_test_all_cliptest_functions( "default" );
211 _mesa_init_all_x86_transform_asm();
214 _mesa_init_all_sparc_transform_asm();
221 _math_init_transformation();
222 _math_init_translate();