mesa: Restore 78-column wrapping of license text in C-style comments.
[mesa.git] / src / mesa / math / m_clip_tmp.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.2
4 *
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 /*
27 * New (3.1) transformation code written by Keith Whitwell.
28 */
29
30
31 /* KW: a clever asm implementation would nestle integer versions
32 * of the outcode calculation underneath the division. Gcc won't
33 * do this, strangely enough, so I only do the divide in
34 * the case where the cliptest passes. This isn't essential,
35 * and an asm implementation needn't replicate that behaviour.
36 *
37 * \param clip_vec vector of incoming clip-space coords
38 * \param proj_vec vector of resultant NDC-space projected coords
39 * \param clipMask resulting array of clip flags
40 * \param orMask bitwise-OR of clipMask values
41 * \param andMask bitwise-AND of clipMask values
42 * \return proj_vec pointer
43 */
44 static GLvector4f * _XFORMAPI TAG(cliptest_points4)( GLvector4f *clip_vec,
45 GLvector4f *proj_vec,
46 GLubyte clipMask[],
47 GLubyte *orMask,
48 GLubyte *andMask,
49 GLboolean viewport_z_clip )
50 {
51 const GLuint stride = clip_vec->stride;
52 const GLfloat *from = (GLfloat *)clip_vec->start;
53 const GLuint count = clip_vec->count;
54 GLuint c = 0;
55 GLfloat (*vProj)[4] = (GLfloat (*)[4])proj_vec->start;
56 GLubyte tmpAndMask = *andMask;
57 GLubyte tmpOrMask = *orMask;
58 GLuint i;
59 STRIDE_LOOP {
60 const GLfloat cx = from[0];
61 const GLfloat cy = from[1];
62 const GLfloat cz = from[2];
63 const GLfloat cw = from[3];
64 #if defined(macintosh) || defined(__powerpc__)
65 /* on powerpc cliptest is 17% faster in this way. */
66 GLuint mask;
67 mask = (((cw < cx) << CLIP_RIGHT_SHIFT));
68 mask |= (((cw < -cx) << CLIP_LEFT_SHIFT));
69 mask |= (((cw < cy) << CLIP_TOP_SHIFT));
70 mask |= (((cw < -cy) << CLIP_BOTTOM_SHIFT));
71 if (viewport_z_clip) {
72 mask |= (((cw < cz) << CLIP_FAR_SHIFT));
73 mask |= (((cw < -cz) << CLIP_NEAR_SHIFT));
74 }
75 #else /* !defined(macintosh)) */
76 GLubyte mask = 0;
77 if (-cx + cw < 0) mask |= CLIP_RIGHT_BIT;
78 if ( cx + cw < 0) mask |= CLIP_LEFT_BIT;
79 if (-cy + cw < 0) mask |= CLIP_TOP_BIT;
80 if ( cy + cw < 0) mask |= CLIP_BOTTOM_BIT;
81 if (viewport_z_clip) {
82 if (-cz + cw < 0) mask |= CLIP_FAR_BIT;
83 if ( cz + cw < 0) mask |= CLIP_NEAR_BIT;
84 }
85 #endif /* defined(macintosh) */
86
87 clipMask[i] = mask;
88 if (mask) {
89 c++;
90 tmpAndMask &= mask;
91 tmpOrMask |= mask;
92 vProj[i][0] = 0;
93 vProj[i][1] = 0;
94 vProj[i][2] = 0;
95 vProj[i][3] = 1;
96 } else {
97 GLfloat oow = 1.0F / cw;
98 vProj[i][0] = cx * oow;
99 vProj[i][1] = cy * oow;
100 vProj[i][2] = cz * oow;
101 vProj[i][3] = oow;
102 }
103 }
104
105 *orMask = tmpOrMask;
106 *andMask = (GLubyte) (c < count ? 0 : tmpAndMask);
107
108 proj_vec->flags |= VEC_SIZE_4;
109 proj_vec->size = 4;
110 proj_vec->count = clip_vec->count;
111 return proj_vec;
112 }
113
114
115
116 /*
117 * \param clip_vec vector of incoming clip-space coords
118 * \param proj_vec vector of resultant NDC-space projected coords
119 * \param clipMask resulting array of clip flags
120 * \param orMask bitwise-OR of clipMask values
121 * \param andMask bitwise-AND of clipMask values
122 * \return clip_vec pointer
123 */
124 static GLvector4f * _XFORMAPI TAG(cliptest_np_points4)( GLvector4f *clip_vec,
125 GLvector4f *proj_vec,
126 GLubyte clipMask[],
127 GLubyte *orMask,
128 GLubyte *andMask,
129 GLboolean viewport_z_clip )
130 {
131 const GLuint stride = clip_vec->stride;
132 const GLuint count = clip_vec->count;
133 const GLfloat *from = (GLfloat *)clip_vec->start;
134 GLuint c = 0;
135 GLubyte tmpAndMask = *andMask;
136 GLubyte tmpOrMask = *orMask;
137 GLuint i;
138 (void) proj_vec;
139 STRIDE_LOOP {
140 const GLfloat cx = from[0];
141 const GLfloat cy = from[1];
142 const GLfloat cz = from[2];
143 const GLfloat cw = from[3];
144 #if defined(macintosh) || defined(__powerpc__)
145 /* on powerpc cliptest is 17% faster in this way. */
146 GLuint mask;
147 mask = (((cw < cx) << CLIP_RIGHT_SHIFT));
148 mask |= (((cw < -cx) << CLIP_LEFT_SHIFT));
149 mask |= (((cw < cy) << CLIP_TOP_SHIFT));
150 mask |= (((cw < -cy) << CLIP_BOTTOM_SHIFT));
151 if (viewport_z_clip) {
152 mask |= (((cw < cz) << CLIP_FAR_SHIFT));
153 mask |= (((cw < -cz) << CLIP_NEAR_SHIFT));
154 }
155 #else /* !defined(macintosh)) */
156 GLubyte mask = 0;
157 if (-cx + cw < 0) mask |= CLIP_RIGHT_BIT;
158 if ( cx + cw < 0) mask |= CLIP_LEFT_BIT;
159 if (-cy + cw < 0) mask |= CLIP_TOP_BIT;
160 if ( cy + cw < 0) mask |= CLIP_BOTTOM_BIT;
161 if (viewport_z_clip) {
162 if (-cz + cw < 0) mask |= CLIP_FAR_BIT;
163 if ( cz + cw < 0) mask |= CLIP_NEAR_BIT;
164 }
165 #endif /* defined(macintosh) */
166
167 clipMask[i] = mask;
168 if (mask) {
169 c++;
170 tmpAndMask &= mask;
171 tmpOrMask |= mask;
172 }
173 }
174
175 *orMask = tmpOrMask;
176 *andMask = (GLubyte) (c < count ? 0 : tmpAndMask);
177 return clip_vec;
178 }
179
180
181 static GLvector4f * _XFORMAPI TAG(cliptest_points3)( GLvector4f *clip_vec,
182 GLvector4f *proj_vec,
183 GLubyte clipMask[],
184 GLubyte *orMask,
185 GLubyte *andMask,
186 GLboolean viewport_z_clip )
187 {
188 const GLuint stride = clip_vec->stride;
189 const GLuint count = clip_vec->count;
190 const GLfloat *from = (GLfloat *)clip_vec->start;
191 GLubyte tmpOrMask = *orMask;
192 GLubyte tmpAndMask = *andMask;
193 GLuint i;
194 (void) proj_vec;
195 STRIDE_LOOP {
196 const GLfloat cx = from[0], cy = from[1], cz = from[2];
197 GLubyte mask = 0;
198 if (cx > 1.0) mask |= CLIP_RIGHT_BIT;
199 else if (cx < -1.0) mask |= CLIP_LEFT_BIT;
200 if (cy > 1.0) mask |= CLIP_TOP_BIT;
201 else if (cy < -1.0) mask |= CLIP_BOTTOM_BIT;
202 if (viewport_z_clip) {
203 if (cz > 1.0) mask |= CLIP_FAR_BIT;
204 else if (cz < -1.0) mask |= CLIP_NEAR_BIT;
205 }
206 clipMask[i] = mask;
207 tmpOrMask |= mask;
208 tmpAndMask &= mask;
209 }
210
211 *orMask = tmpOrMask;
212 *andMask = tmpAndMask;
213 return clip_vec;
214 }
215
216
217 static GLvector4f * _XFORMAPI TAG(cliptest_points2)( GLvector4f *clip_vec,
218 GLvector4f *proj_vec,
219 GLubyte clipMask[],
220 GLubyte *orMask,
221 GLubyte *andMask,
222 GLboolean viewport_z_clip )
223 {
224 const GLuint stride = clip_vec->stride;
225 const GLuint count = clip_vec->count;
226 const GLfloat *from = (GLfloat *)clip_vec->start;
227 GLubyte tmpOrMask = *orMask;
228 GLubyte tmpAndMask = *andMask;
229 GLuint i;
230 (void) proj_vec;
231 STRIDE_LOOP {
232 const GLfloat cx = from[0], cy = from[1];
233 GLubyte mask = 0;
234 if (cx > 1.0) mask |= CLIP_RIGHT_BIT;
235 else if (cx < -1.0) mask |= CLIP_LEFT_BIT;
236 if (cy > 1.0) mask |= CLIP_TOP_BIT;
237 else if (cy < -1.0) mask |= CLIP_BOTTOM_BIT;
238 clipMask[i] = mask;
239 tmpOrMask |= mask;
240 tmpAndMask &= mask;
241 }
242
243 *orMask = tmpOrMask;
244 *andMask = tmpAndMask;
245 return clip_vec;
246 }
247
248
249 void TAG(init_c_cliptest)( void )
250 {
251 _mesa_clip_tab[4] = TAG(cliptest_points4);
252 _mesa_clip_tab[3] = TAG(cliptest_points3);
253 _mesa_clip_tab[2] = TAG(cliptest_points2);
254
255 _mesa_clip_np_tab[4] = TAG(cliptest_np_points4);
256 _mesa_clip_np_tab[3] = TAG(cliptest_points3);
257 _mesa_clip_np_tab[2] = TAG(cliptest_points2);
258 }