re-add MSAA support
[mesa.git] / src / mesa / drivers / dri / ffb / ffb_lines.c
1 /*
2 *
3 * GLX Hardware Device Driver for Sun Creator/Creator3D
4 * Copyright (C) 2000, 2001 David S. Miller
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
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 * DAVID MILLER, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 *
25 * David S. Miller <davem@redhat.com>
26 */
27
28 #include "main/mtypes.h"
29 #include "main/mm.h"
30 #include "main/extensions.h"
31 #include "ffb_dd.h"
32 #include "ffb_span.h"
33 #include "ffb_depth.h"
34 #include "ffb_context.h"
35 #include "ffb_vb.h"
36 #include "ffb_lines.h"
37 #include "ffb_tris.h"
38 #include "ffb_lock.h"
39
40 #undef FFB_LINE_TRACE
41
42 #define FFB_LINE_FLAT_BIT 0x01
43 #define FFB_LINE_ALPHA_BIT 0x02
44 #define MAX_FFB_LINE_FUNCS 0x04
45
46 static ffb_line_func ffb_line_tab[MAX_FFB_LINE_FUNCS];
47
48 /* If the line is not wide, we can support all of the line
49 * patterning and smooth shading features of OpenGL fully.
50 */
51
52 #define IND (0)
53 #define TAG(x) x
54 #include "ffb_linetmp.h"
55
56 #define IND (FFB_LINE_FLAT_BIT)
57 #define TAG(x) x##_flat
58 #include "ffb_linetmp.h"
59
60 #define IND (FFB_LINE_ALPHA_BIT)
61 #define TAG(x) x##_alpha
62 #include "ffb_linetmp.h"
63
64 #define IND (FFB_LINE_ALPHA_BIT|FFB_LINE_FLAT_BIT)
65 #define TAG(x) x##_alpha_flat
66 #include "ffb_linetmp.h"
67
68 void ffbDDLinefuncInit(void)
69 {
70 init();
71 init_flat();
72 init_alpha();
73 init_alpha_flat();
74 }
75
76 static void ffb_dd_line( GLcontext *ctx, GLuint e0, GLuint e1 )
77 {
78 ffbContextPtr fmesa = FFB_CONTEXT(ctx);
79 ffb_vertex *v0 = &fmesa->verts[e0];
80 ffb_vertex *v1 = &fmesa->verts[e1];
81 fmesa->draw_line( ctx, v0, v1 );
82 }
83
84 void ffbChooseLineState(GLcontext *ctx)
85 {
86 ffbContextPtr fmesa = FFB_CONTEXT(ctx);
87 TNLcontext *tnl = TNL_CONTEXT(ctx);
88 GLuint flags = ctx->_TriangleCaps;
89 GLuint ind = 0;
90
91 tnl->Driver.Render.Line = ffb_dd_line;
92
93 if (flags & DD_FLATSHADE)
94 ind |= FFB_LINE_FLAT_BIT;
95
96 if ((flags & DD_LINE_STIPPLE) != 0 &&
97 fmesa->lpat == FFB_LPAT_BAD) {
98 fmesa->draw_line = ffb_fallback_line;
99 return;
100 }
101
102 /* If blending or the alpha test is enabled we need to
103 * provide alpha components to the chip, else we can
104 * do without it and thus feed vertex data to the chip
105 * more efficiently.
106 */
107 if (ctx->Color.BlendEnabled || ctx->Color.AlphaEnabled)
108 ind |= FFB_LINE_ALPHA_BIT;
109
110 fmesa->draw_line = ffb_line_tab[ind];
111 }