2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 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.
31 #include "s_context.h"
33 #include "s_feedback.h"
39 * Init the mask[] array to implement a line stipple.
42 compute_stipple_mask( GLcontext
*ctx
, GLuint len
, GLubyte mask
[] )
44 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
47 for (i
= 0; i
< len
; i
++) {
48 GLuint bit
= (swrast
->StippleCounter
/ ctx
->Line
.StippleFactor
) & 0xf;
49 if ((1 << bit
) & ctx
->Line
.StipplePattern
) {
55 swrast
->StippleCounter
++;
61 * To draw a wide line we can simply redraw the span N times, side by side.
64 draw_wide_line( GLcontext
*ctx
, struct sw_span
*span
, GLboolean xMajor
)
68 ASSERT(span
->end
< MAX_WIDTH
);
70 width
= (GLint
) CLAMP( ctx
->Line
._Width
, MIN_LINE_WIDTH
, MAX_LINE_WIDTH
);
75 start
= width
/ 2 - 1;
78 GLint
*y
= span
->array
->y
;
81 for (w
= 0; w
< width
; w
++) {
83 for (i
= 0; i
< span
->end
; i
++)
87 for (i
= 0; i
< span
->end
; i
++)
90 if (ctx
->Visual
.rgbMode
)
91 _swrast_write_rgba_span(ctx
, span
);
93 _swrast_write_index_span(ctx
, span
);
97 GLint
*x
= span
->array
->x
;
100 for (w
= 0; w
< width
; w
++) {
102 for (i
= 0; i
< span
->end
; i
++)
106 for (i
= 0; i
< span
->end
; i
++)
109 if (ctx
->Visual
.rgbMode
)
110 _swrast_write_rgba_span(ctx
, span
);
112 _swrast_write_index_span(ctx
, span
);
119 /**********************************************************************/
120 /***** Rasterization *****/
121 /**********************************************************************/
123 /* Simple color index line (no stipple, width=1, no Z, no fog, no tex)*/
124 #define NAME simple_ci_line
126 #define RENDER_SPAN(span) _swrast_write_index_span(ctx, &span)
127 #include "s_linetemp.h"
129 /* Simple RGBA index line (no stipple, width=1, no Z, no fog, no tex)*/
130 #define NAME simple_rgba_line
132 #define RENDER_SPAN(span) _swrast_write_rgba_span(ctx, &span);
133 #include "s_linetemp.h"
136 /* Z, fog, wide, stipple color index line */
137 #define NAME general_ci_line
141 #define RENDER_SPAN(span) \
142 if (ctx->Line.StippleFlag) { \
143 span.arrayMask |= SPAN_MASK; \
144 compute_stipple_mask(ctx, span.end, span.array->mask); \
146 if (ctx->Line._Width > 1.0) { \
147 draw_wide_line(ctx, &span, (GLboolean)(dx > dy)); \
150 _swrast_write_index_span(ctx, &span); \
152 #include "s_linetemp.h"
155 /* Z, fog, wide, stipple RGBA line */
156 #define NAME general_rgba_line
160 #define RENDER_SPAN(span) \
161 if (ctx->Line.StippleFlag) { \
162 span.arrayMask |= SPAN_MASK; \
163 compute_stipple_mask(ctx, span.end, span.array->mask); \
165 if (ctx->Line._Width > 1.0) { \
166 draw_wide_line(ctx, &span, (GLboolean)(dx > dy)); \
169 _swrast_write_rgba_span(ctx, &span); \
171 #include "s_linetemp.h"
174 /* Single-texture line, w/ fog, Z, specular, etc. */
175 #define NAME textured_line
180 #define RENDER_SPAN(span) \
181 if (ctx->Line.StippleFlag) { \
182 span.arrayMask |= SPAN_MASK; \
183 compute_stipple_mask(ctx, span.end, span.array->mask); \
185 if (ctx->Line._Width > 1.0) { \
186 draw_wide_line(ctx, &span, (GLboolean)(dx > dy)); \
189 _swrast_write_rgba_span(ctx, &span); \
191 #include "s_linetemp.h"
194 /* Multi-texture or separate specular line, w/ fog, Z, specular, etc. */
195 #define NAME multitextured_line
200 #define INTERP_MULTITEX
201 #define RENDER_SPAN(span) \
202 if (ctx->Line.StippleFlag) { \
203 span.arrayMask |= SPAN_MASK; \
204 compute_stipple_mask(ctx, span.end, span.array->mask); \
206 if (ctx->Line._Width > 1.0) { \
207 draw_wide_line(ctx, &span, (GLboolean)(dx > dy)); \
210 _swrast_write_rgba_span(ctx, &span); \
212 #include "s_linetemp.h"
217 _swrast_add_spec_terms_line( GLcontext
*ctx
,
221 SWvertex
*ncv0
= (SWvertex
*)v0
;
222 SWvertex
*ncv1
= (SWvertex
*)v1
;
224 COPY_CHAN4( c
[0], ncv0
->color
);
225 COPY_CHAN4( c
[1], ncv1
->color
);
226 ACC_3V( ncv0
->color
, ncv0
->specular
);
227 ACC_3V( ncv1
->color
, ncv1
->specular
);
228 SWRAST_CONTEXT(ctx
)->SpecLine( ctx
, ncv0
, ncv1
);
229 COPY_CHAN4( ncv0
->color
, c
[0] );
230 COPY_CHAN4( ncv1
->color
, c
[1] );
236 _mesa_print_line_function(GLcontext
*ctx
); /* silence compiler warning */
238 _mesa_print_line_function(GLcontext
*ctx
)
240 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
242 _mesa_printf("Line Func == ");
243 if (swrast
->Line
== simple_ci_line
)
244 _mesa_printf("simple_ci_line\n");
245 else if (swrast
->Line
== simple_rgba_line
)
246 _mesa_printf("simple_rgba_line\n");
247 else if (swrast
->Line
== general_ci_line
)
248 _mesa_printf("general_ci_line\n");
249 else if (swrast
->Line
== general_rgba_line
)
250 _mesa_printf("general_rgba_line\n");
251 else if (swrast
->Line
== textured_line
)
252 _mesa_printf("textured_line\n");
253 else if (swrast
->Line
== multitextured_line
)
254 _mesa_printf("multitextured_line\n");
256 _mesa_printf("Driver func %p\n", (void *(*)()) swrast
->Line
);
264 /* record the current line function name */
265 static const char *lineFuncName
= NULL
;
267 #define USE(lineFunc) \
269 lineFuncName = #lineFunc; \
270 /*_mesa_printf("%s\n", lineFuncName);*/ \
271 swrast->Line = lineFunc; \
276 #define USE(lineFunc) swrast->Line = lineFunc
283 * Determine which line drawing function to use given the current
286 * Please update the summary flag _SWRAST_NEW_LINE if you add or remove
287 * tests to this code.
290 _swrast_choose_line( GLcontext
*ctx
)
292 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
293 const GLboolean rgbmode
= ctx
->Visual
.rgbMode
;
295 if (ctx
->RenderMode
== GL_RENDER
) {
296 if (ctx
->Line
.SmoothFlag
) {
297 /* antialiased lines */
298 _swrast_choose_aa_line_function(ctx
);
299 ASSERT(swrast
->Line
);
301 else if (ctx
->Texture
._EnabledCoordUnits
) {
303 if (ctx
->Texture
._EnabledCoordUnits
> 0x1
304 || NEED_SECONDARY_COLOR(ctx
)) {
305 /* multi-texture and/or separate specular color */
306 USE(multitextured_line
);
312 else if (ctx
->Depth
.Test
|| swrast
->_FogEnabled
|| ctx
->Line
._Width
!= 1.0
313 || ctx
->Line
.StippleFlag
) {
314 /* no texture, but Z, fog, width>1, stipple, etc. */
316 USE(general_rgba_line
);
318 USE(general_ci_line
);
323 USE(simple_rgba_line
);
328 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
329 USE(_swrast_feedback_line
);
332 ASSERT(ctx
->RenderMode
== GL_SELECT
);
333 USE(_swrast_select_line
);
336 /*_mesa_print_line_function(ctx);*/