1 /* $XFree86: xc/lib/GL/mesa/src/drv/gamma/gamma_vb.c,v 1.4 2003/03/26 20:43:48 tsi Exp $ */
3 * Copyright 2001 by Alan Hourihane.
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of Alan Hourihane not be used in
10 * advertising or publicity pertaining to distribution of the software without
11 * specific, written prior permission. Alan Hourihane makes no representations
12 * about the suitability of this software for any purpose. It is provided
13 * "as is" without express or implied warranty.
15 * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21 * PERFORMANCE OF THIS SOFTWARE.
23 * Authors: Alan Hourihane, <alanh@tungstengraphics.com>
24 * Keith Whitwell, <keith@tungstengraphics.com>
26 * 3DLabs Gamma driver.
35 #include "swrast_setup/swrast_setup.h"
36 #include "tnl/t_context.h"
39 #include "gamma_context.h"
41 #include "gamma_tris.h"
44 #define GAMMA_TEX0_BIT 0x1
45 #define GAMMA_RGBA_BIT 0x2
46 #define GAMMA_XYZW_BIT 0x4
47 #define GAMMA_PTEX_BIT 0x8
48 #define GAMMA_FOG_BIT 0x10
49 #define GAMMA_SPEC_BIT 0x20
50 #define GAMMA_MAX_SETUP 0x40
53 void (*emit
)( GLcontext
*, GLuint
, GLuint
, void *, GLuint
);
56 GLboolean (*check_tex_sizes
)( GLcontext
*ctx
);
58 GLuint vertex_stride_shift
;
60 } setup_tab
[GAMMA_MAX_SETUP
];
62 #define TINY_VERTEX_FORMAT 1
63 #define NOTEX_VERTEX_FORMAT 2
64 #define TEX0_VERTEX_FORMAT 3
65 #define TEX1_VERTEX_FORMAT 0
66 #define PROJ_TEX1_VERTEX_FORMAT 0
67 #define TEX2_VERTEX_FORMAT 0
68 #define TEX3_VERTEX_FORMAT 0
69 #define PROJ_TEX3_VERTEX_FORMAT 0
71 #define DO_XYZW (IND & GAMMA_XYZW_BIT)
72 #define DO_RGBA (IND & GAMMA_RGBA_BIT)
73 #define DO_SPEC (IND & GAMMA_SPEC_BIT)
74 #define DO_FOG (IND & GAMMA_FOG_BIT)
75 #define DO_TEX0 (IND & GAMMA_TEX0_BIT)
79 #define DO_PTEX (IND & GAMMA_PTEX_BIT)
81 #define VERTEX gammaVertex
82 #define VERTEX_COLOR gamma_color_t
83 #define GET_VIEWPORT_MAT() 0
84 #define GET_TEXSOURCE(n) n
85 #define GET_VERTEX_FORMAT() GAMMA_CONTEXT(ctx)->vertex_format
86 #define GET_VERTEX_STORE() GAMMA_CONTEXT(ctx)->verts
87 #define GET_VERTEX_STRIDE_SHIFT() GAMMA_CONTEXT(ctx)->vertex_stride_shift
88 #define INVALIDATE_STORED_VERTICES()
89 #define GET_UBYTE_COLOR_STORE() &GAMMA_CONTEXT(ctx)->UbyteColor
90 #define GET_UBYTE_SPEC_COLOR_STORE() &GAMMA_CONTEXT(ctx)->UbyteSecondaryColor
92 #define HAVE_HW_VIEWPORT 1
93 #define HAVE_HW_DIVIDE 1
94 #define HAVE_RGBA_COLOR 0 /* we're BGRA */
95 #define HAVE_TINY_VERTICES 1
96 #define HAVE_NOTEX_VERTICES 1
97 #define HAVE_TEX0_VERTICES 1
98 #define HAVE_TEX1_VERTICES 0
99 #define HAVE_TEX2_VERTICES 0
100 #define HAVE_TEX3_VERTICES 0
101 #define HAVE_PTEX_VERTICES 1
103 #define PTEX_FALLBACK() /* never needed */
105 #define IMPORT_QUALIFIER
106 #define IMPORT_FLOAT_COLORS gamma_import_float_colors
107 #define IMPORT_FLOAT_SPEC_COLORS gamma_import_float_spec_colors
109 #define INTERP_VERTEX setup_tab[GAMMA_CONTEXT(ctx)->SetupIndex].interp
110 #define COPY_PV_VERTEX setup_tab[GAMMA_CONTEXT(ctx)->SetupIndex].copy_pv
114 /***********************************************************************
115 * Generate pv-copying and translation functions *
116 ***********************************************************************/
118 #define TAG(x) gamma_##x
119 #include "tnl_dd/t_dd_vb.c"
121 /***********************************************************************
122 * Generate vertex emit and interp functions *
123 ***********************************************************************/
125 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT)
126 #define TAG(x) x##_wg
127 #include "tnl_dd/t_dd_vbtmp.h"
129 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_SPEC_BIT)
130 #define TAG(x) x##_wgs
131 #include "tnl_dd/t_dd_vbtmp.h"
133 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_TEX0_BIT)
134 #define TAG(x) x##_wgt0
135 #include "tnl_dd/t_dd_vbtmp.h"
137 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_TEX0_BIT|GAMMA_PTEX_BIT)
138 #define TAG(x) x##_wgpt0
139 #include "tnl_dd/t_dd_vbtmp.h"
141 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_SPEC_BIT|GAMMA_TEX0_BIT)
142 #define TAG(x) x##_wgst0
143 #include "tnl_dd/t_dd_vbtmp.h"
145 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_SPEC_BIT|GAMMA_TEX0_BIT|\
147 #define TAG(x) x##_wgspt0
148 #include "tnl_dd/t_dd_vbtmp.h"
150 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_FOG_BIT)
151 #define TAG(x) x##_wgf
152 #include "tnl_dd/t_dd_vbtmp.h"
154 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_FOG_BIT|GAMMA_SPEC_BIT)
155 #define TAG(x) x##_wgfs
156 #include "tnl_dd/t_dd_vbtmp.h"
158 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_FOG_BIT|GAMMA_TEX0_BIT)
159 #define TAG(x) x##_wgft0
160 #include "tnl_dd/t_dd_vbtmp.h"
162 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_FOG_BIT|GAMMA_TEX0_BIT|\
164 #define TAG(x) x##_wgfpt0
165 #include "tnl_dd/t_dd_vbtmp.h"
167 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_FOG_BIT|GAMMA_SPEC_BIT|\
169 #define TAG(x) x##_wgfst0
170 #include "tnl_dd/t_dd_vbtmp.h"
172 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_FOG_BIT|GAMMA_SPEC_BIT|\
173 GAMMA_TEX0_BIT|GAMMA_PTEX_BIT)
174 #define TAG(x) x##_wgfspt0
175 #include "tnl_dd/t_dd_vbtmp.h"
177 #define IND (GAMMA_TEX0_BIT)
178 #define TAG(x) x##_t0
179 #include "tnl_dd/t_dd_vbtmp.h"
181 #define IND (GAMMA_FOG_BIT)
183 #include "tnl_dd/t_dd_vbtmp.h"
185 #define IND (GAMMA_FOG_BIT|GAMMA_TEX0_BIT)
186 #define TAG(x) x##_ft0
187 #include "tnl_dd/t_dd_vbtmp.h"
189 #define IND (GAMMA_RGBA_BIT)
191 #include "tnl_dd/t_dd_vbtmp.h"
193 #define IND (GAMMA_RGBA_BIT|GAMMA_SPEC_BIT)
194 #define TAG(x) x##_gs
195 #include "tnl_dd/t_dd_vbtmp.h"
197 #define IND (GAMMA_RGBA_BIT|GAMMA_TEX0_BIT)
198 #define TAG(x) x##_gt0
199 #include "tnl_dd/t_dd_vbtmp.h"
201 #define IND (GAMMA_RGBA_BIT|GAMMA_SPEC_BIT|GAMMA_TEX0_BIT)
202 #define TAG(x) x##_gst0
203 #include "tnl_dd/t_dd_vbtmp.h"
205 #define IND (GAMMA_RGBA_BIT|GAMMA_FOG_BIT)
206 #define TAG(x) x##_gf
207 #include "tnl_dd/t_dd_vbtmp.h"
209 #define IND (GAMMA_RGBA_BIT|GAMMA_FOG_BIT|GAMMA_SPEC_BIT)
210 #define TAG(x) x##_gfs
211 #include "tnl_dd/t_dd_vbtmp.h"
213 #define IND (GAMMA_RGBA_BIT|GAMMA_FOG_BIT|GAMMA_TEX0_BIT)
214 #define TAG(x) x##_gft0
215 #include "tnl_dd/t_dd_vbtmp.h"
217 #define IND (GAMMA_RGBA_BIT|GAMMA_FOG_BIT|GAMMA_SPEC_BIT|GAMMA_TEX0_BIT)
218 #define TAG(x) x##_gfst0
219 #include "tnl_dd/t_dd_vbtmp.h"
221 static void init_setup_tab( void )
248 void gammaCheckTexSizes( GLcontext
*ctx
)
250 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
251 gammaContextPtr gmesa
= GAMMA_CONTEXT( ctx
);
253 if (!setup_tab
[gmesa
->SetupIndex
].check_tex_sizes(ctx
)) {
254 /* Invalidate stored verts
256 gmesa
->SetupNewInputs
= ~0;
257 gmesa
->SetupIndex
|= GAMMA_PTEX_BIT
;
259 if (!(ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
))) {
260 tnl
->Driver
.Render
.Interp
= setup_tab
[gmesa
->SetupIndex
].interp
;
261 tnl
->Driver
.Render
.CopyPV
= setup_tab
[gmesa
->SetupIndex
].copy_pv
;
266 void gammaBuildVertices( GLcontext
*ctx
,
271 gammaContextPtr gmesa
= GAMMA_CONTEXT( ctx
);
272 GLubyte
*v
= ((GLubyte
*)gmesa
->verts
+ (start
<<gmesa
->vertex_stride_shift
));
273 GLuint stride
= 1<<gmesa
->vertex_stride_shift
;
275 newinputs
|= gmesa
->SetupNewInputs
;
276 gmesa
->SetupNewInputs
= 0;
281 if (newinputs
& VERT_BIT_POS
) {
282 setup_tab
[gmesa
->SetupIndex
].emit( ctx
, start
, count
, v
, stride
);
286 if (newinputs
& VERT_BIT_COLOR0
)
287 ind
|= GAMMA_RGBA_BIT
;
289 if (newinputs
& VERT_BIT_COLOR1
)
290 ind
|= GAMMA_SPEC_BIT
;
292 if (newinputs
& VERT_BIT_TEX0
)
293 ind
|= GAMMA_TEX0_BIT
;
295 if (newinputs
& VERT_BIT_FOG
)
296 ind
|= GAMMA_FOG_BIT
;
298 if (gmesa
->SetupIndex
& GAMMA_PTEX_BIT
)
301 ind
&= gmesa
->SetupIndex
;
304 setup_tab
[ind
].emit( ctx
, start
, count
, v
, stride
);
309 void gammaChooseVertexState( GLcontext
*ctx
)
311 gammaContextPtr gmesa
= GAMMA_CONTEXT( ctx
);
312 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
313 GLuint ind
= GAMMA_XYZW_BIT
|GAMMA_RGBA_BIT
;
315 if (ctx
->_TriangleCaps
& DD_SEPARATE_SPECULAR
)
316 ind
|= GAMMA_SPEC_BIT
;
318 if (ctx
->Fog
.Enabled
)
319 ind
|= GAMMA_FOG_BIT
;
321 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
) {
322 _tnl_need_projected_coords( ctx
, GL_FALSE
);
323 ind
|= GAMMA_TEX0_BIT
;
325 _tnl_need_projected_coords( ctx
, GL_FALSE
);
327 gmesa
->SetupIndex
= ind
;
329 if (setup_tab
[ind
].vertex_format
!= gmesa
->vertex_format
) {
330 gmesa
->vertex_format
= setup_tab
[ind
].vertex_format
;
331 gmesa
->vertex_size
= setup_tab
[ind
].vertex_size
;
332 gmesa
->vertex_stride_shift
= setup_tab
[ind
].vertex_stride_shift
;
335 if (ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
)) {
336 tnl
->Driver
.Render
.Interp
= gamma_interp_extras
;
337 tnl
->Driver
.Render
.CopyPV
= gamma_copy_pv_extras
;
339 tnl
->Driver
.Render
.Interp
= setup_tab
[ind
].interp
;
340 tnl
->Driver
.Render
.CopyPV
= setup_tab
[ind
].copy_pv
;
345 void gammaInitVB( GLcontext
*ctx
)
347 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
348 GLuint size
= TNL_CONTEXT(ctx
)->vb
.Size
;
350 gmesa
->verts
= (GLubyte
*)ALIGN_MALLOC(size
* 4 * 16, 32);
353 static int firsttime
= 1;
357 gmesa
->vertex_stride_shift
= 6; /* FIXME - only one vertex setup */
363 void gammaFreeVB( GLcontext
*ctx
)
365 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
367 ALIGN_FREE(gmesa
->verts
);
371 if (gmesa
->UbyteSecondaryColor
.Ptr
) {
372 ALIGN_FREE(gmesa
->UbyteSecondaryColor
.Ptr
);
373 gmesa
->UbyteSecondaryColor
.Ptr
= 0;
376 if (gmesa
->UbyteColor
.Ptr
) {
377 ALIGN_FREE(gmesa
->UbyteColor
.Ptr
);
378 gmesa
->UbyteColor
.Ptr
= 0;