draw: corrections to allow for different cliptest cases
[mesa.git] / src / mesa / drivers / dri / mach64 / mach64_native_vb.c
1 /* -*- mode: c; c-basic-offset: 3 -*- */
2 /*
3 * Mesa 3-D graphics library
4 * Version: 3.5
5 *
6 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 * Original authors:
26 * Keith Whitwell <keithw@valinux.com>
27 *
28 * Adapted to Mach64 by:
29 * José Fonseca <j_r_fonseca@yahoo.co.uk>
30 */
31
32 #include "math/m_translate.h"
33
34 #ifndef LOCALVARS
35 #define LOCALVARS
36 #endif
37
38 void TAG(translate_vertex)(GLcontext *ctx,
39 const VERTEX *src,
40 SWvertex *dst)
41 {
42 LOCALVARS
43 GLuint format = GET_VERTEX_FORMAT();
44 UNVIEWPORT_VARS;
45 CARD32 *p = (CARD32 *)src + 10 - mmesa->vertex_size;
46
47 dst->attrib[FRAG_ATTRIB_WPOS][3] = 1.0;
48
49 switch ( format ) {
50 case TEX1_VERTEX_FORMAT:
51 #ifdef MACH64_PREMULT_TEXCOORDS
52 {
53 float rhw = 1.0 / LE32_IN_FLOAT( p + 2 );
54
55 dst->attrib[FRAG_ATTRIB_TEX1][0] = rhw*LE32_IN_FLOAT( p++ );
56 dst->attrib[FRAG_ATTRIB_TEX1][1] = rhw*LE32_IN_FLOAT( p++ );
57 }
58 #else
59 dst->attrib[FRAG_ATTRIB_TEX1][0] = LE32_IN_FLOAT( p++ );
60 dst->attrib[FRAG_ATTRIB_TEX1][1] = LE32_IN_FLOAT( p++ );
61 #endif
62 dst->attrib[FRAG_ATTRIB_TEX1][3] = 1.0;
63 p++;
64
65 case TEX0_VERTEX_FORMAT:
66 #ifdef MACH64_PREMULT_TEXCOORDS
67 {
68 float rhw = 1.0 / LE32_IN_FLOAT( p + 2 );
69
70 dst->attrib[FRAG_ATTRIB_TEX0][0] = rhw*LE32_IN_FLOAT( p++ );
71 dst->attrib[FRAG_ATTRIB_TEX0][1] = rhw*LE32_IN_FLOAT( p++ );
72 }
73 #else
74 dst->attrib[FRAG_ATTRIB_TEX0][0] = LE32_IN_FLOAT( p++ );
75 dst->attrib[FRAG_ATTRIB_TEX0][1] = LE32_IN_FLOAT( p++ );
76 #endif
77 dst->attrib[FRAG_ATTRIB_TEX0][3] = 1.0;
78 dst->attrib[FRAG_ATTRIB_WPOS][3] = LE32_IN_FLOAT( p++ );
79
80 case NOTEX_VERTEX_FORMAT:
81 dst->attrib[FRAG_ATTRIB_COL1][2] = UBYTE_TO_FLOAT(((GLubyte *)p)[0]);
82 dst->attrib[FRAG_ATTRIB_COL1][1] = UBYTE_TO_FLOAT(((GLubyte *)p)[1]);
83 dst->attrib[FRAG_ATTRIB_COL1][0] = UBYTE_TO_FLOAT(((GLubyte *)p)[2]);
84 dst->attrib[FRAG_ATTRIB_FOGC][0] = ((GLubyte *)p)[3]; /*XXX int->float?*/
85 p++;
86
87 case TINY_VERTEX_FORMAT:
88 dst->attrib[FRAG_ATTRIB_WPOS][2] = UNVIEWPORT_Z( LE32_IN( p++ ) );
89
90 dst->color[2] = ((GLubyte *)p)[0];
91 dst->color[1] = ((GLubyte *)p)[1];
92 dst->color[0] = ((GLubyte *)p)[2];
93 dst->color[3] = ((GLubyte *)p)[3];
94 p++;
95
96 {
97 GLuint xy = LE32_IN( p );
98
99 dst->attrib[FRAG_ATTRIB_WPOS][0] = UNVIEWPORT_X( (GLfloat)(GLshort)( xy >> 16 ) );
100 dst->attrib[FRAG_ATTRIB_WPOS][1] = UNVIEWPORT_Y( (GLfloat)(GLshort)( xy & 0xffff ) );
101 }
102 }
103
104 assert( p + 1 - (CARD32 *)src == 10 );
105
106 dst->pointSize = ctx->Point.Size;
107 }
108
109
110
111 void TAG(print_vertex)( GLcontext *ctx, const VERTEX *v )
112 {
113 LOCALVARS
114 GLuint format = GET_VERTEX_FORMAT();
115 CARD32 *p = (CARD32 *)v + 10 - mmesa->vertex_size;
116
117 switch ( format ) {
118 case TEX1_VERTEX_FORMAT:
119 {
120 GLfloat u, v, w;
121 #ifdef MACH64_PREMULT_TEXCOORDS
122 float rhw = 1.0 / LE32_IN_FLOAT( p + 2 );
123
124 u = rhw*LE32_IN_FLOAT( p++ );
125 v = rhw*LE32_IN_FLOAT( p++ );
126 #else
127 u = LE32_IN_FLOAT( p++ );
128 v = LE32_IN_FLOAT( p++ );
129 #endif
130 w = LE32_IN_FLOAT( p++ );
131 fprintf( stderr, "u1 %f v1 %f w1 %f\n", u, v, w );
132 }
133
134 case TEX0_VERTEX_FORMAT:
135 {
136 GLfloat u, v, w;
137 #ifdef MACH64_PREMULT_TEXCOORDS
138 float rhw = 1.0 / LE32_IN_FLOAT( p + 2 );
139
140 u = rhw*LE32_IN_FLOAT( p++ );
141 v = rhw*LE32_IN_FLOAT( p++ );
142 #else
143 u = LE32_IN_FLOAT( p++ );
144 v = LE32_IN_FLOAT( p++ );
145 #endif
146 w = LE32_IN_FLOAT( p++ );
147 fprintf( stderr, "u0 %f v0 %f w0 %f\n", u, v, w );
148 }
149
150 case NOTEX_VERTEX_FORMAT:
151 {
152 GLubyte r, g, b, a;
153
154 b = ((GLubyte *)p)[0];
155 g = ((GLubyte *)p)[1];
156 r = ((GLubyte *)p)[2];
157 a = ((GLubyte *)p)[3];
158 p++;
159 fprintf(stderr, "spec: r %d g %d b %d a %d\n", r, g, b, a);
160 }
161
162 case TINY_VERTEX_FORMAT:
163 {
164 GLuint xy;
165 GLfloat x, y, z;
166 GLubyte r, g, b, a;
167
168 z = LE32_IN( p++ ) / 65536.0;
169
170 b = ((GLubyte *)p)[0];
171 g = ((GLubyte *)p)[1];
172 r = ((GLubyte *)p)[2];
173 a = ((GLubyte *)p)[3];
174 p++;
175 xy = LE32_IN( p );
176 x = (GLfloat)(GLshort)( xy >> 16 ) / 4.0;
177 y = (GLfloat)(GLshort)( xy & 0xffff ) / 4.0;
178
179 fprintf(stderr, "x %f y %f z %f\n", x, y, z);
180 fprintf(stderr, "r %d g %d b %d a %d\n", r, g, b, a);
181 }
182 }
183
184 assert( p + 1 - (CARD32 *)v == 10 );
185
186 fprintf(stderr, "\n");
187 }
188
189 /* Interpolate the elements of the VB not included in typical hardware
190 * vertices.
191 *
192 * NOTE: All these arrays are guarenteed by tnl to be writeable and
193 * have good stride.
194 */
195 #ifndef INTERP_QUALIFIER
196 #define INTERP_QUALIFIER static
197 #endif
198
199 #define GET_COLOR(ptr, idx) ((ptr)->data[idx])
200
201
202 INTERP_QUALIFIER void TAG(interp_extras)( GLcontext *ctx,
203 GLfloat t,
204 GLuint dst, GLuint out, GLuint in,
205 GLboolean force_boundary )
206 {
207 LOCALVARS
208 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
209
210 if (VB->BackfaceColorPtr) {
211 assert(VB->BackfaceColorPtr->stride == 4 * sizeof(GLfloat));
212
213 INTERP_4F( t,
214 GET_COLOR(VB->BackfaceColorPtr, dst),
215 GET_COLOR(VB->BackfaceColorPtr, out),
216 GET_COLOR(VB->BackfaceColorPtr, in) );
217
218 if (VB->BackfaceSecondaryColorPtr) {
219 INTERP_3F( t,
220 GET_COLOR(VB->BackfaceSecondaryColorPtr, dst),
221 GET_COLOR(VB->BackfaceSecondaryColorPtr, out),
222 GET_COLOR(VB->BackfaceSecondaryColorPtr, in) );
223 }
224 }
225
226 if (VB->EdgeFlag) {
227 VB->EdgeFlag[dst] = VB->EdgeFlag[out] || force_boundary;
228 }
229
230 INTERP_VERTEX(ctx, t, dst, out, in, force_boundary);
231 }
232
233 INTERP_QUALIFIER void TAG(copy_pv_extras)( GLcontext *ctx,
234 GLuint dst, GLuint src )
235 {
236 LOCALVARS
237 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
238
239 if (VB->BackfaceColorPtr) {
240 COPY_4FV( GET_COLOR(VB->BackfaceColorPtr, dst),
241 GET_COLOR(VB->BackfaceColorPtr, src) );
242
243 if (VB->BackfaceSecondaryColorPtr) {
244 COPY_4FV( GET_COLOR(VB->BackfaceSecondaryColorPtr, dst),
245 GET_COLOR(VB->BackfaceSecondaryColorPtr, src) );
246 }
247 }
248
249 COPY_PV_VERTEX(ctx, dst, src);
250 }
251
252
253 #undef INTERP_QUALIFIER
254 #undef GET_COLOR
255
256 #undef IND
257 #undef TAG