radeon/r200/r300: another big merge upheavel.
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_maos_vbtmp.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 4.1
4 *
5 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Keith Whitwell <keith@tungstengraphics.com>
26 */
27
28 #ifndef LOCALVARS
29 #define LOCALVARS
30 #endif
31
32 #undef TCL_DEBUG
33 #ifndef TCL_DEBUG
34 #define TCL_DEBUG 0
35 #endif
36
37 static void TAG(emit)( GLcontext *ctx,
38 GLuint start, GLuint end,
39 void *dest )
40 {
41 LOCALVARS
42 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
43 GLuint (*tc0)[4], (*tc1)[4], (*tc2)[4];
44 GLfloat (*col)[4], (*spec)[4];
45 GLfloat (*fog)[4];
46 GLuint (*norm)[4];
47 GLuint tc0_stride, tc1_stride, col_stride, spec_stride, fog_stride;
48 GLuint tc2_stride, norm_stride;
49 GLuint fill_tex = 0;
50 GLuint rqcoordsnoswap = 0;
51 GLuint (*coord)[4];
52 GLuint coord_stride; /* object coordinates */
53 int i;
54
55 union emit_union *v = (union emit_union *)dest;
56
57 if (RADEON_DEBUG & DEBUG_VERTS)
58 fprintf(stderr, "%s\n", __FUNCTION__);
59
60 coord = (GLuint (*)[4])VB->ObjPtr->data;
61 coord_stride = VB->ObjPtr->stride;
62
63 if (DO_TEX2) {
64 if (VB->TexCoordPtr[2]) {
65 const GLuint t2 = GET_TEXSOURCE(2);
66 tc2 = (GLuint (*)[4])VB->TexCoordPtr[t2]->data;
67 tc2_stride = VB->TexCoordPtr[t2]->stride;
68 if (DO_PTEX && VB->TexCoordPtr[t2]->size < 3) {
69 fill_tex |= (1<<2);
70 }
71 else if (DO_PTEX && VB->TexCoordPtr[t2]->size < 4) {
72 rqcoordsnoswap |= (1<<2);
73 }
74 } else {
75 tc2 = (GLuint (*)[4])&ctx->Current.Attrib[VERT_ATTRIB_TEX2];
76 tc2_stride = 0;
77 }
78 }
79
80 if (DO_TEX1) {
81 if (VB->TexCoordPtr[1]) {
82 const GLuint t1 = GET_TEXSOURCE(1);
83 tc1 = (GLuint (*)[4])VB->TexCoordPtr[t1]->data;
84 tc1_stride = VB->TexCoordPtr[t1]->stride;
85 if (DO_PTEX && VB->TexCoordPtr[t1]->size < 3) {
86 fill_tex |= (1<<1);
87 }
88 else if (DO_PTEX && VB->TexCoordPtr[t1]->size < 4) {
89 rqcoordsnoswap |= (1<<1);
90 }
91 } else {
92 tc1 = (GLuint (*)[4])&ctx->Current.Attrib[VERT_ATTRIB_TEX1];
93 tc1_stride = 0;
94 }
95 }
96
97 if (DO_TEX0) {
98 if (VB->TexCoordPtr[0]) {
99 const GLuint t0 = GET_TEXSOURCE(0);
100 tc0_stride = VB->TexCoordPtr[t0]->stride;
101 tc0 = (GLuint (*)[4])VB->TexCoordPtr[t0]->data;
102 if (DO_PTEX && VB->TexCoordPtr[t0]->size < 3) {
103 fill_tex |= (1<<0);
104 }
105 else if (DO_PTEX && VB->TexCoordPtr[t0]->size < 4) {
106 rqcoordsnoswap |= (1<<0);
107 }
108 } else {
109 tc0 = (GLuint (*)[4])&ctx->Current.Attrib[VERT_ATTRIB_TEX0];
110 tc0_stride = 0;
111 }
112
113 }
114
115 if (DO_NORM) {
116 if (VB->NormalPtr) {
117 norm_stride = VB->NormalPtr->stride;
118 norm = (GLuint (*)[4])VB->NormalPtr->data;
119 } else {
120 norm_stride = 0;
121 norm = (GLuint (*)[4])&ctx->Current.Attrib[VERT_ATTRIB_NORMAL];
122 }
123 }
124
125 if (DO_RGBA) {
126 if (VB->ColorPtr[0]) {
127 col = VB->ColorPtr[0]->data;
128 col_stride = VB->ColorPtr[0]->stride;
129 } else {
130 col = (GLfloat (*)[4])ctx->Current.Attrib[VERT_ATTRIB_COLOR0];
131 col_stride = 0;
132 }
133 }
134
135 if (DO_SPEC_OR_FOG) {
136 if (VB->SecondaryColorPtr[0]) {
137 spec = VB->SecondaryColorPtr[0]->data;
138 spec_stride = VB->SecondaryColorPtr[0]->stride;
139 } else {
140 spec = (GLfloat (*)[4])ctx->Current.Attrib[VERT_ATTRIB_COLOR1];
141 spec_stride = 0;
142 }
143 }
144
145 if (DO_SPEC_OR_FOG) {
146 if (VB->FogCoordPtr) {
147 fog = VB->FogCoordPtr->data;
148 fog_stride = VB->FogCoordPtr->stride;
149 } else {
150 fog = (GLfloat (*)[4])ctx->Current.Attrib[VERT_ATTRIB_FOG];
151 fog_stride = 0;
152 }
153 }
154
155
156 if (start) {
157 coord = (GLuint (*)[4])((GLubyte *)coord + start * coord_stride);
158 if (DO_TEX0)
159 tc0 = (GLuint (*)[4])((GLubyte *)tc0 + start * tc0_stride);
160 if (DO_TEX1)
161 tc1 = (GLuint (*)[4])((GLubyte *)tc1 + start * tc1_stride);
162 if (DO_TEX2)
163 tc2 = (GLuint (*)[4])((GLubyte *)tc2 + start * tc2_stride);
164 if (DO_NORM)
165 norm = (GLuint (*)[4])((GLubyte *)norm + start * norm_stride);
166 if (DO_RGBA)
167 STRIDE_4F(col, start * col_stride);
168 if (DO_SPEC)
169 STRIDE_4F(spec, start * spec_stride);
170 if (DO_FOG)
171 STRIDE_4F(fog, start * fog_stride);
172 }
173
174
175 {
176 for (i=start; i < end; i++) {
177
178 v[0].ui = coord[0][0];
179 v[1].ui = coord[0][1];
180 v[2].ui = coord[0][2];
181 if (DO_W) {
182 v[3].ui = coord[0][3];
183 v += 4;
184 }
185 else
186 v += 3;
187 coord = (GLuint (*)[4])((GLubyte *)coord + coord_stride);
188
189 if (DO_NORM) {
190 v[0].ui = norm[0][0];
191 v[1].ui = norm[0][1];
192 v[2].ui = norm[0][2];
193 v += 3;
194 norm = (GLuint (*)[4])((GLubyte *)norm + norm_stride);
195 }
196 if (DO_RGBA) {
197 UNCLAMPED_FLOAT_TO_UBYTE(v[0].rgba.red, col[0][0]);
198 UNCLAMPED_FLOAT_TO_UBYTE(v[0].rgba.green, col[0][1]);
199 UNCLAMPED_FLOAT_TO_UBYTE(v[0].rgba.blue, col[0][2]);
200 UNCLAMPED_FLOAT_TO_UBYTE(v[0].rgba.alpha, col[0][3]);
201 STRIDE_4F(col, col_stride);
202 v++;
203 }
204 if (DO_SPEC_OR_FOG) {
205 if (DO_SPEC) {
206 UNCLAMPED_FLOAT_TO_UBYTE(v[0].rgba.red, spec[0][0]);
207 UNCLAMPED_FLOAT_TO_UBYTE(v[0].rgba.green, spec[0][1]);
208 UNCLAMPED_FLOAT_TO_UBYTE(v[0].rgba.blue, spec[0][2]);
209 STRIDE_4F(spec, spec_stride);
210 }
211 if (DO_FOG) {
212 UNCLAMPED_FLOAT_TO_UBYTE(v[0].rgba.alpha, radeonComputeFogBlendFactor(ctx, fog[0][0]));
213 STRIDE_4F(fog, fog_stride);
214 }
215 if (TCL_DEBUG) fprintf(stderr, "%x ", v[0].ui);
216 v++;
217 }
218 if (DO_TEX0) {
219 v[0].ui = tc0[0][0];
220 v[1].ui = tc0[0][1];
221 if (TCL_DEBUG) fprintf(stderr, "t0: %.2f %.2f ", v[0].f, v[1].f);
222 if (DO_PTEX) {
223 if (fill_tex & (1<<0))
224 v[2].f = 1.0;
225 else if (rqcoordsnoswap & (1<<0))
226 v[2].ui = tc0[0][2];
227 else
228 v[2].ui = tc0[0][3];
229 if (TCL_DEBUG) fprintf(stderr, "%.2f ", v[2].f);
230 v += 3;
231 }
232 else
233 v += 2;
234 tc0 = (GLuint (*)[4])((GLubyte *)tc0 + tc0_stride);
235 }
236 if (DO_TEX1) {
237 v[0].ui = tc1[0][0];
238 v[1].ui = tc1[0][1];
239 if (TCL_DEBUG) fprintf(stderr, "t1: %.2f %.2f ", v[0].f, v[1].f);
240 if (DO_PTEX) {
241 if (fill_tex & (1<<1))
242 v[2].f = 1.0;
243 else if (rqcoordsnoswap & (1<<1))
244 v[2].ui = tc1[0][2];
245 else
246 v[2].ui = tc1[0][3];
247 if (TCL_DEBUG) fprintf(stderr, "%.2f ", v[2].f);
248 v += 3;
249 }
250 else
251 v += 2;
252 tc1 = (GLuint (*)[4])((GLubyte *)tc1 + tc1_stride);
253 }
254 if (DO_TEX2) {
255 v[0].ui = tc2[0][0];
256 v[1].ui = tc2[0][1];
257 if (TCL_DEBUG) fprintf(stderr, "t2: %.2f %.2f ", v[0].f, v[1].f);
258 if (DO_PTEX) {
259 if (fill_tex & (1<<2))
260 v[2].f = 1.0;
261 else if (rqcoordsnoswap & (1<<2))
262 v[2].ui = tc2[0][2];
263 else
264 v[2].ui = tc2[0][3];
265 if (TCL_DEBUG) fprintf(stderr, "%.2f ", v[2].f);
266 v += 3;
267 }
268 else
269 v += 2;
270 tc2 = (GLuint (*)[4])((GLubyte *)tc2 + tc2_stride);
271 }
272 if (TCL_DEBUG) fprintf(stderr, "\n");
273 }
274 }
275 }
276
277
278
279 static void TAG(init)( void )
280 {
281 int sz = 3;
282 if (DO_W) sz++;
283 if (DO_NORM) sz += 3;
284 if (DO_RGBA) sz++;
285 if (DO_SPEC_OR_FOG) sz++;
286 if (DO_TEX0) sz += 2;
287 if (DO_TEX0 && DO_PTEX) sz++;
288 if (DO_TEX1) sz += 2;
289 if (DO_TEX1 && DO_PTEX) sz++;
290 if (DO_TEX2) sz += 2;
291 if (DO_TEX2 && DO_PTEX) sz++;
292
293 setup_tab[IDX].emit = TAG(emit);
294 setup_tab[IDX].vertex_format = IND;
295 setup_tab[IDX].vertex_size = sz;
296 }
297
298
299 #undef IND
300 #undef TAG
301 #undef IDX