aeb407da494a388d20b334b0d97bd0379695e800
1 /* $Id: ss_tritmp.h,v 1.14 2001/07/17 19:39:32 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * Keith Whitwell <keithw@valinux.com>
31 static void TAG(triangle
)(GLcontext
*ctx
, GLuint e0
, GLuint e1
, GLuint e2
)
33 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
34 SWvertex
*verts
= SWSETUP_CONTEXT(ctx
)->verts
;
38 GLenum mode
= GL_FILL
;
46 if (IND
& (SS_TWOSIDE_BIT
| SS_OFFSET_BIT
| SS_UNFILLED_BIT
))
48 GLfloat ex
= v
[0]->win
[0] - v
[2]->win
[0];
49 GLfloat ey
= v
[0]->win
[1] - v
[2]->win
[1];
50 GLfloat fx
= v
[1]->win
[0] - v
[2]->win
[0];
51 GLfloat fy
= v
[1]->win
[1] - v
[2]->win
[1];
52 GLfloat cc
= ex
*fy
- ey
*fx
;
54 if (IND
& (SS_TWOSIDE_BIT
| SS_UNFILLED_BIT
))
56 facing
= (cc
< 0.0) ^ ctx
->Polygon
._FrontBit
;
58 if (IND
& SS_UNFILLED_BIT
)
59 mode
= facing
? ctx
->Polygon
.BackMode
: ctx
->Polygon
.FrontMode
;
62 if (IND
& SS_TWOSIDE_BIT
) {
63 if (IND
& SS_RGBA_BIT
) {
64 GLchan (*vbcolor
)[4] = (GLchan (*)[4])VB
->ColorPtr
[1]->Ptr
;
65 SS_COLOR(v
[0]->color
, vbcolor
[e0
]);
66 SS_COLOR(v
[1]->color
, vbcolor
[e1
]);
67 SS_COLOR(v
[2]->color
, vbcolor
[e2
]);
68 if (VB
->SecondaryColorPtr
[1]) {
69 GLchan (*vbspec
)[4] = (GLchan (*)[4])VB
->SecondaryColorPtr
[1]->Ptr
;
70 SS_SPEC(v
[0]->specular
, vbspec
[e0
]);
71 SS_SPEC(v
[1]->specular
, vbspec
[e1
]);
72 SS_SPEC(v
[2]->specular
, vbspec
[e2
]);
75 GLuint
*vbindex
= VB
->IndexPtr
[1]->data
;
76 SS_IND(v
[0]->index
, vbindex
[e0
]);
77 SS_IND(v
[1]->index
, vbindex
[e1
]);
78 SS_IND(v
[2]->index
, vbindex
[e2
]);
84 if (IND
& SS_OFFSET_BIT
)
86 offset
= ctx
->Polygon
.OffsetUnits
;
90 if (cc
* cc
> 1e-16) {
91 GLfloat ez
= z
[0] - z
[2];
92 GLfloat fz
= z
[1] - z
[2];
93 GLfloat a
= ey
*fz
- ez
*fy
;
94 GLfloat b
= ez
*fx
- ex
*fz
;
95 GLfloat ic
= 1.0 / cc
;
98 if (ac
< 0.0f
) ac
= -ac
;
99 if (bc
< 0.0f
) bc
= -bc
;
100 offset
+= MAX2(ac
, bc
) * ctx
->Polygon
.OffsetFactor
;
103 /*printf("offset %g\n", offset);*/
107 if (mode
== GL_POINT
) {
108 if ((IND
& SS_OFFSET_BIT
) && ctx
->Polygon
.OffsetPoint
) {
109 v
[0]->win
[2] += offset
;
110 v
[1]->win
[2] += offset
;
111 v
[2]->win
[2] += offset
;
113 _swsetup_render_point_tri( ctx
, e0
, e1
, e2
);
114 } else if (mode
== GL_LINE
) {
115 if ((IND
& SS_OFFSET_BIT
) && ctx
->Polygon
.OffsetLine
) {
116 v
[0]->win
[2] += offset
;
117 v
[1]->win
[2] += offset
;
118 v
[2]->win
[2] += offset
;
120 _swsetup_render_line_tri( ctx
, e0
, e1
, e2
);
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 GLchan (*vbcolor
)[4] = (GLchan (*)[4])VB
->ColorPtr
[0]->Ptr
;
140 SS_COLOR(v
[0]->color
, vbcolor
[e0
]);
141 SS_COLOR(v
[1]->color
, vbcolor
[e1
]);
142 SS_COLOR(v
[2]->color
, vbcolor
[e2
]);
143 if (VB
->SecondaryColorPtr
[0]) {
144 GLchan (*vbspec
)[4] = (GLchan (*)[4])VB
->SecondaryColorPtr
[0]->Ptr
;
145 SS_SPEC(v
[0]->specular
, vbspec
[e0
]);
146 SS_SPEC(v
[1]->specular
, vbspec
[e1
]);
147 SS_SPEC(v
[2]->specular
, vbspec
[e2
]);
150 GLuint
*vbindex
= VB
->IndexPtr
[0]->data
;
151 SS_IND(v
[0]->index
, vbindex
[e0
]);
152 SS_IND(v
[1]->index
, vbindex
[e1
]);
153 SS_IND(v
[2]->index
, vbindex
[e2
]);
161 /* Need to fixup edgeflags when decomposing to triangles:
163 static void TAG(quadfunc
)( GLcontext
*ctx
, GLuint v0
,
164 GLuint v1
, GLuint v2
, GLuint v3
)
166 if (IND
& SS_UNFILLED_BIT
) {
167 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
168 GLubyte ef1
= VB
->EdgeFlag
[v1
];
169 GLubyte ef3
= VB
->EdgeFlag
[v3
];
170 VB
->EdgeFlag
[v1
] = 0;
171 TAG(triangle
)( ctx
, v0
, v1
, v3
);
172 VB
->EdgeFlag
[v1
] = ef1
;
173 VB
->EdgeFlag
[v3
] = 0;
174 TAG(triangle
)( ctx
, v1
, v2
, v3
);
175 VB
->EdgeFlag
[v3
] = ef3
;
177 TAG(triangle
)( ctx
, v0
, v1
, v3
);
178 TAG(triangle
)( ctx
, v1
, v2
, v3
);
185 static void TAG(init
)( void )
187 tri_tab
[IND
] = TAG(triangle
);
188 quad_tab
[IND
] = TAG(quadfunc
);