2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
27 * Antialiased line template.
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
37 NAME(plot
)(GLcontext
*ctx
, struct LineInfo
*line
, int ix
, int iy
)
39 const GLfloat fx
= (GLfloat
) ix
;
40 const GLfloat fy
= (GLfloat
) iy
;
42 const GLfloat coverage
= compute_coveragei(line
, ix
, iy
);
44 const GLfloat coverage
= compute_coveragef(line
, ix
, iy
);
46 const GLuint i
= line
->span
.end
;
52 line
->span
.array
->coverage
[i
] = coverage
;
53 line
->span
.array
->x
[i
] = ix
;
54 line
->span
.array
->y
[i
] = iy
;
57 * Compute Z, color, texture coords, fog for the fragment by
58 * solving the plane equations at (ix,iy).
61 line
->span
.array
->z
[i
] = (GLdepth
) IROUND(solve_plane(fx
, fy
, line
->zPlane
));
64 line
->span
.array
->fog
[i
] = solve_plane(fx
, fy
, line
->fPlane
);
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
);
73 line
->span
.array
->index
[i
] = (GLint
) solve_plane(fx
, fy
, line
->iPlane
);
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
);
83 if (ctx
->FragmentProgram
._Active
) {
87 invQ
= solve_plane_recip(fx
, fy
, line
->vPlane
[0]);
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
,
97 #elif defined(DO_MULTITEX)
100 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
101 if (ctx
->Texture
.Unit
[unit
]._ReallyEnabled
) {
103 if (ctx
->FragmentProgram
._Active
) {
107 invQ
= solve_plane_recip(fx
, fy
, line
->vPlane
[unit
]);
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
]);
120 if (line
->span
.end
== MAX_WIDTH
) {
122 _swrast_write_rgba_span(ctx
, &(line
->span
));
124 _swrast_write_index_span(ctx
, &(line
->span
));
126 line
->span
.end
= 0; /* reset counter */
136 NAME(line
)(GLcontext
*ctx
, const SWvertex
*v0
, const SWvertex
*v1
)
138 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
139 GLfloat tStart
, tEnd
; /* segment start, end along line length */
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
;
154 if (line
.len
== 0.0 || IS_INF_OR_NAN(line
.len
))
157 INIT_SPAN(line
.span
, GL_LINE
, 0, 0, SPAN_XY
| SPAN_COVERAGE
);
159 line
.xAdj
= line
.dx
/ line
.len
* line
.halfWidth
;
160 line
.yAdj
= line
.dy
/ line
.len
* line
.halfWidth
;
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
);
168 line
.span
.arrayMask
|= SPAN_FOG
;
169 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
170 v0
->fog
, v1
->fog
, line
.fPlane
);
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
);
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
);
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
);
202 constant_plane(v1
->specular
[RCOMP
], line
.srPlane
);
203 constant_plane(v1
->specular
[GCOMP
], line
.sgPlane
);
204 constant_plane(v1
->specular
[BCOMP
], line
.sbPlane
);
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
);
214 constant_plane(v1
->index
, line
.iPlane
);
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
;
239 #elif defined(DO_MULTITEX)
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
;
269 inSegment
= GL_FALSE
;
270 iLen
= (GLint
) line
.len
;
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
;
279 /* start new segment */
284 /* still in the segment, extend it */
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
;
296 /* still between segments, do nothing */
299 swrast
->StippleCounter
++;
303 /* draw the final segment of the line */
304 segment(ctx
, &line
, NAME(plot
), tStart
, 1.0F
);
309 segment(ctx
, &line
, NAME(plot
), 0.0, 1.0);
313 _swrast_write_rgba_span(ctx
, &(line
.span
));
315 _swrast_write_index_span(ctx
, &(line
.span
));