added missing \'s
[mesa.git] / src / mesa / swrast / s_pointtemp.h
1 /* $Id: s_pointtemp.h,v 1.8 2001/05/17 09:32:17 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 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 /*
29 * Point rendering template code.
30 *
31 * Set FLAGS = bitwise-OR of the following tokens:
32 *
33 * RGBA = do rgba instead of color index
34 * SMOOTH = do antialiasing
35 * TEXTURE = do texture coords
36 * SPECULAR = do separate specular color
37 * LARGE = do points with diameter > 1 pixel
38 * ATTENUATE = compute point size attenuation
39 * SPRITE = GL_MESA_sprite_point
40 *
41 * Notes: LARGE and ATTENUATE are exclusive of each other.
42 * TEXTURE requires RGBA
43 * SPECULAR requires TEXTURE
44 */
45
46
47 /*
48 * NOTES on antialiased point rasterization:
49 *
50 * Let d = distance of fragment center from vertex.
51 * if d < rmin2 then
52 * fragment has 100% coverage
53 * else if d > rmax2 then
54 * fragment has 0% coverage
55 * else
56 * fragement has % coverage = (d - rmin2) / (rmax2 - rmin2)
57 */
58
59
60
61 static void
62 NAME ( GLcontext *ctx, const SWvertex *vert )
63 {
64 SWcontext *swrast = SWRAST_CONTEXT(ctx);
65 struct pixel_buffer *PB = swrast->PB;
66
67 const GLint z = (GLint) (vert->win[2]);
68
69 #if FLAGS & RGBA
70 const GLint red = vert->color[0];
71 const GLint green = vert->color[1];
72 const GLint blue = vert->color[2];
73 GLint alpha = vert->color[3];
74 #if FLAGS & SPECULAR
75 const GLint sRed = vert->specular[0];
76 const GLint sGreen = vert->specular[1];
77 const GLint sBlue = vert->specular[2];
78 #endif
79 #else
80 GLint index = vert->index;
81 #endif
82 #if FLAGS & (ATTENUATE | LARGE | SMOOTH)
83 GLfloat size;
84 #endif
85 #if FLAGS & ATTENUATE
86 GLfloat alphaAtten;
87 #endif
88
89 #if FLAGS & TEXTURE
90 GLfloat texcoord[MAX_TEXTURE_UNITS][4];
91 GLuint u;
92 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
93 if (ctx->Texture.Unit[u]._ReallyEnabled) {
94 if (vert->texcoord[u][3] != 1.0 && vert->texcoord[u][3] != 0.0) {
95 texcoord[u][0] = vert->texcoord[u][0] / vert->texcoord[u][3];
96 texcoord[u][1] = vert->texcoord[u][1] / vert->texcoord[u][3];
97 texcoord[u][2] = vert->texcoord[u][2] / vert->texcoord[u][3];
98 }
99 else {
100 texcoord[u][0] = vert->texcoord[u][0];
101 texcoord[u][1] = vert->texcoord[u][1];
102 texcoord[u][2] = vert->texcoord[u][2];
103 }
104 }
105 }
106 #endif
107
108 #if FLAGS & ATTENUATE
109 if (vert->pointSize >= ctx->Point.Threshold) {
110 size = MIN2(vert->pointSize, ctx->Point.MaxSize);
111 alphaAtten = 1.0F;
112 }
113 else {
114 GLfloat dsize = vert->pointSize / ctx->Point.Threshold;
115 size = MAX2(ctx->Point.Threshold, ctx->Point.MinSize);
116 alphaAtten = dsize * dsize;
117 }
118 #elif FLAGS & (LARGE | SMOOTH)
119 size = ctx->Point._Size;
120 #endif
121
122 #if FLAGS & SPRITE
123 {
124 SWcontext *swctx = SWRAST_CONTEXT(ctx);
125 const GLfloat radius = 0.5 * vert->pointSize; /* XXX threshold, alpha */
126 SWvertex v0, v1, v2, v3;
127 GLuint unit;
128
129 (void) red;
130 (void) green;
131 (void) blue;
132 (void) alpha;
133 (void) z;
134
135 /* lower left corner */
136 v0 = *vert;
137 v0.win[0] -= radius;
138 v0.win[1] -= radius;
139
140 /* lower right corner */
141 v1 = *vert;
142 v1.win[0] += radius;
143 v1.win[1] -= radius;
144
145 /* upper right corner */
146 v2 = *vert;
147 v2.win[0] += radius;
148 v2.win[1] += radius;
149
150 /* upper left corner */
151 v3 = *vert;
152 v3.win[0] -= radius;
153 v3.win[1] += radius;
154
155 for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
156 if (ctx->Texture.Unit[unit]._ReallyEnabled) {
157 v0.texcoord[unit][0] = 0.0;
158 v0.texcoord[unit][1] = 0.0;
159 v1.texcoord[unit][0] = 1.0;
160 v1.texcoord[unit][1] = 0.0;
161 v2.texcoord[unit][0] = 1.0;
162 v2.texcoord[unit][1] = 1.0;
163 v3.texcoord[unit][0] = 0.0;
164 v3.texcoord[unit][1] = 1.0;
165 }
166 }
167
168 /* XXX if radius < threshold, attenuate alpha? */
169
170 /* XXX need to implement clipping!!! */
171
172 /* render */
173 swctx->Triangle(ctx, &v0, &v1, &v2);
174 swctx->Triangle(ctx, &v0, &v2, &v3);
175 }
176
177 #elif FLAGS & (LARGE | ATTENUATE | SMOOTH)
178
179 {
180 GLint x, y;
181 const GLfloat radius = 0.5F * size;
182 #if FLAGS & SMOOTH
183 const GLfloat rmin = radius - 0.7071F; /* 0.7071 = sqrt(2)/2 */
184 const GLfloat rmax = radius + 0.7071F;
185 const GLfloat rmin2 = MAX2(0.0, rmin * rmin);
186 const GLfloat rmax2 = rmax * rmax;
187 const GLfloat cscale = 1.0F / (rmax2 - rmin2);
188 const GLint xmin = (GLint) (vert->win[0] - radius);
189 const GLint xmax = (GLint) (vert->win[0] + radius);
190 const GLint ymin = (GLint) (vert->win[1] - radius);
191 const GLint ymax = (GLint) (vert->win[1] + radius);
192 #else
193 /* non-smooth */
194 GLint xmin, xmax, ymin, ymax;
195 GLint iSize = (GLint) (size + 0.5F);
196 GLint iRadius;
197 iSize = MAX2(1, iSize);
198 iRadius = iSize / 2;
199 if (iSize & 1) {
200 /* odd size */
201 xmin = (GLint) (vert->win[0] - iRadius);
202 xmax = (GLint) (vert->win[0] + iRadius);
203 ymin = (GLint) (vert->win[1] - iRadius);
204 ymax = (GLint) (vert->win[1] + iRadius);
205 }
206 else {
207 /* even size */
208 xmin = (GLint) vert->win[0] - iRadius + 1;
209 xmax = xmin + iSize - 1;
210 ymin = (GLint) vert->win[1] - iRadius + 1;
211 ymax = ymin + iSize - 1;
212 }
213 #endif
214 (void) radius;
215
216 for (y = ymin; y <= ymax; y++) {
217 for (x = xmin; x <= xmax; x++) {
218 #if FLAGS & SMOOTH
219 /* compute coverage */
220 const GLfloat dx = x - vert->win[0] + 0.5F;
221 const GLfloat dy = y - vert->win[1] + 0.5F;
222 const GLfloat dist2 = dx * dx + dy * dy;
223 if (dist2 < rmax2) {
224 #if FLAGS & RGBA
225 alpha = vert->color[3];
226 #endif
227 if (dist2 >= rmin2) {
228 /* compute partial coverage */
229 PB_COVERAGE(PB, 1.0F - (dist2 - rmin2) * cscale);
230 }
231 else {
232 /* full coverage */
233 PB_COVERAGE(PB, 1.0F);
234 }
235
236 #endif /* SMOOTH */
237
238 #if ((FLAGS & (ATTENUATE | RGBA)) == (ATTENUATE | RGBA))
239 alpha = (GLint) (alpha * alphaAtten);
240 #endif
241
242 #if FLAGS & SPECULAR
243 PB_WRITE_MULTITEX_SPEC_PIXEL(PB, x, y, z, vert->fog,
244 red, green, blue, alpha,
245 sRed, sGreen, sBlue,
246 texcoord);
247 #elif FLAGS & TEXTURE
248 if (ctx->Texture._ReallyEnabled > TEXTURE0_ANY) {
249 PB_WRITE_MULTITEX_PIXEL(PB, x, y, z, vert->fog,
250 red, green, blue, alpha,
251 texcoord);
252 }
253 else if (ctx->Texture._ReallyEnabled) {
254 PB_WRITE_TEX_PIXEL(PB, x,y,z, vert->fog,
255 red, green, blue, alpha,
256 texcoord[0][0],
257 texcoord[0][1],
258 texcoord[0][2]);
259 }
260 else {
261 PB_WRITE_RGBA_PIXEL(PB, x, y, z, vert->fog,
262 red, green, blue, alpha);
263 }
264 #elif FLAGS & RGBA
265 PB_WRITE_RGBA_PIXEL(PB, x, y, z, vert->fog,
266 red, green, blue, alpha);
267 #else /* color index */
268 PB_WRITE_CI_PIXEL(PB, x, y, z, vert->fog, index);
269 #endif
270 #if FLAGS & SMOOTH
271 }
272 #endif
273 }
274 }
275
276 #if FLAGS & SMOOTH
277 PB->haveCoverage = GL_TRUE;
278 #endif
279
280 PB_CHECK_FLUSH(ctx,PB);
281 }
282
283 #else /* LARGE || ATTENUATE || SMOOTH*/
284
285 {
286 /* size == 1 */
287 GLint x = (GLint) vert->win[0];
288 GLint y = (GLint) vert->win[1];
289 #if ((FLAGS & (SPECULAR | TEXTURE)) == (SPECULAR | TEXTURE))
290 PB_WRITE_MULTITEX_SPEC_PIXEL(PB, x, y, z, vert->fog,
291 red, green, blue, alpha,
292 sRed, sGreen, sBlue,
293 texcoord);
294 #elif FLAGS & TEXTURE
295 if (ctx->Texture._ReallyEnabled > TEXTURE0_ANY) {
296 PB_WRITE_MULTITEX_PIXEL(PB, x, y, z, vert->fog,
297 red, green, blue, alpha, texcoord );
298 }
299 else {
300 PB_WRITE_TEX_PIXEL(PB, x, y, z, vert->fog,
301 red, green, blue, alpha,
302 texcoord[0][0], texcoord[0][1], texcoord[0][2]);
303 }
304 #elif FLAGS & RGBA
305 /* rgba size 1 point */
306 alpha = vert->color[3];
307 PB_WRITE_RGBA_PIXEL(PB, x, y, z, vert->fog, red, green, blue, alpha);
308 #else
309 /* color index size 1 point */
310 PB_WRITE_CI_PIXEL(PB, x, y, z, vert->fog, index);
311 #endif
312 }
313 #endif /* LARGE || ATTENUATE || SMOOTH */
314
315 PB_CHECK_FLUSH(ctx, PB);
316 }
317
318
319 #undef FLAGS
320 #undef NAME