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 * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
33 * Gareth Hughes <gareth@valinux.com>
34 * Brian Paul <brianp@valinux.com>
39 #include "tdfx_context.h"
41 #include "tdfx_state.h"
43 #include "tdfx_tris.h"
44 #include "tdfx_render.h"
45 #include "tdfx_span.h"
46 #include "tdfx_texman.h"
47 #include "extensions.h"
50 #include "swrast/swrast.h"
51 #include "swrast_setup/swrast_setup.h"
52 #include "array_cache/acache.h"
55 #include "tnl/t_pipeline.h"
57 const char __driConfigOptions
[] = { 0 };
58 const GLuint __driNConfigOptions
= 0;
61 * Enable/Disable the extensions for this context.
63 static void tdfxDDInitExtensions( GLcontext
*ctx
)
65 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
67 _mesa_enable_extension( ctx
, "GL_HP_occlusion_test" );
68 _mesa_enable_extension( ctx
, "GL_EXT_paletted_texture" );
69 _mesa_enable_extension( ctx
, "GL_EXT_texture_lod_bias" );
71 if ( fxMesa
->haveTwoTMUs
) {
72 _mesa_enable_extension( ctx
, "GL_EXT_texture_env_add" );
73 _mesa_enable_extension( ctx
, "GL_ARB_multitexture" );
76 if ( TDFX_IS_NAPALM( fxMesa
) ) {
78 _mesa_enable_extension( ctx
, "GL_ARB_texture_compression" );
79 _mesa_enable_extension( ctx
, "GL_3DFX_texture_compression_FXT1" );
81 _mesa_enable_extension( ctx
, "GL_EXT_texture_env_combine" );
85 _mesa_enable_extension( ctx
, "GL_ARB_texture_cube_map");
86 _mesa_enable_extension( ctx
, "GL_NV_texture_rectangle");
89 if (fxMesa
->haveHwStencil
) {
90 _mesa_enable_extension( ctx
, "GL_EXT_stencil_wrap" );
96 static const struct tnl_pipeline_stage
*tdfx_pipeline
[] = {
97 &_tnl_vertex_transform_stage
,
98 &_tnl_normal_transform_stage
,
99 &_tnl_lighting_stage
, /* REMOVE: fog coord stage */
101 &_tnl_texture_transform_stage
,
102 /* REMOVE: point attenuation stage */
108 GLboolean
tdfxCreateContext( const __GLcontextModes
*mesaVis
,
109 __DRIcontextPrivate
*driContextPriv
,
110 void *sharedContextPrivate
)
112 tdfxContextPtr fxMesa
;
113 GLcontext
*ctx
, *shareCtx
;
114 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
115 tdfxScreenPrivate
*fxScreen
= (tdfxScreenPrivate
*) sPriv
->private;
116 TDFXSAREAPriv
*saPriv
= (TDFXSAREAPriv
*) ((char *) sPriv
->pSAREA
+
117 sizeof(XF86DRISAREARec
));
119 /* Allocate tdfx context */
120 fxMesa
= (tdfxContextPtr
) CALLOC( sizeof(tdfxContextRec
) );
124 /* Allocate the Mesa context */
125 if (sharedContextPrivate
)
126 shareCtx
= ((tdfxContextPtr
) sharedContextPrivate
)->glCtx
;
130 fxMesa
->glCtx
= _mesa_create_context(mesaVis
, shareCtx
, (void *) fxMesa
, GL_TRUE
);
131 if (!fxMesa
->glCtx
) {
135 driContextPriv
->driverPrivate
= fxMesa
;
137 /* Mirror some important DRI state
139 fxMesa
->hHWContext
= driContextPriv
->hHWContext
;
140 fxMesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
141 fxMesa
->driFd
= sPriv
->fd
;
143 fxMesa
->driScreen
= sPriv
;
144 fxMesa
->driContext
= driContextPriv
;
145 fxMesa
->fxScreen
= fxScreen
;
146 fxMesa
->sarea
= saPriv
;
148 fxMesa
->haveHwStencil
= ( TDFX_IS_NAPALM( fxMesa
) &&
149 mesaVis
->stencilBits
&&
150 mesaVis
->depthBits
== 24 );
152 fxMesa
->screen_width
= fxScreen
->width
;
153 fxMesa
->screen_height
= fxScreen
->height
;
155 fxMesa
->new_gl_state
= ~0;
156 fxMesa
->new_state
= ~0;
159 /* NOTE: This must be here before any Glide calls! */
160 if (!tdfxInitGlide( fxMesa
)) {
165 fxMesa
->Glide
.grDRIOpen( (char*) sPriv
->pFB
, fxScreen
->regs
.map
, fxScreen
->deviceID
,
166 fxScreen
->width
, fxScreen
->height
, fxScreen
->mem
, fxScreen
->cpp
,
167 fxScreen
->stride
, fxScreen
->fifoOffset
, fxScreen
->fifoSize
,
168 fxScreen
->fbOffset
, fxScreen
->backOffset
, fxScreen
->depthOffset
,
169 fxScreen
->textureOffset
, fxScreen
->textureSize
, &saPriv
->fifoPtr
,
172 if ( getenv( "FX_GLIDE_SWAPINTERVAL" ) ) {
173 fxMesa
->Glide
.SwapInterval
= atoi( getenv( "FX_GLIDE_SWAPINTERVAL" ) );
175 fxMesa
->Glide
.SwapInterval
= 0;
177 if ( getenv( "FX_MAX_PENDING_SWAPS" ) ) {
178 fxMesa
->Glide
.MaxPendingSwaps
= atoi( getenv( "FX_MAX_PENDING_SWAPS" ) );
180 fxMesa
->Glide
.MaxPendingSwaps
= 2;
183 fxMesa
->Glide
.Initialized
= GL_FALSE
;
184 fxMesa
->Glide
.Board
= 0;
187 if (getenv("FX_EMULATE_SINGLE_TMU")) {
188 fxMesa
->haveTwoTMUs
= GL_FALSE
;
191 if ( TDFX_IS_BANSHEE( fxMesa
) ) {
192 fxMesa
->haveTwoTMUs
= GL_FALSE
;
194 fxMesa
->haveTwoTMUs
= GL_TRUE
;
198 fxMesa
->stats
.swapBuffer
= 0;
199 fxMesa
->stats
.reqTexUpload
= 0;
200 fxMesa
->stats
.texUpload
= 0;
201 fxMesa
->stats
.memTexUpload
= 0;
203 fxMesa
->tmuSrc
= TDFX_TMU_NONE
;
206 if ( TDFX_IS_NAPALM( fxMesa
) ) {
207 ctx
->Const
.MaxTextureLevels
= 12;
209 ctx
->Const
.MaxTextureLevels
= 9;
211 ctx
->Const
.MaxTextureUnits
= TDFX_IS_BANSHEE( fxMesa
) ? 1 : 2;
212 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
213 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
217 ctx
->Const
.MinPointSize
= 1.0;
218 ctx
->Const
.MinPointSizeAA
= 1.0;
219 ctx
->Const
.MaxPointSize
= 1.0;
220 ctx
->Const
.MaxPointSizeAA
= 1.0;
222 /* Disable wide lines as we can't antialias them correctly in
225 ctx
->Const
.MinLineWidth
= 1.0;
226 ctx
->Const
.MinLineWidthAA
= 1.0;
227 ctx
->Const
.MaxLineWidth
= 1.0;
228 ctx
->Const
.MaxLineWidthAA
= 1.0;
229 ctx
->Const
.LineWidthGranularity
= 1.0;
231 /* Initialize the software rasterizer and helper modules.
233 _swrast_CreateContext( ctx
);
234 _ac_CreateContext( ctx
);
235 _tnl_CreateContext( ctx
);
236 _swsetup_CreateContext( ctx
);
238 /* Install the customized pipeline:
240 _tnl_destroy_pipeline( ctx
);
241 _tnl_install_pipeline( ctx
, tdfx_pipeline
);
243 /* Configure swrast to match hardware characteristics:
245 _swrast_allow_pixel_fog( ctx
, GL_TRUE
);
246 _swrast_allow_vertex_fog( ctx
, GL_FALSE
);
248 tdfxDDInitExtensions( ctx
);
249 tdfxDDInitDriverFuncs( ctx
);
250 tdfxDDInitStateFuncs( ctx
);
251 tdfxDDInitRenderFuncs( ctx
);
252 tdfxDDInitSpanFuncs( ctx
);
253 tdfxDDInitTriFuncs( ctx
);
255 tdfxInitState( fxMesa
);
261 static GLboolean
tdfxInitVertexFormats( tdfxContextPtr fxMesa
)
266 LOCK_HARDWARE( fxMesa
);
268 fxMesa
->Glide
.grGet( GR_GLIDE_VERTEXLAYOUT_SIZE
, sizeof(FxI32
), &result
);
269 for ( i
= 0 ; i
< TDFX_NUM_LAYOUTS
; i
++ ) {
270 fxMesa
->layout
[i
] = MALLOC( result
);
271 if ( !fxMesa
->layout
[i
] ) {
272 UNLOCK_HARDWARE( fxMesa
);
277 /* Tiny vertex format - 16 bytes.
279 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
280 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
281 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
282 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
283 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
284 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_TINY
] );
286 /* Non textured vertex format - 24 bytes (Need w for table fog)
288 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
289 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
290 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
291 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
292 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
293 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
294 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_NOTEX
] );
296 /* Single textured vertex format - 32 bytes.
298 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
299 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
300 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
301 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
302 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
303 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
304 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
305 /*grVertexLayout( GR_PARAM_FOG_EXT, TDFX_FOG_OFFSET, GR_PARAM_ENABLE );*/
306 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_SINGLE
] );
308 /* Multitextured vertex format - 40 bytes.
310 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
311 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
312 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
313 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
314 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
315 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
316 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
317 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST1
, TDFX_ST1_OFFSET
, GR_PARAM_ENABLE
);
318 /*fxMesa->Glide.grVertexLayout( GR_PARAM_FOG_EXT, TDFX_FOG_OFFSET, GR_PARAM_ENABLE );*/
319 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_MULTI
] );
321 /* Projected texture vertex format - 48 bytes.
323 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
324 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
325 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
326 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
327 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
328 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
329 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
330 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q0
, TDFX_Q0_OFFSET
, GR_PARAM_ENABLE
);
331 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST1
, TDFX_ST1_OFFSET
, GR_PARAM_ENABLE
);
332 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q1
, TDFX_Q1_OFFSET
, GR_PARAM_ENABLE
);
333 /*fxMesa->Glide.grVertexLayout( GR_PARAM_FOG_EXT, TDFX_FOG_OFFSET, GR_PARAM_ENABLE );*/
334 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_PROJECT
] );
336 UNLOCK_HARDWARE( fxMesa
);
343 * Initialize the state in an tdfxContextPtr struct.
346 tdfxInitContext( __DRIdrawablePrivate
*driDrawPriv
, tdfxContextPtr fxMesa
)
348 /* KW: Would be nice to make one of these a member of the other.
352 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
353 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)fxMesa
);
357 fprintf(stderr
, "Debug locking enabled\n");
360 if ( fxMesa
->Glide
.Initialized
)
363 fxMesa
->width
= driDrawPriv
->w
;
364 fxMesa
->height
= driDrawPriv
->h
;
366 /* We have to use a light lock here, because we can't do any glide
367 * operations yet. No use of FX_* functions in this function.
369 DRM_LIGHT_LOCK( fxMesa
->driFd
, fxMesa
->driHwLock
, fxMesa
->hHWContext
);
371 fxMesa
->Glide
.grGlideInit();
372 fxMesa
->Glide
.grSstSelect( fxMesa
->Glide
.Board
);
374 fxMesa
->Glide
.Context
= fxMesa
->Glide
.grSstWinOpen( (FxU32
) -1,
377 fxMesa
->Glide
.ColorFormat
,
378 fxMesa
->Glide
.Origin
,
381 fxMesa
->Glide
.grDRIResetSAREA();
383 DRM_UNLOCK( fxMesa
->driFd
, fxMesa
->driHwLock
, fxMesa
->hHWContext
);
385 if ( !fxMesa
->Glide
.Context
)
389 /* Perform the Glide-dependant part of the context initialization.
391 FX_grColorMaskv( fxMesa
->glCtx
, true4
);
393 tdfxTMInit( fxMesa
);
395 LOCK_HARDWARE( fxMesa
);
397 if ( fxMesa
->glCtx
->Visual
.depthBits
> 0 ) {
398 fxMesa
->Glide
.grDepthBufferMode(GR_DEPTHBUFFER_ZBUFFER
);
400 fxMesa
->Glide
.grDepthBufferMode(GR_DEPTHBUFFER_DISABLE
);
403 fxMesa
->Glide
.grLfbWriteColorFormat( GR_COLORFORMAT_ABGR
);
405 fxMesa
->Glide
.grGet( GR_TEXTURE_ALIGN
, sizeof(FxI32
), result
);
406 fxMesa
->Glide
.TextureAlign
= result
[0];
408 fxMesa
->Glide
.State
= NULL
;
409 fxMesa
->Glide
.grGet( GR_GLIDE_STATE_SIZE
, sizeof(FxI32
), result
);
410 fxMesa
->Glide
.State
= MALLOC( result
[0] );
412 fxMesa
->Fog
.Table
= NULL
;
413 fxMesa
->Glide
.grGet( GR_FOG_TABLE_ENTRIES
, sizeof(FxI32
), result
);
414 fxMesa
->Fog
.Table
= MALLOC( result
[0] * sizeof(GrFog_t
) );
416 UNLOCK_HARDWARE( fxMesa
);
418 if ( !fxMesa
->Glide
.State
|| !fxMesa
->Fog
.Table
) {
419 if ( fxMesa
->Glide
.State
)
420 FREE( fxMesa
->Glide
.State
);
421 if ( fxMesa
->Fog
.Table
)
422 FREE( fxMesa
->Fog
.Table
);
426 if ( !tdfxInitVertexFormats( fxMesa
) ) {
430 LOCK_HARDWARE( fxMesa
);
432 fxMesa
->Glide
.grGlideGetState( fxMesa
->Glide
.State
);
434 if ( getenv( "FX_GLIDE_INFO" ) ) {
435 printf( "GR_RENDERER = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_RENDERER
) );
436 printf( "GR_VERSION = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_VERSION
) );
437 printf( "GR_VENDOR = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_VENDOR
) );
438 printf( "GR_HARDWARE = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_HARDWARE
) );
439 printf( "GR_EXTENSION = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_EXTENSION
) );
442 UNLOCK_HARDWARE( fxMesa
);
445 const char *debug
= getenv("LIBGL_DEBUG");
446 if (debug
&& strstr(debug
, "fallbacks")) {
447 fxMesa
->debugFallbacks
= GL_TRUE
;
452 fxMesa
->numClipRects
= 0;
453 fxMesa
->pClipRects
= NULL
;
454 fxMesa
->scissoredClipRects
= GL_FALSE
;
456 fxMesa
->Glide
.Initialized
= GL_TRUE
;
463 tdfxDestroyContext( __DRIcontextPrivate
*driContextPriv
)
465 tdfxContextPtr fxMesa
= (tdfxContextPtr
) driContextPriv
->driverPrivate
;
467 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
468 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)fxMesa
);
472 if (fxMesa
->glCtx
->Shared
->RefCount
== 1 && fxMesa
->driDrawable
) {
473 /* This share group is about to go away, free our private
474 * texture object data.
476 struct gl_texture_object
*tObj
;
477 tObj
= fxMesa
->glCtx
->Shared
->TexObjectList
;
479 tdfxTMFreeTexture(fxMesa
, tObj
);
484 tdfxTMClose(fxMesa
); /* free texture memory */
486 _swsetup_DestroyContext( fxMesa
->glCtx
);
487 _tnl_DestroyContext( fxMesa
->glCtx
);
488 _ac_DestroyContext( fxMesa
->glCtx
);
489 _swrast_DestroyContext( fxMesa
->glCtx
);
491 tdfxFreeVB( fxMesa
->glCtx
);
493 /* Free Mesa context */
494 fxMesa
->glCtx
->DriverCtx
= NULL
;
495 _mesa_destroy_context(fxMesa
->glCtx
);
497 /* free the tdfx context */
504 tdfxUnbindContext( __DRIcontextPrivate
*driContextPriv
)
506 GET_CURRENT_CONTEXT(ctx
);
507 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
509 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
510 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)driContextPriv
);
513 if ( driContextPriv
&& (tdfxContextPtr
) driContextPriv
== fxMesa
) {
514 LOCK_HARDWARE(fxMesa
);
515 fxMesa
->Glide
.grGlideGetState(fxMesa
->Glide
.State
);
516 UNLOCK_HARDWARE(fxMesa
);
523 tdfxMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
524 __DRIdrawablePrivate
*driDrawPriv
,
525 __DRIdrawablePrivate
*driReadPriv
)
527 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
528 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)driContextPriv
);
531 if ( driContextPriv
) {
532 tdfxContextPtr newFx
= (tdfxContextPtr
) driContextPriv
->driverPrivate
;
533 GLcontext
*newCtx
= newFx
->glCtx
;
534 GET_CURRENT_CONTEXT(curCtx
);
536 if ( newFx
->driDrawable
!= driDrawPriv
) {
537 newFx
->driDrawable
= driDrawPriv
;
540 else if (curCtx
== newCtx
) {
541 /* same drawable, same context -> no-op */
542 /* Need to call _mesa_make_current2() in order to make sure API
543 * dispatch is set correctly.
545 _mesa_make_current2( newCtx
,
546 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
547 (GLframebuffer
*) driReadPriv
->driverPrivate
);
551 if ( !newFx
->Glide
.Initialized
) {
552 if ( !tdfxInitContext( driDrawPriv
, newFx
) )
555 LOCK_HARDWARE( newFx
);
557 /* FIXME: Force loading of window information */
559 tdfxUpdateClipping(newCtx
);
560 tdfxUploadClipping(newFx
);
562 UNLOCK_HARDWARE( newFx
);
564 LOCK_HARDWARE( newFx
);
566 newFx
->Glide
.grSstSelect( newFx
->Glide
.Board
);
567 newFx
->Glide
.grGlideSetState( newFx
->Glide
.State
);
569 tdfxUpdateClipping(newCtx
);
570 tdfxUploadClipping(newFx
);
572 UNLOCK_HARDWARE( newFx
);
575 _mesa_make_current2( newCtx
,
576 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
577 (GLframebuffer
*) driReadPriv
->driverPrivate
);
579 if ( !newCtx
->Viewport
.Width
) {
580 _mesa_set_viewport( newCtx
, 0, 0, driDrawPriv
->w
, driDrawPriv
->h
);
583 _mesa_make_current( 0, 0 );
591 * Enable this to trace calls to various Glide functions.
593 /*#define DEBUG_TRAP*/
595 static void (*real_grDrawTriangle
)( const void *a
, const void *b
, const void *c
);
596 static void (*real_grDrawPoint
)( const void *a
);
597 static void (*real_grDrawVertexArray
)(FxU32 mode
, FxU32 Count
, void *pointers
);
598 static void (*real_grDrawVertexArrayContiguous
)(FxU32 mode
, FxU32 Count
,
599 void *pointers
, FxU32 stride
);
600 static void (*real_grClipWindow
)( FxU32 minx
, FxU32 miny
, FxU32 maxx
, FxU32 maxy
);
602 static void (*real_grVertexLayout
)(FxU32 param
, FxI32 offset
, FxU32 mode
);
603 static void (*real_grGlideGetVertexLayout
)( void *layout
);
604 static void (*real_grGlideSetVertexLayout
)( const void *layout
);
606 static void (*real_grTexDownloadMipMapLevel
)( GrChipID_t tmu
,
610 GrAspectRatio_t aspectRatio
,
611 GrTextureFormat_t format
,
616 static void debug_grDrawTriangle( const void *a
, const void *b
, const void *c
)
618 printf("%s\n", __FUNCTION__
);
619 (*real_grDrawTriangle
)(a
, b
, c
);
622 static void debug_grDrawPoint( const void *a
)
624 const float *f
= (const float *) a
;
625 printf("%s %g %g\n", __FUNCTION__
, f
[0], f
[1]);
626 (*real_grDrawPoint
)(a
);
629 static void debug_grDrawVertexArray(FxU32 mode
, FxU32 Count
, void *pointers
)
631 printf("%s count=%d\n", __FUNCTION__
, (int) Count
);
632 (*real_grDrawVertexArray
)(mode
, Count
, pointers
);
635 static void debug_grDrawVertexArrayContiguous(FxU32 mode
, FxU32 Count
,
636 void *pointers
, FxU32 stride
)
638 printf("%s mode=0x%x count=%d\n", __FUNCTION__
, (int) mode
, (int) Count
);
639 (*real_grDrawVertexArrayContiguous
)(mode
, Count
, pointers
, stride
);
642 static void debug_grClipWindow( FxU32 minx
, FxU32 miny
, FxU32 maxx
, FxU32 maxy
)
644 printf("%s %d,%d .. %d,%d\n", __FUNCTION__
,
645 (int) minx
, (int) miny
, (int) maxx
, (int) maxy
);
646 (*real_grClipWindow
)(minx
, miny
, maxx
, maxy
);
649 static void debug_grVertexLayout(FxU32 param
, FxI32 offset
, FxU32 mode
)
651 (*real_grVertexLayout
)(param
, offset
, mode
);
654 static void debug_grGlideGetVertexLayout( void *layout
)
656 (*real_grGlideGetVertexLayout
)(layout
);
659 static void debug_grGlideSetVertexLayout( const void *layout
)
661 (*real_grGlideSetVertexLayout
)(layout
);
664 static void debug_grTexDownloadMipMapLevel( GrChipID_t tmu
,
668 GrAspectRatio_t aspectRatio
,
669 GrTextureFormat_t format
,
673 (*real_grTexDownloadMipMapLevel
)(tmu
, startAddress
, thisLod
, largeLod
,
674 aspectRatio
, format
, evenOdd
, data
);
681 * Examine the context's deviceID to determine what kind of 3dfx hardware
682 * is installed. dlopen() the appropriate Glide library and initialize
683 * this context's Glide function pointers.
684 * Return: true/false = success/failure
686 GLboolean
tdfxInitGlide(tdfxContextPtr tmesa
)
688 static const char *defaultGlide
= "libglide3.so";
693 * XXX this code which selects a Glide library filename given the
694 * deviceID may need to be cleaned up a bit.
695 * Non-Linux systems may have different filenames, for example.
697 switch (tmesa
->fxScreen
->deviceID
) {
698 case PCI_CHIP_BANSHEE
:
699 case PCI_CHIP_VOODOO3
:
700 libName
= "libglide3-v3.so";
702 case PCI_CHIP_VOODOO5
: /* same as PCI_CHIP_VOODOO4 */
703 libName
= "libglide3-v5.so";
707 __driUtilMessage("unrecognized 3dfx deviceID: 0x%x",
708 tmesa
->fxScreen
->deviceID
);
713 libHandle
= dlopen(libName
, RTLD_NOW
);
715 /* The device-specific Glide library filename didn't work, try the
716 * old, generic libglide3.so library.
718 libHandle
= dlopen(defaultGlide
, RTLD_NOW
);
721 "can't find Glide library, dlopen(%s) and dlopen(%s) both failed.",
722 libName
, defaultGlide
);
723 __driUtilMessage("dlerror() message: %s", dlerror());
726 libName
= defaultGlide
;
730 const char *env
= getenv("LIBGL_DEBUG");
731 if (env
&& strstr(env
, "verbose")) {
732 fprintf(stderr
, "libGL: using Glide library %s\n", libName
);
736 #define GET_FUNCTION(PTR, NAME) \
737 tmesa->Glide.PTR = dlsym(libHandle, NAME); \
738 if (!tmesa->Glide.PTR) { \
739 __driUtilMessage("couldn't find Glide function %s in %s.", \
743 GET_FUNCTION(grDrawPoint
, "grDrawPoint");
744 GET_FUNCTION(grDrawLine
, "grDrawLine");
745 GET_FUNCTION(grDrawTriangle
, "grDrawTriangle");
746 GET_FUNCTION(grVertexLayout
, "grVertexLayout");
747 GET_FUNCTION(grDrawVertexArray
, "grDrawVertexArray");
748 GET_FUNCTION(grDrawVertexArrayContiguous
, "grDrawVertexArrayContiguous");
749 GET_FUNCTION(grBufferClear
, "grBufferClear");
750 /*GET_FUNCTION(grBufferSwap, "grBufferSwap");*/
751 GET_FUNCTION(grRenderBuffer
, "grRenderBuffer");
752 GET_FUNCTION(grErrorSetCallback
, "grErrorSetCallback");
753 GET_FUNCTION(grFinish
, "grFinish");
754 GET_FUNCTION(grFlush
, "grFlush");
755 GET_FUNCTION(grSstWinOpen
, "grSstWinOpen");
756 GET_FUNCTION(grSstWinClose
, "grSstWinClose");
758 /* Not in V3 lib, and not used anyway. */
759 GET_FUNCTION(grSetNumPendingBuffers
, "grSetNumPendingBuffers");
761 GET_FUNCTION(grSelectContext
, "grSelectContext");
762 GET_FUNCTION(grSstOrigin
, "grSstOrigin");
763 GET_FUNCTION(grSstSelect
, "grSstSelect");
764 GET_FUNCTION(grAlphaBlendFunction
, "grAlphaBlendFunction");
765 GET_FUNCTION(grAlphaCombine
, "grAlphaCombine");
766 GET_FUNCTION(grAlphaControlsITRGBLighting
, "grAlphaControlsITRGBLighting");
767 GET_FUNCTION(grAlphaTestFunction
, "grAlphaTestFunction");
768 GET_FUNCTION(grAlphaTestReferenceValue
, "grAlphaTestReferenceValue");
769 GET_FUNCTION(grChromakeyMode
, "grChromakeyMode");
770 GET_FUNCTION(grChromakeyValue
, "grChromakeyValue");
771 GET_FUNCTION(grClipWindow
, "grClipWindow");
772 GET_FUNCTION(grColorCombine
, "grColorCombine");
773 GET_FUNCTION(grColorMask
, "grColorMask");
774 GET_FUNCTION(grCullMode
, "grCullMode");
775 GET_FUNCTION(grConstantColorValue
, "grConstantColorValue");
776 GET_FUNCTION(grDepthBiasLevel
, "grDepthBiasLevel");
777 GET_FUNCTION(grDepthBufferFunction
, "grDepthBufferFunction");
778 GET_FUNCTION(grDepthBufferMode
, "grDepthBufferMode");
779 GET_FUNCTION(grDepthMask
, "grDepthMask");
780 GET_FUNCTION(grDisableAllEffects
, "grDisableAllEffects");
781 GET_FUNCTION(grDitherMode
, "grDitherMode");
782 GET_FUNCTION(grFogColorValue
, "grFogColorValue");
783 GET_FUNCTION(grFogMode
, "grFogMode");
784 GET_FUNCTION(grFogTable
, "grFogTable");
785 GET_FUNCTION(grLoadGammaTable
, "grLoadGammaTable");
786 GET_FUNCTION(grSplash
, "grSplash");
787 GET_FUNCTION(grGet
, "grGet");
788 GET_FUNCTION(grGetString
, "grGetString");
789 GET_FUNCTION(grQueryResolutions
, "grQueryResolutions");
790 GET_FUNCTION(grReset
, "grReset");
791 GET_FUNCTION(grGetProcAddress
, "grGetProcAddress");
792 GET_FUNCTION(grEnable
, "grEnable");
793 GET_FUNCTION(grDisable
, "grDisable");
794 GET_FUNCTION(grCoordinateSpace
, "grCoordinateSpace");
795 GET_FUNCTION(grDepthRange
, "grDepthRange");
796 GET_FUNCTION(grStippleMode
, "grStippleMode");
797 GET_FUNCTION(grStipplePattern
, "grStipplePattern");
798 GET_FUNCTION(grViewport
, "grViewport");
799 GET_FUNCTION(grTexCalcMemRequired
, "grTexCalcMemRequired");
800 GET_FUNCTION(grTexTextureMemRequired
, "grTexTextureMemRequired");
801 GET_FUNCTION(grTexMinAddress
, "grTexMinAddress");
802 GET_FUNCTION(grTexMaxAddress
, "grTexMaxAddress");
803 GET_FUNCTION(grTexNCCTable
, "grTexNCCTable");
804 GET_FUNCTION(grTexSource
, "grTexSource");
805 GET_FUNCTION(grTexClampMode
, "grTexClampMode");
806 GET_FUNCTION(grTexCombine
, "grTexCombine");
807 GET_FUNCTION(grTexDetailControl
, "grTexDetailControl");
808 GET_FUNCTION(grTexFilterMode
, "grTexFilterMode");
809 GET_FUNCTION(grTexLodBiasValue
, "grTexLodBiasValue");
810 GET_FUNCTION(grTexDownloadMipMap
, "grTexDownloadMipMap");
811 GET_FUNCTION(grTexDownloadMipMapLevel
, "grTexDownloadMipMapLevel");
812 GET_FUNCTION(grTexDownloadMipMapLevelPartial
, "grTexDownloadMipMapLevelPartial");
813 GET_FUNCTION(grTexDownloadTable
, "grTexDownloadTable");
814 GET_FUNCTION(grTexDownloadTablePartial
, "grTexDownloadTablePartial");
815 GET_FUNCTION(grTexMipMapMode
, "grTexMipMapMode");
816 GET_FUNCTION(grTexMultibase
, "grTexMultibase");
817 GET_FUNCTION(grTexMultibaseAddress
, "grTexMultibaseAddress");
818 GET_FUNCTION(grLfbLock
, "grLfbLock");
819 GET_FUNCTION(grLfbUnlock
, "grLfbUnlock");
820 GET_FUNCTION(grLfbConstantAlpha
, "grLfbConstantAlpha");
821 GET_FUNCTION(grLfbConstantDepth
, "grLfbConstantDepth");
822 GET_FUNCTION(grLfbWriteColorSwizzle
, "grLfbWriteColorSwizzle");
823 GET_FUNCTION(grLfbWriteColorFormat
, "grLfbWriteColorFormat");
824 GET_FUNCTION(grLfbWriteRegion
, "grLfbWriteRegion");
825 GET_FUNCTION(grLfbReadRegion
, "grLfbReadRegion");
826 GET_FUNCTION(grGlideInit
, "grGlideInit");
827 GET_FUNCTION(grGlideShutdown
, "grGlideShutdown");
828 GET_FUNCTION(grGlideGetState
, "grGlideGetState");
829 GET_FUNCTION(grGlideSetState
, "grGlideSetState");
830 GET_FUNCTION(grGlideGetVertexLayout
, "grGlideGetVertexLayout");
831 GET_FUNCTION(grGlideSetVertexLayout
, "grGlideSetVertexLayout");
833 /* Glide utility functions */
834 GET_FUNCTION(guFogGenerateExp
, "guFogGenerateExp");
835 GET_FUNCTION(guFogGenerateExp2
, "guFogGenerateExp2");
836 GET_FUNCTION(guFogGenerateLinear
, "guFogGenerateLinear");
839 GET_FUNCTION(grDRIOpen
, "grDRIOpen");
840 GET_FUNCTION(grDRIPosition
, "grDRIPosition");
841 /*GET_FUNCTION(grDRILostContext, "grDRILostContext");*/
842 GET_FUNCTION(grDRIImportFifo
, "grDRIImportFifo");
843 GET_FUNCTION(grDRIInvalidateAll
, "grDRIInvalidateAll");
844 GET_FUNCTION(grDRIResetSAREA
, "grDRIResetSAREA");
845 GET_FUNCTION(grDRIBufferSwap
, "grDRIBufferSwap");
848 * Extension functions:
849 * Just use dlysm() because we want a NULL pointer if the function is
852 /* PIXEXT extension */
853 tmesa
->Glide
.grStencilFunc
= dlsym(libHandle
, "grStencilFunc");
854 tmesa
->Glide
.grStencilMask
= dlsym(libHandle
, "grStencilMask");
855 tmesa
->Glide
.grStencilOp
= dlsym(libHandle
, "grStencilOp");
856 tmesa
->Glide
.grBufferClearExt
= dlsym(libHandle
, "grBufferClearExt");
857 tmesa
->Glide
.grColorMaskExt
= dlsym(libHandle
, "grColorMaskExt");
858 /* COMBINE extension */
859 tmesa
->Glide
.grColorCombineExt
= dlsym(libHandle
, "grColorCombineExt");
860 tmesa
->Glide
.grTexColorCombineExt
= dlsym(libHandle
, "grTexColorCombineExt");
861 tmesa
->Glide
.grAlphaCombineExt
= dlsym(libHandle
, "grAlphaCombineExt");
862 tmesa
->Glide
.grTexAlphaCombineExt
= dlsym(libHandle
, "grTexAlphaCombineExt");
863 tmesa
->Glide
.grAlphaBlendFunctionExt
= dlsym(libHandle
, "grAlphaBlendFunctionExt");
864 tmesa
->Glide
.grConstantColorValueExt
= dlsym(libHandle
, "grConstantColorValueExt");
866 tmesa
->Glide
.txImgQuantize
= dlsym(libHandle
, "txImgQuantize");
867 tmesa
->Glide
.txImgDequantizeFXT1
= dlsym(libHandle
, "_txImgDequantizeFXT1");
868 tmesa
->Glide
.txErrorSetCallback
= dlsym(libHandle
, "txErrorSetCallback");
871 /* wrap the drawing functions so we can trap them */
872 real_grDrawTriangle
= tmesa
->Glide
.grDrawTriangle
;
873 tmesa
->Glide
.grDrawTriangle
= debug_grDrawTriangle
;
875 real_grDrawPoint
= tmesa
->Glide
.grDrawPoint
;
876 tmesa
->Glide
.grDrawPoint
= debug_grDrawPoint
;
878 real_grDrawVertexArray
= tmesa
->Glide
.grDrawVertexArray
;
879 tmesa
->Glide
.grDrawVertexArray
= debug_grDrawVertexArray
;
881 real_grDrawVertexArrayContiguous
= tmesa
->Glide
.grDrawVertexArrayContiguous
;
882 tmesa
->Glide
.grDrawVertexArrayContiguous
= debug_grDrawVertexArrayContiguous
;
884 real_grClipWindow
= tmesa
->Glide
.grClipWindow
;
885 tmesa
->Glide
.grClipWindow
= debug_grClipWindow
;
887 real_grVertexLayout
= tmesa
->Glide
.grVertexLayout
;
888 tmesa
->Glide
.grVertexLayout
= debug_grVertexLayout
;
890 real_grGlideGetVertexLayout
= tmesa
->Glide
.grGlideGetVertexLayout
;
891 tmesa
->Glide
.grGlideGetVertexLayout
= debug_grGlideGetVertexLayout
;
893 real_grGlideSetVertexLayout
= tmesa
->Glide
.grGlideSetVertexLayout
;
894 tmesa
->Glide
.grGlideSetVertexLayout
= debug_grGlideSetVertexLayout
;
896 real_grTexDownloadMipMapLevel
= tmesa
->Glide
.grTexDownloadMipMapLevel
;
897 tmesa
->Glide
.grTexDownloadMipMapLevel
= debug_grTexDownloadMipMapLevel
;