Make binary - even though this is a text file, common practice is to store MS studio...
[mesa.git] / src / mesa / math / m_xform.h
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 3.5
5 *
6 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27
28
29
30 #ifndef _M_XFORM_H
31 #define _M_XFORM_H
32
33
34 #include "glheader.h"
35 #include "config.h"
36 #include "math/m_vector.h"
37 #include "math/m_matrix.h"
38
39 #ifdef USE_X86_ASM
40 #define _XFORMAPI _ASMAPI
41 #define _XFORMAPIP _ASMAPIP
42 #else
43 #define _XFORMAPI
44 #define _XFORMAPIP *
45 #endif
46
47 /*
48 * Transform a point (column vector) by a matrix: Q = M * P
49 */
50 #define TRANSFORM_POINT( Q, M, P ) \
51 Q[0] = M[0] * P[0] + M[4] * P[1] + M[8] * P[2] + M[12] * P[3]; \
52 Q[1] = M[1] * P[0] + M[5] * P[1] + M[9] * P[2] + M[13] * P[3]; \
53 Q[2] = M[2] * P[0] + M[6] * P[1] + M[10] * P[2] + M[14] * P[3]; \
54 Q[3] = M[3] * P[0] + M[7] * P[1] + M[11] * P[2] + M[15] * P[3];
55
56
57 #define TRANSFORM_POINT3( Q, M, P ) \
58 Q[0] = M[0] * P[0] + M[4] * P[1] + M[8] * P[2] + M[12]; \
59 Q[1] = M[1] * P[0] + M[5] * P[1] + M[9] * P[2] + M[13]; \
60 Q[2] = M[2] * P[0] + M[6] * P[1] + M[10] * P[2] + M[14]; \
61 Q[3] = M[3] * P[0] + M[7] * P[1] + M[11] * P[2] + M[15];
62
63
64 /*
65 * Transform a normal (row vector) by a matrix: [NX NY NZ] = N * MAT
66 */
67 #define TRANSFORM_NORMAL( TO, N, MAT ) \
68 do { \
69 TO[0] = N[0] * MAT[0] + N[1] * MAT[1] + N[2] * MAT[2]; \
70 TO[1] = N[0] * MAT[4] + N[1] * MAT[5] + N[2] * MAT[6]; \
71 TO[2] = N[0] * MAT[8] + N[1] * MAT[9] + N[2] * MAT[10]; \
72 } while (0)
73
74
75 extern void _mesa_transform_vector( GLfloat u[4],
76 CONST GLfloat v[4],
77 CONST GLfloat m[16] );
78
79
80 extern void
81 _math_init_transformation( void );
82
83
84 /* KW: Clip functions now do projective divide as well. The projected
85 * coordinates are very useful to us because they let us cull
86 * backfaces and eliminate vertices from lighting, fogging, etc
87 * calculations. Despite the fact that this divide could be done one
88 * day in hardware, we would still have a reason to want to do it here
89 * as long as those other calculations remain in software.
90 *
91 * Clipping is a convenient place to do the divide on x86 as it should be
92 * possible to overlap with integer outcode calculations.
93 *
94 * There are two cases where we wouldn't want to do the divide in cliptest:
95 * - When we aren't clipping. We still might want to cull backfaces
96 * so the divide should be done elsewhere. This currently never
97 * happens.
98 *
99 * - When culling isn't likely to help us, such as when the GL culling
100 * is disabled and we not lighting or are only lighting
101 * one-sided. In this situation, backface determination provides
102 * us with no useful information. A tricky case to detect is when
103 * all input data is already culled, although hopefully the
104 * application wouldn't turn on culling in such cases.
105 *
106 * We supply a buffer to hold the [x/w,y/w,z/w,1/w] values which
107 * are the result of the projection. This is only used in the
108 * 4-vector case - in other cases, we just use the clip coordinates
109 * as the projected coordinates - they are identical.
110 *
111 * This is doubly convenient because it means the Win[] array is now
112 * of the same stride as all the others, so I can now turn map_vertices
113 * into a straight-forward matrix transformation, with asm acceleration
114 * automatically available.
115 */
116
117 /* Vertex buffer clipping flags
118 */
119 #define CLIP_RIGHT_SHIFT 0
120 #define CLIP_LEFT_SHIFT 1
121 #define CLIP_TOP_SHIFT 2
122 #define CLIP_BOTTOM_SHIFT 3
123 #define CLIP_NEAR_SHIFT 4
124 #define CLIP_FAR_SHIFT 5
125
126 #define CLIP_RIGHT_BIT 0x01
127 #define CLIP_LEFT_BIT 0x02
128 #define CLIP_TOP_BIT 0x04
129 #define CLIP_BOTTOM_BIT 0x08
130 #define CLIP_NEAR_BIT 0x10
131 #define CLIP_FAR_BIT 0x20
132 #define CLIP_USER_BIT 0x40
133 #define CLIP_ALL_BITS 0x3f
134
135
136 typedef GLvector4f * (_XFORMAPIP clip_func)( GLvector4f *vClip,
137 GLvector4f *vProj,
138 GLubyte clipMask[],
139 GLubyte *orMask,
140 GLubyte *andMask );
141
142 typedef void (*dotprod_func)( GLfloat *out,
143 GLuint out_stride,
144 CONST GLvector4f *coord_vec,
145 CONST GLfloat plane[4] );
146
147 typedef void (*vec_copy_func)( GLvector4f *to,
148 CONST GLvector4f *from );
149
150
151
152 /*
153 * Functions for transformation of normals in the VB.
154 */
155 typedef void (_NORMAPIP normal_func)( CONST GLmatrix *mat,
156 GLfloat scale,
157 CONST GLvector4f *in,
158 CONST GLfloat lengths[],
159 GLvector4f *dest );
160
161
162 /* Flags for selecting a normal transformation function.
163 */
164 #define NORM_RESCALE 0x1 /* apply the scale factor */
165 #define NORM_NORMALIZE 0x2 /* normalize */
166 #define NORM_TRANSFORM 0x4 /* apply the transformation matrix */
167 #define NORM_TRANSFORM_NO_ROT 0x8 /* apply the transformation matrix */
168
169
170
171
172 /* KW: New versions of the transform function allow a mask array
173 * specifying that individual vector transform should be skipped
174 * when the mask byte is zero. This is always present as a
175 * parameter, to allow a unified interface.
176 */
177 typedef void (_XFORMAPIP transform_func)( GLvector4f *to_vec,
178 CONST GLfloat m[16],
179 CONST GLvector4f *from_vec );
180
181
182 extern GLvector4f *_mesa_project_points( GLvector4f *to,
183 CONST GLvector4f *from );
184
185 extern void _mesa_transform_bounds3( GLubyte *orMask, GLubyte *andMask,
186 CONST GLfloat m[16],
187 CONST GLfloat src[][3] );
188
189 extern void _mesa_transform_bounds2( GLubyte *orMask, GLubyte *andMask,
190 CONST GLfloat m[16],
191 CONST GLfloat src[][3] );
192
193
194 extern dotprod_func _mesa_dotprod_tab[5];
195 extern vec_copy_func _mesa_copy_tab[0x10];
196 extern vec_copy_func _mesa_copy_clean_tab[5];
197 extern clip_func _mesa_clip_tab[5];
198 extern clip_func _mesa_clip_np_tab[5];
199 extern normal_func _mesa_normal_tab[0xf];
200
201 /* Use of 2 layers of linked 1-dimensional arrays to reduce
202 * cost of lookup.
203 */
204 extern transform_func *_mesa_transform_tab[5];
205
206
207 extern void _mesa_transform_point_sz( GLfloat Q[4], CONST GLfloat M[16],
208 CONST GLfloat P[4], GLuint sz );
209
210
211 #define TransformRaw( to, mat, from ) \
212 ( _mesa_transform_tab[(from)->size][(mat)->type]( to, (mat)->m, from ), \
213 (to) )
214
215
216 #endif