~ubuntu-branches/ubuntu/quantal/mesa-glw/quantal

« back to all changes in this revision

Viewing changes to src/mesa/swrast_setup/ss_tritmp.h

  • Committer: Bazaar Package Importer
  • Author(s): Morten Kjeldgaard
  • Date: 2008-05-06 16:19:15 UTC
  • Revision ID: james.westby@ubuntu.com-20080506161915-uynz7nftmfixu6bq
Tags: upstream-7.0.3
ImportĀ upstreamĀ versionĀ 7.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Mesa 3-D graphics library
 
3
 * Version:  6.1
 
4
 *
 
5
 * Copyright (C) 1999-2004  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 <keith@tungstengraphics.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 = 0;
 
38
   GLchan saved_color[3][4];
 
39
   GLchan saved_spec[3][4];
 
40
   GLfloat saved_index[3];
 
41
 
 
42
   v[0] = &verts[e0];
 
43
   v[1] = &verts[e1];
 
44
   v[2] = &verts[e2];
 
45
 
 
46
   if (IND & (SS_TWOSIDE_BIT | SS_OFFSET_BIT | SS_UNFILLED_BIT))
 
47
   {
 
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;
 
53
 
 
54
      if (IND & (SS_TWOSIDE_BIT | SS_UNFILLED_BIT))
 
55
      {
 
56
         facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
 
57
 
 
58
         if (IND & SS_UNFILLED_BIT)
 
59
            mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
 
60
 
 
61
         if (facing == 1) {
 
62
            if (IND & SS_TWOSIDE_BIT) {
 
63
               if (IND & SS_RGBA_BIT) {
 
64
                  if (VB->ColorPtr[1]) {
 
65
                     GLfloat (*vbcolor)[4] = VB->ColorPtr[1]->data;
 
66
 
 
67
                     COPY_CHAN4(saved_color[0], v[0]->color);
 
68
                     COPY_CHAN4(saved_color[1], v[1]->color);
 
69
                     COPY_CHAN4(saved_color[2], v[2]->color);
 
70
 
 
71
                     if (VB->ColorPtr[1]->stride) {
 
72
                        SS_COLOR(v[0]->color, vbcolor[e0]);
 
73
                        SS_COLOR(v[1]->color, vbcolor[e1]);
 
74
                        SS_COLOR(v[2]->color, vbcolor[e2]);
 
75
                     }
 
76
                     else {
 
77
                        SS_COLOR(v[0]->color, vbcolor[0]);
 
78
                        SS_COLOR(v[1]->color, vbcolor[0]);
 
79
                        SS_COLOR(v[2]->color, vbcolor[0]);
 
80
                     }
 
81
                  }
 
82
 
 
83
                  if (VB->SecondaryColorPtr[1]) {
 
84
                     GLfloat (*vbspec)[4] = VB->SecondaryColorPtr[1]->data;
 
85
 
 
86
                     COPY_CHAN4(saved_spec[0], v[0]->specular);
 
87
                     COPY_CHAN4(saved_spec[1], v[1]->specular);
 
88
                     COPY_CHAN4(saved_spec[2], v[2]->specular);
 
89
 
 
90
                     if (VB->SecondaryColorPtr[1]->stride) {
 
91
                        SS_SPEC(v[0]->specular, vbspec[e0]);
 
92
                        SS_SPEC(v[1]->specular, vbspec[e1]);
 
93
                        SS_SPEC(v[2]->specular, vbspec[e2]);
 
94
                     }
 
95
                     else {
 
96
                        SS_SPEC(v[0]->specular, vbspec[0]);
 
97
                        SS_SPEC(v[1]->specular, vbspec[0]);
 
98
                        SS_SPEC(v[2]->specular, vbspec[0]);
 
99
                     }
 
100
                  }
 
101
               } else {
 
102
                  GLfloat *vbindex = (GLfloat *)VB->IndexPtr[1]->data;
 
103
                  saved_index[0] = v[0]->index;
 
104
                  saved_index[1] = v[1]->index;
 
105
                  saved_index[2] = v[2]->index;
 
106
                  
 
107
                  SS_IND(v[0]->index, (GLuint) vbindex[e0]);
 
108
                  SS_IND(v[1]->index, (GLuint) vbindex[e1]);
 
109
                  SS_IND(v[2]->index, (GLuint) vbindex[e2]);
 
110
               }
 
111
            }
 
112
         }
 
113
      }
 
114
 
 
115
      if (IND & SS_OFFSET_BIT)
 
116
      {
 
117
         offset = ctx->Polygon.OffsetUnits * ctx->DrawBuffer->_MRD;
 
118
         z[0] = v[0]->win[2];
 
119
         z[1] = v[1]->win[2];
 
120
         z[2] = v[2]->win[2];
 
121
         if (cc * cc > 1e-16) {
 
122
            const GLfloat ez = z[0] - z[2];
 
123
            const GLfloat fz = z[1] - z[2];
 
124
            const GLfloat oneOverArea = 1.0F / cc;
 
125
            const GLfloat dzdx = FABSF((ey * fz - ez * fy) * oneOverArea);
 
126
            const GLfloat dzdy = FABSF((ez * fx - ex * fz) * oneOverArea);
 
127
            offset += MAX2(dzdx, dzdy) * ctx->Polygon.OffsetFactor;
 
128
            /* Unfortunately, we need to clamp to prevent negative Zs below.
 
129
             * Technically, we should do the clamping per-fragment.
 
130
             */
 
131
            offset = MAX2(offset, -v[0]->win[2]);
 
132
            offset = MAX2(offset, -v[1]->win[2]);
 
133
            offset = MAX2(offset, -v[2]->win[2]);
 
134
         }
 
135
      }
 
136
   }
 
