1 /* $Id: s_lines.c,v 1.33 2002/11/14 03:48:03 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 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.
33 #include "s_context.h"
35 #include "s_feedback.h"
41 * Init the mask[] array to implement a line stipple.
44 compute_stipple_mask( GLcontext
*ctx
, GLuint len
, GLubyte mask
[] )
46 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
49 for (i
= 0; i
< len
; i
++) {
50 GLuint bit
= (swrast
->StippleCounter
/ ctx
->Line
.StippleFactor
) & 0xf;
51 if ((1 << bit
) & ctx
->Line
.StipplePattern
) {
57 swrast
->StippleCounter
++;
63 * To draw a wide line we can simply redraw the span N times, side by side.
66 draw_wide_line( GLcontext
*ctx
, struct sw_span
*span
, GLboolean xMajor
)
70 ASSERT(span
->end
< MAX_WIDTH
);
72 width
= (GLint
) CLAMP( ctx
->Line
.Width
, MIN_LINE_WIDTH
, MAX_LINE_WIDTH
);
77 start
= width
/ 2 - 1;
80 GLint
*y
= span
->array
->y
;
83 for (w
= 0; w
< width
; w
++) {
85 for (i
= 0; i
< span
->end
; i
++)
89 for (i
= 0; i
< span
->end
; i
++)
92 if ((span
->interpMask
| span
->arrayMask
) & SPAN_TEXTURE
)
93 _mesa_write_texture_span(ctx
, span
);
94 else if ((span
->interpMask
| span
->arrayMask
) & SPAN_RGBA
)
95 _mesa_write_rgba_span(ctx
, span
);
97 _mesa_write_index_span(ctx
, span
);
101 GLint
*x
= span
->array
->x
;
104 for (w
= 0; w
< width
; w
++) {
106 for (i
= 0; i
< span
->end
; i
++)
110 for (i
= 0; i
< span
->end
; i
++)
113 if ((span
->interpMask
| span
->arrayMask
) & SPAN_TEXTURE
)
114 _mesa_write_texture_span(ctx
, span
);
115 else if ((span
->interpMask
| span
->arrayMask
) & SPAN_RGBA
)
116 _mesa_write_rgba_span(ctx
, span
);
118 _mesa_write_index_span(ctx
, span
);
125 /**********************************************************************/
126 /***** Rasterization *****/
127 /**********************************************************************/
130 /* Simple color index line (no stipple, width=1, no Z, no fog, no tex)*/
131 #define NAME simple_ci_line
133 #define RENDER_SPAN(span) _mesa_write_index_span(ctx, &span)
134 #include "s_linetemp.h"
137 /* Simple RGBA index line (no stipple, width=1, no Z, no fog, no tex)*/
138 #define NAME simple_rgba_line
140 #define RENDER_SPAN(span) _mesa_write_rgba_span(ctx, &span);
141 #include "s_linetemp.h"
144 /* Z, fog, wide, stipple color index line */
145 #define NAME general_ci_line
149 #define RENDER_SPAN(span) \
150 if (ctx->Line.StippleFlag) { \
151 span.arrayMask |= SPAN_MASK; \
152 compute_stipple_mask(ctx, span.end, span.array->mask); \
154 if (ctx->Line.Width > 1.0) { \
155 draw_wide_line(ctx, &span, dx > dy); \
158 _mesa_write_index_span(ctx, &span); \
160 #include "s_linetemp.h"
163 /* Z, fog, wide, stipple RGBA line */
164 #define NAME general_rgba_line
168 #define RENDER_SPAN(span) \
169 if (ctx->Line.StippleFlag) { \
170 span.arrayMask |= SPAN_MASK; \
171 compute_stipple_mask(ctx, span.end, span.array->mask); \
173 if (ctx->Line.Width > 1.0) { \
174 draw_wide_line(ctx, &span, dx > dy); \
177 _mesa_write_rgba_span(ctx, &span); \
179 #include "s_linetemp.h"
182 /* Single-texture line, w/ fog, Z, specular, etc. */
183 #define NAME textured_line
188 #define RENDER_SPAN(span) \
189 if (ctx->Line.StippleFlag) { \
190 span.arrayMask |= SPAN_MASK; \
191 compute_stipple_mask(ctx, span.end, span.array->mask); \
193 if (ctx->Line.Width > 1.0) { \
194 draw_wide_line(ctx, &span, dx > dy); \
197 _mesa_write_texture_span(ctx, &span); \
199 #include "s_linetemp.h"
202 /* Multi-texture or separate specular line, w/ fog, Z, specular, etc. */
203 #define NAME multitextured_line
208 #define INTERP_MULTITEX
209 #define RENDER_SPAN(span) \
210 if (ctx->Line.StippleFlag) { \
211 span.arrayMask |= SPAN_MASK; \
212 compute_stipple_mask(ctx, span.end, span.array->mask); \
214 if (ctx->Line.Width > 1.0) { \
215 draw_wide_line(ctx, &span, dx > dy); \
218 _mesa_write_texture_span(ctx, &span); \
220 #include "s_linetemp.h"
225 _swrast_add_spec_terms_line( GLcontext
*ctx
,
229 SWvertex
*ncv0
= (SWvertex
*)v0
;
230 SWvertex
*ncv1
= (SWvertex
*)v1
;
232 COPY_CHAN4( c
[0], ncv0
->color
);
233 COPY_CHAN4( c
[1], ncv1
->color
);
234 ACC_3V( ncv0
->color
, ncv0
->specular
);
235 ACC_3V( ncv1
->color
, ncv1
->specular
);
236 SWRAST_CONTEXT(ctx
)->SpecLine( ctx
, ncv0
, ncv1
);
237 COPY_CHAN4( ncv0
->color
, c
[0] );
238 COPY_CHAN4( ncv1
->color
, c
[1] );
244 _mesa_print_line_function(GLcontext
*ctx
); /* silence compiler warning */
246 _mesa_print_line_function(GLcontext
*ctx
)
248 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
250 _mesa_printf("Line Func == ");
251 if (swrast
->Line
== simple_ci_line
)
252 _mesa_printf("simple_ci_line\n");
253 else if (swrast
->Line
== simple_rgba_line
)
254 _mesa_printf("simple_rgba_line\n");
255 else if (swrast
->Line
== general_ci_line
)
256 _mesa_printf("general_ci_line\n");
257 else if (swrast
->Line
== general_rgba_line
)
258 _mesa_printf("general_rgba_line\n");
259 else if (swrast
->Line
== textured_line
)
260 _mesa_printf("textured_line\n");
261 else if (swrast
->Line
== multitextured_line
)
262 _mesa_printf("multitextured_line\n");
264 _mesa_printf("Driver func %p\n", (void *) swrast
->Line
);
272 /* record the current line function name */
273 static const char *lineFuncName
= NULL
;
275 #define USE(lineFunc) \
277 lineFuncName = #lineFunc; \
278 /*_mesa_printf("%s\n", lineFuncName);*/ \
279 swrast->Line = lineFunc; \
284 #define USE(lineFunc) swrast->Line = lineFunc
291 * Determine which line drawing function to use given the current
294 * Please update the summary flag _SWRAST_NEW_LINE if you add or remove
295 * tests to this code.
298 _swrast_choose_line( GLcontext
*ctx
)
300 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
301 const GLboolean rgbmode
= ctx
->Visual
.rgbMode
;
303 if (ctx
->RenderMode
== GL_RENDER
) {
304 if (ctx
->Line
.SmoothFlag
) {
305 /* antialiased lines */
306 _swrast_choose_aa_line_function(ctx
);
307 ASSERT(swrast
->Triangle
);
309 else if (ctx
->Texture
._EnabledUnits
) {
311 if (ctx
->Texture
._EnabledUnits
> 0x1 || (ctx
->_TriangleCaps
& DD_SEPARATE_SPECULAR
)) {
312 /* multi-texture and/or separate specular color */
313 USE(multitextured_line
);
319 else if (ctx
->Depth
.Test
|| ctx
->Fog
.Enabled
|| ctx
->Line
.Width
!= 1.0
320 || ctx
->Line
.StippleFlag
) {
321 /* no texture, but Z, fog, width>1, stipple, etc. */
323 USE(general_rgba_line
);
325 USE(general_ci_line
);
330 USE(simple_rgba_line
);
335 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
336 USE(_mesa_feedback_line
);
339 ASSERT(ctx
->RenderMode
== GL_SELECT
);
340 USE(_mesa_select_line
);
343 /*_mesa_print_line_function(ctx);*/