1 /* $Id: m_norm_tmp.h,v 1.8 2001/06/28 17:34:14 keithw 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.
28 * New (3.1) transformation code written by Keith Whitwell.
32 #include "m_vertices.h"
35 TAG(transform_normalize_normals
)( const GLmatrix
*mat
,
38 const GLfloat
*lengths
,
42 const GLfloat
*from
= in
->start
;
43 GLuint stride
= in
->stride
;
44 GLuint count
= in
->count
;
45 GLfloat (*out
)[3] = (GLfloat (*)[3])dest
->start
;
46 GLfloat
*m
= mat
->inv
;
47 GLfloat m0
= m
[0], m4
= m
[4], m8
= m
[8];
48 GLfloat m1
= m
[1], m5
= m
[5], m9
= m
[9];
49 GLfloat m2
= m
[2], m6
= m
[6], m10
= m
[10];
55 const GLfloat ux
= from
[0], uy
= from
[1], uz
= from
[2];
56 tx
= ux
* m0
+ uy
* m1
+ uz
* m2
;
57 ty
= ux
* m4
+ uy
* m5
+ uz
* m6
;
58 tz
= ux
* m8
+ uy
* m9
+ uz
* m10
;
61 GLdouble len
= tx
*tx
+ ty
*ty
+ tz
*tz
;
63 GLdouble scale
= 1.0 / GL_SQRT(len
);
64 out
[i
][0] = (GLfloat
) (tx
* scale
);
65 out
[i
][1] = (GLfloat
) (ty
* scale
);
66 out
[i
][2] = (GLfloat
) (tz
* scale
);
70 out
[i
][0] = out
[i
][1] = out
[i
][2] = 0;
77 m0
*= scale
, m4
*= scale
, m8
*= scale
;
78 m1
*= scale
, m5
*= scale
, m9
*= scale
;
79 m2
*= scale
, m6
*= scale
, m10
*= scale
;
85 const GLfloat ux
= from
[0], uy
= from
[1], uz
= from
[2];
86 tx
= ux
* m0
+ uy
* m1
+ uz
* m2
;
87 ty
= ux
* m4
+ uy
* m5
+ uz
* m6
;
88 tz
= ux
* m8
+ uy
* m9
+ uz
* m10
;
91 GLfloat len
= lengths
[i
];
98 dest
->count
= in
->count
;
102 static void _XFORMAPI
103 TAG(transform_normalize_normals_no_rot
)( const GLmatrix
*mat
,
105 const GLvector3f
*in
,
106 const GLfloat
*lengths
,
110 const GLfloat
*from
= in
->start
;
111 GLuint stride
= in
->stride
;
112 GLuint count
= in
->count
;
113 GLfloat (*out
)[3] = (GLfloat (*)[3])dest
->start
;
114 GLfloat
*m
= mat
->inv
;
122 const GLfloat ux
= from
[0], uy
= from
[1], uz
= from
[2];
128 GLdouble len
= tx
*tx
+ ty
*ty
+ tz
*tz
;
130 GLdouble scale
= 1.0 / GL_SQRT(len
);
131 out
[i
][0] = (GLfloat
) (tx
* scale
);
132 out
[i
][1] = (GLfloat
) (ty
* scale
);
133 out
[i
][2] = (GLfloat
) (tz
* scale
);
137 out
[i
][0] = out
[i
][1] = out
[i
][2] = 0;
150 const GLfloat ux
= from
[0], uy
= from
[1], uz
= from
[2];
156 GLfloat len
= lengths
[i
];
157 out
[i
][0] = tx
* len
;
158 out
[i
][1] = ty
* len
;
159 out
[i
][2] = tz
* len
;
163 dest
->count
= in
->count
;
167 static void _XFORMAPI
168 TAG(transform_rescale_normals_no_rot
)( const GLmatrix
*mat
,
170 const GLvector3f
*in
,
171 const GLfloat
*lengths
,
175 const GLfloat
*from
= in
->start
;
176 GLuint stride
= in
->stride
;
177 GLuint count
= in
->count
;
178 GLfloat (*out
)[3] = (GLfloat (*)[3])dest
->start
;
179 const GLfloat
*m
= mat
->inv
;
180 GLfloat m0
= scale
*m
[0];
181 GLfloat m5
= scale
*m
[5];
182 GLfloat m10
= scale
*m
[10];
185 GLfloat ux
= from
[0], uy
= from
[1], uz
= from
[2];
188 out
[i
][2] = uz
* m10
;
190 dest
->count
= in
->count
;
193 static void _XFORMAPI
194 TAG(transform_rescale_normals
)( const GLmatrix
*mat
,
196 const GLvector3f
*in
,
197 const GLfloat
*lengths
,
201 const GLfloat
*from
= in
->start
;
202 GLuint stride
= in
->stride
;
203 GLuint count
= in
->count
;
204 GLfloat (*out
)[3] = (GLfloat (*)[3])dest
->start
;
205 /* Since we are unlikely to have < 3 vertices in the buffer,
206 * it makes sense to pre-multiply by scale.
208 const GLfloat
*m
= mat
->inv
;
209 GLfloat m0
= scale
*m
[0], m4
= scale
*m
[4], m8
= scale
*m
[8];
210 GLfloat m1
= scale
*m
[1], m5
= scale
*m
[5], m9
= scale
*m
[9];
211 GLfloat m2
= scale
*m
[2], m6
= scale
*m
[6], m10
= scale
*m
[10];
214 GLfloat ux
= from
[0], uy
= from
[1], uz
= from
[2];
215 out
[i
][0] = ux
* m0
+ uy
* m1
+ uz
* m2
;
216 out
[i
][1] = ux
* m4
+ uy
* m5
+ uz
* m6
;
217 out
[i
][2] = ux
* m8
+ uy
* m9
+ uz
* m10
;
219 dest
->count
= in
->count
;
223 static void _XFORMAPI
224 TAG(transform_normals_no_rot
)( const GLmatrix
*mat
,
226 const GLvector3f
*in
,
227 const GLfloat
*lengths
,
231 const GLfloat
*from
= in
->start
;
232 GLuint stride
= in
->stride
;
233 GLuint count
= in
->count
;
234 GLfloat (*out
)[3] = (GLfloat (*)[3])dest
->start
;
235 const GLfloat
*m
= mat
->inv
;
242 GLfloat ux
= from
[0], uy
= from
[1], uz
= from
[2];
245 out
[i
][2] = uz
* m10
;
247 dest
->count
= in
->count
;
251 static void _XFORMAPI
252 TAG(transform_normals
)( const GLmatrix
*mat
,
254 const GLvector3f
*in
,
255 const GLfloat
*lengths
,
259 const GLfloat
*from
= in
->start
;
260 GLuint stride
= in
->stride
;
261 GLuint count
= in
->count
;
262 GLfloat (*out
)[3] = (GLfloat (*)[3])dest
->start
;
263 const GLfloat
*m
= mat
->inv
;
264 GLfloat m0
= m
[0], m4
= m
[4], m8
= m
[8];
265 GLfloat m1
= m
[1], m5
= m
[5], m9
= m
[9];
266 GLfloat m2
= m
[2], m6
= m
[6], m10
= m
[10];
270 GLfloat ux
= from
[0], uy
= from
[1], uz
= from
[2];
271 out
[i
][0] = ux
* m0
+ uy
* m1
+ uz
* m2
;
272 out
[i
][1] = ux
* m4
+ uy
* m5
+ uz
* m6
;
273 out
[i
][2] = ux
* m8
+ uy
* m9
+ uz
* m10
;
275 dest
->count
= in
->count
;
279 static void _XFORMAPI
280 TAG(normalize_normals
)( const GLmatrix
*mat
,
282 const GLvector3f
*in
,
283 const GLfloat
*lengths
,
287 const GLfloat
*from
= in
->start
;
288 GLuint stride
= in
->stride
;
289 GLuint count
= in
->count
;
290 GLfloat (*out
)[3] = (GLfloat (*)[3])dest
->start
;
295 const GLfloat x
= from
[0], y
= from
[1], z
= from
[2];
296 GLfloat invlen
= lengths
[i
];
297 out
[i
][0] = x
* invlen
;
298 out
[i
][1] = y
* invlen
;
299 out
[i
][2] = z
* invlen
;
304 const GLfloat x
= from
[0], y
= from
[1], z
= from
[2];
305 GLdouble len
= x
* x
+ y
* y
+ z
* z
;
307 len
= 1.0 / GL_SQRT(len
);
308 out
[i
][0] = (GLfloat
) (x
* len
);
309 out
[i
][1] = (GLfloat
) (y
* len
);
310 out
[i
][2] = (GLfloat
) (z
* len
);
319 dest
->count
= in
->count
;
323 static void _XFORMAPI
324 TAG(rescale_normals
)( const GLmatrix
*mat
,
326 const GLvector3f
*in
,
327 const GLfloat
*lengths
,
331 const GLfloat
*from
= in
->start
;
332 GLuint stride
= in
->stride
;
333 GLuint count
= in
->count
;
334 GLfloat (*out
)[3] = (GLfloat (*)[3])dest
->start
;
338 SCALE_SCALAR_3V( out
[i
], scale
, from
);
340 dest
->count
= in
->count
;
344 static void _XFORMAPI
345 TAG(init_c_norm_transform
)( void )
347 _mesa_normal_tab
[NORM_TRANSFORM_NO_ROT
] =
348 TAG(transform_normals_no_rot
);
350 _mesa_normal_tab
[NORM_TRANSFORM_NO_ROT
| NORM_RESCALE
] =
351 TAG(transform_rescale_normals_no_rot
);
353 _mesa_normal_tab
[NORM_TRANSFORM_NO_ROT
| NORM_NORMALIZE
] =
354 TAG(transform_normalize_normals_no_rot
);
356 _mesa_normal_tab
[NORM_TRANSFORM
] =
357 TAG(transform_normals
);
359 _mesa_normal_tab
[NORM_TRANSFORM
| NORM_RESCALE
] =
360 TAG(transform_rescale_normals
);
362 _mesa_normal_tab
[NORM_TRANSFORM
| NORM_NORMALIZE
] =
363 TAG(transform_normalize_normals
);
365 _mesa_normal_tab
[NORM_RESCALE
] =
366 TAG(rescale_normals
);
368 _mesa_normal_tab
[NORM_NORMALIZE
] =
369 TAG(normalize_normals
);