[SDK] Provide .const macro for gas
[reactos.git] / dll / opengl / mesa / swrast_setup / ss_tritmp.h
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
29 /**
30 * This is where we handle assigning vertex colors based on front/back
31 * facing, compute polygon offset and handle glPolygonMode().
32 */
33 static void TAG(triangle)(struct gl_context *ctx, GLuint e0, GLuint e1, GLuint e2 )
34 {
35 #if IND & SS_TWOSIDE_BIT
36 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
37 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
38 GLchan saved_color[3][4] = { { 0 } };
39 GLfloat saved_col0[3][4] = { { 0 } };
40 #endif
41 SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts;
42 SWvertex *v[3];
43 #if IND & SS_OFFSET_BIT
44 GLfloat z[3];
45 #endif
46 GLfloat oz0, oz1, oz2;
47 GLenum mode = GL_FILL;
48 GLuint facing = 0;
49
50 v[0] = &verts[e0];
51 v[1] = &verts[e1];
52 v[2] = &verts[e2];
53
54 #if IND & (SS_TWOSIDE_BIT | SS_OFFSET_BIT | SS_UNFILLED_BIT)
55 {
56 GLfloat ex = v[0]->attrib[FRAG_ATTRIB_WPOS][0] - v[2]->attrib[FRAG_ATTRIB_WPOS][0];
57 GLfloat ey = v[0]->attrib[FRAG_ATTRIB_WPOS][1] - v[2]->attrib[FRAG_ATTRIB_WPOS][1];
58 GLfloat fx = v[1]->attrib[FRAG_ATTRIB_WPOS][0] - v[2]->attrib[FRAG_ATTRIB_WPOS][0];
59 GLfloat fy = v[1]->attrib[FRAG_ATTRIB_WPOS][1] - v[2]->attrib[FRAG_ATTRIB_WPOS][1];
60 GLfloat cc = ex*fy - ey*fx;
61
62 #if IND & (SS_TWOSIDE_BIT | SS_UNFILLED_BIT)
63 {
64 facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
65
66 #if IND & SS_UNFILLED_BIT
67 mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
68 #endif
69
70 #if IND & SS_TWOSIDE_BIT
71 if (facing == 1) {
72 if (VB->BackfaceColorPtr) {
73 GLfloat (*vbcolor)[4] = VB->BackfaceColorPtr->data;
74
75 if (swsetup->intColors) {
76 COPY_CHAN4(saved_color[0], v[0]->color);
77 COPY_CHAN4(saved_color[1], v[1]->color);
78 COPY_CHAN4(saved_color[2], v[2]->color);
79 }
80 else {
81 COPY_4V(saved_col0[0], v[0]->attrib[FRAG_ATTRIB_COL]);
82 COPY_4V(saved_col0[1], v[1]->attrib[FRAG_ATTRIB_COL]);
83 COPY_4V(saved_col0[2], v[2]->attrib[FRAG_ATTRIB_COL]);
84 }
85
86 if (VB->BackfaceColorPtr->stride) {
87 if (swsetup->intColors) {
88 SS_COLOR(v[0]->color, vbcolor[e0]);
89 SS_COLOR(v[1]->color, vbcolor[e1]);
90 SS_COLOR(v[2]->color, vbcolor[e2]);
91 }
92 else {
93 COPY_4V(v[0]->attrib[FRAG_ATTRIB_COL], vbcolor[e0]);
94 COPY_4V(v[1]->attrib[FRAG_ATTRIB_COL], vbcolor[e1]);
95 COPY_4V(v[2]->attrib[FRAG_ATTRIB_COL], vbcolor[e2]);
96 }
97 }
98 else {
99 /* flat shade */
100 if (swsetup->intColors) {
101 SS_COLOR(v[0]->color, vbcolor[0]);
102 SS_COLOR(v[1]->color, vbcolor[0]);
103 SS_COLOR(v[2]->color, vbcolor[0]);
104 }
105 else {
106 COPY_4V(v[0]->attrib[FRAG_ATTRIB_COL], vbcolor[0]);
107 COPY_4V(v[1]->attrib[FRAG_ATTRIB_COL], vbcolor[0]);
108 COPY_4V(v[2]->attrib[FRAG_ATTRIB_COL], vbcolor[0]);
109 }
110 }
111 }
112 }
113 #endif
114 }
115 #endif
116
117 #if IND & SS_OFFSET_BIT
118 {
119 GLfloat offset;
120 const GLfloat max = ctx->DrawBuffer->_DepthMaxF;
121 /* save original Z values (restored later) */
122 z[0] = v[0]->attrib[FRAG_ATTRIB_WPOS][2];
123 z[1] = v[1]->attrib[FRAG_ATTRIB_WPOS][2];
124 z[2] = v[2]->attrib[FRAG_ATTRIB_WPOS][2];
125 /* Note that Z values are already scaled to [0,65535] (for example)
126 * so no MRD value is used here.
127 */
128 offset = ctx->Polygon.OffsetUnits;
129 if (cc * cc > 1e-16) {
130 const GLfloat ez = z[0] - z[2];
131 const GLfloat fz = z[1] - z[2];
132 const GLfloat oneOverArea = 1.0F / cc;
133 const GLfloat dzdx = FABSF((ey * fz - ez * fy) * oneOverArea);
134 const GLfloat dzdy = FABSF((ez * fx - ex * fz) * oneOverArea);
135 offset += MAX2(dzdx, dzdy) * ctx->Polygon.OffsetFactor;
136 }
137 /* new Z values */
138 oz0 = CLAMP(v[0]->attrib[FRAG_ATTRIB_WPOS][2] + offset, 0.0F, max);
139 oz1 = CLAMP(v[1]->attrib[FRAG_ATTRIB_WPOS][2] + offset, 0.0F, max);
140 oz2 = CLAMP(v[2]->attrib[FRAG_ATTRIB_WPOS][2] + offset, 0.0F, max);
141 }
142 #endif
143 }
144 #endif
145
146 if (mode == GL_POINT) {
147 if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetPoint) {
148 v[0]->attrib[FRAG_ATTRIB_WPOS][2] = oz0;
149 v[1]->attrib[FRAG_ATTRIB_WPOS][2] = oz1;
150 v[2]->attrib[FRAG_ATTRIB_WPOS][2] = oz2;
151 }
152 _swsetup_render_tri(ctx, e0, e1, e2, facing, _swsetup_edge_render_point_tri);
153 } else if (mode == GL_LINE) {
154 if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetLine) {
155 v[0]->attrib[FRAG_ATTRIB_WPOS][2] = oz0;
156 v[1]->attrib[FRAG_ATTRIB_WPOS][2] = oz1;
157 v[2]->attrib[FRAG_ATTRIB_WPOS][2] = oz2;
158 }
159 _swsetup_render_tri(ctx, e0, e1, e2, facing, _swsetup_edge_render_line_tri);
160 }
161 else {
162 #if IND & SS_OFFSET_BIT
163 if (ctx->Polygon.OffsetFill) {
164 v[0]->attrib[FRAG_ATTRIB_WPOS][2] = oz0;
165 v[1]->attrib[FRAG_ATTRIB_WPOS][2] = oz1;
166 v[2]->attrib[FRAG_ATTRIB_WPOS][2] = oz2;
167 }
168 #endif
169 _swrast_Triangle( ctx, v[0], v[1], v[2] );
170 }
171
172 /*
173 * Restore original vertex colors, etc.
174 */
175 #if IND & SS_OFFSET_BIT
176 {
177 v[0]->attrib[FRAG_ATTRIB_WPOS][2] = z[0];
178 v[1]->attrib[FRAG_ATTRIB_WPOS][2] = z[1];
179 v[2]->attrib[FRAG_ATTRIB_WPOS][2] = z[2];
180 }
181 #endif
182
183 #if IND & SS_TWOSIDE_BIT
184 {
185 if (facing == 1) {
186 if (VB->BackfaceColorPtr) {
187 if (swsetup->intColors) {
188 COPY_CHAN4(v[0]->color, saved_color[0]);
189 COPY_CHAN4(v[1]->color, saved_color[1]);
190 COPY_CHAN4(v[2]->color, saved_color[2]);
191 }
192 else {
193 COPY_4V(v[0]->attrib[FRAG_ATTRIB_COL], saved_col0[0]);
194 COPY_4V(v[1]->attrib[FRAG_ATTRIB_COL], saved_col0[1]);
195 COPY_4V(v[2]->attrib[FRAG_ATTRIB_COL], saved_col0[2]);
196 }
197 }
198 }
199 }
200 #endif
201 }
202
203
204
205 /* Need to fixup edgeflags when decomposing to triangles:
206 */
207 static void TAG(quadfunc)( struct gl_context *ctx, GLuint v0,
208 GLuint v1, GLuint v2, GLuint v3 )
209 {
210 if (IND & SS_UNFILLED_BIT) {
211 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
212 if (VB->EdgeFlag) { /* XXX this test shouldn't be needed (bug 12614) */
213 GLubyte ef1 = VB->EdgeFlag[v1];
214 GLubyte ef3 = VB->EdgeFlag[v3];
215 VB->EdgeFlag[v1] = 0;
216 TAG(triangle)( ctx, v0, v1, v3 );
217 VB->EdgeFlag[v1] = ef1;
218 VB->EdgeFlag[v3] = 0;
219 TAG(triangle)( ctx, v1, v2, v3 );
220 VB->EdgeFlag[v3] = ef3;
221 }
222 } else {
223 TAG(triangle)( ctx, v0, v1, v3 );
224 TAG(triangle)( ctx, v1, v2, v3 );
225 }
226 }
227
228
229
230
231 static void TAG(init)( void )
232 {
233 tri_tab[IND] = TAG(triangle);
234 quad_tab[IND] = TAG(quadfunc);
235 }
236
237
238 #undef IND
239 #undef TAG