1 /* $Id: m_clip_tmp.h,v 1.5 2001/03/03 20:57:00 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
28 * New (3.1) transformation code written by Keith Whitwell.
32 /* KW: a clever asm implementation would nestle integer versions
33 * of the outcode calculation underneath the division. Gcc won't
34 * do this, strangely enough, so I only do the divide in
35 * the case where the cliptest passes. This isn't essential,
36 * and an asm implementation needn't replicate that behaviour.
38 static GLvector4f
* _XFORMAPI
TAG(cliptest_points4
)( GLvector4f
*clip_vec
,
44 const GLuint stride
= clip_vec
->stride
;
45 const GLfloat
*from
= (GLfloat
*)clip_vec
->start
;
46 const GLuint count
= clip_vec
->count
;
48 GLfloat (*vProj
)[4] = (GLfloat (*)[4])proj_vec
->start
;
49 GLubyte tmpAndMask
= *andMask
;
50 GLubyte tmpOrMask
= *orMask
;
53 const GLfloat cx
= from
[0];
54 const GLfloat cy
= from
[1];
55 const GLfloat cz
= from
[2];
56 const GLfloat cw
= from
[3];
57 #if defined(macintosh)
58 /* on powerpc cliptest is 17% faster in this way. */
60 mask
= (((cw
< cx
) << CLIP_RIGHT_SHIFT
));
61 mask
|= (((cw
< -cx
) << CLIP_LEFT_SHIFT
));
62 mask
|= (((cw
< cy
) << CLIP_TOP_SHIFT
));
63 mask
|= (((cw
< -cy
) << CLIP_BOTTOM_SHIFT
));
64 mask
|= (((cw
< cz
) << CLIP_FAR_SHIFT
));
65 mask
|= (((cw
< -cz
) << CLIP_NEAR_SHIFT
));
66 #else /* !defined(macintosh)) */
68 if (-cx
+ cw
< 0) mask
|= CLIP_RIGHT_BIT
;
69 if ( cx
+ cw
< 0) mask
|= CLIP_LEFT_BIT
;
70 if (-cy
+ cw
< 0) mask
|= CLIP_TOP_BIT
;
71 if ( cy
+ cw
< 0) mask
|= CLIP_BOTTOM_BIT
;
72 if (-cz
+ cw
< 0) mask
|= CLIP_FAR_BIT
;
73 if ( cz
+ cw
< 0) mask
|= CLIP_NEAR_BIT
;
74 #endif /* defined(macintosh) */
86 GLfloat oow
= 1.0F
/ cw
;
87 vProj
[i
][0] = cx
* oow
;
88 vProj
[i
][1] = cy
* oow
;
89 vProj
[i
][2] = cz
* oow
;
95 *andMask
= (GLubyte
) (c
< count
? 0 : tmpAndMask
);
97 proj_vec
->flags
|= VEC_SIZE_4
;
99 proj_vec
->count
= clip_vec
->count
;
105 static GLvector4f
* _XFORMAPI
TAG(cliptest_np_points4
)( GLvector4f
*clip_vec
,
106 GLvector4f
*proj_vec
,
111 const GLuint stride
= clip_vec
->stride
;
112 const GLfloat
*from
= (GLfloat
*)clip_vec
->start
;
113 const GLuint count
= clip_vec
->count
;
115 GLubyte tmpAndMask
= *andMask
;
116 GLubyte tmpOrMask
= *orMask
;
119 const GLfloat cx
= from
[0];
120 const GLfloat cy
= from
[1];
121 const GLfloat cz
= from
[2];
122 const GLfloat cw
= from
[3];
123 #if defined(macintosh)
124 /* on powerpc cliptest is 17% faster in this way. */
126 mask
= (((cw
< cx
) << CLIP_RIGHT_SHIFT
));
127 mask
|= (((cw
< -cx
) << CLIP_LEFT_SHIFT
));
128 mask
|= (((cw
< cy
) << CLIP_TOP_SHIFT
));
129 mask
|= (((cw
< -cy
) << CLIP_BOTTOM_SHIFT
));
130 mask
|= (((cw
< cz
) << CLIP_FAR_SHIFT
));
131 mask
|= (((cw
< -cz
) << CLIP_NEAR_SHIFT
));
132 #else /* !defined(macintosh)) */
134 if (-cx
+ cw
< 0) mask
|= CLIP_RIGHT_BIT
;
135 if ( cx
+ cw
< 0) mask
|= CLIP_LEFT_BIT
;
136 if (-cy
+ cw
< 0) mask
|= CLIP_TOP_BIT
;
137 if ( cy
+ cw
< 0) mask
|= CLIP_BOTTOM_BIT
;
138 if (-cz
+ cw
< 0) mask
|= CLIP_FAR_BIT
;
139 if ( cz
+ cw
< 0) mask
|= CLIP_NEAR_BIT
;
140 #endif /* defined(macintosh) */
151 *andMask
= (GLubyte
) (c
< count
? 0 : tmpAndMask
);
156 static GLvector4f
* _XFORMAPI
TAG(cliptest_points3
)( GLvector4f
*clip_vec
,
157 GLvector4f
*proj_vec
,
162 const GLuint stride
= clip_vec
->stride
;
163 const GLuint count
= clip_vec
->count
;
164 const GLfloat
*from
= (GLfloat
*)clip_vec
->start
;
166 GLubyte tmpOrMask
= *orMask
;
167 GLubyte tmpAndMask
= *andMask
;
170 const GLfloat cx
= from
[0], cy
= from
[1], cz
= from
[2];
172 if (cx
> 1.0) mask
|= CLIP_RIGHT_BIT
;
173 else if (cx
< -1.0) mask
|= CLIP_LEFT_BIT
;
174 if (cy
> 1.0) mask
|= CLIP_TOP_BIT
;
175 else if (cy
< -1.0) mask
|= CLIP_BOTTOM_BIT
;
176 if (cz
> 1.0) mask
|= CLIP_FAR_BIT
;
177 else if (cz
< -1.0) mask
|= CLIP_NEAR_BIT
;
184 *andMask
= tmpAndMask
;
189 static GLvector4f
* _XFORMAPI
TAG(cliptest_points2
)( GLvector4f
*clip_vec
,
190 GLvector4f
*proj_vec
,
195 const GLuint stride
= clip_vec
->stride
;
196 const GLuint count
= clip_vec
->count
;
197 const GLfloat
*from
= (GLfloat
*)clip_vec
->start
;
199 GLubyte tmpOrMask
= *orMask
;
200 GLubyte tmpAndMask
= *andMask
;
203 const GLfloat cx
= from
[0], cy
= from
[1];
205 if (cx
> 1.0) mask
|= CLIP_RIGHT_BIT
;
206 else if (cx
< -1.0) mask
|= CLIP_LEFT_BIT
;
207 if (cy
> 1.0) mask
|= CLIP_TOP_BIT
;
208 else if (cy
< -1.0) mask
|= CLIP_BOTTOM_BIT
;
215 *andMask
= tmpAndMask
;
220 static void TAG(init_c_cliptest
)( void )
222 _mesa_clip_tab
[4] = TAG(cliptest_points4
);
223 _mesa_clip_tab
[3] = TAG(cliptest_points3
);
224 _mesa_clip_tab
[2] = TAG(cliptest_points2
);
226 _mesa_clip_np_tab
[4] = TAG(cliptest_np_points4
);
227 _mesa_clip_np_tab
[3] = TAG(cliptest_points3
);
228 _mesa_clip_np_tab
[2] = TAG(cliptest_points2
);