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"
59 * Enable/Disable the extensions for this context.
61 static void tdfxDDInitExtensions( GLcontext
*ctx
)
63 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
65 _mesa_enable_extension( ctx
, "GL_HP_occlusion_test" );
66 _mesa_enable_extension( ctx
, "GL_EXT_paletted_texture" );
67 _mesa_enable_extension( ctx
, "GL_EXT_texture_lod_bias" );
69 if ( fxMesa
->haveTwoTMUs
) {
70 _mesa_enable_extension( ctx
, "GL_EXT_texture_env_add" );
71 _mesa_enable_extension( ctx
, "GL_ARB_multitexture" );
74 if ( TDFX_IS_NAPALM( fxMesa
) ) {
76 _mesa_enable_extension( ctx
, "GL_ARB_texture_compression" );
77 _mesa_enable_extension( ctx
, "GL_3DFX_texture_compression_FXT1" );
79 _mesa_enable_extension( ctx
, "GL_EXT_texture_env_combine" );
83 _mesa_enable_extension( ctx
, "GL_ARB_texture_cube_map");
84 _mesa_enable_extension( ctx
, "GL_NV_texture_rectangle");
87 if (fxMesa
->haveHwStencil
) {
88 _mesa_enable_extension( ctx
, "GL_EXT_stencil_wrap" );
94 static const struct tnl_pipeline_stage
*tdfx_pipeline
[] = {
95 &_tnl_vertex_transform_stage
,
96 &_tnl_normal_transform_stage
,
97 &_tnl_lighting_stage
, /* REMOVE: fog coord stage */
99 &_tnl_texture_transform_stage
,
100 /* REMOVE: point attenuation stage */
106 GLboolean
tdfxCreateContext( const __GLcontextModes
*mesaVis
,
107 __DRIcontextPrivate
*driContextPriv
,
108 void *sharedContextPrivate
)
110 tdfxContextPtr fxMesa
;
111 GLcontext
*ctx
, *shareCtx
;
112 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
113 tdfxScreenPrivate
*fxScreen
= (tdfxScreenPrivate
*) sPriv
->private;
114 TDFXSAREAPriv
*saPriv
= (TDFXSAREAPriv
*) ((char *) sPriv
->pSAREA
+
115 sizeof(XF86DRISAREARec
));
117 /* Allocate tdfx context */
118 fxMesa
= (tdfxContextPtr
) CALLOC( sizeof(tdfxContextRec
) );
122 /* Allocate the Mesa context */
123 if (sharedContextPrivate
)
124 shareCtx
= ((tdfxContextPtr
) sharedContextPrivate
)->glCtx
;
128 fxMesa
->glCtx
= _mesa_create_context(mesaVis
, shareCtx
, (void *) fxMesa
, GL_TRUE
);
129 if (!fxMesa
->glCtx
) {
133 driContextPriv
->driverPrivate
= fxMesa
;
135 /* Mirror some important DRI state
137 fxMesa
->hHWContext
= driContextPriv
->hHWContext
;
138 fxMesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
139 fxMesa
->driFd
= sPriv
->fd
;
141 fxMesa
->driScreen
= sPriv
;
142 fxMesa
->driContext
= driContextPriv
;
143 fxMesa
->fxScreen
= fxScreen
;
144 fxMesa
->sarea
= saPriv
;
146 fxMesa
->haveHwStencil
= ( TDFX_IS_NAPALM( fxMesa
) &&
147 mesaVis
->stencilBits
&&
148 mesaVis
->depthBits
== 24 );
150 fxMesa
->screen_width
= fxScreen
->width
;
151 fxMesa
->screen_height
= fxScreen
->height
;
153 fxMesa
->new_gl_state
= ~0;
154 fxMesa
->new_state
= ~0;
157 /* NOTE: This must be here before any Glide calls! */
158 if (!tdfxInitGlide( fxMesa
)) {
163 fxMesa
->Glide
.grDRIOpen( (char*) sPriv
->pFB
, fxScreen
->regs
.map
, fxScreen
->deviceID
,
164 fxScreen
->width
, fxScreen
->height
, fxScreen
->mem
, fxScreen
->cpp
,
165 fxScreen
->stride
, fxScreen
->fifoOffset
, fxScreen
->fifoSize
,
166 fxScreen
->fbOffset
, fxScreen
->backOffset
, fxScreen
->depthOffset
,
167 fxScreen
->textureOffset
, fxScreen
->textureSize
, &saPriv
->fifoPtr
,
170 if ( getenv( "FX_GLIDE_SWAPINTERVAL" ) ) {
171 fxMesa
->Glide
.SwapInterval
= atoi( getenv( "FX_GLIDE_SWAPINTERVAL" ) );
173 fxMesa
->Glide
.SwapInterval
= 0;
175 if ( getenv( "FX_MAX_PENDING_SWAPS" ) ) {
176 fxMesa
->Glide
.MaxPendingSwaps
= atoi( getenv( "FX_MAX_PENDING_SWAPS" ) );
178 fxMesa
->Glide
.MaxPendingSwaps
= 2;
181 fxMesa
->Glide
.Initialized
= GL_FALSE
;
182 fxMesa
->Glide
.Board
= 0;
185 if (getenv("FX_EMULATE_SINGLE_TMU")) {
186 fxMesa
->haveTwoTMUs
= GL_FALSE
;
189 if ( TDFX_IS_BANSHEE( fxMesa
) ) {
190 fxMesa
->haveTwoTMUs
= GL_FALSE
;
192 fxMesa
->haveTwoTMUs
= GL_TRUE
;
196 fxMesa
->stats
.swapBuffer
= 0;
197 fxMesa
->stats
.reqTexUpload
= 0;
198 fxMesa
->stats
.texUpload
= 0;
199 fxMesa
->stats
.memTexUpload
= 0;
201 fxMesa
->tmuSrc
= TDFX_TMU_NONE
;
204 if ( TDFX_IS_NAPALM( fxMesa
) ) {
205 ctx
->Const
.MaxTextureLevels
= 12;
207 ctx
->Const
.MaxTextureLevels
= 9;
209 ctx
->Const
.MaxTextureUnits
= TDFX_IS_BANSHEE( fxMesa
) ? 1 : 2;
213 ctx
->Const
.MinPointSize
= 1.0;
214 ctx
->Const
.MinPointSizeAA
= 1.0;
215 ctx
->Const
.MaxPointSize
= 1.0;
216 ctx
->Const
.MaxPointSizeAA
= 1.0;
218 /* Disable wide lines as we can't antialias them correctly in
221 ctx
->Const
.MinLineWidth
= 1.0;
222 ctx
->Const
.MinLineWidthAA
= 1.0;
223 ctx
->Const
.MaxLineWidth
= 1.0;
224 ctx
->Const
.MaxLineWidthAA
= 1.0;
225 ctx
->Const
.LineWidthGranularity
= 1.0;
227 /* Initialize the software rasterizer and helper modules.
229 _swrast_CreateContext( ctx
);
230 _ac_CreateContext( ctx
);
231 _tnl_CreateContext( ctx
);
232 _swsetup_CreateContext( ctx
);
234 /* Install the customized pipeline:
236 _tnl_destroy_pipeline( ctx
);
237 _tnl_install_pipeline( ctx
, tdfx_pipeline
);
239 /* Configure swrast to match hardware characteristics:
241 _swrast_allow_pixel_fog( ctx
, GL_TRUE
);
242 _swrast_allow_vertex_fog( ctx
, GL_FALSE
);
244 tdfxDDInitExtensions( ctx
);
245 tdfxDDInitDriverFuncs( ctx
);
246 tdfxDDInitStateFuncs( ctx
);
247 tdfxDDInitRenderFuncs( ctx
);
248 tdfxDDInitSpanFuncs( ctx
);
249 tdfxDDInitTriFuncs( ctx
);
251 tdfxInitState( fxMesa
);
257 static GLboolean
tdfxInitVertexFormats( tdfxContextPtr fxMesa
)
262 LOCK_HARDWARE( fxMesa
);
264 fxMesa
->Glide
.grGet( GR_GLIDE_VERTEXLAYOUT_SIZE
, sizeof(FxI32
), &result
);
265 for ( i
= 0 ; i
< TDFX_NUM_LAYOUTS
; i
++ ) {
266 fxMesa
->layout
[i
] = MALLOC( result
);
267 if ( !fxMesa
->layout
[i
] ) {
268 UNLOCK_HARDWARE( fxMesa
);
273 /* Tiny vertex format - 16 bytes.
275 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
276 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
277 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
278 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
279 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
280 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_TINY
] );
282 /* Non textured vertex format - 24 bytes (Need w for table fog)
284 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
285 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
286 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
287 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
288 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
289 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
290 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_NOTEX
] );
292 /* Single textured vertex format - 32 bytes.
294 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
295 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
296 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
297 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
298 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
299 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
300 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
301 /*grVertexLayout( GR_PARAM_FOG_EXT, TDFX_FOG_OFFSET, GR_PARAM_ENABLE );*/
302 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_SINGLE
] );
304 /* Multitextured vertex format - 40 bytes.
306 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
307 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
308 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
309 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
310 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
311 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
312 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
313 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST1
, TDFX_ST1_OFFSET
, GR_PARAM_ENABLE
);
314 /*fxMesa->Glide.grVertexLayout( GR_PARAM_FOG_EXT, TDFX_FOG_OFFSET, GR_PARAM_ENABLE );*/
315 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_MULTI
] );
317 /* Projected texture vertex format - 48 bytes.
319 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
320 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
321 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
322 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
323 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
324 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
325 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
326 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q0
, TDFX_Q0_OFFSET
, GR_PARAM_ENABLE
);
327 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST1
, TDFX_ST1_OFFSET
, GR_PARAM_ENABLE
);
328 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q1
, TDFX_Q1_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_PROJECT
] );
332 UNLOCK_HARDWARE( fxMesa
);
339 * Initialize the state in an tdfxContextPtr struct.
342 tdfxInitContext( __DRIdrawablePrivate
*driDrawPriv
, tdfxContextPtr fxMesa
)
344 /* KW: Would be nice to make one of these a member of the other.
348 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
349 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)fxMesa
);
353 fprintf(stderr
, "Debug locking enabled\n");
356 if ( fxMesa
->Glide
.Initialized
)
359 fxMesa
->width
= driDrawPriv
->w
;
360 fxMesa
->height
= driDrawPriv
->h
;
362 /* We have to use a light lock here, because we can't do any glide
363 * operations yet. No use of FX_* functions in this function.
365 DRM_LIGHT_LOCK( fxMesa
->driFd
, fxMesa
->driHwLock
, fxMesa
->hHWContext
);
367 fxMesa
->Glide
.grGlideInit();
368 fxMesa
->Glide
.grSstSelect( fxMesa
->Glide
.Board
);
370 fxMesa
->Glide
.Context
= fxMesa
->Glide
.grSstWinOpen( (FxU32
) -1,
373 fxMesa
->Glide
.ColorFormat
,
374 fxMesa
->Glide
.Origin
,
377 fxMesa
->Glide
.grDRIResetSAREA();
379 DRM_UNLOCK( fxMesa
->driFd
, fxMesa
->driHwLock
, fxMesa
->hHWContext
);
381 if ( !fxMesa
->Glide
.Context
)
385 /* Perform the Glide-dependant part of the context initialization.
387 FX_grColorMaskv( fxMesa
->glCtx
, true4
);
389 tdfxTMInit( fxMesa
);
391 LOCK_HARDWARE( fxMesa
);
393 if ( fxMesa
->glCtx
->Visual
.depthBits
> 0 ) {
394 fxMesa
->Glide
.grDepthBufferMode(GR_DEPTHBUFFER_ZBUFFER
);
396 fxMesa
->Glide
.grDepthBufferMode(GR_DEPTHBUFFER_DISABLE
);
399 fxMesa
->Glide
.grLfbWriteColorFormat( GR_COLORFORMAT_ABGR
);
401 fxMesa
->Glide
.grGet( GR_TEXTURE_ALIGN
, sizeof(FxI32
), result
);
402 fxMesa
->Glide
.TextureAlign
= result
[0];
404 fxMesa
->Glide
.State
= NULL
;
405 fxMesa
->Glide
.grGet( GR_GLIDE_STATE_SIZE
, sizeof(FxI32
), result
);
406 fxMesa
->Glide
.State
= MALLOC( result
[0] );
408 fxMesa
->Fog
.Table
= NULL
;
409 fxMesa
->Glide
.grGet( GR_FOG_TABLE_ENTRIES
, sizeof(FxI32
), result
);
410 fxMesa
->Fog
.Table
= MALLOC( result
[0] * sizeof(GrFog_t
) );
412 UNLOCK_HARDWARE( fxMesa
);
414 if ( !fxMesa
->Glide
.State
|| !fxMesa
->Fog
.Table
) {
415 if ( fxMesa
->Glide
.State
)
416 FREE( fxMesa
->Glide
.State
);
417 if ( fxMesa
->Fog
.Table
)
418 FREE( fxMesa
->Fog
.Table
);
422 if ( !tdfxInitVertexFormats( fxMesa
) ) {
426 LOCK_HARDWARE( fxMesa
);
428 fxMesa
->Glide
.grGlideGetState( fxMesa
->Glide
.State
);
430 if ( getenv( "FX_GLIDE_INFO" ) ) {
431 printf( "GR_RENDERER = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_RENDERER
) );
432 printf( "GR_VERSION = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_VERSION
) );
433 printf( "GR_VENDOR = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_VENDOR
) );
434 printf( "GR_HARDWARE = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_HARDWARE
) );
435 printf( "GR_EXTENSION = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_EXTENSION
) );
438 UNLOCK_HARDWARE( fxMesa
);
441 const char *debug
= getenv("LIBGL_DEBUG");
442 if (debug
&& strstr(debug
, "fallbacks")) {
443 fxMesa
->debugFallbacks
= GL_TRUE
;
448 fxMesa
->numClipRects
= 0;
449 fxMesa
->pClipRects
= NULL
;
450 fxMesa
->scissoredClipRects
= GL_FALSE
;
452 fxMesa
->Glide
.Initialized
= GL_TRUE
;
459 tdfxDestroyContext( __DRIcontextPrivate
*driContextPriv
)
461 tdfxContextPtr fxMesa
= (tdfxContextPtr
) driContextPriv
->driverPrivate
;
463 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
464 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)fxMesa
);
468 if (fxMesa
->glCtx
->Shared
->RefCount
== 1 && fxMesa
->driDrawable
) {
469 /* This share group is about to go away, free our private
470 * texture object data.
472 struct gl_texture_object
*tObj
;
473 tObj
= fxMesa
->glCtx
->Shared
->TexObjectList
;
475 tdfxTMFreeTexture(fxMesa
, tObj
);
480 tdfxTMClose(fxMesa
); /* free texture memory */
482 _swsetup_DestroyContext( fxMesa
->glCtx
);
483 _tnl_DestroyContext( fxMesa
->glCtx
);
484 _ac_DestroyContext( fxMesa
->glCtx
);
485 _swrast_DestroyContext( fxMesa
->glCtx
);
487 tdfxFreeVB( fxMesa
->glCtx
);
489 /* Free Mesa context */
490 fxMesa
->glCtx
->DriverCtx
= NULL
;
491 _mesa_destroy_context(fxMesa
->glCtx
);
493 /* free the tdfx context */
500 tdfxUnbindContext( __DRIcontextPrivate
*driContextPriv
)
502 GET_CURRENT_CONTEXT(ctx
);
503 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
505 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
506 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)driContextPriv
);
509 if ( driContextPriv
&& (tdfxContextPtr
) driContextPriv
== fxMesa
) {
510 LOCK_HARDWARE(fxMesa
);
511 fxMesa
->Glide
.grGlideGetState(fxMesa
->Glide
.State
);
512 UNLOCK_HARDWARE(fxMesa
);
519 tdfxMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
520 __DRIdrawablePrivate
*driDrawPriv
,
521 __DRIdrawablePrivate
*driReadPriv
)
523 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
524 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)driContextPriv
);
527 if ( driContextPriv
) {
528 tdfxContextPtr newFx
= (tdfxContextPtr
) driContextPriv
->driverPrivate
;
529 GLcontext
*newCtx
= newFx
->glCtx
;
530 GET_CURRENT_CONTEXT(curCtx
);
532 if ( newFx
->driDrawable
!= driDrawPriv
) {
533 newFx
->driDrawable
= driDrawPriv
;
536 else if (curCtx
== newCtx
) {
537 /* same drawable, same context -> no-op */
538 /* Need to call _mesa_make_current2() in order to make sure API
539 * dispatch is set correctly.
541 _mesa_make_current2( newCtx
,
542 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
543 (GLframebuffer
*) driReadPriv
->driverPrivate
);
547 if ( !newFx
->Glide
.Initialized
) {
548 if ( !tdfxInitContext( driDrawPriv
, newFx
) )
551 LOCK_HARDWARE( newFx
);
553 /* FIXME: Force loading of window information */
555 tdfxUpdateClipping(newCtx
);
556 tdfxUploadClipping(newFx
);
558 UNLOCK_HARDWARE( newFx
);
560 LOCK_HARDWARE( newFx
);
562 newFx
->Glide
.grSstSelect( newFx
->Glide
.Board
);
563 newFx
->Glide
.grGlideSetState( newFx
->Glide
.State
);
565 tdfxUpdateClipping(newCtx
);
566 tdfxUploadClipping(newFx
);
568 UNLOCK_HARDWARE( newFx
);
571 _mesa_make_current2( newCtx
,
572 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
573 (GLframebuffer
*) driReadPriv
->driverPrivate
);
575 if ( !newCtx
->Viewport
.Width
) {
576 _mesa_set_viewport( newCtx
, 0, 0, driDrawPriv
->w
, driDrawPriv
->h
);
579 _mesa_make_current( 0, 0 );
587 * Enable this to trace calls to various Glide functions.
589 /*#define DEBUG_TRAP*/
591 static void (*real_grDrawTriangle
)( const void *a
, const void *b
, const void *c
);
592 static void (*real_grDrawPoint
)( const void *a
);
593 static void (*real_grDrawVertexArray
)(FxU32 mode
, FxU32 Count
, void *pointers
);
594 static void (*real_grDrawVertexArrayContiguous
)(FxU32 mode
, FxU32 Count
,
595 void *pointers
, FxU32 stride
);
596 static void (*real_grClipWindow
)( FxU32 minx
, FxU32 miny
, FxU32 maxx
, FxU32 maxy
);
598 static void (*real_grVertexLayout
)(FxU32 param
, FxI32 offset
, FxU32 mode
);
599 static void (*real_grGlideGetVertexLayout
)( void *layout
);
600 static void (*real_grGlideSetVertexLayout
)( const void *layout
);
602 static void (*real_grTexDownloadMipMapLevel
)( GrChipID_t tmu
,
606 GrAspectRatio_t aspectRatio
,
607 GrTextureFormat_t format
,
612 static void debug_grDrawTriangle( const void *a
, const void *b
, const void *c
)
614 printf("%s\n", __FUNCTION__
);
615 (*real_grDrawTriangle
)(a
, b
, c
);
618 static void debug_grDrawPoint( const void *a
)
620 const float *f
= (const float *) a
;
621 printf("%s %g %g\n", __FUNCTION__
, f
[0], f
[1]);
622 (*real_grDrawPoint
)(a
);
625 static void debug_grDrawVertexArray(FxU32 mode
, FxU32 Count
, void *pointers
)
627 printf("%s count=%d\n", __FUNCTION__
, (int) Count
);
628 (*real_grDrawVertexArray
)(mode
, Count
, pointers
);
631 static void debug_grDrawVertexArrayContiguous(FxU32 mode
, FxU32 Count
,
632 void *pointers
, FxU32 stride
)
634 printf("%s mode=0x%x count=%d\n", __FUNCTION__
, (int) mode
, (int) Count
);
635 (*real_grDrawVertexArrayContiguous
)(mode
, Count
, pointers
, stride
);
638 static void debug_grClipWindow( FxU32 minx
, FxU32 miny
, FxU32 maxx
, FxU32 maxy
)
640 printf("%s %d,%d .. %d,%d\n", __FUNCTION__
,
641 (int) minx
, (int) miny
, (int) maxx
, (int) maxy
);
642 (*real_grClipWindow
)(minx
, miny
, maxx
, maxy
);
645 static void debug_grVertexLayout(FxU32 param
, FxI32 offset
, FxU32 mode
)
647 (*real_grVertexLayout
)(param
, offset
, mode
);
650 static void debug_grGlideGetVertexLayout( void *layout
)
652 (*real_grGlideGetVertexLayout
)(layout
);
655 static void debug_grGlideSetVertexLayout( const void *layout
)
657 (*real_grGlideSetVertexLayout
)(layout
);
660 static void debug_grTexDownloadMipMapLevel( GrChipID_t tmu
,
664 GrAspectRatio_t aspectRatio
,
665 GrTextureFormat_t format
,
669 (*real_grTexDownloadMipMapLevel
)(tmu
, startAddress
, thisLod
, largeLod
,
670 aspectRatio
, format
, evenOdd
, data
);
677 * Examine the context's deviceID to determine what kind of 3dfx hardware
678 * is installed. dlopen() the appropriate Glide library and initialize
679 * this context's Glide function pointers.
680 * Return: true/false = success/failure
682 GLboolean
tdfxInitGlide(tdfxContextPtr tmesa
)
684 static const char *defaultGlide
= "libglide3.so";
689 * XXX this code which selects a Glide library filename given the
690 * deviceID may need to be cleaned up a bit.
691 * Non-Linux systems may have different filenames, for example.
693 switch (tmesa
->fxScreen
->deviceID
) {
694 case PCI_CHIP_BANSHEE
:
695 case PCI_CHIP_VOODOO3
:
696 libName
= "libglide3-v3.so";
698 case PCI_CHIP_VOODOO5
: /* same as PCI_CHIP_VOODOO4 */
699 libName
= "libglide3-v5.so";
703 __driUtilMessage("unrecognized 3dfx deviceID: 0x%x",
704 tmesa
->fxScreen
->deviceID
);
709 libHandle
= dlopen(libName
, RTLD_NOW
);
711 /* The device-specific Glide library filename didn't work, try the
712 * old, generic libglide3.so library.
714 libHandle
= dlopen(defaultGlide
, RTLD_NOW
);
717 "can't find Glide library, dlopen(%s) and dlopen(%s) both failed.",
718 libName
, defaultGlide
);
719 __driUtilMessage("dlerror() message: %s", dlerror());
722 libName
= defaultGlide
;
726 const char *env
= getenv("LIBGL_DEBUG");
727 if (env
&& strstr(env
, "verbose")) {
728 fprintf(stderr
, "libGL: using Glide library %s\n", libName
);
732 #define GET_FUNCTION(PTR, NAME) \
733 tmesa->Glide.PTR = dlsym(libHandle, NAME); \
734 if (!tmesa->Glide.PTR) { \
735 __driUtilMessage("couldn't find Glide function %s in %s.", \
739 GET_FUNCTION(grDrawPoint
, "grDrawPoint");
740 GET_FUNCTION(grDrawLine
, "grDrawLine");
741 GET_FUNCTION(grDrawTriangle
, "grDrawTriangle");
742 GET_FUNCTION(grVertexLayout
, "grVertexLayout");
743 GET_FUNCTION(grDrawVertexArray
, "grDrawVertexArray");
744 GET_FUNCTION(grDrawVertexArrayContiguous
, "grDrawVertexArrayContiguous");
745 GET_FUNCTION(grBufferClear
, "grBufferClear");
746 /*GET_FUNCTION(grBufferSwap, "grBufferSwap");*/
747 GET_FUNCTION(grRenderBuffer
, "grRenderBuffer");
748 GET_FUNCTION(grErrorSetCallback
, "grErrorSetCallback");
749 GET_FUNCTION(grFinish
, "grFinish");
750 GET_FUNCTION(grFlush
, "grFlush");
751 GET_FUNCTION(grSstWinOpen
, "grSstWinOpen");
752 GET_FUNCTION(grSstWinClose
, "grSstWinClose");
754 /* Not in V3 lib, and not used anyway. */
755 GET_FUNCTION(grSetNumPendingBuffers
, "grSetNumPendingBuffers");
757 GET_FUNCTION(grSelectContext
, "grSelectContext");
758 GET_FUNCTION(grSstOrigin
, "grSstOrigin");
759 GET_FUNCTION(grSstSelect
, "grSstSelect");
760 GET_FUNCTION(grAlphaBlendFunction
, "grAlphaBlendFunction");
761 GET_FUNCTION(grAlphaCombine
, "grAlphaCombine");
762 GET_FUNCTION(grAlphaControlsITRGBLighting
, "grAlphaControlsITRGBLighting");
763 GET_FUNCTION(grAlphaTestFunction
, "grAlphaTestFunction");
764 GET_FUNCTION(grAlphaTestReferenceValue
, "grAlphaTestReferenceValue");
765 GET_FUNCTION(grChromakeyMode
, "grChromakeyMode");
766 GET_FUNCTION(grChromakeyValue
, "grChromakeyValue");
767 GET_FUNCTION(grClipWindow
, "grClipWindow");
768 GET_FUNCTION(grColorCombine
, "grColorCombine");
769 GET_FUNCTION(grColorMask
, "grColorMask");
770 GET_FUNCTION(grCullMode
, "grCullMode");
771 GET_FUNCTION(grConstantColorValue
, "grConstantColorValue");
772 GET_FUNCTION(grDepthBiasLevel
, "grDepthBiasLevel");
773 GET_FUNCTION(grDepthBufferFunction
, "grDepthBufferFunction");
774 GET_FUNCTION(grDepthBufferMode
, "grDepthBufferMode");
775 GET_FUNCTION(grDepthMask
, "grDepthMask");
776 GET_FUNCTION(grDisableAllEffects
, "grDisableAllEffects");
777 GET_FUNCTION(grDitherMode
, "grDitherMode");
778 GET_FUNCTION(grFogColorValue
, "grFogColorValue");
779 GET_FUNCTION(grFogMode
, "grFogMode");
780 GET_FUNCTION(grFogTable
, "grFogTable");
781 GET_FUNCTION(grLoadGammaTable
, "grLoadGammaTable");
782 GET_FUNCTION(grSplash
, "grSplash");
783 GET_FUNCTION(grGet
, "grGet");
784 GET_FUNCTION(grGetString
, "grGetString");
785 GET_FUNCTION(grQueryResolutions
, "grQueryResolutions");
786 GET_FUNCTION(grReset
, "grReset");
787 GET_FUNCTION(grGetProcAddress
, "grGetProcAddress");
788 GET_FUNCTION(grEnable
, "grEnable");
789 GET_FUNCTION(grDisable
, "grDisable");
790 GET_FUNCTION(grCoordinateSpace
, "grCoordinateSpace");
791 GET_FUNCTION(grDepthRange
, "grDepthRange");
792 GET_FUNCTION(grStippleMode
, "grStippleMode");
793 GET_FUNCTION(grStipplePattern
, "grStipplePattern");
794 GET_FUNCTION(grViewport
, "grViewport");
795 GET_FUNCTION(grTexCalcMemRequired
, "grTexCalcMemRequired");
796 GET_FUNCTION(grTexTextureMemRequired
, "grTexTextureMemRequired");
797 GET_FUNCTION(grTexMinAddress
, "grTexMinAddress");
798 GET_FUNCTION(grTexMaxAddress
, "grTexMaxAddress");
799 GET_FUNCTION(grTexNCCTable
, "grTexNCCTable");
800 GET_FUNCTION(grTexSource
, "grTexSource");
801 GET_FUNCTION(grTexClampMode
, "grTexClampMode");
802 GET_FUNCTION(grTexCombine
, "grTexCombine");
803 GET_FUNCTION(grTexDetailControl
, "grTexDetailControl");
804 GET_FUNCTION(grTexFilterMode
, "grTexFilterMode");
805 GET_FUNCTION(grTexLodBiasValue
, "grTexLodBiasValue");
806 GET_FUNCTION(grTexDownloadMipMap
, "grTexDownloadMipMap");
807 GET_FUNCTION(grTexDownloadMipMapLevel
, "grTexDownloadMipMapLevel");
808 GET_FUNCTION(grTexDownloadMipMapLevelPartial
, "grTexDownloadMipMapLevelPartial");
809 GET_FUNCTION(grTexDownloadTable
, "grTexDownloadTable");
810 GET_FUNCTION(grTexDownloadTablePartial
, "grTexDownloadTablePartial");
811 GET_FUNCTION(grTexMipMapMode
, "grTexMipMapMode");
812 GET_FUNCTION(grTexMultibase
, "grTexMultibase");
813 GET_FUNCTION(grTexMultibaseAddress
, "grTexMultibaseAddress");
814 GET_FUNCTION(grLfbLock
, "grLfbLock");
815 GET_FUNCTION(grLfbUnlock
, "grLfbUnlock");
816 GET_FUNCTION(grLfbConstantAlpha
, "grLfbConstantAlpha");
817 GET_FUNCTION(grLfbConstantDepth
, "grLfbConstantDepth");
818 GET_FUNCTION(grLfbWriteColorSwizzle
, "grLfbWriteColorSwizzle");
819 GET_FUNCTION(grLfbWriteColorFormat
, "grLfbWriteColorFormat");
820 GET_FUNCTION(grLfbWriteRegion
, "grLfbWriteRegion");
821 GET_FUNCTION(grLfbReadRegion
, "grLfbReadRegion");
822 GET_FUNCTION(grGlideInit
, "grGlideInit");
823 GET_FUNCTION(grGlideShutdown
, "grGlideShutdown");
824 GET_FUNCTION(grGlideGetState
, "grGlideGetState");
825 GET_FUNCTION(grGlideSetState
, "grGlideSetState");
826 GET_FUNCTION(grGlideGetVertexLayout
, "grGlideGetVertexLayout");
827 GET_FUNCTION(grGlideSetVertexLayout
, "grGlideSetVertexLayout");
829 /* Glide utility functions */
830 GET_FUNCTION(guFogGenerateExp
, "guFogGenerateExp");
831 GET_FUNCTION(guFogGenerateExp2
, "guFogGenerateExp2");
832 GET_FUNCTION(guFogGenerateLinear
, "guFogGenerateLinear");
835 GET_FUNCTION(grDRIOpen
, "grDRIOpen");
836 GET_FUNCTION(grDRIPosition
, "grDRIPosition");
837 /*GET_FUNCTION(grDRILostContext, "grDRILostContext");*/
838 GET_FUNCTION(grDRIImportFifo
, "grDRIImportFifo");
839 GET_FUNCTION(grDRIInvalidateAll
, "grDRIInvalidateAll");
840 GET_FUNCTION(grDRIResetSAREA
, "grDRIResetSAREA");
841 GET_FUNCTION(grDRIBufferSwap
, "grDRIBufferSwap");
844 * Extension functions:
845 * Just use dlysm() because we want a NULL pointer if the function is
848 /* PIXEXT extension */
849 tmesa
->Glide
.grStencilFunc
= dlsym(libHandle
, "grStencilFunc");
850 tmesa
->Glide
.grStencilMask
= dlsym(libHandle
, "grStencilMask");
851 tmesa
->Glide
.grStencilOp
= dlsym(libHandle
, "grStencilOp");
852 tmesa
->Glide
.grBufferClearExt
= dlsym(libHandle
, "grBufferClearExt");
853 tmesa
->Glide
.grColorMaskExt
= dlsym(libHandle
, "grColorMaskExt");
854 /* COMBINE extension */
855 tmesa
->Glide
.grColorCombineExt
= dlsym(libHandle
, "grColorCombineExt");
856 tmesa
->Glide
.grTexColorCombineExt
= dlsym(libHandle
, "grTexColorCombineExt");
857 tmesa
->Glide
.grAlphaCombineExt
= dlsym(libHandle
, "grAlphaCombineExt");
858 tmesa
->Glide
.grTexAlphaCombineExt
= dlsym(libHandle
, "grTexAlphaCombineExt");
859 tmesa
->Glide
.grAlphaBlendFunctionExt
= dlsym(libHandle
, "grAlphaBlendFunctionExt");
860 tmesa
->Glide
.grConstantColorValueExt
= dlsym(libHandle
, "grConstantColorValueExt");
862 tmesa
->Glide
.txImgQuantize
= dlsym(libHandle
, "txImgQuantize");
863 tmesa
->Glide
.txImgDequantizeFXT1
= dlsym(libHandle
, "_txImgDequantizeFXT1");
864 tmesa
->Glide
.txErrorSetCallback
= dlsym(libHandle
, "txErrorSetCallback");
867 /* wrap the drawing functions so we can trap them */
868 real_grDrawTriangle
= tmesa
->Glide
.grDrawTriangle
;
869 tmesa
->Glide
.grDrawTriangle
= debug_grDrawTriangle
;
871 real_grDrawPoint
= tmesa
->Glide
.grDrawPoint
;
872 tmesa
->Glide
.grDrawPoint
= debug_grDrawPoint
;
874 real_grDrawVertexArray
= tmesa
->Glide
.grDrawVertexArray
;
875 tmesa
->Glide
.grDrawVertexArray
= debug_grDrawVertexArray
;
877 real_grDrawVertexArrayContiguous
= tmesa
->Glide
.grDrawVertexArrayContiguous
;
878 tmesa
->Glide
.grDrawVertexArrayContiguous
= debug_grDrawVertexArrayContiguous
;
880 real_grClipWindow
= tmesa
->Glide
.grClipWindow
;
881 tmesa
->Glide
.grClipWindow
= debug_grClipWindow
;
883 real_grVertexLayout
= tmesa
->Glide
.grVertexLayout
;
884 tmesa
->Glide
.grVertexLayout
= debug_grVertexLayout
;
886 real_grGlideGetVertexLayout
= tmesa
->Glide
.grGlideGetVertexLayout
;
887 tmesa
->Glide
.grGlideGetVertexLayout
= debug_grGlideGetVertexLayout
;
889 real_grGlideSetVertexLayout
= tmesa
->Glide
.grGlideSetVertexLayout
;
890 tmesa
->Glide
.grGlideSetVertexLayout
= debug_grGlideSetVertexLayout
;
892 real_grTexDownloadMipMapLevel
= tmesa
->Glide
.grTexDownloadMipMapLevel
;
893 tmesa
->Glide
.grTexDownloadMipMapLevel
= debug_grTexDownloadMipMapLevel
;