7a8ab7a4412a903702c69b51d84eeddaf8969ad7
[reactos.git] / reactos / dll / opengl / mesa / swrast / s_aalinetemp.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.1
4 *
5 * Copyright (C) 1999-2007 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)(struct gl_context *ctx, struct LineInfo *line, int ix, int iy)
38 {
39 const SWcontext *swrast = SWRAST_CONTEXT(ctx);
40 const GLfloat fx = (GLfloat) ix;
41 const GLfloat fy = (GLfloat) iy;
42 const GLfloat coverage = compute_coveragef(line, ix, iy);
43 const GLuint i = line->span.end;
44
45 (void) swrast;
46
47 if (coverage == 0.0)
48 return;
49
50 line->span.end++;
51 line->span.array->coverage[i] = coverage;
52 line->span.array->x[i] = ix;
53 line->span.array->y[i] = iy;
54
55 /*
56 * Compute Z, color, texture coords, fog for the fragment by
57 * solving the plane equations at (ix,iy).
58 */
59 #ifdef DO_Z
60 line->span.array->z[i] = (GLuint) solve_plane(fx, fy, line->zPlane);
61 #endif
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);
66 #if defined(DO_ATTRIBS)
67 ATTRIB_LOOP_BEGIN
68 GLfloat (*attribArray)[4] = line->span.array->attribs[attr];
69 if (attr == FRAG_ATTRIB_TEX) {
70 /* texcoord w/ divide by Q */
71 const GLfloat invQ = solve_plane_recip(fx, fy, line->attrPlane[attr][3]);
72 GLuint c;
73 for (c = 0; c < 3; c++) {
74 attribArray[i][c] = solve_plane(fx, fy, line->attrPlane[attr][c]) * invQ;
75 }
76 line->span.array->lambda[i]
77 = compute_lambda(line->attrPlane[attr][0],
78 line->attrPlane[attr][1], invQ,
79 line->texWidth[attr], line->texHeight[attr]);
80 }
81 else {
82 /* non-texture attrib */
83 const GLfloat invW = solve_plane_recip(fx, fy, line->wPlane);
84 GLuint c;
85 for (c = 0; c < 4; c++) {
86 attribArray[i][c] = solve_plane(fx, fy, line->attrPlane[attr][c]) * invW;
87 }
88 }
89 ATTRIB_LOOP_END
90 #endif
91
92 if (line->span.end == MAX_WIDTH) {
93 _swrast_write_rgba_span(ctx, &(line->span));
94 line->span.end = 0; /* reset counter */
95 }
96 }
97
98
99
100 /*
101 * Line setup
102 */
103 static void
104 NAME(line)(struct gl_context *ctx, const SWvertex *v0, const SWvertex *v1)
105 {
106 SWcontext *swrast = SWRAST_CONTEXT(ctx);
107 GLfloat tStart, tEnd; /* segment start, end along line length */
108 GLboolean inSegment;
109 GLint iLen, i;
110
111 /* Init the LineInfo struct */
112 struct LineInfo line;
113 line.x0 = v0->attrib[FRAG_ATTRIB_WPOS][0];
114 line.y0 = v0->attrib[FRAG_ATTRIB_WPOS][1];
115 line.x1 = v1->attrib[FRAG_ATTRIB_WPOS][0];
116 line.y1 = v1->attrib[FRAG_ATTRIB_WPOS][1];
117 line.dx = line.x1 - line.x0;
118 line.dy = line.y1 - line.y0;
119 line.len = SQRTF(line.dx * line.dx + line.dy * line.dy);
120 line.halfWidth = 0.5F * CLAMP(ctx->Line.Width,
121 ctx->Const.MinLineWidthAA,
122 ctx->Const.MaxLineWidthAA);
123
124 if (line.len == 0.0 || IS_INF_OR_NAN(line.len))
125 return;
126
127 INIT_SPAN(line.span, GL_LINE);
128 line.span.arrayMask = SPAN_XY | SPAN_COVERAGE;
129 line.span.facing = swrast->PointLineFacing;
130 line.xAdj = line.dx / line.len * line.halfWidth;
131 line.yAdj = line.dy / line.len * line.halfWidth;
132
133 #ifdef DO_Z
134 line.span.arrayMask |= SPAN_Z;
135 compute_plane(line.x0, line.y0, line.x1, line.y1,
136 v0->attrib[FRAG_ATTRIB_WPOS][2], v1->attrib[FRAG_ATTRIB_WPOS][2], line.zPlane);
137 #endif
138 line.span.arrayMask |= SPAN_RGBA;
139 if (ctx->Light.ShadeModel == GL_SMOOTH) {
140 compute_plane(line.x0, line.y0, line.x1, line.y1,
141 v0->color[RCOMP], v1->color[RCOMP], line.rPlane);
142 compute_plane(line.x0, line.y0, line.x1, line.y1,
143 v0->color[GCOMP], v1->color[GCOMP], line.gPlane);
144 compute_plane(line.x0, line.y0, line.x1, line.y1,
145 v0->color[BCOMP], v1->color[BCOMP], line.bPlane);
146 compute_plane(line.x0, line.y0, line.x1, line.y1,
147 v0->color[ACOMP], v1->color[ACOMP], line.aPlane);
148 }
149 else {
150 constant_plane(v1->color[RCOMP], line.rPlane);
151 constant_plane(v1->color[GCOMP], line.gPlane);
152 constant_plane(v1->color[BCOMP], line.bPlane);
153 constant_plane(v1->color[ACOMP], line.aPlane);
154 }
155 #if defined(DO_ATTRIBS)
156 {
157 const GLfloat invW0 = v0->attrib[FRAG_ATTRIB_WPOS][3];
158 const GLfloat invW1 = v1->attrib[FRAG_ATTRIB_WPOS][3];
159 line.span.arrayMask |= SPAN_LAMBDA;
160 compute_plane(line.x0, line.y0, line.x1, line.y1, invW0, invW1, line.wPlane);
161 ATTRIB_LOOP_BEGIN
162 GLuint c;
163 if (swrast->_InterpMode[attr] == GL_FLAT) {
164 for (c = 0; c < 4; c++) {
165 constant_plane(v1->attrib[attr][c], line.attrPlane[attr][c]);
166 }
167 }
168 else {
169 for (c = 0; c < 4; c++) {
170 const GLfloat a0 = v0->attrib[attr][c] * invW0;
171 const GLfloat a1 = v1->attrib[attr][c] * invW1;
172 compute_plane(line.x0, line.y0, line.x1, line.y1, a0, a1,
173 line.attrPlane[attr][c]);
174 }
175 }
176 line.span.arrayAttribs |= BITFIELD64_BIT(attr);
177 if (attr == FRAG_ATTRIB_TEX) {
178 const struct gl_texture_object *obj = ctx->Texture.Unit._Current;
179 const struct gl_texture_image *texImage = obj->Image[0][obj->BaseLevel];
180 line.texWidth[attr] = (GLfloat) texImage->Width;
181 line.texHeight[attr] = (GLfloat) texImage->Height;
182 }
183 ATTRIB_LOOP_END
184 }
185 #endif
186
187 tStart = tEnd = 0.0;
188 inSegment = GL_FALSE;
189 iLen = (GLint) line.len;
190
191 if (ctx->Line.StippleFlag) {
192 for (i = 0; i < iLen; i++) {
193 const GLuint bit = (swrast->StippleCounter / ctx->Line.StippleFactor) & 0xf;
194 if ((1 << bit) & ctx->Line.StipplePattern) {
195 /* stipple bit is on */
196 const GLfloat t = (GLfloat) i / (GLfloat) line.len;
197 if (!inSegment) {
198 /* start new segment */
199 inSegment = GL_TRUE;
200 tStart = t;
201 }
202 else {
203 /* still in the segment, extend it */
204 tEnd = t;
205 }
206 }
207 else {
208 /* stipple bit is off */
209 if (inSegment && (tEnd > tStart)) {
210 /* draw the segment */
211 segment(ctx, &line, NAME(plot), tStart, tEnd);
212 inSegment = GL_FALSE;
213 }
214 else {
215 /* still between segments, do nothing */
216 }
217 }
218 swrast->StippleCounter++;
219 }
220
221 if (inSegment) {
222 /* draw the final segment of the line */
223 segment(ctx, &line, NAME(plot), tStart, 1.0F);
224 }
225 }
226 else {
227 /* non-stippled */
228 segment(ctx, &line, NAME(plot), 0.0, 1.0);
229 }
230
231 _swrast_write_rgba_span(ctx, &(line.span));
232 }
233
234
235
236
237 #undef DO_Z
238 #undef DO_ATTRIBS
239 #undef NAME