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_setup/swrast_setup.h"
43 #include "swrast/swrast.h"
46 #define MGA_TEX1_BIT 0x1
47 #define MGA_TEX0_BIT 0x2
48 #define MGA_RGBA_BIT 0x4
49 #define MGA_SPEC_BIT 0x8
50 #define MGA_FOG_BIT 0x10
51 #define MGA_XYZW_BIT 0x20
52 #define MGA_PTEX_BIT 0x40
53 #define MGA_MAX_SETUP 0x80
56 void (*emit
)( GLcontext
*, GLuint
, GLuint
, void *, GLuint
);
57 tnl_interp_func interp
;
58 tnl_copy_pv_func copy_pv
;
59 GLboolean (*check_tex_sizes
)( GLcontext
*ctx
);
62 } setup_tab
[MGA_MAX_SETUP
];
65 #define TINY_VERTEX_FORMAT 0
66 #define NOTEX_VERTEX_FORMAT 0
67 #define TEX0_VERTEX_FORMAT (MGA_A|MGA_S|MGA_F)
68 #define TEX1_VERTEX_FORMAT (MGA_A|MGA_S|MGA_F|MGA_T2)
69 #define PROJ_TEX1_VERTEX_FORMAT 0
70 #define TEX2_VERTEX_FORMAT 0
71 #define TEX3_VERTEX_FORMAT 0
72 #define PROJ_TEX3_VERTEX_FORMAT 0
74 #define DO_XYZW (IND & MGA_XYZW_BIT)
75 #define DO_RGBA (IND & MGA_RGBA_BIT)
76 #define DO_SPEC (IND & MGA_SPEC_BIT)
77 #define DO_FOG (IND & MGA_FOG_BIT)
78 #define DO_TEX0 (IND & MGA_TEX0_BIT)
79 #define DO_TEX1 (IND & MGA_TEX1_BIT)
82 #define DO_PTEX (IND & MGA_PTEX_BIT)
85 #define VERTEX mgaVertex
86 #define VERTEX_COLOR mga_color_t
87 #define LOCALVARS mgaContextPtr mmesa = MGA_CONTEXT(ctx);
88 #define GET_VIEWPORT_MAT() mmesa->hw_viewport
89 #define GET_TEXSOURCE(n) mmesa->tmu_source[n]
90 #define GET_VERTEX_FORMAT() mmesa->vertex_format
91 #define GET_VERTEX_STORE() mmesa->verts
92 #define GET_VERTEX_SIZE() mmesa->vertex_size * sizeof(GLuint)
94 #define HAVE_HW_VIEWPORT 0
95 #define HAVE_HW_DIVIDE 0
96 #define HAVE_RGBA_COLOR 0
97 #define HAVE_TINY_VERTICES 0
98 #define HAVE_NOTEX_VERTICES 0
99 #define HAVE_TEX0_VERTICES 1
100 #define HAVE_TEX1_VERTICES 1
101 #define HAVE_TEX2_VERTICES 0
102 #define HAVE_TEX3_VERTICES 0
103 #define HAVE_PTEX_VERTICES 0
105 #define UNVIEWPORT_VARS \
106 const GLfloat dx = - mmesa->drawX - SUBPIXEL_X; \
107 const GLfloat dy = (mmesa->driDrawable->h + \
108 mmesa->drawY + SUBPIXEL_Y); \
109 const GLfloat sz = 1.0 / mmesa->depth_scale
111 #define UNVIEWPORT_X(x) x + dx;
112 #define UNVIEWPORT_Y(y) - y + dy;
113 #define UNVIEWPORT_Z(z) z * sz;
115 #define PTEX_FALLBACK() FALLBACK(ctx, MGA_FALLBACK_TEXTURE, 1)
117 #define INTERP_VERTEX setup_tab[mmesa->SetupIndex].interp
118 #define COPY_PV_VERTEX setup_tab[mmesa->SetupIndex].copy_pv
121 /***********************************************************************
122 * Generate pv-copying and translation functions *
123 ***********************************************************************/
125 #define TAG(x) mga_##x
126 #include "tnl_dd/t_dd_vb.c"
128 /***********************************************************************
129 * Generate vertex emit and interp functions *
130 ***********************************************************************/
133 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT)
134 #define TAG(x) x##_wg
135 #include "tnl_dd/t_dd_vbtmp.h"
137 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_SPEC_BIT)
138 #define TAG(x) x##_wgs
139 #include "tnl_dd/t_dd_vbtmp.h"
141 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_TEX0_BIT)
142 #define TAG(x) x##_wgt0
143 #include "tnl_dd/t_dd_vbtmp.h"
145 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
146 #define TAG(x) x##_wgt0t1
147 #include "tnl_dd/t_dd_vbtmp.h"
149 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_TEX0_BIT|MGA_PTEX_BIT)
150 #define TAG(x) x##_wgpt0
151 #include "tnl_dd/t_dd_vbtmp.h"
153 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT)
154 #define TAG(x) x##_wgst0
155 #include "tnl_dd/t_dd_vbtmp.h"
157 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
158 #define TAG(x) x##_wgst0t1
159 #include "tnl_dd/t_dd_vbtmp.h"
161 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_PTEX_BIT)
162 #define TAG(x) x##_wgspt0
163 #include "tnl_dd/t_dd_vbtmp.h"
165 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT)
166 #define TAG(x) x##_wgf
167 #include "tnl_dd/t_dd_vbtmp.h"
169 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT)
170 #define TAG(x) x##_wgfs
171 #include "tnl_dd/t_dd_vbtmp.h"
173 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_TEX0_BIT)
174 #define TAG(x) x##_wgft0
175 #include "tnl_dd/t_dd_vbtmp.h"
177 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
178 #define TAG(x) x##_wgft0t1
179 #include "tnl_dd/t_dd_vbtmp.h"
181 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_TEX0_BIT|MGA_PTEX_BIT)
182 #define TAG(x) x##_wgfpt0
183 #include "tnl_dd/t_dd_vbtmp.h"
185 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT)
186 #define TAG(x) x##_wgfst0
187 #include "tnl_dd/t_dd_vbtmp.h"
189 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
190 #define TAG(x) x##_wgfst0t1
191 #include "tnl_dd/t_dd_vbtmp.h"
193 #define IND (MGA_XYZW_BIT|MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_PTEX_BIT)
194 #define TAG(x) x##_wgfspt0
195 #include "tnl_dd/t_dd_vbtmp.h"
197 #define IND (MGA_TEX0_BIT)
198 #define TAG(x) x##_t0
199 #include "tnl_dd/t_dd_vbtmp.h"
201 #define IND (MGA_TEX0_BIT|MGA_TEX1_BIT)
202 #define TAG(x) x##_t0t1
203 #include "tnl_dd/t_dd_vbtmp.h"
205 #define IND (MGA_FOG_BIT)
207 #include "tnl_dd/t_dd_vbtmp.h"
209 #define IND (MGA_FOG_BIT|MGA_TEX0_BIT)
210 #define TAG(x) x##_ft0
211 #include "tnl_dd/t_dd_vbtmp.h"
213 #define IND (MGA_FOG_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
214 #define TAG(x) x##_ft0t1
215 #include "tnl_dd/t_dd_vbtmp.h"
217 #define IND (MGA_RGBA_BIT)
219 #include "tnl_dd/t_dd_vbtmp.h"
221 #define IND (MGA_RGBA_BIT|MGA_SPEC_BIT)
222 #define TAG(x) x##_gs
223 #include "tnl_dd/t_dd_vbtmp.h"
225 #define IND (MGA_RGBA_BIT|MGA_TEX0_BIT)
226 #define TAG(x) x##_gt0
227 #include "tnl_dd/t_dd_vbtmp.h"
229 #define IND (MGA_RGBA_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
230 #define TAG(x) x##_gt0t1
231 #include "tnl_dd/t_dd_vbtmp.h"
233 #define IND (MGA_RGBA_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT)
234 #define TAG(x) x##_gst0
235 #include "tnl_dd/t_dd_vbtmp.h"
237 #define IND (MGA_RGBA_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
238 #define TAG(x) x##_gst0t1
239 #include "tnl_dd/t_dd_vbtmp.h"
241 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT)
242 #define TAG(x) x##_gf
243 #include "tnl_dd/t_dd_vbtmp.h"
245 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT)
246 #define TAG(x) x##_gfs
247 #include "tnl_dd/t_dd_vbtmp.h"
249 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT|MGA_TEX0_BIT)
250 #define TAG(x) x##_gft0
251 #include "tnl_dd/t_dd_vbtmp.h"
253 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
254 #define TAG(x) x##_gft0t1
255 #include "tnl_dd/t_dd_vbtmp.h"
257 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT)
258 #define TAG(x) x##_gfst0
259 #include "tnl_dd/t_dd_vbtmp.h"
261 #define IND (MGA_RGBA_BIT|MGA_FOG_BIT|MGA_SPEC_BIT|MGA_TEX0_BIT|MGA_TEX1_BIT)
262 #define TAG(x) x##_gfst0t1
263 #include "tnl_dd/t_dd_vbtmp.h"
266 static void init_setup_tab( void )
306 void mgaPrintSetupFlags(char *msg
, GLuint flags
)
308 fprintf(stderr
, "%s: %d %s%s%s%s%s%s\n",
311 (flags
& MGA_XYZW_BIT
) ? " xyzw," : "",
312 (flags
& MGA_RGBA_BIT
) ? " rgba," : "",
313 (flags
& MGA_SPEC_BIT
) ? " spec," : "",
314 (flags
& MGA_FOG_BIT
) ? " fog," : "",
315 (flags
& MGA_TEX0_BIT
) ? " tex-0," : "",
316 (flags
& MGA_TEX1_BIT
) ? " tex-1," : "");
320 void mgaCheckTexSizes( GLcontext
*ctx
)
322 mgaContextPtr mmesa
= MGA_CONTEXT( ctx
);
323 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
325 /*fprintf(stderr, "%s\n", __FUNCTION__);*/
327 if (!setup_tab
[mmesa
->SetupIndex
].check_tex_sizes(ctx
)) {
328 mmesa
->SetupIndex
|= MGA_PTEX_BIT
;
329 mmesa
->SetupNewInputs
= ~0;
331 if (!mmesa
->Fallback
&&
332 !(ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
))) {
333 tnl
->Driver
.Render
.Interp
= setup_tab
[mmesa
->SetupIndex
].interp
;
334 tnl
->Driver
.Render
.CopyPV
= setup_tab
[mmesa
->SetupIndex
].copy_pv
;
336 if (mmesa
->Fallback
) {
337 tnl
->Driver
.Render
.Start(ctx
);
343 void mgaBuildVertices( GLcontext
*ctx
,
348 mgaContextPtr mmesa
= MGA_CONTEXT( ctx
);
349 GLuint stride
= mmesa
->vertex_size
* sizeof(int);
350 GLubyte
*v
= ((GLubyte
*)mmesa
->verts
+ (start
* stride
));
352 newinputs
|= mmesa
->SetupNewInputs
;
353 mmesa
->SetupNewInputs
= 0;
358 if (newinputs
& VERT_BIT_POS
) {
359 setup_tab
[mmesa
->SetupIndex
].emit( ctx
, start
, count
, v
, stride
);
363 if (newinputs
& VERT_BIT_COLOR0
)
366 if (newinputs
& VERT_BIT_COLOR1
)
369 if (newinputs
& VERT_BIT_TEX0
)
372 if (newinputs
& VERT_BIT_TEX1
)
373 ind
|= MGA_TEX0_BIT
|MGA_TEX1_BIT
;
375 if (newinputs
& VERT_BIT_FOG
)
378 if (mmesa
->SetupIndex
& MGA_PTEX_BIT
)
381 ind
&= mmesa
->SetupIndex
;
384 setup_tab
[ind
].emit( ctx
, start
, count
, v
, stride
);
390 void mgaChooseVertexState( GLcontext
*ctx
)
392 mgaContextPtr mmesa
= MGA_CONTEXT( ctx
);
393 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
394 GLuint ind
= MGA_XYZW_BIT
|MGA_RGBA_BIT
;
396 if (ctx
->_TriangleCaps
& DD_SEPARATE_SPECULAR
)
399 if (ctx
->Fog
.Enabled
)
402 if (ctx
->Texture
._EnabledUnits
& 0x2) {
404 if (ctx
->Texture
._EnabledUnits
& 0x1) {
406 ind
|= MGA_TEX1_BIT
|MGA_TEX0_BIT
;
412 else if (ctx
->Texture
._EnabledUnits
& 0x1) {
417 mmesa
->SetupIndex
= ind
;
419 if (ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
)) {
420 tnl
->Driver
.Render
.Interp
= mga_interp_extras
;
421 tnl
->Driver
.Render
.CopyPV
= mga_copy_pv_extras
;
423 tnl
->Driver
.Render
.Interp
= setup_tab
[ind
].interp
;
424 tnl
->Driver
.Render
.CopyPV
= setup_tab
[ind
].copy_pv
;
427 if (setup_tab
[ind
].vertex_format
!= mmesa
->vertex_format
) {
429 mmesa
->dirty
|= MGA_UPLOAD_PIPE
;
430 mmesa
->vertex_format
= setup_tab
[ind
].vertex_format
;
431 mmesa
->vertex_size
= setup_tab
[ind
].vertex_size
;
437 void *mga_emit_contiguous_verts( GLcontext
*ctx
,
442 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
443 GLuint stride
= mmesa
->vertex_size
* 4;
444 setup_tab
[mmesa
->SetupIndex
].emit( ctx
, start
, count
, dest
, stride
);
445 return (void *)((char *)dest
+ stride
* (count
- start
));
450 void mgaInitVB( GLcontext
*ctx
)
452 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
453 GLuint size
= TNL_CONTEXT(ctx
)->vb
.Size
;
455 mmesa
->verts
= (GLubyte
*)ALIGN_MALLOC(size
* sizeof(mgaVertex
), 32);
458 static int firsttime
= 1;
465 mmesa
->dirty
|= MGA_UPLOAD_PIPE
;
466 mmesa
->vertex_format
= setup_tab
[0].vertex_format
;
467 mmesa
->vertex_size
= setup_tab
[0].vertex_size
;
471 void mgaFreeVB( GLcontext
*ctx
)
473 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
475 ALIGN_FREE(mmesa
->verts
);