| 1 |
/* |
| 2 |
* Mesa 3-D graphics library |
| 3 |
* Version: 6.3 |
| 4 |
* |
| 5 |
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved. |
| 6 |
* |
| 7 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 8 |
* copy of this software and associated documentation files (the "Software"), |
| 9 |
* to deal in the Software without restriction, including without limitation |
| 10 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 12 |
* Software is furnished to do so, subject to the following conditions: |
| 13 |
* |
| 14 |
* The above copyright notice and this permission notice shall be included |
| 15 |
* in all copies or substantial portions of the Software. |
| 16 |
* |
| 17 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 |
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 21 |
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 |
*/ |
| 24 |
|
| 25 |
|
| 26 |
/* |
| 27 |
* Antialiased line template. |
| 28 |
*/ |
| 29 |
|
| 30 |
|
| 31 |
/* |
| 32 |
* Function to render each fragment in the AA line. |
| 33 |
* \param ix - integer fragment window X coordiante |
| 34 |
* \param iy - integer fragment window Y coordiante |
| 35 |
*/ |
| 36 |
static void |
| 37 |
NAME(plot)(GLcontext *ctx, struct LineInfo *line, int ix, int iy) |
| 38 |
{ |
| 39 |
const GLfloat fx = (GLfloat) ix; |
| 40 |
const GLfloat fy = (GLfloat) iy; |
| 41 |
#ifdef DO_INDEX |
| 42 |
const GLfloat coverage = compute_coveragei(line, ix, iy); |
| 43 |
#else |
| 44 |
const GLfloat coverage = compute_coveragef(line, ix, iy); |
| 45 |
#endif |
| 46 |
const GLuint i = line->span.end; |
| 47 |
|
| 48 |
if (coverage == 0.0) |
| 49 |
return; |
| 50 |
|
| 51 |
line->span.end++; |
| 52 |
line->span.array->coverage[i] = coverage; |
| 53 |
line->span.array->x[i] = ix; |
| 54 |
line->span.array->y[i] = iy; |
| 55 |
|
| 56 |
/* |
| 57 |
* Compute Z, color, texture coords, fog for the fragment by |
| 58 |
* solving the plane equations at (ix,iy). |
| 59 |
*/ |
| 60 |
#ifdef DO_Z |
| 61 |
line->span.array->z[i] = (GLdepth) IROUND(solve_plane(fx, fy, line->zPlane)); |
| 62 |
#endif |
| 63 |
#ifdef DO_FOG |
| 64 |
line->span.array->fog[i] = solve_plane(fx, fy, line->fPlane); |
| 65 |
#endif |
| 66 |
#ifdef DO_RGBA |
| 67 |
line->span.array->rgba[i][RCOMP] = solve_plane_chan(fx, fy, line->rPlane); |
| 68 |
line->span.array->rgba[i][GCOMP] = solve_plane_chan(fx, fy, line->gPlane); |
| 69 |
line->span.array->rgba[i][BCOMP] = solve_plane_chan(fx, fy, line->bPlane); |
| 70 |
line->span.array->rgba[i][ACOMP] = solve_plane_chan(fx, fy, line->aPlane); |
| 71 |
#endif |
| 72 |
#ifdef DO_INDEX |
| 73 |
line->span.array->index[i] = (GLint) solve_plane(fx, fy, line->iPlane); |
| 74 |
#endif |
| 75 |
#ifdef DO_SPEC |
| 76 |
line->span.array->spec[i][RCOMP] = solve_plane_chan(fx, fy, line->srPlane); |
| 77 |
line->span.array->spec[i][GCOMP] = solve_plane_chan(fx, fy, line->sgPlane); |
| 78 |
line->span.array->spec[i][BCOMP] = solve_plane_chan(fx, fy, line->sbPlane); |
| 79 |
#endif |
| 80 |
#ifdef DO_TEX |
| 81 |
{ |
| 82 |
GLfloat invQ; |
| 83 |
if (ctx->FragmentProgram._Active) { |
| 84 |
invQ = 1.0F; |
| 85 |
} |
| 86 |
else { |
| 87 |
invQ = solve_plane_recip(fx, fy, line->vPlane[0]); |
| 88 |
} |
| 89 |
line->span.array->texcoords[0][i][0] = solve_plane(fx, fy, line->sPlane[0]) * invQ; |
| 90 |
line->span.array->texcoords[0][i][1] = solve_plane(fx, fy, line->tPlane[0]) * invQ; |
| 91 |
line->span.array->texcoords[0][i][2] = solve_plane(fx, fy, line->uPlane[0]) * invQ; |
| 92 |
line->span.array->lambda[0][i] = compute_lambda(line->sPlane[0], |
| 93 |
line->tPlane[0], invQ, |
| 94 |
line->texWidth[0], |
| 95 |
line->texHeight[0]); |
| 96 |
} |
| 97 |
#elif defined(DO_MULTITEX) |
| 98 |
{ |
| 99 |
GLuint unit; |
| 100 |
for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { |
| 101 |
if (ctx->Texture.Unit[unit]._ReallyEnabled) { |
| 102 |
GLfloat invQ; |
| 103 |
if (ctx->FragmentProgram._Active) { |
| 104 |
invQ = 1.0F; |
| 105 |
} |
| 106 |
else { |
| 107 |
invQ = solve_plane_recip(fx, fy, line->vPlane[unit]); |
| 108 |
} |
| 109 |
line->span.array->texcoords[unit][i][0] = solve_plane(fx, fy, line->sPlane[unit]) * invQ; |
| 110 |
line->span.array->texcoords[unit][i][1] = solve_plane(fx, fy, line->tPlane[unit]) * invQ; |
| 111 |
line->span.array->texcoords[unit][i][2] = solve_plane(fx, fy, line->uPlane[unit]) * invQ; |
| 112 |
line->span.array->lambda[unit][i] = compute_lambda(line->sPlane[unit], |
| 113 |
line->tPlane[unit], invQ, |
| 114 |
line->texWidth[unit], line->texHeight[unit]); |
| 115 |
} |
| 116 |
} |
| 117 |
} |
| 118 |
#endif |
| 119 |
|
| 120 |
if (line->span.end == MAX_WIDTH) { |
| 121 |
#if defined(DO_RGBA) |
| 122 |
_swrast_write_rgba_span(ctx, &(line->span)); |
| 123 |
#else |
| 124 |
_swrast_write_index_span(ctx, &(line->span)); |
| 125 |
#endif |
| 126 |
line->span.end = 0; /* reset counter */ |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
/* |
| 133 |
* Line setup |
| 134 |
*/ |
| 135 |
static void |
| 136 |
NAME(line)(GLcontext *ctx, const SWvertex *v0, const SWvertex *v1) |
| 137 |
{ |
| 138 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 139 |
GLfloat tStart, tEnd; /* segment start, end along line length */ |
| 140 |
GLboolean inSegment; |
| 141 |
GLint iLen, i; |
| 142 |
|
| 143 |
/* Init the LineInfo struct */ |
| 144 |
struct LineInfo line; |
| 145 |
line.x0 = v0->win[0]; |
| 146 |
line.y0 = v0->win[1]; |
| 147 |
line.x1 = v1->win[0]; |
| 148 |
line.y1 = v1->win[1]; |
| 149 |
line.dx = line.x1 - line.x0; |
| 150 |
line.dy = line.y1 - line.y0; |
| 151 |
line.len = SQRTF(line.dx * line.dx + line.dy * line.dy); |
| 152 |
line.halfWidth = 0.5F * ctx->Line._Width; |
| 153 |
|
| 154 |
if (line.len == 0.0 || IS_INF_OR_NAN(line.len)) |
| 155 |
return; |
| 156 |
|
| 157 |
INIT_SPAN(line.span, GL_LINE, 0, 0, SPAN_XY | SPAN_COVERAGE); |
| 158 |
|
| 159 |
line.xAdj = line.dx / line.len * line.halfWidth; |
| 160 |
line.yAdj = line.dy / line.len * line.halfWidth; |
| 161 |
|
| 162 |
#ifdef DO_Z |
| 163 |
line.span.arrayMask |= SPAN_Z; |
| 164 |
compute_plane(line.x0, line.y0, line.x1, line.y1, |
| 165 |
v0->win[2], v1->win[2], line.zPlane); |
| 166 |
#endif |
| 167 |
#ifdef DO_FOG |
| 168 |
line.span.arrayMask |= SPAN_FOG; |
| 169 |
compute_plane(line.x0, line.y0, line.x1, line.y1, |
| 170 |
v0->fog, v1->fog, line.fPlane); |
| 171 |
#endif |
| 172 |
#ifdef DO_RGBA |
| 173 |
line.span.arrayMask |= SPAN_RGBA; |
| 174 |
if (ctx->Light.ShadeModel == GL_SMOOTH) { |
| 175 |
compute_plane(line.x0, line.y0, line.x1, line.y1, |
| 176 |
v0->color[RCOMP], v1->color[RCOMP], line.rPlane); |
| 177 |
compute_plane(line.x0, line.y0, line.x1, line.y1, |
| 178 |
v0->color[GCOMP], v1->color[GCOMP], line.gPlane); |
| 179 |
compute_plane(line.x0, line.y0, line.x1, line.y1, |
| 180 |
v0->color[BCOMP], v1->color[BCOMP], line.bPlane); |
| 181 |
compute_plane(line.x0, line.y0, line.x1, line.y1, |
| 182 |
v0->color[ACOMP], v1->color[ACOMP], line.aPlane); |
| 183 |
} |
| 184 |
else { |
| 185 |
constant_plane(v1->color[RCOMP], line.rPlane); |
| 186 |
constant_plane(v1->color[GCOMP], line.gPlane); |
| 187 |
constant_plane(v1->color[BCOMP], line.bPlane); |
| 188 |
constant_plane(v1->color[ACOMP], line.aPlane); |
| 189 |
} |
| 190 |
#endif |
| 191 |
#ifdef DO_SPEC |
| 192 |
line.span.arrayMask |= SPAN_SPEC; |
| 193 |
if (ctx->Light.ShadeModel == GL_SMOOTH) { |
| 194 |
compute_plane(line.x0, line.y0, line.x1, line.y1, |
| 195 |
v0->specular[RCOMP], v1->specular[RCOMP], line.srPlane); |
| 196 |
compute_plane(line.x0, line.y0, line.x1, line.y1, |
| 197 |
v0->specular[GCOMP], v1->specular[GCOMP], line.sgPlane); |
| 198 |
compute_plane(line.x0, line.y0, line.x1, line.y1, |
| 199 |
v0->specular[BCOMP], v1->specular[BCOMP], line.sbPlane); |
| 200 |
} |
| 201 |
else { |
| 202 |
constant_plane(v1->specular[RCOMP], line.srPlane); |
| 203 |
constant_plane(v1->specular[GCOMP], line.sgPlane); |
| 204 |
constant_plane(v1->specular[BCOMP], line.sbPlane); |
| 205 |
} |
| 206 |
#endif |
| 207 |
#ifdef DO_INDEX |
| 208 |
line.span.arrayMask |= SPAN_INDEX; |
| 209 |
if (ctx->Light.ShadeModel == GL_SMOOTH) { |
| 210 |
compute_plane(line.x0, line.y0, line.x1, line.y1, |
| 211 |
v0->index, v1->index, line.iPlane); |
| 212 |
} |
| 213 |
else { |
| 214 |
constant_plane(v1->index, line.iPlane); |
| 215 |
} |
| 216 |
#endif |
| 217 |
#ifdef DO_TEX |
| 218 |
{ |
| 219 |
const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current; |
| 220 |
const struct gl_texture_image *texImage = obj->Image[0][obj->BaseLevel]; |
| 221 |
const GLfloat invW0 = v0->win[3]; |
| 222 |
const GLfloat invW1 = v1->win[3]; |
| 223 |
const GLfloat s0 = v0->texcoord[0][0] * invW0; |
| 224 |
const GLfloat s1 = v1->texcoord[0][0] * invW1; |
| 225 |
const GLfloat t0 = v0->texcoord[0][1] * invW0; |
| 226 |
const GLfloat t1 = v1->texcoord[0][1] * invW1; |
| 227 |
const GLfloat r0 = v0->texcoord[0][2] * invW0; |
| 228 |
const GLfloat r1 = v1->texcoord[0][2] * invW1; |
| 229 |
const GLfloat q0 = v0->texcoord[0][3] * invW0; |
| 230 |
const GLfloat q1 = v1->texcoord[0][3] * invW1; |
| 231 |
line.span.arrayMask |= (SPAN_TEXTURE | SPAN_LAMBDA); |
| 232 |
compute_plane(line.x0, line.y0, line.x1, line.y1, s0, s1, line.sPlane[0]); |
| 233 |
compute_plane(line.x0, line.y0, line.x1, line.y1, t0, t1, line.tPlane[0]); |
| 234 |
compute_plane(line.x0, line.y0, line.x1, line.y1, r0, r1, line.uPlane[0]); |
| 235 |
compute_plane(line.x0, line.y0, line.x1, line.y1, q0, q1, line.vPlane[0]); |
| 236 |
line.texWidth[0] = (GLfloat) texImage->Width; |
| 237 |
line.texHeight[0] = (GLfloat) texImage->Height; |
| 238 |
} |
| 239 |
#elif defined(DO_MULTITEX) |
| 240 |
{ |
| 241 |
GLuint u; |
| 242 |
line.span.arrayMask |= (SPAN_TEXTURE | SPAN_LAMBDA); |
| 243 |
for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { |
| 244 |
if (ctx->Texture.Unit[u]._ReallyEnabled) { |
| 245 |
const struct gl_texture_object *obj = ctx->Texture.Unit[u]._Current; |
| 246 |
const struct gl_texture_image *texImage = obj->Image[0][obj->BaseLevel]; |
| 247 |
const GLfloat invW0 = v0->win[3]; |
| 248 |
const GLfloat invW1 = v1->win[3]; |
| 249 |
const GLfloat s0 = v0->texcoord[u][0] * invW0; |
| 250 |
const GLfloat s1 = v1->texcoord[u][0] * invW1; |
| 251 |
const GLfloat t0 = v0->texcoord[u][1] * invW0; |
| 252 |
const GLfloat t1 = v1->texcoord[u][1] * invW1; |
| 253 |
const GLfloat r0 = v0->texcoord[u][2] * invW0; |
| 254 |
const GLfloat r1 = v1->texcoord[u][2] * invW1; |
| 255 |
const GLfloat q0 = v0->texcoord[u][3] * invW0; |
| 256 |
const GLfloat q1 = v1->texcoord[u][3] * invW1; |
| 257 |
compute_plane(line.x0, line.y0, line.x1, line.y1, s0, s1, line.sPlane[u]); |
| 258 |
compute_plane(line.x0, line.y0, line.x1, line.y1, t0, t1, line.tPlane[u]); |
| 259 |
compute_plane(line.x0, line.y0, line.x1, line.y1, r0, r1, line.uPlane[u]); |
| 260 |
compute_plane(line.x0, line.y0, line.x1, line.y1, q0, q1, line.vPlane[u]); |
| 261 |
line.texWidth[u] = (GLfloat) texImage->Width; |
| 262 |
line.texHeight[u] = (GLfloat) texImage->Height; |
| 263 |
} |
| 264 |
} |
| 265 |
} |
| 266 |
#endif |
| 267 |
|
| 268 |
tStart = tEnd = 0.0; |
| 269 |
inSegment = GL_FALSE; |
| 270 |
iLen = (GLint) line.len; |
| 271 |
|
| 272 |
if (ctx->Line.StippleFlag) { |
| 273 |
for (i = 0; i < iLen; i++) { |
| 274 |
const GLuint bit = (swrast->StippleCounter / ctx->Line.StippleFactor) & 0xf; |
| 275 |
if ((1 << bit) & ctx->Line.StipplePattern) { |
| 276 |
/* stipple bit is on */ |
| 277 |
const GLfloat t = (GLfloat) i / (GLfloat) line.len; |
| 278 |
if (!inSegment) { |
| 279 |
/* start new segment */ |
| 280 |
inSegment = GL_TRUE; |
| 281 |
tStart = t; |
| 282 |
} |
| 283 |
else { |
| 284 |
/* still in the segment, extend it */ |
| 285 |
tEnd = t; |
| 286 |
} |
| 287 |
} |
| 288 |
else { |
| 289 |
/* stipple bit is off */ |
| 290 |
if (inSegment && (tEnd > tStart)) { |
| 291 |
/* draw the segment */ |
| 292 |
segment(ctx, &line, NAME(plot), tStart, tEnd); |
| 293 |
inSegment = GL_FALSE; |
| 294 |
} |
| 295 |
else { |
| 296 |
/* still between segments, do nothing */ |
| 297 |
} |
| 298 |
} |
| 299 |
swrast->StippleCounter++; |
| 300 |
} |
| 301 |
|
| 302 |
if (inSegment) { |
| 303 |
/* draw the final segment of the line */ |
| 304 |
segment(ctx, &line, NAME(plot), tStart, 1.0F); |
| 305 |
} |
| 306 |
} |
| 307 |
else { |
| 308 |
/* non-stippled */ |
| 309 |
segment(ctx, &line, NAME(plot), 0.0, 1.0); |
| 310 |
} |
| 311 |
|
| 312 |
#if defined(DO_RGBA) |
| 313 |
_swrast_write_rgba_span(ctx, &(line.span)); |
| 314 |
#else |
| 315 |
_swrast_write_index_span(ctx, &(line.span)); |
| 316 |
#endif |
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
#undef DO_Z |
| 323 |
#undef DO_FOG |
| 324 |
#undef DO_RGBA |
| 325 |
#undef DO_INDEX |
| 326 |
#undef DO_SPEC |
| 327 |
#undef DO_TEX |
| 328 |
#undef DO_MULTITEX |
| 329 |
#undef NAME |