fix some obvious typos in radeon_reg.h (only currently unused bits affected)
[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 GLubyte dummy[4];
54 int i;
55
56 union emit_union *v = (union emit_union *)dest;
57
58 if (RADEON_DEBUG & DEBUG_VERTS)
59 fprintf(stderr, "%s\n", __FUNCTION__);
60
61 coord = (GLuint (*)[4])VB->ObjPtr->data;
62 coord_stride = VB->ObjPtr->stride;
63
64 if (DO_TEX2) {
65 if (VB->TexCoordPtr[2]) {
66 const GLuint t2 = GET_TEXSOURCE(2);
67 tc2 = (GLuint (*)[4])VB->TexCoordPtr[t2]->data;
68 tc2_stride = VB->TexCoordPtr[t2]->stride;
69 if (DO_PTEX && VB->TexCoordPtr[t2]->size < 3) {
70 fill_tex |= (1<<2);
71 }
72 else if (DO_PTEX && VB->TexCoordPtr[t2]->size < 4) {
73 rqcoordsnoswap |= (1<<2);
74 }
75 } else {
76 tc2 = (GLuint (*)[4])&ctx->Current.Attrib[VERT_ATTRIB_TEX2];
77 tc2_stride = 0;
78 }
79 }
80
81 if (DO_TEX1) {
82 if (VB->TexCoordPtr[1]) {
83 const GLuint t1 = GET_TEXSOURCE(1);
84 tc1 = (GLuint (*)[4])VB->TexCoordPtr[t1]->data;
85 tc1_stride = VB->TexCoordPtr[t1]->stride;
86 if (DO_PTEX && VB->TexCoordPtr[t1]->size < 3) {
87 fill_tex |= (1<<1);
88 }
89 else if (DO_PTEX && VB->TexCoordPtr[t1]->size < 4) {
90 rqcoordsnoswap |= (1<<1);
91 }
92 } else {
93 tc1 = (GLuint (*)[4])&ctx->Current.Attrib[VERT_ATTRIB_TEX1];
94 tc1_stride = 0;
95 }
96 }
97
98 if (DO_TEX0) {
99 if (VB->TexCoordPtr[0]) {
100 const GLuint t0 = GET_TEXSOURCE(0);
101 tc0_stride = VB->TexCoordPtr[t0]->stride;
102 tc0 = (GLuint (*)[4])VB->TexCoordPtr[t0]->data;
103 if (DO_PTEX && VB->TexCoordPtr[t0]->size < 3) {
104 fill_tex |= (1<<0);
105 }
106 else if (DO_PTEX && VB->TexCoordPtr[t0]->size < 4) {
107 rqcoordsnoswap |= (1<<0);
108 }
109 } else {
110 tc0 = (GLuint (*)[4])&ctx->Current.Attrib[VERT_ATTRIB_TEX0];
111 tc0_stride = 0;
112 }
113
114 }
115
116 if (DO_NORM) {
117 if (VB->NormalPtr) {
118 norm_stride = VB->NormalPtr->stride;
119 norm = (GLuint (*)[4])VB->NormalPtr->data;
120 } else {
121 norm_stride = 0;
122 norm = (GLuint (*)[4])&ctx->Current.Attrib[VERT_ATTRIB_NORMAL];
123 }
124 }
125
126 if (DO_RGBA) {
127 if (VB->ColorPtr[0]) {
128 col = VB->ColorPtr[0]->data;
129 col_stride = VB->ColorPtr[0]->stride;
130 } else {
131 col = (GLfloat (*)[4])ctx->Current.Attrib[VERT_ATTRIB_COLOR0];
132 col_stride = 0;
133 }
134 }
135
136 if (DO_SPEC) {
137 if (VB->SecondaryColorPtr[0]) {
138 spec = VB->SecondaryColorPtr[0]->data;
139 spec_stride = VB->SecondaryColorPtr[0]->stride;
140 } else {
141 spec = (GLfloat (*)[4])ctx->Current.Attrib[VERT_ATTRIB_COLOR1];
142 spec_stride = 0;
143 }
144 }
145
146 if (DO_FOG) {
147 if (VB->FogCoordPtr) {
148 fog = VB->FogCoordPtr->data;
149 fog_stride = VB->FogCoordPtr->stride;
150 } else {
151 fog = (GLfloat (*)[4])&dummy; fog[0][0] = 0.0F;
152 fog_stride = 0;
153 }
154 }
155
156
157 if (start) {
158 coord = (GLuint (*)[4])((GLubyte *)coord + start * coord_stride);
159 if (DO_TEX0)
160 tc0 = (GLuint (*)[4])((GLubyte *)tc0 + start * tc0_stride);
161 if (DO_TEX1)
162 tc1 = (GLuint (*)[4])((GLubyte *)tc1 + start * tc1_stride);
163 if (DO_TEX2)
164 tc2 = (GLuint (*)[4])((GLubyte *)tc2 + start * tc2_stride);
165 if (DO_NORM)
166 norm = (GLuint (*)[4])((GLubyte *)norm + start * norm_stride);
167 if (DO_RGBA)
168 STRIDE_4F(col, start * col_stride);
169 if (DO_SPEC)
170 STRIDE_4F(spec, start * spec_stride);
171 if (DO_FOG)
172 STRIDE_4F(fog, start * fog_stride);
173 }
174
175
176 {
177 for (i=start; i < end; i++) {
178
179 v[0].ui = coord[0][0];
180 v[1].ui = coord[0][1];
181 v[2].ui = coord[0][2];
182 if (DO_W) {
183 v[3].ui = coord[0][3];
184 v += 4;
185 }
186 else
187 v += 3;
188 coord = (GLuint (*)[4])((GLubyte *)coord + coord_stride);
189
190 if (DO_NORM) {
191 v[0].ui = norm[0][0];
192 v[1].ui = norm[0][1];
193 v[2].ui = norm[0][2];
194 v += 3;
195 norm = (GLuint (*)[4])((GLubyte *)norm + norm_stride);
196 }
197 if (DO_RGBA) {
198 UNCLAMPED_FLOAT_TO_UBYTE(v[0].rgba.red, col[0][0]);
199 UNCLAMPED_FLOAT_TO_UBYTE(v[0].rgba.green, col[0][1]);
200 UNCLAMPED_FLOAT_TO_UBYTE(v[0].rgba.blue, col[0][2]);
201 UNCLAMPED_FLOAT_TO_UBYTE(v[0].rgba.alpha, col[0][3]);
202 STRIDE_4F(col, col_stride);
203 v++;
204 }
205 if (DO_SPEC || DO_FOG) {
206 if (DO_SPEC) {
207 UNCLAMPED_FLOAT_TO_UBYTE(v[0].rgba.red, spec[0][0]);
208 UNCLAMPED_FLOAT_TO_UBYTE(v[0].rgba.green, spec[0][1]);
209 UNCLAMPED_FLOAT_TO_UBYTE(v[0].rgba.blue, spec[0][2]);
210 STRIDE_4F(spec, spec_stride);
211 }
212 if (DO_FOG) {
213 UNCLAMPED_FLOAT_TO_UBYTE(v[0].rgba.alpha, fog[0][0]);
214 fog = (GLfloat (*)[4])((GLubyte *)fog + fog_stride);
215 }
216 if (TCL_DEBUG) fprintf(stderr, "%x ", v[0].ui);
217 v++;
218 }
219 if (DO_TEX0) {
220 v[0].ui = tc0[0][0];
221 v[1].ui = tc0[0][1];
222 if (TCL_DEBUG) fprintf(stderr, "t0: %.2f %.2f ", v[0].f, v[1].f);
223 if (DO_PTEX) {
224 if (fill_tex & (1<<0))
225 v[2].f = 1.0;
226 else if (rqcoordsnoswap & (1<<0))
227 v[2].ui = tc0[0][2];
228 else
229 v[2].ui = tc0[0][3];
230 if (TCL_DEBUG) fprintf(stderr, "%.2f ", v[2].f);
231 v += 3;
232 }
233 else
234 v += 2;
235 tc0 = (GLuint (*)[4])((GLubyte *)tc0 + tc0_stride);
236 }
237 if (DO_TEX1) {
238 v[0].ui = tc1[0][0];
239 v[1].ui = tc1[0][1];
240 if (TCL_DEBUG) fprintf(stderr, "t1: %.2f %.2f ", v[0].f, v[1].f);
241 if (DO_PTEX) {
242 if (fill_tex & (1<<1))
243 v[2].f = 1.0;
244 else if (rqcoordsnoswap & (1<<1))
245 v[2].ui = tc1[0][2];
246 else
247 v[2].ui = tc1[0][3];
248 if (TCL_DEBUG) fprintf(stderr, "%.2f ", v[2].f);
249 v += 3;
250 }
251 else
252 v += 2;
253 tc1 = (GLuint (*)[4])((GLubyte *)tc1 + tc1_stride);
254 }
255 if (DO_TEX2) {
256 v[0].ui = tc2[0][0];
257 v[1].ui = tc2[0][1];
258 if (TCL_DEBUG) fprintf(stderr, "t2: %.2f %.2f ", v[0].f, v[1].f);
259 if (DO_PTEX) {
260 if (fill_tex & (1<<2))
261 v[2].f = 1.0;
262 else if (rqcoordsnoswap & (1<<2))
263 v[2].ui = tc2[0][2];
264 else
265 v[2].ui = tc2[0][3];
266 if (TCL_DEBUG) fprintf(stderr, "%.2f ", v[2].f);
267 v += 3;
268 }
269 else
270 v += 2;
271 tc2 = (GLuint (*)[4])((GLubyte *)tc2 + tc2_stride);
272 }
273 if (TCL_DEBUG) fprintf(stderr, "\n");
274 }
275 }
276 }
277
278
279
280 static void TAG(init)( void )
281 {
282 int sz = 3;
283 if (DO_W) sz++;
284 if (DO_NORM) sz += 3;
285 if (DO_RGBA) sz++;
286 if (DO_SPEC || DO_FOG) sz++;
287 if (DO_TEX0) sz += 2;
288 if (DO_TEX0 && DO_PTEX) sz++;
289 if (DO_TEX1) sz += 2;
290 if (DO_TEX1 && DO_PTEX) sz++;
291 if (DO_TEX2) sz += 2;
292 if (DO_TEX2 && DO_PTEX) sz++;
293
294 setup_tab[IDX].emit = TAG(emit);
295 setup_tab[IDX].vertex_format = IND;
296 setup_tab[IDX].vertex_size = sz;
297 }
298
299
300 #undef IND
301 #undef TAG
302 #undef IDX