Remove 'pv' parameter from Line/Tri/Point funcs. The provoking vertex
[mesa.git] / src / mesa / swrast_setup / ss_tritmp.h
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
29 static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
30 {
31 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
32 SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts;
33 SWvertex *v[3];
34 GLfloat z[3];
35 GLfloat offset;
36 GLenum mode = GL_FILL;
37 GLuint facing;
38
39 v[0] = &verts[e0];
40 v[1] = &verts[e1];
41 v[2] = &verts[e2];
42
43
44 if (IND & (SS_TWOSIDE_BIT | SS_OFFSET_BIT | SS_UNFILLED_BIT))
45 {
46 GLfloat ex = v[0]->win[0] - v[2]->win[0];
47 GLfloat ey = v[0]->win[1] - v[2]->win[1];
48 GLfloat fx = v[1]->win[0] - v[2]->win[0];
49 GLfloat fy = v[1]->win[1] - v[2]->win[1];
50 GLfloat cc = ex*fy - ey*fx;
51
52 if (IND & (SS_TWOSIDE_BIT | SS_UNFILLED_BIT))
53 {
54 facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
55
56 if (IND & SS_UNFILLED_BIT)
57 mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
58
59 if (facing == 1) {
60 if (IND & SS_TWOSIDE_BIT) {
61 if (IND & SS_RGBA_BIT) {
62 GLubyte (*vbcolor)[4] = VB->ColorPtr[1]->data;
63 GLubyte (*vbspec)[4] = VB->SecondaryColorPtr[1]->data;
64 SS_COLOR(v[0]->color, vbcolor[e0]);
65 SS_COLOR(v[1]->color, vbcolor[e1]);
66 SS_COLOR(v[2]->color, vbcolor[e2]);
67 SS_SPEC(v[0]->specular, vbspec[e0]);
68 SS_SPEC(v[1]->specular, vbspec[e1]);
69 SS_SPEC(v[2]->specular, vbspec[e2]);
70 } else {
71 GLuint *vbindex = VB->IndexPtr[1]->data;
72 SS_IND(v[0]->index, vbindex[e0]);
73 SS_IND(v[1]->index, vbindex[e1]);
74 SS_IND(v[2]->index, vbindex[e2]);
75 }
76 }
77 }
78 }
79
80 if (IND & SS_OFFSET_BIT)
81 {
82 offset = ctx->Polygon.OffsetUnits;
83 z[0] = v[0]->win[2];
84 z[1] = v[1]->win[2];
85 z[2] = v[2]->win[2];
86 if (cc * cc > 1e-16) {
87 GLfloat ez = z[0] - z[2];
88 GLfloat fz = z[1] - z[2];
89 GLfloat a = ey*fz - ez*fy;
90 GLfloat b = ez*fx - ex*fz;
91 GLfloat ic = 1.0 / cc;
92 GLfloat ac = a * ic;
93 GLfloat bc = b * ic;
94 if (ac < 0.0f) ac = -ac;
95 if (bc < 0.0f) bc = -bc;
96 offset += MAX2(ac, bc) * ctx->Polygon.OffsetFactor;
97 }
98 }
99 }
100
101 if (mode == GL_POINT) {
102 GLubyte *ef = VB->EdgeFlag;
103 if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetPoint) {
104 v[0]->win[2] += offset;
105 v[1]->win[2] += offset;
106 v[2]->win[2] += offset;
107 }
108 if (ef[e0]) _swrast_Point( ctx, v[0] );
109 if (ef[e1]) _swrast_Point( ctx, v[1] );
110 if (ef[e2]) _swrast_Point( ctx, v[2] );
111 } else if (mode == GL_LINE) {
112 GLubyte *ef = VB->EdgeFlag;
113 if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetLine) {
114 v[0]->win[2] += offset;
115 v[1]->win[2] += offset;
116 v[2]->win[2] += offset;
117 }
118 if (ef[e0]) _swrast_Line( ctx, v[0], v[1] );
119 if (ef[e1]) _swrast_Line( ctx, v[1], v[2] );
120 if (ef[e2]) _swrast_Line( ctx, v[2], v[0] );
121 } else {
122 if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetFill) {
123 v[0]->win[2] += offset;
124 v[1]->win[2] += offset;
125 v[2]->win[2] += offset;
126 }
127 _swrast_Triangle( ctx, v[0], v[1], v[2] );
128 }
129
130 if (IND & SS_OFFSET_BIT) {
131 v[0]->win[2] = z[0];
132 v[1]->win[2] = z[1];
133 v[2]->win[2] = z[2];
134 }
135
136 if (IND & SS_TWOSIDE_BIT) {
137 if (facing == 1) {
138 if (IND & SS_RGBA_BIT) {
139 GLubyte (*vbcolor)[4] = VB->ColorPtr[0]->data;
140 GLubyte (*vbspec)[4] = VB->SecondaryColorPtr[0]->data;
141 SS_COLOR(v[0]->color, vbcolor[e0]);
142 SS_COLOR(v[1]->color, vbcolor[e1]);
143 SS_COLOR(v[2]->color, vbcolor[e2]);
144 SS_SPEC(v[0]->specular, vbspec[e0]);
145 SS_SPEC(v[1]->specular, vbspec[e1]);
146 SS_SPEC(v[2]->specular, vbspec[e2]);
147 } else {
148 GLuint *vbindex = VB->IndexPtr[0]->data;
149 SS_IND(v[0]->index, vbindex[e0]);
150 SS_IND(v[1]->index, vbindex[e1]);
151 SS_IND(v[2]->index, vbindex[e2]);
152 }
153 }
154 }
155 }
156
157
158
159 /* Need to do something with edgeflags:
160 */
161 static void TAG(quad)( GLcontext *ctx, GLuint v0,
162 GLuint v1, GLuint v2, GLuint v3 )
163 {
164 if (IND & SS_UNFILLED_BIT) {
165 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
166 GLubyte ef1 = VB->EdgeFlag[v1];
167 GLubyte ef3 = VB->EdgeFlag[v3];
168 VB->EdgeFlag[v1] = 0;
169 TAG(triangle)( ctx, v0, v1, v3 );
170 VB->EdgeFlag[v1] = ef1;
171 VB->EdgeFlag[v3] = 0;
172 TAG(triangle)( ctx, v1, v2, v3 );
173 VB->EdgeFlag[v3] = ef3;
174 } else {
175 TAG(triangle)( ctx, v0, v1, v3 );
176 TAG(triangle)( ctx, v1, v2, v3 );
177 }
178 }
179
180
181
182
183 static void TAG(init)( void )
184 {
185 tri_tab[IND] = TAG(triangle);
186 quad_tab[IND] = TAG(quad);
187 }
188
189
190 #undef IND
191 #undef TAG
192
193
194