Fix TCL_LIGHT_MODEL_CTL setting in radeonColorMaterial.
[mesa.git] / src / mesa / swrast_setup / ss_tritmp.h
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 5.0
5 *
6 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * Keith Whitwell <keith@tungstengraphics.com>
27 */
28
29
30 static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
31 {
32 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
33 SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts;
34 SWvertex *v[3];
35 GLfloat z[3];
36 GLfloat offset;
37 GLenum mode = GL_FILL;
38 GLuint facing = 0;
39 GLchan saved_color[3][4];
40 GLchan saved_spec[3][4];
41 GLuint saved_index[3];
42
43 v[0] = &verts[e0];
44 v[1] = &verts[e1];
45 v[2] = &verts[e2];
46
47
48 if (IND & (SS_TWOSIDE_BIT | SS_OFFSET_BIT | SS_UNFILLED_BIT))
49 {
50 GLfloat ex = v[0]->win[0] - v[2]->win[0];
51 GLfloat ey = v[0]->win[1] - v[2]->win[1];
52 GLfloat fx = v[1]->win[0] - v[2]->win[0];
53 GLfloat fy = v[1]->win[1] - v[2]->win[1];
54 GLfloat cc = ex*fy - ey*fx;
55
56 if (IND & (SS_TWOSIDE_BIT | SS_UNFILLED_BIT))
57 {
58 facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
59 if (ctx->Stencil.TestTwoSide)
60 ctx->_Facing = facing; /* for 2-sided stencil test */
61
62 if (IND & SS_UNFILLED_BIT)
63 mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
64
65 if (facing == 1) {
66 if (IND & SS_TWOSIDE_BIT) {
67 if (IND & SS_RGBA_BIT) {
68 GLfloat (*vbcolor)[4] = VB->ColorPtr[1]->data;
69
70 COPY_CHAN4(saved_color[0], v[0]->color);
71 COPY_CHAN4(saved_color[1], v[1]->color);
72 COPY_CHAN4(saved_color[2], v[2]->color);
73
74 SS_COLOR(v[0]->color, vbcolor[e0]);
75 SS_COLOR(v[1]->color, vbcolor[e1]);
76 SS_COLOR(v[2]->color, vbcolor[e2]);
77
78 if (VB->SecondaryColorPtr[1]) {
79 GLfloat (*vbspec)[4] = VB->SecondaryColorPtr[1]->data;
80
81 COPY_CHAN4(saved_spec[0], v[0]->specular);
82 COPY_CHAN4(saved_spec[1], v[1]->specular);
83 COPY_CHAN4(saved_spec[2], v[2]->specular);
84
85 SS_SPEC(v[0]->specular, vbspec[e0]);
86 SS_SPEC(v[1]->specular, vbspec[e1]);
87 SS_SPEC(v[2]->specular, vbspec[e2]);
88 }
89 } else {
90 GLfloat *vbindex = (GLfloat *)VB->IndexPtr[1]->data;
91 saved_index[0] = v[0]->index;
92 saved_index[1] = v[1]->index;
93 saved_index[2] = v[2]->index;
94
95 SS_IND(v[0]->index, (GLuint) vbindex[e0]);
96 SS_IND(v[1]->index, (GLuint) vbindex[e1]);
97 SS_IND(v[2]->index, (GLuint) vbindex[e2]);
98 }
99 }
100 }
101 }
102
103 if (IND & SS_OFFSET_BIT)
104 {
105 offset = ctx->Polygon.OffsetUnits;
106 z[0] = v[0]->win[2];
107 z[1] = v[1]->win[2];
108 z[2] = v[2]->win[2];
109 if (cc * cc > 1e-16) {
110 GLfloat ez = z[0] - z[2];
111 GLfloat fz = z[1] - z[2];
112 GLfloat a = ey*fz - ez*fy;
113 GLfloat b = ez*fx - ex*fz;
114 GLfloat ic = 1.0F / cc;
115 GLfloat ac = a * ic;
116 GLfloat bc = b * ic;
117 if (ac < 0.0F) ac = -ac;
118 if (bc < 0.0F) bc = -bc;
119 offset += MAX2(ac, bc) * ctx->Polygon.OffsetFactor;
120 }
121 offset *= ctx->MRD;
122 /*printf("offset %g\n", offset);*/
123 }
124 }
125
126 if (mode == GL_POINT) {
127 if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetPoint) {
128 v[0]->win[2] += offset;
129 v[1]->win[2] += offset;
130 v[2]->win[2] += offset;
131 }
132 _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
133 } else if (mode == GL_LINE) {
134 if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetLine) {
135 v[0]->win[2] += offset;
136 v[1]->win[2] += offset;
137 v[2]->win[2] += offset;
138 }
139 _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
140 } else {
141 if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetFill) {
142 v[0]->win[2] += offset;
143 v[1]->win[2] += offset;
144 v[2]->win[2] += offset;
145 }
146 _swrast_Triangle( ctx, v[0], v[1], v[2] );
147 }
148
149 if (IND & SS_OFFSET_BIT) {
150 v[0]->win[2] = z[0];
151 v[1]->win[2] = z[1];
152 v[2]->win[2] = z[2];
153 }
154
155 if (IND & SS_TWOSIDE_BIT) {
156 if (facing == 1) {
157 if (IND & SS_RGBA_BIT) {
158 COPY_CHAN4(v[0]->color, saved_color[0]);
159 COPY_CHAN4(v[1]->color, saved_color[1]);
160 COPY_CHAN4(v[2]->color, saved_color[2]);
161 if (VB->SecondaryColorPtr[1]) {
162 COPY_CHAN4(v[0]->specular, saved_spec[0]);
163 COPY_CHAN4(v[1]->specular, saved_spec[1]);
164 COPY_CHAN4(v[2]->specular, saved_spec[2]);
165 }
166 } else {
167 v[0]->index = saved_index[0];
168 v[1]->index = saved_index[1];
169 v[2]->index = saved_index[2];
170 }
171 }
172 }
173 }
174
175
176
177 /* Need to fixup edgeflags when decomposing to triangles:
178 */
179 static void TAG(quadfunc)( GLcontext *ctx, GLuint v0,
180 GLuint v1, GLuint v2, GLuint v3 )
181 {
182 if (IND & SS_UNFILLED_BIT) {
183 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
184 GLubyte ef1 = VB->EdgeFlag[v1];
185 GLubyte ef3 = VB->EdgeFlag[v3];
186 VB->EdgeFlag[v1] = 0;
187 TAG(triangle)( ctx, v0, v1, v3 );
188 VB->EdgeFlag[v1] = ef1;
189 VB->EdgeFlag[v3] = 0;
190 TAG(triangle)( ctx, v1, v2, v3 );
191 VB->EdgeFlag[v3] = ef3;
192 } else {
193 TAG(triangle)( ctx, v0, v1, v3 );
194 TAG(triangle)( ctx, v1, v2, v3 );
195 }
196 }
197
198
199
200
201 static void TAG(init)( void )
202 {
203 tri_tab[IND] = TAG(triangle);
204 quad_tab[IND] = TAG(quadfunc);
205 }
206
207
208 #undef IND
209 #undef TAG