992bc4f396a163fdbbd5be2b9031f08c266988ed
[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 "types.h"
31
32 #include "ss_triangle.h"
33 #include "ss_context.h"
34
35 #define SS_FLAT_BIT 0x1
36 #define SS_OFFSET_BIT 0x2
37 #define SS_TWOSIDE_BIT 0x4
38 #define SS_UNFILLED_BIT 0x10
39 #define SS_MAX_TRIFUNC 0x20
40
41 static triangle_func tri_tab[SS_MAX_TRIFUNC];
42 static line_func line_tab[SS_MAX_TRIFUNC];
43 static points_func points_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_FLAT_BIT)
56 #define TAG(x) x##_flat
57 #include "ss_tritmp.h"
58
59 #define IND (SS_OFFSET_BIT)
60 #define TAG(x) x##_offset
61 #include "ss_tritmp.h"
62
63 #define IND (SS_FLAT_BIT|SS_OFFSET_BIT)
64 #define TAG(x) x##_flat_offset
65 #include "ss_tritmp.h"
66
67 #define IND (SS_TWOSIDE_BIT)
68 #define TAG(x) x##_twoside
69 #include "ss_tritmp.h"
70
71 #define IND (SS_FLAT_BIT|SS_TWOSIDE_BIT)
72 #define TAG(x) x##_flat_twoside
73 #include "ss_tritmp.h"
74
75 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT)
76 #define TAG(x) x##_offset_twoside
77 #include "ss_tritmp.h"
78
79 #define IND (SS_FLAT_BIT|SS_OFFSET_BIT|SS_TWOSIDE_BIT)
80 #define TAG(x) x##_flat_offset_twoside
81 #include "ss_tritmp.h"
82
83 #define IND (SS_UNFILLED_BIT)
84 #define TAG(x) x##_unfilled
85 #include "ss_tritmp.h"
86
87 #define IND (SS_FLAT_BIT|SS_UNFILLED_BIT)
88 #define TAG(x) x##_flat_unfilled
89 #include "ss_tritmp.h"
90
91 #define IND (SS_OFFSET_BIT|SS_UNFILLED_BIT)
92 #define TAG(x) x##_offset_unfilled
93 #include "ss_tritmp.h"
94
95 #define IND (SS_FLAT_BIT|SS_OFFSET_BIT|SS_UNFILLED_BIT)
96 #define TAG(x) x##_flat_offset_unfilled
97 #include "ss_tritmp.h"
98
99 #define IND (SS_TWOSIDE_BIT|SS_UNFILLED_BIT)
100 #define TAG(x) x##_twoside_unfilled
101 #include "ss_tritmp.h"
102
103 #define IND (SS_FLAT_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT)
104 #define TAG(x) x##_flat_twoside_unfilled
105 #include "ss_tritmp.h"
106
107 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT)
108 #define TAG(x) x##_offset_twoside_unfilled
109 #include "ss_tritmp.h"
110
111 #define IND (SS_FLAT_BIT|SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT)
112 #define TAG(x) x##_flat_offset_twoside_unfilled
113 #include "ss_tritmp.h"
114
115
116 void _swsetup_trifuncs_init( GLcontext *ctx )
117 {
118 (void) ctx;
119
120 init();
121 init_flat();
122 init_offset();
123 init_flat_offset();
124 init_twoside();
125 init_flat_twoside();
126 init_offset_twoside();
127 init_flat_offset_twoside();
128 init_unfilled();
129 init_flat_unfilled();
130 init_offset_unfilled();
131 init_flat_offset_unfilled();
132 init_twoside_unfilled();
133 init_flat_twoside_unfilled();
134 init_offset_twoside_unfilled();
135 init_flat_offset_twoside_unfilled();
136 }
137
138
139 void _swsetup_choose_trifuncs( GLcontext *ctx )
140 {
141 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
142 GLuint ind = 0;
143
144 if (ctx->Light.ShadeModel == GL_FLAT)
145 ind |= SS_FLAT_BIT;
146
147 if (ctx->Polygon._OffsetAny)
148 ind |= SS_OFFSET_BIT;
149
150 if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
151 ind |= SS_TWOSIDE_BIT;
152
153 if (ctx->Polygon._Unfilled)
154 ind |= SS_UNFILLED_BIT;
155
156 swsetup->Triangle = tri_tab[ind];
157 swsetup->Line = line_tab[ind];
158 swsetup->Points = points_tab[ind];
159 swsetup->Quad = quad_tab[ind];
160 }
161