137
 
 
138
   if (mode == GL_POINT) {
 
139
      if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetPoint) {
 
140
         v[0]->win[2] += offset;
 
141
         v[1]->win[2] += offset;
 
142
         v[2]->win[2] += offset;
 
143
      }
 
144
      _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
 
145
   } else if (mode == GL_LINE) {
 
146
      if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetLine) {
 
147
         v[0]->win[2] += offset;
 
148
         v[1]->win[2] += offset;
 
149
         v[2]->win[2] += offset;
 
150
      }
 
151
      _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
 
152
   } else {
 
153
      if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetFill) {
 
154
         v[0]->win[2] += offset;
 
155
         v[1]->win[2] += offset;
 
156
         v[2]->win[2] += offset;
 
157
      }
 
158
      _swrast_Triangle( ctx, v[0], v[1], v[2] );
 
159
   }
 
160
 
 
161
   if (IND & SS_OFFSET_BIT) {
 
162
      v[0]->win[2] = z[0];
 
163
      v[1]->win[2] = z[1];
 
164
      v[2]->win[2] = z[2];
 
165
   }
 
166
 
 
167
   if (IND & SS_TWOSIDE_BIT) {
 
168
      if (facing == 1) {
 
169
         if (IND & SS_RGBA_BIT) {
 
170
            if (VB->ColorPtr[1]) {
 
171
               COPY_CHAN4(v[0]->color, saved_color[0]);
 
172
               COPY_CHAN4(v[1]->color, saved_color[1]);
 
173
               COPY_CHAN4(v[2]->color, saved_color[2]);
 
174
            }
 
175
 
 
176
            if (VB->SecondaryColorPtr[1]) {
 
177
               COPY_CHAN4(v[0]->specular, saved_spec[0]);
 
178
               COPY_CHAN4(v[1]->specular, saved_spec[1]);
 
179
               COPY_CHAN4(v[2]->specular, saved_spec[2]);
 
180
            }
 
181
         } else {
 
182
            v[0]->index = saved_index[0];
 
183
            v[1]->index = saved_index[1];
 
184
            v[2]->index = saved_index[2];
 
185
         }
 
186
      }
 
187
   }
 
188
}
 
189
 
 
190
 
 
191
 
 
192
/* Need to fixup edgeflags when decomposing to triangles:
 
193
 */
 
194
static void TAG(quadfunc)( GLcontext *ctx, GLuint v0,
 
195
                       GLuint v1, GLuint v2, GLuint v3 )
 
196
{
 
197
   if (IND & SS_UNFILLED_BIT) {
 
198
      struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
 
199
      if (VB->EdgeFlag) { /* XXX this test shouldn't be needed (bug 12614) */
 
200
         GLubyte ef1 = VB->EdgeFlag[v1];
 
201
         GLubyte ef3 = VB->EdgeFlag[v3];
 
202
         VB->EdgeFlag[v1] = 0;
 
203
         TAG(triangle)( ctx, v0, v1, v3 );
 
204
         VB->EdgeFlag[v1] = ef1;
 
205
         VB->EdgeFlag[v3] = 0;
 
206
         TAG(triangle)( ctx, v1, v2, v3 );
 
207
         VB->EdgeFlag[v3] = ef3;
 
208
      }
 
209
   } else {
 
210
      TAG(triangle)( ctx, v0, v1, v3 );
 
211
      TAG(triangle)( ctx, v1, v2, v3 );
 
212
   }
 
213
}
 
214
 
 
215
 
 
216
 
 
217
 
 
218
static void TAG(init)( void )
 
219
{
 
220
   tri_tab[IND] = TAG(triangle);
 
221
   quad_tab[IND] = TAG(quadfunc);
 
222
}
 
223
 
 
224
 
 
225
#undef IND
 
226
#undef TAG