db7bcd3334852d85b243cacc156c2a978c1de018
[mesa.git] / src / mesa / drivers / dri / mach64 / mach64_native_vb.c
1 /* $XFree86$ */ /* -*- 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->win[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->texcoord[1][0] = rhw*LE32_IN_FLOAT( p++ );
56 dst->texcoord[1][1] = rhw*LE32_IN_FLOAT( p++ );
57 }
58 #else
59 dst->texcoord[1][0] = LE32_IN_FLOAT( p++ );
60 dst->texcoord[1][1] = LE32_IN_FLOAT( p++ );
61 #endif
62 dst->texcoord[1][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->texcoord[0][0] = rhw*LE32_IN_FLOAT( p++ );
71 dst->texcoord[0][1] = rhw*LE32_IN_FLOAT( p++ );
72 }
73 #else
74 dst->texcoord[0][0] = LE32_IN_FLOAT( p++ );
75 dst->texcoord[0][1] = LE32_IN_FLOAT( p++ );
76 #endif
77 dst->texcoord[0][3] = 1.0;
78 dst->win[3] = LE32_IN_FLOAT( p++ );
79
80 case NOTEX_VERTEX_FORMAT:
81 dst->specular[2] = *((GLubyte *)p)++;
82 dst->specular[1] = *((GLubyte *)p)++;
83 dst->specular[0] = *((GLubyte *)p)++;
84 dst->fog = *((GLubyte *)p)++;
85
86 case TINY_VERTEX_FORMAT:
87 dst->win[2] = UNVIEWPORT_Z( LE32_IN( p++ ) );
88
89 dst->color[2] = *((GLubyte *)p)++;
90 dst->color[1] = *((GLubyte *)p)++;
91 dst->color[0] = *((GLubyte *)p)++;
92 dst->color[3] = *((GLubyte *)p)++;
93
94 {
95 GLuint xy = LE32_IN( p );
96
97 dst->win[0] = UNVIEWPORT_X( (GLfloat)(GLshort)( xy >> 16 ) );
98 dst->win[1] = UNVIEWPORT_Y( (GLfloat)(GLshort)( xy & 0xffff ) );
99 }
100 }
101
102 assert( p + 1 - (CARD32 *)src == 10 );
103
104 dst->pointSize = ctx->Point._Size;
105 }
106
107
108
109 void TAG(print_vertex)( GLcontext *ctx, const VERTEX *v )
110 {
111 LOCALVARS
112 GLuint format = GET_VERTEX_FORMAT();
113 CARD32 *p = (CARD32 *)v + 10 - mmesa->vertex_size;
114
115 switch ( format ) {
116 case TEX1_VERTEX_FORMAT:
117 {
118 GLfloat u, v, w;
119 #ifdef MACH64_PREMULT_TEXCOORDS
120 float rhw = 1.0 / LE32_IN_FLOAT( p + 2 );
121
122 u = rhw*LE32_IN_FLOAT( p++ );
123 v = rhw*LE32_IN_FLOAT( p++ );
124 #else
125 u = LE32_IN_FLOAT( p++ );
126 v = LE32_IN_FLOAT( p++ );
127 #endif
128 w = LE32_IN_FLOAT( p++ );
129 fprintf( stderr, "u1 %f v1 %f w1 %f\n", u, v, w );
130 }
131
132 case TEX0_VERTEX_FORMAT:
133 {
134 GLfloat u, v, w;
135 #ifdef MACH64_PREMULT_TEXCOORDS
136 float rhw = 1.0 / LE32_IN_FLOAT( p + 2 );
137
138 u = rhw*LE32_IN_FLOAT( p++ );
139 v = rhw*LE32_IN_FLOAT( p++ );
140 #else
141 u = LE32_IN_FLOAT( p++ );
142 v = LE32_IN_FLOAT( p++ );
143 #endif
144 w = LE32_IN_FLOAT( p++ );
145 fprintf( stderr, "u0 %f v0 %f w0 %f\n", u, v, w );
146 }
147
148 case NOTEX_VERTEX_FORMAT:
149 {
150 GLubyte r, g, b, a;
151
152 b = *((GLubyte *)p)++;
153 g = *((GLubyte *)p)++;
154 r = *((GLubyte *)p)++;
155 a = *((GLubyte *)p)++;
156
157 fprintf(stderr, "spec: r %d g %d b %d a %d\n", r, g, b, a);
158 }
159
160 case TINY_VERTEX_FORMAT:
161 {
162 GLuint xy;
163 GLfloat x, y, z;
164 GLubyte r, g, b, a;
165
166 z = LE32_IN( p++ ) / 65536.0;
167
168 b = *((GLubyte *)p)++;
169 g = *((GLubyte *)p)++;
170 r = *((GLubyte *)p)++;
171 a = *((GLubyte *)p)++;
172
173 xy = LE32_IN( p );
174 x = (GLfloat)(GLshort)( xy >> 16 ) / 4.0;
175 y = (GLfloat)(GLshort)( xy & 0xffff ) / 4.0;
176
177 fprintf(stderr, "x %f y %f z %f\n", x, y, z);
178 fprintf(stderr, "r %d g %d b %d a %d\n", r, g, b, a);
179 }
180 }
181
182 assert( p + 1 - (CARD32 *)v == 10 );
183
184 fprintf(stderr, "\n");
185 }
186
187 /* Interpolate the elements of the VB not included in typical hardware
188 * vertices.
189 *
190 * NOTE: All these arrays are guarenteed by tnl to be writeable and
191 * have good stride.
192 */
193 #ifndef INTERP_QUALIFIER
194 #define INTERP_QUALIFIER static
195 #endif
196
197 #define GET_COLOR(ptr, idx) ((ptr)->data[idx])
198
199
200 INTERP_QUALIFIER void TAG(interp_extras)( GLcontext *ctx,
201 GLfloat t,
202 GLuint dst, GLuint out, GLuint in,
203 GLboolean force_boundary )
204 {
205 LOCALVARS
206 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
207
208 if (VB->ColorPtr[1]) {
209 assert(VB->ColorPtr[1]->stride == 4 * sizeof(GLfloat));
210
211 INTERP_4F( t,
212 GET_COLOR(VB->ColorPtr[1], dst),
213 GET_COLOR(VB->ColorPtr[1], out),
214 GET_COLOR(VB->ColorPtr[1], in) );
215
216 if (VB->SecondaryColorPtr[1]) {
217 INTERP_3F( t,
218 GET_COLOR(VB->SecondaryColorPtr[1], dst),
219 GET_COLOR(VB->SecondaryColorPtr[1], out),
220 GET_COLOR(VB->SecondaryColorPtr[1], in) );
221 }
222 }
223
224 if (VB->EdgeFlag) {
225 VB->EdgeFlag[dst] = VB->EdgeFlag[out] || force_boundary;
226 }
227
228 INTERP_VERTEX(ctx, t, dst, out, in, force_boundary);
229 }
230
231 INTERP_QUALIFIER void TAG(copy_pv_extras)( GLcontext *ctx,
232 GLuint dst, GLuint src )
233 {
234 LOCALVARS
235 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
236
237 if (VB->ColorPtr[1]) {
238 COPY_4FV( GET_COLOR(VB->ColorPtr[1], dst),
239 GET_COLOR(VB->ColorPtr[1], src) );
240
241 if (VB->SecondaryColorPtr[1]) {
242 COPY_4FV( GET_COLOR(VB->SecondaryColorPtr[1], dst),
243 GET_COLOR(VB->SecondaryColorPtr[1], src) );
244 }
245 }
246
247 COPY_PV_VERTEX(ctx, dst, src);
248 }
249
250
251 #undef INTERP_QUALIFIER
252 #undef GET_COLOR
253
254 #undef IND
255 #undef TAG