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>
29 #include "mgacontext.h"
33 #include "mga_xmesa.h"
35 #include "main/glheader.h"
36 #include "main/mtypes.h"
37 #include "main/imports.h"
38 #include "main/macros.h"
39 #include "main/colormac.h"
41 #include "tnl/t_context.h"
42 #include "swrast/swrast.h"
45 #define MGA_TEX1_BIT 0x1
46 #define MGA_TEX0_BIT 0x2
47 #define MGA_RGBA_BIT 0x4
48 #define MGA_SPEC_BIT 0x8
49 #define MGA_FOG_BIT 0x10
50 #define MGA_XYZW_BIT 0x20
51 #define MGA_PTEX_BIT 0x40
52 #define MGA_MAX_SETUP 0x80
55 void (*emit
)( GLcontext
*, GLuint
, GLuint
, void *, GLuint
);
56 tnl_interp_func interp
;
57 tnl_copy_pv_func copy_pv
;
58 GLboolean (*check_tex_sizes
)( GLcontext
*ctx
);
61 } setup_tab
[MGA_MAX_SETUP
];
64 #define TINY_VERTEX_FORMAT 0
65 #define NOTEX_VERTEX_FORMAT 0
66 #define TEX0_VERTEX_FORMAT (MGA_A|MGA_S|MGA_F)
67 #define TEX1_VERTEX_FORMAT (MGA_A|MGA_S|MGA_F|MGA_T2)
68 #define PROJ_TEX1_VERTEX_FORMAT 0
69 #define TEX2_VERTEX_FORMAT 0
70 #define TEX3_VERTEX_FORMAT 0
71 #define PROJ_TEX3_VERTEX_FORMAT 0
73 #define DO_XYZW (IND & MGA_XYZW_BIT)
74 #define DO_RGBA (IND & MGA_RGBA_BIT)
75 #define DO_SPEC (IND & MGA_SPEC_BIT)
76 #define DO_FOG (IND & MGA_FOG_BIT)
77 #define DO_TEX0 (IND & MGA_TEX0_BIT)
78 #define DO_TEX1 (IND & MGA_TEX1_BIT)
81 #define DO_PTEX (IND & MGA_PTEX_BIT)
84 #define VERTEX mgaVertex
85 #define VERTEX_COLOR mga_color_t
86 #define LOCALVARS mgaContextPtr mmesa = MGA_CONTEXT(ctx);
87 #define GET_VIEWPORT_MAT() mmesa->hw_viewport
88 #define GET_TEXSOURCE(n) mmesa->tmu_source[n]
89 #define GET_VERTEX_FORMAT() mmesa->vertex_format
90 #define GET_VERTEX_STORE() mmesa->verts
91 #define GET_VERTEX_SIZE() mmesa->vertex_size * sizeof(GLuint)
93 #define HAVE_HW_VIEWPORT 0
94 #define HAVE_HW_DIVIDE 0
95 #define HAVE_RGBA_COLOR 0
96 #define HAVE_TINY_VERTICES 0
97 #define HAVE_NOTEX_VERTICES 0
98 #define HAVE_TEX0_VERTICES 1
99 #define HAVE_TEX1_VERTICES 1
100 #define HAVE_TEX2_VERTICES 0
101 #define HAVE_TEX3_VERTICES 0
102 #define HAVE_PTEX_VERTICES 0
104 #define UNVIEWPORT_VARS \
105 const GLfloat dx = - mmesa->drawX - SUBPIXEL_X; \
106 const GLfloat dy = (mmesa->driDrawable->h + \
107 mmesa->drawY + SUBPIXEL_Y); \
108 const GLfloat sz = 1.0 / mmesa->depth_scale
110 #define UNVIEWPORT_X(x) x + dx;
111 #define UNVIEWPORT_Y(y) - y + dy;
112 #define UNVIEWPORT_Z(z) z * sz;
114 #define PTEX_FALLBACK() FALLBACK(ctx, MGA_FALLBACK_TEXTURE, 1)
116 #define INTERP_VERTEX setup_tab[mmesa->SetupIndex].interp
117 #define COPY_PV_VERTEX setup_tab[mmesa->SetupIndex].copy_pv
120 /***********************************************************************
121 * Generate pv-copying and translation functions *
122 ***********************************************************************/
124 #define TAG(x) mga_##x
125 #include "tnl_dd/t_dd_vb.c"
127 /***********************************************************************
128 * Generate vertex emit and interp functions *
129 ***********************************************************************/
132 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT)
133 #define TAG(x) x##_wg
134 #include "tnl_dd/t_dd_vbtmp.h"
136 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_SPEC_BIT)
137 #define TAG(x) x##_wgs
138 #include "tnl_dd/t_dd_vbtmp.h"
140 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_TEX0_BIT)
141 #define TAG(x) x##_wgt0
142 #include "tnl_dd/t_dd_vbtmp.h"
144 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
145 #define TAG(x) x##_wgt0t1
146 #include "tnl_dd/t_dd_vbtmp.h"
148 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_TEX0_BIT|MGA_PTEX_BIT)
149 #define TAG(x) x##_wgpt0
150 #include "tnl_dd/t_dd_vbtmp.h"
152 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT)
153 #define TAG(x) x##_wgst0
154 #include "tnl_dd/t_dd_vbtmp.h"
156 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
157 #define TAG(x) x##_wgst0t1
158 #include "tnl_dd/t_dd_vbtmp.h"
160 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_PTEX_BIT)
161 #define TAG(x) x##_wgspt0
162 #include "tnl_dd/t_dd_vbtmp.h"
164 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT)
165 #define TAG(x) x##_wgf
166 #include "tnl_dd/t_dd_vbtmp.h"
168 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT)
169 #define TAG(x) x##_wgfs
170 #include "tnl_dd/t_dd_vbtmp.h"
172 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_TEX0_BIT)
173 #define TAG(x) x##_wgft0
174 #include "tnl_dd/t_dd_vbtmp.h"
176 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
177 #define TAG(x) x##_wgft0t1
178 #include "tnl_dd/t_dd_vbtmp.h"
180 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_TEX0_BIT|MGA_PTEX_BIT)
181 #define TAG(x) x##_wgfpt0
182 #include "tnl_dd/t_dd_vbtmp.h"
184 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT)
185 #define TAG(x) x##_wgfst0
186 #include "tnl_dd/t_dd_vbtmp.h"
188 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
189 #define TAG(x) x##_wgfst0t1
190 #include "tnl_dd/t_dd_vbtmp.h"
192 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_PTEX_BIT)
193 #define TAG(x) x##_wgfspt0
194 #include "tnl_dd/t_dd_vbtmp.h"
196 #define IND (MGA_TEX0_BIT)
197 #define TAG(x) x##_t0
198 #include "tnl_dd/t_dd_vbtmp.h"
200 #define IND (MGA_TEX0_BIT|MGA_TEX1_BIT)
201 #define TAG(x) x##_t0t1
202 #include "tnl_dd/t_dd_vbtmp.h"
204 #define IND (MGA_FOG_BIT)
206 #include "tnl_dd/t_dd_vbtmp.h"
208 #define IND (MGA_FOG_BIT|MGA_TEX0_BIT)
209 #define TAG(x) x##_ft0
210 #include "tnl_dd/t_dd_vbtmp.h"
212 #define IND (MGA_FOG_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
213 #define TAG(x) x##_ft0t1
214 #include "tnl_dd/t_dd_vbtmp.h"
216 #define IND (MGA_RGBA_BIT)
218 #include "tnl_dd/t_dd_vbtmp.h"
220 #define IND (MGA_RGBA_BIT|MGA_SPEC_BIT)
221 #define TAG(x) x##_gs
222 #include "tnl_dd/t_dd_vbtmp.h"
224 #define IND (MGA_RGBA_BIT|MGA_TEX0_BIT)
225 #define TAG(x) x##_gt0
226 #include "tnl_dd/t_dd_vbtmp.h"
228 #define IND (MGA_RGBA_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
229 #define TAG(x) x##_gt0t1
230 #include "tnl_dd/t_dd_vbtmp.h"
232 #define IND (MGA_RGBA_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT)
233 #define TAG(x) x##_gst0
234 #include "tnl_dd/t_dd_vbtmp.h"
236 #define IND (MGA_RGBA_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
237 #define TAG(x) x##_gst0t1
238 #include "tnl_dd/t_dd_vbtmp.h"
240 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT)
241 #define TAG(x) x##_gf
242 #include "tnl_dd/t_dd_vbtmp.h"
244 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT)
245 #define TAG(x) x##_gfs
246 #include "tnl_dd/t_dd_vbtmp.h"
248 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT|MGA_TEX0_BIT)
249 #define TAG(x) x##_gft0
250 #include "tnl_dd/t_dd_vbtmp.h"
252 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
253 #define TAG(x) x##_gft0t1
254 #include "tnl_dd/t_dd_vbtmp.h"
256 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT)
257 #define TAG(x) x##_gfst0
258 #include "tnl_dd/t_dd_vbtmp.h"
260 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
261 #define TAG(x) x##_gfst0t1
262 #include "tnl_dd/t_dd_vbtmp.h"
265 static void init_setup_tab( void )
305 void mgaPrintSetupFlags(char *msg
, GLuint flags
)
307 fprintf(stderr
, "%s: %d %s%s%s%s%s%s\n",
310 (flags
& MGA_XYZW_BIT
) ? " xyzw," : "",
311 (flags
& MGA_RGBA_BIT
) ? " rgba," : "",
312 (flags
& MGA_SPEC_BIT
) ? " spec," : "",
313 (flags
& MGA_FOG_BIT
) ? " fog," : "",
314 (flags
& MGA_TEX0_BIT
) ? " tex-0," : "",
315 (flags
& MGA_TEX1_BIT
) ? " tex-1," : "");
319 void mgaCheckTexSizes( GLcontext
*ctx
)
321 mgaContextPtr mmesa
= MGA_CONTEXT( ctx
);
322 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
324 /*fprintf(stderr, "%s\n", __FUNCTION__);*/
326 if (!setup_tab
[mmesa
->SetupIndex
].check_tex_sizes(ctx
)) {
327 mmesa
->SetupIndex
|= MGA_PTEX_BIT
;
328 mmesa
->SetupNewInputs
= ~0;
330 if (!mmesa
->Fallback
&&
331 !(ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
))) {
332 tnl
->Driver
.Render
.Interp
= setup_tab
[mmesa
->SetupIndex
].interp
;
333 tnl
->Driver
.Render
.CopyPV
= setup_tab
[mmesa
->SetupIndex
].copy_pv
;
335 if (mmesa
->Fallback
) {
336 tnl
->Driver
.Render
.Start(ctx
);
342 void mgaBuildVertices( GLcontext
*ctx
,
347 mgaContextPtr mmesa
= MGA_CONTEXT( ctx
);
348 GLuint stride
= mmesa
->vertex_size
* sizeof(int);
349 GLubyte
*v
= ((GLubyte
*)mmesa
->verts
+ (start
* stride
));
351 newinputs
|= mmesa
->SetupNewInputs
;
352 mmesa
->SetupNewInputs
= 0;
357 if (newinputs
& VERT_BIT_POS
) {
358 setup_tab
[mmesa
->SetupIndex
].emit( ctx
, start
, count
, v
, stride
);
362 if (newinputs
& VERT_BIT_COLOR0
)
365 if (newinputs
& VERT_BIT_COLOR1
)
368 if (newinputs
& VERT_BIT_TEX0
)
371 if (newinputs
& VERT_BIT_TEX1
)
372 ind
|= MGA_TEX0_BIT
|MGA_TEX1_BIT
;
374 if (newinputs
& VERT_BIT_FOG
)
377 if (mmesa
->SetupIndex
& MGA_PTEX_BIT
)
380 ind
&= mmesa
->SetupIndex
;
383 setup_tab
[ind
].emit( ctx
, start
, count
, v
, stride
);
389 void mgaChooseVertexState( GLcontext
*ctx
)
391 mgaContextPtr mmesa
= MGA_CONTEXT( ctx
);
392 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
393 GLuint ind
= MGA_XYZW_BIT
|MGA_RGBA_BIT
;
395 if (ctx
->_TriangleCaps
& DD_SEPARATE_SPECULAR
)
398 if (ctx
->Fog
.Enabled
)
401 if (ctx
->Texture
._EnabledUnits
& 0x2) {
403 if (ctx
->Texture
._EnabledUnits
& 0x1) {
405 ind
|= MGA_TEX1_BIT
|MGA_TEX0_BIT
;
411 else if (ctx
->Texture
._EnabledUnits
& 0x1) {
416 mmesa
->SetupIndex
= ind
;
418 if (ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
)) {
419 tnl
->Driver
.Render
.Interp
= mga_interp_extras
;
420 tnl
->Driver
.Render
.CopyPV
= mga_copy_pv_extras
;
422 tnl
->Driver
.Render
.Interp
= setup_tab
[ind
].interp
;
423 tnl
->Driver
.Render
.CopyPV
= setup_tab
[ind
].copy_pv
;
426 if (setup_tab
[ind
].vertex_format
!= mmesa
->vertex_format
) {
428 mmesa
->dirty
|= MGA_UPLOAD_PIPE
;
429 mmesa
->vertex_format
= setup_tab
[ind
].vertex_format
;
430 mmesa
->vertex_size
= setup_tab
[ind
].vertex_size
;
436 void *mga_emit_contiguous_verts( GLcontext
*ctx
,
441 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
442 GLuint stride
= mmesa
->vertex_size
* 4;
443 setup_tab
[mmesa
->SetupIndex
].emit( ctx
, start
, count
, dest
, stride
);
444 return (void *)((char *)dest
+ stride
* (count
- start
));
449 void mgaInitVB( GLcontext
*ctx
)
451 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
452 GLuint size
= TNL_CONTEXT(ctx
)->vb
.Size
;
454 mmesa
->verts
= (GLubyte
*)ALIGN_MALLOC(size
* sizeof(mgaVertex
), 32);
457 static int firsttime
= 1;
464 mmesa
->dirty
|= MGA_UPLOAD_PIPE
;
465 mmesa
->vertex_format
= setup_tab
[0].vertex_format
;
466 mmesa
->vertex_size
= setup_tab
[0].vertex_size
;
470 void mgaFreeVB( GLcontext
*ctx
)
472 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
474 ALIGN_FREE(mmesa
->verts
);