summaryrefslogtreecommitdiff
path: root/xc/lib/GL/mesa/src/drv/r128/r128_tritmp.h
blob: aa0d16b396f8f03d58d290e363e90202cc29b60a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/* $XFree86$ */
/**************************************************************************

Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc.,
                                               Cedar Park, Texas. 
All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
on the rights to use, copy, modify, merge, publish, distribute, sub
license, and/or sell copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.

**************************************************************************/

/*
 * Authors:
 *   Kevin E. Martin <kevin@precisioninsight.com>
 *
 */

#if !defined(TAG) || !defined(IND)
    this is an error
#endif

/* Draw a single triangle.  Note that the device-dependent vertex data
   might need to be changed based on the render state. */
static void TAG(triangle)(GLcontext *ctx,
			  GLuint e0, GLuint e1, GLuint e2,
			  GLuint pv)
{
    r128ContextPtr        r128ctx   = R128_CONTEXT(ctx);
    struct vertex_buffer *VB        = ctx->VB;
    r128VertexPtr         r128verts = R128_DRIVER_DATA(VB)->verts;
    const r128_vertex    *v0        = &r128verts[e0].v;  
    const r128_vertex    *v1        = &r128verts[e1].v;  
    const r128_vertex    *v2        = &r128verts[e2].v;  

#if (IND & R128_OFFSET_BIT)
    GLfloat offset;
#endif

#if (IND & (R128_FLAT_BIT | R128_TWOSIDE_BIT))
    int c0 = *(int *)&r128verts[pv].v.dif_argb; 
    int c1 = c0;
    int c2 = c0;
#endif

#if (IND & R128_OFFSET_BIT)
    switch (ctx->Visual->DepthBits) {
    case 16: offset = ctx->Polygon.OffsetUnits / 65536.0;      break;
    case 24: offset = ctx->Polygon.OffsetUnits / 16777216.0;   break;
    case 32: offset = ctx->Polygon.OffsetUnits / 4294967296.0; break;
    default: offset = ctx->Polygon.OffsetUnits / 65536.0;      break;
    }
#endif

#if (IND & (R128_TWOSIDE_BIT | R128_OFFSET_BIT)) 
    {
	GLfloat ex = v0->x - v2->x;
	GLfloat ey = v0->y - v2->y;
	GLfloat fx = v1->x - v2->x;
	GLfloat fy = v1->y - v2->y;
	GLfloat c  = ex*fy - ey*fx;
         
#if (IND & R128_TWOSIDE_BIT) 
	{
	    GLuint  facing        = (c > 0.0) ^ ctx->Polygon.FrontBit;
	    GLubyte (*vbcolor)[4] = VB->Color[facing]->data;
	    if (IND & R128_FLAT_BIT) {
		R128_COLOR((char *)&c0, vbcolor[pv]);
		c2 = c1 = c0;
	    } else {
		R128_COLOR((char *)&c0, vbcolor[e0]);
		R128_COLOR((char *)&c1, vbcolor[e1]);
		R128_COLOR((char *)&c2, vbcolor[e2]);
	    }
	}
#endif
      
#if (IND & R128_OFFSET_BIT) 
	{
	    if (c * c > 1e-16) {
		GLfloat factor = ctx->Polygon.OffsetFactor;
		GLfloat ez     = v0->z - v2->z;
		GLfloat fz     = v1->z - v2->z;
		GLfloat a      = ey*fz - ez*fy;
		GLfloat b      = ez*fx - ex*fz;
		GLfloat ic     = 1.0 / c;
		GLfloat ac     = a * ic;
		GLfloat bc     = b * ic;
		if (ac < 0.0f) ac = -ac;
		if (bc < 0.0f) bc = -bc;
		offset += MAX2(ac, bc) * factor;
	    }
	}
#endif
    }
#endif  

   {
      r128_vertex *vbptr;
      R128CCE_ALLOC_VB_SPACE(r128ctx, vbptr, 3);

      vbptr[0] = *v0;
#if (IND & (R128_FLAT_BIT|R128_TWOSIDE_BIT))
      *((int *)(&vbptr[0].dif_argb)) = c0;
#endif
#if (IND & R128_OFFSET_BIT)
      vbptr[0].z = v0->z + offset;
#endif

      vbptr[1] = *v1;
#if (IND & (R128_FLAT_BIT|R128_TWOSIDE_BIT))
      *((int *)(&vbptr[1].dif_argb)) = c1;
#endif
#if (IND & R128_OFFSET_BIT)
      vbptr[1].z = v1->z + offset;
#endif

      vbptr[2] = *v2;
#if (IND & (R128_FLAT_BIT|R128_TWOSIDE_BIT))
      *((int *)(&vbptr[2].dif_argb)) = c2;
#endif
#if (IND & R128_OFFSET_BIT)
      vbptr[2].z = v2->z + offset;
#endif
   }
}


