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"
44 #include "tdfx_tris.h"
45 #include "tdfx_render.h"
46 #include "tdfx_span.h"
47 #include "tdfx_texman.h"
48 #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 #include "drivers/common/driverfuncs.h"
59 const char __driConfigOptions
[] = { 0 };
60 const GLuint __driNConfigOptions
= 0;
63 * Enable/Disable the extensions for this context.
65 static void tdfxDDInitExtensions( GLcontext
*ctx
)
67 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
69 _mesa_enable_extension( ctx
, "GL_HP_occlusion_test" );
70 _mesa_enable_extension( ctx
, "GL_EXT_paletted_texture" );
71 _mesa_enable_extension( ctx
, "GL_EXT_texture_lod_bias" );
73 if ( fxMesa
->haveTwoTMUs
) {
74 _mesa_enable_extension( ctx
, "GL_EXT_texture_env_add" );
75 _mesa_enable_extension( ctx
, "GL_ARB_multitexture" );
78 if ( TDFX_IS_NAPALM( fxMesa
) ) {
80 _mesa_enable_extension( ctx
, "GL_ARB_texture_compression" );
81 _mesa_enable_extension( ctx
, "GL_3DFX_texture_compression_FXT1" );
83 _mesa_enable_extension( ctx
, "GL_EXT_texture_env_combine" );
87 _mesa_enable_extension( ctx
, "GL_ARB_texture_cube_map");
88 _mesa_enable_extension( ctx
, "GL_NV_texture_rectangle");
91 if (fxMesa
->haveHwStencil
) {
92 _mesa_enable_extension( ctx
, "GL_EXT_stencil_wrap" );
98 static const struct tnl_pipeline_stage
*tdfx_pipeline
[] = {
99 &_tnl_vertex_transform_stage
,
100 &_tnl_normal_transform_stage
,
101 &_tnl_lighting_stage
, /* REMOVE: fog coord stage */
103 &_tnl_texture_transform_stage
,
104 /* REMOVE: point attenuation stage */
110 GLboolean
tdfxCreateContext( const __GLcontextModes
*mesaVis
,
111 __DRIcontextPrivate
*driContextPriv
,
112 void *sharedContextPrivate
)
114 tdfxContextPtr fxMesa
;
115 GLcontext
*ctx
, *shareCtx
;
116 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
117 tdfxScreenPrivate
*fxScreen
= (tdfxScreenPrivate
*) sPriv
->private;
118 TDFXSAREAPriv
*saPriv
= (TDFXSAREAPriv
*) ((char *) sPriv
->pSAREA
+
119 sizeof(XF86DRISAREARec
));
120 struct dd_function_table functions
;
122 /* Allocate tdfx context */
123 fxMesa
= (tdfxContextPtr
) CALLOC( sizeof(tdfxContextRec
) );
127 /* Init default driver functions then plug in our tdfx-specific functions
128 * (the texture functions are especially important)
130 _mesa_init_driver_functions(&functions
);
131 tdfxDDInitDriverFuncs(mesaVis
, &functions
);
132 tdfxInitTextureFuncs(&functions
);
133 tdfxInitRenderFuncs(&functions
);
135 /* Allocate the Mesa context */
136 if (sharedContextPrivate
)
137 shareCtx
= ((tdfxContextPtr
) sharedContextPrivate
)->glCtx
;
141 fxMesa
->glCtx
= _mesa_create_context(mesaVis
, shareCtx
,
142 &functions
, (void *) fxMesa
);
143 if (!fxMesa
->glCtx
) {
147 driContextPriv
->driverPrivate
= fxMesa
;
149 /* Mirror some important DRI state
151 fxMesa
->hHWContext
= driContextPriv
->hHWContext
;
152 fxMesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
153 fxMesa
->driFd
= sPriv
->fd
;
155 fxMesa
->driScreen
= sPriv
;
156 fxMesa
->driContext
= driContextPriv
;
157 fxMesa
->fxScreen
= fxScreen
;
158 fxMesa
->sarea
= saPriv
;
160 fxMesa
->haveHwStencil
= ( TDFX_IS_NAPALM( fxMesa
) &&
161 mesaVis
->stencilBits
&&
162 mesaVis
->depthBits
== 24 );
164 fxMesa
->screen_width
= fxScreen
->width
;
165 fxMesa
->screen_height
= fxScreen
->height
;
167 fxMesa
->new_gl_state
= ~0;
168 fxMesa
->new_state
= ~0;
171 /* NOTE: This must be here before any Glide calls! */
172 if (!tdfxInitGlide( fxMesa
)) {
177 fxMesa
->Glide
.grDRIOpen( (char*) sPriv
->pFB
, fxScreen
->regs
.map
, fxScreen
->deviceID
,
178 fxScreen
->width
, fxScreen
->height
, fxScreen
->mem
, fxScreen
->cpp
,
179 fxScreen
->stride
, fxScreen
->fifoOffset
, fxScreen
->fifoSize
,
180 fxScreen
->fbOffset
, fxScreen
->backOffset
, fxScreen
->depthOffset
,
181 fxScreen
->textureOffset
, fxScreen
->textureSize
, &saPriv
->fifoPtr
,
184 if ( getenv( "FX_GLIDE_SWAPINTERVAL" ) ) {
185 fxMesa
->Glide
.SwapInterval
= atoi( getenv( "FX_GLIDE_SWAPINTERVAL" ) );
187 fxMesa
->Glide
.SwapInterval
= 0;
189 if ( getenv( "FX_MAX_PENDING_SWAPS" ) ) {
190 fxMesa
->Glide
.MaxPendingSwaps
= atoi( getenv( "FX_MAX_PENDING_SWAPS" ) );
192 fxMesa
->Glide
.MaxPendingSwaps
= 2;
195 fxMesa
->Glide
.Initialized
= GL_FALSE
;
196 fxMesa
->Glide
.Board
= 0;
199 if (getenv("FX_EMULATE_SINGLE_TMU")) {
200 fxMesa
->haveTwoTMUs
= GL_FALSE
;
203 if ( TDFX_IS_BANSHEE( fxMesa
) ) {
204 fxMesa
->haveTwoTMUs
= GL_FALSE
;
206 fxMesa
->haveTwoTMUs
= GL_TRUE
;
210 fxMesa
->stats
.swapBuffer
= 0;
211 fxMesa
->stats
.reqTexUpload
= 0;
212 fxMesa
->stats
.texUpload
= 0;
213 fxMesa
->stats
.memTexUpload
= 0;
215 fxMesa
->tmuSrc
= TDFX_TMU_NONE
;
218 if ( TDFX_IS_NAPALM( fxMesa
) ) {
219 ctx
->Const
.MaxTextureLevels
= 12;
221 ctx
->Const
.MaxTextureLevels
= 9;
223 ctx
->Const
.MaxTextureUnits
= TDFX_IS_BANSHEE( fxMesa
) ? 1 : 2;
224 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
225 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
229 ctx
->Const
.MinPointSize
= 1.0;
230 ctx
->Const
.MinPointSizeAA
= 1.0;
231 ctx
->Const
.MaxPointSize
= 1.0;
232 ctx
->Const
.MaxPointSizeAA
= 1.0;
234 /* Disable wide lines as we can't antialias them correctly in
237 ctx
->Const
.MinLineWidth
= 1.0;
238 ctx
->Const
.MinLineWidthAA
= 1.0;
239 ctx
->Const
.MaxLineWidth
= 1.0;
240 ctx
->Const
.MaxLineWidthAA
= 1.0;
241 ctx
->Const
.LineWidthGranularity
= 1.0;
243 /* Initialize the software rasterizer and helper modules.
245 _swrast_CreateContext( ctx
);
246 _ac_CreateContext( ctx
);
247 _tnl_CreateContext( ctx
);
248 _swsetup_CreateContext( ctx
);
250 /* Install the customized pipeline:
252 _tnl_destroy_pipeline( ctx
);
253 _tnl_install_pipeline( ctx
, tdfx_pipeline
);
255 /* Configure swrast to match hardware characteristics:
257 _swrast_allow_pixel_fog( ctx
, GL_TRUE
);
258 _swrast_allow_vertex_fog( ctx
, GL_FALSE
);
260 tdfxDDInitExtensions( ctx
);
261 /* XXX these should really go right after _mesa_init_driver_functions() */
262 tdfxDDInitSpanFuncs( ctx
);
263 tdfxDDInitStateFuncs( ctx
);
264 tdfxDDInitTriFuncs( ctx
);
266 tdfxInitState( fxMesa
);
272 static GLboolean
tdfxInitVertexFormats( tdfxContextPtr fxMesa
)
277 LOCK_HARDWARE( fxMesa
);
279 fxMesa
->Glide
.grGet( GR_GLIDE_VERTEXLAYOUT_SIZE
, sizeof(FxI32
), &result
);
280 for ( i
= 0 ; i
< TDFX_NUM_LAYOUTS
; i
++ ) {
281 fxMesa
->layout
[i
] = MALLOC( result
);
282 if ( !fxMesa
->layout
[i
] ) {
283 UNLOCK_HARDWARE( fxMesa
);
288 /* Tiny vertex format - 16 bytes.
290 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
291 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
292 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
293 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
294 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
295 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_TINY
] );
297 /* Non textured vertex format - 24 bytes (Need w for table fog)
299 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
300 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
301 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
302 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
303 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
304 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
305 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_NOTEX
] );
307 /* Single textured vertex format - 32 bytes.
309 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
310 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
311 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
312 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
313 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
314 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
315 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
316 /*grVertexLayout( GR_PARAM_FOG_EXT, TDFX_FOG_OFFSET, GR_PARAM_ENABLE );*/
317 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_SINGLE
] );
319 /* Multitextured vertex format - 40 bytes.
321 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
322 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
323 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
324 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
325 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
326 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
327 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
328 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST1
, TDFX_ST1_OFFSET
, GR_PARAM_ENABLE
);
329 /*fxMesa->Glide.grVertexLayout( GR_PARAM_FOG_EXT, TDFX_FOG_OFFSET, GR_PARAM_ENABLE );*/
330 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_MULTI
] );
332 /* Projected texture vertex format - 48 bytes.
334 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
335 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
336 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
337 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
338 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
339 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
340 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
341 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q0
, TDFX_Q0_OFFSET
, GR_PARAM_ENABLE
);
342 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST1
, TDFX_ST1_OFFSET
, GR_PARAM_ENABLE
);
343 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q1
, TDFX_Q1_OFFSET
, GR_PARAM_ENABLE
);
344 /*fxMesa->Glide.grVertexLayout( GR_PARAM_FOG_EXT, TDFX_FOG_OFFSET, GR_PARAM_ENABLE );*/
345 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_PROJECT
] );
347 UNLOCK_HARDWARE( fxMesa
);
354 * Initialize the state in an tdfxContextPtr struct.
357 tdfxInitContext( __DRIdrawablePrivate
*driDrawPriv
, tdfxContextPtr fxMesa
)
359 /* KW: Would be nice to make one of these a member of the other.
363 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
364 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)fxMesa
);
368 fprintf(stderr
, "Debug locking enabled\n");
371 if ( fxMesa
->Glide
.Initialized
)
374 fxMesa
->width
= driDrawPriv
->w
;
375 fxMesa
->height
= driDrawPriv
->h
;
377 /* We have to use a light lock here, because we can't do any glide
378 * operations yet. No use of FX_* functions in this function.
380 DRM_LIGHT_LOCK( fxMesa
->driFd
, fxMesa
->driHwLock
, fxMesa
->hHWContext
);
382 fxMesa
->Glide
.grGlideInit();
383 fxMesa
->Glide
.grSstSelect( fxMesa
->Glide
.Board
);
385 fxMesa
->Glide
.Context
= fxMesa
->Glide
.grSstWinOpen( (FxU32
) -1,
388 fxMesa
->Glide
.ColorFormat
,
389 fxMesa
->Glide
.Origin
,
392 fxMesa
->Glide
.grDRIResetSAREA();
394 DRM_UNLOCK( fxMesa
->driFd
, fxMesa
->driHwLock
, fxMesa
->hHWContext
);
396 if ( !fxMesa
->Glide
.Context
)
400 /* Perform the Glide-dependant part of the context initialization.
402 FX_grColorMaskv( fxMesa
->glCtx
, true4
);
404 tdfxTMInit( fxMesa
);
406 LOCK_HARDWARE( fxMesa
);
408 if ( fxMesa
->glCtx
->Visual
.depthBits
> 0 ) {
409 fxMesa
->Glide
.grDepthBufferMode(GR_DEPTHBUFFER_ZBUFFER
);
411 fxMesa
->Glide
.grDepthBufferMode(GR_DEPTHBUFFER_DISABLE
);
414 fxMesa
->Glide
.grLfbWriteColorFormat( GR_COLORFORMAT_ABGR
);
416 fxMesa
->Glide
.grGet( GR_TEXTURE_ALIGN
, sizeof(FxI32
), result
);
417 fxMesa
->Glide
.TextureAlign
= result
[0];
419 fxMesa
->Glide
.State
= NULL
;
420 fxMesa
->Glide
.grGet( GR_GLIDE_STATE_SIZE
, sizeof(FxI32
), result
);
421 fxMesa
->Glide
.State
= MALLOC( result
[0] );
423 fxMesa
->Fog
.Table
= NULL
;
424 fxMesa
->Glide
.grGet( GR_FOG_TABLE_ENTRIES
, sizeof(FxI32
), result
);
425 fxMesa
->Fog
.Table
= MALLOC( result
[0] * sizeof(GrFog_t
) );
427 UNLOCK_HARDWARE( fxMesa
);
429 if ( !fxMesa
->Glide
.State
|| !fxMesa
->Fog
.Table
) {
430 if ( fxMesa
->Glide
.State
)
431 FREE( fxMesa
->Glide
.State
);
432 if ( fxMesa
->Fog
.Table
)
433 FREE( fxMesa
->Fog
.Table
);
437 if ( !tdfxInitVertexFormats( fxMesa
) ) {
441 LOCK_HARDWARE( fxMesa
);
443 fxMesa
->Glide
.grGlideGetState( fxMesa
->Glide
.State
);
445 if ( getenv( "FX_GLIDE_INFO" ) ) {
446 printf( "GR_RENDERER = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_RENDERER
) );
447 printf( "GR_VERSION = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_VERSION
) );
448 printf( "GR_VENDOR = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_VENDOR
) );
449 printf( "GR_HARDWARE = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_HARDWARE
) );
450 printf( "GR_EXTENSION = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_EXTENSION
) );
453 UNLOCK_HARDWARE( fxMesa
);
456 const char *debug
= getenv("LIBGL_DEBUG");
457 if (debug
&& strstr(debug
, "fallbacks")) {
458 fxMesa
->debugFallbacks
= GL_TRUE
;
463 fxMesa
->numClipRects
= 0;
464 fxMesa
->pClipRects
= NULL
;
465 fxMesa
->scissoredClipRects
= GL_FALSE
;
467 fxMesa
->Glide
.Initialized
= GL_TRUE
;
474 tdfxDestroyContext( __DRIcontextPrivate
*driContextPriv
)
476 tdfxContextPtr fxMesa
= (tdfxContextPtr
) driContextPriv
->driverPrivate
;
478 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
479 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)fxMesa
);
483 if (fxMesa
->glCtx
->Shared
->RefCount
== 1 && fxMesa
->driDrawable
) {
484 /* This share group is about to go away, free our private
485 * texture object data.
487 struct gl_texture_object
*tObj
;
488 tObj
= fxMesa
->glCtx
->Shared
->TexObjectList
;
490 tdfxTMFreeTexture(fxMesa
, tObj
);
495 tdfxTMClose(fxMesa
); /* free texture memory */
497 _swsetup_DestroyContext( fxMesa
->glCtx
);
498 _tnl_DestroyContext( fxMesa
->glCtx
);
499 _ac_DestroyContext( fxMesa
->glCtx
);
500 _swrast_DestroyContext( fxMesa
->glCtx
);
502 tdfxFreeVB( fxMesa
->glCtx
);
504 /* Free Mesa context */
505 fxMesa
->glCtx
->DriverCtx
= NULL
;
506 _mesa_destroy_context(fxMesa
->glCtx
);
508 /* free the tdfx context */
515 tdfxUnbindContext( __DRIcontextPrivate
*driContextPriv
)
517 GET_CURRENT_CONTEXT(ctx
);
518 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
520 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
521 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)driContextPriv
);
524 if ( driContextPriv
&& (tdfxContextPtr
) driContextPriv
== fxMesa
) {
525 LOCK_HARDWARE(fxMesa
);
526 fxMesa
->Glide
.grGlideGetState(fxMesa
->Glide
.State
);
527 UNLOCK_HARDWARE(fxMesa
);
534 tdfxMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
535 __DRIdrawablePrivate
*driDrawPriv
,
536 __DRIdrawablePrivate
*driReadPriv
)
538 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
539 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)driContextPriv
);
542 if ( driContextPriv
) {
543 tdfxContextPtr newFx
= (tdfxContextPtr
) driContextPriv
->driverPrivate
;
544 GLcontext
*newCtx
= newFx
->glCtx
;
545 GET_CURRENT_CONTEXT(curCtx
);
547 if ( newFx
->driDrawable
!= driDrawPriv
) {
548 newFx
->driDrawable
= driDrawPriv
;
551 else if (curCtx
== newCtx
) {
552 /* same drawable, same context -> no-op */
553 /* Need to call _mesa_make_current2() in order to make sure API
554 * dispatch is set correctly.
556 _mesa_make_current2( newCtx
,
557 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
558 (GLframebuffer
*) driReadPriv
->driverPrivate
);
562 if ( !newFx
->Glide
.Initialized
) {
563 if ( !tdfxInitContext( driDrawPriv
, newFx
) )
566 LOCK_HARDWARE( newFx
);
568 /* FIXME: Force loading of window information */
570 tdfxUpdateClipping(newCtx
);
571 tdfxUploadClipping(newFx
);
573 UNLOCK_HARDWARE( newFx
);
575 LOCK_HARDWARE( newFx
);
577 newFx
->Glide
.grSstSelect( newFx
->Glide
.Board
);
578 newFx
->Glide
.grGlideSetState( newFx
->Glide
.State
);
580 tdfxUpdateClipping(newCtx
);
581 tdfxUploadClipping(newFx
);
583 UNLOCK_HARDWARE( newFx
);
586 _mesa_make_current2( newCtx
,
587 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
588 (GLframebuffer
*) driReadPriv
->driverPrivate
);
590 if ( !newCtx
->Viewport
.Width
) {
591 _mesa_set_viewport( newCtx
, 0, 0, driDrawPriv
->w
, driDrawPriv
->h
);
594 _mesa_make_current( 0, 0 );
602 * Enable this to trace calls to various Glide functions.
604 /*#define DEBUG_TRAP*/
606 static void (*real_grDrawTriangle
)( const void *a
, const void *b
, const void *c
);
607 static void (*real_grDrawPoint
)( const void *a
);
608 static void (*real_grDrawVertexArray
)(FxU32 mode
, FxU32 Count
, void *pointers
);
609 static void (*real_grDrawVertexArrayContiguous
)(FxU32 mode
, FxU32 Count
,
610 void *pointers
, FxU32 stride
);
611 static void (*real_grClipWindow
)( FxU32 minx
, FxU32 miny
, FxU32 maxx
, FxU32 maxy
);
613 static void (*real_grVertexLayout
)(FxU32 param
, FxI32 offset
, FxU32 mode
);
614 static void (*real_grGlideGetVertexLayout
)( void *layout
);
615 static void (*real_grGlideSetVertexLayout
)( const void *layout
);
617 static void (*real_grTexDownloadMipMapLevel
)( GrChipID_t tmu
,
621 GrAspectRatio_t aspectRatio
,
622 GrTextureFormat_t format
,
627 static void debug_grDrawTriangle( const void *a
, const void *b
, const void *c
)
629 printf("%s\n", __FUNCTION__
);
630 (*real_grDrawTriangle
)(a
, b
, c
);
633 static void debug_grDrawPoint( const void *a
)
635 const float *f
= (const float *) a
;
636 printf("%s %g %g\n", __FUNCTION__
, f
[0], f
[1]);
637 (*real_grDrawPoint
)(a
);
640 static void debug_grDrawVertexArray(FxU32 mode
, FxU32 Count
, void *pointers
)
642 printf("%s count=%d\n", __FUNCTION__
, (int) Count
);
643 (*real_grDrawVertexArray
)(mode
, Count
, pointers
);
646 static void debug_grDrawVertexArrayContiguous(FxU32 mode
, FxU32 Count
,
647 void *pointers
, FxU32 stride
)
649 printf("%s mode=0x%x count=%d\n", __FUNCTION__
, (int) mode
, (int) Count
);
650 (*real_grDrawVertexArrayContiguous
)(mode
, Count
, pointers
, stride
);
653 static void debug_grClipWindow( FxU32 minx
, FxU32 miny
, FxU32 maxx
, FxU32 maxy
)
655 printf("%s %d,%d .. %d,%d\n", __FUNCTION__
,
656 (int) minx
, (int) miny
, (int) maxx
, (int) maxy
);
657 (*real_grClipWindow
)(minx
, miny
, maxx
, maxy
);
660 static void debug_grVertexLayout(FxU32 param
, FxI32 offset
, FxU32 mode
)
662 (*real_grVertexLayout
)(param
, offset
, mode
);
665 static void debug_grGlideGetVertexLayout( void *layout
)
667 (*real_grGlideGetVertexLayout
)(layout
);
670 static void debug_grGlideSetVertexLayout( const void *layout
)
672 (*real_grGlideSetVertexLayout
)(layout
);
675 static void debug_grTexDownloadMipMapLevel( GrChipID_t tmu
,
679 GrAspectRatio_t aspectRatio
,
680 GrTextureFormat_t format
,
684 (*real_grTexDownloadMipMapLevel
)(tmu
, startAddress
, thisLod
, largeLod
,
685 aspectRatio
, format
, evenOdd
, data
);
692 * Examine the context's deviceID to determine what kind of 3dfx hardware
693 * is installed. dlopen() the appropriate Glide library and initialize
694 * this context's Glide function pointers.
695 * Return: true/false = success/failure
697 GLboolean
tdfxInitGlide(tdfxContextPtr tmesa
)
699 static const char *defaultGlide
= "libglide3.so";
704 * XXX this code which selects a Glide library filename given the
705 * deviceID may need to be cleaned up a bit.
706 * Non-Linux systems may have different filenames, for example.
708 switch (tmesa
->fxScreen
->deviceID
) {
709 case PCI_CHIP_BANSHEE
:
710 case PCI_CHIP_VOODOO3
:
711 libName
= "libglide3-v3.so";
713 case PCI_CHIP_VOODOO5
: /* same as PCI_CHIP_VOODOO4 */
714 libName
= "libglide3-v5.so";
718 __driUtilMessage("unrecognized 3dfx deviceID: 0x%x",
719 tmesa
->fxScreen
->deviceID
);
724 libHandle
= dlopen(libName
, RTLD_NOW
);
726 /* The device-specific Glide library filename didn't work, try the
727 * old, generic libglide3.so library.
729 libHandle
= dlopen(defaultGlide
, RTLD_NOW
);
732 "can't find Glide library, dlopen(%s) and dlopen(%s) both failed.",
733 libName
, defaultGlide
);
734 __driUtilMessage("dlerror() message: %s", dlerror());
737 libName
= defaultGlide
;
741 const char *env
= getenv("LIBGL_DEBUG");
742 if (env
&& strstr(env
, "verbose")) {
743 fprintf(stderr
, "libGL: using Glide library %s\n", libName
);
747 #define GET_FUNCTION(PTR, NAME) \
748 tmesa->Glide.PTR = dlsym(libHandle, NAME); \
749 if (!tmesa->Glide.PTR) { \
750 __driUtilMessage("couldn't find Glide function %s in %s.", \
754 GET_FUNCTION(grDrawPoint
, "grDrawPoint");
755 GET_FUNCTION(grDrawLine
, "grDrawLine");
756 GET_FUNCTION(grDrawTriangle
, "grDrawTriangle");
757 GET_FUNCTION(grVertexLayout
, "grVertexLayout");
758 GET_FUNCTION(grDrawVertexArray
, "grDrawVertexArray");
759 GET_FUNCTION(grDrawVertexArrayContiguous
, "grDrawVertexArrayContiguous");
760 GET_FUNCTION(grBufferClear
, "grBufferClear");
761 /*GET_FUNCTION(grBufferSwap, "grBufferSwap");*/
762 GET_FUNCTION(grRenderBuffer
, "grRenderBuffer");
763 GET_FUNCTION(grErrorSetCallback
, "grErrorSetCallback");
764 GET_FUNCTION(grFinish
, "grFinish");
765 GET_FUNCTION(grFlush
, "grFlush");
766 GET_FUNCTION(grSstWinOpen
, "grSstWinOpen");
767 GET_FUNCTION(grSstWinClose
, "grSstWinClose");
769 /* Not in V3 lib, and not used anyway. */
770 GET_FUNCTION(grSetNumPendingBuffers
, "grSetNumPendingBuffers");
772 GET_FUNCTION(grSelectContext
, "grSelectContext");
773 GET_FUNCTION(grSstOrigin
, "grSstOrigin");
774 GET_FUNCTION(grSstSelect
, "grSstSelect");
775 GET_FUNCTION(grAlphaBlendFunction
, "grAlphaBlendFunction");
776 GET_FUNCTION(grAlphaCombine
, "grAlphaCombine");
777 GET_FUNCTION(grAlphaControlsITRGBLighting
, "grAlphaControlsITRGBLighting");
778 GET_FUNCTION(grAlphaTestFunction
, "grAlphaTestFunction");
779 GET_FUNCTION(grAlphaTestReferenceValue
, "grAlphaTestReferenceValue");
780 GET_FUNCTION(grChromakeyMode
, "grChromakeyMode");
781 GET_FUNCTION(grChromakeyValue
, "grChromakeyValue");
782 GET_FUNCTION(grClipWindow
, "grClipWindow");
783 GET_FUNCTION(grColorCombine
, "grColorCombine");
784 GET_FUNCTION(grColorMask
, "grColorMask");
785 GET_FUNCTION(grCullMode
, "grCullMode");
786 GET_FUNCTION(grConstantColorValue
, "grConstantColorValue");
787 GET_FUNCTION(grDepthBiasLevel
, "grDepthBiasLevel");
788 GET_FUNCTION(grDepthBufferFunction
, "grDepthBufferFunction");
789 GET_FUNCTION(grDepthBufferMode
, "grDepthBufferMode");
790 GET_FUNCTION(grDepthMask
, "grDepthMask");
791 GET_FUNCTION(grDisableAllEffects
, "grDisableAllEffects");
792 GET_FUNCTION(grDitherMode
, "grDitherMode");
793 GET_FUNCTION(grFogColorValue
, "grFogColorValue");
794 GET_FUNCTION(grFogMode
, "grFogMode");
795 GET_FUNCTION(grFogTable
, "grFogTable");
796 GET_FUNCTION(grLoadGammaTable
, "grLoadGammaTable");
797 GET_FUNCTION(grSplash
, "grSplash");
798 GET_FUNCTION(grGet
, "grGet");
799 GET_FUNCTION(grGetString
, "grGetString");
800 GET_FUNCTION(grQueryResolutions
, "grQueryResolutions");
801 GET_FUNCTION(grReset
, "grReset");
802 GET_FUNCTION(grGetProcAddress
, "grGetProcAddress");
803 GET_FUNCTION(grEnable
, "grEnable");
804 GET_FUNCTION(grDisable
, "grDisable");
805 GET_FUNCTION(grCoordinateSpace
, "grCoordinateSpace");
806 GET_FUNCTION(grDepthRange
, "grDepthRange");
807 GET_FUNCTION(grStippleMode
, "grStippleMode");
808 GET_FUNCTION(grStipplePattern
, "grStipplePattern");
809 GET_FUNCTION(grViewport
, "grViewport");
810 GET_FUNCTION(grTexCalcMemRequired
, "grTexCalcMemRequired");
811 GET_FUNCTION(grTexTextureMemRequired
, "grTexTextureMemRequired");
812 GET_FUNCTION(grTexMinAddress
, "grTexMinAddress");
813 GET_FUNCTION(grTexMaxAddress
, "grTexMaxAddress");
814 GET_FUNCTION(grTexNCCTable
, "grTexNCCTable");
815 GET_FUNCTION(grTexSource
, "grTexSource");
816 GET_FUNCTION(grTexClampMode
, "grTexClampMode");
817 GET_FUNCTION(grTexCombine
, "grTexCombine");
818 GET_FUNCTION(grTexDetailControl
, "grTexDetailControl");
819 GET_FUNCTION(grTexFilterMode
, "grTexFilterMode");
820 GET_FUNCTION(grTexLodBiasValue
, "grTexLodBiasValue");
821 GET_FUNCTION(grTexDownloadMipMap
, "grTexDownloadMipMap");
822 GET_FUNCTION(grTexDownloadMipMapLevel
, "grTexDownloadMipMapLevel");
823 GET_FUNCTION(grTexDownloadMipMapLevelPartial
, "grTexDownloadMipMapLevelPartial");
824 GET_FUNCTION(grTexDownloadTable
, "grTexDownloadTable");
825 GET_FUNCTION(grTexDownloadTablePartial
, "grTexDownloadTablePartial");
826 GET_FUNCTION(grTexMipMapMode
, "grTexMipMapMode");
827 GET_FUNCTION(grTexMultibase
, "grTexMultibase");
828 GET_FUNCTION(grTexMultibaseAddress
, "grTexMultibaseAddress");
829 GET_FUNCTION(grLfbLock
, "grLfbLock");
830 GET_FUNCTION(grLfbUnlock
, "grLfbUnlock");
831 GET_FUNCTION(grLfbConstantAlpha
, "grLfbConstantAlpha");
832 GET_FUNCTION(grLfbConstantDepth
, "grLfbConstantDepth");
833 GET_FUNCTION(grLfbWriteColorSwizzle
, "grLfbWriteColorSwizzle");
834 GET_FUNCTION(grLfbWriteColorFormat
, "grLfbWriteColorFormat");
835 GET_FUNCTION(grLfbWriteRegion
, "grLfbWriteRegion");
836 GET_FUNCTION(grLfbReadRegion
, "grLfbReadRegion");
837 GET_FUNCTION(grGlideInit
, "grGlideInit");
838 GET_FUNCTION(grGlideShutdown
, "grGlideShutdown");
839 GET_FUNCTION(grGlideGetState
, "grGlideGetState");
840 GET_FUNCTION(grGlideSetState
, "grGlideSetState");
841 GET_FUNCTION(grGlideGetVertexLayout
, "grGlideGetVertexLayout");
842 GET_FUNCTION(grGlideSetVertexLayout
, "grGlideSetVertexLayout");
844 /* Glide utility functions */
845 GET_FUNCTION(guFogGenerateExp
, "guFogGenerateExp");
846 GET_FUNCTION(guFogGenerateExp2
, "guFogGenerateExp2");
847 GET_FUNCTION(guFogGenerateLinear
, "guFogGenerateLinear");
850 GET_FUNCTION(grDRIOpen
, "grDRIOpen");
851 GET_FUNCTION(grDRIPosition
, "grDRIPosition");
852 /*GET_FUNCTION(grDRILostContext, "grDRILostContext");*/
853 GET_FUNCTION(grDRIImportFifo
, "grDRIImportFifo");
854 GET_FUNCTION(grDRIInvalidateAll
, "grDRIInvalidateAll");
855 GET_FUNCTION(grDRIResetSAREA
, "grDRIResetSAREA");
856 GET_FUNCTION(grDRIBufferSwap
, "grDRIBufferSwap");
859 * Extension functions:
860 * Just use dlysm() because we want a NULL pointer if the function is
863 /* PIXEXT extension */
864 tmesa
->Glide
.grStencilFunc
= dlsym(libHandle
, "grStencilFunc");
865 tmesa
->Glide
.grStencilMask
= dlsym(libHandle
, "grStencilMask");
866 tmesa
->Glide
.grStencilOp
= dlsym(libHandle
, "grStencilOp");
867 tmesa
->Glide
.grBufferClearExt
= dlsym(libHandle
, "grBufferClearExt");
868 tmesa
->Glide
.grColorMaskExt
= dlsym(libHandle
, "grColorMaskExt");
869 /* COMBINE extension */
870 tmesa
->Glide
.grColorCombineExt
= dlsym(libHandle
, "grColorCombineExt");
871 tmesa
->Glide
.grTexColorCombineExt
= dlsym(libHandle
, "grTexColorCombineExt");
872 tmesa
->Glide
.grAlphaCombineExt
= dlsym(libHandle
, "grAlphaCombineExt");
873 tmesa
->Glide
.grTexAlphaCombineExt
= dlsym(libHandle
, "grTexAlphaCombineExt");
874 tmesa
->Glide
.grAlphaBlendFunctionExt
= dlsym(libHandle
, "grAlphaBlendFunctionExt");
875 tmesa
->Glide
.grConstantColorValueExt
= dlsym(libHandle
, "grConstantColorValueExt");
877 tmesa
->Glide
.txImgQuantize
= dlsym(libHandle
, "txImgQuantize");
878 tmesa
->Glide
.txImgDequantizeFXT1
= dlsym(libHandle
, "_txImgDequantizeFXT1");
879 tmesa
->Glide
.txErrorSetCallback
= dlsym(libHandle
, "txErrorSetCallback");
882 /* wrap the drawing functions so we can trap them */
883 real_grDrawTriangle
= tmesa
->Glide
.grDrawTriangle
;
884 tmesa
->Glide
.grDrawTriangle
= debug_grDrawTriangle
;
886 real_grDrawPoint
= tmesa
->Glide
.grDrawPoint
;
887 tmesa
->Glide
.grDrawPoint
= debug_grDrawPoint
;
889 real_grDrawVertexArray
= tmesa
->Glide
.grDrawVertexArray
;
890 tmesa
->Glide
.grDrawVertexArray
= debug_grDrawVertexArray
;
892 real_grDrawVertexArrayContiguous
= tmesa
->Glide
.grDrawVertexArrayContiguous
;
893 tmesa
->Glide
.grDrawVertexArrayContiguous
= debug_grDrawVertexArrayContiguous
;
895 real_grClipWindow
= tmesa
->Glide
.grClipWindow
;
896 tmesa
->Glide
.grClipWindow
= debug_grClipWindow
;
898 real_grVertexLayout
= tmesa
->Glide
.grVertexLayout
;
899 tmesa
->Glide
.grVertexLayout
= debug_grVertexLayout
;
901 real_grGlideGetVertexLayout
= tmesa
->Glide
.grGlideGetVertexLayout
;
902 tmesa
->Glide
.grGlideGetVertexLayout
= debug_grGlideGetVertexLayout
;
904 real_grGlideSetVertexLayout
= tmesa
->Glide
.grGlideSetVertexLayout
;
905 tmesa
->Glide
.grGlideSetVertexLayout
= debug_grGlideSetVertexLayout
;
907 real_grTexDownloadMipMapLevel
= tmesa
->Glide
.grTexDownloadMipMapLevel
;
908 tmesa
->Glide
.grTexDownloadMipMapLevel
= debug_grTexDownloadMipMapLevel
;