[SDK] Provide .const macro for gas
[reactos.git] / dll / opengl / mesa / swrast_setup / ss_triangle.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.1
4 *
5 * Copyright (C) 1999-2007 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 <keith@tungstengraphics.com>
26 */
27
28 #include "main/glheader.h"
29 #include "main/colormac.h"
30 #include "main/macros.h"
31 #include "main/mtypes.h"
32
33 #include "tnl/t_context.h"
34
35 #include "ss_triangle.h"
36 #include "ss_context.h"
37
38 #define SS_OFFSET_BIT 0x1
39 #define SS_TWOSIDE_BIT 0x2
40 #define SS_UNFILLED_BIT 0x4
41 #define SS_MAX_TRIFUNC 0x8
42
43 static tnl_triangle_func tri_tab[SS_MAX_TRIFUNC];
44 static tnl_quad_func quad_tab[SS_MAX_TRIFUNC];
45
46
47 /*
48 * Render a triangle respecting edge flags.
49 */
50 typedef void (* swsetup_edge_render_prim_tri)(struct gl_context *ctx,
51 const GLubyte *ef,
52 GLuint e0,
53 GLuint e1,
54 GLuint e2,
55 const SWvertex *v0,
56 const SWvertex *v1,
57 const SWvertex *v2);
58
59 /*
60 * Render a triangle using lines and respecting edge flags.
61 */
62 static void
63 _swsetup_edge_render_line_tri(struct gl_context *ctx,
64 const GLubyte *ef,
65 GLuint e0,
66 GLuint e1,
67 GLuint e2,
68 const SWvertex *v0,
69 const SWvertex *v1,
70 const SWvertex *v2)
71 {
72 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
73
74 if (swsetup->render_prim == GL_POLYGON) {
75 if (ef[e2]) _swrast_Line( ctx, v2, v0 );
76 if (ef[e0]) _swrast_Line( ctx, v0, v1 );
77 if (ef[e1]) _swrast_Line( ctx, v1, v2 );
78 } else {
79 if (ef[e0]) _swrast_Line( ctx, v0, v1 );
80 if (ef[e1]) _swrast_Line( ctx, v1, v2 );
81 if (ef[e2]) _swrast_Line( ctx, v2, v0 );
82 }
83 }
84
85 /*
86 * Render a triangle using points and respecting edge flags.
87 */
88 static void
89 _swsetup_edge_render_point_tri(struct gl_context *ctx,
90 const GLubyte *ef,
91 GLuint e0,
92 GLuint e1,
93 GLuint e2,
94 const SWvertex *v0,
95 const SWvertex *v1,
96 const SWvertex *v2)
97 {
98 if (ef[e0]) _swrast_Point( ctx, v0 );
99 if (ef[e1]) _swrast_Point( ctx, v1 );
100 if (ef[e2]) _swrast_Point( ctx, v2 );
101
102 _swrast_flush(ctx);
103 }
104
105 /*
106 * Render a triangle respecting cull and shade model.
107 */
108 static void _swsetup_render_tri(struct gl_context *ctx,
109 GLuint e0,
110 GLuint e1,
111 GLuint e2,
112 GLuint facing,
113 swsetup_edge_render_prim_tri render)
114 {
115 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
116 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
117 GLubyte *ef = VB->EdgeFlag;
118 SWvertex *verts = swsetup->verts;
119 SWvertex *v0 = &verts[e0];
120 SWvertex *v1 = &verts[e1];
121 SWvertex *v2 = &verts[e2];
122
123 /* cull testing */
124 if (ctx->Polygon.CullFlag) {
125 if (facing == 1 && ctx->Polygon.CullFaceMode != GL_FRONT)
126 return;
127 if (facing == 0 && ctx->Polygon.CullFaceMode != GL_BACK)
128 return;
129 }
130
131 if (ctx->Light.ShadeModel == GL_FLAT) {
132 GLchan c[2][4];
133
134 /* save colors/indexes for v0, v1 vertices */
135 COPY_CHAN4(c[0], v0->color);
136 COPY_CHAN4(c[1], v1->color);
137
138 /* copy v2 color/indexes to v0, v1 indexes */
139 COPY_CHAN4(v0->color, v2->color);
140 COPY_CHAN4(v1->color, v2->color);
141 render(ctx, ef, e0, e1, e2, v0, v1, v2);
142
143 COPY_CHAN4(v0->color, c[0]);
144 COPY_CHAN4(v1->color, c[1]);
145 }
146 else {
147 render(ctx, ef, e0, e1, e2, v0, v1, v2);
148 }
149 }
150
151 #define SS_COLOR(a,b) UNCLAMPED_FLOAT_TO_RGBA_CHAN(a,b)
152 #define SS_SPEC(a,b) COPY_4V(a,b)
153 #define SS_IND(a,b) (a = b)
154
155 #define IND (0)
156 #define TAG(x) x##_rgba
157 #include "ss_tritmp.h"
158
159 #define IND (SS_OFFSET_BIT)
160 #define TAG(x) x##_offset_rgba
161 #include "ss_tritmp.h"
162
163 #define IND (SS_TWOSIDE_BIT)
164 #define TAG(x) x##_twoside_rgba
165 #include "ss_tritmp.h"
166
167 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT)
168 #define TAG(x) x##_offset_twoside_rgba
169 #include "ss_tritmp.h"
170
171 #define IND (SS_UNFILLED_BIT)
172 #define TAG(x) x##_unfilled_rgba
173 #include "ss_tritmp.h"
174
175 #define IND (SS_OFFSET_BIT|SS_UNFILLED_BIT)
176 #define TAG(x) x##_offset_unfilled_rgba
177 #include "ss_tritmp.h"
178
179 #define IND (SS_TWOSIDE_BIT|SS_UNFILLED_BIT)
180 #define TAG(x) x##_twoside_unfilled_rgba
181 #include "ss_tritmp.h"
182
183 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT)
184 #define TAG(x) x##_offset_twoside_unfilled_rgba
185 #include "ss_tritmp.h"
186
187
188 void _swsetup_trifuncs_init( struct gl_context *ctx )
189 {
190 (void) ctx;
191
192 init_rgba();
193 init_offset_rgba();
194 init_twoside_rgba();
195 init_offset_twoside_rgba();
196 init_unfilled_rgba();
197 init_offset_unfilled_rgba();
198 init_twoside_unfilled_rgba();
199 init_offset_twoside_unfilled_rgba();
200 }
201
202
203 static void swsetup_points( struct gl_context *ctx, GLuint first, GLuint last )
204 {
205 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
206 SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts;
207 GLuint i;
208
209 if (VB->Elts) {
210 for (i = first; i < last; i++)
211 if (VB->ClipMask[VB->Elts[i]] == 0)
212 _swrast_Point( ctx, &verts[VB->Elts[i]] );
213 }
214 else {
215 for (i = first; i < last; i++)
216 if (VB->ClipMask[i] == 0)
217 _swrast_Point( ctx, &verts[i] );
218 }
219 }
220
221 static void swsetup_line( struct gl_context *ctx, GLuint v0, GLuint v1 )
222 {
223 SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts;
224 _swrast_Line( ctx, &verts[v0], &verts[v1] );
225 }
226
227
228
229 void _swsetup_choose_trifuncs( struct gl_context *ctx )
230 {
231 TNLcontext *tnl = TNL_CONTEXT(ctx);
232 GLuint ind = 0;
233
234 if (ctx->Polygon.OffsetPoint ||
235 ctx->Polygon.OffsetLine ||
236 ctx->Polygon.OffsetFill)
237 ind |= SS_OFFSET_BIT;
238
239 if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
240 ind |= SS_TWOSIDE_BIT;
241
242 /* We piggyback the two-sided stencil front/back determination on the
243 * unfilled triangle path.
244 */
245 if (ctx->Polygon.FrontMode != GL_FILL ||
246 ctx->Polygon.BackMode != GL_FILL)
247 ind |= SS_UNFILLED_BIT;
248
249 tnl->Driver.Render.Triangle = tri_tab[ind];
250 tnl->Driver.Render.Quad = quad_tab[ind];
251 tnl->Driver.Render.Line = swsetup_line;
252 tnl->Driver.Render.Points = swsetup_points;
253 }