Fix calculation of fog coordinate in translate_vertex().
[mesa.git] / src / mesa / drivers / common / t_dd_vb.c
1 /* $Id: t_dd_vb.c,v 1.8 2001/03/30 00:39:02 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 * Authors:
27 * Keith Whitwell <keithw@valinux.com>
28 */
29
30 #if (HAVE_HW_VIEWPORT)
31 #define UNVIEWPORT_VARS
32 #define UNVIEWPORT_X(x) x
33 #define UNVIEWPORT_Y(x) x
34 #define UNVIEWPORT_Z(x) x
35 #endif
36
37 #ifndef LOCALVARS
38 #define LOCALVARS
39 #endif
40
41 /* These don't need to be duplicated, but there's currently nowhere
42 * really convenient to put them. Need to build some actual .o files in
43 * this directory?
44 */
45 static void copy_pv_rgba4_spec5( GLcontext *ctx, GLuint edst, GLuint esrc )
46 {
47 LOCALVARS
48 GLubyte *verts = GET_VERTEX_STORE();
49 GLuint shift = GET_VERTEX_STRIDE_SHIFT();
50 GLuint *dst = (GLuint *)(verts + (edst << shift));
51 GLuint *src = (GLuint *)(verts + (esrc << shift));
52 dst[4] = src[4];
53 dst[5] = src[5];
54 }
55
56 static void copy_pv_rgba4( GLcontext *ctx, GLuint edst, GLuint esrc )
57 {
58 LOCALVARS
59 GLubyte *verts = GET_VERTEX_STORE();
60 GLuint shift = GET_VERTEX_STRIDE_SHIFT();
61 GLuint *dst = (GLuint *)(verts + (edst << shift));
62 GLuint *src = (GLuint *)(verts + (esrc << shift));
63 dst[4] = src[4];
64 }
65
66 static void copy_pv_rgba3( GLcontext *ctx, GLuint edst, GLuint esrc )
67 {
68 LOCALVARS
69 GLubyte *verts = GET_VERTEX_STORE();
70 GLuint shift = GET_VERTEX_STRIDE_SHIFT();
71 GLuint *dst = (GLuint *)(verts + (edst << shift));
72 GLuint *src = (GLuint *)(verts + (esrc << shift));
73 dst[3] = src[3];
74 }
75
76
77 void TAG(translate_vertex)(GLcontext *ctx,
78 const VERTEX *src,
79 SWvertex *dst)
80 {
81 LOCALVARS
82 GLuint format = GET_VERTEX_FORMAT();
83 GLfloat *s = ctx->Viewport._WindowMap.m;
84 UNVIEWPORT_VARS;
85
86 if (format == TINY_VERTEX_FORMAT) {
87 if (HAVE_HW_VIEWPORT) {
88 dst->win[0] = s[0] * src->v.x + s[12];
89 dst->win[1] = s[5] * src->v.y + s[13];
90 dst->win[2] = s[10] * src->v.z + s[14];
91 dst->win[3] = 1.0;
92 } else {
93 dst->win[0] = UNVIEWPORT_X( src->v.x );
94 dst->win[1] = UNVIEWPORT_Y( src->v.y );
95 dst->win[2] = UNVIEWPORT_Z( src->v.z );
96 dst->win[3] = 1.0;
97 }
98
99 dst->color[0] = src->tv.color.red;
100 dst->color[1] = src->tv.color.green;
101 dst->color[2] = src->tv.color.blue;
102 dst->color[3] = src->tv.color.alpha;
103 }
104 else {
105 GLfloat oow = (HAVE_HW_DIVIDE) ? 1.0 / src->v.w : src->v.w;
106
107 if (HAVE_HW_VIEWPORT) {
108 if (HAVE_HW_DIVIDE) {
109 dst->win[0] = s[0] * src->v.x * oow + s[12];
110 dst->win[1] = s[5] * src->v.y * oow + s[13];
111 dst->win[2] = s[10] * src->v.z * oow + s[14];
112 dst->win[3] = oow;
113 } else {
114 dst->win[0] = s[0] * src->v.x + s[12];
115 dst->win[1] = s[5] * src->v.y + s[13];
116 dst->win[2] = s[10] * src->v.z + s[14];
117 dst->win[3] = oow;
118 }
119 } else {
120 dst->win[0] = UNVIEWPORT_X( src->v.x );
121 dst->win[1] = UNVIEWPORT_Y( src->v.y );
122 dst->win[2] = UNVIEWPORT_Z( src->v.z );
123 dst->win[3] = oow;
124 }
125
126 dst->color[0] = src->v.color.red;
127 dst->color[1] = src->v.color.green;
128 dst->color[2] = src->v.color.blue;
129 dst->color[3] = src->v.color.alpha;
130
131 dst->specular[0] = src->v.specular.red;
132 dst->specular[1] = src->v.specular.green;
133 dst->specular[2] = src->v.specular.blue;
134
135 dst->fog = src->v.specular.alpha/255.0;
136
137 if (HAVE_PTEX_VERTICES &&
138 ((HAVE_TEX2_VERTICES && format == PROJ_TEX3_VERTEX_FORMAT) ||
139 (format == PROJ_TEX1_VERTEX_FORMAT))) {
140
141 dst->texcoord[0][0] = src->pv.u0;
142 dst->texcoord[0][1] = src->pv.v0;
143 dst->texcoord[0][3] = src->pv.q0;
144
145 dst->texcoord[1][0] = src->pv.u1;
146 dst->texcoord[1][1] = src->pv.v1;
147 dst->texcoord[1][3] = src->pv.q1;
148
149 if (HAVE_TEX2_VERTICES) {
150 dst->texcoord[2][0] = src->pv.u2;
151 dst->texcoord[2][1] = src->pv.v2;
152 dst->texcoord[2][3] = src->pv.q2;
153 }
154
155 if (HAVE_TEX3_VERTICES) {
156 dst->texcoord[3][0] = src->pv.u3;
157 dst->texcoord[3][1] = src->pv.v3;
158 dst->texcoord[3][3] = src->pv.q3;
159 }
160 }
161 else {
162 dst->texcoord[0][0] = src->v.u0;
163 dst->texcoord[0][1] = src->v.v0;
164 dst->texcoord[0][3] = 1.0;
165
166 dst->texcoord[1][0] = src->v.u1;
167 dst->texcoord[1][1] = src->v.v1;
168 dst->texcoord[1][3] = 1.0;
169
170 if (HAVE_TEX2_VERTICES) {
171 dst->texcoord[2][0] = src->v.u2;
172 dst->texcoord[2][1] = src->v.v2;
173 dst->texcoord[2][3] = 1.0;
174 }
175
176 if (HAVE_TEX3_VERTICES) {
177 dst->texcoord[3][0] = src->v.u3;
178 dst->texcoord[3][1] = src->v.v3;
179 dst->texcoord[3][3] = 1.0;
180 }
181 }
182 }
183
184 dst->pointSize = ctx->Point._Size;
185 }
186
187
188
189 void TAG(print_vertex)( GLcontext *ctx, const VERTEX *v )
190 {
191 LOCALVARS
192 GLuint format = GET_VERTEX_FORMAT();
193
194 if (format == TINY_VERTEX_FORMAT) {
195 fprintf(stderr, "x %f y %f z %f\n", v->v.x, v->v.y, v->v.z);
196 fprintf(stderr, "r %d g %d b %d a %d\n",
197 v->tv.color.red,
198 v->tv.color.green,
199 v->tv.color.blue,
200 v->tv.color.alpha);
201 }
202 else {
203 fprintf(stderr, "x %f y %f z %f oow %f\n",
204 v->v.x, v->v.y, v->v.z, v->v.w);
205 fprintf(stderr, "r %d g %d b %d a %d\n",
206 v->v.color.red,
207 v->v.color.green,
208 v->v.color.blue,
209 v->v.color.alpha);
210 }
211
212 fprintf(stderr, "\n");
213 }
214
215
216 #undef TAG