1 /* $Id: m_norm_tmp.h,v 1.5 2001/03/12 00:48:41 gareth 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
,
43 const GLfloat
*from
= in
->start
;
44 GLuint stride
= in
->stride
;
45 GLuint count
= in
->count
;
46 GLfloat (*out
)[3] = (GLfloat (*)[3])dest
->start
;
47 GLfloat
*m
= mat
->inv
;
48 GLfloat m0
= m
[0], m4
= m
[4], m8
= m
[8];
49 GLfloat m1
= m
[1], m5
= m
[5], m9
= m
[9];
50 GLfloat m2
= m
[2], m6
= m
[6], m10
= m
[10];
58 const GLfloat ux
= from
[0], uy
= from
[1], uz
= from
[2];
59 tx
= ux
* m0
+ uy
* m1
+ uz
* m2
;
60 ty
= ux
* m4
+ uy
* m5
+ uz
* m6
;
61 tz
= ux
* m8
+ uy
* m9
+ uz
* m10
;
64 GLdouble len
= tx
*tx
+ ty
*ty
+ tz
*tz
;
66 GLdouble scale
= 1.0 / GL_SQRT(len
);
67 out
[i
][0] = (GLfloat
) (tx
* scale
);
68 out
[i
][1] = (GLfloat
) (ty
* scale
);
69 out
[i
][2] = (GLfloat
) (tz
* scale
);
73 out
[i
][0] = out
[i
][1] = out
[i
][2] = 0;
81 m0
*= scale
, m4
*= scale
, m8
*= scale
;
82 m1
*= scale
, m5
*= scale
, m9
*= scale
;
83 m2
*= scale
, m6
*= scale
, m10
*= scale
;
90 const GLfloat ux
= from
[0], uy
= from
[1], uz
= from
[2];
91 tx
= ux
* m0
+ uy
* m1
+ uz
* m2
;
92 ty
= ux
* m4
+ uy
* m5
+ uz
* m6
;
93 tz
= ux
* m8
+ uy
* m9
+ uz
* m10
;
96 GLfloat len
= lengths
[i
];
104 dest
->count
= in
->count
;
108 static void _XFORMAPI
109 TAG(transform_normalize_normals_no_rot
)( const GLmatrix
*mat
,
111 const GLvector3f
*in
,
112 const GLfloat
*lengths
,
113 const GLubyte mask
[],
117 const GLfloat
*from
= in
->start
;
118 GLuint stride
= in
->stride
;
119 GLuint count
= in
->count
;
120 GLfloat (*out
)[3] = (GLfloat (*)[3])dest
->start
;
121 GLfloat
*m
= mat
->inv
;
131 const GLfloat ux
= from
[0], uy
= from
[1], uz
= from
[2];
137 GLdouble len
= tx
*tx
+ ty
*ty
+ tz
*tz
;
139 GLdouble scale
= 1.0 / GL_SQRT(len
);
140 out
[i
][0] = (GLfloat
) (tx
* scale
);
141 out
[i
][1] = (GLfloat
) (ty
* scale
);
142 out
[i
][2] = (GLfloat
) (tz
* scale
);
146 out
[i
][0] = out
[i
][1] = out
[i
][2] = 0;
153 /* scale has been snapped to 1.0 if it is close.
165 const GLfloat ux
= from
[0], uy
= from
[1], uz
= from
[2];
171 GLfloat len
= lengths
[i
];
172 out
[i
][0] = tx
* len
;
173 out
[i
][1] = ty
* len
;
174 out
[i
][2] = tz
* len
;
179 dest
->count
= in
->count
;
183 static void _XFORMAPI
184 TAG(transform_rescale_normals_no_rot
)( const GLmatrix
*mat
,
186 const GLvector3f
*in
,
187 const GLfloat
*lengths
,
188 const GLubyte mask
[],
192 const GLfloat
*from
= in
->start
;
193 GLuint stride
= in
->stride
;
194 GLuint count
= in
->count
;
195 GLfloat (*out
)[3] = (GLfloat (*)[3])dest
->start
;
196 const GLfloat
*m
= mat
->inv
;
197 GLfloat m0
= scale
*m
[0];
198 GLfloat m5
= scale
*m
[5];
199 GLfloat m10
= scale
*m
[10];
204 GLfloat ux
= from
[0], uy
= from
[1], uz
= from
[2];
207 out
[i
][2] = uz
* m10
;
210 dest
->count
= in
->count
;
213 static void _XFORMAPI
214 TAG(transform_rescale_normals
)( const GLmatrix
*mat
,
216 const GLvector3f
*in
,
217 const GLfloat
*lengths
,
218 const GLubyte mask
[],
222 const GLfloat
*from
= in
->start
;
223 GLuint stride
= in
->stride
;
224 GLuint count
= in
->count
;
225 GLfloat (*out
)[3] = (GLfloat (*)[3])dest
->start
;
226 /* Since we are unlikely to have < 3 vertices in the buffer,
227 * it makes sense to pre-multiply by scale.
229 const GLfloat
*m
= mat
->inv
;
230 GLfloat m0
= scale
*m
[0], m4
= scale
*m
[4], m8
= scale
*m
[8];
231 GLfloat m1
= scale
*m
[1], m5
= scale
*m
[5], m9
= scale
*m
[9];
232 GLfloat m2
= scale
*m
[2], m6
= scale
*m
[6], m10
= scale
*m
[10];
237 GLfloat ux
= from
[0], uy
= from
[1], uz
= from
[2];
238 out
[i
][0] = ux
* m0
+ uy
* m1
+ uz
* m2
;
239 out
[i
][1] = ux
* m4
+ uy
* m5
+ uz
* m6
;
240 out
[i
][2] = ux
* m8
+ uy
* m9
+ uz
* m10
;
243 dest
->count
= in
->count
;
247 static void _XFORMAPI
248 TAG(transform_normals_no_rot
)(const GLmatrix
*mat
,
250 const GLvector3f
*in
,
251 const GLfloat
*lengths
,
252 const GLubyte mask
[],
256 const GLfloat
*from
= in
->start
;
257 GLuint stride
= in
->stride
;
258 GLuint count
= in
->count
;
259 GLfloat (*out
)[3] = (GLfloat (*)[3])dest
->start
;
260 const GLfloat
*m
= mat
->inv
;
269 GLfloat ux
= from
[0], uy
= from
[1], uz
= from
[2];
272 out
[i
][2] = uz
* m10
;
275 dest
->count
= in
->count
;
279 static void _XFORMAPI
280 TAG(transform_normals
)( const GLmatrix
*mat
,
282 const GLvector3f
*in
,
283 const GLfloat
*lengths
,
284 const GLubyte mask
[],
288 const GLfloat
*from
= in
->start
;
289 GLuint stride
= in
->stride
;
290 GLuint count
= in
->count
;
291 GLfloat (*out
)[3] = (GLfloat (*)[3])dest
->start
;
292 const GLfloat
*m
= mat
->inv
;
293 GLfloat m0
= m
[0], m4
= m
[4], m8
= m
[8];
294 GLfloat m1
= m
[1], m5
= m
[5], m9
= m
[9];
295 GLfloat m2
= m
[2], m6
= m
[6], m10
= m
[10];
301 GLfloat ux
= from
[0], uy
= from
[1], uz
= from
[2];
302 out
[i
][0] = ux
* m0
+ uy
* m1
+ uz
* m2
;
303 out
[i
][1] = ux
* m4
+ uy
* m5
+ uz
* m6
;
304 out
[i
][2] = ux
* m8
+ uy
* m9
+ uz
* m10
;
307 dest
->count
= in
->count
;
311 static void _XFORMAPI
312 TAG(normalize_normals
)( const GLmatrix
*mat
,
314 const GLvector3f
*in
,
315 const GLfloat
*lengths
,
316 const GLubyte mask
[],
320 const GLfloat
*from
= in
->start
;
321 GLuint stride
= in
->stride
;
322 GLuint count
= in
->count
;
323 GLfloat (*out
)[3] = (GLfloat (*)[3])dest
->start
;
330 const GLfloat x
= from
[0], y
= from
[1], z
= from
[2];
331 GLfloat invlen
= lengths
[i
];
332 out
[i
][0] = x
* invlen
;
333 out
[i
][1] = y
* invlen
;
334 out
[i
][2] = z
* invlen
;
341 const GLfloat x
= from
[0], y
= from
[1], z
= from
[2];
342 GLdouble len
= x
* x
+ y
* y
+ z
* z
;
344 len
= 1.0 / GL_SQRT(len
);
345 out
[i
][0] = (GLfloat
) (x
* len
);
346 out
[i
][1] = (GLfloat
) (y
* len
);
347 out
[i
][2] = (GLfloat
) (z
* len
);
357 dest
->count
= in
->count
;
361 static void _XFORMAPI
362 TAG(rescale_normals
)( const GLmatrix
*mat
,
364 const GLvector3f
*in
,
365 const GLfloat
*lengths
,
366 const GLubyte mask
[],
370 const GLfloat
*from
= in
->start
;
371 GLuint stride
= in
->stride
;
372 GLuint count
= in
->count
;
373 GLfloat (*out
)[3] = (GLfloat (*)[3])dest
->start
;
380 SCALE_SCALAR_3V( out
[i
], scale
, from
);
383 dest
->count
= in
->count
;
387 static void _XFORMAPI
388 TAG(init_c_norm_transform
)( void )
390 _mesa_normal_tab
[NORM_TRANSFORM_NO_ROT
][IDX
] =
391 TAG(transform_normals_no_rot
);
393 _mesa_normal_tab
[NORM_TRANSFORM_NO_ROT
| NORM_RESCALE
][IDX
] =
394 TAG(transform_rescale_normals_no_rot
);
396 _mesa_normal_tab
[NORM_TRANSFORM_NO_ROT
| NORM_NORMALIZE
][IDX
] =
397 TAG(transform_normalize_normals_no_rot
);
399 _mesa_normal_tab
[NORM_TRANSFORM
][IDX
] =
400 TAG(transform_normals
);
402 _mesa_normal_tab
[NORM_TRANSFORM
| NORM_RESCALE
][IDX
] =
403 TAG(transform_rescale_normals
);
405 _mesa_normal_tab
[NORM_TRANSFORM
| NORM_NORMALIZE
][IDX
] =
406 TAG(transform_normalize_normals
);
408 _mesa_normal_tab
[NORM_RESCALE
][IDX
] =
409 TAG(rescale_normals
);
411 _mesa_normal_tab
[NORM_NORMALIZE
][IDX
] =
412 TAG(normalize_normals
);