3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Antialiased line template.
33 * Function to render each fragment in the AA line.
36 NAME(plot
)(GLcontext
*ctx
, struct LineInfo
*line
, int ix
, int iy
)
38 const GLfloat fx
= (GLfloat
) ix
;
39 const GLfloat fy
= (GLfloat
) iy
;
40 const GLfloat coverage
= compute_coveragef(line
, ix
, iy
);
41 const GLuint i
= line
->span
.end
;
47 line
->span
.array
->coverage
[i
] = coverage
;
48 line
->span
.array
->x
[i
] = ix
;
49 line
->span
.array
->y
[i
] = iy
;
52 * Compute Z, color, texture coords, fog for the fragment by
53 * solving the plane equations at (ix,iy).
56 line
->span
.array
->z
[i
] = (GLdepth
) IROUND(solve_plane(fx
, fy
, line
->zPlane
));
59 line
->span
.array
->fog
[i
] = solve_plane(fx
, fy
, line
->fPlane
);
62 line
->span
.array
->rgba
[i
][RCOMP
] = solve_plane_chan(fx
, fy
, line
->rPlane
);
63 line
->span
.array
->rgba
[i
][GCOMP
] = solve_plane_chan(fx
, fy
, line
->gPlane
);
64 line
->span
.array
->rgba
[i
][BCOMP
] = solve_plane_chan(fx
, fy
, line
->bPlane
);
65 line
->span
.array
->rgba
[i
][ACOMP
] = solve_plane_chan(fx
, fy
, line
->aPlane
);
68 line
->span
.array
->index
[i
] = (GLint
) solve_plane(fx
, fy
, line
->iPlane
);
71 line
->span
.array
->spec
[i
][RCOMP
] = solve_plane_chan(fx
, fy
, line
->srPlane
);
72 line
->span
.array
->spec
[i
][GCOMP
] = solve_plane_chan(fx
, fy
, line
->sgPlane
);
73 line
->span
.array
->spec
[i
][BCOMP
] = solve_plane_chan(fx
, fy
, line
->sbPlane
);
77 const GLfloat invQ
= solve_plane_recip(fx
, fy
, line
->vPlane
[0]);
78 line
->span
.array
->texcoords
[0][i
][0] = solve_plane(fx
, fy
, line
->sPlane
[0]) * invQ
;
79 line
->span
.array
->texcoords
[0][i
][1] = solve_plane(fx
, fy
, line
->tPlane
[0]) * invQ
;
80 line
->span
.array
->texcoords
[0][i
][2] = solve_plane(fx
, fy
, line
->uPlane
[0]) * invQ
;
81 line
->span
.array
->lambda
[0][i
] = compute_lambda(line
->sPlane
[0], line
->tPlane
[0], invQ
,
82 line
->texWidth
[0], line
->texHeight
[0]);
84 #elif defined(DO_MULTITEX)
87 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
88 if (ctx
->Texture
.Unit
[unit
]._ReallyEnabled
) {
89 const GLfloat invQ
= solve_plane_recip(fx
, fy
, line
->vPlane
[unit
]);
90 line
->span
.array
->texcoords
[unit
][i
][0] = solve_plane(fx
, fy
, line
->sPlane
[unit
]) * invQ
;
91 line
->span
.array
->texcoords
[unit
][i
][1] = solve_plane(fx
, fy
, line
->tPlane
[unit
]) * invQ
;
92 line
->span
.array
->texcoords
[unit
][i
][2] = solve_plane(fx
, fy
, line
->uPlane
[unit
]) * invQ
;
93 line
->span
.array
->lambda
[unit
][i
] = compute_lambda(line
->sPlane
[unit
],
94 line
->tPlane
[unit
], invQ
,
95 line
->texWidth
[unit
], line
->texHeight
[unit
]);
101 if (line
->span
.end
== MAX_WIDTH
) {
102 #if defined(DO_TEX) || defined(DO_MULTITEX)
103 _swrast_write_texture_span(ctx
, &(line
->span
));
104 #elif defined(DO_RGBA)
105 _swrast_write_rgba_span(ctx
, &(line
->span
));
107 _swrast_write_index_span(ctx
, &(line
->span
));
109 line
->span
.end
= 0; /* reset counter */
119 NAME(line
)(GLcontext
*ctx
, const SWvertex
*v0
, const SWvertex
*v1
)
121 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
122 GLfloat tStart
, tEnd
; /* segment start, end along line length */
126 /* Init the LineInfo struct */
127 struct LineInfo line
;
128 line
.x0
= v0
->win
[0];
129 line
.y0
= v0
->win
[1];
130 line
.x1
= v1
->win
[0];
131 line
.y1
= v1
->win
[1];
132 line
.dx
= line
.x1
- line
.x0
;
133 line
.dy
= line
.y1
- line
.y0
;
134 line
.len
= SQRTF(line
.dx
* line
.dx
+ line
.dy
* line
.dy
);
135 line
.halfWidth
= 0.5F
* ctx
->Line
.Width
;
137 if (line
.len
== 0.0 || IS_INF_OR_NAN(line
.len
))
140 INIT_SPAN(line
.span
, GL_LINE
, 0, 0, SPAN_XY
| SPAN_COVERAGE
);
142 line
.xAdj
= line
.dx
/ line
.len
* line
.halfWidth
;
143 line
.yAdj
= line
.dy
/ line
.len
* line
.halfWidth
;
146 line
.span
.arrayMask
|= SPAN_Z
;
147 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
148 v0
->win
[2], v1
->win
[2], line
.zPlane
);
151 line
.span
.arrayMask
|= SPAN_FOG
;
152 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
153 v0
->fog
, v1
->fog
, line
.fPlane
);
156 line
.span
.arrayMask
|= SPAN_RGBA
;
157 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
158 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
159 v0
->color
[RCOMP
], v1
->color
[RCOMP
], line
.rPlane
);
160 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
161 v0
->color
[GCOMP
], v1
->color
[GCOMP
], line
.gPlane
);
162 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
163 v0
->color
[BCOMP
], v1
->color
[BCOMP
], line
.bPlane
);
164 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
165 v0
->color
[ACOMP
], v1
->color
[ACOMP
], line
.aPlane
);
168 constant_plane(v1
->color
[RCOMP
], line
.rPlane
);
169 constant_plane(v1
->color
[GCOMP
], line
.gPlane
);
170 constant_plane(v1
->color
[BCOMP
], line
.bPlane
);
171 constant_plane(v1
->color
[ACOMP
], line
.aPlane
);
175 line
.span
.arrayMask
|= SPAN_SPEC
;
176 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
177 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
178 v0
->specular
[RCOMP
], v1
->specular
[RCOMP
], line
.srPlane
);
179 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
180 v0
->specular
[GCOMP
], v1
->specular
[GCOMP
], line
.sgPlane
);
181 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
182 v0
->specular
[BCOMP
], v1
->specular
[BCOMP
], line
.sbPlane
);
185 constant_plane(v1
->specular
[RCOMP
], line
.srPlane
);
186 constant_plane(v1
->specular
[GCOMP
], line
.sgPlane
);
187 constant_plane(v1
->specular
[BCOMP
], line
.sbPlane
);
191 line
.span
.arrayMask
|= SPAN_INDEX
;
192 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
193 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
194 (GLfloat
) v0
->index
, (GLfloat
) v1
->index
, line
.iPlane
);
197 constant_plane((GLfloat
) v1
->index
, line
.iPlane
);
202 const struct gl_texture_object
*obj
= ctx
->Texture
.Unit
[0]._Current
;
203 const struct gl_texture_image
*texImage
= obj
->Image
[0][obj
->BaseLevel
];
204 const GLfloat invW0
= v0
->win
[3];
205 const GLfloat invW1
= v1
->win
[3];
206 const GLfloat s0
= v0
->texcoord
[0][0] * invW0
;
207 const GLfloat s1
= v1
->texcoord
[0][0] * invW1
;
208 const GLfloat t0
= v0
->texcoord
[0][1] * invW0
;
209 const GLfloat t1
= v1
->texcoord
[0][1] * invW0
;
210 const GLfloat r0
= v0
->texcoord
[0][2] * invW0
;
211 const GLfloat r1
= v1
->texcoord
[0][2] * invW0
;
212 const GLfloat q0
= v0
->texcoord
[0][3] * invW0
;
213 const GLfloat q1
= v1
->texcoord
[0][3] * invW0
;
214 line
.span
.arrayMask
|= (SPAN_TEXTURE
| SPAN_LAMBDA
);
215 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
, s0
, s1
, line
.sPlane
[0]);
216 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
, t0
, t1
, line
.tPlane
[0]);
217 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
, r0
, r1
, line
.uPlane
[0]);
218 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
, q0
, q1
, line
.vPlane
[0]);
219 line
.texWidth
[0] = (GLfloat
) texImage
->Width
;
220 line
.texHeight
[0] = (GLfloat
) texImage
->Height
;
222 #elif defined(DO_MULTITEX)
225 line
.span
.arrayMask
|= (SPAN_TEXTURE
| SPAN_LAMBDA
);
226 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
227 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
228 const struct gl_texture_object
*obj
= ctx
->Texture
.Unit
[u
]._Current
;
229 const struct gl_texture_image
*texImage
= obj
->Image
[0][obj
->BaseLevel
];
230 const GLfloat invW0
= v0
->win
[3];
231 const GLfloat invW1
= v1
->win
[3];
232 const GLfloat s0
= v0
->texcoord
[u
][0] * invW0
;
233 const GLfloat s1
= v1
->texcoord
[u
][0] * invW1
;
234 const GLfloat t0
= v0
->texcoord
[u
][1] * invW0
;
235 const GLfloat t1
= v1
->texcoord
[u
][1] * invW0
;
236 const GLfloat r0
= v0
->texcoord
[u
][2] * invW0
;
237 const GLfloat r1
= v1
->texcoord
[u
][2] * invW0
;
238 const GLfloat q0
= v0
->texcoord
[u
][3] * invW0
;
239 const GLfloat q1
= v1
->texcoord
[u
][3] * invW0
;
240 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
, s0
, s1
, line
.sPlane
[u
]);
241 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
, t0
, t1
, line
.tPlane
[u
]);
242 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
, r0
, r1
, line
.uPlane
[u
]);
243 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
, q0
, q1
, line
.vPlane
[u
]);
244 line
.texWidth
[u
] = (GLfloat
) texImage
->Width
;
245 line
.texHeight
[u
] = (GLfloat
) texImage
->Height
;
252 inSegment
= GL_FALSE
;
253 iLen
= (GLint
) line
.len
;
255 if (ctx
->Line
.StippleFlag
) {
256 for (i
= 0; i
< iLen
; i
++) {
257 const GLuint bit
= (swrast
->StippleCounter
/ ctx
->Line
.StippleFactor
) & 0xf;
258 if ((1 << bit
) & ctx
->Line
.StipplePattern
) {
259 /* stipple bit is on */
260 const GLfloat t
= (GLfloat
) i
/ (GLfloat
) line
.len
;
262 /* start new segment */
267 /* still in the segment, extend it */
272 /* stipple bit is off */
273 if (inSegment
&& (tEnd
> tStart
)) {
274 /* draw the segment */
275 segment(ctx
, &line
, NAME(plot
), tStart
, tEnd
);
276 inSegment
= GL_FALSE
;
279 /* still between segments, do nothing */
282 swrast
->StippleCounter
++;
286 /* draw the final segment of the line */
287 segment(ctx
, &line
, NAME(plot
), tStart
, 1.0F
);
292 segment(ctx
, &line
, NAME(plot
), 0.0, 1.0);
295 #if defined(DO_TEX) || defined(DO_MULTITEX)
296 _swrast_write_texture_span(ctx
, &(line
.span
));
297 #elif defined(DO_RGBA)
298 _swrast_write_rgba_span(ctx
, &(line
.span
));
300 _swrast_write_index_span(ctx
, &(line
.span
));