dacb38dd9fcc5c70ccd42595053f1d4daebe3302
2 * Copyright 2000-2001 VA Linux Systems, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
25 * Keith Whitwell <keith@tungstengraphics.com>
27 /* $XFree86: xc/lib/GL/mesa/src/drv/mga/mgavb.c,v 1.15 2003/03/26 20:43:49 tsi Exp $ */
30 #include "mgacontext.h"
34 #include "mga_xmesa.h"
42 #include "tnl/t_context.h"
43 #include "swrast_setup/swrast_setup.h"
44 #include "swrast/swrast.h"
47 #define MGA_TEX1_BIT 0x1
48 #define MGA_TEX0_BIT 0x2
49 #define MGA_RGBA_BIT 0x4
50 #define MGA_SPEC_BIT 0x8
51 #define MGA_FOG_BIT 0x10
52 #define MGA_XYZW_BIT 0x20
53 #define MGA_PTEX_BIT 0x40
54 #define MGA_MAX_SETUP 0x80
57 void (*emit
)( GLcontext
*, GLuint
, GLuint
, void *, GLuint
);
60 GLboolean (*check_tex_sizes
)( GLcontext
*ctx
);
63 } setup_tab
[MGA_MAX_SETUP
];
66 #define TINY_VERTEX_FORMAT 0
67 #define NOTEX_VERTEX_FORMAT 0
68 #define TEX0_VERTEX_FORMAT (MGA_A|MGA_S|MGA_F)
69 #define TEX1_VERTEX_FORMAT (MGA_A|MGA_S|MGA_F|MGA_T2)
70 #define PROJ_TEX1_VERTEX_FORMAT 0
71 #define TEX2_VERTEX_FORMAT 0
72 #define TEX3_VERTEX_FORMAT 0
73 #define PROJ_TEX3_VERTEX_FORMAT 0
75 #define DO_XYZW (IND & MGA_XYZW_BIT)
76 #define DO_RGBA (IND & MGA_RGBA_BIT)
77 #define DO_SPEC (IND & MGA_SPEC_BIT)
78 #define DO_FOG (IND & MGA_FOG_BIT)
79 #define DO_TEX0 (IND & MGA_TEX0_BIT)
80 #define DO_TEX1 (IND & MGA_TEX1_BIT)
83 #define DO_PTEX (IND & MGA_PTEX_BIT)
86 #define VERTEX mgaVertex
87 #define VERTEX_COLOR mga_color_t
88 #define LOCALVARS mgaContextPtr mmesa = MGA_CONTEXT(ctx);
89 #define GET_VIEWPORT_MAT() mmesa->hw_viewport
90 #define GET_TEXSOURCE(n) mmesa->tmu_source[n]
91 #define GET_VERTEX_FORMAT() mmesa->vertex_format
92 #define GET_VERTEX_STORE() mmesa->verts
93 #define GET_VERTEX_SIZE() mmesa->vertex_size * sizeof(GLuint)
95 #define HAVE_HW_VIEWPORT 0
96 #define HAVE_HW_DIVIDE 0
97 #define HAVE_RGBA_COLOR 0
98 #define HAVE_TINY_VERTICES 0
99 #define HAVE_NOTEX_VERTICES 0
100 #define HAVE_TEX0_VERTICES 1
101 #define HAVE_TEX1_VERTICES 1
102 #define HAVE_TEX2_VERTICES 0
103 #define HAVE_TEX3_VERTICES 0
104 #define HAVE_PTEX_VERTICES 0
106 #define UNVIEWPORT_VARS \
107 const GLfloat dx = - mmesa->drawX - SUBPIXEL_X; \
108 const GLfloat dy = (mmesa->driDrawable->h + \
109 mmesa->drawY + SUBPIXEL_Y); \
110 const GLfloat sz = 1.0 / mmesa->depth_scale
112 #define UNVIEWPORT_X(x) x + dx;
113 #define UNVIEWPORT_Y(y) - y + dy;
114 #define UNVIEWPORT_Z(z) z * sz;
116 #define PTEX_FALLBACK() FALLBACK(ctx, MGA_FALLBACK_TEXTURE, 1)
118 #define INTERP_VERTEX setup_tab[mmesa->SetupIndex].interp
119 #define COPY_PV_VERTEX setup_tab[mmesa->SetupIndex].copy_pv
122 /***********************************************************************
123 * Generate pv-copying and translation functions *
124 ***********************************************************************/
126 #define TAG(x) mga_##x
127 #include "tnl_dd/t_dd_vb.c"
129 /***********************************************************************
130 * Generate vertex emit and interp functions *
131 ***********************************************************************/
134 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT)
135 #define TAG(x) x##_wg
136 #include "tnl_dd/t_dd_vbtmp.h"
138 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_SPEC_BIT)
139 #define TAG(x) x##_wgs
140 #include "tnl_dd/t_dd_vbtmp.h"
142 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_TEX0_BIT)
143 #define TAG(x) x##_wgt0
144 #include "tnl_dd/t_dd_vbtmp.h"
146 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
147 #define TAG(x) x##_wgt0t1
148 #include "tnl_dd/t_dd_vbtmp.h"
150 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_TEX0_BIT|MGA_PTEX_BIT)
151 #define TAG(x) x##_wgpt0
152 #include "tnl_dd/t_dd_vbtmp.h"
154 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT)
155 #define TAG(x) x##_wgst0
156 #include "tnl_dd/t_dd_vbtmp.h"
158 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
159 #define TAG(x) x##_wgst0t1
160 #include "tnl_dd/t_dd_vbtmp.h"
162 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_PTEX_BIT)
163 #define TAG(x) x##_wgspt0
164 #include "tnl_dd/t_dd_vbtmp.h"
166 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT)
167 #define TAG(x) x##_wgf
168 #include "tnl_dd/t_dd_vbtmp.h"
170 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT)
171 #define TAG(x) x##_wgfs
172 #include "tnl_dd/t_dd_vbtmp.h"
174 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_TEX0_BIT)
175 #define TAG(x) x##_wgft0
176 #include "tnl_dd/t_dd_vbtmp.h"
178 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
179 #define TAG(x) x##_wgft0t1
180 #include "tnl_dd/t_dd_vbtmp.h"
182 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_TEX0_BIT|MGA_PTEX_BIT)
183 #define TAG(x) x##_wgfpt0
184 #include "tnl_dd/t_dd_vbtmp.h"
186 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT)
187 #define TAG(x) x##_wgfst0
188 #include "tnl_dd/t_dd_vbtmp.h"
190 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
191 #define TAG(x) x##_wgfst0t1
192 #include "tnl_dd/t_dd_vbtmp.h"
194 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_PTEX_BIT)
195 #define TAG(x) x##_wgfspt0
196 #include "tnl_dd/t_dd_vbtmp.h"
198 #define IND (MGA_TEX0_BIT)
199 #define TAG(x) x##_t0
200 #include "tnl_dd/t_dd_vbtmp.h"
202 #define IND (MGA_TEX0_BIT|MGA_TEX1_BIT)
203 #define TAG(x) x##_t0t1
204 #include "tnl_dd/t_dd_vbtmp.h"
206 #define IND (MGA_FOG_BIT)
208 #include "tnl_dd/t_dd_vbtmp.h"
210 #define IND (MGA_FOG_BIT|MGA_TEX0_BIT)
211 #define TAG(x) x##_ft0
212 #include "tnl_dd/t_dd_vbtmp.h"
214 #define IND (MGA_FOG_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
215 #define TAG(x) x##_ft0t1
216 #include "tnl_dd/t_dd_vbtmp.h"
218 #define IND (MGA_RGBA_BIT)
220 #include "tnl_dd/t_dd_vbtmp.h"
222 #define IND (MGA_RGBA_BIT|MGA_SPEC_BIT)
223 #define TAG(x) x##_gs
224 #include "tnl_dd/t_dd_vbtmp.h"
226 #define IND (MGA_RGBA_BIT|MGA_TEX0_BIT)
227 #define TAG(x) x##_gt0
228 #include "tnl_dd/t_dd_vbtmp.h"
230 #define IND (MGA_RGBA_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
231 #define TAG(x) x##_gt0t1
232 #include "tnl_dd/t_dd_vbtmp.h"
234 #define IND (MGA_RGBA_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT)
235 #define TAG(x) x##_gst0
236 #include "tnl_dd/t_dd_vbtmp.h"
238 #define IND (MGA_RGBA_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
239 #define TAG(x) x##_gst0t1
240 #include "tnl_dd/t_dd_vbtmp.h"
242 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT)
243 #define TAG(x) x##_gf
244 #include "tnl_dd/t_dd_vbtmp.h"
246 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT)
247 #define TAG(x) x##_gfs
248 #include "tnl_dd/t_dd_vbtmp.h"
250 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT|MGA_TEX0_BIT)
251 #define TAG(x) x##_gft0
252 #include "tnl_dd/t_dd_vbtmp.h"
254 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
255 #define TAG(x) x##_gft0t1
256 #include "tnl_dd/t_dd_vbtmp.h"
258 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT)
259 #define TAG(x) x##_gfst0
260 #include "tnl_dd/t_dd_vbtmp.h"
262 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
263 #define TAG(x) x##_gfst0t1
264 #include "tnl_dd/t_dd_vbtmp.h"
267 static void init_setup_tab( void )
307 void mgaPrintSetupFlags(char *msg
, GLuint flags
)
309 fprintf(stderr
, "%s: %d %s%s%s%s%s%s\n",
312 (flags
& MGA_XYZW_BIT
) ? " xyzw," : "",
313 (flags
& MGA_RGBA_BIT
) ? " rgba," : "",
314 (flags
& MGA_SPEC_BIT
) ? " spec," : "",
315 (flags
& MGA_FOG_BIT
) ? " fog," : "",
316 (flags
& MGA_TEX0_BIT
) ? " tex-0," : "",
317 (flags
& MGA_TEX1_BIT
) ? " tex-1," : "");
321 void mgaCheckTexSizes( GLcontext
*ctx
)
323 mgaContextPtr mmesa
= MGA_CONTEXT( ctx
);
324 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
326 /*fprintf(stderr, "%s\n", __FUNCTION__);*/
328 if (!setup_tab
[mmesa
->SetupIndex
].check_tex_sizes(ctx
)) {
329 mmesa
->SetupIndex
|= MGA_PTEX_BIT
;
330 mmesa
->SetupNewInputs
= ~0;
332 if (!mmesa
->Fallback
&&
333 !(ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
))) {
334 tnl
->Driver
.Render
.Interp
= setup_tab
[mmesa
->SetupIndex
].interp
;
335 tnl
->Driver
.Render
.CopyPV
= setup_tab
[mmesa
->SetupIndex
].copy_pv
;
337 if (mmesa
->Fallback
) {
338 tnl
->Driver
.Render
.Start(ctx
);
344 void mgaBuildVertices( GLcontext
*ctx
,
349 mgaContextPtr mmesa
= MGA_CONTEXT( ctx
);
350 GLuint stride
= mmesa
->vertex_size
* sizeof(int);
351 GLubyte
*v
= ((GLubyte
*)mmesa
->verts
+ (start
* stride
));
353 newinputs
|= mmesa
->SetupNewInputs
;
354 mmesa
->SetupNewInputs
= 0;
359 if (newinputs
& VERT_BIT_POS
) {
360 setup_tab
[mmesa
->SetupIndex
].emit( ctx
, start
, count
, v
, stride
);
364 if (newinputs
& VERT_BIT_COLOR0
)
367 if (newinputs
& VERT_BIT_COLOR1
)
370 if (newinputs
& VERT_BIT_TEX0
)
373 if (newinputs
& VERT_BIT_TEX1
)
374 ind
|= MGA_TEX0_BIT
|MGA_TEX1_BIT
;
376 if (newinputs
& VERT_BIT_FOG
)
379 if (mmesa
->SetupIndex
& MGA_PTEX_BIT
)
382 ind
&= mmesa
->SetupIndex
;
385 setup_tab
[ind
].emit( ctx
, start
, count
, v
, stride
);
391 void mgaChooseVertexState( GLcontext
*ctx
)
393 mgaContextPtr mmesa
= MGA_CONTEXT( ctx
);
394 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
395 GLuint ind
= MGA_XYZW_BIT
|MGA_RGBA_BIT
;
397 if (ctx
->_TriangleCaps
& DD_SEPARATE_SPECULAR
)
400 if (ctx
->Fog
.Enabled
)
403 if (ctx
->Texture
._EnabledUnits
& 0x2) {
405 if (ctx
->Texture
._EnabledUnits
& 0x1) {
407 ind
|= MGA_TEX1_BIT
|MGA_TEX0_BIT
;
413 else if (ctx
->Texture
._EnabledUnits
& 0x1) {
418 mmesa
->SetupIndex
= ind
;
420 if (ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
)) {
421 tnl
->Driver
.Render
.Interp
= mga_interp_extras
;
422 tnl
->Driver
.Render
.CopyPV
= mga_copy_pv_extras
;
424 tnl
->Driver
.Render
.Interp
= setup_tab
[ind
].interp
;
425 tnl
->Driver
.Render
.CopyPV
= setup_tab
[ind
].copy_pv
;
428 if (setup_tab
[ind
].vertex_format
!= mmesa
->vertex_format
) {
430 mmesa
->dirty
|= MGA_UPLOAD_PIPE
;
431 mmesa
->vertex_format
= setup_tab
[ind
].vertex_format
;
432 mmesa
->vertex_size
= setup_tab
[ind
].vertex_size
;
438 void *mga_emit_contiguous_verts( GLcontext
*ctx
,
443 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
444 GLuint stride
= mmesa
->vertex_size
* 4;
445 setup_tab
[mmesa
->SetupIndex
].emit( ctx
, start
, count
, dest
, stride
);
446 return (void *)((char *)dest
+ stride
* (count
- start
));
451 void mgaInitVB( GLcontext
*ctx
)
453 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
454 GLuint size
= TNL_CONTEXT(ctx
)->vb
.Size
;
456 mmesa
->verts
= (GLubyte
*)ALIGN_MALLOC(size
* sizeof(mgaVertex
), 32);
459 static int firsttime
= 1;
466 mmesa
->dirty
|= MGA_UPLOAD_PIPE
;
467 mmesa
->vertex_format
= setup_tab
[0].vertex_format
;
468 mmesa
->vertex_size
= setup_tab
[0].vertex_size
;
472 void mgaFreeVB( GLcontext
*ctx
)
474 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
476 ALIGN_FREE(mmesa
->verts
);