source: trunk/src/opengl/mesa/xform.c

Last change on this file was 3598, checked in by jeroen, 25 years ago

* empty log message *

File size: 7.6 KB
Line 
1/* $Id: xform.c,v 1.3 2000-05-23 20:41:07 jeroen Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version: 3.3
6 *
7 * Copyright (C) 1999 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/* $XFree86: xc/lib/GL/mesa/src/xform.c,v 1.4 1999/04/04 00:20:36 dawes Exp $ */
29
30/*
31 * Matrix/vertex/vector transformation stuff
32 *
33 *
34 * NOTES:
35 * 1. 4x4 transformation matrices are stored in memory in column major order.
36 * 2. Points/vertices are to be thought of as column vectors.
37 * 3. Transformation of a point p by a matrix M is: p' = M * p
38 */
39
40
41#ifdef PC_HEADER
42#include "all.h"
43#else
44#include "glheader.h"
45#include "vb.h"
46#include "types.h"
47#include "context.h"
48#include "mmath.h"
49#include "vb.h"
50#include "xform.h"
51#endif
52
53#ifdef DEBUG_XFORM
54#include "debug_xform.h"
55#endif
56
57#ifdef USE_X86_ASM
58#include "common_x86asm.h"
59#endif
60
61clip_func gl_clip_tab[5];
62dotprod_func gl_dotprod_tab[2][5];
63vec_copy_func gl_copy_tab[2][0x10];
64normal_func gl_normal_tab[0xf][0x4];
65transform_func **(gl_transform_tab[2]);
66static transform_func *cull_transform_tab[5];
67static transform_func *raw_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#define TAG(x) x##_raw
78#define TAG2(x,y) x##y##_raw
79#define IDX 0
80#define STRIDE_LOOP for (i=0;i<count;i++, STRIDE_F(from, stride))
81#define LOOP for (i=0;i<n;i++)
82#define CULL_CHECK
83#define CLIP_CHECK
84#define ARGS
85#include "xform_tmp.h"
86#include "clip_tmp.h"
87#include "norm_tmp.h"
88#include "dotprod_tmp.h"
89#include "copy_tmp.h"
90#undef TAG
91#undef TAG2
92#undef LOOP
93#undef CULL_CHECK
94#undef CLIP_CHECK
95#undef ARGS
96#undef IDX
97
98/* Culled data used for:
99 * - texture transformations
100 * - viewport map transformation
101 * - normal transformations prior to lighting
102 * - user cliptests
103 */
104#define TAG(x) x##_masked
105#define TAG2(x,y) x##y##_masked
106#define IDX CULL_MASK_ACTIVE
107#define STRIDE_LOOP for (i=0;i<count;i++, STRIDE_F(from, stride))
108#define LOOP for (i=0;i<n;i++)
109#define CULL_CHECK if (mask[i])
110#define CLIP_CHECK if ((mask[i] & flag) == 0)
111#define ARGS , const GLubyte mask[]
112#include "xform_tmp.h"
113#include "norm_tmp.h"
114#include "dotprod_tmp.h"
115#include "copy_tmp.h"
116#undef TAG
117#undef TAG2
118#undef LOOP
119#undef CULL_CHECK
120#undef CLIP_CHECK
121#undef ARGS
122#undef IDX
123
124
125
126
127#if 0
128
129#define TAG(x) x##_raw_compacted
130#define TAG2(x,y) x##y##_raw_compacted
131#define IDX COMPACTED_NORMALS
132#define STRIDE_LOOP for (i=0;i<count;i++, STRIDE_F(from, stride))
133#define LOOP for (i=0;i<n;i++)
134#define CHECK if (flag[i] & VERT_NORM)
135#define ARGS
136#include "norm_tmp.h"
137#undef TAG
138#undef TAG2
139#undef LOOP
140#undef CHECK
141#undef ARGS
142#undef IDX
143
144
145#define TAG(x) x##_masked
146#define TAG2(x,y) x##y##_masked
147#define IDX CULL_MASK_ACTIVE|COMPACTED_NORMALS
148#define DUPLICATE_FUNCTIONS
149#include "norm_tmp.h"
150#undef TAG
151#undef TAG2
152#undef LOOP
153#undef CHECK
154#undef ARGS
155#undef IDX
156
157#endif
158
159
160GLvector4f *gl_project_points( GLvector4f *proj_vec,
161 const GLvector4f *clip_vec )
162{
163 const GLuint stride = clip_vec->stride;
164 const GLfloat *from = (GLfloat *)clip_vec->start;
165 const GLuint count = clip_vec->count;
166 GLfloat (*vProj)[4] = (GLfloat (*)[4])proj_vec->start;
167 GLuint i;
168
169 for (i = 0 ; i < count ; i++, STRIDE_F(from, stride))
170 {
171 GLfloat oow = 1.0F / from[3];
172 vProj[i][3] = oow;
173 vProj[i][0] = from[0] * oow;
174 vProj[i][1] = from[1] * oow;
175 vProj[i][2] = from[2] * oow;
176 }
177
178 proj_vec->flags |= VEC_SIZE_4;
179 proj_vec->size = 3;
180 proj_vec->count = clip_vec->count;
181 return proj_vec;
182}
183
184
185
186/*
187 * This is called only once. It initializes several tables with pointers
188 * to optimized transformation functions. This is where we can test for
189 * AMD 3Dnow! capability, Intel Katmai, etc. and hook in the right code.
190 */
191void gl_init_transformation( void )
192{
193 gl_transform_tab[0] = raw_transform_tab;
194 gl_transform_tab[1] = cull_transform_tab;
195
196 init_c_transformations_raw();
197 init_c_transformations_masked();
198 init_c_norm_transform_raw();
199 init_c_norm_transform_masked();
200 init_c_cliptest_raw();
201 init_copy0_raw();
202 init_copy0_masked();
203 init_dotprod_raw();
204 init_dotprod_masked();
205
206#ifdef DEBUG_XFORM
207 gl_test_all_transform_functions ("default");
208 gl_test_all_normal_transform_functions ("default");
209#endif
210
211#ifdef USE_X86_ASM
212 gl_init_all_x86_asm ();
213#endif
214}
215
216
217
218/*
219 * Transform a 4-element row vector (1x4 matrix) by a 4x4 matrix. This
220 * function is used for transforming clipping plane equations and spotlight
221 * directions.
222 * Mathematically, u = v * m.
223 * Input: v - input vector
224 * m - transformation matrix
225 * Output: u - transformed vector
226 */
227void gl_transform_vector( GLfloat u[4], const GLfloat v[4], const GLfloat m[16] )
228{
229 GLfloat v0=v[0], v1=v[1], v2=v[2], v3=v[3];
230#define M(row,col) m[row + col*4]
231 u[0] = v0 * M(0,0) + v1 * M(1,0) + v2 * M(2,0) + v3 * M(3,0);
232 u[1] = v0 * M(0,1) + v1 * M(1,1) + v2 * M(2,1) + v3 * M(3,1);
233 u[2] = v0 * M(0,2) + v1 * M(1,2) + v2 * M(2,2) + v3 * M(3,2);
234 u[3] = v0 * M(0,3) + v1 * M(1,3) + v2 * M(2,3) + v3 * M(3,3);
235#undef M
236}
237
238
239/* Useful for one-off point transformations, as in clipping.
240 * Note that because the matrix isn't analyzed we do too many
241 * multiplies, and that the result is always 4-clean.
242 */
243void gl_transform_point_sz( GLfloat Q[4], const GLfloat M[16],
244 const GLfloat P[4], GLuint sz )
245{
246 if (Q == P)
247 return;
248
249 if (sz == 4)
250 {
251 Q[0] = M[0] * P[0] + M[4] * P[1] + M[8] * P[2] + M[12] * P[3];
252 Q[1] = M[1] * P[0] + M[5] * P[1] + M[9] * P[2] + M[13] * P[3];
253 Q[2] = M[2] * P[0] + M[6] * P[1] + M[10] * P[2] + M[14] * P[3];
254 Q[3] = M[3] * P[0] + M[7] * P[1] + M[11] * P[2] + M[15] * P[3];
255 }
256 else if (sz == 3)
257 {
258 Q[0] = M[0] * P[0] + M[4] * P[1] + M[8] * P[2] + M[12];
259 Q[1] = M[1] * P[0] + M[5] * P[1] + M[9] * P[2] + M[13];
260 Q[2] = M[2] * P[0] + M[6] * P[1] + M[10] * P[2] + M[14];
261 Q[3] = M[3] * P[0] + M[7] * P[1] + M[11] * P[2] + M[15];
262 }
263 else if (sz == 2)
264 {
265 Q[0] = M[0] * P[0] + M[4] * P[1] + M[12];
266 Q[1] = M[1] * P[0] + M[5] * P[1] + M[13];
267 Q[2] = M[2] * P[0] + M[6] * P[1] + M[14];
268 Q[3] = M[3] * P[0] + M[7] * P[1] + M[15];
269 }
270 else if (sz == 1)
271 {
272 Q[0] = M[0] * P[0] + M[12];
273 Q[1] = M[1] * P[0] + M[13];
274 Q[2] = M[2] * P[0] + M[14];
275 Q[3] = M[3] * P[0] + M[15];
276 }
277}
Note: See TracBrowser for help on using the repository browser.