73a19ad38af4a04f9fbdf2adc272362b8b7b3770
[mesa.git] / src / mesa / swrast_setup / ss_triangle.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 3.5
4 *
5 * Copyright (C) 1999 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 *
24 * Authors:
25 * Keith Whitwell <keithw@valinux.com>
26 */
27
28 #include "glheader.h"
29 #include "macros.h"
30 #include "mtypes.h"
31
32 #include "tnl/t_context.h"
33
34 #include "ss_triangle.h"
35 #include "ss_context.h"
36
37 #define SS_RGBA_BIT 0x1
38 #define SS_OFFSET_BIT 0x2
39 #define SS_TWOSIDE_BIT 0x4
40 #define SS_UNFILLED_BIT 0x8
41 #define SS_MAX_TRIFUNC 0x10
42
43 static triangle_func tri_tab[SS_MAX_TRIFUNC];
44 static quad_func quad_tab[SS_MAX_TRIFUNC];
45
46
47 #define SS_COLOR(a,b) COPY_4UBV(a,b)
48 #define SS_SPEC(a,b) COPY_4UBV(a,b)
49 #define SS_IND(a,b) (a = b)
50
51 #define IND (0)
52 #define TAG(x) x
53 #include "ss_tritmp.h"
54
55 #define IND (SS_OFFSET_BIT)
56 #define TAG(x) x##_offset
57 #include "ss_tritmp.h"
58
59 #define IND (SS_TWOSIDE_BIT)
60 #define TAG(x) x##_twoside
61 #include "ss_tritmp.h"
62
63 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT)
64 #define TAG(x) x##_offset_twoside
65 #include "ss_tritmp.h"
66
67 #define IND (SS_UNFILLED_BIT)
68 #define TAG(x) x##_unfilled
69 #include "ss_tritmp.h"
70
71 #define IND (SS_OFFSET_BIT|SS_UNFILLED_BIT)
72 #define TAG(x) x##_offset_unfilled
73 #include "ss_tritmp.h"
74
75 #define IND (SS_TWOSIDE_BIT|SS_UNFILLED_BIT)
76 #define TAG(x) x##_twoside_unfilled
77 #include "ss_tritmp.h"
78
79 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT)
80 #define TAG(x) x##_offset_twoside_unfilled
81 #include "ss_tritmp.h"
82
83 #define IND (0|SS_RGBA_BIT)
84 #define TAG(x) x##_rgba
85 #include "ss_tritmp.h"
86
87 #define IND (SS_OFFSET_BIT|SS_RGBA_BIT)
88 #define TAG(x) x##_offset_rgba
89 #include "ss_tritmp.h"
90
91 #define IND (SS_TWOSIDE_BIT|SS_RGBA_BIT)
92 #define TAG(x) x##_twoside_rgba
93 #include "ss_tritmp.h"
94
95 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_RGBA_BIT)
96 #define TAG(x) x##_offset_twoside_rgba
97 #include "ss_tritmp.h"
98
99 #define IND (SS_UNFILLED_BIT|SS_RGBA_BIT)
100 #define TAG(x) x##_unfilled_rgba
101 #include "ss_tritmp.h"
102
103 #define IND (SS_OFFSET_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT)
104 #define TAG(x) x##_offset_unfilled_rgba
105 #include "ss_tritmp.h"
106
107 #define IND (SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT)
108 #define TAG(x) x##_twoside_unfilled_rgba
109 #include "ss_tritmp.h"
110
111 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT)
112 #define TAG(x) x##_offset_twoside_unfilled_rgba
113 #include "ss_tritmp.h"
114
115
116 void _swsetup_trifuncs_init( GLcontext *ctx )
117 {
118 (void) ctx;
119
120 init();
121 init_offset();
122 init_twoside();
123 init_offset_twoside();
124 init_unfilled();
125 init_offset_unfilled();
126 init_twoside_unfilled();
127 init_offset_twoside_unfilled();
128
129 init_rgba();
130 init_offset_rgba();
131 init_twoside_rgba();
132 init_offset_twoside_rgba();
133 init_unfilled_rgba();
134 init_offset_unfilled_rgba();
135 init_twoside_unfilled_rgba();
136 init_offset_twoside_unfilled_rgba();
137 }
138
139
140 static void swsetup_points( GLcontext *ctx, GLuint first, GLuint last )
141 {
142 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
143 SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts;
144 int i;
145
146 if (VB->Elts) {
147 for(i=first;i<last;i++)
148 if(VB->ClipMask[VB->Elts[i]]==0)
149 _swrast_Point( ctx, &verts[VB->Elts[i]] );
150 } else {
151 for(i=first;i<last;i++)
152 if(VB->ClipMask[i]==0)
153 _swrast_Point( ctx, &verts[i] );
154 }
155 }
156
157 static void swsetup_line( GLcontext *ctx, GLuint v0, GLuint v1 )
158 {
159 SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts;
160 _swrast_Line( ctx, &verts[v0], &verts[v1] );
161 }
162
163
164
165 void _swsetup_choose_trifuncs( GLcontext *ctx )
166 {
167 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
168 GLuint ind = 0;
169
170 if (ctx->Polygon._OffsetAny)
171 ind |= SS_OFFSET_BIT;
172
173 if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
174 ind |= SS_TWOSIDE_BIT;
175
176 if (ctx->_TriangleCaps & DD_TRI_UNFILLED)
177 ind |= SS_UNFILLED_BIT;
178
179 if (ctx->Visual.RGBAflag)
180 ind |= SS_RGBA_BIT;
181
182 swsetup->Triangle = tri_tab[ind];
183 swsetup->Quad = quad_tab[ind];
184 swsetup->Line = swsetup_line;
185 swsetup->Points = swsetup_points;
186 }
187