Rev 134 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
134 | giacomo | 1 | /* $Id: m_xform.c,v 1.3 2003-04-24 13:37:47 giacomo Exp $ */ |
56 | pj | 2 | |
3 | /* |
||
4 | * Mesa 3-D graphics library |
||
5 | * Version: 3.5 |
||
6 | * |
||
7 | * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. |
||
8 | * |
||
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: |
||
15 | * |
||
16 | * The above copyright notice and this permission notice shall be included |
||
17 | * in all copies or substantial portions of the Software. |
||
18 | * |
||
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. |
||
25 | */ |
||
26 | |||
27 | |||
28 | /* |
||
29 | * Matrix/vertex/vector transformation stuff |
||
30 | * |
||
31 | * |
||
32 | * NOTES: |
||
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 |
||
36 | */ |
||
37 | |||
38 | #include "glheader.h" |
||
39 | #include "macros.h" |
||
40 | #include "mmath.h" |
||
41 | |||
42 | #include "m_eval.h" |
||
43 | #include "m_matrix.h" |
||
44 | #include "m_translate.h" |
||
45 | #include "m_xform.h" |
||
46 | #include "mathmod.h" |
||
47 | |||
48 | |||
49 | #ifdef DEBUG |
||
50 | #include "m_debug.h" |
||
51 | #endif |
||
52 | |||
53 | #ifdef USE_X86_ASM |
||
72 | giacomo | 54 | #include "x86/common_x86_asm.h" |
56 | pj | 55 | #endif |
56 | |||
57 | #ifdef USE_SPARC_ASM |
||
58 | #include "SPARC/sparc.h" |
||
59 | #endif |
||
60 | |||
61 | clip_func _mesa_clip_tab[5]; |
||
62 | clip_func _mesa_clip_np_tab[5]; |
||
63 | dotprod_func _mesa_dotprod_tab[5]; |
||
64 | vec_copy_func _mesa_copy_tab[0x10]; |
||
65 | normal_func _mesa_normal_tab[0xf]; |
||
66 | transform_func *_mesa_transform_tab[5]; |
||
67 | |||
68 | |||
69 | /* Raw data format used for: |
||
70 | * - Object-to-eye transform prior to culling, although this too |
||
71 | * could be culled under some circumstances. |
||
72 | * - Eye-to-clip transform (via the function above). |
||
73 | * - Cliptesting |
||
74 | * - And everything else too, if culling happens to be disabled. |
||
75 | * |
||
76 | * GH: It's used for everything now, as clipping/culling is done |
||
77 | * elsewhere (most often by the driver itself). |
||
78 | */ |
||
79 | #define TAG(x) x |
||
80 | #define TAG2(x,y) x##y |
||
81 | #define STRIDE_LOOP for ( i = 0 ; i < count ; i++, STRIDE_F(from, stride) ) |
||
82 | #define LOOP for ( i = 0 ; i < n ; i++ ) |
||
83 | #define ARGS |
||
134 | giacomo | 84 | #include "m_tmp_xform.h" |
56 | pj | 85 | #include "m_clip_tmp.h" |
86 | #include "m_norm_tmp.h" |
||
87 | #include "m_dotprod_tmp.h" |
||
88 | #include "m_copy_tmp.h" |
||
89 | #undef TAG |
||
90 | #undef TAG2 |
||
91 | #undef LOOP |
||
92 | #undef ARGS |
||
93 | |||
94 | |||
95 | |||
96 | |||
97 | GLvector4f *_mesa_project_points( GLvector4f *proj_vec, |
||
98 | const GLvector4f *clip_vec ) |
||
99 | { |
||
100 | const GLuint stride = clip_vec->stride; |
||
101 | const GLfloat *from = (GLfloat *)clip_vec->start; |
||
102 | const GLuint count = clip_vec->count; |
||
103 | GLfloat (*vProj)[4] = (GLfloat (*)[4])proj_vec->start; |
||
104 | GLuint i; |
||
105 | |||
106 | for (i = 0 ; i < count ; i++, STRIDE_F(from, stride)) |
||
107 | { |
||
108 | GLfloat oow = 1.0F / from[3]; |
||
109 | vProj[i][3] = oow; |
||
110 | vProj[i][0] = from[0] * oow; |
||
111 | vProj[i][1] = from[1] * oow; |
||
112 | vProj[i][2] = from[2] * oow; |
||
113 | } |
||
114 | |||
115 | proj_vec->flags |= VEC_SIZE_4; |
||
116 | proj_vec->size = 3; |
||
117 | proj_vec->count = clip_vec->count; |
||
118 | return proj_vec; |
||
119 | } |
||
120 | |||
121 | |||
122 | |||
123 | |||
124 | |||
125 | |||
126 | /* |
||
127 | * Transform a 4-element row vector (1x4 matrix) by a 4x4 matrix. This |
||
128 | * function is used for transforming clipping plane equations and spotlight |
||
129 | * directions. |
||
130 | * Mathematically, u = v * m. |
||
131 | * Input: v - input vector |
||
132 | * m - transformation matrix |
||
133 | * Output: u - transformed vector |
||
134 | */ |
||
135 | void _mesa_transform_vector( GLfloat u[4], const GLfloat v[4], const GLfloat m[16] ) |
||
136 | { |
||
137 | GLfloat v0=v[0], v1=v[1], v2=v[2], v3=v[3]; |
||
138 | #define M(row,col) m[row + col*4] |
||
139 | u[0] = v0 * M(0,0) + v1 * M(1,0) + v2 * M(2,0) + v3 * M(3,0); |
||
140 | u[1] = v0 * M(0,1) + v1 * M(1,1) + v2 * M(2,1) + v3 * M(3,1); |
||
141 | u[2] = v0 * M(0,2) + v1 * M(1,2) + v2 * M(2,2) + v3 * M(3,2); |
||
142 | u[3] = v0 * M(0,3) + v1 * M(1,3) + v2 * M(2,3) + v3 * M(3,3); |
||
143 | #undef M |
||
144 | } |
||
145 | |||
146 | |||
147 | /* Useful for one-off point transformations, as in clipping. |
||
148 | * Note that because the matrix isn't analysed we do too many |
||
149 | * multiplies, and that the result is always 4-clean. |
||
150 | */ |
||
151 | void _mesa_transform_point_sz( GLfloat Q[4], const GLfloat M[16], |
||
152 | const GLfloat P[4], GLuint sz ) |
||
153 | { |
||
154 | if (Q == P) |
||
155 | return; |
||
156 | |||
157 | if (sz == 4) |
||
158 | { |
||
159 | Q[0] = M[0] * P[0] + M[4] * P[1] + M[8] * P[2] + M[12] * P[3]; |
||
160 | Q[1] = M[1] * P[0] + M[5] * P[1] + M[9] * P[2] + M[13] * P[3]; |
||
161 | Q[2] = M[2] * P[0] + M[6] * P[1] + M[10] * P[2] + M[14] * P[3]; |
||
162 | Q[3] = M[3] * P[0] + M[7] * P[1] + M[11] * P[2] + M[15] * P[3]; |
||
163 | } |
||
164 | else if (sz == 3) |
||
165 | { |
||
166 | Q[0] = M[0] * P[0] + M[4] * P[1] + M[8] * P[2] + M[12]; |
||
167 | Q[1] = M[1] * P[0] + M[5] * P[1] + M[9] * P[2] + M[13]; |
||
168 | Q[2] = M[2] * P[0] + M[6] * P[1] + M[10] * P[2] + M[14]; |
||
169 | Q[3] = M[3] * P[0] + M[7] * P[1] + M[11] * P[2] + M[15]; |
||
170 | } |
||
171 | else if (sz == 2) |
||
172 | { |
||
173 | Q[0] = M[0] * P[0] + M[4] * P[1] + M[12]; |
||
174 | Q[1] = M[1] * P[0] + M[5] * P[1] + M[13]; |
||
175 | Q[2] = M[2] * P[0] + M[6] * P[1] + M[14]; |
||
176 | Q[3] = M[3] * P[0] + M[7] * P[1] + M[15]; |
||
177 | } |
||
178 | else if (sz == 1) |
||
179 | { |
||
180 | Q[0] = M[0] * P[0] + M[12]; |
||
181 | Q[1] = M[1] * P[0] + M[13]; |
||
182 | Q[2] = M[2] * P[0] + M[14]; |
||
183 | Q[3] = M[3] * P[0] + M[15]; |
||
184 | } |
||
185 | } |
||
186 | |||
187 | |||
188 | /* |
||
189 | * This is called only once. It initializes several tables with pointers |
||
190 | * to optimized transformation functions. This is where we can test for |
||
191 | * AMD 3Dnow! capability, Intel Katmai, etc. and hook in the right code. |
||
192 | */ |
||
193 | void |
||
194 | _math_init_transformation( void ) |
||
195 | { |
||
196 | init_c_transformations(); |
||
197 | init_c_norm_transform(); |
||
198 | init_c_cliptest(); |
||
199 | init_copy0(); |
||
200 | init_dotprod(); |
||
201 | |||
202 | #ifdef DEBUG |
||
203 | _math_test_all_transform_functions( "default" ); |
||
204 | _math_test_all_normal_transform_functions( "default" ); |
||
205 | _math_test_all_cliptest_functions( "default" ); |
||
206 | #endif |
||
207 | |||
208 | #ifdef USE_X86_ASM |
||
209 | _mesa_init_all_x86_transform_asm(); |
||
210 | #endif |
||
211 | #ifdef USE_SPARC_ASM |
||
212 | _mesa_init_all_sparc_transform_asm(); |
||
213 | #endif |
||
214 | } |
||
215 | |||
216 | void |
||
217 | _math_init( void ) |
||
218 | { |
||
219 | _math_init_transformation(); |
||
220 | _math_init_translate(); |
||
221 | _math_init_eval(); |
||
222 | } |