1 /* -*- mode: c; c-basic-offset: 3 -*- */
3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
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.
26 * Keith Whitwell <keithw@valinux.com>
28 * Adapted to Mach64 by:
29 * José Fonseca <j_r_fonseca@yahoo.co.uk>
32 #include "math/m_translate.h"
38 void TAG(translate_vertex)(struct gl_context *ctx,
43 GLuint format = GET_VERTEX_FORMAT();
45 CARD32 *p = (CARD32 *)src + 10 - mmesa->vertex_size;
47 dst->attrib[FRAG_ATTRIB_WPOS][3] = 1.0;
50 case TEX1_VERTEX_FORMAT:
51 #ifdef MACH64_PREMULT_TEXCOORDS
53 float rhw = 1.0 / LE32_IN_FLOAT( p + 2 );
55 dst->attrib[FRAG_ATTRIB_TEX1][0] = rhw*LE32_IN_FLOAT( p++ );
56 dst->attrib[FRAG_ATTRIB_TEX1][1] = rhw*LE32_IN_FLOAT( p++ );
59 dst->attrib[FRAG_ATTRIB_TEX1][0] = LE32_IN_FLOAT( p++ );
60 dst->attrib[FRAG_ATTRIB_TEX1][1] = LE32_IN_FLOAT( p++ );
62 dst->attrib[FRAG_ATTRIB_TEX1][3] = 1.0;
65 case TEX0_VERTEX_FORMAT:
66 #ifdef MACH64_PREMULT_TEXCOORDS
68 float rhw = 1.0 / LE32_IN_FLOAT( p + 2 );
70 dst->attrib[FRAG_ATTRIB_TEX0][0] = rhw*LE32_IN_FLOAT( p++ );
71 dst->attrib[FRAG_ATTRIB_TEX0][1] = rhw*LE32_IN_FLOAT( p++ );
74 dst->attrib[FRAG_ATTRIB_TEX0][0] = LE32_IN_FLOAT( p++ );
75 dst->attrib[FRAG_ATTRIB_TEX0][1] = LE32_IN_FLOAT( p++ );
77 dst->attrib[FRAG_ATTRIB_TEX0][3] = 1.0;
78 dst->attrib[FRAG_ATTRIB_WPOS][3] = LE32_IN_FLOAT( p++ );
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?*/
87 case TINY_VERTEX_FORMAT:
88 dst->attrib[FRAG_ATTRIB_WPOS][2] = UNVIEWPORT_Z( LE32_IN( p++ ) );
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];
97 GLuint xy = LE32_IN( p );
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 ) );
104 assert( p + 1 - (CARD32 *)src == 10 );
106 dst->pointSize = ctx->Point.Size;
111 void TAG(print_vertex)( struct gl_context *ctx, const VERTEX *v )
114 GLuint format = GET_VERTEX_FORMAT();
115 CARD32 *p = (CARD32 *)v + 10 - mmesa->vertex_size;
118 case TEX1_VERTEX_FORMAT:
121 #ifdef MACH64_PREMULT_TEXCOORDS
122 float rhw = 1.0 / LE32_IN_FLOAT( p + 2 );
124 u = rhw*LE32_IN_FLOAT( p++ );
125 v = rhw*LE32_IN_FLOAT( p++ );
127 u = LE32_IN_FLOAT( p++ );
128 v = LE32_IN_FLOAT( p++ );
130 w = LE32_IN_FLOAT( p++ );
131 fprintf( stderr, "u1 %f v1 %f w1 %f\n", u, v, w );
134 case TEX0_VERTEX_FORMAT:
137 #ifdef MACH64_PREMULT_TEXCOORDS
138 float rhw = 1.0 / LE32_IN_FLOAT( p + 2 );
140 u = rhw*LE32_IN_FLOAT( p++ );
141 v = rhw*LE32_IN_FLOAT( p++ );
143 u = LE32_IN_FLOAT( p++ );
144 v = LE32_IN_FLOAT( p++ );
146 w = LE32_IN_FLOAT( p++ );
147 fprintf( stderr, "u0 %f v0 %f w0 %f\n", u, v, w );
150 case NOTEX_VERTEX_FORMAT:
154 b = ((GLubyte *)p)[0];
155 g = ((GLubyte *)p)[1];
156 r = ((GLubyte *)p)[2];
157 a = ((GLubyte *)p)[3];
159 fprintf(stderr, "spec: r %d g %d b %d a %d\n", r, g, b, a);
162 case TINY_VERTEX_FORMAT:
168 z = LE32_IN( p++ ) / 65536.0;
170 b = ((GLubyte *)p)[0];
171 g = ((GLubyte *)p)[1];
172 r = ((GLubyte *)p)[2];
173 a = ((GLubyte *)p)[3];
176 x = (GLfloat)(GLshort)( xy >> 16 ) / 4.0;
177 y = (GLfloat)(GLshort)( xy & 0xffff ) / 4.0;
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);
184 assert( p + 1 - (CARD32 *)v == 10 );
186 fprintf(stderr, "\n");
189 /* Interpolate the elements of the VB not included in typical hardware
192 * NOTE: All these arrays are guarenteed by tnl to be writeable and
195 #ifndef INTERP_QUALIFIER
196 #define INTERP_QUALIFIER static
199 #define GET_COLOR(ptr, idx) ((ptr)->data[idx])
202 INTERP_QUALIFIER void TAG(interp_extras)( struct gl_context *ctx,
204 GLuint dst, GLuint out, GLuint in,
205 GLboolean force_boundary )
208 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
210 if (VB->BackfaceColorPtr) {
211 assert(VB->BackfaceColorPtr->stride == 4 * sizeof(GLfloat));
214 GET_COLOR(VB->BackfaceColorPtr, dst),
215 GET_COLOR(VB->BackfaceColorPtr, out),
216 GET_COLOR(VB->BackfaceColorPtr, in) );
218 if (VB->BackfaceSecondaryColorPtr) {
220 GET_COLOR(VB->BackfaceSecondaryColorPtr, dst),
221 GET_COLOR(VB->BackfaceSecondaryColorPtr, out),
222 GET_COLOR(VB->BackfaceSecondaryColorPtr, in) );
227 VB->EdgeFlag[dst] = VB->EdgeFlag[out] || force_boundary;
230 INTERP_VERTEX(ctx, t, dst, out, in, force_boundary);
233 INTERP_QUALIFIER void TAG(copy_pv_extras)( struct gl_context *ctx,
234 GLuint dst, GLuint src )
237 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
239 if (VB->BackfaceColorPtr) {
240 COPY_4FV( GET_COLOR(VB->BackfaceColorPtr, dst),
241 GET_COLOR(VB->BackfaceColorPtr, src) );
243 if (VB->BackfaceSecondaryColorPtr) {
244 COPY_4FV( GET_COLOR(VB->BackfaceSecondaryColorPtr, dst),
245 GET_COLOR(VB->BackfaceSecondaryColorPtr, src) );
249 COPY_PV_VERTEX(ctx, dst, src);
253 #undef INTERP_QUALIFIER