Silence gcc 3.4 warnings on ReactOS. Mostly unused var warnings. (patch 1015696)
[mesa.git] / src / mesa / math / m_clip_tmp.h
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 5.1
5 *
6 * Copyright (C) 1999-2003 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 * 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 {
50 const GLuint stride = clip_vec->stride;
51 const GLfloat *from = (GLfloat *)clip_vec->start;
52 const GLuint count = clip_vec->count;
53 GLuint c = 0;
54 GLfloat (*vProj)[4] = (GLfloat (*)[4])proj_vec->start;
55 GLubyte tmpAndMask = *andMask;
56 GLubyte tmpOrMask = *orMask;
57 GLuint i;
58 STRIDE_LOOP {
59 const GLfloat cx = from[0];
60 const GLfloat cy = from[1];
61 const GLfloat cz = from[2];
62 const GLfloat cw = from[3];
63 #if defined(macintosh) || defined(__powerpc__)
64 /* on powerpc cliptest is 17% faster in this way. */
65 GLuint mask;
66 mask = (((cw < cx) << CLIP_RIGHT_SHIFT));
67 mask |= (((cw < -cx) << CLIP_LEFT_SHIFT));
68 mask |= (((cw < cy) << CLIP_TOP_SHIFT));
69 mask |= (((cw < -cy) << CLIP_BOTTOM_SHIFT));
70 mask |= (((cw < cz) << CLIP_FAR_SHIFT));
71 mask |= (((cw < -cz) << CLIP_NEAR_SHIFT));
72 #else /* !defined(macintosh)) */
73 GLubyte mask = 0;
74 if (-cx + cw < 0) mask |= CLIP_RIGHT_BIT;
75 if ( cx + cw < 0) mask |= CLIP_LEFT_BIT;
76 if (-cy + cw < 0) mask |= CLIP_TOP_BIT;
77 if ( cy + cw < 0) mask |= CLIP_BOTTOM_BIT;
78 if (-cz + cw < 0) mask |= CLIP_FAR_BIT;
79 if ( cz + cw < 0) mask |= CLIP_NEAR_BIT;
80 #endif /* defined(macintosh) */
81
82 clipMask[i] = mask;
83 if (mask) {
84 c++;
85 tmpAndMask &= mask;
86 tmpOrMask |= mask;
87 vProj[i][0] = 0;
88 vProj[i][1] = 0;
89 vProj[i][2] = 0;
90 vProj[i][3] = 1;
91 } else {
92 GLfloat oow = 1.0F / cw;
93 vProj[i][0] = cx * oow;
94 vProj[i][1] = cy * oow;
95 vProj[i][2] = cz * oow;
96 vProj[i][3] = oow;
97 }
98 }
99
100 *orMask = tmpOrMask;
101 *andMask = (GLubyte) (c < count ? 0 : tmpAndMask);
102
103 proj_vec->flags |= VEC_SIZE_4;
104 proj_vec->size = 4;
105 proj_vec->count = clip_vec->count;
106 return proj_vec;
107 }
108
109
110
111 /*
112 * \param clip_vec vector of incoming clip-space coords
113 * \param proj_vec vector of resultant NDC-space projected coords
114 * \param clipMask resulting array of clip flags
115 * \param orMask bitwise-OR of clipMask values
116 * \param andMask bitwise-AND of clipMask values
117 * \return clip_vec pointer
118 */
119 static GLvector4f * _XFORMAPI TAG(cliptest_np_points4)( GLvector4f *clip_vec,
120 GLvector4f *proj_vec,
121 GLubyte clipMask[],
122 GLubyte *orMask,
123 GLubyte *andMask )
124 {
125 const GLuint stride = clip_vec->stride;
126 const GLuint count = clip_vec->count;
127 const GLfloat *from = (GLfloat *)clip_vec->start;
128 GLuint c = 0;
129 GLubyte tmpAndMask = *andMask;
130 GLubyte tmpOrMask = *orMask;
131 GLuint i;
132 (void) proj_vec;
133 STRIDE_LOOP {
134 const GLfloat cx = from[0];
135 const GLfloat cy = from[1];
136 const GLfloat cz = from[2];
137 const GLfloat cw = from[3];
138 #if defined(macintosh) || defined(__powerpc__)
139 /* on powerpc cliptest is 17% faster in this way. */
140 GLuint mask;
141 mask = (((cw < cx) << CLIP_RIGHT_SHIFT));
142 mask |= (((cw < -cx) << CLIP_LEFT_SHIFT));
143 mask |= (((cw < cy) << CLIP_TOP_SHIFT));
144 mask |= (((cw < -cy) << CLIP_BOTTOM_SHIFT));
145 mask |= (((cw < cz) << CLIP_FAR_SHIFT));
146 mask |= (((cw < -cz) << CLIP_NEAR_SHIFT));
147 #else /* !defined(macintosh)) */
148 GLubyte mask = 0;
149 if (-cx + cw < 0) mask |= CLIP_RIGHT_BIT;
150 if ( cx + cw < 0) mask |= CLIP_LEFT_BIT;
151 if (-cy + cw < 0) mask |= CLIP_TOP_BIT;
152 if ( cy + cw < 0) mask |= CLIP_BOTTOM_BIT;
153 if (-cz + cw < 0) mask |= CLIP_FAR_BIT;
154 if ( cz + cw < 0) mask |= CLIP_NEAR_BIT;
155 #endif /* defined(macintosh) */
156
157 clipMask[i] = mask;
158 if (mask) {
159 c++;
160 tmpAndMask &= mask;
161 tmpOrMask |= mask;
162 }
163 }
164
165 *orMask = tmpOrMask;
166 *andMask = (GLubyte) (c < count ? 0 : tmpAndMask);
167 return clip_vec;
168 }
169
170
171 static GLvector4f * _XFORMAPI TAG(cliptest_points3)( GLvector4f *clip_vec,
172 GLvector4f *proj_vec,
173 GLubyte clipMask[],
174 GLubyte *orMask,
175 GLubyte *andMask )
176 {
177 const GLuint stride = clip_vec->stride;
178 const GLuint count = clip_vec->count;
179 const GLfloat *from = (GLfloat *)clip_vec->start;
180 (void) proj_vec;
181
182 GLubyte tmpOrMask = *orMask;
183 GLubyte tmpAndMask = *andMask;
184 GLuint i;
185 STRIDE_LOOP {
186 const GLfloat cx = from[0], cy = from[1], cz = from[2];
187 GLubyte mask = 0;
188 if (cx > 1.0) mask |= CLIP_RIGHT_BIT;
189 else if (cx < -1.0) mask |= CLIP_LEFT_BIT;
190 if (cy > 1.0) mask |= CLIP_TOP_BIT;
191 else if (cy < -1.0) mask |= CLIP_BOTTOM_BIT;
192 if (cz > 1.0) mask |= CLIP_FAR_BIT;
193 else if (cz < -1.0) mask |= CLIP_NEAR_BIT;
194 clipMask[i] = mask;
195 tmpOrMask |= mask;
196 tmpAndMask &= mask;
197 }
198
199 *orMask = tmpOrMask;
200 *andMask = tmpAndMask;
201 return clip_vec;
202 }
203
204
205 static GLvector4f * _XFORMAPI TAG(cliptest_points2)( GLvector4f *clip_vec,
206 GLvector4f *proj_vec,
207 GLubyte clipMask[],
208 GLubyte *orMask,
209 GLubyte *andMask )
210 {
211 const GLuint stride = clip_vec->stride;
212 const GLuint count = clip_vec->count;
213 const GLfloat *from = (GLfloat *)clip_vec->start;
214 (void) proj_vec;
215
216 GLubyte tmpOrMask = *orMask;
217 GLubyte tmpAndMask = *andMask;
218 GLuint i;
219 STRIDE_LOOP {
220 const GLfloat cx = from[0], cy = from[1];
221 GLubyte mask = 0;
222 if (cx > 1.0) mask |= CLIP_RIGHT_BIT;
223 else if (cx < -1.0) mask |= CLIP_LEFT_BIT;
224 if (cy > 1.0) mask |= CLIP_TOP_BIT;
225 else if (cy < -1.0) mask |= CLIP_BOTTOM_BIT;
226 clipMask[i] = mask;
227 tmpOrMask |= mask;
228 tmpAndMask &= mask;
229 }
230
231 *orMask = tmpOrMask;
232 *andMask = tmpAndMask;
233 return clip_vec;
234 }
235
236
237 static void TAG(init_c_cliptest)( void )
238 {
239 _mesa_clip_tab[4] = TAG(cliptest_points4);
240 _mesa_clip_tab[3] = TAG(cliptest_points3);
241 _mesa_clip_tab[2] = TAG(cliptest_points2);
242
243 _mesa_clip_np_tab[4] = TAG(cliptest_np_points4);
244 _mesa_clip_np_tab[3] = TAG(cliptest_points3);
245 _mesa_clip_np_tab[2] = TAG(cliptest_points2);
246 }