Rename the various function types in t_context.h to include a tnl_ prefix.
[mesa.git] / src / mesa / drivers / dri / gamma / gamma_vb.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/gamma/gamma_vb.c,v 1.4 2003/03/26 20:43:48 tsi Exp $ */
2 /*
3 * Copyright 2001 by Alan Hourihane.
4 *
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.
14 *
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.
22 *
23 * Authors: Alan Hourihane, <alanh@tungstengraphics.com>
24 * Keith Whitwell, <keith@tungstengraphics.com>
25 *
26 * 3DLabs Gamma driver.
27 */
28
29 #include "glheader.h"
30 #include "mtypes.h"
31 #include "imports.h"
32 #include "macros.h"
33 #include "colormac.h"
34
35 #include "swrast_setup/swrast_setup.h"
36 #include "tnl/t_context.h"
37 #include "tnl/tnl.h"
38
39 #include "gamma_context.h"
40 #include "gamma_vb.h"
41 #include "gamma_tris.h"
42
43
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
51
52 static struct {
53 void (*emit)( GLcontext *, GLuint, GLuint, void *, GLuint );
54 tnl_interp_func interp;
55 tnl_copy_pv_func copy_pv;
56 GLboolean (*check_tex_sizes)( GLcontext *ctx );
57 GLuint vertex_size;
58 GLuint vertex_format;
59 } setup_tab[GAMMA_MAX_SETUP];
60
61 #define TINY_VERTEX_FORMAT 1
62 #define NOTEX_VERTEX_FORMAT 2
63 #define TEX0_VERTEX_FORMAT 3
64 #define TEX1_VERTEX_FORMAT 0
65 #define PROJ_TEX1_VERTEX_FORMAT 0
66 #define TEX2_VERTEX_FORMAT 0
67 #define TEX3_VERTEX_FORMAT 0
68 #define PROJ_TEX3_VERTEX_FORMAT 0
69
70 #define DO_XYZW (IND & GAMMA_XYZW_BIT)
71 #define DO_RGBA (IND & GAMMA_RGBA_BIT)
72 #define DO_SPEC (IND & GAMMA_SPEC_BIT)
73 #define DO_FOG (IND & GAMMA_FOG_BIT)
74 #define DO_TEX0 (IND & GAMMA_TEX0_BIT)
75 #define DO_TEX1 0
76 #define DO_TEX2 0
77 #define DO_TEX3 0
78 #define DO_PTEX (IND & GAMMA_PTEX_BIT)
79
80 #define VERTEX gammaVertex
81 #define VERTEX_COLOR gamma_color_t
82 #define GET_VIEWPORT_MAT() 0
83 #define GET_TEXSOURCE(n) n
84 #define GET_VERTEX_FORMAT() GAMMA_CONTEXT(ctx)->vertex_format
85 #define GET_VERTEX_STORE() GAMMA_CONTEXT(ctx)->verts
86 #define GET_VERTEX_SIZE() GAMMA_CONTEXT(ctx)->vertex_size * sizeof(GLuint)
87 #define INVALIDATE_STORED_VERTICES()
88
89 #define HAVE_HW_VIEWPORT 1
90 #define HAVE_HW_DIVIDE 1
91 #define HAVE_RGBA_COLOR 0 /* we're BGRA */
92 #define HAVE_TINY_VERTICES 1
93 #define HAVE_NOTEX_VERTICES 1
94 #define HAVE_TEX0_VERTICES 1
95 #define HAVE_TEX1_VERTICES 0
96 #define HAVE_TEX2_VERTICES 0
97 #define HAVE_TEX3_VERTICES 0
98 #define HAVE_PTEX_VERTICES 1
99
100 #define PTEX_FALLBACK() /* never needed */
101
102 #define INTERP_VERTEX setup_tab[GAMMA_CONTEXT(ctx)->SetupIndex].interp
103 #define COPY_PV_VERTEX setup_tab[GAMMA_CONTEXT(ctx)->SetupIndex].copy_pv
104
105
106
107 /***********************************************************************
108 * Generate pv-copying and translation functions *
109 ***********************************************************************/
110
111 #define TAG(x) gamma_##x
112 #include "tnl_dd/t_dd_vb.c"
113
114 /***********************************************************************
115 * Generate vertex emit and interp functions *
116 ***********************************************************************/
117
118 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT)
119 #define TAG(x) x##_wg
120 #include "tnl_dd/t_dd_vbtmp.h"
121
122 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_SPEC_BIT)
123 #define TAG(x) x##_wgs
124 #include "tnl_dd/t_dd_vbtmp.h"
125
126 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_TEX0_BIT)
127 #define TAG(x) x##_wgt0
128 #include "tnl_dd/t_dd_vbtmp.h"
129
130 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_TEX0_BIT|GAMMA_PTEX_BIT)
131 #define TAG(x) x##_wgpt0
132 #include "tnl_dd/t_dd_vbtmp.h"
133
134 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_SPEC_BIT|GAMMA_TEX0_BIT)
135 #define TAG(x) x##_wgst0
136 #include "tnl_dd/t_dd_vbtmp.h"
137
138 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_SPEC_BIT|GAMMA_TEX0_BIT|\
139 GAMMA_PTEX_BIT)
140 #define TAG(x) x##_wgspt0
141 #include "tnl_dd/t_dd_vbtmp.h"
142
143 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_FOG_BIT)
144 #define TAG(x) x##_wgf
145 #include "tnl_dd/t_dd_vbtmp.h"
146
147 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_FOG_BIT|GAMMA_SPEC_BIT)
148 #define TAG(x) x##_wgfs
149 #include "tnl_dd/t_dd_vbtmp.h"
150
151 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_FOG_BIT|GAMMA_TEX0_BIT)
152 #define TAG(x) x##_wgft0
153 #include "tnl_dd/t_dd_vbtmp.h"
154
155 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_FOG_BIT|GAMMA_TEX0_BIT|\
156 GAMMA_PTEX_BIT)
157 #define TAG(x) x##_wgfpt0
158 #include "tnl_dd/t_dd_vbtmp.h"
159
160 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_FOG_BIT|GAMMA_SPEC_BIT|\
161 GAMMA_TEX0_BIT)
162 #define TAG(x) x##_wgfst0
163 #include "tnl_dd/t_dd_vbtmp.h"
164
165 #define IND (GAMMA_XYZW_BIT|GAMMA_RGBA_BIT|GAMMA_FOG_BIT|GAMMA_SPEC_BIT|\
166 GAMMA_TEX0_BIT|GAMMA_PTEX_BIT)
167 #define TAG(x) x##_wgfspt0
168 #include "tnl_dd/t_dd_vbtmp.h"
169
170 #define IND (GAMMA_TEX0_BIT)
171 #define TAG(x) x##_t0
172 #include "tnl_dd/t_dd_vbtmp.h"
173
174 #define IND (GAMMA_FOG_BIT)
175 #define TAG(x) x##_f
176 #include "tnl_dd/t_dd_vbtmp.h"
177
178 #define IND (GAMMA_FOG_BIT|GAMMA_TEX0_BIT)
179 #define TAG(x) x##_ft0
180 #include "tnl_dd/t_dd_vbtmp.h"
181
182 #define IND (GAMMA_RGBA_BIT)
183 #define TAG(x) x##_g
184 #include "tnl_dd/t_dd_vbtmp.h"
185
186 #define IND (GAMMA_RGBA_BIT|GAMMA_SPEC_BIT)
187 #define TAG(x) x##_gs
188 #include "tnl_dd/t_dd_vbtmp.h"
189
190 #define IND (GAMMA_RGBA_BIT|GAMMA_TEX0_BIT)
191 #define TAG(x) x##_gt0
192 #include "tnl_dd/t_dd_vbtmp.h"
193
194 #define IND (GAMMA_RGBA_BIT|GAMMA_SPEC_BIT|GAMMA_TEX0_BIT)
195 #define TAG(x) x##_gst0
196 #include "tnl_dd/t_dd_vbtmp.h"
197
198 #define IND (GAMMA_RGBA_BIT|GAMMA_FOG_BIT)
199 #define TAG(x) x##_gf
200 #include "tnl_dd/t_dd_vbtmp.h"
201
202 #define IND (GAMMA_RGBA_BIT|GAMMA_FOG_BIT|GAMMA_SPEC_BIT)
203 #define TAG(x) x##_gfs
204 #include "tnl_dd/t_dd_vbtmp.h"
205
206 #define IND (GAMMA_RGBA_BIT|GAMMA_FOG_BIT|GAMMA_TEX0_BIT)
207 #define TAG(x) x##_gft0
208 #include "tnl_dd/t_dd_vbtmp.h"
209
210 #define IND (GAMMA_RGBA_BIT|GAMMA_FOG_BIT|GAMMA_SPEC_BIT|GAMMA_TEX0_BIT)
211 #define TAG(x) x##_gfst0
212 #include "tnl_dd/t_dd_vbtmp.h"
213
214 static void init_setup_tab( void )
215 {
216 init_wg();
217 init_wgs();
218 init_wgt0();
219 init_wgpt0();
220 init_wgst0();
221 init_wgspt0();
222 init_wgf();
223 init_wgfs();
224 init_wgft0();
225 init_wgfpt0();
226 init_wgfst0();
227 init_wgfspt0();
228 init_t0();
229 init_f();
230 init_ft0();
231 init_g();
232 init_gs();
233 init_gt0();
234 init_gst0();
235 init_gf();
236 init_gfs();
237 init_gft0();
238 init_gfst0();
239 }
240
241 void gammaCheckTexSizes( GLcontext *ctx )
242 {
243 TNLcontext *tnl = TNL_CONTEXT(ctx);
244 gammaContextPtr gmesa = GAMMA_CONTEXT( ctx );
245
246 if (!setup_tab[gmesa->SetupIndex].check_tex_sizes(ctx)) {
247 /* Invalidate stored verts
248 */
249 gmesa->SetupNewInputs = ~0;
250 gmesa->SetupIndex |= GAMMA_PTEX_BIT;
251
252 if (!(ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
253 tnl->Driver.Render.Interp = setup_tab[gmesa->SetupIndex].interp;
254 tnl->Driver.Render.CopyPV = setup_tab[gmesa->SetupIndex].copy_pv;
255 }
256 }
257 }
258
259 void gammaBuildVertices( GLcontext *ctx,
260 GLuint start,
261 GLuint count,
262 GLuint newinputs )
263 {
264 gammaContextPtr gmesa = GAMMA_CONTEXT( ctx );
265 GLuint stride = gmesa->vertex_size * sizeof(int);
266 GLubyte *v = ((GLubyte *)gmesa->verts + (start * stride));
267
268 newinputs |= gmesa->SetupNewInputs;
269 gmesa->SetupNewInputs = 0;
270
271 if (!newinputs)
272 return;
273
274 if (newinputs & VERT_BIT_POS) {
275 setup_tab[gmesa->SetupIndex].emit( ctx, start, count, v, stride );
276 } else {
277 GLuint ind = 0;
278
279 if (newinputs & VERT_BIT_COLOR0)
280 ind |= GAMMA_RGBA_BIT;
281
282 if (newinputs & VERT_BIT_COLOR1)
283 ind |= GAMMA_SPEC_BIT;
284
285 if (newinputs & VERT_BIT_TEX0)
286 ind |= GAMMA_TEX0_BIT;
287
288 if (newinputs & VERT_BIT_FOG)
289 ind |= GAMMA_FOG_BIT;
290
291 if (gmesa->SetupIndex & GAMMA_PTEX_BIT)
292 ind = ~0;
293
294 ind &= gmesa->SetupIndex;
295
296 if (ind) {
297 setup_tab[ind].emit( ctx, start, count, v, stride );
298 }
299 }
300 }
301
302 void gammaChooseVertexState( GLcontext *ctx )
303 {
304 gammaContextPtr gmesa = GAMMA_CONTEXT( ctx );
305 TNLcontext *tnl = TNL_CONTEXT(ctx);
306 GLuint ind = GAMMA_XYZW_BIT|GAMMA_RGBA_BIT;
307
308 if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)
309 ind |= GAMMA_SPEC_BIT;
310
311 if (ctx->Fog.Enabled)
312 ind |= GAMMA_FOG_BIT;
313
314 if (ctx->Texture.Unit[0]._ReallyEnabled) {
315 _tnl_need_projected_coords( ctx, GL_FALSE );
316 ind |= GAMMA_TEX0_BIT;
317 } else
318 _tnl_need_projected_coords( ctx, GL_FALSE );
319
320 gmesa->SetupIndex = ind;
321
322 if (setup_tab[ind].vertex_format != gmesa->vertex_format) {
323 gmesa->vertex_format = setup_tab[ind].vertex_format;
324 gmesa->vertex_size = setup_tab[ind].vertex_size;
325 }
326
327 if (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED)) {
328 tnl->Driver.Render.Interp = gamma_interp_extras;
329 tnl->Driver.Render.CopyPV = gamma_copy_pv_extras;
330 } else {
331 tnl->Driver.Render.Interp = setup_tab[ind].interp;
332 tnl->Driver.Render.CopyPV = setup_tab[ind].copy_pv;
333 }
334 }
335
336
337 void gammaInitVB( GLcontext *ctx )
338 {
339 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
340 GLuint size = TNL_CONTEXT(ctx)->vb.Size;
341
342 gmesa->verts = (GLubyte *)ALIGN_MALLOC(size * 4 * 16, 32);
343
344 {
345 static int firsttime = 1;
346 if (firsttime) {
347 init_setup_tab();
348 firsttime = 0;
349 gmesa->vertex_size = 16; /* FIXME - only one vertex setup */
350 }
351 }
352 }
353
354
355 void gammaFreeVB( GLcontext *ctx )
356 {
357 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
358 if (gmesa->verts) {
359 ALIGN_FREE(gmesa->verts);
360 gmesa->verts = 0;
361 }
362 }