97143a2f4b715ffbd6f673b2a5273bf265366746
2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 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.
30 #include "s_context.h"
32 #include "s_feedback.h"
38 * Init the mask[] array to implement a line stipple.
41 compute_stipple_mask( GLcontext
*ctx
, GLuint len
, GLubyte mask
[] )
43 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
46 for (i
= 0; i
< len
; i
++) {
47 GLuint bit
= (swrast
->StippleCounter
/ ctx
->Line
.StippleFactor
) & 0xf;
48 if ((1 << bit
) & ctx
->Line
.StipplePattern
) {
54 swrast
->StippleCounter
++;
60 * To draw a wide line we can simply redraw the span N times, side by side.
63 draw_wide_line( GLcontext
*ctx
, struct sw_span
*span
, GLboolean xMajor
)
67 ASSERT(span
->end
< MAX_WIDTH
);
69 width
= (GLint
) CLAMP( ctx
->Line
.Width
, MIN_LINE_WIDTH
, MAX_LINE_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 if ((span
->interpMask
| span
->arrayMask
) & SPAN_TEXTURE
)
90 _swrast_write_texture_span(ctx
, span
);
91 else if ((span
->interpMask
| span
->arrayMask
) & SPAN_RGBA
)
92 _swrast_write_rgba_span(ctx
, span
);
94 _swrast_write_index_span(ctx
, span
);
98 GLint
*x
= span
->array
->x
;
101 for (w
= 0; w
< width
; w
++) {
103 for (i
= 0; i
< span
->end
; i
++)
107 for (i
= 0; i
< span
->end
; i
++)
110 if ((span
->interpMask
| span
->arrayMask
) & SPAN_TEXTURE
)
111 _swrast_write_texture_span(ctx
, span
);
112 else if ((span
->interpMask
| span
->arrayMask
) & SPAN_RGBA
)
113 _swrast_write_rgba_span(ctx
, span
);
115 _swrast_write_index_span(ctx
, span
);
122 /**********************************************************************/
123 /***** Rasterization *****/
124 /**********************************************************************/
126 /* Simple color index line (no stipple, width=1, no Z, no fog, no tex)*/
127 #define NAME simple_ci_line
129 #define RENDER_SPAN(span) _swrast_write_index_span(ctx, &span)
130 #include "s_linetemp.h"
132 /* Simple RGBA index line (no stipple, width=1, no Z, no fog, no tex)*/
133 #define NAME simple_rgba_line
135 #define RENDER_SPAN(span) _swrast_write_rgba_span(ctx, &span);
136 #include "s_linetemp.h"
139 /* Z, fog, wide, stipple color index line */
140 #define NAME general_ci_line
144 #define RENDER_SPAN(span) \
145 if (ctx->Line.StippleFlag) { \
146 span.arrayMask |= SPAN_MASK; \
147 compute_stipple_mask(ctx, span.end, span.array->mask); \
149 if (ctx->Line.Width > 1.0) { \
150 draw_wide_line(ctx, &span, (GLboolean)(dx > dy)); \
153 _swrast_write_index_span(ctx, &span); \
155 #include "s_linetemp.h"
158 /* Z, fog, wide, stipple RGBA line */
159 #define NAME general_rgba_line
163 #define RENDER_SPAN(span) \
164 if (ctx->Line.StippleFlag) { \
165 span.arrayMask |= SPAN_MASK; \
166 compute_stipple_mask(ctx, span.end, span.array->mask); \
168 if (ctx->Line.Width > 1.0) { \
169 draw_wide_line(ctx, &span, (GLboolean)(dx > dy)); \
172 _swrast_write_rgba_span(ctx, &span); \
174 #include "s_linetemp.h"
177 /* Single-texture line, w/ fog, Z, specular, etc. */
178 #define NAME textured_line
183 #define RENDER_SPAN(span) \
184 if (ctx->Line.StippleFlag) { \
185 span.arrayMask |= SPAN_MASK; \
186 compute_stipple_mask(ctx, span.end, span.array->mask); \
188 if (ctx->Line.Width > 1.0) { \
189 draw_wide_line(ctx, &span, (GLboolean)(dx > dy)); \
192 _swrast_write_texture_span(ctx, &span); \
194 #include "s_linetemp.h"
197 /* Multi-texture or separate specular line, w/ fog, Z, specular, etc. */
198 #define NAME multitextured_line
203 #define INTERP_MULTITEX
204 #define RENDER_SPAN(span) \
205 if (ctx->Line.StippleFlag) { \
206 span.arrayMask |= SPAN_MASK; \
207 compute_stipple_mask(ctx, span.end, span.array->mask); \
209 if (ctx->Line.Width > 1.0) { \
210 draw_wide_line(ctx, &span, (GLboolean)(dx > dy)); \
213 _swrast_write_texture_span(ctx, &span); \
215 #include "s_linetemp.h"
220 _swrast_add_spec_terms_line( GLcontext
*ctx
,
224 SWvertex
*ncv0
= (SWvertex
*)v0
;
225 SWvertex
*ncv1
= (SWvertex
*)v1
;
227 COPY_CHAN4( c
[0], ncv0
->color
);
228 COPY_CHAN4( c
[1], ncv1
->color
);
229 ACC_3V( ncv0
->color
, ncv0
->specular
);
230 ACC_3V( ncv1
->color
, ncv1
->specular
);
231 SWRAST_CONTEXT(ctx
)->SpecLine( ctx
, ncv0
, ncv1
);
232 COPY_CHAN4( ncv0
->color
, c
[0] );
233 COPY_CHAN4( ncv1
->color
, c
[1] );
239 _mesa_print_line_function(GLcontext
*ctx
); /* silence compiler warning */
241 _mesa_print_line_function(GLcontext
*ctx
)
243 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
245 _mesa_printf("Line Func == ");
246 if (swrast
->Line
== simple_ci_line
)
247 _mesa_printf("simple_ci_line\n");
248 else if (swrast
->Line
== simple_rgba_line
)
249 _mesa_printf("simple_rgba_line\n");
250 else if (swrast
->Line
== general_ci_line
)
251 _mesa_printf("general_ci_line\n");
252 else if (swrast
->Line
== general_rgba_line
)
253 _mesa_printf("general_rgba_line\n");
254 else if (swrast
->Line
== textured_line
)
255 _mesa_printf("textured_line\n");
256 else if (swrast
->Line
== multitextured_line
)
257 _mesa_printf("multitextured_line\n");
259 _mesa_printf("Driver func %p\n", (void *) swrast
->Line
);
267 /* record the current line function name */
268 static const char *lineFuncName
= NULL
;
270 #define USE(lineFunc) \
272 lineFuncName = #lineFunc; \
273 /*_mesa_printf("%s\n", lineFuncName);*/ \
274 swrast->Line = lineFunc; \
279 #define USE(lineFunc) swrast->Line = lineFunc
286 * Determine which line drawing function to use given the current
289 * Please update the summary flag _SWRAST_NEW_LINE if you add or remove
290 * tests to this code.
293 _swrast_choose_line( GLcontext
*ctx
)
295 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
296 const GLboolean rgbmode
= ctx
->Visual
.rgbMode
;
298 if (ctx
->RenderMode
== GL_RENDER
) {
299 if (ctx
->Line
.SmoothFlag
) {
300 /* antialiased lines */
301 _swrast_choose_aa_line_function(ctx
);
302 ASSERT(swrast
->Line
);
304 else if (ctx
->Texture
._EnabledCoordUnits
) {
306 if (ctx
->Texture
._EnabledCoordUnits
> 0x1
307 || (ctx
->_TriangleCaps
& DD_SEPARATE_SPECULAR
)) {
308 /* multi-texture and/or separate specular color */
309 USE(multitextured_line
);
315 else if (ctx
->Depth
.Test
|| ctx
->Fog
.Enabled
|| ctx
->Line
.Width
!= 1.0
316 || ctx
->Line
.StippleFlag
) {
317 /* no texture, but Z, fog, width>1, stipple, etc. */
319 USE(general_rgba_line
);
321 USE(general_ci_line
);
326 USE(simple_rgba_line
);
331 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
332 USE(_swrast_feedback_line
);
335 ASSERT(ctx
->RenderMode
== GL_SELECT
);
336 USE(_swrast_select_line
);
339 /*_mesa_print_line_function(ctx);*/