Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
56 pj 1
/* $Id: m_clip_tmp.h,v 1.1 2003-02-28 11:48:04 pj Exp $ */
2
 
3
/*
4
 * Mesa 3-D graphics library
5
 * Version:  4.0.3
6
 *
7
 * Copyright (C) 1999-2002  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
 * New (3.1) transformation code written by Keith Whitwell.
29
 */
30
 
31
 
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.
37
 */
38
static GLvector4f * _XFORMAPI TAG(cliptest_points4)( GLvector4f *clip_vec,
39
                                                     GLvector4f *proj_vec,
40
                                                     GLubyte clipMask[],
41
                                                     GLubyte *orMask,
42
                                                     GLubyte *andMask )
43
{
44
   const GLuint stride = clip_vec->stride;
45
   const GLfloat *from = (GLfloat *)clip_vec->start;
46
   const GLuint count = clip_vec->count;
47
   GLuint c = 0;
48
   GLfloat (*vProj)[4] = (GLfloat (*)[4])proj_vec->start;
49
   GLubyte tmpAndMask = *andMask;
50
   GLubyte tmpOrMask = *orMask;
51
   GLuint i;
52
   STRIDE_LOOP {
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) || defined(__powerpc__)
58
      /* on powerpc cliptest is 17% faster in this way. */
59
      GLuint mask;
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)) */
67
      GLubyte mask = 0;
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) */
75
 
76
      clipMask[i] = mask;
77
      if (mask) {
78
         c++;
79
         tmpAndMask &= mask;
80
         tmpOrMask |= mask;
81
         vProj[i][0] = 0;
82
         vProj[i][1] = 0;
83
         vProj[i][2] = 0;
84
         vProj[i][3] = 1;
85
      } else {
86
         GLfloat oow = 1.0F / cw;
87
         vProj[i][0] = cx * oow;
88
         vProj[i][1] = cy * oow;
89
         vProj[i][2] = cz * oow;
90
         vProj[i][3] = oow;
91
      }
92
   }
93
 
94
   *orMask = tmpOrMask;
95
   *andMask = (GLubyte) (c < count ? 0 : tmpAndMask);
96
 
97
   proj_vec->flags |= VEC_SIZE_4;
98
   proj_vec->size = 4;
99
   proj_vec->count = clip_vec->count;
100
   return proj_vec;
101
}
102
 
103
 
104
 
105
static GLvector4f * _XFORMAPI TAG(cliptest_np_points4)( GLvector4f *clip_vec,
106
                                                        GLvector4f *proj_vec,
107
                                                        GLubyte clipMask[],
108
                                                        GLubyte *orMask,
109
                                                        GLubyte *andMask )
110
{
111
   const GLuint stride = clip_vec->stride;
112
   const GLuint count = clip_vec->count;
113
   const GLfloat *from = (GLfloat *)clip_vec->start;
114
   GLuint c = 0;
115
   GLubyte tmpAndMask = *andMask;
116
   GLubyte tmpOrMask = *orMask;
117
   GLuint i;
118
   STRIDE_LOOP {
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) || defined(__powerpc__)
124
      /* on powerpc cliptest is 17% faster in this way. */
125
      GLuint mask;
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)) */
133
      GLubyte mask = 0;
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) */
141
 
142
      clipMask[i] = mask;
143
      if (mask) {
144
         c++;
145
         tmpAndMask &= mask;
146
         tmpOrMask |= mask;
147
      }
148
   }
149
 
150
   *orMask = tmpOrMask;
151
   *andMask = (GLubyte) (c < count ? 0 : tmpAndMask);
152
   return clip_vec;
153
}
154
 
155
 
156
static GLvector4f * _XFORMAPI TAG(cliptest_points3)( GLvector4f *clip_vec,
157
                                                     GLvector4f *proj_vec,
158
                                                     GLubyte clipMask[],
159
                                                     GLubyte *orMask,
160
                                                     GLubyte *andMask )
161
{
162
   const GLuint stride = clip_vec->stride;
163
   const GLuint count = clip_vec->count;
164
   const GLfloat *from = (GLfloat *)clip_vec->start;
165
 
166
   GLubyte tmpOrMask = *orMask;
167
   GLubyte tmpAndMask = *andMask;
168
   GLuint i;
169
   STRIDE_LOOP {
170
      const GLfloat cx = from[0], cy = from[1], cz = from[2];
171
      GLubyte mask = 0;
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;
178
      clipMask[i] = mask;
179
      tmpOrMask |= mask;
180
      tmpAndMask &= mask;
181
   }
182
 
183
   *orMask = tmpOrMask;
184
   *andMask = tmpAndMask;
185
   return clip_vec;
186
}
187
 
188
 
189
static GLvector4f * _XFORMAPI TAG(cliptest_points2)( GLvector4f *clip_vec,
190
                                                     GLvector4f *proj_vec,
191
                                                     GLubyte clipMask[],
192
                                                     GLubyte *orMask,
193
                                                     GLubyte *andMask )
194
{
195
   const GLuint stride = clip_vec->stride;
196
   const GLuint count = clip_vec->count;
197
   const GLfloat *from = (GLfloat *)clip_vec->start;
198
 
199
   GLubyte tmpOrMask = *orMask;
200
   GLubyte tmpAndMask = *andMask;
201
   GLuint i;
202
   STRIDE_LOOP {
203
      const GLfloat cx = from[0], cy = from[1];
204
      GLubyte mask = 0;
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;
209
      clipMask[i] = mask;
210
      tmpOrMask |= mask;
211
      tmpAndMask &= mask;
212
   }
213
 
214
   *orMask = tmpOrMask;
215
   *andMask = tmpAndMask;
216
   return clip_vec;
217
}
218
 
219
 
220
static void TAG(init_c_cliptest)( void )
221
{
222
   _mesa_clip_tab[4] = TAG(cliptest_points4);
223
   _mesa_clip_tab[3] = TAG(cliptest_points3);
224
   _mesa_clip_tab[2] = TAG(cliptest_points2);
225
 
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);
229
}