2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
26 #include "main/glheader.h"
27 #include "main/context.h"
28 #include "main/macros.h"
30 #include "s_context.h"
31 #include "s_feedback.h"
37 * Init the mask[] array to implement a line stipple.
40 compute_stipple_mask( struct gl_context
*ctx
, GLuint len
, GLubyte mask
[] )
42 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
45 for (i
= 0; i
< len
; i
++) {
46 GLuint bit
= (swrast
->StippleCounter
/ ctx
->Line
.StippleFactor
) & 0xf;
47 if ((1 << bit
) & ctx
->Line
.StipplePattern
) {
53 swrast
->StippleCounter
++;
59 * To draw a wide line we can simply redraw the span N times, side by side.
62 draw_wide_line( struct gl_context
*ctx
, SWspan
*span
, GLboolean xMajor
)
64 const GLint width
= (GLint
) CLAMP(ctx
->Line
.Width
,
65 ctx
->Const
.MinLineWidth
,
66 ctx
->Const
.MaxLineWidth
);
69 assert(span
->end
< SWRAST_MAX_WIDTH
);
74 start
= width
/ 2 - 1;
77 GLint
*y
= span
->array
->y
;
80 for (w
= 0; w
< width
; w
++) {
82 for (i
= 0; i
< span
->end
; i
++)
86 for (i
= 0; i
< span
->end
; i
++)
89 _swrast_write_rgba_span(ctx
, span
);
93 GLint
*x
= span
->array
->x
;
96 for (w
= 0; w
< width
; w
++) {
98 for (i
= 0; i
< span
->end
; i
++)
102 for (i
= 0; i
< span
->end
; i
++)
105 _swrast_write_rgba_span(ctx
, span
);
112 /**********************************************************************/
113 /***** Rasterization *****/
114 /**********************************************************************/
116 /* Simple RGBA index line (no stipple, width=1, no Z, no fog, no tex)*/
117 #define NAME simple_no_z_rgba_line
119 #define RENDER_SPAN(span) _swrast_write_rgba_span(ctx, &span);
120 #include "s_linetemp.h"
123 /* Z, fog, wide, stipple RGBA line */
124 #define NAME rgba_line
127 #define RENDER_SPAN(span) \
128 if (ctx->Line.StippleFlag) { \
129 span.arrayMask |= SPAN_MASK; \
130 compute_stipple_mask(ctx, span.end, span.array->mask); \
132 if (ctx->Line.Width > 1.0) { \
133 draw_wide_line(ctx, &span, (GLboolean)(dx > dy)); \
136 _swrast_write_rgba_span(ctx, &span); \
138 #include "s_linetemp.h"
141 /* General-purpose line (any/all features). */
142 #define NAME general_line
145 #define INTERP_ATTRIBS
146 #define RENDER_SPAN(span) \
147 if (ctx->Line.StippleFlag) { \
148 span.arrayMask |= SPAN_MASK; \
149 compute_stipple_mask(ctx, span.end, span.array->mask); \
151 if (ctx->Line.Width > 1.0) { \
152 draw_wide_line(ctx, &span, (GLboolean)(dx > dy)); \
155 _swrast_write_rgba_span(ctx, &span); \
157 #include "s_linetemp.h"
162 _swrast_add_spec_terms_line(struct gl_context
*ctx
,
163 const SWvertex
*v0
, const SWvertex
*v1
)
165 SWvertex
*ncv0
= (SWvertex
*)v0
;
166 SWvertex
*ncv1
= (SWvertex
*)v1
;
167 GLfloat rSum
, gSum
, bSum
;
170 /* save original colors */
171 COPY_CHAN4(cSave
[0], ncv0
->color
);
172 COPY_CHAN4(cSave
[1], ncv1
->color
);
174 rSum
= CHAN_TO_FLOAT(ncv0
->color
[0]) + ncv0
->attrib
[VARYING_SLOT_COL1
][0];
175 gSum
= CHAN_TO_FLOAT(ncv0
->color
[1]) + ncv0
->attrib
[VARYING_SLOT_COL1
][1];
176 bSum
= CHAN_TO_FLOAT(ncv0
->color
[2]) + ncv0
->attrib
[VARYING_SLOT_COL1
][2];
177 UNCLAMPED_FLOAT_TO_CHAN(ncv0
->color
[0], rSum
);
178 UNCLAMPED_FLOAT_TO_CHAN(ncv0
->color
[1], gSum
);
179 UNCLAMPED_FLOAT_TO_CHAN(ncv0
->color
[2], bSum
);
181 rSum
= CHAN_TO_FLOAT(ncv1
->color
[0]) + ncv1
->attrib
[VARYING_SLOT_COL1
][0];
182 gSum
= CHAN_TO_FLOAT(ncv1
->color
[1]) + ncv1
->attrib
[VARYING_SLOT_COL1
][1];
183 bSum
= CHAN_TO_FLOAT(ncv1
->color
[2]) + ncv1
->attrib
[VARYING_SLOT_COL1
][2];
184 UNCLAMPED_FLOAT_TO_CHAN(ncv1
->color
[0], rSum
);
185 UNCLAMPED_FLOAT_TO_CHAN(ncv1
->color
[1], gSum
);
186 UNCLAMPED_FLOAT_TO_CHAN(ncv1
->color
[2], bSum
);
188 SWRAST_CONTEXT(ctx
)->SpecLine( ctx
, ncv0
, ncv1
);
189 /* restore original colors */
190 COPY_CHAN4(ncv0
->color
, cSave
[0]);
191 COPY_CHAN4(ncv1
->color
, cSave
[1]);
198 /* record the current line function name */
199 static const char *lineFuncName
= NULL
;
201 #define USE(lineFunc) \
203 lineFuncName = #lineFunc; \
204 /*printf("%s\n", lineFuncName);*/ \
205 swrast->Line = lineFunc; \
210 #define USE(lineFunc) swrast->Line = lineFunc
217 * Determine which line drawing function to use given the current
220 * Please update the summary flag _SWRAST_NEW_LINE if you add or remove
221 * tests to this code.
224 _swrast_choose_line( struct gl_context
*ctx
)
226 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
227 GLboolean specular
= (ctx
->Fog
.ColorSumEnabled
||
228 (ctx
->Light
.Enabled
&&
229 ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
));
231 if (ctx
->RenderMode
== GL_RENDER
) {
232 if (ctx
->Line
.SmoothFlag
) {
233 /* antialiased lines */
234 _swrast_choose_aa_line_function(ctx
);
235 assert(swrast
->Line
);
237 else if (ctx
->Texture
._EnabledCoordUnits
238 || _swrast_use_fragment_program(ctx
)
239 || swrast
->_FogEnabled
243 else if (ctx
->Depth
.Test
244 || ctx
->Line
.Width
!= 1.0F
245 || ctx
->Line
.StippleFlag
) {
246 /* no texture, but Z, fog, width>1, stipple, etc. */
254 assert(!ctx
->Depth
.Test
);
255 assert(ctx
->Line
.Width
== 1.0F
);
257 USE(simple_no_z_rgba_line
);
260 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
261 USE(_swrast_feedback_line
);
264 assert(ctx
->RenderMode
== GL_SELECT
);
265 USE(_swrast_select_line
);