2 * Author: Max Lingua <sunmax@libero.it>
5 #include "main/glheader.h"
6 #include "main/mtypes.h"
7 #include "main/macros.h"
8 #include "main/colormac.h"
10 #include "swrast_setup/swrast_setup.h"
11 #include "tnl/t_context.h"
14 #include "s3v_context.h"
18 #define S3V_XYZW_BIT 0x1
19 #define S3V_RGBA_BIT 0x2
20 #define S3V_TEX0_BIT 0x4
21 #define S3V_PTEX_BIT 0x8
22 #define S3V_FOG_BIT 0x10
23 #define S3V_MAX_SETUP 0x20
26 void (*emit
)( GLcontext
*, GLuint
, GLuint
, void *, GLuint
);
27 tnl_interp_func interp
;
28 tnl_copy_pv_func copy_pv
;
29 GLboolean (*check_tex_sizes
)( GLcontext
*ctx
);
31 GLuint vertex_stride_shift
;
33 } setup_tab
[S3V_MAX_SETUP
];
36 /* Only one vertex format, atm, so no need to give them names:
38 #define TINY_VERTEX_FORMAT 1
39 #define NOTEX_VERTEX_FORMAT 0
40 #define TEX0_VERTEX_FORMAT 0
41 #define TEX1_VERTEX_FORMAT 0
42 #define PROJ_TEX1_VERTEX_FORMAT 0
43 #define TEX2_VERTEX_FORMAT 0
44 #define TEX3_VERTEX_FORMAT 0
45 #define PROJ_TEX3_VERTEX_FORMAT 0
47 #define DO_XYZW (IND & S3V_XYZW_BIT)
48 #define DO_RGBA (IND & S3V_RGBA_BIT)
50 #define DO_FOG (IND & S3V_FOG_BIT)
51 #define DO_TEX0 (IND & S3V_TEX0_BIT)
55 #define DO_PTEX (IND & S3V_PTEX_BIT)
57 #define VERTEX s3vVertex
58 #define LOCALVARS /* s3vContextPtr vmesa = S3V_CONTEXT(ctx); */
59 #define GET_VIEWPORT_MAT() 0 /* vmesa->hw_viewport */
60 #define GET_TEXSOURCE(n) n
61 #define GET_VERTEX_FORMAT() 0
62 #define GET_VERTEX_SIZE() S3V_CONTEXT(ctx)->vertex_size * sizeof(GLuint)
63 #define GET_VERTEX_STORE() S3V_CONTEXT(ctx)->verts
64 #define GET_VERTEX_STRIDE_SHIFT() S3V_CONTEXT(ctx)->vertex_stride_shift
65 #define INVALIDATE_STORED_VERTICES()
66 #define GET_UBYTE_COLOR_STORE() &S3V_CONTEXT(ctx)->UbyteColor
67 #define GET_UBYTE_SPEC_COLOR_STORE() &S3V_CONTEXT(ctx)->UbyteSecondaryColor
69 #define HAVE_HW_VIEWPORT 1 /* FIXME */
70 #define HAVE_HW_DIVIDE 1
71 #define HAVE_RGBA_COLOR 0 /* we're BGRA */
72 #define HAVE_TINY_VERTICES 1
73 #define HAVE_NOTEX_VERTICES 0
74 #define HAVE_TEX0_VERTICES 0
75 #define HAVE_TEX1_VERTICES 0
76 #define HAVE_TEX2_VERTICES 0
77 #define HAVE_TEX3_VERTICES 0
78 #define HAVE_PTEX_VERTICES 1
81 #define SUBPIXEL_X -.5
82 #define SUBPIXEL_Y -.5
83 #define UNVIEWPORT_VARS GLfloat h = S3V_CONTEXT(ctx)->driDrawable->h
84 #define UNVIEWPORT_X(x) x - SUBPIXEL_X
85 #define UNVIEWPORT_Y(y) - y + h + SUBPIXEL_Y
86 #define UNVIEWPORT_Z(z) z / vmesa->depth_scale
89 #define PTEX_FALLBACK() /* never needed */
91 #define IMPORT_QUALIFIER
92 #define IMPORT_FLOAT_COLORS s3v_import_float_colors
93 #define IMPORT_FLOAT_SPEC_COLORS s3v_import_float_spec_colors
95 #define INTERP_VERTEX setup_tab[S3V_CONTEXT(ctx)->SetupIndex].interp
96 #define COPY_PV_VERTEX setup_tab[S3V_CONTEXT(ctx)->SetupIndex].copy_pv
100 /***********************************************************************
101 * Generate pv-copying and translation functions *
102 ***********************************************************************/
104 #define TAG(x) s3v_##x
105 #include "tnl_dd/t_dd_vb.c"
107 /***********************************************************************
108 * Generate vertex emit and interp functions *
109 ***********************************************************************/
112 #define IND (S3V_XYZW_BIT|S3V_RGBA_BIT)
113 #define TAG(x) x##_wg
114 #include "tnl_dd/t_dd_vbtmp.h"
116 #define IND (S3V_XYZW_BIT|S3V_RGBA_BIT|S3V_TEX0_BIT)
117 #define TAG(x) x##_wgt0
118 #include "tnl_dd/t_dd_vbtmp.h"
120 #define IND (S3V_XYZW_BIT|S3V_RGBA_BIT|S3V_TEX0_BIT|S3V_PTEX_BIT)
121 #define TAG(x) x##_wgpt0
122 #include "tnl_dd/t_dd_vbtmp.h"
124 #define IND (S3V_TEX0_BIT)
125 #define TAG(x) x##_t0
126 #include "tnl_dd/t_dd_vbtmp.h"
128 #define IND (S3V_RGBA_BIT)
130 #include "tnl_dd/t_dd_vbtmp.h"
132 #define IND (S3V_RGBA_BIT|S3V_TEX0_BIT)
133 #define TAG(x) x##_gt0
134 #include "tnl_dd/t_dd_vbtmp.h"
136 #define IND (S3V_XYZW_BIT|S3V_RGBA_BIT|S3V_FOG_BIT)
137 #define TAG(x) x##_wgf
138 #include "tnl_dd/t_dd_vbtmp.h"
140 #define IND (S3V_XYZW_BIT|S3V_RGBA_BIT|S3V_FOG_BIT|S3V_TEX0_BIT)
141 #define TAG(x) x##_wgft0
142 #include "tnl_dd/t_dd_vbtmp.h"
144 #define IND (S3V_XYZW_BIT|S3V_RGBA_BIT|S3V_FOG_BIT|S3V_TEX0_BIT|S3V_PTEX_BIT)
145 #define TAG(x) x##_wgfpt0
146 #include "tnl_dd/t_dd_vbtmp.h"
148 #define IND (S3V_FOG_BIT)
150 #include "tnl_dd/t_dd_vbtmp.h"
152 #define IND (S3V_RGBA_BIT | S3V_FOG_BIT)
153 #define TAG(x) x##_gf
154 #include "tnl_dd/t_dd_vbtmp.h"
156 #define IND (S3V_RGBA_BIT | S3V_FOG_BIT | S3V_TEX0_BIT)
157 #define TAG(x) x##_gft0
158 #include "tnl_dd/t_dd_vbtmp.h"
160 static void init_setup_tab( void )
162 init_wg(); /* pos + col */
163 init_wgt0(); /* pos + col + tex0 */
164 init_wgpt0(); /* pos + col + p-tex0 (?) */
165 init_t0(); /* tex0 */
167 init_gt0(); /* col + tex */
178 void s3vPrintSetupFlags(char *msg
, GLuint flags
)
180 fprintf(stderr
, "%s(%x): %s%s%s%s%s%s\n",
183 (flags
& S3V_XYZW_BIT
) ? " xyzw," : "",
184 (flags
& S3V_RGBA_BIT
) ? " rgba," : "",
185 (flags
& S3V_SPEC_BIT
) ? " spec," : "",
186 (flags
& S3V_FOG_BIT
) ? " fog," : "",
187 (flags
& S3V_TEX0_BIT
) ? " tex-0," : "",
188 (flags
& S3V_TEX1_BIT
) ? " tex-1," : "");
193 void s3vCheckTexSizes( GLcontext
*ctx
)
195 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
196 s3vContextPtr vmesa
= S3V_CONTEXT( ctx
);
198 if (!setup_tab
[vmesa
->SetupIndex
].check_tex_sizes(ctx
)) {
200 vmesa
->SetupIndex
|= (S3V_PTEX_BIT
|S3V_RGBA_BIT
);
202 if (1 || !(ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
))) {
203 tnl
->Driver
.Render
.Interp
= setup_tab
[vmesa
->SetupIndex
].interp
;
204 tnl
->Driver
.Render
.CopyPV
= setup_tab
[vmesa
->SetupIndex
].copy_pv
;
209 void s3vBuildVertices( GLcontext
*ctx
,
214 s3vContextPtr vmesa
= S3V_CONTEXT( ctx
);
215 GLubyte
*v
= ((GLubyte
*)vmesa
->verts
+
216 (start
<<vmesa
->vertex_stride_shift
));
217 GLuint stride
= 1<<vmesa
->vertex_stride_shift
;
219 DEBUG(("*** s3vBuildVertices ***\n"));
220 DEBUG(("vmesa->SetupNewInputs = 0x%x\n", vmesa
->SetupNewInputs
));
221 DEBUG(("vmesa->SetupIndex = 0x%x\n", vmesa
->SetupIndex
));
224 setup_tab
[vmesa
->SetupIndex
].emit( ctx
, start
, count
, v
, stride
);
226 newinputs
|= vmesa
->SetupNewInputs
;
227 vmesa
->SetupNewInputs
= 0;
229 DEBUG(("newinputs is 0x%x\n", newinputs
));
232 DEBUG(("!newinputs\n"));
236 if (newinputs
& VERT_CLIP
) {
237 setup_tab
[vmesa
->SetupIndex
].emit( ctx
, start
, count
, v
, stride
);
238 DEBUG(("newinputs & VERT_CLIP\n"));
241 /* GLuint ind = 0; */
243 if (newinputs
& VERT_RGBA
) {
244 DEBUG(("newinputs & VERT_RGBA\n"));
248 if (newinputs
& VERT_TEX0
) {
249 DEBUG(("newinputs & VERT_TEX0\n"));
253 if (newinputs
& VERT_FOG_COORD
)
256 if (vmesa
->SetupIndex
& S3V_PTEX_BIT
)
259 ind
&= vmesa
->SetupIndex
;
261 DEBUG(("vmesa->SetupIndex = 0x%x\n", vmesa
->SetupIndex
));
262 DEBUG(("ind = 0x%x\n", ind
));
263 DEBUG(("ind & vmesa->SetupIndex = 0x%x\n", (ind
& vmesa
->SetupIndex
)));
266 setup_tab
[ind
].emit( ctx
, start
, count
, v
, stride
);
271 void s3vChooseVertexState( GLcontext
*ctx
)
273 s3vContextPtr vmesa
= S3V_CONTEXT( ctx
);
274 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
276 GLuint ind
= S3V_XYZW_BIT
| S3V_RGBA_BIT
;
278 /* FIXME: will segv in tnl_dd/t_dd_vbtmp.h (line 196) on some demos */
280 if (ctx->Fog.Enabled)
285 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
) {
286 _tnl_need_projected_coords( ctx
, GL_FALSE
);
289 _tnl_need_projected_coords( ctx
, GL_TRUE
);
292 vmesa
->SetupIndex
= ind
;
294 if (ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
)) {
295 tnl
->Driver
.Render
.Interp
= s3v_interp_extras
;
296 tnl
->Driver
.Render
.CopyPV
= s3v_copy_pv_extras
;
298 tnl
->Driver
.Render
.Interp
= setup_tab
[ind
].interp
;
299 tnl
->Driver
.Render
.CopyPV
= setup_tab
[ind
].copy_pv
;
304 void s3vInitVB( GLcontext
*ctx
)
306 s3vContextPtr vmesa
= S3V_CONTEXT(ctx
);
307 GLuint size
= TNL_CONTEXT(ctx
)->vb
.Size
;
309 vmesa
->verts
= (char *)ALIGN_MALLOC(size
* 4 * 16, 32);
312 static int firsttime
= 1;
316 vmesa
->vertex_stride_shift
= 6 /* 4 */; /* FIXME - only one vertex setup */
322 void s3vFreeVB( GLcontext
*ctx
)
324 s3vContextPtr vmesa
= S3V_CONTEXT(ctx
);
326 ALIGN_FREE(vmesa
->verts
);
330 if (vmesa
->UbyteSecondaryColor
.Ptr
) {
331 ALIGN_FREE((void *)vmesa
->UbyteSecondaryColor
.Ptr
);
332 vmesa
->UbyteSecondaryColor
.Ptr
= 0;
335 if (vmesa
->UbyteColor
.Ptr
) {
336 ALIGN_FREE((void *)vmesa
->UbyteColor
.Ptr
);
337 vmesa
->UbyteColor
.Ptr
= 0;