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
26 /* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/tdfx_context.c,v 1.12 2003/05/08 09:25:35 herrb Exp $ */
30 * Daniel Borca <dborca@users.sourceforge.net>, 19 Jul 2004
33 * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
36 * Gareth Hughes <gareth@valinux.com>
37 * Brian Paul <brianp@valinux.com>
42 #include "tdfx_context.h"
44 #include "tdfx_state.h"
47 #include "tdfx_tris.h"
48 #include "tdfx_render.h"
49 #include "tdfx_span.h"
50 #include "tdfx_texman.h"
51 #include "extensions.h"
53 #include "swrast/swrast.h"
54 #include "swrast_setup/swrast_setup.h"
55 #include "array_cache/acache.h"
58 #include "tnl/t_pipeline.h"
60 #include "drivers/common/driverfuncs.h"
64 const char __driConfigOptions
[] = { 0 };
65 const GLuint __driNConfigOptions
= 0;
68 * Common extension strings exported by all cards
70 static const char * const card_extensions
[] =
72 "GL_ARB_texture_mirrored_repeat",
73 "GL_ARB_vertex_buffer_object",
74 "GL_EXT_blend_func_separate",
76 "GL_EXT_multi_draw_arrays",
77 "GL_EXT_paletted_texture",
78 "GL_EXT_shared_texture_palette",
79 "GL_EXT_stencil_wrap",
80 "GL_EXT_texture_env_add",
81 "GL_EXT_texture_lod_bias",
82 "GL_HP_occlusion_test",
83 "GL_IBM_multimode_draw_arrays",
86 "GL_ARB_point_sprite",
87 "GL_EXT_point_parameters",
88 "GL_EXT_secondary_color",
92 "GL_ARB_vertex_program",
93 "GL_NV_vertex_program",
94 "GL_NV_vertex_program1_1",
95 "GL_MESA_program_debug",
101 * Extension strings exported only by Naplam (e.g., Voodoo4 & Voodoo5) cards.
103 static const char * const napalm_extensions
[] =
105 "GL_ARB_texture_compression",
106 "GL_ARB_texture_env_combine",
107 "GL_EXT_blend_equation_separate",
108 "GL_EXT_blend_subtract",
109 "GL_EXT_texture_compression_s3tc",
110 "GL_EXT_texture_env_combine",
112 "GL_3DFX_texture_compression_FXT1",
113 "GL_NV_blend_square",
119 * Enable/Disable the extensions for this context.
121 static void tdfxDDInitExtensions( GLcontext
*ctx
)
123 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
125 driInitExtensions( ctx
, card_extensions
, GL_FALSE
);
127 if ( fxMesa
->haveTwoTMUs
) {
128 _mesa_enable_extension( ctx
, "GL_ARB_multitexture" );
131 if ( TDFX_IS_NAPALM( fxMesa
) ) {
132 driInitExtensions( ctx
, napalm_extensions
, GL_FALSE
);
134 _mesa_enable_extension( ctx
, "GL_SGIS_generate_mipmap" );
140 static const struct tnl_pipeline_stage
*tdfx_pipeline
[] = {
141 &_tnl_vertex_transform_stage
,
142 &_tnl_normal_transform_stage
,
143 &_tnl_lighting_stage
,
144 &_tnl_fog_coordinate_stage
,
146 &_tnl_texture_transform_stage
,
147 &_tnl_point_attenuation_stage
,
149 #if defined(FEATURE_NV_vertex_program) || defined(FEATURE_ARB_vertex_program)
150 &_tnl_vertex_program_stage
,
158 GLboolean
tdfxCreateContext( const __GLcontextModes
*mesaVis
,
159 __DRIcontextPrivate
*driContextPriv
,
160 void *sharedContextPrivate
)
162 tdfxContextPtr fxMesa
;
163 GLcontext
*ctx
, *shareCtx
;
164 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
165 tdfxScreenPrivate
*fxScreen
= (tdfxScreenPrivate
*) sPriv
->private;
166 TDFXSAREAPriv
*saPriv
= (TDFXSAREAPriv
*) ((char *) sPriv
->pSAREA
+
167 sizeof(drm_sarea_t
));
168 struct dd_function_table functions
;
170 /* Allocate tdfx context */
171 fxMesa
= (tdfxContextPtr
) CALLOC( sizeof(tdfxContextRec
) );
175 /* Init default driver functions then plug in our tdfx-specific functions
176 * (the texture functions are especially important)
178 _mesa_init_driver_functions(&functions
);
179 tdfxDDInitDriverFuncs(mesaVis
, &functions
);
180 tdfxInitTextureFuncs(&functions
);
181 tdfxInitRenderFuncs(&functions
);
183 /* Allocate the Mesa context */
184 if (sharedContextPrivate
)
185 shareCtx
= ((tdfxContextPtr
) sharedContextPrivate
)->glCtx
;
189 fxMesa
->glCtx
= _mesa_create_context(mesaVis
, shareCtx
,
190 &functions
, (void *) fxMesa
);
191 if (!fxMesa
->glCtx
) {
195 driContextPriv
->driverPrivate
= fxMesa
;
197 /* Mirror some important DRI state
199 fxMesa
->hHWContext
= driContextPriv
->hHWContext
;
200 fxMesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
201 fxMesa
->driFd
= sPriv
->fd
;
203 fxMesa
->driScreen
= sPriv
;
204 fxMesa
->driContext
= driContextPriv
;
205 fxMesa
->fxScreen
= fxScreen
;
206 fxMesa
->sarea
= saPriv
;
209 fxMesa
->haveHwAlpha
= ( mesaVis
->alphaBits
&&
210 ((mesaVis
->greenBits
== 8) ||
211 (mesaVis
->depthBits
== 0)) );
212 fxMesa
->haveHwStencil
= ( TDFX_IS_NAPALM( fxMesa
) &&
213 mesaVis
->stencilBits
&&
214 mesaVis
->depthBits
== 24 );
216 fxMesa
->screen_width
= fxScreen
->width
;
217 fxMesa
->screen_height
= fxScreen
->height
;
219 fxMesa
->new_gl_state
= ~0;
220 fxMesa
->new_state
= ~0;
223 /* NOTE: This must be here before any Glide calls! */
224 if (!tdfxInitGlide( fxMesa
)) {
229 fxMesa
->Glide
.grDRIOpen( (char*) sPriv
->pFB
, fxScreen
->regs
.map
, fxScreen
->deviceID
,
230 fxScreen
->width
, fxScreen
->height
, fxScreen
->mem
, fxScreen
->cpp
,
231 fxScreen
->stride
, fxScreen
->fifoOffset
, fxScreen
->fifoSize
,
232 fxScreen
->fbOffset
, fxScreen
->backOffset
, fxScreen
->depthOffset
,
233 fxScreen
->textureOffset
, fxScreen
->textureSize
, &saPriv
->fifoPtr
,
236 if ( getenv( "FX_GLIDE_SWAPINTERVAL" ) ) {
237 fxMesa
->Glide
.SwapInterval
= atoi( getenv( "FX_GLIDE_SWAPINTERVAL" ) );
239 fxMesa
->Glide
.SwapInterval
= 0;
241 if ( getenv( "FX_MAX_PENDING_SWAPS" ) ) {
242 fxMesa
->Glide
.MaxPendingSwaps
= atoi( getenv( "FX_MAX_PENDING_SWAPS" ) );
244 fxMesa
->Glide
.MaxPendingSwaps
= 2;
247 fxMesa
->Glide
.Initialized
= GL_FALSE
;
248 fxMesa
->Glide
.Board
= 0;
251 if (getenv("FX_EMULATE_SINGLE_TMU")) {
252 fxMesa
->haveTwoTMUs
= GL_FALSE
;
255 if ( TDFX_IS_BANSHEE( fxMesa
) ) {
256 fxMesa
->haveTwoTMUs
= GL_FALSE
;
258 fxMesa
->haveTwoTMUs
= GL_TRUE
;
262 fxMesa
->stats
.swapBuffer
= 0;
263 fxMesa
->stats
.reqTexUpload
= 0;
264 fxMesa
->stats
.texUpload
= 0;
265 fxMesa
->stats
.memTexUpload
= 0;
267 fxMesa
->tmuSrc
= TDFX_TMU_NONE
;
270 if ( TDFX_IS_NAPALM( fxMesa
) ) {
271 ctx
->Const
.MaxTextureLevels
= 12;
273 ctx
->Const
.MaxTextureLevels
= 9;
275 ctx
->Const
.MaxTextureUnits
= TDFX_IS_BANSHEE( fxMesa
) ? 1 : 2;
276 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
277 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
281 ctx
->Const
.MinPointSize
= 1.0;
282 ctx
->Const
.MinPointSizeAA
= 1.0;
283 ctx
->Const
.MaxPointSize
= 1.0;
284 ctx
->Const
.MaxPointSizeAA
= 1.0;
286 /* Disable wide lines as we can't antialias them correctly in
289 ctx
->Const
.MinLineWidth
= 1.0;
290 ctx
->Const
.MinLineWidthAA
= 1.0;
291 ctx
->Const
.MaxLineWidth
= 1.0;
292 ctx
->Const
.MaxLineWidthAA
= 1.0;
293 ctx
->Const
.LineWidthGranularity
= 1.0;
295 /* Initialize the software rasterizer and helper modules.
297 _swrast_CreateContext( ctx
);
298 _ac_CreateContext( ctx
);
299 _tnl_CreateContext( ctx
);
300 _swsetup_CreateContext( ctx
);
302 /* Install the customized pipeline:
304 _tnl_destroy_pipeline( ctx
);
305 _tnl_install_pipeline( ctx
, tdfx_pipeline
);
307 /* Configure swrast and T&L to match hardware characteristics:
309 _swrast_allow_pixel_fog( ctx
, GL_TRUE
);
310 _swrast_allow_vertex_fog( ctx
, GL_FALSE
);
311 _tnl_allow_pixel_fog( ctx
, GL_TRUE
);
312 _tnl_allow_vertex_fog( ctx
, GL_FALSE
);
314 tdfxDDInitExtensions( ctx
);
315 /* XXX these should really go right after _mesa_init_driver_functions() */
316 tdfxDDInitSpanFuncs( ctx
);
317 tdfxDDInitStateFuncs( ctx
);
318 tdfxDDInitTriFuncs( ctx
);
320 tdfxInitState( fxMesa
);
326 static GLboolean
tdfxInitVertexFormats( tdfxContextPtr fxMesa
)
331 LOCK_HARDWARE( fxMesa
);
333 fxMesa
->Glide
.grGet( GR_GLIDE_VERTEXLAYOUT_SIZE
, sizeof(FxI32
), &result
);
334 for ( i
= 0 ; i
< TDFX_NUM_LAYOUTS
; i
++ ) {
335 fxMesa
->layout
[i
] = MALLOC( result
);
336 if ( !fxMesa
->layout
[i
] ) {
337 UNLOCK_HARDWARE( fxMesa
);
342 /* Tiny vertex format - 16 bytes.
344 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
345 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
346 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
347 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
348 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
349 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_TINY
] );
351 /* Non textured vertex format - 24 bytes (Need w for table fog)
353 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
354 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
355 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
356 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
357 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
358 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
359 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_NOTEX
] );
361 /* Single textured vertex format - 32 bytes.
363 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
364 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
365 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
366 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
367 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
368 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
369 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
370 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_SINGLE
] );
372 /* Multitextured vertex format - 40 bytes.
374 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
375 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
376 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
377 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
378 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
379 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
380 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
381 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST1
, TDFX_ST1_OFFSET
, GR_PARAM_ENABLE
);
382 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_MULTI
] );
384 /* Projected texture vertex format - 36 bytes.
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
.grVertexLayout( GR_PARAM_Q0
, TDFX_Q0_OFFSET
, GR_PARAM_ENABLE
);
394 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_PROJ1
] );
396 /* Projected multitexture vertex format - 48 bytes.
398 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
399 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
400 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
401 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
402 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
403 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
404 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
405 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q0
, TDFX_Q0_OFFSET
, GR_PARAM_ENABLE
);
406 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST1
, TDFX_ST1_OFFSET
, GR_PARAM_ENABLE
);
407 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q1
, TDFX_Q1_OFFSET
, GR_PARAM_ENABLE
);
408 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_PROJ2
] );
410 UNLOCK_HARDWARE( fxMesa
);
417 * Initialize the state in an tdfxContextPtr struct.
420 tdfxInitContext( __DRIdrawablePrivate
*driDrawPriv
, tdfxContextPtr fxMesa
)
422 /* KW: Would be nice to make one of these a member of the other.
427 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
428 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)fxMesa
);
432 fprintf(stderr
, "Debug locking enabled\n");
435 if ( fxMesa
->Glide
.Initialized
)
438 fxMesa
->width
= driDrawPriv
->w
;
439 fxMesa
->height
= driDrawPriv
->h
;
441 /* We have to use a light lock here, because we can't do any glide
442 * operations yet. No use of FX_* functions in this function.
444 DRM_LIGHT_LOCK( fxMesa
->driFd
, fxMesa
->driHwLock
, fxMesa
->hHWContext
);
446 fxMesa
->Glide
.grGlideInit();
447 fxMesa
->Glide
.grSstSelect( fxMesa
->Glide
.Board
);
449 fxMesa
->Glide
.Context
= fxMesa
->Glide
.grSstWinOpen( (FxU32
) -1,
452 fxMesa
->Glide
.ColorFormat
,
453 fxMesa
->Glide
.Origin
,
456 fxMesa
->Glide
.grDRIResetSAREA();
458 DRM_UNLOCK( fxMesa
->driFd
, fxMesa
->driHwLock
, fxMesa
->hHWContext
);
460 if ( !fxMesa
->Glide
.Context
)
464 /* Perform the Glide-dependant part of the context initialization.
466 FX_grColorMaskv( fxMesa
->glCtx
, true4
);
468 tdfxTMInit( fxMesa
);
470 LOCK_HARDWARE( fxMesa
);
472 /* JJJ - COMMAND_TRANSPORT, PALETTE6666 */
473 gext
= fxMesa
->Glide
.grGetString( GR_EXTENSION
);
474 fxMesa
->Glide
.HaveCombineExt
= strstr(gext
, "COMBINE") && !getenv("MESA_FX_IGNORE_CMBEXT");
475 fxMesa
->Glide
.HaveCommandTransportExt
= GL_FALSE
;
476 fxMesa
->Glide
.HaveFogCoordExt
= GL_TRUE
;
477 fxMesa
->Glide
.HavePixelExt
= strstr(gext
, "PIXEXT") && !getenv("MESA_FX_IGNORE_PIXEXT");
478 fxMesa
->Glide
.HaveTextureBufferExt
= GL_TRUE
;
479 fxMesa
->Glide
.HaveTexFmtExt
= strstr(gext
, "TEXFMT") && !getenv("MESA_FX_IGNORE_TEXFMT");
480 fxMesa
->Glide
.HaveTexUMAExt
= strstr(gext
, "TEXUMA") && !getenv("MESA_FX_IGNORE_TEXUMA");
481 fxMesa
->Glide
.HaveMirrorExt
= strstr(gext
, "TEXMIRROR") && !getenv("MESA_FX_IGNORE_MIREXT");
482 fxMesa
->Glide
.HaveTexus2
= GL_FALSE
;
484 if ( fxMesa
->glCtx
->Visual
.depthBits
> 0 ) {
485 fxMesa
->Glide
.grDepthBufferMode(GR_DEPTHBUFFER_ZBUFFER
);
487 fxMesa
->Glide
.grDepthBufferMode(GR_DEPTHBUFFER_DISABLE
);
490 fxMesa
->Glide
.grLfbWriteColorFormat( GR_COLORFORMAT_ABGR
);
492 fxMesa
->Glide
.grGet( GR_TEXTURE_ALIGN
, sizeof(FxI32
), result
);
493 fxMesa
->Glide
.TextureAlign
= result
[0];
495 fxMesa
->Glide
.State
= NULL
;
496 fxMesa
->Glide
.grGet( GR_GLIDE_STATE_SIZE
, sizeof(FxI32
), result
);
497 fxMesa
->Glide
.State
= MALLOC( result
[0] );
499 fxMesa
->Fog
.Table
= NULL
;
500 fxMesa
->Glide
.grGet( GR_FOG_TABLE_ENTRIES
, sizeof(FxI32
), result
);
501 fxMesa
->Fog
.Table
= MALLOC( result
[0] * sizeof(GrFog_t
) );
503 UNLOCK_HARDWARE( fxMesa
);
505 if ( !fxMesa
->Glide
.State
|| !fxMesa
->Fog
.Table
) {
506 if ( fxMesa
->Glide
.State
)
507 FREE( fxMesa
->Glide
.State
);
508 if ( fxMesa
->Fog
.Table
)
509 FREE( fxMesa
->Fog
.Table
);
513 if ( !tdfxInitVertexFormats( fxMesa
) ) {
517 LOCK_HARDWARE( fxMesa
);
519 fxMesa
->Glide
.grGlideGetState( fxMesa
->Glide
.State
);
521 if ( getenv( "FX_GLIDE_INFO" ) ) {
522 printf( "GR_RENDERER = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_RENDERER
) );
523 printf( "GR_VERSION = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_VERSION
) );
524 printf( "GR_VENDOR = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_VENDOR
) );
525 printf( "GR_HARDWARE = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_HARDWARE
) );
526 printf( "GR_EXTENSION = %s\n", (char *) gext
);
529 UNLOCK_HARDWARE( fxMesa
);
532 const char *debug
= getenv("LIBGL_DEBUG");
533 if (debug
&& strstr(debug
, "fallbacks")) {
534 fxMesa
->debugFallbacks
= GL_TRUE
;
539 fxMesa
->numClipRects
= 0;
540 fxMesa
->pClipRects
= NULL
;
541 fxMesa
->scissoredClipRects
= GL_FALSE
;
543 fxMesa
->Glide
.Initialized
= GL_TRUE
;
550 tdfxDestroyContext( __DRIcontextPrivate
*driContextPriv
)
552 tdfxContextPtr fxMesa
= (tdfxContextPtr
) driContextPriv
->driverPrivate
;
554 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
555 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)fxMesa
);
559 if (fxMesa
->glCtx
->Shared
->RefCount
== 1 && fxMesa
->driDrawable
) {
560 /* This share group is about to go away, free our private
561 * texture object data.
563 struct gl_texture_object
*tObj
;
564 tObj
= fxMesa
->glCtx
->Shared
->TexObjectList
;
566 tdfxTMFreeTexture(fxMesa
, tObj
);
571 tdfxTMClose(fxMesa
); /* free texture memory */
573 _swsetup_DestroyContext( fxMesa
->glCtx
);
574 _tnl_DestroyContext( fxMesa
->glCtx
);
575 _ac_DestroyContext( fxMesa
->glCtx
);
576 _swrast_DestroyContext( fxMesa
->glCtx
);
578 tdfxFreeVB( fxMesa
->glCtx
);
580 /* Free Mesa context */
581 fxMesa
->glCtx
->DriverCtx
= NULL
;
582 _mesa_destroy_context(fxMesa
->glCtx
);
584 /* free the tdfx context */
591 tdfxUnbindContext( __DRIcontextPrivate
*driContextPriv
)
593 GET_CURRENT_CONTEXT(ctx
);
594 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
596 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
597 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)driContextPriv
);
600 if ( driContextPriv
&& (tdfxContextPtr
) driContextPriv
== fxMesa
) {
601 LOCK_HARDWARE(fxMesa
);
602 fxMesa
->Glide
.grGlideGetState(fxMesa
->Glide
.State
);
603 UNLOCK_HARDWARE(fxMesa
);
610 tdfxMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
611 __DRIdrawablePrivate
*driDrawPriv
,
612 __DRIdrawablePrivate
*driReadPriv
)
614 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
615 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)driContextPriv
);
618 if ( driContextPriv
) {
619 tdfxContextPtr newFx
= (tdfxContextPtr
) driContextPriv
->driverPrivate
;
620 GLcontext
*newCtx
= newFx
->glCtx
;
621 GET_CURRENT_CONTEXT(curCtx
);
623 if ( newFx
->driDrawable
!= driDrawPriv
) {
624 newFx
->driDrawable
= driDrawPriv
;
628 if (curCtx
== newCtx
) {
629 /* same drawable, same context -> no-op */
630 /* Need to call _mesa_make_current2() in order to make sure API
631 * dispatch is set correctly.
633 _mesa_make_current2( newCtx
,
634 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
635 (GLframebuffer
*) driReadPriv
->driverPrivate
);
638 /* [dBorca] tunnel2 requires this */
642 if ( !newFx
->Glide
.Initialized
) {
643 if ( !tdfxInitContext( driDrawPriv
, newFx
) )
646 LOCK_HARDWARE( newFx
);
648 /* FIXME: Force loading of window information */
650 tdfxUpdateClipping(newCtx
);
651 tdfxUploadClipping(newFx
);
653 UNLOCK_HARDWARE( newFx
);
655 LOCK_HARDWARE( newFx
);
657 newFx
->Glide
.grSstSelect( newFx
->Glide
.Board
);
658 newFx
->Glide
.grGlideSetState( newFx
->Glide
.State
);
660 tdfxUpdateClipping(newCtx
);
661 tdfxUploadClipping(newFx
);
663 UNLOCK_HARDWARE( newFx
);
666 _mesa_make_current2( newCtx
,
667 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
668 (GLframebuffer
*) driReadPriv
->driverPrivate
);
670 if ( !newCtx
->Viewport
.Width
) {
671 _mesa_set_viewport( newCtx
, 0, 0, driDrawPriv
->w
, driDrawPriv
->h
);
674 _mesa_make_current( 0, 0 );
682 * Enable this to trace calls to various Glide functions.
684 /*#define DEBUG_TRAP*/
686 static void (*real_grDrawTriangle
)( const void *a
, const void *b
, const void *c
);
687 static void (*real_grDrawPoint
)( const void *a
);
688 static void (*real_grDrawVertexArray
)(FxU32 mode
, FxU32 Count
, void *pointers
);
689 static void (*real_grDrawVertexArrayContiguous
)(FxU32 mode
, FxU32 Count
,
690 void *pointers
, FxU32 stride
);
691 static void (*real_grClipWindow
)( FxU32 minx
, FxU32 miny
, FxU32 maxx
, FxU32 maxy
);
693 static void (*real_grVertexLayout
)(FxU32 param
, FxI32 offset
, FxU32 mode
);
694 static void (*real_grGlideGetVertexLayout
)( void *layout
);
695 static void (*real_grGlideSetVertexLayout
)( const void *layout
);
697 static void (*real_grTexDownloadMipMapLevel
)( GrChipID_t tmu
,
701 GrAspectRatio_t aspectRatio
,
702 GrTextureFormat_t format
,
707 static void debug_grDrawTriangle( const void *a
, const void *b
, const void *c
)
709 printf("%s\n", __FUNCTION__
);
710 (*real_grDrawTriangle
)(a
, b
, c
);
713 static void debug_grDrawPoint( const void *a
)
715 const float *f
= (const float *) a
;
716 printf("%s %g %g\n", __FUNCTION__
, f
[0], f
[1]);
717 (*real_grDrawPoint
)(a
);
720 static void debug_grDrawVertexArray(FxU32 mode
, FxU32 Count
, void *pointers
)
722 printf("%s count=%d\n", __FUNCTION__
, (int) Count
);
723 (*real_grDrawVertexArray
)(mode
, Count
, pointers
);
726 static void debug_grDrawVertexArrayContiguous(FxU32 mode
, FxU32 Count
,
727 void *pointers
, FxU32 stride
)
729 printf("%s mode=0x%x count=%d\n", __FUNCTION__
, (int) mode
, (int) Count
);
730 (*real_grDrawVertexArrayContiguous
)(mode
, Count
, pointers
, stride
);
733 static void debug_grClipWindow( FxU32 minx
, FxU32 miny
, FxU32 maxx
, FxU32 maxy
)
735 printf("%s %d,%d .. %d,%d\n", __FUNCTION__
,
736 (int) minx
, (int) miny
, (int) maxx
, (int) maxy
);
737 (*real_grClipWindow
)(minx
, miny
, maxx
, maxy
);
740 static void debug_grVertexLayout(FxU32 param
, FxI32 offset
, FxU32 mode
)
742 (*real_grVertexLayout
)(param
, offset
, mode
);
745 static void debug_grGlideGetVertexLayout( void *layout
)
747 (*real_grGlideGetVertexLayout
)(layout
);
750 static void debug_grGlideSetVertexLayout( const void *layout
)
752 (*real_grGlideSetVertexLayout
)(layout
);
755 static void debug_grTexDownloadMipMapLevel( GrChipID_t tmu
,
759 GrAspectRatio_t aspectRatio
,
760 GrTextureFormat_t format
,
764 (*real_grTexDownloadMipMapLevel
)(tmu
, startAddress
, thisLod
, largeLod
,
765 aspectRatio
, format
, evenOdd
, data
);
772 * Examine the context's deviceID to determine what kind of 3dfx hardware
773 * is installed. dlopen() the appropriate Glide library and initialize
774 * this context's Glide function pointers.
775 * Return: true/false = success/failure
777 GLboolean
tdfxInitGlide(tdfxContextPtr tmesa
)
779 static const char *defaultGlide
= "libglide3.so";
784 * XXX this code which selects a Glide library filename given the
785 * deviceID may need to be cleaned up a bit.
786 * Non-Linux systems may have different filenames, for example.
788 switch (tmesa
->fxScreen
->deviceID
) {
789 case PCI_CHIP_BANSHEE
:
790 case PCI_CHIP_VOODOO3
:
791 libName
= "libglide3-v3.so";
793 case PCI_CHIP_VOODOO5
: /* same as PCI_CHIP_VOODOO4 */
794 libName
= "libglide3-v5.so";
798 __driUtilMessage("unrecognized 3dfx deviceID: 0x%x",
799 tmesa
->fxScreen
->deviceID
);
804 libHandle
= dlopen(libName
, RTLD_NOW
);
806 /* The device-specific Glide library filename didn't work, try the
807 * old, generic libglide3.so library.
809 libHandle
= dlopen(defaultGlide
, RTLD_NOW
);
812 "can't find Glide library, dlopen(%s) and dlopen(%s) both failed.",
813 libName
, defaultGlide
);
814 __driUtilMessage("dlerror() message: %s", dlerror());
817 libName
= defaultGlide
;
821 const char *env
= getenv("LIBGL_DEBUG");
822 if (env
&& strstr(env
, "verbose")) {
823 fprintf(stderr
, "libGL: using Glide library %s\n", libName
);
827 #define GET_FUNCTION(PTR, NAME) \
828 tmesa->Glide.PTR = dlsym(libHandle, NAME); \
829 if (!tmesa->Glide.PTR) { \
830 __driUtilMessage("couldn't find Glide function %s in %s.", \
834 GET_FUNCTION(grDrawPoint
, "grDrawPoint");
835 GET_FUNCTION(grDrawLine
, "grDrawLine");
836 GET_FUNCTION(grDrawTriangle
, "grDrawTriangle");
837 GET_FUNCTION(grVertexLayout
, "grVertexLayout");
838 GET_FUNCTION(grDrawVertexArray
, "grDrawVertexArray");
839 GET_FUNCTION(grDrawVertexArrayContiguous
, "grDrawVertexArrayContiguous");
840 GET_FUNCTION(grBufferClear
, "grBufferClear");
841 /*GET_FUNCTION(grBufferSwap, "grBufferSwap");*/
842 GET_FUNCTION(grRenderBuffer
, "grRenderBuffer");
843 GET_FUNCTION(grErrorSetCallback
, "grErrorSetCallback");
844 GET_FUNCTION(grFinish
, "grFinish");
845 GET_FUNCTION(grFlush
, "grFlush");
846 GET_FUNCTION(grSstWinOpen
, "grSstWinOpen");
847 GET_FUNCTION(grSstWinClose
, "grSstWinClose");
849 /* Not in V3 lib, and not used anyway. */
850 GET_FUNCTION(grSetNumPendingBuffers
, "grSetNumPendingBuffers");
852 GET_FUNCTION(grSelectContext
, "grSelectContext");
853 GET_FUNCTION(grSstOrigin
, "grSstOrigin");
854 GET_FUNCTION(grSstSelect
, "grSstSelect");
855 GET_FUNCTION(grAlphaBlendFunction
, "grAlphaBlendFunction");
856 GET_FUNCTION(grAlphaCombine
, "grAlphaCombine");
857 GET_FUNCTION(grAlphaControlsITRGBLighting
, "grAlphaControlsITRGBLighting");
858 GET_FUNCTION(grAlphaTestFunction
, "grAlphaTestFunction");
859 GET_FUNCTION(grAlphaTestReferenceValue
, "grAlphaTestReferenceValue");
860 GET_FUNCTION(grChromakeyMode
, "grChromakeyMode");
861 GET_FUNCTION(grChromakeyValue
, "grChromakeyValue");
862 GET_FUNCTION(grClipWindow
, "grClipWindow");
863 GET_FUNCTION(grColorCombine
, "grColorCombine");
864 GET_FUNCTION(grColorMask
, "grColorMask");
865 GET_FUNCTION(grCullMode
, "grCullMode");
866 GET_FUNCTION(grConstantColorValue
, "grConstantColorValue");
867 GET_FUNCTION(grDepthBiasLevel
, "grDepthBiasLevel");
868 GET_FUNCTION(grDepthBufferFunction
, "grDepthBufferFunction");
869 GET_FUNCTION(grDepthBufferMode
, "grDepthBufferMode");
870 GET_FUNCTION(grDepthMask
, "grDepthMask");
871 GET_FUNCTION(grDisableAllEffects
, "grDisableAllEffects");
872 GET_FUNCTION(grDitherMode
, "grDitherMode");
873 GET_FUNCTION(grFogColorValue
, "grFogColorValue");
874 GET_FUNCTION(grFogMode
, "grFogMode");
875 GET_FUNCTION(grFogTable
, "grFogTable");
876 GET_FUNCTION(grLoadGammaTable
, "grLoadGammaTable");
877 GET_FUNCTION(grSplash
, "grSplash");
878 GET_FUNCTION(grGet
, "grGet");
879 GET_FUNCTION(grGetString
, "grGetString");
880 GET_FUNCTION(grQueryResolutions
, "grQueryResolutions");
881 GET_FUNCTION(grReset
, "grReset");
882 GET_FUNCTION(grGetProcAddress
, "grGetProcAddress");
883 GET_FUNCTION(grEnable
, "grEnable");
884 GET_FUNCTION(grDisable
, "grDisable");
885 GET_FUNCTION(grCoordinateSpace
, "grCoordinateSpace");
886 GET_FUNCTION(grDepthRange
, "grDepthRange");
887 GET_FUNCTION(grStippleMode
, "grStippleMode");
888 GET_FUNCTION(grStipplePattern
, "grStipplePattern");
889 GET_FUNCTION(grViewport
, "grViewport");
890 GET_FUNCTION(grTexCalcMemRequired
, "grTexCalcMemRequired");
891 GET_FUNCTION(grTexTextureMemRequired
, "grTexTextureMemRequired");
892 GET_FUNCTION(grTexMinAddress
, "grTexMinAddress");
893 GET_FUNCTION(grTexMaxAddress
, "grTexMaxAddress");
894 GET_FUNCTION(grTexNCCTable
, "grTexNCCTable");
895 GET_FUNCTION(grTexSource
, "grTexSource");
896 GET_FUNCTION(grTexClampMode
, "grTexClampMode");
897 GET_FUNCTION(grTexCombine
, "grTexCombine");
898 GET_FUNCTION(grTexDetailControl
, "grTexDetailControl");
899 GET_FUNCTION(grTexFilterMode
, "grTexFilterMode");
900 GET_FUNCTION(grTexLodBiasValue
, "grTexLodBiasValue");
901 GET_FUNCTION(grTexDownloadMipMap
, "grTexDownloadMipMap");
902 GET_FUNCTION(grTexDownloadMipMapLevel
, "grTexDownloadMipMapLevel");
903 GET_FUNCTION(grTexDownloadMipMapLevelPartial
, "grTexDownloadMipMapLevelPartial");
904 GET_FUNCTION(grTexDownloadTable
, "grTexDownloadTable");
905 GET_FUNCTION(grTexDownloadTablePartial
, "grTexDownloadTablePartial");
906 GET_FUNCTION(grTexMipMapMode
, "grTexMipMapMode");
907 GET_FUNCTION(grTexMultibase
, "grTexMultibase");
908 GET_FUNCTION(grTexMultibaseAddress
, "grTexMultibaseAddress");
909 GET_FUNCTION(grLfbLock
, "grLfbLock");
910 GET_FUNCTION(grLfbUnlock
, "grLfbUnlock");
911 GET_FUNCTION(grLfbConstantAlpha
, "grLfbConstantAlpha");
912 GET_FUNCTION(grLfbConstantDepth
, "grLfbConstantDepth");
913 GET_FUNCTION(grLfbWriteColorSwizzle
, "grLfbWriteColorSwizzle");
914 GET_FUNCTION(grLfbWriteColorFormat
, "grLfbWriteColorFormat");
915 GET_FUNCTION(grLfbWriteRegion
, "grLfbWriteRegion");
916 GET_FUNCTION(grLfbReadRegion
, "grLfbReadRegion");
917 GET_FUNCTION(grGlideInit
, "grGlideInit");
918 GET_FUNCTION(grGlideShutdown
, "grGlideShutdown");
919 GET_FUNCTION(grGlideGetState
, "grGlideGetState");
920 GET_FUNCTION(grGlideSetState
, "grGlideSetState");
921 GET_FUNCTION(grGlideGetVertexLayout
, "grGlideGetVertexLayout");
922 GET_FUNCTION(grGlideSetVertexLayout
, "grGlideSetVertexLayout");
924 /* Glide utility functions */
925 GET_FUNCTION(guFogGenerateExp
, "guFogGenerateExp");
926 GET_FUNCTION(guFogGenerateExp2
, "guFogGenerateExp2");
927 GET_FUNCTION(guFogGenerateLinear
, "guFogGenerateLinear");
930 GET_FUNCTION(grDRIOpen
, "grDRIOpen");
931 GET_FUNCTION(grDRIPosition
, "grDRIPosition");
932 /*GET_FUNCTION(grDRILostContext, "grDRILostContext");*/
933 GET_FUNCTION(grDRIImportFifo
, "grDRIImportFifo");
934 GET_FUNCTION(grDRIInvalidateAll
, "grDRIInvalidateAll");
935 GET_FUNCTION(grDRIResetSAREA
, "grDRIResetSAREA");
936 GET_FUNCTION(grDRIBufferSwap
, "grDRIBufferSwap");
939 * Extension functions:
940 * Just use dlysm() because we want a NULL pointer if the function is
943 /* PIXEXT extension */
944 tmesa
->Glide
.grStencilFunc
= dlsym(libHandle
, "grStencilFunc");
945 tmesa
->Glide
.grStencilMask
= dlsym(libHandle
, "grStencilMask");
946 tmesa
->Glide
.grStencilOp
= dlsym(libHandle
, "grStencilOp");
947 tmesa
->Glide
.grBufferClearExt
= dlsym(libHandle
, "grBufferClearExt");
948 tmesa
->Glide
.grColorMaskExt
= dlsym(libHandle
, "grColorMaskExt");
949 /* COMBINE extension */
950 tmesa
->Glide
.grColorCombineExt
= dlsym(libHandle
, "grColorCombineExt");
951 tmesa
->Glide
.grTexColorCombineExt
= dlsym(libHandle
, "grTexColorCombineExt");
952 tmesa
->Glide
.grAlphaCombineExt
= dlsym(libHandle
, "grAlphaCombineExt");
953 tmesa
->Glide
.grTexAlphaCombineExt
= dlsym(libHandle
, "grTexAlphaCombineExt");
954 tmesa
->Glide
.grAlphaBlendFunctionExt
= dlsym(libHandle
, "grAlphaBlendFunctionExt");
955 tmesa
->Glide
.grConstantColorValueExt
= dlsym(libHandle
, "grConstantColorValueExt");
957 tmesa
->Glide
.txImgQuantize
= dlsym(libHandle
, "txImgQuantize");
958 tmesa
->Glide
.txImgDequantizeFXT1
= dlsym(libHandle
, "_txImgDequantizeFXT1");
959 tmesa
->Glide
.txErrorSetCallback
= dlsym(libHandle
, "txErrorSetCallback");
962 /* wrap the drawing functions so we can trap them */
963 real_grDrawTriangle
= tmesa
->Glide
.grDrawTriangle
;
964 tmesa
->Glide
.grDrawTriangle
= debug_grDrawTriangle
;
966 real_grDrawPoint
= tmesa
->Glide
.grDrawPoint
;
967 tmesa
->Glide
.grDrawPoint
= debug_grDrawPoint
;
969 real_grDrawVertexArray
= tmesa
->Glide
.grDrawVertexArray
;
970 tmesa
->Glide
.grDrawVertexArray
= debug_grDrawVertexArray
;
972 real_grDrawVertexArrayContiguous
= tmesa
->Glide
.grDrawVertexArrayContiguous
;
973 tmesa
->Glide
.grDrawVertexArrayContiguous
= debug_grDrawVertexArrayContiguous
;
975 real_grClipWindow
= tmesa
->Glide
.grClipWindow
;
976 tmesa
->Glide
.grClipWindow
= debug_grClipWindow
;
978 real_grVertexLayout
= tmesa
->Glide
.grVertexLayout
;
979 tmesa
->Glide
.grVertexLayout
= debug_grVertexLayout
;
981 real_grGlideGetVertexLayout
= tmesa
->Glide
.grGlideGetVertexLayout
;
982 tmesa
->Glide
.grGlideGetVertexLayout
= debug_grGlideGetVertexLayout
;
984 real_grGlideSetVertexLayout
= tmesa
->Glide
.grGlideSetVertexLayout
;
985 tmesa
->Glide
.grGlideSetVertexLayout
= debug_grGlideSetVertexLayout
;
987 real_grTexDownloadMipMapLevel
= tmesa
->Glide
.grTexDownloadMipMapLevel
;
988 tmesa
->Glide
.grTexDownloadMipMapLevel
= debug_grTexDownloadMipMapLevel
;