2 * Mesa 3-D graphics library
5 * Copyright (C) 1999 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
25 * Keith Whitwell <keithw@valinux.com>
29 static void TAG(triangle
)(GLcontext
*ctx
, GLuint e0
, GLuint e1
, GLuint e2
)
31 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
32 SWvertex
*verts
= SWSETUP_CONTEXT(ctx
)->verts
;
36 GLenum mode
= GL_FILL
;
44 if (IND
& (SS_TWOSIDE_BIT
| SS_OFFSET_BIT
| SS_UNFILLED_BIT
))
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
;
52 if (IND
& (SS_TWOSIDE_BIT
| SS_UNFILLED_BIT
))
54 facing
= (cc
< 0.0) ^ ctx
->Polygon
._FrontBit
;
56 if (IND
& SS_UNFILLED_BIT
)
57 mode
= facing
? ctx
->Polygon
.BackMode
: ctx
->Polygon
.FrontMode
;
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
]);
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
]);
80 if (IND
& SS_OFFSET_BIT
)
82 offset
= ctx
->Polygon
.OffsetUnits
;
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
;
94 if (ac
< 0.0f
) ac
= -ac
;
95 if (bc
< 0.0f
) bc
= -bc
;
96 offset
+= MAX2(ac
, bc
) * ctx
->Polygon
.OffsetFactor
;
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
;
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
;
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] );
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
;
127 _swrast_Triangle( ctx
, v
[0], v
[1], v
[2] );
130 if (IND
& SS_OFFSET_BIT
) {
136 if (IND
& SS_TWOSIDE_BIT
) {
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
]);
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
]);
159 /* Need to do something with edgeflags:
161 static void TAG(quad
)( GLcontext
*ctx
, GLuint v0
,
162 GLuint v1
, GLuint v2
, GLuint v3
)
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
;
175 TAG(triangle
)( ctx
, v0
, v1
, v3
);
176 TAG(triangle
)( ctx
, v1
, v2
, v3
);
183 static void TAG(init
)( void )
185 tri_tab
[IND
] = TAG(triangle
);
186 quad_tab
[IND
] = TAG(quad
);