996784dde4a461be5ec8a40acd08ee0621f0ee51
1 /* $Id: s_aalinetemp.h,v 1.10 2001/05/15 21:30:26 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
29 * Antialiased line template.
34 * Function to render each fragment in the AA line.
37 NAME(plot
)(GLcontext
*ctx
, const struct LineInfo
*line
,
38 struct pixel_buffer
*pb
, int ix
, int iy
)
40 const GLfloat fx
= (GLfloat
) ix
;
41 const GLfloat fy
= (GLfloat
) iy
;
42 const GLfloat coverage
= compute_coveragef(line
, ix
, iy
);
46 GLchan red
, green
, blue
, alpha
;
50 GLchan specRed
, specGreen
, specBlue
;
51 GLfloat tex
[MAX_TEXTURE_UNITS
][4], lambda
[MAX_TEXTURE_UNITS
];
57 * Compute Z, color, texture coords, fog for the fragment by
58 * solving the plane equations at (ix,iy).
61 z
= (GLdepth
) solve_plane(fx
, fy
, line
->zPlane
);
66 fog
= solve_plane(fx
, fy
, line
->fPlane
);
71 red
= solve_plane_chan(fx
, fy
, line
->rPlane
);
72 green
= solve_plane_chan(fx
, fy
, line
->gPlane
);
73 blue
= solve_plane_chan(fx
, fy
, line
->bPlane
);
74 alpha
= solve_plane_chan(fx
, fy
, line
->aPlane
);
77 index
= (GLint
) solve_plane(fx
, fy
, line
->iPlane
);
82 specRed
= solve_plane_chan(fx
, fy
, line
->srPlane
);
83 specGreen
= solve_plane_chan(fx
, fy
, line
->sgPlane
);
84 specBlue
= solve_plane_chan(fx
, fy
, line
->sbPlane
);
92 GLfloat invQ
= solve_plane_recip(fx
, fy
, line
->vPlane
[0]);
93 tex
[0][0] = solve_plane(fx
, fy
, line
->sPlane
[0]) * invQ
;
94 tex
[0][1] = solve_plane(fx
, fy
, line
->tPlane
[0]) * invQ
;
95 tex
[0][2] = solve_plane(fx
, fy
, line
->uPlane
[0]) * invQ
;
96 lambda
[0] = compute_lambda(line
->sPlane
[0], line
->tPlane
[0], invQ
,
97 line
->texWidth
[0], line
->texHeight
[0]);
99 #elif defined(DO_MULTITEX)
102 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
103 if (ctx
->Texture
.Unit
[unit
]._ReallyEnabled
) {
104 GLfloat invQ
= solve_plane_recip(fx
, fy
, line
->vPlane
[unit
]);
105 tex
[unit
][0] = solve_plane(fx
, fy
, line
->sPlane
[unit
]) * invQ
;
106 tex
[unit
][1] = solve_plane(fx
, fy
, line
->tPlane
[unit
]) * invQ
;
107 tex
[unit
][2] = solve_plane(fx
, fy
, line
->uPlane
[unit
]) * invQ
;
108 lambda
[unit
] = compute_lambda(line
->sPlane
[unit
],
109 line
->tPlane
[unit
], invQ
,
110 line
->texWidth
[unit
], line
->texHeight
[unit
]);
120 PB_COVERAGE(pb
, coverage
);
122 #if defined(DO_MULTITEX)
124 PB_WRITE_MULTITEX_SPEC_PIXEL(pb
, ix
, iy
, z
, fog
, red
, green
, blue
, alpha
,
125 specRed
, specGreen
, specBlue
, tex
);
127 PB_WRITE_MULTITEX_PIXEL(pb
, ix
, iy
, z
, fog
, red
, green
, blue
, alpha
, texcoords
);
129 #elif defined(DO_TEX)
130 PB_WRITE_TEX_PIXEL(pb
, ix
, iy
, z
, fog
, red
, green
, blue
, alpha
,
131 tex
[0][0], tex
[0][1], tex
[0][2]);
132 #elif defined(DO_RGBA)
133 PB_WRITE_RGBA_PIXEL(pb
, ix
, iy
, z
, fog
, red
, green
, blue
, alpha
);
134 #elif defined(DO_INDEX)
135 PB_WRITE_CI_PIXEL(pb
, ix
, iy
, z
, fog
, index
);
138 pb
->haveCoverage
= GL_TRUE
;
139 PB_CHECK_FLUSH(ctx
, pb
);
148 NAME(line
)(GLcontext
*ctx
, const SWvertex
*v0
, const SWvertex
*v1
)
150 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
151 struct pixel_buffer
*pb
= SWRAST_CONTEXT(ctx
)->PB
;
152 GLfloat tStart
, tEnd
; /* segment start, end along line length */
156 /* Init the LineInfo struct */
157 struct LineInfo line
;
158 line
.x0
= v0
->win
[0];
159 line
.y0
= v0
->win
[1];
160 line
.x1
= v1
->win
[0];
161 line
.y1
= v1
->win
[1];
162 line
.dx
= line
.x1
- line
.x0
;
163 line
.dy
= line
.y1
- line
.y0
;
164 line
.len
= sqrt(line
.dx
* line
.dx
+ line
.dy
* line
.dy
);
165 line
.halfWidth
= 0.5F
* ctx
->Line
.Width
;
170 line
.xAdj
= line
.dx
/ line
.len
* line
.halfWidth
;
171 line
.yAdj
= line
.dy
/ line
.len
* line
.halfWidth
;
174 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
175 v0
->win
[2], v1
->win
[2], line
.zPlane
);
178 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
179 v0
->fog
, v1
->fog
, line
.fPlane
);
182 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
183 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
184 v0
->color
[RCOMP
], v1
->color
[RCOMP
], line
.rPlane
);
185 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
186 v0
->color
[GCOMP
], v1
->color
[GCOMP
], line
.gPlane
);
187 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
188 v0
->color
[BCOMP
], v1
->color
[BCOMP
], line
.bPlane
);
189 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
190 v0
->color
[ACOMP
], v1
->color
[ACOMP
], line
.aPlane
);
193 constant_plane(v1
->color
[RCOMP
], line
.rPlane
);
194 constant_plane(v1
->color
[GCOMP
], line
.gPlane
);
195 constant_plane(v1
->color
[BCOMP
], line
.bPlane
);
196 constant_plane(v1
->color
[ACOMP
], line
.aPlane
);
200 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
201 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
202 v0
->specular
[RCOMP
], v1
->specular
[RCOMP
], line
.srPlane
);
203 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
204 v0
->specular
[GCOMP
], v1
->specular
[GCOMP
], line
.sgPlane
);
205 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
206 v0
->specular
[BCOMP
], v1
->specular
[BCOMP
], line
.sbPlane
);
209 constant_plane(v1
->specular
[RCOMP
], line
.srPlane
);
210 constant_plane(v1
->specular
[GCOMP
], line
.sgPlane
);
211 constant_plane(v1
->specular
[BCOMP
], line
.sbPlane
);
215 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
216 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
,
217 v0
->index
, v1
->index
, line
.iPlane
);
220 constant_plane(v1
->index
, line
.iPlane
);
225 const struct gl_texture_object
*obj
= ctx
->Texture
.Unit
[0]._Current
;
226 const struct gl_texture_image
*texImage
= obj
->Image
[obj
->BaseLevel
];
227 const GLfloat invW0
= v0
->win
[3];
228 const GLfloat invW1
= v1
->win
[3];
229 const GLfloat s0
= v0
->texcoord
[0][0] * invW0
;
230 const GLfloat s1
= v1
->texcoord
[0][0] * invW1
;
231 const GLfloat t0
= v0
->texcoord
[0][1] * invW0
;
232 const GLfloat t1
= v1
->texcoord
[0][1] * invW0
;
233 const GLfloat r0
= v0
->texcoord
[0][2] * invW0
;
234 const GLfloat r1
= v1
->texcoord
[0][2] * invW0
;
235 const GLfloat q0
= v0
->texcoord
[0][3] * invW0
;
236 const GLfloat q1
= v1
->texcoord
[0][3] * invW0
;
237 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
, s0
, s1
, line
.sPlane
[0]);
238 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
, t0
, t1
, line
.tPlane
[0]);
239 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
, r0
, r1
, line
.uPlane
[0]);
240 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
, q0
, q1
, line
.vPlane
[0]);
241 line
.texWidth
[0] = (GLfloat
) texImage
->Width
;
242 line
.texHeight
[0] = (GLfloat
) texImage
->Height
;
244 #elif defined(DO_MULITEX)
247 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
248 if (ctx
->Texture
.Unit
[u
].ReallyEnabled
) {
249 const struct gl_texture_object
*obj
= ctx
->Texture
.Unit
[u
].Current
;
250 const struct gl_texture_image
*texImage
= obj
->Image
[obj
->BaseLevel
];
251 const GLfloat invW0
= v0
->win
[3];
252 const GLfloat invW1
= v1
->win
[3];
253 GLfloat (*texCoord
)[4] = VB
->TexCoordPtr
[u
]->data
;
254 const GLfloat s0
= v0
->texcoord
[u
][0] * invW0
;
255 const GLfloat s1
= v1
->texcoord
[u
][0] * invW1
;
256 const GLfloat t0
= v0
->texcoord
[u
][1] * invW0
;
257 const GLfloat t1
= v1
->texcoord
[u
][1] * invW0
;
258 const GLfloat r0
= v0
->texcoord
[u
][2] * invW0
;
259 const GLfloat r1
= v1
->texcoord
[u
][2] * invW0
;
260 const GLfloat q0
= v0
->texcoord
[u
][3] * invW0
;
261 const GLfloat q1
= v1
->texcoord
[u
][3] * invW0
;
262 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
, s0
, s1
, line
.sPlane
[u
]);
263 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
, t0
, t1
, line
.tPlane
[u
]);
264 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
, u0
, u1
, line
.uPlane
[u
]);
265 compute_plane(line
.x0
, line
.y0
, line
.x1
, line
.y1
, v0
, v1
, line
.vPlane
[u
]);
266 line
.texWidth
[u
] = (GLfloat
) texImage
->Width
;
267 line
.texHeight
[u
] = (GLfloat
) texImage
->Height
;
274 inSegment
= GL_FALSE
;
275 iLen
= (GLint
) line
.len
;
277 if (ctx
->Line
.StippleFlag
) {
278 for (i
= 0; i
< iLen
; i
++) {
279 const GLuint bit
= (swrast
->StippleCounter
/ ctx
->Line
.StippleFactor
) & 0xf;
280 if ((1 << bit
) & ctx
->Line
.StipplePattern
) {
281 /* stipple bit is on */
282 const GLfloat t
= (GLfloat
) i
/ (GLfloat
) line
.len
;
284 /* start new segment */
289 /* still in the segment, extend it */
294 /* stipple bit is off */
295 if (inSegment
&& (tEnd
> tStart
)) {
296 /* draw the segment */
297 segment(ctx
, &line
, NAME(plot
), pb
, tStart
, tEnd
);
298 inSegment
= GL_FALSE
;
301 /* still between segments, do nothing */
304 swrast
->StippleCounter
++;
308 /* draw the final segment of the line */
309 segment(ctx
, &line
, NAME(plot
), pb
, tStart
, 1.0F
);
314 segment(ctx
, &line
, NAME(plot
), pb
, 0.0, 1.0);