static void TAG(quad)(GLcontext *ctx,
		      GLuint v0, GLuint v1, GLuint v2, GLuint v3,
		      GLuint pv)
{
    TAG(triangle)(ctx, v0, v1, v3, pv);
    TAG(triangle)(ctx, v1, v2, v3, pv);
}


/* Draw a single line.  Note that the device-dependent vertex data might
   need to be changed based on the render state. */
static void TAG(line)(GLcontext *ctx,
		      GLuint v0, GLuint v1,
		      GLuint pv)
{
    r128ContextPtr  r128ctx   = R128_CONTEXT(ctx);
    r128VertexPtr   r128verts = R128_DRIVER_DATA(ctx->VB)->verts;
    float           width     = ctx->Line.Width;

   if (IND & (R128_TWOSIDE_BIT|R128_FLAT_BIT)) {
      r128Vertex tmp0 = r128verts[v0];
      r128Vertex tmp1 = r128verts[v1];

      if (IND & R128_TWOSIDE_BIT) {
	 GLubyte (*vbcolor)[4] = ctx->VB->ColorPtr->data;

	 if (IND & R128_FLAT_BIT) {
 	    R128_COLOR((char *)&tmp0.v.dif_argb, vbcolor[pv]);
	    *(int *)&tmp1.v.dif_argb = *(int *)&tmp0.v.dif_argb;
	 } else {
	    R128_COLOR((char *)&tmp0.v.dif_argb, vbcolor[v0]);
	    R128_COLOR((char *)&tmp1.v.dif_argb, vbcolor[v1]);
	 }
      } else {
	 *(int *)&tmp0.v.dif_argb = *(int *)&r128verts[pv].v.dif_argb;
	 *(int *)&tmp1.v.dif_argb = *(int *)&r128verts[pv].v.dif_argb;
      }

      r128DrawLineVB( r128ctx, &tmp0.v, &tmp1.v, width );
   }
   else
      r128DrawLineVB( r128ctx, &r128verts[v0].v, &r128verts[v1].v, width );
}

/* Draw a set of points.  Note that the device-dependent vertex data
   might need to be changed based on the render state. */
static void TAG(points)(GLcontext *ctx,
			GLuint first, GLuint last)
{
    r128ContextPtr        r128ctx   = R128_CONTEXT(ctx);
    struct vertex_buffer *VB        = ctx->VB;
    r128VertexPtr         r128verts = R128_DRIVER_DATA(VB)->verts;
    GLfloat               size      = ctx->Point.Size * 0.5;
    int                   i;

    for(i = first; i <= last; i++) {
	if(VB->ClipMask[i] == 0) {
	   if (IND & R128_TWOSIDE_BIT) {	
	      GLubyte (*vbcolor)[4] = VB->ColorPtr->data;
	      r128Vertex tmp0 = r128verts[i];
	      R128_COLOR((char *)&tmp0.v.dif_argb, vbcolor[i]);
	      r128DrawPointVB( r128ctx, &tmp0.v, size );
	   } else
	      r128DrawPointVB( r128ctx, &r128verts[i].v, size );
	}
    }
}

/* Initialize the table of primitives to render. */
static void TAG(init)(void)
{
    tri_tab[IND]    = TAG(triangle);
    quad_tab[IND]   = TAG(quad);
    line_tab[IND]   = TAG(line);
    points_tab[IND] = TAG(points);
}

#undef IND
#undef TAG