1 | /* $Id: clip_tmp.h,v 1.3 2000-05-21 20:17:32 jeroen Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Mesa 3-D graphics library
|
---|
5 | * Version: 3.1
|
---|
6 | *
|
---|
7 | * Copyright (C) 1999 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)
|
---|
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; /* no longer required? */
|
---|
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][3] = oow;
|
---|
88 | vProj[i][0] = cx * oow;
|
---|
89 | vProj[i][1] = cy * oow;
|
---|
90 | vProj[i][2] = cz * 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 = 3;
|
---|
99 | proj_vec->count = clip_vec->count;
|
---|
100 | return proj_vec;
|
---|
101 | }
|
---|
102 |
|
---|
103 | static GLvector4f * _XFORMAPI TAG(cliptest_points3)( GLvector4f *clip_vec,
|
---|
104 | GLvector4f *proj_vec,
|
---|
105 | GLubyte clipMask[],
|
---|
106 | GLubyte *orMask,
|
---|
107 | GLubyte *andMask )
|
---|
108 | {
|
---|
109 | const GLuint stride = clip_vec->stride;
|
---|
110 | const GLuint count = clip_vec->count;
|
---|
111 | const GLfloat *from = (GLfloat *)clip_vec->start;
|
---|
112 |
|
---|
113 | GLubyte tmpOrMask = *orMask;
|
---|
114 | GLubyte tmpAndMask = *andMask;
|
---|
115 | GLuint i;
|
---|
116 | STRIDE_LOOP {
|
---|
117 | const GLfloat cx = from[0], cy = from[1], cz = from[2];
|
---|
118 | GLubyte mask = 0;
|
---|
119 | if (cx > 1.0) mask |= CLIP_RIGHT_BIT;
|
---|
120 | else if (cx < -1.0) mask |= CLIP_LEFT_BIT;
|
---|
121 | if (cy > 1.0) mask |= CLIP_TOP_BIT;
|
---|
122 | else if (cy < -1.0) mask |= CLIP_BOTTOM_BIT;
|
---|
123 | if (cz > 1.0) mask |= CLIP_FAR_BIT;
|
---|
124 | else if (cz < -1.0) mask |= CLIP_NEAR_BIT;
|
---|
125 | clipMask[i] = mask;
|
---|
126 | tmpOrMask |= mask;
|
---|
127 | tmpAndMask &= mask;
|
---|
128 | }
|
---|
129 |
|
---|
130 | gl_vector4f_clean_elem(proj_vec, count, 3);
|
---|
131 |
|
---|
132 | *orMask = tmpOrMask;
|
---|
133 | *andMask = tmpAndMask;
|
---|
134 | return clip_vec;
|
---|
135 | }
|
---|
136 |
|
---|
137 | static GLvector4f * _XFORMAPI TAG(cliptest_points2)( GLvector4f *clip_vec,
|
---|
138 | GLvector4f *proj_vec,
|
---|
139 | GLubyte clipMask[],
|
---|
140 | GLubyte *orMask,
|
---|
141 | GLubyte *andMask )
|
---|
142 | {
|
---|
143 | const GLuint stride = clip_vec->stride;
|
---|
144 | const GLuint count = clip_vec->count;
|
---|
145 | const GLfloat *from = (GLfloat *)clip_vec->start;
|
---|
146 |
|
---|
147 | GLubyte tmpOrMask = *orMask;
|
---|
148 | GLubyte tmpAndMask = *andMask;
|
---|
149 | GLuint i;
|
---|
150 | STRIDE_LOOP {
|
---|
151 | const GLfloat cx = from[0], cy = from[1];
|
---|
152 | GLubyte mask = 0;
|
---|
153 | if (cx > 1.0) mask |= CLIP_RIGHT_BIT;
|
---|
154 | else if (cx < -1.0) mask |= CLIP_LEFT_BIT;
|
---|
155 | if (cy > 1.0) mask |= CLIP_TOP_BIT;
|
---|
156 | else if (cy < -1.0) mask |= CLIP_BOTTOM_BIT;
|
---|
157 | clipMask[i] = mask;
|
---|
158 | tmpOrMask |= mask;
|
---|
159 | tmpAndMask &= mask;
|
---|
160 | }
|
---|
161 |
|
---|
162 | gl_vector4f_clean_elem(proj_vec, count, 3);
|
---|
163 |
|
---|
164 | *orMask = tmpOrMask;
|
---|
165 | *andMask = tmpAndMask;
|
---|
166 | return clip_vec;
|
---|
167 | }
|
---|
168 |
|
---|
169 |
|
---|
170 | static void TAG(init_c_cliptest)( void )
|
---|
171 | {
|
---|
172 | gl_clip_tab[4] = TAG(cliptest_points4);
|
---|
173 | gl_clip_tab[3] = TAG(cliptest_points3);
|
---|
174 | gl_clip_tab[2] = TAG(cliptest_points2);
|
---|
175 | }
|
---|