Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / drivers / dri / tdfx / tdfx_context.c
1 /* -*- mode: c; c-basic-offset: 3 -*-
2  *
3  * Copyright 2000 VA Linux Systems Inc., Fremont, California.
4  *
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the next
15  * paragraph) shall be included in all copies or substantial portions of the
16  * Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21  * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26
27 /**
28  * \file tdfx_context.c
29  * Context management functions for 3Dfx hardware.
30  *
31  * \author Gareth Hughes <gareth@valinux.com> (original rewrite 29 Sep - 1 Oct 2000)
32  * \author Brian Paul <brianp@valinux.com>
33  * \author Daniel Borca <dborca@users.sourceforge.net> (new fixes 19 Jul 2004)
34  */
35
36 #include <dlfcn.h>
37 #include "tdfx_context.h"
38 #include "tdfx_dd.h"
39 #include "tdfx_state.h"
40 #include "tdfx_vb.h"
41 #include "tdfx_tex.h"
42 #include "tdfx_tris.h"
43 #include "tdfx_render.h"
44 #include "tdfx_span.h"
45 #include "tdfx_texman.h"
46 #include "main/extensions.h"
47 #include "main/hash.h"
48 #include "main/texobj.h"
49
50 #include "swrast/swrast.h"
51 #include "swrast_setup/swrast_setup.h"
52 #include "vbo/vbo.h"
53
54 #include "tnl/tnl.h"
55 #include "tnl/t_pipeline.h"
56
57 #include "drivers/common/driverfuncs.h"
58
59 #include "utils.h"
60
61 /* #define need_GL_ARB_point_parameters */
62 #define need_GL_ARB_occlusion_query
63 /* #define need_GL_ARB_vertex_program */
64 #define need_GL_EXT_blend_equation_separate
65 #define need_GL_EXT_blend_func_separate
66 #define need_GL_EXT_blend_minmax
67 #define need_GL_EXT_fog_coord
68 #define need_GL_EXT_paletted_texture
69 /* #define need_GL_EXT_secondary_color */
70 /* #define need_GL_NV_vertex_program */
71 #include "main/remap_helper.h"
72
73
74 /**
75  * Common extension strings exported by all cards
76  */
77 static const struct dri_extension card_extensions[] =
78 {
79     { "GL_ARB_occlusion_query",            GL_ARB_occlusion_query_functions },
80     { "GL_ARB_texture_mirrored_repeat",    NULL },
81
82     { "GL_EXT_blend_func_separate",        GL_EXT_blend_func_separate_functions },
83     { "GL_EXT_fog_coord",                  GL_EXT_fog_coord_functions },
84     { "GL_EXT_paletted_texture",           GL_EXT_paletted_texture_functions },
85     { "GL_EXT_shared_texture_palette",     NULL },
86     { "GL_EXT_stencil_wrap",               NULL },
87     { "GL_EXT_texture_env_add",            NULL },
88     { "GL_EXT_texture_lod_bias",           NULL },
89
90 #ifdef need_GL_ARB_point_parameters
91     { "GL_ARB_point_parameters",           GL_ARB_point_parameters_functions },
92     { "GL_ARB_point_sprite",               NULL },
93 #endif
94 #ifdef need_GL_EXT_secondary_color
95     { "GL_EXT_secondary_color",            GL_EXT_secondary_color_functions },
96 #endif
97 #ifdef need_GL_ARB_vertex_program
98     { "GL_ARB_vertex_program",             GL_ARB_vertex_program_functions }
99 #endif
100 #ifdef need_GL_NV_vertex_program
101     { "GL_NV_vertex_program",              GL_NV_vertex_program_functions }
102     { "GL_NV_vertex_program1_1",           NULL },
103 #endif
104     { NULL,                                NULL }
105 };
106
107 /**
108  * Extension strings exported only by Naplam (e.g., Voodoo4 & Voodoo5) cards.
109  */
110 static const struct dri_extension napalm_extensions[] =
111 {
112     { "GL_ARB_texture_env_combine",        NULL },
113     { "GL_EXT_blend_equation_separate",    GL_EXT_blend_equation_separate_functions },
114     { "GL_EXT_blend_subtract",             GL_EXT_blend_minmax_functions },
115     { "GL_EXT_texture_compression_s3tc",   NULL },
116     { "GL_EXT_texture_env_combine",        NULL },
117
118     { "GL_3DFX_texture_compression_FXT1",  NULL },
119     { "GL_NV_blend_square",                NULL },
120     { "GL_S3_s3tc",                        NULL },
121     { NULL,                                NULL }
122 };
123
124 /*
125  * Enable/Disable the extensions for this context.
126  */
127 static void tdfxDDInitExtensions( struct gl_context *ctx )
128 {
129    tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
130
131    driInitExtensions( ctx, card_extensions, GL_FALSE );
132
133    if ( fxMesa->haveTwoTMUs ) {
134       _mesa_enable_extension( ctx, "GL_ARB_multitexture" );
135    }
136
137    if ( TDFX_IS_NAPALM( fxMesa ) ) {
138       driInitExtensions( ctx, napalm_extensions, GL_FALSE );
139    }
140 }
141
142
143
144 static const struct tnl_pipeline_stage *tdfx_pipeline[] = {
145    &_tnl_vertex_transform_stage, 
146    &_tnl_normal_transform_stage, 
147    &_tnl_lighting_stage,
148    &_tnl_fog_coordinate_stage, 
149    &_tnl_texgen_stage, 
150    &_tnl_texture_transform_stage, 
151    &_tnl_point_attenuation_stage,
152    &_tnl_render_stage,          
153    0,
154 };
155
156 static const struct dri_debug_control debug_control[] =
157 {
158     { "dri",   DEBUG_VERBOSE_DRI },
159     { "sync",  DEBUG_ALWAYS_SYNC },
160     { "api",   DEBUG_VERBOSE_API },
161     { "fall",  DEBUG_VERBOSE_FALL },
162     { NULL,    0 }
163 };
164
165 GLboolean tdfxCreateContext( gl_api api,
166                              const struct gl_config *mesaVis,
167                              __DRIcontext *driContextPriv,
168                              void *sharedContextPrivate )
169 {
170    tdfxContextPtr fxMesa;
171    struct gl_context *ctx, *shareCtx;
172    __DRIscreen *sPriv = driContextPriv->driScreenPriv;
173    tdfxScreenPrivate *fxScreen = (tdfxScreenPrivate *) sPriv->private;
174    TDFXSAREAPriv *saPriv = (TDFXSAREAPriv *) ((char *) sPriv->pSAREA +
175                                               sizeof(drm_sarea_t));
176    struct dd_function_table functions;
177
178    /* Allocate tdfx context */
179    fxMesa = (tdfxContextPtr) CALLOC( sizeof(tdfxContextRec) );
180    if (!fxMesa)
181       return GL_FALSE;
182
183    /* Init default driver functions then plug in our tdfx-specific functions
184     * (the texture functions are especially important)
185     */
186    _mesa_init_driver_functions(&functions);
187    tdfxDDInitDriverFuncs(mesaVis, &functions);
188    tdfxInitTextureFuncs(&functions);
189    tdfxInitRenderFuncs(&functions);
190
191    /* Allocate the Mesa context */
192    if (sharedContextPrivate)
193       shareCtx = ((tdfxContextPtr) sharedContextPrivate)->glCtx;
194    else 
195       shareCtx = NULL;
196
197    fxMesa->glCtx = _mesa_create_context(api, mesaVis, shareCtx,
198                                         &functions, (void *) fxMesa);
199    if (!fxMesa->glCtx) {
200       FREE(fxMesa);
201       return GL_FALSE;
202    }
203    driContextPriv->driverPrivate = fxMesa;
204
205    /* Mirror some important DRI state
206     */
207    fxMesa->hHWContext = driContextPriv->hHWContext;
208    fxMesa->driHwLock = &sPriv->pSAREA->lock;
209    fxMesa->driFd = sPriv->fd;
210
211    fxMesa->driScreen = sPriv;
212    fxMesa->driContext = driContextPriv;
213    fxMesa->fxScreen = fxScreen;
214    fxMesa->sarea = saPriv;
215
216    /*JJJ - really?*/
217    fxMesa->haveHwAlpha = ( mesaVis->alphaBits &&
218                            ((mesaVis->greenBits == 8) ||
219                             (mesaVis->depthBits == 0)) );
220    fxMesa->haveHwStencil = ( TDFX_IS_NAPALM( fxMesa ) &&
221                              mesaVis->stencilBits &&
222                              mesaVis->depthBits == 24 );
223
224    fxMesa->screen_width = fxScreen->width;
225    fxMesa->screen_height = fxScreen->height;
226
227    fxMesa->new_gl_state = ~0;
228    fxMesa->new_state = ~0;
229    fxMesa->dirty = ~0;
230
231    /* Parse configuration files */
232    driParseConfigFiles (&fxMesa->optionCache, &fxScreen->optionCache,
233                         fxMesa->driScreen->myNum, "tdfx");
234
235    /* NOTE: This must be here before any Glide calls! */
236    if (!tdfxInitGlide( fxMesa )) {
237       FREE(fxMesa);
238       return GL_FALSE;
239    }
240
241    fxMesa->Glide.grDRIOpen( (char*) sPriv->pFB, fxScreen->regs.map, fxScreen->deviceID,
242               fxScreen->width, fxScreen->height, fxScreen->mem, fxScreen->cpp,
243               fxScreen->stride, fxScreen->fifoOffset, fxScreen->fifoSize,
244               fxScreen->fbOffset, fxScreen->backOffset, fxScreen->depthOffset,
245               fxScreen->textureOffset, fxScreen->textureSize, &saPriv->fifoPtr,
246               &saPriv->fifoRead );
247
248    if ( getenv( "FX_GLIDE_SWAPINTERVAL" ) ) {
249       fxMesa->Glide.SwapInterval = atoi( getenv( "FX_GLIDE_SWAPINTERVAL" ) );
250    } else {
251       fxMesa->Glide.SwapInterval = 0;
252    }
253    if ( getenv( "FX_MAX_PENDING_SWAPS" ) ) {
254       fxMesa->Glide.MaxPendingSwaps = atoi( getenv( "FX_MAX_PENDING_SWAPS" ) );
255    } else {
256       fxMesa->Glide.MaxPendingSwaps = 2;
257    }
258
259    fxMesa->Glide.Initialized = GL_FALSE;
260    fxMesa->Glide.Board = 0;
261
262
263    if (getenv("FX_EMULATE_SINGLE_TMU")) {
264       fxMesa->haveTwoTMUs = GL_FALSE;
265    }
266    else {
267       if ( TDFX_IS_BANSHEE( fxMesa ) ) {
268          fxMesa->haveTwoTMUs = GL_FALSE;
269       } else {
270          fxMesa->haveTwoTMUs = GL_TRUE;
271       }
272    }
273
274    fxMesa->stats.swapBuffer = 0;
275    fxMesa->stats.reqTexUpload = 0;
276    fxMesa->stats.texUpload = 0;
277    fxMesa->stats.memTexUpload = 0;
278
279    fxMesa->tmuSrc = TDFX_TMU_NONE;
280
281    ctx = fxMesa->glCtx;
282    if ( TDFX_IS_NAPALM( fxMesa ) ) {
283       ctx->Const.MaxTextureLevels = 12;
284    } else {
285       ctx->Const.MaxTextureLevels = 9;
286    }
287    ctx->Const.MaxTextureUnits = TDFX_IS_BANSHEE( fxMesa ) ? 1 : 2;
288    ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits;
289    ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits;
290
291    /* No wide points.
292     */
293    ctx->Const.MinPointSize = 1.0;
294    ctx->Const.MinPointSizeAA = 1.0;
295    ctx->Const.MaxPointSize = 1.0;
296    ctx->Const.MaxPointSizeAA = 1.0;
297
298    /* Disable wide lines as we can't antialias them correctly in
299     * hardware.
300     */
301    ctx->Const.MinLineWidth = 1.0;
302    ctx->Const.MinLineWidthAA = 1.0;
303    ctx->Const.MaxLineWidth = 1.0;
304    ctx->Const.MaxLineWidthAA = 1.0;
305    ctx->Const.LineWidthGranularity = 1.0;
306
307    ctx->Const.MaxDrawBuffers = 1;
308
309    /* Initialize the software rasterizer and helper modules.
310     */
311    _swrast_CreateContext( ctx );
312    _vbo_CreateContext( ctx );
313    _tnl_CreateContext( ctx );
314    _swsetup_CreateContext( ctx );
315
316    /* Install the customized pipeline:
317     */
318    _tnl_destroy_pipeline( ctx );
319    _tnl_install_pipeline( ctx, tdfx_pipeline );
320
321    /* Configure swrast and T&L to match hardware characteristics:
322     */
323    _swrast_allow_pixel_fog( ctx, GL_TRUE );
324    _swrast_allow_vertex_fog( ctx, GL_FALSE );
325    _tnl_allow_pixel_fog( ctx, GL_TRUE );
326    _tnl_allow_vertex_fog( ctx, GL_FALSE );
327
328    tdfxDDInitExtensions( ctx );
329    /* XXX these should really go right after _mesa_init_driver_functions() */
330    tdfxDDInitSpanFuncs( ctx ); 
331    tdfxDDInitStateFuncs( ctx );
332    tdfxDDInitTriFuncs( ctx );
333    tdfxInitVB( ctx );
334    tdfxInitState( fxMesa );
335
336 #if DO_DEBUG
337    TDFX_DEBUG = driParseDebugString( getenv( "TDFX_DEBUG" ), debug_control );
338 #endif
339
340    if (driQueryOptionb(&fxMesa->optionCache, "no_rast")) {
341       fprintf(stderr, "disabling 3D acceleration\n");
342       FALLBACK(fxMesa, TDFX_FALLBACK_DISABLE, 1);
343    }
344
345    return GL_TRUE;
346 }
347
348
349 static GLboolean tdfxInitVertexFormats( tdfxContextPtr fxMesa )
350 {
351    FxI32 result;
352    int i;
353
354    LOCK_HARDWARE( fxMesa );
355
356    fxMesa->Glide.grGet( GR_GLIDE_VERTEXLAYOUT_SIZE, sizeof(FxI32), &result );
357    for ( i = 0 ; i < TDFX_NUM_LAYOUTS ; i++ ) {
358       fxMesa->layout[i] = MALLOC( result );
359       if ( !fxMesa->layout[i] ) {
360          UNLOCK_HARDWARE( fxMesa );
361          return GL_FALSE;
362       }
363    }
364
365    /* Tiny vertex format - 16 bytes.
366     */
367    fxMesa->Glide.grReset( GR_VERTEX_PARAMETER );
368    fxMesa->Glide.grCoordinateSpace( GR_WINDOW_COORDS );
369    fxMesa->Glide.grVertexLayout( GR_PARAM_XY,   TDFX_XY_OFFSET, GR_PARAM_ENABLE );
370    fxMesa->Glide.grVertexLayout( GR_PARAM_Z, TDFX_Z_OFFSET, GR_PARAM_ENABLE );
371    fxMesa->Glide.grVertexLayout( GR_PARAM_PARGB, TDFX_ARGB_OFFSET, GR_PARAM_ENABLE );
372    fxMesa->Glide.grGlideGetVertexLayout( fxMesa->layout[TDFX_LAYOUT_TINY] );
373
374    /* Non textured vertex format - 24 bytes (Need w for table fog)
375     */
376    fxMesa->Glide.grReset( GR_VERTEX_PARAMETER );
377    fxMesa->Glide.grCoordinateSpace( GR_WINDOW_COORDS );
378    fxMesa->Glide.grVertexLayout( GR_PARAM_XY,   TDFX_XY_OFFSET, GR_PARAM_ENABLE );
379    fxMesa->Glide.grVertexLayout( GR_PARAM_Z, TDFX_Z_OFFSET, GR_PARAM_ENABLE );
380    fxMesa->Glide.grVertexLayout( GR_PARAM_Q, TDFX_Q_OFFSET, GR_PARAM_ENABLE );
381    fxMesa->Glide.grVertexLayout( GR_PARAM_PARGB, TDFX_ARGB_OFFSET, GR_PARAM_ENABLE );
382    fxMesa->Glide.grGlideGetVertexLayout( fxMesa->layout[TDFX_LAYOUT_NOTEX] );
383
384    /* Single textured vertex format - 32 bytes.
385     */
386    fxMesa->Glide.grReset( GR_VERTEX_PARAMETER );
387    fxMesa->Glide.grCoordinateSpace( GR_WINDOW_COORDS );
388    fxMesa->Glide.grVertexLayout( GR_PARAM_XY,   TDFX_XY_OFFSET, GR_PARAM_ENABLE );
389    fxMesa->Glide.grVertexLayout( GR_PARAM_Z, TDFX_Z_OFFSET, GR_PARAM_ENABLE );
390    fxMesa->Glide.grVertexLayout( GR_PARAM_Q, TDFX_Q_OFFSET, GR_PARAM_ENABLE );
391    fxMesa->Glide.grVertexLayout( GR_PARAM_PARGB, TDFX_ARGB_OFFSET, GR_PARAM_ENABLE );
392    fxMesa->Glide.grVertexLayout( GR_PARAM_ST0, TDFX_ST0_OFFSET, GR_PARAM_ENABLE );
393    fxMesa->Glide.grGlideGetVertexLayout( fxMesa->layout[TDFX_LAYOUT_SINGLE] );
394
395    /* Multitextured vertex format - 40 bytes.
396     */
397    fxMesa->Glide.grReset( GR_VERTEX_PARAMETER );
398    fxMesa->Glide.grCoordinateSpace( GR_WINDOW_COORDS );
399    fxMesa->Glide.grVertexLayout( GR_PARAM_XY, TDFX_XY_OFFSET, GR_PARAM_ENABLE );
400    fxMesa->Glide.grVertexLayout( GR_PARAM_Z, TDFX_Z_OFFSET, GR_PARAM_ENABLE );
401    fxMesa->Glide.grVertexLayout( GR_PARAM_Q, TDFX_Q_OFFSET, GR_PARAM_ENABLE );
402    fxMesa->Glide.grVertexLayout( GR_PARAM_PARGB, TDFX_ARGB_OFFSET, GR_PARAM_ENABLE );
403    fxMesa->Glide.grVertexLayout( GR_PARAM_ST0, TDFX_ST0_OFFSET, GR_PARAM_ENABLE );
404    fxMesa->Glide.grVertexLayout( GR_PARAM_ST1, TDFX_ST1_OFFSET, GR_PARAM_ENABLE );
405    fxMesa->Glide.grGlideGetVertexLayout( fxMesa->layout[TDFX_LAYOUT_MULTI] );
406
407    /* Projected texture vertex format - 36 bytes.
408     */
409    fxMesa->Glide.grReset( GR_VERTEX_PARAMETER );
410    fxMesa->Glide.grCoordinateSpace( GR_WINDOW_COORDS );
411    fxMesa->Glide.grVertexLayout( GR_PARAM_XY, TDFX_XY_OFFSET, GR_PARAM_ENABLE );
412    fxMesa->Glide.grVertexLayout( GR_PARAM_Z, TDFX_Z_OFFSET, GR_PARAM_ENABLE );
413    fxMesa->Glide.grVertexLayout( GR_PARAM_Q, TDFX_Q_OFFSET, GR_PARAM_ENABLE );
414    fxMesa->Glide.grVertexLayout( GR_PARAM_PARGB, TDFX_ARGB_OFFSET, GR_PARAM_ENABLE );
415    fxMesa->Glide.grVertexLayout( GR_PARAM_ST0, TDFX_ST0_OFFSET, GR_PARAM_ENABLE );
416    fxMesa->Glide.grVertexLayout( GR_PARAM_Q0, TDFX_Q0_OFFSET, GR_PARAM_ENABLE );
417    fxMesa->Glide.grGlideGetVertexLayout( fxMesa->layout[TDFX_LAYOUT_PROJ1] );
418
419    /* Projected multitexture vertex format - 48 bytes.
420     */
421    fxMesa->Glide.grReset( GR_VERTEX_PARAMETER );
422    fxMesa->Glide.grCoordinateSpace( GR_WINDOW_COORDS );
423    fxMesa->Glide.grVertexLayout( GR_PARAM_XY, TDFX_XY_OFFSET, GR_PARAM_ENABLE );
424    fxMesa->Glide.grVertexLayout( GR_PARAM_Z, TDFX_Z_OFFSET, GR_PARAM_ENABLE );
425    fxMesa->Glide.grVertexLayout( GR_PARAM_Q, TDFX_Q_OFFSET, GR_PARAM_ENABLE );
426    fxMesa->Glide.grVertexLayout( GR_PARAM_PARGB, TDFX_ARGB_OFFSET, GR_PARAM_ENABLE );
427    fxMesa->Glide.grVertexLayout( GR_PARAM_ST0, TDFX_ST0_OFFSET, GR_PARAM_ENABLE );
428    fxMesa->Glide.grVertexLayout( GR_PARAM_Q0, TDFX_Q0_OFFSET, GR_PARAM_ENABLE );
429    fxMesa->Glide.grVertexLayout( GR_PARAM_ST1, TDFX_ST1_OFFSET, GR_PARAM_ENABLE );
430    fxMesa->Glide.grVertexLayout( GR_PARAM_Q1, TDFX_Q1_OFFSET, GR_PARAM_ENABLE );
431    fxMesa->Glide.grGlideGetVertexLayout( fxMesa->layout[TDFX_LAYOUT_PROJ2] );
432
433    UNLOCK_HARDWARE( fxMesa );
434
435    return GL_TRUE;
436 }
437
438
439 /*
440  * Initialize the state in an tdfxContextPtr struct.
441  */
442 static GLboolean
443 tdfxInitContext( __DRIdrawable *driDrawPriv, tdfxContextPtr fxMesa )
444 {
445    /* KW: Would be nice to make one of these a member of the other.
446     */
447    FxI32 result[2];
448    const char *gext;
449
450    if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) {
451       fprintf( stderr, "%s( %p )\n", __FUNCTION__, (void *)fxMesa );
452    }
453
454 #if DEBUG_LOCKING
455    fprintf(stderr, "Debug locking enabled\n");
456 #endif
457
458    if ( fxMesa->Glide.Initialized )
459       return GL_TRUE;
460
461    fxMesa->width = driDrawPriv->w;
462    fxMesa->height = driDrawPriv->h;
463
464    /* We have to use a light lock here, because we can't do any glide
465     * operations yet. No use of FX_* functions in this function.
466     */
467    DRM_LIGHT_LOCK( fxMesa->driFd, fxMesa->driHwLock, fxMesa->hHWContext );
468
469    fxMesa->Glide.grGlideInit();
470    fxMesa->Glide.grSstSelect( fxMesa->Glide.Board );
471
472    fxMesa->Glide.Context = fxMesa->Glide.grSstWinOpen( (FxU32) -1,
473                                          GR_RESOLUTION_NONE,
474                                          GR_REFRESH_NONE,
475                                          fxMesa->Glide.ColorFormat,
476                                          fxMesa->Glide.Origin,
477                                          2, 1 );
478
479    fxMesa->Glide.grDRIResetSAREA();
480
481    DRM_UNLOCK( fxMesa->driFd, fxMesa->driHwLock, fxMesa->hHWContext );
482
483    if ( !fxMesa->Glide.Context )
484       return GL_FALSE;
485
486
487    /* Perform the Glide-dependant part of the context initialization.
488     */
489    FX_grColorMaskv( fxMesa->glCtx, true4 );
490
491    tdfxTMInit( fxMesa );
492
493    LOCK_HARDWARE( fxMesa );
494
495    /* JJJ - COMMAND_TRANSPORT, PALETTE6666 */
496    gext = fxMesa->Glide.grGetString( GR_EXTENSION );
497    fxMesa->Glide.HaveCombineExt = strstr(gext, "COMBINE") && !getenv("MESA_FX_IGNORE_CMBEXT");
498    fxMesa->Glide.HaveCommandTransportExt = GL_FALSE;
499    fxMesa->Glide.HaveFogCoordExt = GL_TRUE;
500    fxMesa->Glide.HavePixelExt = strstr(gext, "PIXEXT") && !getenv("MESA_FX_IGNORE_PIXEXT");
501    fxMesa->Glide.HaveTextureBufferExt = GL_TRUE;
502    fxMesa->Glide.HaveTexFmtExt = strstr(gext, "TEXFMT") && !getenv("MESA_FX_IGNORE_TEXFMT");
503    fxMesa->Glide.HaveTexUMAExt = strstr(gext, "TEXUMA") && !getenv("MESA_FX_IGNORE_TEXUMA");
504    fxMesa->Glide.HaveMirrorExt = strstr(gext, "TEXMIRROR") && !getenv("MESA_FX_IGNORE_MIREXT");
505    fxMesa->Glide.HaveTexus2 = GL_FALSE;
506
507    if ( fxMesa->glCtx->Visual.depthBits > 0 ) {
508       fxMesa->Glide.grDepthBufferMode(GR_DEPTHBUFFER_ZBUFFER);
509    } else {
510       fxMesa->Glide.grDepthBufferMode(GR_DEPTHBUFFER_DISABLE);
511    }
512
513    fxMesa->Glide.grLfbWriteColorFormat( GR_COLORFORMAT_ABGR );
514
515    fxMesa->Glide.grGet( GR_TEXTURE_ALIGN, sizeof(FxI32), result );
516    fxMesa->Glide.TextureAlign = result[0];
517
518    fxMesa->Glide.State = NULL;
519    fxMesa->Glide.grGet( GR_GLIDE_STATE_SIZE, sizeof(FxI32), result );
520    fxMesa->Glide.State = MALLOC( result[0] );
521
522    fxMesa->Fog.Table = NULL;
523    fxMesa->Glide.grGet( GR_FOG_TABLE_ENTRIES, sizeof(FxI32), result );
524    fxMesa->Fog.Table = MALLOC( result[0] * sizeof(GrFog_t) );
525
526    UNLOCK_HARDWARE( fxMesa );
527
528    if ( !fxMesa->Glide.State || !fxMesa->Fog.Table ) {
529       if ( fxMesa->Glide.State )
530          FREE( fxMesa->Glide.State );
531       if ( fxMesa->Fog.Table )
532          FREE( fxMesa->Fog.Table );
533       return GL_FALSE;
534    }
535
536    if ( !tdfxInitVertexFormats( fxMesa ) ) {
537       return GL_FALSE;
538    }
539
540    LOCK_HARDWARE( fxMesa );
541
542    fxMesa->Glide.grGlideGetState( fxMesa->Glide.State );
543
544    if ( getenv( "FX_GLIDE_INFO" ) ) {
545       printf( "GR_RENDERER  = %s\n", (char *) fxMesa->Glide.grGetString( GR_RENDERER ) );
546       printf( "GR_VERSION   = %s\n", (char *) fxMesa->Glide.grGetString( GR_VERSION ) );
547       printf( "GR_VENDOR    = %s\n", (char *) fxMesa->Glide.grGetString( GR_VENDOR ) );
548       printf( "GR_HARDWARE  = %s\n", (char *) fxMesa->Glide.grGetString( GR_HARDWARE ) );
549       printf( "GR_EXTENSION = %s\n", (char *) gext );
550    }
551
552    UNLOCK_HARDWARE( fxMesa );
553
554    fxMesa->numClipRects = 0;
555    fxMesa->pClipRects = NULL;
556    fxMesa->scissoredClipRects = GL_FALSE;
557
558    fxMesa->Glide.Initialized = GL_TRUE;
559
560    return GL_TRUE;
561 }
562
563
564 void
565 tdfxDestroyContext( __DRIcontext *driContextPriv )
566 {
567    tdfxContextPtr fxMesa = (tdfxContextPtr) driContextPriv->driverPrivate;
568
569    if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) {
570       fprintf( stderr, "%s( %p )\n", __FUNCTION__, (void *)fxMesa );
571    }
572
573    if ( fxMesa ) {
574       if (fxMesa->glCtx->Shared->RefCount == 1 && fxMesa->driDrawable) {
575          /* This share group is about to go away, free our private
576           * texture object data.
577           */
578          struct _mesa_HashTable *textures = fxMesa->glCtx->Shared->TexObjects;
579          GLuint id;
580          for (id = _mesa_HashFirstEntry(textures);
581               id;
582               id = _mesa_HashNextEntry(textures, id)) {
583             struct gl_texture_object *tObj
584                = _mesa_lookup_texture(fxMesa->glCtx, id);
585             tdfxTMFreeTexture(fxMesa, tObj);
586          }
587       }
588
589       tdfxTMClose(fxMesa);  /* free texture memory */
590
591       _swsetup_DestroyContext( fxMesa->glCtx );
592       _tnl_DestroyContext( fxMesa->glCtx );
593       _vbo_DestroyContext( fxMesa->glCtx );
594       _swrast_DestroyContext( fxMesa->glCtx );
595
596       tdfxFreeVB( fxMesa->glCtx );
597
598       /* Free Mesa context */
599       fxMesa->glCtx->DriverCtx = NULL;
600       _mesa_destroy_context(fxMesa->glCtx);
601
602       /* free the tdfx context */
603       FREE( fxMesa );
604    }
605 }
606
607
608 GLboolean
609 tdfxUnbindContext( __DRIcontext *driContextPriv )
610 {
611    GET_CURRENT_CONTEXT(ctx);
612    tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
613
614    if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) {
615       fprintf( stderr, "%s( %p )\n", __FUNCTION__, (void *)driContextPriv );
616    }
617
618    if ( driContextPriv && (tdfxContextPtr) driContextPriv == fxMesa ) {
619       LOCK_HARDWARE(fxMesa);
620       fxMesa->Glide.grGlideGetState(fxMesa->Glide.State);
621       UNLOCK_HARDWARE(fxMesa);
622    }
623    return GL_TRUE;
624 }
625
626
627 GLboolean
628 tdfxMakeCurrent( __DRIcontext *driContextPriv,
629                  __DRIdrawable *driDrawPriv,
630                  __DRIdrawable *driReadPriv )
631 {
632    if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) {
633       fprintf( stderr, "%s( %p )\n", __FUNCTION__, (void *)driContextPriv );
634    }
635
636    if ( driContextPriv ) {
637       tdfxContextPtr newFx = (tdfxContextPtr) driContextPriv->driverPrivate;
638       struct gl_context *newCtx = newFx->glCtx;
639       GET_CURRENT_CONTEXT(curCtx);
640
641       if ((newFx->driDrawable != driDrawPriv)
642           || (newFx->driReadable != driReadPriv)) {
643          newFx->driDrawable = driDrawPriv;
644          newFx->driReadable = driReadPriv;
645          newFx->dirty = ~0;
646       }
647       else {
648          if (curCtx == newCtx) {
649             /* same drawable, same context -> no-op */
650             /* Need to call _mesa_make_current2() in order to make sure API
651              * dispatch is set correctly.
652              */
653             _mesa_make_current( newCtx,
654                                 (struct gl_framebuffer *) driDrawPriv->driverPrivate,
655                                 (struct gl_framebuffer *) driReadPriv->driverPrivate );
656             return GL_TRUE;
657          }
658          /* [dBorca] tunnel2 requires this */
659          newFx->dirty = ~0;
660       }
661
662       driUpdateFramebufferSize(newCtx, driDrawPriv);
663       if (driDrawPriv != driReadPriv) {
664          driUpdateFramebufferSize(newCtx, driReadPriv);
665       }
666
667       if ( !newFx->Glide.Initialized ) {
668          if ( !tdfxInitContext( driDrawPriv, newFx ) )
669             return GL_FALSE;
670
671          LOCK_HARDWARE( newFx );
672
673          /* FIXME: Force loading of window information */
674          newFx->width = 0;
675          tdfxUpdateClipping(newCtx);
676          tdfxUploadClipping(newFx);
677
678          UNLOCK_HARDWARE( newFx );
679       } else {
680          LOCK_HARDWARE( newFx );
681
682          newFx->Glide.grSstSelect( newFx->Glide.Board );
683          newFx->Glide.grGlideSetState( newFx->Glide.State );
684
685          tdfxUpdateClipping(newCtx);
686          tdfxUploadClipping(newFx);
687
688          UNLOCK_HARDWARE( newFx );
689       }
690
691       _mesa_make_current( newCtx,
692                           (struct gl_framebuffer *) driDrawPriv->driverPrivate,
693                           (struct gl_framebuffer *) driReadPriv->driverPrivate );
694    } else {
695       _mesa_make_current( NULL, NULL, NULL );
696    }
697
698    return GL_TRUE;
699 }
700
701
702 /*
703  * Enable this to trace calls to various Glide functions.
704  */
705 /*#define DEBUG_TRAP*/
706 #ifdef DEBUG_TRAP
707 static void (*real_grDrawTriangle)( const void *a, const void *b, const void *c );
708 static void (*real_grDrawPoint)( const void *a );
709 static void (*real_grDrawVertexArray)(FxU32 mode, FxU32 Count, void *pointers);
710 static void (*real_grDrawVertexArrayContiguous)(FxU32 mode, FxU32 Count,
711                                        void *pointers, FxU32 stride);
712 static void (*real_grClipWindow)( FxU32 minx, FxU32 miny, FxU32 maxx, FxU32 maxy );
713
714 static void (*real_grVertexLayout)(FxU32 param, FxI32 offset, FxU32 mode);
715 static void (*real_grGlideGetVertexLayout)( void *layout );
716 static void (*real_grGlideSetVertexLayout)( const void *layout );
717
718 static void (*real_grTexDownloadMipMapLevel)( GrChipID_t        tmu,
719                                      FxU32             startAddress,
720                                      GrLOD_t           thisLod,
721                                      GrLOD_t           largeLod,
722                                      GrAspectRatio_t   aspectRatio,
723                                      GrTextureFormat_t format,
724                                      FxU32             evenOdd,
725                                               void              *data );
726
727
728 static void debug_grDrawTriangle( const void *a, const void *b, const void *c )
729 {
730    printf("%s\n", __FUNCTION__);
731    (*real_grDrawTriangle)(a, b, c);
732 }
733
734 static void debug_grDrawPoint( const void *a )
735 {
736    const float *f = (const float *) a;
737    printf("%s %g %g\n", __FUNCTION__, f[0], f[1]);
738    (*real_grDrawPoint)(a);
739 }
740
741 static void debug_grDrawVertexArray(FxU32 mode, FxU32 Count, void *pointers)
742 {
743    printf("%s count=%d\n", __FUNCTION__, (int) Count);
744    (*real_grDrawVertexArray)(mode, Count, pointers);
745 }
746
747 static void debug_grDrawVertexArrayContiguous(FxU32 mode, FxU32 Count,
748                                        void *pointers, FxU32 stride)
749 {
750    printf("%s mode=0x%x count=%d\n", __FUNCTION__, (int) mode, (int) Count);
751    (*real_grDrawVertexArrayContiguous)(mode, Count, pointers, stride);
752 }
753
754 static void debug_grClipWindow( FxU32 minx, FxU32 miny, FxU32 maxx, FxU32 maxy )
755 {
756    printf("%s %d,%d .. %d,%d\n", __FUNCTION__,
757           (int) minx, (int) miny, (int) maxx, (int) maxy);
758    (*real_grClipWindow)(minx, miny, maxx, maxy);
759 }
760
761 static void debug_grVertexLayout(FxU32 param, FxI32 offset, FxU32 mode)
762 {
763    (*real_grVertexLayout)(param, offset, mode);
764 }
765
766 static void debug_grGlideGetVertexLayout( void *layout )
767 {
768    (*real_grGlideGetVertexLayout)(layout);
769 }
770
771 static void debug_grGlideSetVertexLayout( const void *layout )
772 {
773    (*real_grGlideSetVertexLayout)(layout);
774 }
775
776 static void debug_grTexDownloadMipMapLevel( GrChipID_t        tmu,
777                                      FxU32             startAddress,
778                                      GrLOD_t           thisLod,
779                                      GrLOD_t           largeLod,
780                                      GrAspectRatio_t   aspectRatio,
781                                      GrTextureFormat_t format,
782                                      FxU32             evenOdd,
783                                      void              *data )
784 {
785    (*real_grTexDownloadMipMapLevel)(tmu, startAddress, thisLod, largeLod,
786                                     aspectRatio, format, evenOdd, data);
787 }
788
789 #endif
790
791
792 /*
793  * Examine the context's deviceID to determine what kind of 3dfx hardware
794  * is installed.  dlopen() the appropriate Glide library and initialize
795  * this context's Glide function pointers.
796  * Return:  true/false = success/failure
797  */
798 GLboolean tdfxInitGlide(tdfxContextPtr tmesa)
799 {
800    static const char *defaultGlide = "libglide3.so";
801    const char *libName;
802    void *libHandle;
803
804    /*
805     * XXX this code which selects a Glide library filename given the
806     * deviceID may need to be cleaned up a bit.
807     * Non-Linux systems may have different filenames, for example.
808     */
809    switch (tmesa->fxScreen->deviceID) {
810    case PCI_CHIP_BANSHEE:
811    case PCI_CHIP_VOODOO3:
812       libName = "libglide3-v3.so";
813       break;
814    case PCI_CHIP_VOODOO5:   /* same as PCI_CHIP_VOODOO4 */
815       libName = "libglide3-v5.so";
816       break;
817    default:
818       {
819          __driUtilMessage("unrecognized 3dfx deviceID: 0x%x",
820                  tmesa->fxScreen->deviceID);
821       }
822       return GL_FALSE;
823    }
824
825    libHandle = dlopen(libName, RTLD_NOW);
826    if (!libHandle) {
827       /* The device-specific Glide library filename didn't work, try the
828        * old, generic libglide3.so library.
829        */
830       libHandle = dlopen(defaultGlide, RTLD_NOW); 
831       if (!libHandle) {
832          __driUtilMessage(
833             "can't find Glide library, dlopen(%s) and dlopen(%s) both failed.",
834             libName, defaultGlide);
835          __driUtilMessage("dlerror() message: %s", dlerror());
836          return GL_FALSE;
837       }
838       libName = defaultGlide;
839    }
840
841    {
842       const char *env = getenv("LIBGL_DEBUG");
843       if (env && strstr(env, "verbose")) {
844          fprintf(stderr, "libGL: using Glide library %s\n", libName);
845       }
846    }         
847
848 #define GET_FUNCTION(PTR, NAME)                                         \
849    tmesa->Glide.PTR = dlsym(libHandle, NAME);                           \
850    if (!tmesa->Glide.PTR) {                                             \
851       __driUtilMessage("couldn't find Glide function %s in %s.",        \
852               NAME, libName);                                           \
853    }
854
855    GET_FUNCTION(grDrawPoint, "grDrawPoint");
856    GET_FUNCTION(grDrawLine, "grDrawLine");
857    GET_FUNCTION(grDrawTriangle, "grDrawTriangle");
858    GET_FUNCTION(grVertexLayout, "grVertexLayout");
859    GET_FUNCTION(grDrawVertexArray, "grDrawVertexArray");
860    GET_FUNCTION(grDrawVertexArrayContiguous, "grDrawVertexArrayContiguous");
861    GET_FUNCTION(grBufferClear, "grBufferClear");
862    /*GET_FUNCTION(grBufferSwap, "grBufferSwap");*/
863    GET_FUNCTION(grRenderBuffer, "grRenderBuffer");
864    GET_FUNCTION(grErrorSetCallback, "grErrorSetCallback");
865    GET_FUNCTION(grFinish, "grFinish");
866    GET_FUNCTION(grFlush, "grFlush");
867    GET_FUNCTION(grSstWinOpen, "grSstWinOpen");
868    GET_FUNCTION(grSstWinClose, "grSstWinClose");
869 #if 0
870    /* Not in V3 lib, and not used anyway. */
871    GET_FUNCTION(grSetNumPendingBuffers, "grSetNumPendingBuffers");
872 #endif
873    GET_FUNCTION(grSelectContext, "grSelectContext");
874    GET_FUNCTION(grSstOrigin, "grSstOrigin");
875    GET_FUNCTION(grSstSelect, "grSstSelect");
876    GET_FUNCTION(grAlphaBlendFunction, "grAlphaBlendFunction");
877    GET_FUNCTION(grAlphaCombine, "grAlphaCombine");
878    GET_FUNCTION(grAlphaControlsITRGBLighting, "grAlphaControlsITRGBLighting");
879    GET_FUNCTION(grAlphaTestFunction, "grAlphaTestFunction");
880    GET_FUNCTION(grAlphaTestReferenceValue, "grAlphaTestReferenceValue");
881    GET_FUNCTION(grChromakeyMode, "grChromakeyMode");
882    GET_FUNCTION(grChromakeyValue, "grChromakeyValue");
883    GET_FUNCTION(grClipWindow, "grClipWindow");
884    GET_FUNCTION(grColorCombine, "grColorCombine");
885    GET_FUNCTION(grColorMask, "grColorMask");
886    GET_FUNCTION(grCullMode, "grCullMode");
887    GET_FUNCTION(grConstantColorValue, "grConstantColorValue");
888    GET_FUNCTION(grDepthBiasLevel, "grDepthBiasLevel");
889    GET_FUNCTION(grDepthBufferFunction, "grDepthBufferFunction");
890    GET_FUNCTION(grDepthBufferMode, "grDepthBufferMode");
891    GET_FUNCTION(grDepthMask, "grDepthMask");
892    GET_FUNCTION(grDisableAllEffects, "grDisableAllEffects");
893    GET_FUNCTION(grDitherMode, "grDitherMode");
894    GET_FUNCTION(grFogColorValue, "grFogColorValue");
895    GET_FUNCTION(grFogMode, "grFogMode");
896    GET_FUNCTION(grFogTable, "grFogTable");
897    GET_FUNCTION(grLoadGammaTable, "grLoadGammaTable");
898    GET_FUNCTION(grSplash, "grSplash");
899    GET_FUNCTION(grGet, "grGet");
900    GET_FUNCTION(grGetString, "grGetString");
901    GET_FUNCTION(grQueryResolutions, "grQueryResolutions");
902    GET_FUNCTION(grReset, "grReset");
903    GET_FUNCTION(grGetProcAddress, "grGetProcAddress");
904    GET_FUNCTION(grEnable, "grEnable");
905    GET_FUNCTION(grDisable, "grDisable");
906    GET_FUNCTION(grCoordinateSpace, "grCoordinateSpace");
907    GET_FUNCTION(grDepthRange, "grDepthRange");
908    GET_FUNCTION(grStippleMode, "grStippleMode");
909    GET_FUNCTION(grStipplePattern, "grStipplePattern");
910    GET_FUNCTION(grViewport, "grViewport");
911    GET_FUNCTION(grTexCalcMemRequired, "grTexCalcMemRequired");
912    GET_FUNCTION(grTexTextureMemRequired, "grTexTextureMemRequired");
913    GET_FUNCTION(grTexMinAddress, "grTexMinAddress");
914    GET_FUNCTION(grTexMaxAddress, "grTexMaxAddress");
915    GET_FUNCTION(grTexNCCTable, "grTexNCCTable");
916    GET_FUNCTION(grTexSource, "grTexSource");
917    GET_FUNCTION(grTexClampMode, "grTexClampMode");
918    GET_FUNCTION(grTexCombine, "grTexCombine");
919    GET_FUNCTION(grTexDetailControl, "grTexDetailControl");
920    GET_FUNCTION(grTexFilterMode, "grTexFilterMode");
921    GET_FUNCTION(grTexLodBiasValue, "grTexLodBiasValue");
922    GET_FUNCTION(grTexDownloadMipMap, "grTexDownloadMipMap");
923    GET_FUNCTION(grTexDownloadMipMapLevel, "grTexDownloadMipMapLevel");
924    GET_FUNCTION(grTexDownloadMipMapLevelPartial, "grTexDownloadMipMapLevelPartial");
925    GET_FUNCTION(grTexDownloadTable, "grTexDownloadTable");
926    GET_FUNCTION(grTexDownloadTablePartial, "grTexDownloadTablePartial");
927    GET_FUNCTION(grTexMipMapMode, "grTexMipMapMode");
928    GET_FUNCTION(grTexMultibase, "grTexMultibase");
929    GET_FUNCTION(grTexMultibaseAddress, "grTexMultibaseAddress");
930    GET_FUNCTION(grLfbLock, "grLfbLock");
931    GET_FUNCTION(grLfbUnlock, "grLfbUnlock");
932    GET_FUNCTION(grLfbConstantAlpha, "grLfbConstantAlpha");
933    GET_FUNCTION(grLfbConstantDepth, "grLfbConstantDepth");
934    GET_FUNCTION(grLfbWriteColorSwizzle, "grLfbWriteColorSwizzle");
935    GET_FUNCTION(grLfbWriteColorFormat, "grLfbWriteColorFormat");
936    GET_FUNCTION(grLfbWriteRegion, "grLfbWriteRegion");
937    GET_FUNCTION(grLfbReadRegion, "grLfbReadRegion");
938    GET_FUNCTION(grGlideInit, "grGlideInit");
939    GET_FUNCTION(grGlideShutdown, "grGlideShutdown");
940    GET_FUNCTION(grGlideGetState, "grGlideGetState");
941    GET_FUNCTION(grGlideSetState, "grGlideSetState");
942    GET_FUNCTION(grGlideGetVertexLayout, "grGlideGetVertexLayout");
943    GET_FUNCTION(grGlideSetVertexLayout, "grGlideSetVertexLayout");
944
945    /* Glide utility functions */
946    GET_FUNCTION(guFogGenerateExp, "guFogGenerateExp");
947    GET_FUNCTION(guFogGenerateExp2, "guFogGenerateExp2");
948    GET_FUNCTION(guFogGenerateLinear, "guFogGenerateLinear");
949
950    /* DRI functions */
951    GET_FUNCTION(grDRIOpen, "grDRIOpen");
952    GET_FUNCTION(grDRIPosition, "grDRIPosition");
953    /*GET_FUNCTION(grDRILostContext, "grDRILostContext");*/
954    GET_FUNCTION(grDRIImportFifo, "grDRIImportFifo");
955    GET_FUNCTION(grDRIInvalidateAll, "grDRIInvalidateAll");
956    GET_FUNCTION(grDRIResetSAREA, "grDRIResetSAREA");
957    GET_FUNCTION(grDRIBufferSwap, "grDRIBufferSwap");
958
959    /*
960     * Extension functions:
961     * Just use dlysm() because we want a NULL pointer if the function is
962     * not found.
963     */
964    /* PIXEXT extension */
965    tmesa->Glide.grStencilFunc = dlsym(libHandle, "grStencilFunc");
966    tmesa->Glide.grStencilMask = dlsym(libHandle, "grStencilMask");
967    tmesa->Glide.grStencilOp = dlsym(libHandle, "grStencilOp");
968    tmesa->Glide.grBufferClearExt = dlsym(libHandle, "grBufferClearExt");
969    tmesa->Glide.grColorMaskExt = dlsym(libHandle, "grColorMaskExt");
970    /* COMBINE extension */
971    tmesa->Glide.grColorCombineExt = dlsym(libHandle, "grColorCombineExt");
972    tmesa->Glide.grTexColorCombineExt = dlsym(libHandle, "grTexColorCombineExt");
973    tmesa->Glide.grAlphaCombineExt = dlsym(libHandle, "grAlphaCombineExt");
974    tmesa->Glide.grTexAlphaCombineExt = dlsym(libHandle, "grTexAlphaCombineExt");
975    tmesa->Glide.grAlphaBlendFunctionExt = dlsym(libHandle, "grAlphaBlendFunctionExt");
976    tmesa->Glide.grConstantColorValueExt = dlsym(libHandle, "grConstantColorValueExt");
977    /* Texus 2 */
978    tmesa->Glide.txImgQuantize = dlsym(libHandle, "txImgQuantize");
979    tmesa->Glide.txImgDequantizeFXT1 = dlsym(libHandle, "_txImgDequantizeFXT1");
980    tmesa->Glide.txErrorSetCallback = dlsym(libHandle, "txErrorSetCallback");
981    
982 #ifdef DEBUG_TRAP
983    /* wrap the drawing functions so we can trap them */
984    real_grDrawTriangle = tmesa->Glide.grDrawTriangle;
985    tmesa->Glide.grDrawTriangle = debug_grDrawTriangle;
986
987    real_grDrawPoint = tmesa->Glide.grDrawPoint;
988    tmesa->Glide.grDrawPoint = debug_grDrawPoint;
989
990    real_grDrawVertexArray = tmesa->Glide.grDrawVertexArray;
991    tmesa->Glide.grDrawVertexArray = debug_grDrawVertexArray;
992
993    real_grDrawVertexArrayContiguous = tmesa->Glide.grDrawVertexArrayContiguous;
994    tmesa->Glide.grDrawVertexArrayContiguous = debug_grDrawVertexArrayContiguous;
995
996    real_grClipWindow = tmesa->Glide.grClipWindow;
997    tmesa->Glide.grClipWindow = debug_grClipWindow;
998
999    real_grVertexLayout = tmesa->Glide.grVertexLayout;
1000    tmesa->Glide.grVertexLayout = debug_grVertexLayout;
1001
1002    real_grGlideGetVertexLayout = tmesa->Glide.grGlideGetVertexLayout;
1003    tmesa->Glide.grGlideGetVertexLayout = debug_grGlideGetVertexLayout;
1004
1005    real_grGlideSetVertexLayout = tmesa->Glide.grGlideSetVertexLayout;
1006    tmesa->Glide.grGlideSetVertexLayout = debug_grGlideSetVertexLayout;
1007
1008    real_grTexDownloadMipMapLevel = tmesa->Glide.grTexDownloadMipMapLevel;
1009    tmesa->Glide.grTexDownloadMipMapLevel = debug_grTexDownloadMipMapLevel;
1010
1011 #endif
1012    return GL_TRUE;
1013 }