1 /* -*- mode: c; c-basic-offset: 3 -*-
3 * Copyright 2000 VA Linux Systems Inc., Fremont, California.
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:
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
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
28 * \file tdfx_context.c
29 * Context management functions for 3Dfx hardware.
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)
37 #include "tdfx_context.h"
39 #include "tdfx_state.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"
50 #include "swrast/swrast.h"
51 #include "swrast_setup/swrast_setup.h"
55 #include "tnl/t_pipeline.h"
57 #include "drivers/common/driverfuncs.h"
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_MESA_program_debug */
71 /* #define need_GL_NV_vertex_program */
72 #include "extension_helper.h"
76 * Common extension strings exported by all cards
78 const struct dri_extension card_extensions
[] =
80 { "GL_ARB_occlusion_query", GL_ARB_occlusion_query_functions
},
81 { "GL_ARB_texture_mirrored_repeat", NULL
},
83 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
84 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
85 { "GL_EXT_paletted_texture", GL_EXT_paletted_texture_functions
},
86 { "GL_EXT_shared_texture_palette", NULL
},
87 { "GL_EXT_stencil_wrap", NULL
},
88 { "GL_EXT_texture_env_add", NULL
},
89 { "GL_EXT_texture_lod_bias", NULL
},
91 #ifdef need_GL_ARB_point_parameters
92 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions
},
93 { "GL_ARB_point_sprite", NULL
},
95 #ifdef need_GL_EXT_secondary_color
96 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
98 #ifdef need_GL_ARB_vertex_program
99 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
}
101 #ifdef need_GL_NV_vertex_program
102 { "GL_NV_vertex_program", GL_NV_vertex_program_functions
}
103 { "GL_NV_vertex_program1_1", NULL
},
105 #ifdef need_GL_MESA_program_debug
106 { "GL_MESA_program_debug", GL_MESA_program_debug_functions
},
112 * Extension strings exported only by Naplam (e.g., Voodoo4 & Voodoo5) cards.
114 const struct dri_extension napalm_extensions
[] =
116 { "GL_ARB_texture_env_combine", NULL
},
117 { "GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions
},
118 { "GL_EXT_blend_subtract", GL_EXT_blend_minmax_functions
},
119 { "GL_EXT_texture_compression_s3tc", NULL
},
120 { "GL_EXT_texture_env_combine", NULL
},
122 { "GL_3DFX_texture_compression_FXT1", NULL
},
123 { "GL_NV_blend_square", NULL
},
124 { "GL_S3_s3tc", NULL
},
129 * Enable/Disable the extensions for this context.
131 static void tdfxDDInitExtensions( GLcontext
*ctx
)
133 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
135 driInitExtensions( ctx
, card_extensions
, GL_FALSE
);
137 if ( fxMesa
->haveTwoTMUs
) {
138 _mesa_enable_extension( ctx
, "GL_ARB_multitexture" );
141 if ( TDFX_IS_NAPALM( fxMesa
) ) {
142 driInitExtensions( ctx
, napalm_extensions
, GL_FALSE
);
144 _mesa_enable_extension( ctx
, "GL_SGIS_generate_mipmap" );
150 static const struct tnl_pipeline_stage
*tdfx_pipeline
[] = {
151 &_tnl_vertex_transform_stage
,
152 &_tnl_normal_transform_stage
,
153 &_tnl_lighting_stage
,
154 &_tnl_fog_coordinate_stage
,
156 &_tnl_texture_transform_stage
,
157 &_tnl_point_attenuation_stage
,
162 static const struct dri_debug_control debug_control
[] =
164 { "dri", DEBUG_VERBOSE_DRI
},
165 { "sync", DEBUG_ALWAYS_SYNC
},
166 { "api", DEBUG_VERBOSE_API
},
167 { "fall", DEBUG_VERBOSE_FALL
},
171 GLboolean
tdfxCreateContext( const __GLcontextModes
*mesaVis
,
172 __DRIcontextPrivate
*driContextPriv
,
173 void *sharedContextPrivate
)
175 tdfxContextPtr fxMesa
;
176 GLcontext
*ctx
, *shareCtx
;
177 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
178 tdfxScreenPrivate
*fxScreen
= (tdfxScreenPrivate
*) sPriv
->private;
179 TDFXSAREAPriv
*saPriv
= (TDFXSAREAPriv
*) ((char *) sPriv
->pSAREA
+
180 sizeof(drm_sarea_t
));
181 struct dd_function_table functions
;
183 /* Allocate tdfx context */
184 fxMesa
= (tdfxContextPtr
) CALLOC( sizeof(tdfxContextRec
) );
188 /* Init default driver functions then plug in our tdfx-specific functions
189 * (the texture functions are especially important)
191 _mesa_init_driver_functions(&functions
);
192 tdfxDDInitDriverFuncs(mesaVis
, &functions
);
193 tdfxInitTextureFuncs(&functions
);
194 tdfxInitRenderFuncs(&functions
);
196 /* Allocate the Mesa context */
197 if (sharedContextPrivate
)
198 shareCtx
= ((tdfxContextPtr
) sharedContextPrivate
)->glCtx
;
202 fxMesa
->glCtx
= _mesa_create_context(mesaVis
, shareCtx
,
203 &functions
, (void *) fxMesa
);
204 if (!fxMesa
->glCtx
) {
208 driContextPriv
->driverPrivate
= fxMesa
;
210 /* Mirror some important DRI state
212 fxMesa
->hHWContext
= driContextPriv
->hHWContext
;
213 fxMesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
214 fxMesa
->driFd
= sPriv
->fd
;
216 fxMesa
->driScreen
= sPriv
;
217 fxMesa
->driContext
= driContextPriv
;
218 fxMesa
->fxScreen
= fxScreen
;
219 fxMesa
->sarea
= saPriv
;
222 fxMesa
->haveHwAlpha
= ( mesaVis
->alphaBits
&&
223 ((mesaVis
->greenBits
== 8) ||
224 (mesaVis
->depthBits
== 0)) );
225 fxMesa
->haveHwStencil
= ( TDFX_IS_NAPALM( fxMesa
) &&
226 mesaVis
->stencilBits
&&
227 mesaVis
->depthBits
== 24 );
229 fxMesa
->screen_width
= fxScreen
->width
;
230 fxMesa
->screen_height
= fxScreen
->height
;
232 fxMesa
->new_gl_state
= ~0;
233 fxMesa
->new_state
= ~0;
236 /* Parse configuration files */
237 driParseConfigFiles (&fxMesa
->optionCache
, &fxScreen
->optionCache
,
238 fxMesa
->driScreen
->myNum
, "tdfx");
240 /* NOTE: This must be here before any Glide calls! */
241 if (!tdfxInitGlide( fxMesa
)) {
246 fxMesa
->Glide
.grDRIOpen( (char*) sPriv
->pFB
, fxScreen
->regs
.map
, fxScreen
->deviceID
,
247 fxScreen
->width
, fxScreen
->height
, fxScreen
->mem
, fxScreen
->cpp
,
248 fxScreen
->stride
, fxScreen
->fifoOffset
, fxScreen
->fifoSize
,
249 fxScreen
->fbOffset
, fxScreen
->backOffset
, fxScreen
->depthOffset
,
250 fxScreen
->textureOffset
, fxScreen
->textureSize
, &saPriv
->fifoPtr
,
253 if ( getenv( "FX_GLIDE_SWAPINTERVAL" ) ) {
254 fxMesa
->Glide
.SwapInterval
= atoi( getenv( "FX_GLIDE_SWAPINTERVAL" ) );
256 fxMesa
->Glide
.SwapInterval
= 0;
258 if ( getenv( "FX_MAX_PENDING_SWAPS" ) ) {
259 fxMesa
->Glide
.MaxPendingSwaps
= atoi( getenv( "FX_MAX_PENDING_SWAPS" ) );
261 fxMesa
->Glide
.MaxPendingSwaps
= 2;
264 fxMesa
->Glide
.Initialized
= GL_FALSE
;
265 fxMesa
->Glide
.Board
= 0;
268 if (getenv("FX_EMULATE_SINGLE_TMU")) {
269 fxMesa
->haveTwoTMUs
= GL_FALSE
;
272 if ( TDFX_IS_BANSHEE( fxMesa
) ) {
273 fxMesa
->haveTwoTMUs
= GL_FALSE
;
275 fxMesa
->haveTwoTMUs
= GL_TRUE
;
279 fxMesa
->stats
.swapBuffer
= 0;
280 fxMesa
->stats
.reqTexUpload
= 0;
281 fxMesa
->stats
.texUpload
= 0;
282 fxMesa
->stats
.memTexUpload
= 0;
284 fxMesa
->tmuSrc
= TDFX_TMU_NONE
;
287 if ( TDFX_IS_NAPALM( fxMesa
) ) {
288 ctx
->Const
.MaxTextureLevels
= 12;
290 ctx
->Const
.MaxTextureLevels
= 9;
292 ctx
->Const
.MaxTextureUnits
= TDFX_IS_BANSHEE( fxMesa
) ? 1 : 2;
293 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
294 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
298 ctx
->Const
.MinPointSize
= 1.0;
299 ctx
->Const
.MinPointSizeAA
= 1.0;
300 ctx
->Const
.MaxPointSize
= 1.0;
301 ctx
->Const
.MaxPointSizeAA
= 1.0;
303 /* Disable wide lines as we can't antialias them correctly in
306 ctx
->Const
.MinLineWidth
= 1.0;
307 ctx
->Const
.MinLineWidthAA
= 1.0;
308 ctx
->Const
.MaxLineWidth
= 1.0;
309 ctx
->Const
.MaxLineWidthAA
= 1.0;
310 ctx
->Const
.LineWidthGranularity
= 1.0;
312 /* Initialize the software rasterizer and helper modules.
314 _swrast_CreateContext( ctx
);
315 _vbo_CreateContext( ctx
);
316 _tnl_CreateContext( ctx
);
317 _swsetup_CreateContext( ctx
);
319 /* Install the customized pipeline:
321 _tnl_destroy_pipeline( ctx
);
322 _tnl_install_pipeline( ctx
, tdfx_pipeline
);
324 /* Configure swrast and T&L to match hardware characteristics:
326 _swrast_allow_pixel_fog( ctx
, GL_TRUE
);
327 _swrast_allow_vertex_fog( ctx
, GL_FALSE
);
328 _tnl_allow_pixel_fog( ctx
, GL_TRUE
);
329 _tnl_allow_vertex_fog( ctx
, GL_FALSE
);
331 tdfxDDInitExtensions( ctx
);
332 /* XXX these should really go right after _mesa_init_driver_functions() */
333 tdfxDDInitSpanFuncs( ctx
);
334 tdfxDDInitStateFuncs( ctx
);
335 tdfxDDInitTriFuncs( ctx
);
337 tdfxInitState( fxMesa
);
340 TDFX_DEBUG
= driParseDebugString( getenv( "TDFX_DEBUG" ), debug_control
);
343 if (driQueryOptionb(&fxMesa
->optionCache
, "no_rast")) {
344 fprintf(stderr
, "disabling 3D acceleration\n");
345 FALLBACK(fxMesa
, TDFX_FALLBACK_DISABLE
, 1);
352 static GLboolean
tdfxInitVertexFormats( tdfxContextPtr fxMesa
)
357 LOCK_HARDWARE( fxMesa
);
359 fxMesa
->Glide
.grGet( GR_GLIDE_VERTEXLAYOUT_SIZE
, sizeof(FxI32
), &result
);
360 for ( i
= 0 ; i
< TDFX_NUM_LAYOUTS
; i
++ ) {
361 fxMesa
->layout
[i
] = MALLOC( result
);
362 if ( !fxMesa
->layout
[i
] ) {
363 UNLOCK_HARDWARE( fxMesa
);
368 /* Tiny vertex format - 16 bytes.
370 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
371 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
372 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
373 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
374 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
375 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_TINY
] );
377 /* Non textured vertex format - 24 bytes (Need w for table fog)
379 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
380 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
381 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
382 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
383 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
384 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
385 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_NOTEX
] );
387 /* Single textured vertex format - 32 bytes.
389 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
390 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
391 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
392 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
393 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
394 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
395 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
396 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_SINGLE
] );
398 /* Multitextured vertex format - 40 bytes.
400 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
401 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
402 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
403 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
404 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
405 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
406 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
407 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST1
, TDFX_ST1_OFFSET
, GR_PARAM_ENABLE
);
408 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_MULTI
] );
410 /* Projected texture vertex format - 36 bytes.
412 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
413 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
414 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
415 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
416 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
417 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
418 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
419 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q0
, TDFX_Q0_OFFSET
, GR_PARAM_ENABLE
);
420 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_PROJ1
] );
422 /* Projected multitexture vertex format - 48 bytes.
424 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
425 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
426 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
427 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
428 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
429 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
430 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
431 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q0
, TDFX_Q0_OFFSET
, GR_PARAM_ENABLE
);
432 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST1
, TDFX_ST1_OFFSET
, GR_PARAM_ENABLE
);
433 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q1
, TDFX_Q1_OFFSET
, GR_PARAM_ENABLE
);
434 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_PROJ2
] );
436 UNLOCK_HARDWARE( fxMesa
);
443 * Initialize the state in an tdfxContextPtr struct.
446 tdfxInitContext( __DRIdrawablePrivate
*driDrawPriv
, tdfxContextPtr fxMesa
)
448 /* KW: Would be nice to make one of these a member of the other.
453 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
454 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)fxMesa
);
458 fprintf(stderr
, "Debug locking enabled\n");
461 if ( fxMesa
->Glide
.Initialized
)
464 fxMesa
->width
= driDrawPriv
->w
;
465 fxMesa
->height
= driDrawPriv
->h
;
467 /* We have to use a light lock here, because we can't do any glide
468 * operations yet. No use of FX_* functions in this function.
470 DRM_LIGHT_LOCK( fxMesa
->driFd
, fxMesa
->driHwLock
, fxMesa
->hHWContext
);
472 fxMesa
->Glide
.grGlideInit();
473 fxMesa
->Glide
.grSstSelect( fxMesa
->Glide
.Board
);
475 fxMesa
->Glide
.Context
= fxMesa
->Glide
.grSstWinOpen( (FxU32
) -1,
478 fxMesa
->Glide
.ColorFormat
,
479 fxMesa
->Glide
.Origin
,
482 fxMesa
->Glide
.grDRIResetSAREA();
484 DRM_UNLOCK( fxMesa
->driFd
, fxMesa
->driHwLock
, fxMesa
->hHWContext
);
486 if ( !fxMesa
->Glide
.Context
)
490 /* Perform the Glide-dependant part of the context initialization.
492 FX_grColorMaskv( fxMesa
->glCtx
, true4
);
494 tdfxTMInit( fxMesa
);
496 LOCK_HARDWARE( fxMesa
);
498 /* JJJ - COMMAND_TRANSPORT, PALETTE6666 */
499 gext
= fxMesa
->Glide
.grGetString( GR_EXTENSION
);
500 fxMesa
->Glide
.HaveCombineExt
= strstr(gext
, "COMBINE") && !getenv("MESA_FX_IGNORE_CMBEXT");
501 fxMesa
->Glide
.HaveCommandTransportExt
= GL_FALSE
;
502 fxMesa
->Glide
.HaveFogCoordExt
= GL_TRUE
;
503 fxMesa
->Glide
.HavePixelExt
= strstr(gext
, "PIXEXT") && !getenv("MESA_FX_IGNORE_PIXEXT");
504 fxMesa
->Glide
.HaveTextureBufferExt
= GL_TRUE
;
505 fxMesa
->Glide
.HaveTexFmtExt
= strstr(gext
, "TEXFMT") && !getenv("MESA_FX_IGNORE_TEXFMT");
506 fxMesa
->Glide
.HaveTexUMAExt
= strstr(gext
, "TEXUMA") && !getenv("MESA_FX_IGNORE_TEXUMA");
507 fxMesa
->Glide
.HaveMirrorExt
= strstr(gext
, "TEXMIRROR") && !getenv("MESA_FX_IGNORE_MIREXT");
508 fxMesa
->Glide
.HaveTexus2
= GL_FALSE
;
510 if ( fxMesa
->glCtx
->Visual
.depthBits
> 0 ) {
511 fxMesa
->Glide
.grDepthBufferMode(GR_DEPTHBUFFER_ZBUFFER
);
513 fxMesa
->Glide
.grDepthBufferMode(GR_DEPTHBUFFER_DISABLE
);
516 fxMesa
->Glide
.grLfbWriteColorFormat( GR_COLORFORMAT_ABGR
);
518 fxMesa
->Glide
.grGet( GR_TEXTURE_ALIGN
, sizeof(FxI32
), result
);
519 fxMesa
->Glide
.TextureAlign
= result
[0];
521 fxMesa
->Glide
.State
= NULL
;
522 fxMesa
->Glide
.grGet( GR_GLIDE_STATE_SIZE
, sizeof(FxI32
), result
);
523 fxMesa
->Glide
.State
= MALLOC( result
[0] );
525 fxMesa
->Fog
.Table
= NULL
;
526 fxMesa
->Glide
.grGet( GR_FOG_TABLE_ENTRIES
, sizeof(FxI32
), result
);
527 fxMesa
->Fog
.Table
= MALLOC( result
[0] * sizeof(GrFog_t
) );
529 UNLOCK_HARDWARE( fxMesa
);
531 if ( !fxMesa
->Glide
.State
|| !fxMesa
->Fog
.Table
) {
532 if ( fxMesa
->Glide
.State
)
533 FREE( fxMesa
->Glide
.State
);
534 if ( fxMesa
->Fog
.Table
)
535 FREE( fxMesa
->Fog
.Table
);
539 if ( !tdfxInitVertexFormats( fxMesa
) ) {
543 LOCK_HARDWARE( fxMesa
);
545 fxMesa
->Glide
.grGlideGetState( fxMesa
->Glide
.State
);
547 if ( getenv( "FX_GLIDE_INFO" ) ) {
548 printf( "GR_RENDERER = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_RENDERER
) );
549 printf( "GR_VERSION = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_VERSION
) );
550 printf( "GR_VENDOR = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_VENDOR
) );
551 printf( "GR_HARDWARE = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_HARDWARE
) );
552 printf( "GR_EXTENSION = %s\n", (char *) gext
);
555 UNLOCK_HARDWARE( fxMesa
);
557 fxMesa
->numClipRects
= 0;
558 fxMesa
->pClipRects
= NULL
;
559 fxMesa
->scissoredClipRects
= GL_FALSE
;
561 fxMesa
->Glide
.Initialized
= GL_TRUE
;
568 tdfxDestroyContext( __DRIcontextPrivate
*driContextPriv
)
570 tdfxContextPtr fxMesa
= (tdfxContextPtr
) driContextPriv
->driverPrivate
;
572 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
573 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)fxMesa
);
577 if (fxMesa
->glCtx
->Shared
->RefCount
== 1 && fxMesa
->driDrawable
) {
578 /* This share group is about to go away, free our private
579 * texture object data.
581 struct _mesa_HashTable
*textures
= fxMesa
->glCtx
->Shared
->TexObjects
;
583 for (id
= _mesa_HashFirstEntry(textures
);
585 id
= _mesa_HashNextEntry(textures
, id
)) {
586 struct gl_texture_object
*tObj
587 = _mesa_lookup_texture(fxMesa
->glCtx
, id
);
588 tdfxTMFreeTexture(fxMesa
, tObj
);
592 tdfxTMClose(fxMesa
); /* free texture memory */
594 _swsetup_DestroyContext( fxMesa
->glCtx
);
595 _tnl_DestroyContext( fxMesa
->glCtx
);
596 _vbo_DestroyContext( fxMesa
->glCtx
);
597 _swrast_DestroyContext( fxMesa
->glCtx
);
599 tdfxFreeVB( fxMesa
->glCtx
);
601 /* Free Mesa context */
602 fxMesa
->glCtx
->DriverCtx
= NULL
;
603 _mesa_destroy_context(fxMesa
->glCtx
);
605 /* free the tdfx context */
612 tdfxUnbindContext( __DRIcontextPrivate
*driContextPriv
)
614 GET_CURRENT_CONTEXT(ctx
);
615 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
617 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
618 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)driContextPriv
);
621 if ( driContextPriv
&& (tdfxContextPtr
) driContextPriv
== fxMesa
) {
622 LOCK_HARDWARE(fxMesa
);
623 fxMesa
->Glide
.grGlideGetState(fxMesa
->Glide
.State
);
624 UNLOCK_HARDWARE(fxMesa
);
631 tdfxMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
632 __DRIdrawablePrivate
*driDrawPriv
,
633 __DRIdrawablePrivate
*driReadPriv
)
635 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
636 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)driContextPriv
);
639 if ( driContextPriv
) {
640 tdfxContextPtr newFx
= (tdfxContextPtr
) driContextPriv
->driverPrivate
;
641 GLcontext
*newCtx
= newFx
->glCtx
;
642 GET_CURRENT_CONTEXT(curCtx
);
644 if ((newFx
->driDrawable
!= driDrawPriv
)
645 || (newFx
->driReadable
!= driReadPriv
)) {
646 newFx
->driDrawable
= driDrawPriv
;
647 newFx
->driReadable
= driReadPriv
;
651 if (curCtx
== newCtx
) {
652 /* same drawable, same context -> no-op */
653 /* Need to call _mesa_make_current2() in order to make sure API
654 * dispatch is set correctly.
656 _mesa_make_current( newCtx
,
657 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
658 (GLframebuffer
*) driReadPriv
->driverPrivate
);
661 /* [dBorca] tunnel2 requires this */
665 driUpdateFramebufferSize(newCtx
, driDrawPriv
);
666 if (driDrawPriv
!= driReadPriv
) {
667 driUpdateFramebufferSize(newCtx
, driReadPriv
);
670 if ( !newFx
->Glide
.Initialized
) {
671 if ( !tdfxInitContext( driDrawPriv
, newFx
) )
674 LOCK_HARDWARE( newFx
);
676 /* FIXME: Force loading of window information */
678 tdfxUpdateClipping(newCtx
);
679 tdfxUploadClipping(newFx
);
681 UNLOCK_HARDWARE( newFx
);
683 LOCK_HARDWARE( newFx
);
685 newFx
->Glide
.grSstSelect( newFx
->Glide
.Board
);
686 newFx
->Glide
.grGlideSetState( newFx
->Glide
.State
);
688 tdfxUpdateClipping(newCtx
);
689 tdfxUploadClipping(newFx
);
691 UNLOCK_HARDWARE( newFx
);
694 _mesa_make_current( newCtx
,
695 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
696 (GLframebuffer
*) driReadPriv
->driverPrivate
);
698 _mesa_make_current( NULL
, NULL
, NULL
);
706 * Enable this to trace calls to various Glide functions.
708 /*#define DEBUG_TRAP*/
710 static void (*real_grDrawTriangle
)( const void *a
, const void *b
, const void *c
);
711 static void (*real_grDrawPoint
)( const void *a
);
712 static void (*real_grDrawVertexArray
)(FxU32 mode
, FxU32 Count
, void *pointers
);
713 static void (*real_grDrawVertexArrayContiguous
)(FxU32 mode
, FxU32 Count
,
714 void *pointers
, FxU32 stride
);
715 static void (*real_grClipWindow
)( FxU32 minx
, FxU32 miny
, FxU32 maxx
, FxU32 maxy
);
717 static void (*real_grVertexLayout
)(FxU32 param
, FxI32 offset
, FxU32 mode
);
718 static void (*real_grGlideGetVertexLayout
)( void *layout
);
719 static void (*real_grGlideSetVertexLayout
)( const void *layout
);
721 static void (*real_grTexDownloadMipMapLevel
)( GrChipID_t tmu
,
725 GrAspectRatio_t aspectRatio
,
726 GrTextureFormat_t format
,
731 static void debug_grDrawTriangle( const void *a
, const void *b
, const void *c
)
733 printf("%s\n", __FUNCTION__
);
734 (*real_grDrawTriangle
)(a
, b
, c
);
737 static void debug_grDrawPoint( const void *a
)
739 const float *f
= (const float *) a
;
740 printf("%s %g %g\n", __FUNCTION__
, f
[0], f
[1]);
741 (*real_grDrawPoint
)(a
);
744 static void debug_grDrawVertexArray(FxU32 mode
, FxU32 Count
, void *pointers
)
746 printf("%s count=%d\n", __FUNCTION__
, (int) Count
);
747 (*real_grDrawVertexArray
)(mode
, Count
, pointers
);
750 static void debug_grDrawVertexArrayContiguous(FxU32 mode
, FxU32 Count
,
751 void *pointers
, FxU32 stride
)
753 printf("%s mode=0x%x count=%d\n", __FUNCTION__
, (int) mode
, (int) Count
);
754 (*real_grDrawVertexArrayContiguous
)(mode
, Count
, pointers
, stride
);
757 static void debug_grClipWindow( FxU32 minx
, FxU32 miny
, FxU32 maxx
, FxU32 maxy
)
759 printf("%s %d,%d .. %d,%d\n", __FUNCTION__
,
760 (int) minx
, (int) miny
, (int) maxx
, (int) maxy
);
761 (*real_grClipWindow
)(minx
, miny
, maxx
, maxy
);
764 static void debug_grVertexLayout(FxU32 param
, FxI32 offset
, FxU32 mode
)
766 (*real_grVertexLayout
)(param
, offset
, mode
);
769 static void debug_grGlideGetVertexLayout( void *layout
)
771 (*real_grGlideGetVertexLayout
)(layout
);
774 static void debug_grGlideSetVertexLayout( const void *layout
)
776 (*real_grGlideSetVertexLayout
)(layout
);
779 static void debug_grTexDownloadMipMapLevel( GrChipID_t tmu
,
783 GrAspectRatio_t aspectRatio
,
784 GrTextureFormat_t format
,
788 (*real_grTexDownloadMipMapLevel
)(tmu
, startAddress
, thisLod
, largeLod
,
789 aspectRatio
, format
, evenOdd
, data
);
796 * Examine the context's deviceID to determine what kind of 3dfx hardware
797 * is installed. dlopen() the appropriate Glide library and initialize
798 * this context's Glide function pointers.
799 * Return: true/false = success/failure
801 GLboolean
tdfxInitGlide(tdfxContextPtr tmesa
)
803 static const char *defaultGlide
= "libglide3.so";
808 * XXX this code which selects a Glide library filename given the
809 * deviceID may need to be cleaned up a bit.
810 * Non-Linux systems may have different filenames, for example.
812 switch (tmesa
->fxScreen
->deviceID
) {
813 case PCI_CHIP_BANSHEE
:
814 case PCI_CHIP_VOODOO3
:
815 libName
= "libglide3-v3.so";
817 case PCI_CHIP_VOODOO5
: /* same as PCI_CHIP_VOODOO4 */
818 libName
= "libglide3-v5.so";
822 __driUtilMessage("unrecognized 3dfx deviceID: 0x%x",
823 tmesa
->fxScreen
->deviceID
);
828 libHandle
= dlopen(libName
, RTLD_NOW
);
830 /* The device-specific Glide library filename didn't work, try the
831 * old, generic libglide3.so library.
833 libHandle
= dlopen(defaultGlide
, RTLD_NOW
);
836 "can't find Glide library, dlopen(%s) and dlopen(%s) both failed.",
837 libName
, defaultGlide
);
838 __driUtilMessage("dlerror() message: %s", dlerror());
841 libName
= defaultGlide
;
845 const char *env
= getenv("LIBGL_DEBUG");
846 if (env
&& strstr(env
, "verbose")) {
847 fprintf(stderr
, "libGL: using Glide library %s\n", libName
);
851 #define GET_FUNCTION(PTR, NAME) \
852 tmesa->Glide.PTR = dlsym(libHandle, NAME); \
853 if (!tmesa->Glide.PTR) { \
854 __driUtilMessage("couldn't find Glide function %s in %s.", \
858 GET_FUNCTION(grDrawPoint
, "grDrawPoint");
859 GET_FUNCTION(grDrawLine
, "grDrawLine");
860 GET_FUNCTION(grDrawTriangle
, "grDrawTriangle");
861 GET_FUNCTION(grVertexLayout
, "grVertexLayout");
862 GET_FUNCTION(grDrawVertexArray
, "grDrawVertexArray");
863 GET_FUNCTION(grDrawVertexArrayContiguous
, "grDrawVertexArrayContiguous");
864 GET_FUNCTION(grBufferClear
, "grBufferClear");
865 /*GET_FUNCTION(grBufferSwap, "grBufferSwap");*/
866 GET_FUNCTION(grRenderBuffer
, "grRenderBuffer");
867 GET_FUNCTION(grErrorSetCallback
, "grErrorSetCallback");
868 GET_FUNCTION(grFinish
, "grFinish");
869 GET_FUNCTION(grFlush
, "grFlush");
870 GET_FUNCTION(grSstWinOpen
, "grSstWinOpen");
871 GET_FUNCTION(grSstWinClose
, "grSstWinClose");
873 /* Not in V3 lib, and not used anyway. */
874 GET_FUNCTION(grSetNumPendingBuffers
, "grSetNumPendingBuffers");
876 GET_FUNCTION(grSelectContext
, "grSelectContext");
877 GET_FUNCTION(grSstOrigin
, "grSstOrigin");
878 GET_FUNCTION(grSstSelect
, "grSstSelect");
879 GET_FUNCTION(grAlphaBlendFunction
, "grAlphaBlendFunction");
880 GET_FUNCTION(grAlphaCombine
, "grAlphaCombine");
881 GET_FUNCTION(grAlphaControlsITRGBLighting
, "grAlphaControlsITRGBLighting");
882 GET_FUNCTION(grAlphaTestFunction
, "grAlphaTestFunction");
883 GET_FUNCTION(grAlphaTestReferenceValue
, "grAlphaTestReferenceValue");
884 GET_FUNCTION(grChromakeyMode
, "grChromakeyMode");
885 GET_FUNCTION(grChromakeyValue
, "grChromakeyValue");
886 GET_FUNCTION(grClipWindow
, "grClipWindow");
887 GET_FUNCTION(grColorCombine
, "grColorCombine");
888 GET_FUNCTION(grColorMask
, "grColorMask");
889 GET_FUNCTION(grCullMode
, "grCullMode");
890 GET_FUNCTION(grConstantColorValue
, "grConstantColorValue");
891 GET_FUNCTION(grDepthBiasLevel
, "grDepthBiasLevel");
892 GET_FUNCTION(grDepthBufferFunction
, "grDepthBufferFunction");
893 GET_FUNCTION(grDepthBufferMode
, "grDepthBufferMode");
894 GET_FUNCTION(grDepthMask
, "grDepthMask");
895 GET_FUNCTION(grDisableAllEffects
, "grDisableAllEffects");
896 GET_FUNCTION(grDitherMode
, "grDitherMode");
897 GET_FUNCTION(grFogColorValue
, "grFogColorValue");
898 GET_FUNCTION(grFogMode
, "grFogMode");
899 GET_FUNCTION(grFogTable
, "grFogTable");
900 GET_FUNCTION(grLoadGammaTable
, "grLoadGammaTable");
901 GET_FUNCTION(grSplash
, "grSplash");
902 GET_FUNCTION(grGet
, "grGet");
903 GET_FUNCTION(grGetString
, "grGetString");
904 GET_FUNCTION(grQueryResolutions
, "grQueryResolutions");
905 GET_FUNCTION(grReset
, "grReset");
906 GET_FUNCTION(grGetProcAddress
, "grGetProcAddress");
907 GET_FUNCTION(grEnable
, "grEnable");
908 GET_FUNCTION(grDisable
, "grDisable");
909 GET_FUNCTION(grCoordinateSpace
, "grCoordinateSpace");
910 GET_FUNCTION(grDepthRange
, "grDepthRange");
911 GET_FUNCTION(grStippleMode
, "grStippleMode");
912 GET_FUNCTION(grStipplePattern
, "grStipplePattern");
913 GET_FUNCTION(grViewport
, "grViewport");
914 GET_FUNCTION(grTexCalcMemRequired
, "grTexCalcMemRequired");
915 GET_FUNCTION(grTexTextureMemRequired
, "grTexTextureMemRequired");
916 GET_FUNCTION(grTexMinAddress
, "grTexMinAddress");
917 GET_FUNCTION(grTexMaxAddress
, "grTexMaxAddress");
918 GET_FUNCTION(grTexNCCTable
, "grTexNCCTable");
919 GET_FUNCTION(grTexSource
, "grTexSource");
920 GET_FUNCTION(grTexClampMode
, "grTexClampMode");
921 GET_FUNCTION(grTexCombine
, "grTexCombine");
922 GET_FUNCTION(grTexDetailControl
, "grTexDetailControl");
923 GET_FUNCTION(grTexFilterMode
, "grTexFilterMode");
924 GET_FUNCTION(grTexLodBiasValue
, "grTexLodBiasValue");
925 GET_FUNCTION(grTexDownloadMipMap
, "grTexDownloadMipMap");
926 GET_FUNCTION(grTexDownloadMipMapLevel
, "grTexDownloadMipMapLevel");
927 GET_FUNCTION(grTexDownloadMipMapLevelPartial
, "grTexDownloadMipMapLevelPartial");
928 GET_FUNCTION(grTexDownloadTable
, "grTexDownloadTable");
929 GET_FUNCTION(grTexDownloadTablePartial
, "grTexDownloadTablePartial");
930 GET_FUNCTION(grTexMipMapMode
, "grTexMipMapMode");
931 GET_FUNCTION(grTexMultibase
, "grTexMultibase");
932 GET_FUNCTION(grTexMultibaseAddress
, "grTexMultibaseAddress");
933 GET_FUNCTION(grLfbLock
, "grLfbLock");
934 GET_FUNCTION(grLfbUnlock
, "grLfbUnlock");
935 GET_FUNCTION(grLfbConstantAlpha
, "grLfbConstantAlpha");
936 GET_FUNCTION(grLfbConstantDepth
, "grLfbConstantDepth");
937 GET_FUNCTION(grLfbWriteColorSwizzle
, "grLfbWriteColorSwizzle");
938 GET_FUNCTION(grLfbWriteColorFormat
, "grLfbWriteColorFormat");
939 GET_FUNCTION(grLfbWriteRegion
, "grLfbWriteRegion");
940 GET_FUNCTION(grLfbReadRegion
, "grLfbReadRegion");
941 GET_FUNCTION(grGlideInit
, "grGlideInit");
942 GET_FUNCTION(grGlideShutdown
, "grGlideShutdown");
943 GET_FUNCTION(grGlideGetState
, "grGlideGetState");
944 GET_FUNCTION(grGlideSetState
, "grGlideSetState");
945 GET_FUNCTION(grGlideGetVertexLayout
, "grGlideGetVertexLayout");
946 GET_FUNCTION(grGlideSetVertexLayout
, "grGlideSetVertexLayout");
948 /* Glide utility functions */
949 GET_FUNCTION(guFogGenerateExp
, "guFogGenerateExp");
950 GET_FUNCTION(guFogGenerateExp2
, "guFogGenerateExp2");
951 GET_FUNCTION(guFogGenerateLinear
, "guFogGenerateLinear");
954 GET_FUNCTION(grDRIOpen
, "grDRIOpen");
955 GET_FUNCTION(grDRIPosition
, "grDRIPosition");
956 /*GET_FUNCTION(grDRILostContext, "grDRILostContext");*/
957 GET_FUNCTION(grDRIImportFifo
, "grDRIImportFifo");
958 GET_FUNCTION(grDRIInvalidateAll
, "grDRIInvalidateAll");
959 GET_FUNCTION(grDRIResetSAREA
, "grDRIResetSAREA");
960 GET_FUNCTION(grDRIBufferSwap
, "grDRIBufferSwap");
963 * Extension functions:
964 * Just use dlysm() because we want a NULL pointer if the function is
967 /* PIXEXT extension */
968 tmesa
->Glide
.grStencilFunc
= dlsym(libHandle
, "grStencilFunc");
969 tmesa
->Glide
.grStencilMask
= dlsym(libHandle
, "grStencilMask");
970 tmesa
->Glide
.grStencilOp
= dlsym(libHandle
, "grStencilOp");
971 tmesa
->Glide
.grBufferClearExt
= dlsym(libHandle
, "grBufferClearExt");
972 tmesa
->Glide
.grColorMaskExt
= dlsym(libHandle
, "grColorMaskExt");
973 /* COMBINE extension */
974 tmesa
->Glide
.grColorCombineExt
= dlsym(libHandle
, "grColorCombineExt");
975 tmesa
->Glide
.grTexColorCombineExt
= dlsym(libHandle
, "grTexColorCombineExt");
976 tmesa
->Glide
.grAlphaCombineExt
= dlsym(libHandle
, "grAlphaCombineExt");
977 tmesa
->Glide
.grTexAlphaCombineExt
= dlsym(libHandle
, "grTexAlphaCombineExt");
978 tmesa
->Glide
.grAlphaBlendFunctionExt
= dlsym(libHandle
, "grAlphaBlendFunctionExt");
979 tmesa
->Glide
.grConstantColorValueExt
= dlsym(libHandle
, "grConstantColorValueExt");
981 tmesa
->Glide
.txImgQuantize
= dlsym(libHandle
, "txImgQuantize");
982 tmesa
->Glide
.txImgDequantizeFXT1
= dlsym(libHandle
, "_txImgDequantizeFXT1");
983 tmesa
->Glide
.txErrorSetCallback
= dlsym(libHandle
, "txErrorSetCallback");
986 /* wrap the drawing functions so we can trap them */
987 real_grDrawTriangle
= tmesa
->Glide
.grDrawTriangle
;
988 tmesa
->Glide
.grDrawTriangle
= debug_grDrawTriangle
;
990 real_grDrawPoint
= tmesa
->Glide
.grDrawPoint
;
991 tmesa
->Glide
.grDrawPoint
= debug_grDrawPoint
;
993 real_grDrawVertexArray
= tmesa
->Glide
.grDrawVertexArray
;
994 tmesa
->Glide
.grDrawVertexArray
= debug_grDrawVertexArray
;
996 real_grDrawVertexArrayContiguous
= tmesa
->Glide
.grDrawVertexArrayContiguous
;
997 tmesa
->Glide
.grDrawVertexArrayContiguous
= debug_grDrawVertexArrayContiguous
;
999 real_grClipWindow
= tmesa
->Glide
.grClipWindow
;
1000 tmesa
->Glide
.grClipWindow
= debug_grClipWindow
;
1002 real_grVertexLayout
= tmesa
->Glide
.grVertexLayout
;
1003 tmesa
->Glide
.grVertexLayout
= debug_grVertexLayout
;
1005 real_grGlideGetVertexLayout
= tmesa
->Glide
.grGlideGetVertexLayout
;
1006 tmesa
->Glide
.grGlideGetVertexLayout
= debug_grGlideGetVertexLayout
;
1008 real_grGlideSetVertexLayout
= tmesa
->Glide
.grGlideSetVertexLayout
;
1009 tmesa
->Glide
.grGlideSetVertexLayout
= debug_grGlideSetVertexLayout
;
1011 real_grTexDownloadMipMapLevel
= tmesa
->Glide
.grTexDownloadMipMapLevel
;
1012 tmesa
->Glide
.grTexDownloadMipMapLevel
= debug_grTexDownloadMipMapLevel
;