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