Subversion Repositories shark

Rev

Rev 56 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
56 pj 1
/* $Id: m_xform.h,v 1.1 2003-02-28 11:48:05 pj Exp $ */
2
 
3
/*
4
 * Mesa 3-D graphics library
5
 * Version:  3.5
6
 *
7
 * Copyright (C) 1999-2001  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
 
148
typedef void (*vec_copy_func)( GLvector4f *to,
149
                               CONST GLvector4f *from );
150
 
151
 
152
 
153
/*
154
 * Functions for transformation of normals in the VB.
155
 */
156
typedef void (_NORMAPIP normal_func)( CONST GLmatrix *mat,
157
                                      GLfloat scale,
158
                                      CONST GLvector4f *in,
159
                                      CONST GLfloat lengths[],
160
                                      GLvector4f *dest );
161
 
162
 
163
/* Flags for selecting a normal transformation function.
164
 */
165
#define NORM_RESCALE   0x1              /* apply the scale factor */
166
#define NORM_NORMALIZE 0x2              /* normalize */
167
#define NORM_TRANSFORM 0x4              /* apply the transformation matrix */
168
#define NORM_TRANSFORM_NO_ROT 0x8       /* apply the transformation matrix */
169
 
170
 
171
 
172
 
173
/* KW: New versions of the transform function allow a mask array
174
 *     specifying that individual vector transform should be skipped
175
 *     when the mask byte is zero.  This is always present as a
176
 *     parameter, to allow a unified interface.
177
 */
178
typedef void (_XFORMAPIP transform_func)( GLvector4f *to_vec,
179
                                          CONST GLfloat m[16],
180
                                          CONST GLvector4f *from_vec );
181
 
182
 
183
extern GLvector4f *_mesa_project_points( GLvector4f *to,
184
                                         CONST GLvector4f *from );
185
 
186
extern void _mesa_transform_bounds3( GLubyte *orMask, GLubyte *andMask,
187
                                     CONST GLfloat m[16],
188
                                     CONST GLfloat src[][3] );
189
 
190
extern void _mesa_transform_bounds2( GLubyte *orMask, GLubyte *andMask,
191
                                     CONST GLfloat m[16],
192
                                     CONST GLfloat src[][3] );
193
 
194
 
195
extern dotprod_func  _mesa_dotprod_tab[5];
196
extern vec_copy_func _mesa_copy_tab[0x10];
197
extern vec_copy_func _mesa_copy_clean_tab[5];
198
extern clip_func     _mesa_clip_tab[5];
199
extern clip_func     _mesa_clip_np_tab[5];
200
extern normal_func   _mesa_normal_tab[0xf];
201
 
202
/* Use of 2 layers of linked 1-dimensional arrays to reduce
203
 * cost of lookup.
204
 */
205
extern transform_func *_mesa_transform_tab[5];
206
 
207
 
208
extern void _mesa_transform_point_sz( GLfloat Q[4], CONST GLfloat M[16],
209
                                      CONST GLfloat P[4], GLuint sz );
210
 
211
 
212
#define TransformRaw( to, mat, from ) \
213
   ( _mesa_transform_tab[(from)->size][(mat)->type]( to, (mat)->m, from ), \
214
     (to) )
215
 
216
 
217
#endif