more namespace clean-ups
[mesa.git] / src / mesa / math / m_xform.h
1 /* $Id: m_xform.h,v 1.7 2001/03/03 20:57:00 brianp 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
29
30
31 #ifndef _M_XFORM_H
32 #define _M_XFORM_H
33
34
35 #include "glheader.h"
36 #include "config.h"
37 #include "math/m_vector.h"
38 #include "math/m_matrix.h"
39
40 #ifdef USE_X86_ASM
41 #define _XFORMAPI _ASMAPI
42 #define _XFORMAPIP _ASMAPIP
43 #else
44 #define _XFORMAPI
45 #define _XFORMAPIP *
46 #endif
47
48 /*
49 * Transform a point (column vector) by a matrix: Q = M * P
50 */
51 #define TRANSFORM_POINT( Q, M, P ) \
52 Q[0] = M[0] * P[0] + M[4] * P[1] + M[8] * P[2] + M[12] * P[3]; \
53 Q[1] = M[1] * P[0] + M[5] * P[1] + M[9] * P[2] + M[13] * P[3]; \
54 Q[2] = M[2] * P[0] + M[6] * P[1] + M[10] * P[2] + M[14] * P[3]; \
55 Q[3] = M[3] * P[0] + M[7] * P[1] + M[11] * P[2] + M[15] * P[3];
56
57
58 #define TRANSFORM_POINT3( Q, M, P ) \
59 Q[0] = M[0] * P[0] + M[4] * P[1] + M[8] * P[2] + M[12]; \
60 Q[1] = M[1] * P[0] + M[5] * P[1] + M[9] * P[2] + M[13]; \
61 Q[2] = M[2] * P[0] + M[6] * P[1] + M[10] * P[2] + M[14]; \
62 Q[3] = M[3] * P[0] + M[7] * P[1] + M[11] * P[2] + M[15];
63
64
65 /*
66 * Transform a normal (row vector) by a matrix: [NX NY NZ] = N * MAT
67 */
68 #define TRANSFORM_NORMAL( TO, N, MAT ) \
69 do { \
70 TO[0] = N[0] * MAT[0] + N[1] * MAT[1] + N[2] * MAT[2]; \
71 TO[1] = N[0] * MAT[4] + N[1] * MAT[5] + N[2] * MAT[6]; \
72 TO[2] = N[0] * MAT[8] + N[1] * MAT[9] + N[2] * MAT[10]; \
73 } while (0)
74
75
76 extern void _mesa_transform_vector( GLfloat u[4],
77 CONST GLfloat v[4],
78 CONST GLfloat m[16] );
79
80
81 extern void
82 _math_init_transformation( void );
83
84
85 /* KW: Clip functions now do projective divide as well. The projected
86 * coordinates are very useful to us because they let us cull
87 * backfaces and eliminate vertices from lighting, fogging, etc
88 * calculations. Despite the fact that this divide could be done one
89 * day in hardware, we would still have a reason to want to do it here
90 * as long as those other calculations remain in software.
91 *
92 * Clipping is a convenient place to do the divide on x86 as it should be
93 * possible to overlap with integer outcode calculations.
94 *
95 * There are two cases where we wouldn't want to do the divide in cliptest:
96 * - When we aren't clipping. We still might want to cull backfaces
97 * so the divide should be done elsewhere. This currently never
98 * happens.
99 *
100 * - When culling isn't likely to help us, such as when the GL culling
101 * is disabled and we not lighting or are only lighting
102 * one-sided. In this situation, backface determination provides
103 * us with no useful information. A tricky case to detect is when
104 * all input data is already culled, although hopefully the
105 * application wouldn't turn on culling in such cases.
106 *
107 * We supply a buffer to hold the [x/w,y/w,z/w,1/w] values which
108 * are the result of the projection. This is only used in the
109 * 4-vector case - in other cases, we just use the clip coordinates
110 * as the projected coordinates - they are identical.
111 *
112 * This is doubly convenient because it means the Win[] array is now
113 * of the same stride as all the others, so I can now turn map_vertices
114 * into a straight-forward matrix transformation, with asm acceleration
115 * automatically available.
116 */
117
118 /* Vertex buffer clipping flags
119 */
120 #define CLIP_RIGHT_SHIFT 0
121 #define CLIP_LEFT_SHIFT 1
122 #define CLIP_TOP_SHIFT 2
123 #define CLIP_BOTTOM_SHIFT 3
124 #define CLIP_NEAR_SHIFT 4
125 #define CLIP_FAR_SHIFT 5
126
127 #define CLIP_RIGHT_BIT 0x01
128 #define CLIP_LEFT_BIT 0x02
129 #define CLIP_TOP_BIT 0x04
130 #define CLIP_BOTTOM_BIT 0x08
131 #define CLIP_NEAR_BIT 0x10
132 #define CLIP_FAR_BIT 0x20
133 #define CLIP_USER_BIT 0x40
134 #define CLIP_ALL_BITS 0x3f
135
136
137 typedef GLvector4f * (_XFORMAPIP clip_func)( GLvector4f *vClip,
138 GLvector4f *vProj,
139 GLubyte clipMask[],
140 GLubyte *orMask,
141 GLubyte *andMask );
142
143 typedef void (*dotprod_func)( GLfloat *out,
144 GLuint out_stride,
145 CONST GLvector4f *coord_vec,
146 CONST GLfloat plane[4],
147 CONST GLubyte mask[]);
148
149 typedef void (*vec_copy_func)( GLvector4f *to,
150 CONST GLvector4f *from,
151 CONST GLubyte mask[]);
152
153
154
155 /*
156 * Functions for transformation of normals in the VB.
157 */
158 typedef void (_NORMAPIP normal_func)( CONST GLmatrix *mat,
159 GLfloat scale,
160 CONST GLvector3f *in,
161 CONST GLfloat lengths[],
162 CONST GLubyte mask[],
163 GLvector3f *dest );
164
165
166 /* Flags for selecting a normal transformation function.
167 */
168 #define NORM_RESCALE 0x1 /* apply the scale factor */
169 #define NORM_NORMALIZE 0x2 /* normalize */
170 #define NORM_TRANSFORM 0x4 /* apply the transformation matrix */
171 #define NORM_TRANSFORM_NO_ROT 0x8 /* apply the transformation matrix */
172
173
174
175
176 /* KW: New versions of the transform function allow a mask array
177 * specifying that individual vector transform should be skipped
178 * when the mask byte is zero. This is always present as a
179 * parameter, to allow a unified interface.
180 */
181 typedef void (_XFORMAPIP transform_func)( GLvector4f *to_vec,
182 CONST GLfloat m[16],
183 CONST GLvector4f *from_vec,
184 CONST GLubyte *clipmask,
185 CONST GLubyte flag );
186
187
188 extern GLvector4f *_mesa_project_points( GLvector4f *to,
189 CONST GLvector4f *from );
190
191 extern void _mesa_transform_bounds3( GLubyte *orMask, GLubyte *andMask,
192 CONST GLfloat m[16],
193 CONST GLfloat src[][3] );
194
195 extern void _mesa_transform_bounds2( GLubyte *orMask, GLubyte *andMask,
196 CONST GLfloat m[16],
197 CONST GLfloat src[][3] );
198
199
200 extern dotprod_func _mesa_dotprod_tab[2][5];
201 extern vec_copy_func _mesa_copy_tab[2][0x10];
202 extern vec_copy_func _mesa_copy_clean_tab[2][5];
203 extern clip_func _mesa_clip_tab[5];
204 extern clip_func _mesa_clip_np_tab[5];
205 extern normal_func _mesa_normal_tab[0xf][0x4];
206
207 /* Use of 3 layers of linked 1-dimensional arrays to reduce
208 * cost of lookup.
209 */
210 extern transform_func **(_mesa_transform_tab[2]);
211
212
213 extern void _mesa_transform_point_sz( GLfloat Q[4], CONST GLfloat M[16],
214 CONST GLfloat P[4], GLuint sz );
215
216
217 #define TransformRaw( to, mat, from ) \
218 ( (*_mesa_transform_tab[0][(from)->size][(mat)->type])( to, (mat)->m, from, 0, 0 ), \
219 (to) )
220
221
222 #endif