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