Lots of GLchan datatype changes.
[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 GLchan (*vbcolor)[4] = VB->ColorPtr[1]->data;
63 GLchan (*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 offset *= ctx->MRD;
99 /*printf("offset %g\n", offset);*/
100 }
101 }
102
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;
108 }
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;
115 }
116 _swsetup_render_line_tri( ctx, e0, e1, e2 );
117 } else {
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;
122 }
123 _swrast_Triangle( ctx, v[0], v[1], v[2] );
124 }
125
126 if (IND & SS_OFFSET_BIT) {
127 v[0]->win[2] = z[0];
128 v[1]->win[2] = z[1];
129 v[2]->win[2] = z[2];
130 }
131
132 if (IND & SS_TWOSIDE_BIT) {
133 if (facing == 1) {
134 if (IND & SS_RGBA_BIT) {
135 GLchan (*vbcolor)[4] = VB->ColorPtr[0]->data;
136 GLchan (*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]);
143 } else {
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]);
148 }
149 }
150 }
151 }
152
153
154
155 /* Need to do something with edgeflags:
156 */
157 static void TAG(quad)( GLcontext *ctx, GLuint v0,
158 GLuint v1, GLuint v2, GLuint v3 )
159 {
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;
170 } else {
171 TAG(triangle)( ctx, v0, v1, v3 );
172 TAG(triangle)( ctx, v1, v2, v3 );
173 }
174 }
175
176
177
178
179 static void TAG(init)( void )
180 {
181 tri_tab[IND] = TAG(triangle);
182 quad_tab[IND] = TAG(quad);
183 }
184
185
186 #undef IND
187 #undef TAG
188
189
190