1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
/* $Id: s_pointtemp.h,v 1.12 2002/02/02 17:24:11 brianp Exp $ */
/*
* Mesa 3-D graphics library
* Version: 4.1
*
* Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Point rendering template code.
*
* Set FLAGS = bitwise-OR of the following tokens:
*
* RGBA = do rgba instead of color index
* SMOOTH = do antialiasing
* TEXTURE = do texture coords
* SPECULAR = do separate specular color
* LARGE = do points with diameter > 1 pixel
* ATTENUATE = compute point size attenuation
* SPRITE = GL_MESA_sprite_point
*
* Notes: LARGE and ATTENUATE are exclusive of each other.
* TEXTURE requires RGBA
* SPECULAR requires TEXTURE
*/
/*
* NOTES on antialiased point rasterization:
*
* Let d = distance of fragment center from vertex.
* if d < rmin2 then
* fragment has 100% coverage
* else if d > rmax2 then
* fragment has 0% coverage
* else
* fragment has % coverage = (d - rmin2) / (rmax2 - rmin2)
*/
static void
NAME ( GLcontext *ctx, const SWvertex *vert )
{
#if FLAGS & TEXTURE
GLuint u;
#endif
#if FLAGS & (ATTENUATE | LARGE | SMOOTH)
GLfloat size;
#endif
#if FLAGS & ATTENUATE
GLfloat alphaAtten;
#endif
#if (FLAGS & RGBA) && (FLAGS & SMOOTH)
const GLchan red = vert->color[0];
const GLchan green = vert->color[1];
const GLchan blue = vert->color[2];
const GLchan alpha = vert->color[3];
#endif
struct sw_span span;
/* Cull primitives with malformed coordinates.
*/
{
float tmp = vert->win[0] + vert->win[1];
if (IS_INF_OR_NAN(tmp))
return;
}
INIT_SPAN(span);
span.arrayMask |= (SPAN_XY | SPAN_Z);
span.interpMask |= SPAN_FOG;
span.fog = vert->fog;
span.fogStep = 0.0;
#if (FLAGS & RGBA)
#if (FLAGS & SMOOTH)
span.arrayMask |= SPAN_RGBA;
#else
span.interpMask |= SPAN_RGBA;
span.red = ChanToFixed(vert->color[0]);
span.green = ChanToFixed(vert->color[1]);
span.blue = ChanToFixed(vert->color[2]);
span.alpha = ChanToFixed(vert->color[3]);
span.redStep = span.greenStep = span.blueStep = span.alphaStep = 0;
#endif /*SMOOTH*/
#endif /*RGBA*/
#if FLAGS & SPECULAR
span.interpMask |= SPAN_SPEC;
span.specRed = ChanToFixed(vert->specular[0]);
span.specGreen = ChanToFixed(vert->specular[1]);
span.specBlue = ChanToFixed(vert->specular[2]);
span.specRedStep = span.specGreenStep = span.specBlueStep = 0;
#endif
#if FLAGS & INDEX
span.interpMask |= SPAN_INDEX;
span.index = IntToFixed(vert->index);
span.indexStep = 0;
#endif
#if FLAGS & TEXTURE
span.interpMask |= SPAN_TEXTURE;
span.arrayMask |= SPAN_LAMBDA;
for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
if (ctx->Texture.Unit[u]._ReallyEnabled) {
const GLfloat q = vert->texcoord[u][3];
const GLfloat invQ = (q == 0.0 || q == 1.0) ? 1.0 : (1.0 / q);
span.tex[u][0] = vert->texcoord[u][0] * invQ;
span.tex[u][1] = vert->texcoord[u][1] * invQ;
span.tex[u][2] = vert->texcoord[u][2] * invQ;
span.tex[u][3] = q;
span.texStep[u][0] = 0.0;
span.texStep[u][1] = 0.0;
span.texStep[u][2] = 0.0;
span.texStep[u][3] = 0.0;
span.rho[u] = 0.0;
}
}
#endif
#if FLAGS & SMOOTH
span.arrayMask |= SPAN_COVERAGE;
#endif
#if FLAGS & ATTENUATE
if (vert->pointSize >= ctx->Point.Threshold) {
size = MIN2(vert->pointSize, ctx->Point.MaxSize);
alphaAtten = 1.0F;
}
else {
GLfloat dsize = vert->pointSize / ctx->Point.Threshold;
size = MAX2(ctx->Point.Threshold, ctx->Point.MinSize);
alphaAtten = dsize * dsize;
}
#elif FLAGS & (LARGE | SMOOTH)
size = ctx->Point._Size;
#endif
#if FLAGS & SPRITE
{
SWcontext *swctx = SWRAST_CONTEXT(ctx);
const GLfloat radius = 0.5F * vert->pointSize; /* XXX threshold, alpha */
SWvertex v0, v1, v2, v3;
GLuint unit;
#if (FLAGS & RGBA) && (FLAGS & SMOOTH)
(void) red;
(void) green;
(void) blue;
(void) alpha;
#endif
/* lower left corner */
v0 = *vert;
v0.win[0] -= radius;
v0.win[1] -= radius;
/* lower right corner */
v1 = *vert;
v1.win[0] += radius;
v1.win[1] -= radius;
/* upper right corner */
v2 = *vert;
v2.win[0] += radius;
v2.win[1] += radius;
/* upper left corner */
v3 = *vert;
v3.win[0] -= radius;
v3.win[1] += radius;
for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
if (ctx->Texture.Unit[unit]._ReallyEnabled) {
v0.texcoord[unit][0] = 0.0;
v0.texcoord[unit][1] = 0.0;
v1.texcoord[unit][0] = 1.0;
v1.texcoord[unit][1] = 0.0;
v2.texcoord[unit][0] = 1.0;
v2.texcoord[unit][1] = 1.0;
v3.texcoord[unit][0] = 0.0;
v3.texcoord[unit][1] = 1.0;
}
}
/* XXX if radius < threshold, attenuate alpha? */
/* XXX need to implement clipping!!! */
/* render */
swctx->Triangle(ctx, &v0, &v1, &v2);
swctx->Triangle(ctx, &v0, &v2, &v3);
}
#elif FLAGS & (LARGE | ATTENUATE | SMOOTH)
{
GLint x, y;
const GLfloat radius = 0.5F * size;
const GLint z = (GLint) (vert->win[2]);
GLuint count = 0;
#if FLAGS & SMOOTH
const GLfloat rmin = radius - 0.7071F; /* 0.7071 = sqrt(2)/2 */
const GLfloat rmax = radius + 0.7071F;
const GLfloat rmin2 = MAX2(0.0F, rmin * rmin);
const GLfloat rmax2 = rmax * rmax;
const GLfloat cscale = 1.0F / (rmax2 - rmin2);
const GLint xmin = (GLint) (vert->win[0] - radius);
const GLint xmax = (GLint) (vert->win[0] + radius);
const GLint ymin = (GLint) (vert->win[1] - radius);
const GLint ymax = (GLint) (vert->win[1] + radius);
#else
/* non-smooth */
GLint xmin, xmax, ymin, ymax;
GLint iSize = (GLint) (size + 0.5F);
GLint iRadius;
iSize = MAX2(1, iSize);
iRadius = iSize / 2;
if (iSize & 1) {
/* odd size */
xmin = (GLint) (vert->win[0] - iRadius);
xmax = (GLint) (vert->win[0] + iRadius);
ymin = (GLint) (vert->win[1] - iRadius);
ymax = (GLint) (vert->win[1] + iRadius);
}
else {
/* even size */
xmin = (GLint) vert->win[0] - iRadius + 1;
xmax = xmin + iSize - 1;
ymin = (GLint) vert->win[1] - iRadius + 1;
ymax = ymin + iSize - 1;
}
#endif /*SMOOTH*/
(void) radius;
for (y = ymin; y <= ymax; y++) {
for (x = xmin; x <= xmax; x++) {
#if FLAGS & SMOOTH
/* compute coverage */
const GLfloat dx = x - vert->win[0] + 0.5F;
const GLfloat dy = y - vert->win[1] + 0.5F;
const GLfloat dist2 = dx * dx + dy * dy;
if (dist2 < rmax2) {
if (dist2 >= rmin2) {
/* compute partial coverage */
span.coverage[count] = 1.0F - (dist2 - rmin2) * cscale;
#if FLAGS & INDEX
span.coverage[count] *= 15.0; /* coverage in [0,15] */
#endif
}
else {
/* full coverage */
span.coverage[count] = 1.0F;
}
span.xArray[count] = x;
span.yArray[count] = y;
span.zArray[count] = z;
#if FLAGS & RGBA
span.color.rgba[count][RCOMP] = red;
span.color.rgba[count][GCOMP] = green;
span.color.rgba[count][BCOMP] = blue;
#if FLAGS & ATTENUATE
span.color.rgba[count][ACOMP] = (GLchan) (alpha * alphaAtten);
#else
span.color.rgba[count][ACOMP] = alpha;
#endif /*ATTENUATE*/
#endif /*RGBA*/
count++;
} /*if*/
#else /*SMOOTH*/
/* not smooth (square points */
span.xArray[count] = x;
span.yArray[count] = y;
span.zArray[count] = z;
count++;
#endif /*SMOOTH*/
} /*for x*/
} /*for y*/
span.end = count;
}
#else /* LARGE || ATTENUATE || SMOOTH*/
{
/* size == 1 */
span.xArray[0] = (GLint) vert->win[0];
span.yArray[0] = (GLint) vert->win[1];
span.zArray[0] = (GLint) vert->win[2];
span.end = 1;
}
#endif /* LARGE || ATTENUATE || SMOOTH */
ASSERT(span.end > 0);
#if FLAGS & TEXTURE
if (ctx->Texture._ReallyEnabled)
_mesa_write_texture_span(ctx, &span, GL_POINT);
else
_mesa_write_rgba_span(ctx, &span, GL_POINT);
#elif FLAGS & RGBA
_mesa_write_rgba_span(ctx, &span, GL_POINT);
#else
_mesa_write_index_span(ctx, &span, GL_POINT);
#endif
}
#undef FLAGS
#undef NAME
|