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
;
99 /*printf("offset %g\n", offset);*/
103 if (mode
== GL_POINT
) {
104 if ((IND
& SS_OFFSET_BIT
) && ctx
->Polygon
.OffsetPoint
) {
105 v
[0]->win
[2] += offset
;
106 v
[1]->win
[2] += offset
;
107 v
[2]->win
[2] += offset
;
109 _swsetup_render_point_tri( ctx
, e0
, e1
, e2
);
110 } else if (mode
== GL_LINE
) {
111 if ((IND
& SS_OFFSET_BIT
) && ctx
->Polygon
.OffsetLine
) {
112 v
[0]->win
[2] += offset
;
113 v
[1]->win
[2] += offset
;
114 v
[2]->win
[2] += offset
;
116 _swsetup_render_line_tri( ctx
, e0
, e1
, e2
);
118 if ((IND
& SS_OFFSET_BIT
) && ctx
->Polygon
.OffsetFill
) {
119 v
[0]->win
[2] += offset
;
120 v
[1]->win
[2] += offset
;
121 v
[2]->win
[2] += offset
;
123 _swrast_Triangle( ctx
, v
[0], v
[1], v
[2] );
126 if (IND
& SS_OFFSET_BIT
) {
132 if (IND
& SS_TWOSIDE_BIT
) {
134 if (IND
& SS_RGBA_BIT
) {
135 GLubyte (*vbcolor
)[4] = VB
->ColorPtr
[0]->data
;
136 GLubyte (*vbspec
)[4] = VB
->SecondaryColorPtr
[0]->data
;
137 SS_COLOR(v
[0]->color
, vbcolor
[e0
]);
138 SS_COLOR(v
[1]->color
, vbcolor
[e1
]);
139 SS_COLOR(v
[2]->color
, vbcolor
[e2
]);
140 SS_SPEC(v
[0]->specular
, vbspec
[e0
]);
141 SS_SPEC(v
[1]->specular
, vbspec
[e1
]);
142 SS_SPEC(v
[2]->specular
, vbspec
[e2
]);
144 GLuint
*vbindex
= VB
->IndexPtr
[0]->data
;
145 SS_IND(v
[0]->index
, vbindex
[e0
]);
146 SS_IND(v
[1]->index
, vbindex
[e1
]);
147 SS_IND(v
[2]->index
, vbindex
[e2
]);
155 /* Need to do something with edgeflags:
157 static void TAG(quad
)( GLcontext
*ctx
, GLuint v0
,
158 GLuint v1
, GLuint v2
, GLuint v3
)
160 if (IND
& SS_UNFILLED_BIT
) {
161 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
162 GLubyte ef1
= VB
->EdgeFlag
[v1
];
163 GLubyte ef3
= VB
->EdgeFlag
[v3
];
164 VB
->EdgeFlag
[v1
] = 0;
165 TAG(triangle
)( ctx
, v0
, v1
, v3
);
166 VB
->EdgeFlag
[v1
] = ef1
;
167 VB
->EdgeFlag
[v3
] = 0;
168 TAG(triangle
)( ctx
, v1
, v2
, v3
);
169 VB
->EdgeFlag
[v3
] = ef3
;
171 TAG(triangle
)( ctx
, v0
, v1
, v3
);
172 TAG(triangle
)( ctx
, v1
, v2
, v3
);
179 static void TAG(init
)( void )
181 tri_tab
[IND
] = TAG(triangle
);
182 quad_tab
[IND
] = TAG(quad
);