obsolete in favor of regular Makefiles
[mesa.git] / src / mesa / drivers / dri / r200 / r200_maos_vbtmp.h
1 /* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_maos_vbtmp.h,v 1.2 2002/12/16 16:18:54 dawes Exp $ */
2 /*
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4
5 The Weather Channel (TM) funded Tungsten Graphics to develop the
6 initial release of the Radeon 8500 driver under the XFree86 license.
7 This notice must be preserved.
8
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial
19 portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 */
29
30 /*
31 * Authors:
32 * Keith Whitwell <keith@tungstengraphics.com>
33 */
34
35 #ifndef LOCALVARS
36 #define LOCALVARS
37 #endif
38
39 #undef TCL_DEBUG
40 #ifndef TCL_DEBUG
41 #define TCL_DEBUG 0
42 #endif
43
44 static void TAG(emit)( GLcontext *ctx,
45 GLuint start, GLuint end,
46 void *dest )
47 {
48 LOCALVARS
49 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
50 GLuint (*tc0)[4], (*tc1)[4];
51 GLfloat *fog;
52 GLuint (*tc2)[4], (*norm)[3];
53 GLubyte (*col)[4], (*spec)[4];
54 GLuint tc0_stride, tc1_stride, col_stride, spec_stride, fog_stride;
55 GLuint tc2_stride, norm_stride;
56 GLuint (*coord)[4];
57 GLuint coord_stride;
58 GLubyte dummy[4];
59 int i;
60
61 union emit_union *v = (union emit_union *)dest;
62
63
64 if (R200_DEBUG & DEBUG_VERTS)
65 fprintf(stderr, "%s\n", __FUNCTION__);
66
67 /* The vertex code expects Obj to be clean to element 3. To fix
68 * this, add more vertex code (for obj-2, obj-3) or preferably move
69 * to maos.
70 */
71 if (VB->ObjPtr->size < 3) {
72 if (VB->ObjPtr->flags & VEC_NOT_WRITEABLE) {
73 VB->import_data( ctx, VERT_OBJ, VEC_NOT_WRITEABLE );
74 }
75 _mesa_vector4f_clean_elem( VB->ObjPtr, VB->Count, 2 );
76 }
77
78 if (DO_W && VB->ObjPtr->size < 4) {
79 if (VB->ObjPtr->flags & VEC_NOT_WRITEABLE) {
80 VB->import_data( ctx, VERT_OBJ, VEC_NOT_WRITEABLE );
81 }
82 _mesa_vector4f_clean_elem( VB->ObjPtr, VB->Count, 3 );
83 }
84
85 coord = (GLuint (*)[4])VB->ObjPtr->data;
86 coord_stride = VB->ObjPtr->stride;
87
88 if (DO_TEX2) {
89 const GLuint t2 = GET_TEXSOURCE(2);
90 tc2 = (GLuint (*)[4])VB->TexCoordPtr[t2]->data;
91 tc2_stride = VB->TexCoordPtr[t2]->stride;
92 if (DO_PTEX && VB->TexCoordPtr[t2]->size < 4) {
93 if (VB->TexCoordPtr[t2]->flags & VEC_NOT_WRITEABLE) {
94 VB->import_data( ctx, VERT_TEX2, VEC_NOT_WRITEABLE );
95 }
96 _mesa_vector4f_clean_elem( VB->TexCoordPtr[t2], VB->Count, 3 );
97 }
98 }
99
100 if (DO_TEX1) {
101 if (VB->TexCoordPtr[1]) {
102 const GLuint t1 = GET_TEXSOURCE(1);
103 tc1 = (GLuint (*)[4])VB->TexCoordPtr[t1]->data;
104 tc1_stride = VB->TexCoordPtr[t1]->stride;
105 if (DO_PTEX && VB->TexCoordPtr[t1]->size < 4) {
106 if (VB->TexCoordPtr[t1]->flags & VEC_NOT_WRITEABLE) {
107 VB->import_data( ctx, VERT_TEX1, VEC_NOT_WRITEABLE );
108 }
109 _mesa_vector4f_clean_elem( VB->TexCoordPtr[t1], VB->Count, 3 );
110 }
111 } else {
112 tc1 = (GLuint (*)[4])&ctx->Current.Texcoord[1]; /* could be anything, really */
113 tc1_stride = 0;
114 }
115 }
116
117 if (DO_TEX0) {
118 if (VB->TexCoordPtr[0]) {
119 const GLuint t0 = GET_TEXSOURCE(0);
120 tc0_stride = VB->TexCoordPtr[t0]->stride;
121 tc0 = (GLuint (*)[4])VB->TexCoordPtr[t0]->data;
122 if (DO_PTEX && VB->TexCoordPtr[t0]->size < 4) {
123 if (VB->TexCoordPtr[t0]->flags & VEC_NOT_WRITEABLE) {
124 VB->import_data( ctx, VERT_TEX0, VEC_NOT_WRITEABLE );
125 }
126 _mesa_vector4f_clean_elem( VB->TexCoordPtr[t0], VB->Count, 3 );
127 }
128 } else {
129 tc0 = (GLuint (*)[4])&ctx->Current.Texcoord[0]; /* could be anything, really */
130 tc0_stride = 0;
131 }
132
133 }
134
135 if (DO_NORM) {
136 if (VB->NormalPtr) {
137 norm_stride = VB->NormalPtr->stride;
138 norm = (GLuint (*)[3])VB->NormalPtr->data;
139 } else {
140 norm_stride = 0;
141 norm = (GLuint (*)[3])&ctx->Current.Normal;
142 }
143 }
144
145 if (DO_RGBA) {
146 if (VB->ColorPtr[0]) {
147 /* This is incorrect when colormaterial is enabled:
148 */
149 if (VB->ColorPtr[0]->Type != GL_UNSIGNED_BYTE) {
150 if (0) fprintf(stderr, "IMPORTING FLOAT COLORS\n");
151 IMPORT_FLOAT_COLORS( ctx );
152 }
153 col = (GLubyte (*)[4])VB->ColorPtr[0]->Ptr;
154 col_stride = VB->ColorPtr[0]->StrideB;
155 } else {
156 col = &dummy; /* any old memory is fine */
157 col_stride = 0;
158 }
159
160 }
161
162 if (DO_SPEC) {
163 if (VB->SecondaryColorPtr[0]) {
164 if (VB->SecondaryColorPtr[0]->Type != GL_UNSIGNED_BYTE)
165 IMPORT_FLOAT_SPEC_COLORS( ctx );
166 spec = (GLubyte (*)[4])VB->SecondaryColorPtr[0]->Ptr;
167 spec_stride = VB->SecondaryColorPtr[0]->StrideB;
168 } else {
169 spec = &dummy;
170 spec_stride = 0;
171 }
172
173 }
174
175 if (DO_FOG) {
176 if (VB->FogCoordPtr) {
177 fog = VB->FogCoordPtr->data;
178 fog_stride = VB->FogCoordPtr->stride;
179 } else {
180 fog = (GLfloat *)&dummy; *fog = 0;
181 fog_stride = 0;
182 }
183
184 }
185
186
187 if (VB->importable_data) {
188 if (start) {
189 coord = (GLuint (*)[4])((GLubyte *)coord + start * coord_stride);
190 if (DO_TEX0)
191 tc0 = (GLuint (*)[4])((GLubyte *)tc0 + start * tc0_stride);
192 if (DO_TEX1)
193 tc1 = (GLuint (*)[4])((GLubyte *)tc1 + start * tc1_stride);
194 if (DO_TEX2)
195 tc2 = (GLuint (*)[4])((GLubyte *)tc2 + start * tc2_stride);
196 if (DO_NORM)
197 norm = (GLuint (*)[3])((GLubyte *)norm + start * norm_stride);
198 if (DO_RGBA)
199 STRIDE_4UB(col, start * col_stride);
200 if (DO_SPEC)
201 STRIDE_4UB(spec, start * spec_stride);
202 if (DO_FOG)
203 STRIDE_F(fog, start * fog_stride);
204 }
205
206 for (i=start; i < end; i++) {
207 v[0].ui = coord[0][0];
208 v[1].ui = coord[0][1];
209 v[2].ui = coord[0][2];
210 if (TCL_DEBUG) fprintf(stderr, "%d: %.2f %.2f %.2f ", i, v[0].f, v[1].f, v[2].f);
211 if (DO_W) {
212 v[3].ui = coord[0][3];
213 if (TCL_DEBUG) fprintf(stderr, "%.2f ", v[3].f);
214 v += 4;
215 }
216 else
217 v += 3;
218 coord = (GLuint (*)[4])((GLubyte *)coord + coord_stride);
219
220 if (DO_NORM) {
221 v[0].ui = norm[0][0];
222 v[1].ui = norm[0][1];
223 v[2].ui = norm[0][2];
224 if (TCL_DEBUG) fprintf(stderr, "norm: %.2f %.2f %.2f ", v[0].f, v[1].f, v[2].f);
225 v += 3;
226 norm = (GLuint (*)[3])((GLubyte *)norm + norm_stride);
227 }
228 if (DO_RGBA) {
229 v[0].ui = LE32_TO_CPU(*(GLuint *)&col[0]);
230 STRIDE_4UB(col, col_stride);
231 if (TCL_DEBUG) fprintf(stderr, "%x ", v[0].ui);
232 v++;
233 }
234 if (DO_SPEC || DO_FOG) {
235 if (DO_SPEC) {
236 v[0].ub[0] = spec[0][0];
237 v[0].ub[1] = spec[0][1];
238 v[0].ub[2] = spec[0][2];
239 STRIDE_4UB(spec, spec_stride);
240 }
241 if (DO_FOG) {
242 v[0].ub[3] = fog[0] * 255.0;
243 STRIDE_F(fog, fog_stride);
244 }
245 if (TCL_DEBUG) fprintf(stderr, "%x ", v[0].ui);
246 v++;
247 }
248 if (DO_TEX0) {
249 v[0].ui = tc0[0][0];
250 v[1].ui = tc0[0][1];
251 if (TCL_DEBUG) fprintf(stderr, "t0: %.2f %.2f ", v[0].f, v[1].f);
252 if (DO_PTEX) {
253 v[2].ui = tc0[0][3];
254 if (TCL_DEBUG) fprintf(stderr, "%.2f ", v[2].f);
255 v += 3;
256 }
257 else
258 v += 2;
259 tc0 = (GLuint (*)[4])((GLubyte *)tc0 + tc0_stride);
260 }
261 if (DO_TEX1) {
262 v[0].ui = tc1[0][0];
263 v[1].ui = tc1[0][1];
264 if (TCL_DEBUG) fprintf(stderr, "t1: %.2f %.2f ", v[0].f, v[1].f);
265 if (DO_PTEX) {
266 v[2].ui = tc1[0][3];
267 if (TCL_DEBUG) fprintf(stderr, "%.2f ", v[2].f);
268 v += 3;
269 }
270 else
271 v += 2;
272 tc1 = (GLuint (*)[4])((GLubyte *)tc1 + tc1_stride);
273 }
274 if (DO_TEX2) {
275 v[0].ui = tc2[0][0];
276 v[1].ui = tc2[0][1];
277 if (DO_PTEX) {
278 v[2].ui = tc2[0][3];
279 v += 3;
280 }
281 else
282 v += 2;
283 tc2 = (GLuint (*)[4])((GLubyte *)tc2 + tc2_stride);
284 }
285 if (TCL_DEBUG) fprintf(stderr, "\n");
286 }
287 } else {
288 for (i=start; i < end; i++) {
289 v[0].ui = coord[i][0];
290 v[1].ui = coord[i][1];
291 v[2].ui = coord[i][2];
292 if (DO_W) {
293 v[3].ui = coord[i][3];
294 v += 4;
295 }
296 else
297 v += 3;
298
299 if (DO_NORM) {
300 v[0].ui = norm[i][0];
301 v[1].ui = norm[i][1];
302 v[2].ui = norm[i][2];
303 v += 3;
304 }
305 if (DO_RGBA) {
306 v[0].ui = LE32_TO_CPU(*(GLuint *)&col[i]);
307 v++;
308 }
309 if (DO_SPEC || DO_FOG) {
310 if (DO_SPEC) {
311 v[0].ub[0] = spec[i][0];
312 v[0].ub[1] = spec[i][1];
313 v[0].ub[2] = spec[i][2];
314 }
315 if (DO_FOG) {
316 v[0].ub[3] = fog[i] * 255.0;
317 }
318 v++;
319 }
320 if (DO_TEX0) {
321 v[0].ui = tc0[i][0];
322 v[1].ui = tc0[i][1];
323 if (DO_PTEX) {
324 v[2].ui = tc0[i][3];
325 v += 3;
326 }
327 else
328 v += 2;
329 }
330 if (DO_TEX1) {
331 v[0].ui = tc1[i][0];
332 v[1].ui = tc1[i][1];
333 if (DO_PTEX) {
334 v[2].ui = tc1[i][3];
335 v += 3;
336 }
337 else
338 v += 2;
339 }
340 if (DO_TEX2) {
341 v[0].ui = tc2[i][0];
342 v[1].ui = tc2[i][1];
343 if (DO_PTEX) {
344 v[2].ui = tc2[i][3];
345 v += 3;
346 }
347 else
348 v += 2;
349 }
350 }
351 }
352 }
353
354
355
356 static void TAG(init)( void )
357 {
358 int sz = 3;
359 if (DO_W) sz++;
360 if (DO_NORM) sz += 3;
361 if (DO_RGBA) sz++;
362 if (DO_SPEC || DO_FOG) sz++;
363 if (DO_TEX0) sz += 2;
364 if (DO_TEX0 && DO_PTEX) sz++;
365 if (DO_TEX1) sz += 2;
366 if (DO_TEX1 && DO_PTEX) sz++;
367 if (DO_TEX2) sz += 2;
368 if (DO_TEX2 && DO_PTEX) sz++;
369
370 setup_tab[IDX].emit = TAG(emit);
371 setup_tab[IDX].vertex_format = IND;
372 setup_tab[IDX].vertex_size = sz;
373 }
374
375
376 #undef IND
377 #undef TAG
378 #undef IDX