1 /* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_maos_vbtmp.h,v 1.2 2002/12/16 16:18:54 dawes Exp $ */
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
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.
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:
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.
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.
32 * Keith Whitwell <keith@tungstengraphics.com>
44 static void TAG(emit
)( GLcontext
*ctx
,
45 GLuint start
, GLuint end
,
49 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
50 GLuint (*tc0
)[4], (*tc1
)[4];
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
;
61 union emit_union
*v
= (union emit_union
*)dest
;
64 if (R200_DEBUG
& DEBUG_VERTS
)
65 fprintf(stderr
, "%s\n", __FUNCTION__
);
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
71 if (VB
->ObjPtr
->size
< 3) {
72 if (VB
->ObjPtr
->flags
& VEC_NOT_WRITEABLE
) {
73 VB
->import_data( ctx
, VERT_OBJ
, VEC_NOT_WRITEABLE
);
75 _mesa_vector4f_clean_elem( VB
->ObjPtr
, VB
->Count
, 2 );
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
);
82 _mesa_vector4f_clean_elem( VB
->ObjPtr
, VB
->Count
, 3 );
85 coord
= (GLuint (*)[4])VB
->ObjPtr
->data
;
86 coord_stride
= VB
->ObjPtr
->stride
;
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
);
96 _mesa_vector4f_clean_elem( VB
->TexCoordPtr
[t2
], VB
->Count
, 3 );
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
);
109 _mesa_vector4f_clean_elem( VB
->TexCoordPtr
[t1
], VB
->Count
, 3 );
112 tc1
= (GLuint (*)[4])&ctx
->Current
.Texcoord
[1]; /* could be anything, really */
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
);
126 _mesa_vector4f_clean_elem( VB
->TexCoordPtr
[t0
], VB
->Count
, 3 );
129 tc0
= (GLuint (*)[4])&ctx
->Current
.Texcoord
[0]; /* could be anything, really */
137 norm_stride
= VB
->NormalPtr
->stride
;
138 norm
= (GLuint (*)[3])VB
->NormalPtr
->data
;
141 norm
= (GLuint (*)[3])&ctx
->Current
.Normal
;
146 if (VB
->ColorPtr
[0]) {
147 /* This is incorrect when colormaterial is enabled:
149 if (VB
->ColorPtr
[0]->Type
!= GL_UNSIGNED_BYTE
) {
150 if (0) fprintf(stderr
, "IMPORTING FLOAT COLORS\n");
151 IMPORT_FLOAT_COLORS( ctx
);
153 col
= (GLubyte (*)[4])VB
->ColorPtr
[0]->Ptr
;
154 col_stride
= VB
->ColorPtr
[0]->StrideB
;
156 col
= &dummy
; /* any old memory is fine */
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
;
176 if (VB
->FogCoordPtr
) {
177 fog
= VB
->FogCoordPtr
->data
;
178 fog_stride
= VB
->FogCoordPtr
->stride
;
180 fog
= (GLfloat
*)&dummy
; *fog
= 0;
187 if (VB
->importable_data
) {
189 coord
= (GLuint (*)[4])((GLubyte
*)coord
+ start
* coord_stride
);
191 tc0
= (GLuint (*)[4])((GLubyte
*)tc0
+ start
* tc0_stride
);
193 tc1
= (GLuint (*)[4])((GLubyte
*)tc1
+ start
* tc1_stride
);
195 tc2
= (GLuint (*)[4])((GLubyte
*)tc2
+ start
* tc2_stride
);
197 norm
= (GLuint (*)[3])((GLubyte
*)norm
+ start
* norm_stride
);
199 STRIDE_4UB(col
, start
* col_stride
);
201 STRIDE_4UB(spec
, start
* spec_stride
);
203 STRIDE_F(fog
, start
* fog_stride
);
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
);
212 v
[3].ui
= coord
[0][3];
213 if (TCL_DEBUG
) fprintf(stderr
, "%.2f ", v
[3].f
);
218 coord
= (GLuint (*)[4])((GLubyte
*)coord
+ coord_stride
);
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
);
226 norm
= (GLuint (*)[3])((GLubyte
*)norm
+ norm_stride
);
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
);
234 if (DO_SPEC
|| DO_FOG
) {
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
);
242 v
[0].ub
[3] = fog
[0] * 255.0;
243 STRIDE_F(fog
, fog_stride
);
245 if (TCL_DEBUG
) fprintf(stderr
, "%x ", v
[0].ui
);
251 if (TCL_DEBUG
) fprintf(stderr
, "t0: %.2f %.2f ", v
[0].f
, v
[1].f
);
254 if (TCL_DEBUG
) fprintf(stderr
, "%.2f ", v
[2].f
);
259 tc0
= (GLuint (*)[4])((GLubyte
*)tc0
+ tc0_stride
);
264 if (TCL_DEBUG
) fprintf(stderr
, "t1: %.2f %.2f ", v
[0].f
, v
[1].f
);
267 if (TCL_DEBUG
) fprintf(stderr
, "%.2f ", v
[2].f
);
272 tc1
= (GLuint (*)[4])((GLubyte
*)tc1
+ tc1_stride
);
283 tc2
= (GLuint (*)[4])((GLubyte
*)tc2
+ tc2_stride
);
285 if (TCL_DEBUG
) fprintf(stderr
, "\n");
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];
293 v
[3].ui
= coord
[i
][3];
300 v
[0].ui
= norm
[i
][0];
301 v
[1].ui
= norm
[i
][1];
302 v
[2].ui
= norm
[i
][2];
306 v
[0].ui
= LE32_TO_CPU(*(GLuint
*)&col
[i
]);
309 if (DO_SPEC
|| DO_FOG
) {
311 v
[0].ub
[0] = spec
[i
][0];
312 v
[0].ub
[1] = spec
[i
][1];
313 v
[0].ub
[2] = spec
[i
][2];
316 v
[0].ub
[3] = fog
[i
] * 255.0;
356 static void TAG(init
)( void )
360 if (DO_NORM
) sz
+= 3;
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
++;
370 setup_tab
[IDX
].emit
= TAG(emit
);
371 setup_tab
[IDX
].vertex_format
= IND
;
372 setup_tab
[IDX
].vertex_size
= sz
;