Fix TCL_LIGHT_MODEL_CTL setting in radeonColorMaterial.
[mesa.git] / src / mesa / swrast_setup / ss_vbtmp.h
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 5.1
5 *
6 * Copyright (C) 1999-2003 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 * Authors:
26 * Keith Whitwell <keith@tungstengraphics.com>
27 */
28
29
30 static void TAG(emit)(GLcontext *ctx, GLuint start, GLuint end,
31 GLuint newinputs )
32 {
33 TNLcontext *tnl = TNL_CONTEXT(ctx);
34 struct vertex_buffer *VB = &tnl->vb;
35 SWvertex *v;
36 const GLfloat *ndc; /* NDC (i.e. projected clip coordinates) */
37 const GLfloat *tc[MAX_TEXTURE_COORD_UNITS];
38 const GLfloat *color;
39 const GLfloat *spec;
40 const GLfloat *index;
41 const GLfloat *fog;
42 const GLfloat *pointSize;
43 GLuint tsz[MAX_TEXTURE_COORD_UNITS];
44 GLuint tstride[MAX_TEXTURE_COORD_UNITS];
45 GLuint ndc_stride, color_stride, spec_stride, index_stride;
46 GLuint fog_stride, pointSize_stride;
47 GLuint i;
48 GLfloat *m = ctx->Viewport._WindowMap.m;
49 const GLfloat sx = m[0];
50 const GLfloat sy = m[5];
51 const GLfloat sz = m[10];
52 const GLfloat tx = m[12];
53 const GLfloat ty = m[13];
54 const GLfloat tz = m[14];
55 GLuint maxtex = 0;
56
57 if (IND & TEX0) {
58 tc[0] = (GLfloat *)VB->TexCoordPtr[0]->data;
59 tsz[0] = VB->TexCoordPtr[0]->size;
60 tstride[0] = VB->TexCoordPtr[0]->stride;
61 }
62
63 if (IND & MULTITEX) {
64 for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) {
65 if (VB->TexCoordPtr[i]) {
66 maxtex = i+1;
67 tc[i] = (GLfloat *)VB->TexCoordPtr[i]->data;
68 tsz[i] = VB->TexCoordPtr[i]->size;
69 tstride[i] = VB->TexCoordPtr[i]->stride;
70 }
71 else tc[i] = 0;
72 }
73 }
74
75 ndc = VB->NdcPtr->data[0];
76 ndc_stride = VB->NdcPtr->stride;
77
78 if (IND & FOG) {
79 fog = (GLfloat *) VB->FogCoordPtr->data;
80 fog_stride = VB->FogCoordPtr->stride;
81 }
82 if (IND & COLOR) {
83 color = (GLfloat *) VB->ColorPtr[0]->data;
84 color_stride = VB->ColorPtr[0]->stride;
85 }
86 if (IND & SPEC) {
87 spec = (GLfloat *) VB->SecondaryColorPtr[0]->data;
88 spec_stride = VB->SecondaryColorPtr[0]->stride;
89 }
90 if (IND & INDEX) {
91 index = (GLfloat *) VB->IndexPtr[0]->data;
92 index_stride = VB->IndexPtr[0]->stride;
93 }
94 if (IND & POINT) {
95 pointSize = (GLfloat *) VB->PointSizePtr->data;
96 pointSize_stride = VB->PointSizePtr->stride;
97 }
98
99 v = &(SWSETUP_CONTEXT(ctx)->verts[start]);
100
101 for (i=start; i < end; i++, v++) {
102 if (VB->ClipMask[i] == 0) {
103 v->win[0] = sx * ndc[0] + tx;
104 v->win[1] = sy * ndc[1] + ty;
105 v->win[2] = sz * ndc[2] + tz;
106 v->win[3] = ndc[3];
107 }
108 STRIDE_F(ndc, ndc_stride);
109
110 if (IND & TEX0) {
111 COPY_CLEAN_4V( v->texcoord[0], tsz[0], tc[0] );
112 STRIDE_F(tc[0], tstride[0]);
113 }
114
115 if (IND & MULTITEX) {
116 GLuint u;
117 for (u = 0 ; u < maxtex ; u++)
118 if (tc[u]) {
119 COPY_CLEAN_4V( v->texcoord[u], tsz[u], tc[u] );
120 STRIDE_F(tc[u], tstride[u]);
121 }
122 }
123
124 if (IND & COLOR) {
125 UNCLAMPED_FLOAT_TO_RGBA_CHAN(v->color, color);
126 STRIDE_F(color, color_stride);
127 }
128
129 if (IND & SPEC) {
130 UNCLAMPED_FLOAT_TO_RGBA_CHAN(v->specular, spec);
131 STRIDE_F(spec, spec_stride);
132 }
133
134 if (IND & FOG) {
135 v->fog = fog[0];
136 STRIDE_F(fog, fog_stride);
137 }
138
139 if (IND & INDEX) {
140 v->index = (GLuint) index[0];
141 STRIDE_F(index, index_stride);
142 }
143
144 if (IND & POINT) {
145 v->pointSize = pointSize[0];
146 STRIDE_F(pointSize, pointSize_stride);
147 }
148 }
149 }
150
151
152
153 static void TAG(interp)( GLcontext *ctx,
154 GLfloat t,
155 GLuint edst, GLuint eout, GLuint ein,
156 GLboolean force_boundary )
157 {
158 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
159 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
160 GLfloat *m = ctx->Viewport._WindowMap.m;
161 GLfloat *clip = VB->ClipPtr->data[edst];
162
163 SWvertex *dst = &swsetup->verts[edst];
164 SWvertex *in = &swsetup->verts[ein];
165 SWvertex *out = &swsetup->verts[eout];
166
167 /* Avoid division by zero by rearranging order of clip planes?
168 */
169 if (clip[3] != 0.0) {
170 GLfloat oow = 1.0F / clip[3];
171 dst->win[0] = m[0] * clip[0] * oow + m[12];
172 dst->win[1] = m[5] * clip[1] * oow + m[13];
173 dst->win[2] = m[10] * clip[2] * oow + m[14];
174 dst->win[3] = oow;
175 }
176
177 if (IND & TEX0) {
178 INTERP_4F( t, dst->texcoord[0], out->texcoord[0], in->texcoord[0] );
179 }
180
181 if (IND & MULTITEX) {
182 GLuint u;
183 GLuint maxtex = ctx->Const.MaxTextureUnits;
184 for (u = 0 ; u < maxtex ; u++)
185 if (VB->TexCoordPtr[u]) {
186 INTERP_4F( t, dst->texcoord[u], out->texcoord[u], in->texcoord[u] );
187 }
188 }
189
190 if (IND & COLOR) {
191 INTERP_CHAN( t, dst->color[0], out->color[0], in->color[0] );
192 INTERP_CHAN( t, dst->color[1], out->color[1], in->color[1] );
193 INTERP_CHAN( t, dst->color[2], out->color[2], in->color[2] );
194 INTERP_CHAN( t, dst->color[3], out->color[3], in->color[3] );
195 }
196
197 if (IND & SPEC) {
198 INTERP_CHAN( t, dst->specular[0], out->specular[0], in->specular[0] );
199 INTERP_CHAN( t, dst->specular[1], out->specular[1], in->specular[1] );
200 INTERP_CHAN( t, dst->specular[2], out->specular[2], in->specular[2] );
201 }
202
203 if (IND & FOG) {
204 INTERP_F( t, dst->fog, out->fog, in->fog );
205 }
206
207 if (IND & INDEX) {
208 INTERP_UI( t, dst->index, out->index, in->index );
209 }
210
211 /* XXX Point size interpolation??? */
212 if (IND & POINT) {
213 INTERP_F( t, dst->pointSize, out->pointSize, in->pointSize );
214 }
215 }
216
217
218 static void TAG(copy_pv)( GLcontext *ctx, GLuint edst, GLuint esrc )
219 {
220 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
221 SWvertex *dst = &swsetup->verts[edst];
222 SWvertex *src = &swsetup->verts[esrc];
223
224 if (IND & COLOR) {
225 COPY_CHAN4( dst->color, src->color );
226 }
227
228 if (IND & SPEC) {
229 COPY_3V( dst->specular, src->specular );
230 }
231
232 if (IND & INDEX) {
233 dst->index = src->index;
234 }
235 }
236
237
238 static void TAG(init)( void )
239 {
240 setup_tab[IND] = TAG(emit);
241 interp_tab[IND] = TAG(interp);
242 copy_pv_tab[IND] = TAG(copy_pv);
243 }
244
245 #undef TAG
246 #undef IND
247 #undef SETUP_FLAGS