From d3fd7ba8af15bead2f770d68a893449adeb11397 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 20 Jan 2004 02:49:27 +0000 Subject: Before calling _mesa_create_context(), initialize a dd_function_table struct by calling _mesa_init_driver_functions() and then plugging in the driver- specific functions. In particular, make sure ctx->Driver.NewTextureObject points to the appropriate driver function so that _all_ texture objects are augmented with the driver-specific data. Put in a bunch of assertions in the texture-related driver functions that texObj->DriverData is valid. Remove old dead code in near future. --- src/mesa/Makefile.X11 | 1 + src/mesa/drivers/dri/fb/fb_dri.c | 92 ++++++--------- src/mesa/drivers/dri/ffb/Makefile.solo | 1 + src/mesa/drivers/dri/gamma/Makefile.solo | 3 +- src/mesa/drivers/dri/gamma/gamma_context.c | 17 ++- src/mesa/drivers/dri/gamma/gamma_context.h | 2 +- src/mesa/drivers/dri/gamma/gamma_tex.c | 110 +++++++++++++---- src/mesa/drivers/dri/i810/Makefile.solo | 1 + src/mesa/drivers/dri/i810/i810context.c | 18 ++- src/mesa/drivers/dri/i810/i810ioctl.c | 8 +- src/mesa/drivers/dri/i810/i810ioctl.h | 2 +- src/mesa/drivers/dri/i810/i810tex.c | 83 +++++++------ src/mesa/drivers/dri/i810/i810tex.h | 2 +- src/mesa/drivers/dri/i830/Makefile.solo | 1 + src/mesa/drivers/dri/i830/i830_context.c | 26 ++++- src/mesa/drivers/dri/i830/i830_ioctl.c | 12 +- src/mesa/drivers/dri/i830/i830_ioctl.h | 2 +- src/mesa/drivers/dri/i830/i830_tex.c | 67 ++++++----- src/mesa/drivers/dri/i830/i830_tex.h | 2 +- src/mesa/drivers/dri/mga/Makefile.solo | 1 + src/mesa/drivers/dri/mga/mga_xmesa.c | 22 +++- src/mesa/drivers/dri/mga/mgadd.c | 12 +- src/mesa/drivers/dri/mga/mgadd.h | 2 +- src/mesa/drivers/dri/mga/mgaioctl.c | 14 +-- src/mesa/drivers/dri/mga/mgaioctl.h | 2 +- src/mesa/drivers/dri/mga/mgatex.c | 91 ++++++++------- src/mesa/drivers/dri/mga/mgatex.h | 2 +- src/mesa/drivers/dri/r128/Makefile.solo | 1 + src/mesa/drivers/dri/r128/r128_context.c | 21 +++- src/mesa/drivers/dri/r128/r128_dd.c | 23 ++-- src/mesa/drivers/dri/r128/r128_dd.h | 2 +- src/mesa/drivers/dri/r128/r128_ioctl.c | 6 +- src/mesa/drivers/dri/r128/r128_ioctl.h | 2 +- src/mesa/drivers/dri/r128/r128_tex.c | 77 ++++++------ src/mesa/drivers/dri/r128/r128_tex.h | 2 +- src/mesa/drivers/dri/r200/Makefile.solo | 1 + src/mesa/drivers/dri/r200/r200_context.c | 61 +++++++--- src/mesa/drivers/dri/r200/r200_context.h | 2 +- src/mesa/drivers/dri/r200/r200_ioctl.c | 8 +- src/mesa/drivers/dri/r200/r200_ioctl.h | 2 +- src/mesa/drivers/dri/r200/r200_state.c | 96 +++++++-------- src/mesa/drivers/dri/r200/r200_state.h | 3 +- src/mesa/drivers/dri/r200/r200_swtcl.c | 2 +- src/mesa/drivers/dri/r200/r200_tex.c | 101 +++++++++------- src/mesa/drivers/dri/r200/r200_tex.h | 2 +- src/mesa/drivers/dri/radeon/Makefile.solo | 1 + src/mesa/drivers/dri/radeon/radeon_context.c | 46 +++++--- src/mesa/drivers/dri/radeon/radeon_context.h | 2 +- src/mesa/drivers/dri/radeon/radeon_tex.c | 92 +++++++-------- src/mesa/drivers/dri/radeon/radeon_tex.h | 2 +- src/mesa/drivers/dri/sis/Makefile.solo | 1 + src/mesa/drivers/dri/sis/sis_context.c | 20 +++- src/mesa/drivers/dri/sis/sis_dd.c | 23 ++-- src/mesa/drivers/dri/sis/sis_dd.h | 2 +- src/mesa/drivers/dri/sis/sis_tex.c | 134 ++++++++++----------- src/mesa/drivers/dri/sis/sis_tex.h | 2 +- src/mesa/drivers/dri/tdfx/Makefile.solo | 1 + src/mesa/drivers/dri/tdfx/tdfx_context.c | 21 +++- src/mesa/drivers/dri/tdfx/tdfx_dd.c | 45 +++---- src/mesa/drivers/dri/tdfx/tdfx_dd.h | 3 +- src/mesa/drivers/dri/tdfx/tdfx_render.c | 14 +-- src/mesa/drivers/dri/tdfx/tdfx_render.h | 2 +- src/mesa/drivers/dri/tdfx/tdfx_state.c | 34 ------ src/mesa/drivers/dri/tdfx/tdfx_tex.c | 169 ++++++++++++++------------- src/mesa/drivers/dri/tdfx/tdfx_tex.h | 57 +-------- src/mesa/drivers/fbdev/glfbdev.c | 59 ++-------- src/mesa/drivers/glide/fxapi.c | 8 +- src/mesa/drivers/glide/fxddtex.c | 128 +++++++++----------- src/mesa/drivers/glide/fxdrv.h | 3 + src/mesa/drivers/osmesa/osmesa.c | 63 +++------- src/mesa/drivers/windows/gdi/wmesa.c | 73 +++++------- src/mesa/drivers/x11/xm_api.c | 59 +++++----- src/mesa/drivers/x11/xm_dd.c | 125 +++++--------------- src/mesa/drivers/x11/xmesaP.h | 11 +- src/mesa/main/bufferobj.c | 12 -- src/mesa/main/context.c | 73 +++++++----- src/mesa/main/context.h | 8 +- src/mesa/main/dd.h | 99 +++++++--------- src/mesa/sources | 3 + 79 files changed, 1178 insertions(+), 1225 deletions(-) (limited to 'src') diff --git a/src/mesa/Makefile.X11 b/src/mesa/Makefile.X11 index 3031daf068..c4def10485 100644 --- a/src/mesa/Makefile.X11 +++ b/src/mesa/Makefile.X11 @@ -24,6 +24,7 @@ ASM_SOURCES = # This should get set in Make-config someday: DRIVER_SOURCES = \ + $(COMMON_DRIVER_SOURCES) \ $(X11_DRIVER_SOURCES) \ $(GLIDE_DRIVER_SOURCES) \ $(SVGA_DRIVER_SOURCES) \ diff --git a/src/mesa/drivers/dri/fb/fb_dri.c b/src/mesa/drivers/dri/fb/fb_dri.c index f62f0d4d74..2589c07142 100644 --- a/src/mesa/drivers/dri/fb/fb_dri.c +++ b/src/mesa/drivers/dri/fb/fb_dri.c @@ -77,6 +77,7 @@ #include "tnl/tnl.h" #include "tnl/t_context.h" #include "tnl/t_pipeline.h" +#include "drivers/common/driverfuncs.h" @@ -118,6 +119,10 @@ update_state( GLcontext *ctx, GLuint new_state ) } +/** + * Called by ctx->Driver.GetBufferSize from in core Mesa to query the + * current framebuffer size. + */ static void get_buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height ) { @@ -156,46 +161,14 @@ set_buffer( GLcontext *ctx, GLframebuffer *buffer, GLuint bufferBit ) static void -init_core_functions( GLcontext *ctx ) +init_core_functions( struct dd_function_table *functions ) { - ctx->Driver.GetString = get_string; - ctx->Driver.UpdateState = update_state; - ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; - ctx->Driver.GetBufferSize = get_buffer_size; - - ctx->Driver.Accum = _swrast_Accum; - ctx->Driver.Bitmap = _swrast_Bitmap; - ctx->Driver.Clear = _swrast_Clear; /* could accelerate with blits */ - ctx->Driver.CopyPixels = _swrast_CopyPixels; - ctx->Driver.DrawPixels = _swrast_DrawPixels; - ctx->Driver.ReadPixels = _swrast_ReadPixels; - ctx->Driver.DrawBuffer = _swrast_DrawBuffer; - - ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format; - ctx->Driver.TexImage1D = _mesa_store_teximage1d; - ctx->Driver.TexImage2D = _mesa_store_teximage2d; - ctx->Driver.TexImage3D = _mesa_store_teximage3d; - ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d; - ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d; - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; - ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; - - ctx->Driver.CompressedTexImage1D = _mesa_store_compressed_teximage1d; - ctx->Driver.CompressedTexImage2D = _mesa_store_compressed_teximage2d; - ctx->Driver.CompressedTexImage3D = _mesa_store_compressed_teximage3d; - ctx->Driver.CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d; - ctx->Driver.CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d; - ctx->Driver.CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d; - - ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; - ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; - ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; - ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; - ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; - ctx->Driver.CopyColorTable = _swrast_CopyColorTable; - ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable; - ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D; - ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D; + functions->GetString = get_string; + functions->UpdateState = update_state; + functions->ResizeBuffers = _swrast_alloc_buffers; + functions->GetBufferSize = get_buffer_size; + + functions->Clear = _swrast_Clear; /* could accelerate with blits */ } @@ -294,7 +267,7 @@ init_core_functions( GLcontext *ctx ) #define FETCH_CI_PIXEL(CI, P) \ CI = P[0] -#include "swrast/s_spantemp.h" + #include "swrast/s_spantemp.h" @@ -321,6 +294,7 @@ fbCreateContext( const __GLcontextModes *glVisual, { fbContextPtr fbmesa; GLcontext *ctx, *shareCtx; + struct dd_function_table functions; assert(glVisual); assert(driContextPriv); @@ -330,6 +304,11 @@ fbCreateContext( const __GLcontextModes *glVisual, if ( !fbmesa ) return GL_FALSE; + /* Init default driver functions then plug in our FBdev-specific functions + */ + _mesa_init_driver_functions(&functions); + init_core_functions(&functions); + /* Allocate the Mesa context */ if (sharedContextPrivate) shareCtx = ((fbContextPtr) sharedContextPrivate)->glCtx; @@ -337,8 +316,7 @@ fbCreateContext( const __GLcontextModes *glVisual, shareCtx = NULL; ctx = fbmesa->glCtx = _mesa_create_context(glVisual, shareCtx, - (void *) fbmesa, - GL_TRUE); + &functions, (void *) fbmesa); if (!fbmesa->glCtx) { FREE(fbmesa); return GL_FALSE; @@ -346,7 +324,6 @@ fbCreateContext( const __GLcontextModes *glVisual, driContextPriv->driverPrivate = fbmesa; /* Create module contexts */ - init_core_functions( ctx ); _swrast_CreateContext( ctx ); _ac_CreateContext( ctx ); _tnl_CreateContext( ctx ); @@ -354,7 +331,6 @@ fbCreateContext( const __GLcontextModes *glVisual, _swsetup_Wakeup( ctx ); - /* swrast init -- need to verify these tests - I just plucked the * numbers out of the air. (KW) */ @@ -496,8 +472,6 @@ fbCreateBuffer( __DRIscreenPrivate *driScrnPriv, } - - static void fbDestroyBuffer(__DRIdrawablePrivate *driDrawPriv) { @@ -610,15 +584,14 @@ __driRegisterExtensions( void ) } - - /* * This is the bootstrap function for the driver. * The __driCreateScreen name is the symbol that libGL.so fetches. * Return: pointer to a __DRIscreenPrivate. */ -void *__driCreateScreen(struct DRIDriverRec *driver, - struct DRIDriverContextRec *driverContext) +void * +__driCreateScreen(struct DRIDriverRec *driver, + struct DRIDriverContextRec *driverContext) { __DRIscreenPrivate *psp; psp = __driUtilCreateScreenNoDRM(driver, driverContext, &fbAPI); @@ -626,6 +599,7 @@ void *__driCreateScreen(struct DRIDriverRec *driver, } + /** * \brief Establish the set of modes available for the display. * @@ -661,8 +635,11 @@ const __GLcontextModes __glModes[] = { .depthBits = 16, .stencilBits = 0, .numAuxBuffers= 0, .level = 0, .pixmapMode = GL_FALSE, }, }; -static int __driInitScreenModes( const DRIDriverContext *ctx, - int *numModes, const __GLcontextModes **modes) + + +static int +__driInitScreenModes( const DRIDriverContext *ctx, + int *numModes, const __GLcontextModes **modes) { *numModes = sizeof(__glModes)/sizeof(__GLcontextModes *); *modes = &__glModes[0]; @@ -671,7 +648,8 @@ static int __driInitScreenModes( const DRIDriverContext *ctx, -static int __driValidateMode(const DRIDriverContext *ctx ) +static int +__driValidateMode(const DRIDriverContext *ctx ) { return 1; } @@ -685,9 +663,10 @@ static int __driValidateMode(const DRIDriverContext *ctx ) #else # define DRM_PAGE_SIZE 4096 #endif - -static int __driInitFBDev( struct DRIDriverContextRec *ctx ) + +static int +__driInitFBDev( struct DRIDriverContextRec *ctx ) { int id; ctx->shared.hFrameBuffer = ctx->FBStart; @@ -712,7 +691,8 @@ static int __driInitFBDev( struct DRIDriverContextRec *ctx ) return 1; } -static void __driHaltFBDev( struct DRIDriverContextRec *ctx ) +static void +__driHaltFBDev( struct DRIDriverContextRec *ctx ) { } diff --git a/src/mesa/drivers/dri/ffb/Makefile.solo b/src/mesa/drivers/dri/ffb/Makefile.solo index 4333e0685f..ebf1a8c5d1 100644 --- a/src/mesa/drivers/dri/ffb/Makefile.solo +++ b/src/mesa/drivers/dri/ffb/Makefile.solo @@ -24,6 +24,7 @@ DEFINES += \ # MINIGLX_SOURCES = server/ffb_dri.c DRIVER_SOURCES = ffb_bitmap.c \ + ../../common/driverfuncs.c \ ../common/mm.c \ ../common/utils.c \ ../common/texmem.c \ diff --git a/src/mesa/drivers/dri/gamma/Makefile.solo b/src/mesa/drivers/dri/gamma/Makefile.solo index 04b7b26564..70146e58cb 100644 --- a/src/mesa/drivers/dri/gamma/Makefile.solo +++ b/src/mesa/drivers/dri/gamma/Makefile.solo @@ -1,4 +1,4 @@ -# $Id: Makefile.solo,v 1.1 2003/12/12 15:30:52 brianp Exp $ +# $Id: Makefile.solo,v 1.2 2004/01/20 02:49:27 brianp Exp $ # Mesa 3-D graphics library # Version: 5.0 @@ -39,6 +39,7 @@ DRIVER_SOURCES = \ gamma_tris.c \ gamma_vb.c \ gamma_xmesa.c \ + ../../common/driverfuncs.c \ ../common/mm.c \ ../common/utils.c \ ../common/texmem.c \ diff --git a/src/mesa/drivers/dri/gamma/gamma_context.c b/src/mesa/drivers/dri/gamma/gamma_context.c index df9bc5b54f..ff3b3a47fe 100644 --- a/src/mesa/drivers/dri/gamma/gamma_context.c +++ b/src/mesa/drivers/dri/gamma/gamma_context.c @@ -33,6 +33,8 @@ #include "tnl/tnl.h" #include "tnl/t_pipeline.h" +#include "drivers/common/driverfuncs.h" + #include "context.h" #include "simple_list.h" #include "imports.h" @@ -75,9 +77,17 @@ GLboolean gammaCreateContext( const __GLcontextModes *glVisual, gammaScreenPtr gammascrn; GLINTSAREADRIPtr saPriv=(GLINTSAREADRIPtr)(((char*)sPriv->pSAREA)+ sizeof(XF86DRISAREARec)); + struct dd_function_table functions; gmesa = (gammaContextPtr) CALLOC( sizeof(*gmesa) ); - if ( !gmesa ) return GL_FALSE; + if (!gmesa) + return GL_FALSE; + + /* Init default driver functions then plug in our gamma-specific functions + * (the texture functions are especially important) + */ + _mesa_init_driver_functions( &functions ); + gammaDDInitTextureFuncs( &functions ); /* Allocate the Mesa context */ if (sharedContextPrivate) @@ -85,7 +95,8 @@ GLboolean gammaCreateContext( const __GLcontextModes *glVisual, else shareCtx = NULL; - gmesa->glCtx = _mesa_create_context(glVisual, shareCtx, (void *) gmesa, GL_TRUE); + gmesa->glCtx = _mesa_create_context(glVisual, shareCtx, + &functions, (void *) gmesa); if (!gmesa->glCtx) { FREE(gmesa); return GL_FALSE; @@ -152,10 +163,10 @@ GLboolean gammaCreateContext( const __GLcontextModes *glVisual, gammaInitVB( ctx ); gammaDDInitExtensions( ctx ); + /* XXX these should really go right after _mesa_init_driver_functions() */ gammaDDInitDriverFuncs( ctx ); gammaDDInitStateFuncs( ctx ); gammaDDInitSpanFuncs( ctx ); - gammaDDInitTextureFuncs( ctx ); gammaDDInitTriFuncs( ctx ); gammaDDInitState( gmesa ); diff --git a/src/mesa/drivers/dri/gamma/gamma_context.h b/src/mesa/drivers/dri/gamma/gamma_context.h index 5f183ff264..e969961644 100644 --- a/src/mesa/drivers/dri/gamma/gamma_context.h +++ b/src/mesa/drivers/dri/gamma/gamma_context.h @@ -191,7 +191,7 @@ void gammaDDInitSpanFuncs( GLcontext *ctx ); void gammaDDInitState( gammaContextPtr gmesa ); void gammaInitHW( gammaContextPtr gmesa ); void gammaDDInitStateFuncs( GLcontext *ctx ); -void gammaDDInitTextureFuncs( GLcontext *ctx ); +void gammaDDInitTextureFuncs( struct dd_function_table *table ); void gammaDDInitTriFuncs( GLcontext *ctx ); void gammaUpdateWindow( GLcontext *ctx ); diff --git a/src/mesa/drivers/dri/gamma/gamma_tex.c b/src/mesa/drivers/dri/gamma/gamma_tex.c index e0bc301d9d..b2f1d996b9 100644 --- a/src/mesa/drivers/dri/gamma/gamma_tex.c +++ b/src/mesa/drivers/dri/gamma/gamma_tex.c @@ -299,7 +299,8 @@ static void gammaTexSubImage2D( GLcontext *ctx, texImage); } - +#if 0 +/* no longer needed */ static void gammaBindTexture( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj ) { @@ -352,7 +353,7 @@ static void gammaBindTexture( GLcontext *ctx, GLenum target, gammaSetTexBorderColor( gmesa, t, tObj->_BorderChan ); } } - +#endif static void gammaDeleteTexture( GLcontext *ctx, struct gl_texture_object *tObj ) { @@ -378,7 +379,79 @@ static GLboolean gammaIsTextureResident( GLcontext *ctx, return t && t->MemBlock; } -static void gammaInitTextureObjects( GLcontext *ctx ) +/** + * Allocate a new texture object. + * Called via ctx->Driver.NewTextureObject. + * Note: this function will be called during context creation to + * allocate the default texture objects. + */ +static struct gl_texture_object * +gammaNewTextureObject( GLcontext *ctx, GLuint name, GLenum target ) +{ + gammaContextPtr gmesa = GAMMA_CONTEXT( ctx ); + struct gl_texture_object *obj; + gammaTextureObjectPtr t; + + obj = _mesa_new_texture_object(ctx, name, target); + if (!obj) + return NULL; + + t = CALLOC_STRUCT(gamma_texture_object_t); + if (!t) { + _mesa_delete_texture_object(ctx, obj); + return NULL; + } + + /* Initialize non-image-dependent parts of the state: + */ + t->globj = obj; + obj->DriverData = t; + + t->TextureAddressMode = TextureAddressModeEnable | TAM_Operation_3D | + TAM_DY_Enable | TAM_LODEnable; + t->TextureReadMode = TextureReadModeEnable | TRM_PrimaryCacheEnable | + TRM_MipMapEnable | TRM_BorderClamp | TRM_Border; + t->TextureColorMode = TextureColorModeEnable; + t->TextureFilterMode = TextureFilterModeEnable; + + if (target == GL_TEXTURE_2D) { + t->TextureAddressMode |= TAM_TexMapType_2D; + t->TextureReadMode |= TRM_TexMapType_2D; + } + else if (target == GL_TEXTURE_1D) { + t->TextureAddressMode |= TAM_TexMapType_1D; + t->TextureReadMode |= TRM_TexMapType_1D; + } + + t->TextureColorMode = TextureColorModeEnable; + + t->TextureFilterMode = TextureFilterModeEnable; + +#ifdef MESA_LITTLE_ENDIAN + t->TextureFormat = (TF_LittleEndian | +#else + t->TextureFormat = (TF_BigEndian | +#endif + TF_ColorOrder_RGB | + TF_OutputFmt_Texel); + + t->dirty_images = ~0; + + make_empty_list( t ); + + gammaSetTexWrapping( t, obj->WrapS, obj->WrapT ); + gammaSetTexFilter( gmesa, t, obj->MinFilter, obj->MagFilter, + ctx->Texture.Unit[ctx->Texture.CurrentUnit].LodBias); + + gammaSetTexBorderColor( gmesa, t, obj->_BorderChan ); + + return obj; +} + + +#if 0 +/* no longer needed */ +void gammaInitTextureObjects( GLcontext *ctx ) { struct gl_texture_object *texObj; GLuint tmp = ctx->Texture.CurrentUnit; @@ -403,29 +476,16 @@ static void gammaInitTextureObjects( GLcontext *ctx ) ctx->Texture.CurrentUnit = tmp; } +#endif -void gammaDDInitTextureFuncs( GLcontext *ctx ) +void gammaDDInitTextureFuncs( struct dd_function_table *functions ) { - ctx->Driver.TexEnv = gammaTexEnv; - ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format; - ctx->Driver.TexImage1D = _mesa_store_teximage1d; - ctx->Driver.TexImage2D = gammaTexImage2D; - ctx->Driver.TexImage3D = _mesa_store_teximage3d; - ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d; - ctx->Driver.TexSubImage2D = gammaTexSubImage2D; - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; - ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; - ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; - ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; - ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; - ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; - ctx->Driver.BindTexture = gammaBindTexture; - ctx->Driver.DeleteTexture = gammaDeleteTexture; - ctx->Driver.TexParameter = gammaTexParameter; - ctx->Driver.UpdateTexturePalette = 0; - ctx->Driver.IsTextureResident = gammaIsTextureResident; - ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; - - gammaInitTextureObjects( ctx ); + functions->TexEnv = gammaTexEnv; + functions->TexImage2D = gammaTexImage2D; + functions->TexSubImage2D = gammaTexSubImage2D; + /*functions->BindTexture = gammaBindTexture;*/ + functions->DeleteTexture = gammaDeleteTexture; + functions->TexParameter = gammaTexParameter; + functions->IsTextureResident = gammaIsTextureResident; } diff --git a/src/mesa/drivers/dri/i810/Makefile.solo b/src/mesa/drivers/dri/i810/Makefile.solo index 19fca1864c..2faa5f64f3 100644 --- a/src/mesa/drivers/dri/i810/Makefile.solo +++ b/src/mesa/drivers/dri/i810/Makefile.solo @@ -35,6 +35,7 @@ DRIVER_SOURCES = \ i810texstate.c \ i810tris.c \ i810vb.c \ + ../../common/driverfuncs.c \ ../common/mm.c \ ../common/utils.c \ ../common/texmem.c \ diff --git a/src/mesa/drivers/dri/i810/i810context.c b/src/mesa/drivers/dri/i810/i810context.c index d81431765f..78698e861c 100644 --- a/src/mesa/drivers/dri/i810/i810context.c +++ b/src/mesa/drivers/dri/i810/i810context.c @@ -47,6 +47,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "tnl/t_pipeline.h" +#include "drivers/common/driverfuncs.h" + #include "i810screen.h" #include "i810_dri.h" @@ -152,6 +154,7 @@ i810CreateContext( const __GLcontextModes *mesaVis, i810ScreenPrivate *i810Screen = (i810ScreenPrivate *)sPriv->private; I810SAREAPtr saPriv = (I810SAREAPtr) (((GLubyte *)sPriv->pSAREA) + i810Screen->sarea_priv_offset); + struct dd_function_table functions; /* Allocate i810 context */ imesa = (i810ContextPtr) CALLOC_STRUCT(i810_context_t); @@ -159,12 +162,20 @@ i810CreateContext( const __GLcontextModes *mesaVis, return GL_FALSE; } + /* Init default driver functions then plug in our I810-specific functions + * (the texture functions are especially important) + */ + _mesa_init_driver_functions( &functions ); + i810InitTextureFuncs( &functions ); + i810InitIoctlFuncs( &functions ); + /* Allocate the Mesa context */ if (sharedContextPrivate) shareCtx = ((i810ContextPtr) sharedContextPrivate)->glCtx; else shareCtx = NULL; - imesa->glCtx = _mesa_create_context(mesaVis, shareCtx, (void*) imesa, GL_TRUE); + imesa->glCtx = _mesa_create_context(mesaVis, shareCtx, + &functions, (void*) imesa); if (!imesa->glCtx) { FREE(imesa); return GL_FALSE; @@ -274,14 +285,15 @@ i810CreateContext( const __GLcontextModes *mesaVis, _math_matrix_ctr( &imesa->ViewportMatrix ); driInitExtensions( ctx, card_extensions, GL_TRUE ); + /* XXX these should really go right after _mesa_init_driver_functions() */ i810InitStateFuncs( ctx ); - i810InitTextureFuncs( ctx ); i810InitTriFuncs( ctx ); i810InitSpanFuncs( ctx ); - i810InitIoctlFuncs( ctx ); i810InitVB( ctx ); i810InitState( ctx ); + driInitTextureObjects( ctx, &imesa->swapped, DRI_TEXMGR_DO_TEXTURE_2D); + #if DO_DEBUG I810_DEBUG = driParseDebugString( getenv( "I810_DEBUG" ), debug_control ); diff --git a/src/mesa/drivers/dri/i810/i810ioctl.c b/src/mesa/drivers/dri/i810/i810ioctl.c index d769d58d56..88a048b396 100644 --- a/src/mesa/drivers/dri/i810/i810ioctl.c +++ b/src/mesa/drivers/dri/i810/i810ioctl.c @@ -502,9 +502,9 @@ static void i810Finish( GLcontext *ctx ) i810DmaFinish( imesa ); } -void i810InitIoctlFuncs( GLcontext *ctx ) +void i810InitIoctlFuncs( struct dd_function_table *functions ) { - ctx->Driver.Flush = i810Flush; - ctx->Driver.Clear = i810Clear; - ctx->Driver.Finish = i810Finish; + functions->Flush = i810Flush; + functions->Clear = i810Clear; + functions->Finish = i810Finish; } diff --git a/src/mesa/drivers/dri/i810/i810ioctl.h b/src/mesa/drivers/dri/i810/i810ioctl.h index e287b57b19..61399ee7b7 100644 --- a/src/mesa/drivers/dri/i810/i810ioctl.h +++ b/src/mesa/drivers/dri/i810/i810ioctl.h @@ -14,7 +14,7 @@ void i810WaitAgeLocked( i810ContextPtr imesa, int age ); void i810WaitAge( i810ContextPtr imesa, int age ); void i810DmaFinish( i810ContextPtr imesa ); void i810RegetLockQuiescent( i810ContextPtr imesa ); -void i810InitIoctlFuncs( GLcontext *ctx ); +void i810InitIoctlFuncs( struct dd_function_table *functions ); void i810CopyBuffer( const __DRIdrawablePrivate *dpriv ); void i810PageFlip( const __DRIdrawablePrivate *dpriv ); int i810_check_copy(int fd); diff --git a/src/mesa/drivers/dri/i810/i810tex.c b/src/mesa/drivers/dri/i810/i810tex.c index bab5865e82..bf404e36f0 100644 --- a/src/mesa/drivers/dri/i810/i810tex.c +++ b/src/mesa/drivers/dri/i810/i810tex.c @@ -160,13 +160,16 @@ static void i810SetTexFilter(i810ContextPtr imesa, } -static void i810SetTexBorderColor(i810TextureObjectPtr t, - GLubyte color[4]) +static void +i810SetTexBorderColor( i810TextureObjectPtr t, GLubyte color[4] ) { /* Need a fallback. */ } -static i810TextureObjectPtr i810AllocTexObj( GLcontext *ctx, struct gl_texture_object *texObj ) + + +static i810TextureObjectPtr +i810AllocTexObj( GLcontext *ctx, struct gl_texture_object *texObj ) { i810TextureObjectPtr t; i810ContextPtr imesa = I810_CONTEXT(ctx); @@ -220,8 +223,8 @@ static void i810TexParameter( GLcontext *ctx, GLenum target, { i810ContextPtr imesa = I810_CONTEXT(ctx); i810TextureObjectPtr t = (i810TextureObjectPtr) tObj->DriverData; - if (!t) - return; + + assert(t); if ( target != GL_TEXTURE_2D ) return; @@ -338,6 +341,7 @@ static void i810TexImage1D( GLcontext *ctx, GLenum target, GLint level, struct gl_texture_image *texImage ) { i810TextureObjectPtr t = (i810TextureObjectPtr) texObj->DriverData; + assert(t); if (t) { i810SwapOutTexObj( imesa, t ); } @@ -367,6 +371,7 @@ static void i810TexImage2D( GLcontext *ctx, GLenum target, GLint level, struct gl_texture_image *texImage ) { driTextureObject *t = (driTextureObject *) texObj->DriverData; + assert(t); if (t) { I810_FIREVERTICES( I810_CONTEXT(ctx) ); driSwapOutTextureObject( t ); @@ -381,7 +386,6 @@ static void i810TexImage2D( GLcontext *ctx, GLenum target, GLint level, _mesa_store_teximage2d( ctx, target, level, internalFormat, width, height, border, format, type, pixels, packing, texObj, texImage ); - } static void i810TexSubImage2D( GLcontext *ctx, @@ -396,7 +400,7 @@ static void i810TexSubImage2D( GLcontext *ctx, struct gl_texture_image *texImage ) { driTextureObject *t = (driTextureObject *)texObj->DriverData; - + assert(t); if (t) { I810_FIREVERTICES( I810_CONTEXT(ctx) ); driSwapOutTextureObject( t ); @@ -404,22 +408,26 @@ static void i810TexSubImage2D( GLcontext *ctx, _mesa_store_texsubimage2d(ctx, target, level, xoffset, yoffset, width, height, format, type, pixels, packing, texObj, texImage); - } +#if 0 +/* not needed anymore */ static void i810BindTexture( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj ) { - if (!tObj->DriverData) { + assert(t); + if (!tObj->DriverData) { i810AllocTexObj( ctx, tObj ); } } +#endif static void i810DeleteTexture( GLcontext *ctx, struct gl_texture_object *tObj ) { - driTextureObject * t = (driTextureObject *) tObj->DriverData; + driTextureObject * t = (driTextureObject *) tObj->DriverData; + assert(t); if (t) { i810ContextPtr imesa = I810_CONTEXT( ctx ); if (imesa) @@ -517,30 +525,37 @@ i810ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, return NULL; /* never get here */ } -void i810InitTextureFuncs( GLcontext *ctx ) +/** + * Allocate a new texture object. + * Called via ctx->Driver.NewTextureObject. + * Note: this function will be called during context creation to + * allocate the default texture objects. + */ +static struct gl_texture_object * +i810NewTextureObject( GLcontext *ctx, GLuint name, GLenum target ) { - i810ContextPtr imesa = I810_CONTEXT(ctx); - - ctx->Driver.TexEnv = i810TexEnv; - ctx->Driver.ChooseTextureFormat = i810ChooseTextureFormat; - ctx->Driver.TexImage1D = _mesa_store_teximage1d; - ctx->Driver.TexImage2D = i810TexImage2D; - ctx->Driver.TexImage3D = _mesa_store_teximage3d; - ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d; - ctx->Driver.TexSubImage2D = i810TexSubImage2D; - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; - ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; - ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; - ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; - ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; - ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; - ctx->Driver.BindTexture = i810BindTexture; - ctx->Driver.DeleteTexture = i810DeleteTexture; - ctx->Driver.TexParameter = i810TexParameter; - ctx->Driver.UpdateTexturePalette = 0; - ctx->Driver.IsTextureResident = driIsTextureResident; - ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; - - driInitTextureObjects( ctx, &imesa->swapped, DRI_TEXMGR_DO_TEXTURE_2D); + struct gl_texture_object *obj; + driTextureObject *t; + obj = _mesa_new_texture_object(ctx, name, target); + if (!obj) + return NULL; + t = (driTextureObject *) i810AllocTexObj( ctx, obj ); + if (!t) { + _mesa_delete_texture_object(ctx, obj); + return NULL; + } + return obj; +} +void i810InitTextureFuncs( struct dd_function_table *functions ) +{ + functions->ChooseTextureFormat = i810ChooseTextureFormat; + functions->TexImage2D = i810TexImage2D; + functions->TexSubImage2D = i810TexSubImage2D; + /*functions->BindTexture = i810BindTexture;*/ + functions->NewTextureObject = i810NewTextureObject; + functions->DeleteTexture = i810DeleteTexture; + functions->TexParameter = i810TexParameter; + functions->TexEnv = i810TexEnv; + functions->IsTextureResident = driIsTextureResident; } diff --git a/src/mesa/drivers/dri/i810/i810tex.h b/src/mesa/drivers/dri/i810/i810tex.h index f0b4b88128..c6ab4c8e6d 100644 --- a/src/mesa/drivers/dri/i810/i810tex.h +++ b/src/mesa/drivers/dri/i810/i810tex.h @@ -70,7 +70,7 @@ struct i810_texture_object_t { }; void i810UpdateTextureState( GLcontext *ctx ); -void i810InitTextureFuncs( GLcontext *ctx ); +void i810InitTextureFuncs( struct dd_function_table *functions ); void i810DestroyTexObj( i810ContextPtr imesa, i810TextureObjectPtr t ); int i810UploadTexImagesLocked( i810ContextPtr imesa, i810TextureObjectPtr t ); diff --git a/src/mesa/drivers/dri/i830/Makefile.solo b/src/mesa/drivers/dri/i830/Makefile.solo index cc8e795c38..091c4be95f 100644 --- a/src/mesa/drivers/dri/i830/Makefile.solo +++ b/src/mesa/drivers/dri/i830/Makefile.solo @@ -35,6 +35,7 @@ DRIVER_SOURCES = \ i830_texmem.c \ i830_texstate.c \ i830_tris.c \ + ../../common/driverfuncs.c \ ../common/mm.c \ ../common/utils.c \ ../common/texmem.c \ diff --git a/src/mesa/drivers/dri/i830/i830_context.c b/src/mesa/drivers/dri/i830/i830_context.c index eb4fb3f7a4..74a7d77a86 100644 --- a/src/mesa/drivers/dri/i830/i830_context.c +++ b/src/mesa/drivers/dri/i830/i830_context.c @@ -50,6 +50,8 @@ #include "tnl/t_pipeline.h" +#include "drivers/common/driverfuncs.h" + #include "i830_screen.h" #include "i830_dri.h" @@ -211,17 +213,27 @@ GLboolean i830CreateContext( const __GLcontextModes *mesaVis, i830ScreenPrivate *screen = (i830ScreenPrivate *)sPriv->private; I830SAREAPtr saPriv=(I830SAREAPtr) (((GLubyte *)sPriv->pSAREA)+screen->sarea_priv_offset); + struct dd_function_table functions; /* Allocate i830 context */ imesa = (i830ContextPtr) CALLOC_STRUCT(i830_context_t); - if (!imesa) return GL_FALSE; + if (!imesa) + return GL_FALSE; + + /* Init default driver functions then plug in our I830-specific functions + * (the texture functions are especially important) + */ + _mesa_init_driver_functions(&functions); + i830InitIoctlFuncs(&functions); + i830InitTextureFuncs(&functions); /* Allocate the Mesa context */ if (sharedContextPrivate) shareCtx = ((i830ContextPtr) sharedContextPrivate)->glCtx; else shareCtx = NULL; - imesa->glCtx = _mesa_create_context(mesaVis, shareCtx, (void*) imesa, GL_TRUE); + imesa->glCtx = _mesa_create_context(mesaVis, shareCtx, + &functions, (void*) imesa); if (!imesa->glCtx) { FREE(imesa); return GL_FALSE; @@ -260,7 +272,7 @@ GLboolean i830CreateContext( const __GLcontextModes *mesaVis, ctx->Const.MaxTextureImageUnits = 2; ctx->Const.MaxTextureCoordUnits = 2; - /* FIXME: driCalcualteMaxTextureLevels assumes that mipmaps are tightly + /* FIXME: driCalculateMaxTextureLevels assumes that mipmaps are tightly * FIXME: packed, but they're not in Intel graphics hardware. */ driCalculateMaxTextureLevels( imesa->texture_heaps, @@ -352,13 +364,16 @@ GLboolean i830CreateContext( const __GLcontextModes *mesaVis, _math_matrix_ctr (&imesa->ViewportMatrix); driInitExtensions( ctx, card_extensions, GL_TRUE ); + /* XXX these should really go right after _mesa_init_driver_functions() */ i830DDInitStateFuncs( ctx ); - i830DDInitTextureFuncs( ctx ); i830InitTriFuncs (ctx); i830DDInitSpanFuncs( ctx ); - i830DDInitIoctlFuncs( ctx ); i830DDInitState (ctx); + driInitTextureObjects( ctx, & imesa->swapped, + DRI_TEXMGR_DO_TEXTURE_2D + | DRI_TEXMGR_DO_TEXTURE_RECT ); + #if DO_DEBUG I830_DEBUG = driParseDebugString( getenv( "I830_DEBUG" ), debug_control ); @@ -372,7 +387,6 @@ GLboolean i830CreateContext( const __GLcontextModes *mesaVis, FALLBACK(imesa, I830_FALLBACK_USER, 1); } - return GL_TRUE; } diff --git a/src/mesa/drivers/dri/i830/i830_ioctl.c b/src/mesa/drivers/dri/i830/i830_ioctl.c index 607b813e53..a0f062505b 100644 --- a/src/mesa/drivers/dri/i830/i830_ioctl.c +++ b/src/mesa/drivers/dri/i830/i830_ioctl.c @@ -820,22 +820,22 @@ int i830_check_copy(int fd) return drmCommandNone(fd, DRM_I830_DOCOPY); } -static void i830DDFlush( GLcontext *ctx ) +static void i830Flush( GLcontext *ctx ) { i830ContextPtr imesa = I830_CONTEXT( ctx ); I830_FIREVERTICES( imesa ); } -static void i830DDFinish( GLcontext *ctx ) +static void i830Finish( GLcontext *ctx ) { i830ContextPtr imesa = I830_CONTEXT( ctx ); i830DmaFinish( imesa ); } -void i830DDInitIoctlFuncs( GLcontext *ctx ) +void i830InitIoctlFuncs( struct dd_function_table *functions ) { - ctx->Driver.Flush = i830DDFlush; - ctx->Driver.Clear = i830Clear; - ctx->Driver.Finish = i830DDFinish; + functions->Flush = i830Flush; + functions->Clear = i830Clear; + functions->Finish = i830Finish; } diff --git a/src/mesa/drivers/dri/i830/i830_ioctl.h b/src/mesa/drivers/dri/i830/i830_ioctl.h index 4c64b8d7ab..f92ff44eab 100644 --- a/src/mesa/drivers/dri/i830/i830_ioctl.h +++ b/src/mesa/drivers/dri/i830/i830_ioctl.h @@ -53,7 +53,7 @@ void i830WaitAgeLocked( i830ContextPtr imesa, int age ); void i830WaitAge( i830ContextPtr imesa, int age ); void i830DmaFinish( i830ContextPtr imesa ); void i830RegetLockQuiescent( i830ContextPtr imesa ); -void i830DDInitIoctlFuncs( GLcontext *ctx ); +void i830InitIoctlFuncs( struct dd_function_table *functions ); void i830CopyBuffer( const __DRIdrawablePrivate *dpriv ); void i830PageFlip( const __DRIdrawablePrivate *dpriv ); int i830_check_copy(int fd); diff --git a/src/mesa/drivers/dri/i830/i830_tex.c b/src/mesa/drivers/dri/i830/i830_tex.c index 937f2cf393..6524cef41a 100644 --- a/src/mesa/drivers/dri/i830/i830_tex.c +++ b/src/mesa/drivers/dri/i830/i830_tex.c @@ -276,8 +276,8 @@ static void i830TexParameter( GLcontext *ctx, GLenum target, i830ContextPtr imesa = I830_CONTEXT(ctx); i830TextureObjectPtr t = (i830TextureObjectPtr) tObj->DriverData; GLuint unit = ctx->Texture.CurrentUnit; - if (!t) - return; + + assert(t); if ( target != GL_TEXTURE_2D ) return; @@ -376,6 +376,7 @@ static void i830TexImage2D( GLcontext *ctx, GLenum target, GLint level, struct gl_texture_image *texImage ) { driTextureObject * t = (driTextureObject *) texObj->DriverData; + assert(t); if (t) { I830_FIREVERTICES( I830_CONTEXT(ctx) ); driSwapOutTextureObject( t ); @@ -405,6 +406,7 @@ static void i830TexSubImage2D( GLcontext *ctx, struct gl_texture_image *texImage ) { driTextureObject * t = (driTextureObject *) texObj->DriverData; + assert(t); if (t) { I830_FIREVERTICES( I830_CONTEXT(ctx) ); driSwapOutTextureObject( t ); @@ -416,6 +418,8 @@ static void i830TexSubImage2D( GLcontext *ctx, } +#if 0 +/* no longer needed */ static void i830BindTexture( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj ) { @@ -423,12 +427,13 @@ static void i830BindTexture( GLcontext *ctx, GLenum target, i830AllocTexObj( tObj ); } } +#endif static void i830DeleteTexture( GLcontext *ctx, struct gl_texture_object *tObj ) { driTextureObject * t = (driTextureObject *) tObj->DriverData; - + assert(t); if ( t != NULL ) { i830ContextPtr imesa = I830_CONTEXT( ctx ); @@ -551,31 +556,37 @@ i830ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, return NULL; /* never get here */ } -void i830DDInitTextureFuncs( GLcontext *ctx ) +/** + * Allocate a new texture object. + * Called via ctx->Driver.NewTextureObject. + * Note: this function will be called during context creation to + * allocate the default texture objects. + */ +static struct gl_texture_object * +i830NewTextureObject( GLcontext *ctx, GLuint name, GLenum target ) { - i830ContextPtr imesa = I830_CONTEXT(ctx); + struct gl_texture_object *obj; + driTextureObject *t; + obj = _mesa_new_texture_object(ctx, name, target); + if (!obj) + return NULL; + t = (driTextureObject *) i830AllocTexObj( obj ); + if (!t) { + _mesa_delete_texture_object(ctx, obj); + return NULL; + } + return obj; +} - ctx->Driver.TexEnv = i830TexEnv; - ctx->Driver.ChooseTextureFormat = i830ChooseTextureFormat; - ctx->Driver.TexImage1D = _mesa_store_teximage1d; - ctx->Driver.TexImage2D = i830TexImage2D; - ctx->Driver.TexImage3D = _mesa_store_teximage3d; - ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d; - ctx->Driver.TexSubImage2D = i830TexSubImage2D; - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; - ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; - ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; - ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; - ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; - ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; - ctx->Driver.BindTexture = i830BindTexture; - ctx->Driver.DeleteTexture = i830DeleteTexture; - ctx->Driver.TexParameter = i830TexParameter; - ctx->Driver.UpdateTexturePalette = NULL; - ctx->Driver.IsTextureResident = driIsTextureResident; - ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; - - driInitTextureObjects( ctx, & imesa->swapped, - DRI_TEXMGR_DO_TEXTURE_2D - | DRI_TEXMGR_DO_TEXTURE_RECT ); +void i830InitTextureFuncs( struct dd_function_table *functions ) +{ + functions->NewTextureObject = i830NewTextureObject; + functions->DeleteTexture = i830DeleteTexture; + functions->ChooseTextureFormat = i830ChooseTextureFormat; + functions->TexImage2D = i830TexImage2D; + functions->TexSubImage2D = i830TexSubImage2D; + /*functions->BindTexture = i830BindTexture;*/ + functions->TexParameter = i830TexParameter; + functions->TexEnv = i830TexEnv; + functions->IsTextureResident = driIsTextureResident; } diff --git a/src/mesa/drivers/dri/i830/i830_tex.h b/src/mesa/drivers/dri/i830/i830_tex.h index 91203269e3..68c18b105d 100644 --- a/src/mesa/drivers/dri/i830/i830_tex.h +++ b/src/mesa/drivers/dri/i830/i830_tex.h @@ -62,7 +62,7 @@ struct i830_texture_object_t }; void i830UpdateTextureState( GLcontext *ctx ); -void i830DDInitTextureFuncs( GLcontext *ctx ); +void i830InitTextureFuncs( struct dd_function_table *functions ); void i830DestroyTexObj( i830ContextPtr imesa, i830TextureObjectPtr t ); int i830UploadTexImagesLocked( i830ContextPtr imesa, i830TextureObjectPtr t ); diff --git a/src/mesa/drivers/dri/mga/Makefile.solo b/src/mesa/drivers/dri/mga/Makefile.solo index 326e64a8fe..6d078e6868 100644 --- a/src/mesa/drivers/dri/mga/Makefile.solo +++ b/src/mesa/drivers/dri/mga/Makefile.solo @@ -27,6 +27,7 @@ DRIVER_SOURCES = mgadd.c \ mgarender.c \ mgastate.c \ mgatris.c \ + ../../common/driverfuncs.c \ ../common/mm.c \ ../common/utils.c \ ../common/texmem.c \ diff --git a/src/mesa/drivers/dri/mga/mga_xmesa.c b/src/mesa/drivers/dri/mga/mga_xmesa.c index fa8057e732..6c26489d3c 100644 --- a/src/mesa/drivers/dri/mga/mga_xmesa.c +++ b/src/mesa/drivers/dri/mga/mga_xmesa.c @@ -40,6 +40,8 @@ #include "tnl/t_pipeline.h" +#include "drivers/common/driverfuncs.h" + #include "mgadd.h" #include "mgastate.h" #include "mgatex.h" @@ -352,6 +354,7 @@ mgaCreateContext( const __GLcontextModes *mesaVis, mgaScreenPrivate *mgaScreen = (mgaScreenPrivate *)sPriv->private; MGASAREAPrivPtr saPriv=(MGASAREAPrivPtr)(((char*)sPriv->pSAREA)+ mgaScreen->sarea_priv_offset); + struct dd_function_table functions; if (MGA_DEBUG&DEBUG_VERBOSE_DRI) fprintf(stderr, "mgaCreateContext\n"); @@ -362,12 +365,21 @@ mgaCreateContext( const __GLcontextModes *mesaVis, return GL_FALSE; } + /* Init default driver functions then plug in our Radeon-specific functions + * (the texture functions are especially important) + */ + _mesa_init_driver_functions( &functions ); + mgaInitDriverFuncs( &functions ); + mgaInitTextureFuncs( &functions ); + mgaInitIoctlFuncs( &functions ); + /* Allocate the Mesa context */ if (sharedContextPrivate) shareCtx = ((mgaContextPtr) sharedContextPrivate)->glCtx; else shareCtx = NULL; - mmesa->glCtx = _mesa_create_context(mesaVis, shareCtx, (void *) mmesa, GL_TRUE); + mmesa->glCtx = _mesa_create_context(mesaVis, shareCtx, + &functions, (void *) mmesa); if (!mmesa->glCtx) { FREE(mmesa); return GL_FALSE; @@ -509,14 +521,16 @@ mgaCreateContext( const __GLcontextModes *mesaVis, driInitExtensions( ctx, g400_extensions, GL_FALSE ); } + /* XXX these should really go right after _mesa_init_driver_functions() */ mgaDDInitStateFuncs( ctx ); - mgaDDInitTextureFuncs( ctx ); mgaDDInitSpanFuncs( ctx ); - mgaDDInitDriverFuncs( ctx ); - mgaDDInitIoctlFuncs( ctx ); mgaDDInitPixelFuncs( ctx ); mgaDDInitTriFuncs( ctx ); + driInitTextureObjects( ctx, & mmesa->swapped, + (DRI_TEXMGR_DO_TEXTURE_2D | + DRI_TEXMGR_DO_TEXTURE_RECT) ); + mgaInitVB( ctx ); mgaInitState( mmesa ); diff --git a/src/mesa/drivers/dri/mga/mgadd.c b/src/mesa/drivers/dri/mga/mgadd.c index d2f11d8d45..e8436f2384 100644 --- a/src/mesa/drivers/dri/mga/mgadd.c +++ b/src/mesa/drivers/dri/mga/mgadd.c @@ -48,7 +48,7 @@ ***************************************/ -static const GLubyte *mgaDDGetString( GLcontext *ctx, GLenum name ) +static const GLubyte *mgaGetString( GLcontext *ctx, GLenum name ) { mgaContextPtr mmesa = MGA_CONTEXT( ctx ); static char buffer[128]; @@ -73,7 +73,6 @@ static const GLubyte *mgaDDGetString( GLcontext *ctx, GLenum name ) } - static void mgaBufferSize(GLframebuffer *buffer, GLuint *width, GLuint *height) { GET_CURRENT_CONTEXT(ctx); @@ -89,9 +88,10 @@ static void mgaBufferSize(GLframebuffer *buffer, GLuint *width, GLuint *height) UNLOCK_HARDWARE( mmesa ); } -void mgaDDInitDriverFuncs( GLcontext *ctx ) + +void mgaInitDriverFuncs( struct dd_function_table *functions ) { - ctx->Driver.GetBufferSize = mgaBufferSize; - ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; - ctx->Driver.GetString = mgaDDGetString; + functions->GetBufferSize = mgaBufferSize; + functions->ResizeBuffers = _swrast_alloc_buffers; + functions->GetString = mgaGetString; } diff --git a/src/mesa/drivers/dri/mga/mgadd.h b/src/mesa/drivers/dri/mga/mgadd.h index 919fd742d6..f98bfdc878 100644 --- a/src/mesa/drivers/dri/mga/mgadd.h +++ b/src/mesa/drivers/dri/mga/mgadd.h @@ -31,6 +31,6 @@ #include "context.h" -void mgaDDInitDriverFuncs( GLcontext *ctx ); +extern void mgaInitDriverFuncs( struct dd_function_table *functions ); #endif diff --git a/src/mesa/drivers/dri/mga/mgaioctl.c b/src/mesa/drivers/dri/mga/mgaioctl.c index 08e9705a17..3704734474 100644 --- a/src/mesa/drivers/dri/mga/mgaioctl.c +++ b/src/mesa/drivers/dri/mga/mgaioctl.c @@ -157,7 +157,7 @@ drmBufPtr mga_get_buffer_ioctl( mgaContextPtr mmesa ) static void -mgaDDClear( GLcontext *ctx, GLbitfield mask, GLboolean all, +mgaClear( GLcontext *ctx, GLbitfield mask, GLboolean all, GLint cx, GLint cy, GLint cw, GLint ch ) { mgaContextPtr mmesa = MGA_CONTEXT(ctx); @@ -390,7 +390,7 @@ void mgaCopyBuffer( const __DRIdrawablePrivate *dPriv ) /* This is overkill */ -void mgaDDFinish( GLcontext *ctx ) +void mgaFinish( GLcontext *ctx ) { mgaContextPtr mmesa = MGA_CONTEXT(ctx); @@ -600,7 +600,7 @@ drmBufPtr mgaGetBufferLocked( mgaContextPtr mmesa ) -void mgaDDFlush( GLcontext *ctx ) +void mgaFlush( GLcontext *ctx ) { mgaContextPtr mmesa = MGA_CONTEXT( ctx ); @@ -670,9 +670,9 @@ int mgaFlushDMA( int fd, drmLockFlags flags ) } } -void mgaDDInitIoctlFuncs( GLcontext *ctx ) +void mgaInitIoctlFuncs( struct dd_function_table *functions ) { - ctx->Driver.Clear = mgaDDClear; - ctx->Driver.Flush = mgaDDFlush; - ctx->Driver.Finish = mgaDDFinish; + functions->Clear = mgaClear; + functions->Flush = mgaFlush; + functions->Finish = mgaFinish; } diff --git a/src/mesa/drivers/dri/mga/mgaioctl.h b/src/mesa/drivers/dri/mga/mgaioctl.h index 9e57d48cea..19785ea593 100644 --- a/src/mesa/drivers/dri/mga/mgaioctl.h +++ b/src/mesa/drivers/dri/mga/mgaioctl.h @@ -57,7 +57,7 @@ int mgaFlushDMA( int fd, drmLockFlags flags ); void mgaDDFlush( GLcontext *ctx ); void mgaDDFinish( GLcontext *ctx ); -void mgaDDInitIoctlFuncs( GLcontext *ctx ); +void mgaInitIoctlFuncs( struct dd_function_table *functions ); #define FLUSH_BATCH(mmesa) do { \ if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) \ diff --git a/src/mesa/drivers/dri/mga/mgatex.c b/src/mesa/drivers/dri/mga/mgatex.c index 8b8d472c52..b64335f303 100644 --- a/src/mesa/drivers/dri/mga/mgatex.c +++ b/src/mesa/drivers/dri/mga/mgatex.c @@ -43,6 +43,7 @@ #include "texformat.h" #include "texstore.h" #include "teximage.h" +#include "texobj.h" #include "swrast/swrast.h" @@ -336,7 +337,7 @@ mgaAllocTexObj( struct gl_texture_object *tObj ) } -static void mgaDDTexEnv( GLcontext *ctx, GLenum target, +static void mgaTexEnv( GLcontext *ctx, GLenum target, GLenum pname, const GLfloat *param ) { GLuint unit = ctx->Texture.CurrentUnit; @@ -365,7 +366,7 @@ static void mgaTexImage2D( GLcontext *ctx, GLenum target, GLint level, { driTextureObject * t = (driTextureObject *) texObj->DriverData; - + assert(t); if ( t != NULL ) { driSwapOutTextureObject( t ); } @@ -398,8 +399,7 @@ static void mgaTexSubImage2D( GLcontext *ctx, { driTextureObject * t = (driTextureObject *) texObj->DriverData; - - assert( t != NULL ); /* this _should_ be true */ + assert( t ); /* this _should_ be true */ if ( t != NULL ) { driSwapOutTextureObject( t ); } @@ -426,20 +426,18 @@ static void mgaTexSubImage2D( GLcontext *ctx, */ static void -mgaDDTexParameter( GLcontext *ctx, GLenum target, +mgaTexParameter( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj, GLenum pname, const GLfloat *params ) { - mgaContextPtr mmesa = MGA_CONTEXT( ctx ); - mgaTextureObjectPtr t; - - t = (mgaTextureObjectPtr) tObj->DriverData; + mgaContextPtr mmesa = MGA_CONTEXT( ctx ); + mgaTextureObjectPtr t = (mgaTextureObjectPtr) tObj->DriverData; /* If we don't have a hardware texture, it will be automatically * created with current state before it is used, so we don't have * to do anything now */ - + assert(t); if ( (t == NULL) || (target != GL_TEXTURE_2D && target != GL_TEXTURE_RECTANGLE_NV) ) { @@ -484,8 +482,10 @@ mgaDDTexParameter( GLcontext *ctx, GLenum target, } +#if 0 +/* no longer needed */ static void -mgaDDBindTexture( GLcontext *ctx, GLenum target, +mgaBindTexture( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj ) { if ( target == GL_TEXTURE_2D || @@ -495,14 +495,16 @@ mgaDDBindTexture( GLcontext *ctx, GLenum target, } } } +#endif static void -mgaDDDeleteTexture( GLcontext *ctx, struct gl_texture_object *tObj ) +mgaDeleteTexture( GLcontext *ctx, struct gl_texture_object *tObj ) { mgaContextPtr mmesa = MGA_CONTEXT( ctx ); driTextureObject * t = (driTextureObject *) tObj->DriverData; + assert(t); if ( t ) { if ( mmesa ) { FLUSH_BATCH( mmesa ); @@ -513,38 +515,41 @@ mgaDDDeleteTexture( GLcontext *ctx, struct gl_texture_object *tObj ) } -void -mgaDDInitTextureFuncs( GLcontext *ctx ) +/** + * Allocate a new texture object. + * Called via ctx->Driver.NewTextureObject. + * Note: this function will be called during context creation to + * allocate the default texture objects. + * Fixup MaxAnisotropy according to user preference. + */ +static struct gl_texture_object * +mgaNewTextureObject( GLcontext *ctx, GLuint name, GLenum target ) { - mgaContextPtr mmesa = MGA_CONTEXT(ctx); + mgaContextPtr rmesa = MGA_CONTEXT(ctx); + struct gl_texture_object *obj; + driTextureObject *t; + obj = _mesa_new_texture_object(ctx, name, target); + if (!obj) + return NULL; + t = (driTextureObject *) mgaAllocTexObj( obj ); + if (!t) { + _mesa_delete_texture_object(ctx, obj); + return NULL; + } + return obj; +} - ctx->Driver.ChooseTextureFormat = mgaChooseTextureFormat; - ctx->Driver.TexImage1D = _mesa_store_teximage1d; - ctx->Driver.TexImage2D = mgaTexImage2D; - ctx->Driver.TexImage3D = _mesa_store_teximage3d; - ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d; - ctx->Driver.TexSubImage2D = mgaTexSubImage2D; - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; - ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; - ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; - ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; - ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; - ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; - ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; - - ctx->Driver.BindTexture = mgaDDBindTexture; - ctx->Driver.CreateTexture = NULL; /* FIXME: Is this used??? */ - ctx->Driver.DeleteTexture = mgaDDDeleteTexture; - ctx->Driver.IsTextureResident = driIsTextureResident; - ctx->Driver.PrioritizeTexture = NULL; - ctx->Driver.ActiveTexture = NULL; - ctx->Driver.UpdateTexturePalette = NULL; - - ctx->Driver.TexEnv = mgaDDTexEnv; - ctx->Driver.TexParameter = mgaDDTexParameter; - - driInitTextureObjects( ctx, & mmesa->swapped, - (DRI_TEXMGR_DO_TEXTURE_2D | - DRI_TEXMGR_DO_TEXTURE_RECT) ); +void +mgaInitTextureFuncs( struct dd_function_table *functions ) +{ + functions->ChooseTextureFormat = mgaChooseTextureFormat; + functions->TexImage2D = mgaTexImage2D; + functions->TexSubImage2D = mgaTexSubImage2D; + /*ctx->Driver.BindTexture = mgaBindTexture;*/ + functions->NewTextureObject = mgaNewTextureObject; + functions->DeleteTexture = mgaDeleteTexture; + functions->IsTextureResident = driIsTextureResident; + functions->TexEnv = mgaTexEnv; + functions->TexParameter = mgaTexParameter; } diff --git a/src/mesa/drivers/dri/mga/mgatex.h b/src/mesa/drivers/dri/mga/mgatex.h index 94547e3886..fb7ffcff16 100644 --- a/src/mesa/drivers/dri/mga/mgatex.h +++ b/src/mesa/drivers/dri/mga/mgatex.h @@ -44,7 +44,7 @@ int mgaUploadTexImages( mgaContextPtr mmesa, mgaTextureObjectPtr t ); void mgaDestroyTexObj( mgaContextPtr mmesa, mgaTextureObjectPtr t ); -void mgaDDInitTextureFuncs( GLcontext *ctx ); +void mgaInitTextureFuncs( struct dd_function_table *functions ); GLboolean mgaUpdateTextureEnvCombine( GLcontext *ctx, int unit ); diff --git a/src/mesa/drivers/dri/r128/Makefile.solo b/src/mesa/drivers/dri/r128/Makefile.solo index 39b14c9026..cb40c7692e 100644 --- a/src/mesa/drivers/dri/r128/Makefile.solo +++ b/src/mesa/drivers/dri/r128/Makefile.solo @@ -35,6 +35,7 @@ DRIVER_SOURCES = \ r128_span.c \ r128_texmem.c \ r128_vb.c \ + ../../common/driverfuncs.c \ ../common/mm.c \ ../common/utils.c \ ../common/texmem.c \ diff --git a/src/mesa/drivers/dri/r128/r128_context.c b/src/mesa/drivers/dri/r128/r128_context.c index d1417c853b..7bb324473f 100644 --- a/src/mesa/drivers/dri/r128/r128_context.c +++ b/src/mesa/drivers/dri/r128/r128_context.c @@ -47,6 +47,8 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #include "tnl/tnl.h" #include "tnl/t_pipeline.h" +#include "drivers/common/driverfuncs.h" + #include "r128_context.h" #include "r128_ioctl.h" #include "r128_dd.h" @@ -97,6 +99,7 @@ GLboolean r128CreateContext( const __GLcontextModes *glVisual, { GLcontext *ctx, *shareCtx; __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv; + struct dd_function_table functions; r128ContextPtr rmesa; r128ScreenPtr r128scrn; int i; @@ -106,12 +109,21 @@ GLboolean r128CreateContext( const __GLcontextModes *glVisual, if ( !rmesa ) return GL_FALSE; + /* Init default driver functions then plug in our Radeon-specific functions + * (the texture functions are especially important) + */ + _mesa_init_driver_functions( &functions ); + r128InitDriverFuncs( &functions ); + r128InitIoctlFuncs( &functions ); + r128InitTextureFuncs( &functions ); + /* Allocate the Mesa context */ if (sharedContextPrivate) shareCtx = ((r128ContextPtr) sharedContextPrivate)->glCtx; else shareCtx = NULL; - rmesa->glCtx = _mesa_create_context(glVisual, shareCtx, (void *) rmesa, GL_TRUE); + rmesa->glCtx = _mesa_create_context(glVisual, shareCtx, + &functions, (void *) rmesa); if (!rmesa->glCtx) { FREE(rmesa); return GL_FALSE; @@ -229,13 +241,14 @@ GLboolean r128CreateContext( const __GLcontextModes *glVisual, r128InitVB( ctx ); r128InitTriFuncs( ctx ); - r128DDInitDriverFuncs( ctx ); - r128DDInitIoctlFuncs( ctx ); r128DDInitStateFuncs( ctx ); r128DDInitSpanFuncs( ctx ); - r128DDInitTextureFuncs( ctx ); r128DDInitState( rmesa ); + driInitTextureObjects( ctx, & rmesa->swapped, + DRI_TEXMGR_DO_TEXTURE_1D + | DRI_TEXMGR_DO_TEXTURE_2D ); + rmesa->vblank_flags = (rmesa->r128Screen->irq != 0) ? driGetDefaultVBlankFlags(&rmesa->optionCache) : VBLANK_FLAG_NO_IRQ; diff --git a/src/mesa/drivers/dri/r128/r128_dd.c b/src/mesa/drivers/dri/r128/r128_dd.c index b64c26b4bd..ce2e7f7d70 100644 --- a/src/mesa/drivers/dri/r128/r128_dd.c +++ b/src/mesa/drivers/dri/r128/r128_dd.c @@ -48,7 +48,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. /* Return the width and height of the current color buffer. */ -static void r128DDGetBufferSize( GLframebuffer *buffer, +static void r128GetBufferSize( GLframebuffer *buffer, GLuint *width, GLuint *height ) { GET_CURRENT_CONTEXT(ctx); @@ -62,7 +62,7 @@ static void r128DDGetBufferSize( GLframebuffer *buffer, /* Return various strings for glGetString(). */ -static const GLubyte *r128DDGetString( GLcontext *ctx, GLenum name ) +static const GLubyte *r128GetString( GLcontext *ctx, GLenum name ) { r128ContextPtr rmesa = R128_CONTEXT(ctx); static char buffer[128]; @@ -100,7 +100,7 @@ static const GLubyte *r128DDGetString( GLcontext *ctx, GLenum name ) * hardware. All commands that are normally sent to the ring are * already considered `flushed'. */ -static void r128DDFlush( GLcontext *ctx ) +static void r128Flush( GLcontext *ctx ) { r128ContextPtr rmesa = R128_CONTEXT(ctx); @@ -121,7 +121,7 @@ static void r128DDFlush( GLcontext *ctx ) /* Make sure all commands have been sent to the hardware and have * completed processing. */ -static void r128DDFinish( GLcontext *ctx ) +static void r128Finish( GLcontext *ctx ) { r128ContextPtr rmesa = R128_CONTEXT(ctx); @@ -130,19 +130,18 @@ static void r128DDFinish( GLcontext *ctx ) rmesa->c_drawWaits++; #endif - r128DDFlush( ctx ); + r128Flush( ctx ); r128WaitForIdle( rmesa ); } /* Initialize the driver's misc functions. */ -void r128DDInitDriverFuncs( GLcontext *ctx ) +void r128InitDriverFuncs( struct dd_function_table *functions ) { - ctx->Driver.GetBufferSize = r128DDGetBufferSize; - ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; - ctx->Driver.GetString = r128DDGetString; - ctx->Driver.Finish = r128DDFinish; - ctx->Driver.Flush = r128DDFlush; - ctx->Driver.Error = NULL; + functions->GetBufferSize = r128GetBufferSize; + functions->ResizeBuffers = _swrast_alloc_buffers; + functions->GetString = r128GetString; + functions->Finish = r128Finish; + functions->Flush = r128Flush; } diff --git a/src/mesa/drivers/dri/r128/r128_dd.h b/src/mesa/drivers/dri/r128/r128_dd.h index b8fc7ad9bf..1c8a503050 100644 --- a/src/mesa/drivers/dri/r128/r128_dd.h +++ b/src/mesa/drivers/dri/r128/r128_dd.h @@ -38,7 +38,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #ifdef GLX_DIRECT_RENDERING -extern void r128DDInitDriverFuncs( GLcontext *ctx ); +extern void r128InitDriverFuncs( struct dd_function_table *functions ); #endif #endif diff --git a/src/mesa/drivers/dri/r128/r128_ioctl.c b/src/mesa/drivers/dri/r128/r128_ioctl.c index 7f9f7a923e..6b2785eebe 100644 --- a/src/mesa/drivers/dri/r128/r128_ioctl.c +++ b/src/mesa/drivers/dri/r128/r128_ioctl.c @@ -405,7 +405,7 @@ void r128PageFlip( const __DRIdrawablePrivate *dPriv ) * Buffer clear */ -static void r128DDClear( GLcontext *ctx, GLbitfield mask, GLboolean all, +static void r128Clear( GLcontext *ctx, GLbitfield mask, GLboolean all, GLint cx, GLint cy, GLint cw, GLint ch ) { r128ContextPtr rmesa = R128_CONTEXT(ctx); @@ -810,7 +810,7 @@ void r128WaitForIdleLocked( r128ContextPtr rmesa ) } } -void r128DDInitIoctlFuncs( GLcontext *ctx ) +void r128InitIoctlFuncs( struct dd_function_table *functions ) { - ctx->Driver.Clear = r128DDClear; + functions->Clear = r128Clear; } diff --git a/src/mesa/drivers/dri/r128/r128_ioctl.h b/src/mesa/drivers/dri/r128/r128_ioctl.h index b0f6b363a5..d10758feff 100644 --- a/src/mesa/drivers/dri/r128/r128_ioctl.h +++ b/src/mesa/drivers/dri/r128/r128_ioctl.h @@ -94,7 +94,7 @@ void r128WaitForVBlank( r128ContextPtr rmesa ); extern void r128WaitForIdleLocked( r128ContextPtr rmesa ); -extern void r128DDInitIoctlFuncs( GLcontext *ctx ); +extern void r128InitIoctlFuncs( struct dd_function_table *functions ); /* ================================================================ diff --git a/src/mesa/drivers/dri/r128/r128_tex.c b/src/mesa/drivers/dri/r128/r128_tex.c index b9874bd73f..20e18dafee 100644 --- a/src/mesa/drivers/dri/r128/r128_tex.c +++ b/src/mesa/drivers/dri/r128/r128_tex.c @@ -299,6 +299,7 @@ static void r128TexImage1D( GLcontext *ctx, GLenum target, GLint level, { driTextureObject * t = (driTextureObject *) texObj->DriverData; + assert(t); if ( t ) { driSwapOutTextureObject( t ); } @@ -362,6 +363,7 @@ static void r128TexImage2D( GLcontext *ctx, GLenum target, GLint level, { driTextureObject * t = (driTextureObject *) texObj->DriverData; + assert(t); if ( t ) { driSwapOutTextureObject( (driTextureObject *) t ); } @@ -414,7 +416,7 @@ static void r128TexSubImage2D( GLcontext *ctx, } -static void r128DDTexEnv( GLcontext *ctx, GLenum target, +static void r128TexEnv( GLcontext *ctx, GLenum target, GLenum pname, const GLfloat *param ) { r128ContextPtr rmesa = R128_CONTEXT(ctx); @@ -502,9 +504,9 @@ static void r128DDTexEnv( GLcontext *ctx, GLenum target, } -static void r128DDTexParameter( GLcontext *ctx, GLenum target, - struct gl_texture_object *tObj, - GLenum pname, const GLfloat *params ) +static void r128TexParameter( GLcontext *ctx, GLenum target, + struct gl_texture_object *tObj, + GLenum pname, const GLfloat *params ) { r128ContextPtr rmesa = R128_CONTEXT(ctx); r128TexObjPtr t = (r128TexObjPtr)tObj->DriverData; @@ -553,7 +555,9 @@ static void r128DDTexParameter( GLcontext *ctx, GLenum target, } } -static void r128DDBindTexture( GLcontext *ctx, GLenum target, +#if 00 +/* note needed */ +static void r128BindTexture( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj ) { if ( R128_DEBUG & DEBUG_VERBOSE_API ) { @@ -567,13 +571,15 @@ static void r128DDBindTexture( GLcontext *ctx, GLenum target, } } } +#endif -static void r128DDDeleteTexture( GLcontext *ctx, +static void r128DeleteTexture( GLcontext *ctx, struct gl_texture_object *tObj ) { r128ContextPtr rmesa = R128_CONTEXT(ctx); driTextureObject * t = (driTextureObject *) tObj->DriverData; + assert(t); if ( t ) { if ( t->bound && rmesa ) { FLUSH_BATCH( rmesa ); @@ -585,34 +591,39 @@ static void r128DDDeleteTexture( GLcontext *ctx, _mesa_delete_texture_object(ctx, tObj); } -void r128DDInitTextureFuncs( GLcontext *ctx ) +/** + * Allocate a new texture object. + * Called via ctx->Driver.NewTextureObject. + */ +static struct gl_texture_object * +r128NewTextureObject( GLcontext *ctx, GLuint name, GLenum target ) { r128ContextPtr rmesa = R128_CONTEXT(ctx); + struct gl_texture_object *obj; + driTextureObject *t; + obj = _mesa_new_texture_object(ctx, name, target); + if (!obj) + return NULL; + t = (driTextureObject *) r128AllocTexObj(obj); + if (!t) { + _mesa_delete_texture_object(ctx, obj); + return NULL; + } + return obj; +} - - ctx->Driver.TexEnv = r128DDTexEnv; - ctx->Driver.ChooseTextureFormat = r128ChooseTextureFormat; - ctx->Driver.TexImage1D = r128TexImage1D; - ctx->Driver.TexSubImage1D = r128TexSubImage1D; - ctx->Driver.TexImage2D = r128TexImage2D; - ctx->Driver.TexSubImage2D = r128TexSubImage2D; - ctx->Driver.TexImage3D = _mesa_store_teximage3d; - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; - ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; - ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; - ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; - ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; - ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; - ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; - ctx->Driver.TexParameter = r128DDTexParameter; - ctx->Driver.BindTexture = r128DDBindTexture; - ctx->Driver.DeleteTexture = r128DDDeleteTexture; - ctx->Driver.UpdateTexturePalette = NULL; - ctx->Driver.ActiveTexture = NULL; - ctx->Driver.IsTextureResident = driIsTextureResident; - ctx->Driver.PrioritizeTexture = NULL; - - driInitTextureObjects( ctx, & rmesa->swapped, - DRI_TEXMGR_DO_TEXTURE_1D - | DRI_TEXMGR_DO_TEXTURE_2D ); +void r128InitTextureFuncs( struct dd_function_table *functions ) +{ + functions->TexEnv = r128TexEnv; + functions->ChooseTextureFormat = r128ChooseTextureFormat; + functions->TexImage1D = r128TexImage1D; + functions->TexSubImage1D = r128TexSubImage1D; + functions->TexImage2D = r128TexImage2D; + functions->TexSubImage2D = r128TexSubImage2D; + functions->TexParameter = r128TexParameter; + /*functions->BindTexture = r128BindTexture;*/ + functions->NewTextureObject = r128NewTextureObject; + functions->DeleteTexture = r128DeleteTexture; + functions->IsTextureResident = driIsTextureResident; } + diff --git a/src/mesa/drivers/dri/r128/r128_tex.h b/src/mesa/drivers/dri/r128/r128_tex.h index 2e3d954fbb..00012c5104 100644 --- a/src/mesa/drivers/dri/r128/r128_tex.h +++ b/src/mesa/drivers/dri/r128/r128_tex.h @@ -44,7 +44,7 @@ extern void r128UploadTexImages( r128ContextPtr rmesa, r128TexObjPtr t ); extern void r128DestroyTexObj( r128ContextPtr rmesa, r128TexObjPtr t ); -extern void r128DDInitTextureFuncs( GLcontext *ctx ); +extern void r128InitTextureFuncs( struct dd_function_table *functions ); /* ================================================================ diff --git a/src/mesa/drivers/dri/r200/Makefile.solo b/src/mesa/drivers/dri/r200/Makefile.solo index e3fe696709..b0959b2b7f 100644 --- a/src/mesa/drivers/dri/r200/Makefile.solo +++ b/src/mesa/drivers/dri/r200/Makefile.solo @@ -28,6 +28,7 @@ DRIVER_SOURCES = r200_context.c \ r200_screen.c \ r200_state.c \ r200_state_init.c \ + ../../common/driverfuncs.c \ ../common/mm.c \ ../common/utils.c \ ../common/texmem.c \ diff --git a/src/mesa/drivers/dri/r200/r200_context.c b/src/mesa/drivers/dri/r200/r200_context.c index efa658717b..f8ab8d3697 100644 --- a/src/mesa/drivers/dri/r200/r200_context.c +++ b/src/mesa/drivers/dri/r200/r200_context.c @@ -49,6 +49,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "tnl/tnl.h" #include "tnl/t_pipeline.h" +#include "drivers/common/driverfuncs.h" + #include "r200_context.h" #include "r200_ioctl.h" #include "r200_state.h" @@ -186,15 +188,15 @@ static const struct tnl_pipeline_stage *r200_pipeline[] = { /* Initialize the driver's misc functions. */ -static void r200InitDriverFuncs( GLcontext *ctx ) +static void r200InitDriverFuncs( struct dd_function_table *functions ) { - ctx->Driver.GetBufferSize = r200GetBufferSize; - ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; - ctx->Driver.GetString = r200GetString; + functions->GetBufferSize = r200GetBufferSize; + functions->ResizeBuffers = _swrast_alloc_buffers; + functions->GetString = r200GetString; - ctx->Driver.Error = NULL; - ctx->Driver.DrawPixels = NULL; - ctx->Driver.Bitmap = NULL; + functions->Error = NULL; + functions->DrawPixels = NULL; + functions->Bitmap = NULL; } static const struct dri_debug_control debug_control[] = @@ -227,7 +229,7 @@ get_ust_nop( uint64_t * ust ) } -/* Create the device specific context. +/* Create the device specific rendering context. */ GLboolean r200CreateContext( const __GLcontextModes *glVisual, __DRIcontextPrivate *driContextPriv, @@ -235,6 +237,7 @@ GLboolean r200CreateContext( const __GLcontextModes *glVisual, { __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv; r200ScreenPtr screen = (r200ScreenPtr)(sPriv->private); + struct dd_function_table functions; r200ContextPtr rmesa; GLcontext *ctx, *shareCtx; int i; @@ -249,12 +252,31 @@ GLboolean r200CreateContext( const __GLcontextModes *glVisual, if ( !rmesa ) return GL_FALSE; - /* Allocate the Mesa context */ + /* Parse configuration files. + * Do this here so that initialMaxAnisotropy is set before we create + * the default textures. + */ + driParseConfigFiles (&rmesa->optionCache, &screen->optionCache, + screen->driScreen->myNum, "r200"); + rmesa->initialMaxAnisotropy = driQueryOptionf(&rmesa->optionCache, + "def_max_anisotropy"); + + /* Init default driver functions then plug in our R200-specific functions + * (the texture functions are especially important) + */ + _mesa_init_driver_functions(&functions); + r200InitDriverFuncs(&functions); + r200InitIoctlFuncs(&functions); + r200InitStateFuncs(&functions); + r200InitTextureFuncs(&functions); + + /* Allocate and initialize the Mesa context */ if (sharedContextPrivate) shareCtx = ((r200ContextPtr) sharedContextPrivate)->glCtx; else shareCtx = NULL; - rmesa->glCtx = _mesa_create_context(glVisual, shareCtx, (void *) rmesa, GL_TRUE); + rmesa->glCtx = _mesa_create_context(glVisual, shareCtx, + &functions, (void *) rmesa); if (!rmesa->glCtx) { FREE(rmesa); return GL_FALSE; @@ -270,10 +292,6 @@ GLboolean r200CreateContext( const __GLcontextModes *glVisual, rmesa->dri.fd = sPriv->fd; rmesa->dri.drmMinor = sPriv->drmMinor; - /* Parse configuration files */ - driParseConfigFiles (&rmesa->optionCache, &screen->optionCache, - screen->driScreen->myNum, "r200"); - rmesa->r200Screen = screen; rmesa->sarea = (RADEONSAREAPrivPtr)((GLubyte *)sPriv->pSAREA + screen->sarea_priv_offset); @@ -285,6 +303,7 @@ GLboolean r200CreateContext( const __GLcontextModes *glVisual, make_empty_list( & rmesa->swapped ); rmesa->nr_heaps = 1 /* screen->numTexHeaps */ ; + assert(rmesa->nr_heaps < R200_NR_TEX_HEAPS); for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) { rmesa->texture_heaps[i] = driCreateTextureHeap( i, rmesa, screen->texSize[i], @@ -381,15 +400,25 @@ GLboolean r200CreateContext( const __GLcontextModes *glVisual, if (rmesa->r200Screen->drmSupportsCubeMaps) _mesa_enable_extension( ctx, "GL_ARB_texture_cube_map" ); +#if 0 r200InitDriverFuncs( ctx ); r200InitIoctlFuncs( ctx ); r200InitStateFuncs( ctx ); - r200InitSpanFuncs( ctx ); - r200InitPixelFuncs( ctx ); r200InitTextureFuncs( ctx ); +#endif + /* plug in a few more device driver functions */ + /* XXX these should really go right after _mesa_init_driver_functions() */ + r200InitPixelFuncs( ctx ); + r200InitSpanFuncs( ctx ); + r200InitTnlFuncs( ctx ); r200InitState( rmesa ); r200InitSwtcl( ctx ); + /* used to be in r200InitTextureFuncs() */ + driInitTextureObjects( ctx, & rmesa->swapped, + DRI_TEXMGR_DO_TEXTURE_1D + | DRI_TEXMGR_DO_TEXTURE_2D ); + fthrottle_mode = driQueryOptioni(&rmesa->optionCache, "fthrottle_mode"); rmesa->iw.irq_seq = -1; rmesa->irqsEmitted = 0; diff --git a/src/mesa/drivers/dri/r200/r200_context.h b/src/mesa/drivers/dri/r200/r200_context.h index 066803f236..029dfde664 100644 --- a/src/mesa/drivers/dri/r200/r200_context.h +++ b/src/mesa/drivers/dri/r200/r200_context.h @@ -781,7 +781,7 @@ struct r200_context { driTexHeap * texture_heaps[ R200_NR_TEX_HEAPS ]; driTextureObject swapped; int texture_depth; - + float initialMaxAnisotropy; /* Rasterization and vertex state: */ diff --git a/src/mesa/drivers/dri/r200/r200_ioctl.c b/src/mesa/drivers/dri/r200/r200_ioctl.c index 2abaa5a428..2b5dd88cad 100644 --- a/src/mesa/drivers/dri/r200/r200_ioctl.c +++ b/src/mesa/drivers/dri/r200/r200_ioctl.c @@ -917,10 +917,10 @@ GLuint r200GartOffsetFromVirtual( r200ContextPtr rmesa, const GLvoid *pointer ) -void r200InitIoctlFuncs( GLcontext *ctx ) +void r200InitIoctlFuncs( struct dd_function_table *functions ) { - ctx->Driver.Clear = r200Clear; - ctx->Driver.Finish = r200Finish; - ctx->Driver.Flush = r200Flush; + functions->Clear = r200Clear; + functions->Finish = r200Finish; + functions->Flush = r200Flush; } diff --git a/src/mesa/drivers/dri/r200/r200_ioctl.h b/src/mesa/drivers/dri/r200/r200_ioctl.h index a76dbd2ad1..3c3ad3db54 100644 --- a/src/mesa/drivers/dri/r200/r200_ioctl.h +++ b/src/mesa/drivers/dri/r200/r200_ioctl.h @@ -103,7 +103,7 @@ extern void r200Flush( GLcontext *ctx ); extern void r200Finish( GLcontext *ctx ); extern void r200WaitForIdleLocked( r200ContextPtr rmesa ); extern void r200WaitForVBlank( r200ContextPtr rmesa ); -extern void r200InitIoctlFuncs( GLcontext *ctx ); +extern void r200InitIoctlFuncs( struct dd_function_table *functions ); extern void *r200AllocateMemoryMESA( GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority ); diff --git a/src/mesa/drivers/dri/r200/r200_state.c b/src/mesa/drivers/dri/r200/r200_state.c index 8b945a0147..f9501fd62b 100644 --- a/src/mesa/drivers/dri/r200/r200_state.c +++ b/src/mesa/drivers/dri/r200/r200_state.c @@ -2146,57 +2146,61 @@ static void r200WrapRunPipeline( GLcontext *ctx ) /* Initialize the driver's state functions. */ -void r200InitStateFuncs( GLcontext *ctx ) +void r200InitStateFuncs( struct dd_function_table *functions ) { - ctx->Driver.UpdateState = r200InvalidateState; - ctx->Driver.LightingSpaceChange = r200LightingSpaceChange; - - ctx->Driver.DrawBuffer = r200DrawBuffer; - ctx->Driver.ReadBuffer = r200ReadBuffer; - - ctx->Driver.AlphaFunc = r200AlphaFunc; - ctx->Driver.BlendEquation = r200BlendEquation; - ctx->Driver.BlendFunc = r200BlendFunc; - ctx->Driver.BlendFuncSeparate = r200BlendFuncSeparate; - ctx->Driver.ClearColor = r200ClearColor; - ctx->Driver.ClearDepth = NULL; - ctx->Driver.ClearIndex = NULL; - ctx->Driver.ClearStencil = r200ClearStencil; - ctx->Driver.ClipPlane = r200ClipPlane; - ctx->Driver.ColorMask = r200ColorMask; - ctx->Driver.CullFace = r200CullFace; - ctx->Driver.DepthFunc = r200DepthFunc; - ctx->Driver.DepthMask = r200DepthMask; - ctx->Driver.DepthRange = r200DepthRange; - ctx->Driver.Enable = r200Enable; - ctx->Driver.Fogfv = r200Fogfv; - ctx->Driver.FrontFace = r200FrontFace; - ctx->Driver.Hint = NULL; - ctx->Driver.IndexMask = NULL; - ctx->Driver.LightModelfv = r200LightModelfv; - ctx->Driver.Lightfv = r200Lightfv; - ctx->Driver.LineStipple = r200LineStipple; - ctx->Driver.LineWidth = r200LineWidth; - ctx->Driver.LogicOpcode = r200LogicOpCode; - ctx->Driver.PolygonMode = r200PolygonMode; - ctx->Driver.PolygonOffset = r200PolygonOffset; - ctx->Driver.PolygonStipple = r200PolygonStipple; - ctx->Driver.PointSize = r200PointSize; - ctx->Driver.RenderMode = r200RenderMode; - ctx->Driver.Scissor = r200Scissor; - ctx->Driver.ShadeModel = r200ShadeModel; - ctx->Driver.StencilFunc = r200StencilFunc; - ctx->Driver.StencilMask = r200StencilMask; - ctx->Driver.StencilOp = r200StencilOp; - ctx->Driver.Viewport = r200Viewport; + functions->UpdateState = r200InvalidateState; + functions->LightingSpaceChange = r200LightingSpaceChange; + + functions->DrawBuffer = r200DrawBuffer; + functions->ReadBuffer = r200ReadBuffer; + + functions->AlphaFunc = r200AlphaFunc; + functions->BlendEquation = r200BlendEquation; + functions->BlendFunc = r200BlendFunc; + functions->BlendFuncSeparate = r200BlendFuncSeparate; + functions->ClearColor = r200ClearColor; + functions->ClearDepth = NULL; + functions->ClearIndex = NULL; + functions->ClearStencil = r200ClearStencil; + functions->ClipPlane = r200ClipPlane; + functions->ColorMask = r200ColorMask; + functions->CullFace = r200CullFace; + functions->DepthFunc = r200DepthFunc; + functions->DepthMask = r200DepthMask; + functions->DepthRange = r200DepthRange; + functions->Enable = r200Enable; + functions->Fogfv = r200Fogfv; + functions->FrontFace = r200FrontFace; + functions->Hint = NULL; + functions->IndexMask = NULL; + functions->LightModelfv = r200LightModelfv; + functions->Lightfv = r200Lightfv; + functions->LineStipple = r200LineStipple; + functions->LineWidth = r200LineWidth; + functions->LogicOpcode = r200LogicOpCode; + functions->PolygonMode = r200PolygonMode; + functions->PolygonOffset = r200PolygonOffset; + functions->PolygonStipple = r200PolygonStipple; + functions->PointSize = r200PointSize; + functions->RenderMode = r200RenderMode; + functions->Scissor = r200Scissor; + functions->ShadeModel = r200ShadeModel; + functions->StencilFunc = r200StencilFunc; + functions->StencilMask = r200StencilMask; + functions->StencilOp = r200StencilOp; + functions->Viewport = r200Viewport; /* Swrast hooks for imaging extensions: */ - ctx->Driver.CopyColorTable = _swrast_CopyColorTable; - ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable; - ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D; - ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D; + functions->CopyColorTable = _swrast_CopyColorTable; + functions->CopyColorSubTable = _swrast_CopyColorSubTable; + functions->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D; + functions->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D; +} + +void r200InitTnlFuncs( GLcontext *ctx ) +{ TNL_CONTEXT(ctx)->Driver.NotifyMaterialChange = r200UpdateMaterial; TNL_CONTEXT(ctx)->Driver.RunPipeline = r200WrapRunPipeline; } diff --git a/src/mesa/drivers/dri/r200/r200_state.h b/src/mesa/drivers/dri/r200/r200_state.h index 118712d841..9d9de8e9a2 100644 --- a/src/mesa/drivers/dri/r200/r200_state.h +++ b/src/mesa/drivers/dri/r200/r200_state.h @@ -41,7 +41,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "r200_context.h" extern void r200InitState( r200ContextPtr rmesa ); -extern void r200InitStateFuncs( GLcontext *ctx ); +extern void r200InitStateFuncs( struct dd_function_table *functions ); +extern void r200InitTnlFuncs( GLcontext *ctx ); extern void r200UpdateMaterial( GLcontext *ctx ); diff --git a/src/mesa/drivers/dri/r200/r200_swtcl.c b/src/mesa/drivers/dri/r200/r200_swtcl.c index 231a3ed83f..a66879fe75 100644 --- a/src/mesa/drivers/dri/r200/r200_swtcl.c +++ b/src/mesa/drivers/dri/r200/r200_swtcl.c @@ -1226,7 +1226,7 @@ void r200InitSwtcl( GLcontext *ctx ) { TNLcontext *tnl = TNL_CONTEXT(ctx); r200ContextPtr rmesa = R200_CONTEXT(ctx); - GLuint size = TNL_CONTEXT(ctx)->vb.Size; + GLuint size = tnl->vb.Size; static int firsttime = 1; if (firsttime) { diff --git a/src/mesa/drivers/dri/r200/r200_tex.c b/src/mesa/drivers/dri/r200/r200_tex.c index 91f2fd8cce..1990d66191 100644 --- a/src/mesa/drivers/dri/r200/r200_tex.c +++ b/src/mesa/drivers/dri/r200/r200_tex.c @@ -554,6 +554,7 @@ static void r200TexImage1D( GLcontext *ctx, GLenum target, GLint level, { driTextureObject * t = (driTextureObject *) texObj->DriverData; + assert(t); if ( t ) { driSwapOutTextureObject( t ); } @@ -616,6 +617,8 @@ static void r200TexImage2D( GLcontext *ctx, GLenum target, GLint level, driTextureObject * t = (driTextureObject *) texObj->DriverData; GLuint face; + assert(t); + /* which cube face or ordinary 2D image */ switch (target) { case GL_TEXTURE_CUBE_MAP_POSITIVE_X: @@ -683,7 +686,6 @@ static void r200TexSubImage2D( GLcontext *ctx, GLenum target, GLint level, driTextureObject * t = (driTextureObject *) texObj->DriverData; GLuint face; - /* which cube face or ordinary 2D image */ switch (target) { case GL_TEXTURE_CUBE_MAP_POSITIVE_X: @@ -731,6 +733,8 @@ static void r200TexImage3D( GLcontext *ctx, GLenum target, GLint level, { driTextureObject * t = (driTextureObject *) texObj->DriverData; + assert(t); + if ( t ) { driSwapOutTextureObject( t ); } @@ -934,6 +938,8 @@ static void r200TexParameter( GLcontext *ctx, GLenum target, +#if 0 +/* not needed anymore */ static void r200BindTexture( GLcontext *ctx, GLenum target, struct gl_texture_object *texObj ) { @@ -948,6 +954,8 @@ static void r200BindTexture( GLcontext *ctx, GLenum target, } } } +#endif + static void r200DeleteTexture( GLcontext *ctx, struct gl_texture_object *texObj ) @@ -955,6 +963,8 @@ static void r200DeleteTexture( GLcontext *ctx, r200ContextPtr rmesa = R200_CONTEXT(ctx); driTextureObject * t = (driTextureObject *) texObj->DriverData; + assert(t); + if ( R200_DEBUG & (DEBUG_STATE|DEBUG_TEXTURE) ) { fprintf( stderr, "%s( %p (target = %s) )\n", __FUNCTION__, (void *)texObj, _mesa_lookup_enum_by_nr( texObj->Target ) ); @@ -991,59 +1001,65 @@ static void r200TexGen( GLcontext *ctx, rmesa->recheck_texgen[unit] = GL_TRUE; } -/* Fixup MaxAnisotropy according to user preference. - */ -static struct gl_texture_object *r200NewTextureObject ( GLcontext *ctx, - GLuint name, - GLenum target ) { - struct gl_texture_object *obj; - obj = _mesa_new_texture_object (ctx, name, target); - obj->MaxAnisotropy = driQueryOptionf (&R200_CONTEXT(ctx)->optionCache, - "def_max_anisotropy"); - return obj; -} - -void r200InitTextureFuncs( GLcontext *ctx ) +/** + * Allocate a new texture object. + * Called via ctx->Driver.NewTextureObject. + * Note: this function will be called during context creation to + * allocate the default texture objects. + * Fixup MaxAnisotropy according to user preference. + */ +static struct gl_texture_object * +r200NewTextureObject( GLcontext *ctx, GLuint name, GLenum target ) { r200ContextPtr rmesa = R200_CONTEXT(ctx); + struct gl_texture_object *obj; + driTextureObject *t; + obj = _mesa_new_texture_object(ctx, name, target); + if (!obj) + return NULL; + obj->MaxAnisotropy = rmesa->initialMaxAnisotropy; + t = (driTextureObject *) r200AllocTexObj( obj ); + if (!t) { + _mesa_delete_texture_object(ctx, obj); + return NULL; + } + return obj; +} - ctx->Driver.ChooseTextureFormat = r200ChooseTextureFormat; - ctx->Driver.TexImage1D = r200TexImage1D; - ctx->Driver.TexImage2D = r200TexImage2D; +void r200InitTextureFuncs( struct dd_function_table *functions ) +{ + /* Note: we only plug in the functions we implement in the driver + * since _mesa_init_driver_functions() was already called. + */ + functions->ChooseTextureFormat = r200ChooseTextureFormat; + functions->TexImage1D = r200TexImage1D; + functions->TexImage2D = r200TexImage2D; #if ENABLE_HW_3D_TEXTURE - ctx->Driver.TexImage3D = r200TexImage3D; + functions->TexImage3D = r200TexImage3D; #else - ctx->Driver.TexImage3D = _mesa_store_teximage3d; + functions->TexImage3D = _mesa_store_teximage3d; #endif - ctx->Driver.TexSubImage1D = r200TexSubImage1D; - ctx->Driver.TexSubImage2D = r200TexSubImage2D; + functions->TexSubImage1D = r200TexSubImage1D; + functions->TexSubImage2D = r200TexSubImage2D; #if ENABLE_HW_3D_TEXTURE - ctx->Driver.TexSubImage3D = r200TexSubImage3D; + functions->TexSubImage3D = r200TexSubImage3D; #else - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; + functions->TexSubImage3D = _mesa_store_texsubimage3d; #endif - ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; - ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; - ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; - ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; - ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; - ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; - - ctx->Driver.NewTextureObject = r200NewTextureObject; - ctx->Driver.BindTexture = r200BindTexture; - ctx->Driver.CreateTexture = NULL; /* FIXME: Is this used??? */ - ctx->Driver.DeleteTexture = r200DeleteTexture; - ctx->Driver.IsTextureResident = driIsTextureResident; - ctx->Driver.PrioritizeTexture = NULL; - ctx->Driver.ActiveTexture = NULL; - ctx->Driver.UpdateTexturePalette = NULL; - - ctx->Driver.TexEnv = r200TexEnv; - ctx->Driver.TexParameter = r200TexParameter; - ctx->Driver.TexGen = r200TexGen; + functions->NewTextureObject = r200NewTextureObject; + /*functions->BindTexture = r200BindTexture;*/ + functions->DeleteTexture = r200DeleteTexture; + functions->IsTextureResident = driIsTextureResident; + + functions->TexEnv = r200TexEnv; + functions->TexParameter = r200TexParameter; + functions->TexGen = r200TexGen; +#if 000 + /* moved or obsolete code */ + r200ContextPtr rmesa = R200_CONTEXT(ctx); driInitTextureObjects( ctx, & rmesa->swapped, DRI_TEXMGR_DO_TEXTURE_1D | DRI_TEXMGR_DO_TEXTURE_2D ); @@ -1053,4 +1069,5 @@ void r200InitTextureFuncs( GLcontext *ctx ) * default 2D texture now. */ ctx->Shared->Default2D->MaxAnisotropy = driQueryOptionf (&rmesa->optionCache, "def_max_anisotropy"); +#endif } diff --git a/src/mesa/drivers/dri/r200/r200_tex.h b/src/mesa/drivers/dri/r200/r200_tex.h index a4301206ed..7c507a7fd0 100644 --- a/src/mesa/drivers/dri/r200/r200_tex.h +++ b/src/mesa/drivers/dri/r200/r200_tex.h @@ -44,7 +44,7 @@ extern int r200UploadTexImages( r200ContextPtr rmesa, r200TexObjPtr t, GLuint fa extern void r200DestroyTexObj( r200ContextPtr rmesa, r200TexObjPtr t ); -extern void r200InitTextureFuncs( GLcontext *ctx ); +extern void r200InitTextureFuncs( struct dd_function_table *functions ); #endif #endif /* __R200_TEX_H__ */ diff --git a/src/mesa/drivers/dri/radeon/Makefile.solo b/src/mesa/drivers/dri/radeon/Makefile.solo index 508b476967..a5430b23b2 100644 --- a/src/mesa/drivers/dri/radeon/Makefile.solo +++ b/src/mesa/drivers/dri/radeon/Makefile.solo @@ -45,6 +45,7 @@ DRIVER_SOURCES = radeon_context.c \ radeon_screen.c \ radeon_state.c \ radeon_state_init.c \ + ../../common/driverfuncs.c \ ../common/mm.c \ ../common/utils.c \ ../common/texmem.c \ diff --git a/src/mesa/drivers/dri/radeon/radeon_context.c b/src/mesa/drivers/dri/radeon/radeon_context.c index 9fc012b2e7..492f80f597 100644 --- a/src/mesa/drivers/dri/radeon/radeon_context.c +++ b/src/mesa/drivers/dri/radeon/radeon_context.c @@ -50,6 +50,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "tnl/tnl.h" #include "tnl/t_pipeline.h" +#include "drivers/common/driverfuncs.h" + #include "radeon_context.h" #include "radeon_ioctl.h" #include "radeon_state.h" @@ -175,15 +177,11 @@ static const struct tnl_pipeline_stage *radeon_pipeline[] = { /* Initialize the driver's misc functions. */ -static void radeonInitDriverFuncs( GLcontext *ctx ) +static void radeonInitDriverFuncs( struct dd_function_table *functions ) { - ctx->Driver.GetBufferSize = radeonGetBufferSize; - ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; - ctx->Driver.GetString = radeonGetString; - - ctx->Driver.Error = NULL; - ctx->Driver.DrawPixels = NULL; - ctx->Driver.Bitmap = NULL; + functions->GetBufferSize = radeonGetBufferSize; + functions->ResizeBuffers = _swrast_alloc_buffers; + functions->GetString = radeonGetString; } static const struct dri_debug_control debug_control[] = @@ -222,6 +220,7 @@ radeonCreateContext( const __GLcontextModes *glVisual, { __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv; radeonScreenPtr screen = (radeonScreenPtr)(sPriv->private); + struct dd_function_table functions; radeonContextPtr rmesa; GLcontext *ctx, *shareCtx; int i; @@ -236,12 +235,29 @@ radeonCreateContext( const __GLcontextModes *glVisual, if ( !rmesa ) return GL_FALSE; + /* Parse configuration files. + * Do this here so that initialMaxAnisotropy is set before we create + * the default textures. + */ + driParseConfigFiles (&rmesa->optionCache, &screen->optionCache, + screen->driScreen->myNum, "r200"); + rmesa->initialMaxAnisotropy = driQueryOptionf(&rmesa->optionCache, + "def_max_anisotropy"); + + /* Init default driver functions then plug in our Radeon-specific functions + * (the texture functions are especially important) + */ + _mesa_init_driver_functions( &functions ); + radeonInitDriverFuncs( &functions ); + radeonInitTextureFuncs( &functions ); + /* Allocate the Mesa context */ if (sharedContextPrivate) shareCtx = ((radeonContextPtr) sharedContextPrivate)->glCtx; else shareCtx = NULL; - rmesa->glCtx = _mesa_create_context(glVisual, shareCtx, (void *) rmesa, GL_TRUE); + rmesa->glCtx = _mesa_create_context(glVisual, shareCtx, + &functions, (void *) rmesa); if (!rmesa->glCtx) { FREE(rmesa); return GL_FALSE; @@ -257,10 +273,6 @@ radeonCreateContext( const __GLcontextModes *glVisual, rmesa->dri.fd = sPriv->fd; rmesa->dri.drmMinor = sPriv->drmMinor; - /* Parse configuration files */ - driParseConfigFiles (&rmesa->optionCache, &screen->optionCache, - screen->driScreen->myNum, "radeon"); - rmesa->radeonScreen = screen; rmesa->sarea = (RADEONSAREAPrivPtr)((GLubyte *)sPriv->pSAREA + screen->sarea_priv_offset); @@ -342,6 +354,11 @@ radeonCreateContext( const __GLcontextModes *glVisual, rmesa->boxes = 0; + /* formerly in radeon_tex.c */ + driInitTextureObjects( ctx, & rmesa->swapped, + DRI_TEXMGR_DO_TEXTURE_1D + | DRI_TEXMGR_DO_TEXTURE_2D ); + /* Initialize the software rasterizer and helper modules. */ _swrast_CreateContext( ctx ); @@ -386,11 +403,10 @@ radeonCreateContext( const __GLcontextModes *glVisual, if (rmesa->dri.drmMinor >= 9) _mesa_enable_extension( ctx, "GL_NV_texture_rectangle"); - radeonInitDriverFuncs( ctx ); + /* XXX these should really go right after _mesa_init_driver_functions() */ radeonInitIoctlFuncs( ctx ); radeonInitStateFuncs( ctx ); radeonInitSpanFuncs( ctx ); - radeonInitTextureFuncs( ctx ); radeonInitState( rmesa ); radeonInitSwtcl( ctx ); diff --git a/src/mesa/drivers/dri/radeon/radeon_context.h b/src/mesa/drivers/dri/radeon/radeon_context.h index e5deadb41e..4860d404e2 100644 --- a/src/mesa/drivers/dri/radeon/radeon_context.h +++ b/src/mesa/drivers/dri/radeon/radeon_context.h @@ -700,7 +700,7 @@ struct radeon_context { driTexHeap * texture_heaps[ RADEON_NR_TEX_HEAPS ]; driTextureObject swapped; int texture_depth; - + float initialMaxAnisotropy; /* Rasterization and vertex state: */ diff --git a/src/mesa/drivers/dri/radeon/radeon_tex.c b/src/mesa/drivers/dri/radeon/radeon_tex.c index cea0ca2bfc..ca6acba16a 100644 --- a/src/mesa/drivers/dri/radeon/radeon_tex.c +++ b/src/mesa/drivers/dri/radeon/radeon_tex.c @@ -401,6 +401,7 @@ static void radeonTexImage1D( GLcontext *ctx, GLenum target, GLint level, { driTextureObject * t = (driTextureObject *) texObj->DriverData; + assert(t); if ( t ) { driSwapOutTextureObject( t ); } @@ -463,6 +464,8 @@ static void radeonTexImage2D( GLcontext *ctx, GLenum target, GLint level, driTextureObject * t = (driTextureObject *) texObj->DriverData; GLuint face; + assert(t); + /* which cube face or ordinary 2D image */ switch (target) { case GL_TEXTURE_CUBE_MAP_POSITIVE_X: @@ -510,7 +513,6 @@ static void radeonTexSubImage2D( GLcontext *ctx, GLenum target, GLint level, driTextureObject * t = (driTextureObject *) texObj->DriverData; GLuint face; - /* which cube face or ordinary 2D image */ switch (target) { case GL_TEXTURE_CUBE_MAP_POSITIVE_X: @@ -667,7 +669,8 @@ static void radeonTexParameter( GLcontext *ctx, GLenum target, } - +#if 00 +/* not needed anymore */ static void radeonBindTexture( GLcontext *ctx, GLenum target, struct gl_texture_object *texObj ) { @@ -682,6 +685,7 @@ static void radeonBindTexture( GLcontext *ctx, GLenum target, } } } +#endif static void radeonDeleteTexture( GLcontext *ctx, struct gl_texture_object *texObj ) @@ -694,6 +698,7 @@ static void radeonDeleteTexture( GLcontext *ctx, _mesa_lookup_enum_by_nr( texObj->Target ) ); } + assert(t); if ( t != NULL ) { if ( rmesa ) { RADEON_FIREVERTICES( rmesa ); @@ -726,58 +731,43 @@ static void radeonTexGen( GLcontext *ctx, rmesa->recheck_texgen[unit] = GL_TRUE; } -/* Fixup MaxAnisotropy according to user preference. +/** + * Allocate a new texture object. + * Called via ctx->Driver.NewTextureObject. */ -static struct gl_texture_object *radeonNewTextureObject ( GLcontext *ctx, - GLuint name, - GLenum target ) { - struct gl_texture_object *obj; - obj = _mesa_new_texture_object (ctx, name, target); - obj->MaxAnisotropy = driQueryOptionf (&RADEON_CONTEXT(ctx)->optionCache, - "def_max_anisotropy"); - return obj; -} - - -void radeonInitTextureFuncs( GLcontext *ctx ) +static struct gl_texture_object * +radeonNewTextureObject( GLcontext *ctx, GLuint name, GLenum target ) { radeonContextPtr rmesa = RADEON_CONTEXT(ctx); + struct gl_texture_object *obj; + driTextureObject *t; + obj = _mesa_new_texture_object(ctx, name, target); + if (!obj) + return NULL; + obj->MaxAnisotropy = rmesa->initialMaxAnisotropy; + t = (driTextureObject *) radeonAllocTexObj(obj); + if (!t) { + _mesa_delete_texture_object(ctx, obj); + return NULL; + } + return obj; +} - ctx->Driver.ChooseTextureFormat = radeonChooseTextureFormat; - ctx->Driver.TexImage1D = radeonTexImage1D; - ctx->Driver.TexImage2D = radeonTexImage2D; - ctx->Driver.TexImage3D = _mesa_store_teximage3d; - ctx->Driver.TexSubImage1D = radeonTexSubImage1D; - ctx->Driver.TexSubImage2D = radeonTexSubImage2D; - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; - ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; - ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; - ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; - ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; - ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; - ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; - - ctx->Driver.NewTextureObject = radeonNewTextureObject; - ctx->Driver.BindTexture = radeonBindTexture; - ctx->Driver.CreateTexture = NULL; /* FIXME: Is this used??? */ - ctx->Driver.DeleteTexture = radeonDeleteTexture; - ctx->Driver.IsTextureResident = driIsTextureResident; - ctx->Driver.PrioritizeTexture = NULL; - ctx->Driver.ActiveTexture = NULL; - ctx->Driver.UpdateTexturePalette = NULL; - - ctx->Driver.TexEnv = radeonTexEnv; - ctx->Driver.TexParameter = radeonTexParameter; - ctx->Driver.TexGen = radeonTexGen; - - driInitTextureObjects( ctx, & rmesa->swapped, - DRI_TEXMGR_DO_TEXTURE_1D - | DRI_TEXMGR_DO_TEXTURE_2D ); - - /* Hack: radeonNewTextureObject is not yet installed when the - * default textures are created. Therefore set MaxAnisotropy of the - * default 2D texture now. */ - ctx->Shared->Default2D->MaxAnisotropy = driQueryOptionf (&rmesa->optionCache, - "def_max_anisotropy"); +void radeonInitTextureFuncs( struct dd_function_table *functions ) +{ + functions->ChooseTextureFormat = radeonChooseTextureFormat; + functions->TexImage1D = radeonTexImage1D; + functions->TexImage2D = radeonTexImage2D; + functions->TexSubImage1D = radeonTexSubImage1D; + functions->TexSubImage2D = radeonTexSubImage2D; + + functions->NewTextureObject = radeonNewTextureObject; + /*functions->BindTexture = radeonBindTexture;*/ + functions->DeleteTexture = radeonDeleteTexture; + functions->IsTextureResident = driIsTextureResident; + + functions->TexEnv = radeonTexEnv; + functions->TexParameter = radeonTexParameter; + functions->TexGen = radeonTexGen; } diff --git a/src/mesa/drivers/dri/radeon/radeon_tex.h b/src/mesa/drivers/dri/radeon/radeon_tex.h index ce079baec2..9d9285e530 100644 --- a/src/mesa/drivers/dri/radeon/radeon_tex.h +++ b/src/mesa/drivers/dri/radeon/radeon_tex.h @@ -47,7 +47,7 @@ extern int radeonUploadTexImages( radeonContextPtr rmesa, radeonTexObjPtr t, extern void radeonDestroyTexObj( radeonContextPtr rmesa, radeonTexObjPtr t ); -extern void radeonInitTextureFuncs( GLcontext *ctx ); +extern void radeonInitTextureFuncs( struct dd_function_table *functions ); #endif #endif /* __RADEON_TEX_H__ */ diff --git a/src/mesa/drivers/dri/sis/Makefile.solo b/src/mesa/drivers/dri/sis/Makefile.solo index 655c4e7d31..7648d6921b 100644 --- a/src/mesa/drivers/dri/sis/Makefile.solo +++ b/src/mesa/drivers/dri/sis/Makefile.solo @@ -38,6 +38,7 @@ DRIVER_SOURCES = \ sis_texstate.c \ sis_tris.c \ sis_vb.c \ + ../../common/driverfuncs.c \ ../common/mm.c \ ../common/utils.c \ ../common/texmem.c \ diff --git a/src/mesa/drivers/dri/sis/sis_context.c b/src/mesa/drivers/dri/sis/sis_context.c index 7daa947a46..8a20f7ec0e 100644 --- a/src/mesa/drivers/dri/sis/sis_context.c +++ b/src/mesa/drivers/dri/sis/sis_context.c @@ -48,6 +48,8 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #include "extensions.h" #include "utils.h" +#include "drivers/common/driverfuncs.h" + #include "swrast/swrast.h" #include "swrast_setup/swrast_setup.h" #include "array_cache/acache.h" @@ -108,19 +110,26 @@ sisCreateContext( const __GLcontextModes *glVisual, sisContextPtr smesa; sisScreenPtr sisScreen; int i; + struct dd_function_table functions; smesa = (sisContextPtr)CALLOC( sizeof(*smesa) ); - if ( smesa == NULL ) + if (smesa == NULL) return GL_FALSE; + /* Init default driver functions then plug in our SIS-specific functions + * (the texture functions are especially important) + */ + _mesa_init_driver_functions(&functions); + sisInitTextureFuncs(&functions); + /* Allocate the Mesa context */ if (sharedContextPrivate) shareCtx = ((sisContextPtr)sharedContextPrivate)->glCtx; else shareCtx = NULL; - smesa->glCtx = _mesa_create_context( glVisual, shareCtx, (void *) smesa, - GL_TRUE); - if (smesa->glCtx == NULL) { + smesa->glCtx = _mesa_create_context( glVisual, shareCtx, + &functions, (void *) smesa); + if (!smesa->glCtx) { FREE(smesa); return GL_FALSE; } @@ -217,14 +226,13 @@ sisCreateContext( const __GLcontextModes *glVisual, _swrast_allow_pixel_fog( ctx, GL_TRUE ); _swrast_allow_vertex_fog( ctx, GL_FALSE ); + /* XXX these should really go right after _mesa_init_driver_functions() */ sisDDInitStateFuncs( ctx ); sisDDInitState( smesa ); /* Initializes smesa->zFormat, important */ sisInitVB( ctx ); sisInitTriFuncs( ctx ); - sisDDInitDriverFuncs( ctx ); sisDDInitSpanFuncs( ctx ); sisDDInitStencilFuncs( ctx ); - sisDDInitTextureFuncs( ctx ); driInitExtensions( ctx, card_extensions, GL_FALSE ); diff --git a/src/mesa/drivers/dri/sis/sis_dd.c b/src/mesa/drivers/dri/sis/sis_dd.c index aecc20e53d..2c97d270fd 100644 --- a/src/mesa/drivers/dri/sis/sis_dd.c +++ b/src/mesa/drivers/dri/sis/sis_dd.c @@ -48,7 +48,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. /* Return the width and height of the given buffer. */ static void -sisDDGetBufferSize( GLframebuffer *buffer, +sisGetBufferSize( GLframebuffer *buffer, GLuint *width, GLuint *height ) { GET_CURRENT_CONTEXT(ctx); @@ -63,7 +63,7 @@ sisDDGetBufferSize( GLframebuffer *buffer, /* Return various strings for glGetString(). */ static const GLubyte * -sisDDGetString( GLcontext *ctx, GLenum name ) +sisGetString( GLcontext *ctx, GLenum name ) { sisContextPtr smesa = SIS_CONTEXT(ctx); static char buffer[128]; @@ -88,7 +88,7 @@ sisDDGetString( GLcontext *ctx, GLenum name ) /* Send all commands to the hardware. No-op, due to mmio. */ static void -sisDDFlush( GLcontext *ctx ) +sisFlush( GLcontext *ctx ) { /* Do nothing */ } @@ -97,11 +97,11 @@ sisDDFlush( GLcontext *ctx ) * completed processing. */ static void -sisDDFinish( GLcontext *ctx ) +sisFinish( GLcontext *ctx ) { sisContextPtr smesa = SIS_CONTEXT(ctx); - sisDDFlush( ctx ); + sisFlush( ctx ); WaitEngIdle( smesa ); } @@ -165,12 +165,11 @@ sisUpdateBufferSize( sisContextPtr smesa ) /* Initialize the driver's misc functions. */ void -sisDDInitDriverFuncs( GLcontext *ctx ) +sisInitDriverFuncs( struct dd_function_table *functions ) { - ctx->Driver.GetBufferSize = sisDDGetBufferSize; - ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; - ctx->Driver.GetString = sisDDGetString; - ctx->Driver.Finish = sisDDFinish; - ctx->Driver.Flush = sisDDFlush; - ctx->Driver.Error = NULL; + functions->GetBufferSize = sisGetBufferSize; + functions->ResizeBuffers = _swrast_alloc_buffers; + functions->GetString = sisGetString; + functions->Finish = sisFinish; + functions->Flush = sisFlush; } diff --git a/src/mesa/drivers/dri/sis/sis_dd.h b/src/mesa/drivers/dri/sis/sis_dd.h index 9ff5f5b00d..a016bf8b26 100644 --- a/src/mesa/drivers/dri/sis/sis_dd.h +++ b/src/mesa/drivers/dri/sis/sis_dd.h @@ -36,7 +36,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. extern void sisUpdateBufferSize( sisContextPtr smesa ); -extern void sisDDInitDriverFuncs( GLcontext *ctx ); +extern void sisInitDriverFuncs( struct dd_function_table *functions ); #endif #endif diff --git a/src/mesa/drivers/dri/sis/sis_tex.c b/src/mesa/drivers/dri/sis/sis_tex.c index f5df84b3e7..ece0c519b7 100644 --- a/src/mesa/drivers/dri/sis/sis_tex.c +++ b/src/mesa/drivers/dri/sis/sis_tex.c @@ -40,7 +40,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "teximage.h" #include "texobj.h" -#define ALIGN(value, align) (char *)((long)(value + align - 1) & ~(align - 1)) +#define ALIGN(value, align) (GLubyte *)((long)(value + align - 1) & ~(align - 1)) #define TEXTURE_HW_ALIGNMENT 4 #define TEXTURE_HW_PLUS (4 + 4) @@ -139,7 +139,7 @@ sisFreeTexImage( sisContextPtr smesa, sisTexObjPtr t, int level ) } static void -sisDDTexEnv( GLcontext *ctx, GLenum target, GLenum pname, const GLfloat *param ) +sisTexEnv( GLcontext *ctx, GLenum target, GLenum pname, const GLfloat *param ) { sisContextPtr smesa = SIS_CONTEXT(ctx); @@ -147,9 +147,9 @@ sisDDTexEnv( GLcontext *ctx, GLenum target, GLenum pname, const GLfloat *param ) } static void -sisDDTexParameter( GLcontext *ctx, GLenum target, - struct gl_texture_object *texObj, GLenum pname, - const GLfloat *params ) +sisTexParameter( GLcontext *ctx, GLenum target, + struct gl_texture_object *texObj, GLenum pname, + const GLfloat *params ) { sisContextPtr smesa = SIS_CONTEXT(ctx); @@ -157,22 +157,13 @@ sisDDTexParameter( GLcontext *ctx, GLenum target, } static void -sisDDBindTexture( GLcontext *ctx, GLenum target, - struct gl_texture_object *texObj ) +sisBindTexture( GLcontext *ctx, GLenum target, + struct gl_texture_object *texObj ) { sisContextPtr smesa = SIS_CONTEXT(ctx); - sisTexObjPtr t; - - if ( target == GL_TEXTURE_2D || target == GL_TEXTURE_1D ) { - if ( texObj->DriverData == NULL ) { - sisAllocTexObj( texObj ); - } - } + sisTexObjPtr t = texObj->DriverData; - t = texObj->DriverData; - - if (t == NULL) - return; + assert(t); if (smesa->PrevTexFormat[ctx->Texture.CurrentUnit] != t->format) { smesa->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURE_ENV; @@ -182,7 +173,7 @@ sisDDBindTexture( GLcontext *ctx, GLenum target, } static void -sisDDDeleteTexture( GLcontext * ctx, struct gl_texture_object *texObj ) +sisDeleteTexture( GLcontext * ctx, struct gl_texture_object *texObj ) { sisContextPtr smesa = SIS_CONTEXT(ctx); sisTexObjPtr t; @@ -191,10 +182,11 @@ sisDDDeleteTexture( GLcontext * ctx, struct gl_texture_object *texObj ) smesa->clearTexCache = GL_TRUE; t = texObj->DriverData; + assert(t); if (t == NULL) { /* * this shows the texture is default object and never be a - * argument of sisDDTexImage* + * argument of sisTexImage* */ return; } @@ -208,14 +200,14 @@ sisDDDeleteTexture( GLcontext * ctx, struct gl_texture_object *texObj ) _mesa_delete_texture_object(ctx, texObj); } -static GLboolean sisDDIsTextureResident( GLcontext * ctx, +static GLboolean sisIsTextureResident( GLcontext * ctx, struct gl_texture_object *texObj ) { return (texObj->DriverData != NULL); } static const struct gl_texture_format * -sisDDChooseTextureFormat( GLcontext *ctx, GLint internalFormat, +sisChooseTextureFormat( GLcontext *ctx, GLint internalFormat, GLenum format, GLenum type ) { /* XXX 16-bit internal texture formats? */ @@ -275,7 +267,7 @@ sisDDChooseTextureFormat( GLcontext *ctx, GLint internalFormat, } } -static void sisDDTexImage1D( GLcontext *ctx, GLenum target, GLint level, +static void sisTexImage1D( GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLint width, GLint border, GLenum format, GLenum type, const GLvoid *pixels, @@ -284,13 +276,10 @@ static void sisDDTexImage1D( GLcontext *ctx, GLenum target, GLint level, struct gl_texture_image *texImage ) { sisContextPtr smesa = SIS_CONTEXT(ctx); - sisTexObjPtr t; - - if ( texObj->DriverData == NULL ) - sisAllocTexObj( texObj ); - t = texObj->DriverData; + sisTexObjPtr t = texObj->DriverData; - /* Note, this will call sisDDChooseTextureFormat */ + assert(t); + /* Note, this will call sisChooseTextureFormat */ _mesa_store_teximage1d( ctx, target, level, internalFormat, width, border, format, type, pixels, packing, texObj, texImage ); @@ -311,7 +300,7 @@ static void sisDDTexImage1D( GLcontext *ctx, GLenum target, GLint level, } -static void sisDDTexSubImage1D( GLcontext *ctx, +static void sisTexSubImage1D( GLcontext *ctx, GLenum target, GLint level, GLint xoffset, @@ -323,14 +312,13 @@ static void sisDDTexSubImage1D( GLcontext *ctx, struct gl_texture_image *texImage ) { sisContextPtr smesa = SIS_CONTEXT(ctx); - sisTexObjPtr t; + sisTexObjPtr t = texObj->DriverData; GLuint copySize; GLint texelBytes; - char *src, *dst; + const char *src; + GLubyte *dst; - if ( texObj->DriverData == NULL ) - sisAllocTexObj( texObj ); - t = texObj->DriverData; + assert(t); _mesa_store_texsubimage1d(ctx, target, level, xoffset, width, format, type, pixels, packing, texObj, @@ -359,7 +347,7 @@ static void sisDDTexSubImage1D( GLcontext *ctx, smesa->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURING; } -static void sisDDTexImage2D( GLcontext *ctx, GLenum target, GLint level, +static void sisTexImage2D( GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLint width, GLint height, GLint border, GLenum format, GLenum type, const GLvoid *pixels, @@ -368,13 +356,11 @@ static void sisDDTexImage2D( GLcontext *ctx, GLenum target, GLint level, struct gl_texture_image *texImage ) { sisContextPtr smesa = SIS_CONTEXT(ctx); - sisTexObjPtr t; + sisTexObjPtr t = texObj->DriverData; - if ( texObj->DriverData == NULL ) - sisAllocTexObj( texObj ); - t = texObj->DriverData; + assert(t); - /* Note, this will call sisDDChooseTextureFormat */ + /* Note, this will call sisChooseTextureFormat */ _mesa_store_teximage2d(ctx, target, level, internalFormat, width, height, border, format, type, pixels, &ctx->Unpack, texObj, texImage); @@ -394,7 +380,7 @@ static void sisDDTexImage2D( GLcontext *ctx, GLenum target, GLint level, smesa->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURING; } -static void sisDDTexSubImage2D( GLcontext *ctx, +static void sisTexSubImage2D( GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, @@ -406,16 +392,15 @@ static void sisDDTexSubImage2D( GLcontext *ctx, struct gl_texture_image *texImage ) { sisContextPtr smesa = SIS_CONTEXT(ctx); - sisTexObjPtr t; + sisTexObjPtr t = texObj->DriverData; GLuint copySize; GLint texelBytes; - char *src, *dst; + const char *src; + GLubyte *dst; int j; GLuint soffset; - if ( texObj->DriverData == NULL ) - sisAllocTexObj( texObj ); - t = texObj->DriverData; + assert(t); _mesa_store_texsubimage2d(ctx, target, level, xoffset, yoffset, width, height, format, type, pixels, packing, texObj, @@ -449,28 +434,43 @@ static void sisDDTexSubImage2D( GLcontext *ctx, smesa->PrevTexFormat[ctx->Texture.CurrentUnit] = t->format; } smesa->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURING; +} + +/** + * Allocate a new texture object. + * Called via ctx->Driver.NewTextureObject. + * Note: this function will be called during context creation to + * allocate the default texture objects. + */ +static struct gl_texture_object * +sisNewTextureObject( GLcontext *ctx, GLuint name, GLenum target ) +{ + struct gl_texture_object *obj; + sisTexObjPtr t; + obj = _mesa_new_texture_object(ctx, name, target); + if (!obj) + return NULL; + t = (sisTexObjPtr) sisAllocTexObj( obj ); + if (!t) { + _mesa_delete_texture_object(ctx, obj); + return NULL; + } + return obj; } -void sisDDInitTextureFuncs( GLcontext *ctx ) + +void sisInitTextureFuncs( struct dd_function_table *functions ) { - ctx->Driver.TexEnv = sisDDTexEnv; - ctx->Driver.ChooseTextureFormat = sisDDChooseTextureFormat; - ctx->Driver.TexImage1D = sisDDTexImage1D; - ctx->Driver.TexSubImage1D = sisDDTexSubImage1D; - ctx->Driver.TexImage2D = sisDDTexImage2D; - ctx->Driver.TexSubImage2D = sisDDTexSubImage2D; - ctx->Driver.TexImage3D = _mesa_store_teximage3d; - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; - ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; - ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; - ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; - ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; - ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; - ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; - ctx->Driver.TexParameter = sisDDTexParameter; - ctx->Driver.BindTexture = sisDDBindTexture; - ctx->Driver.DeleteTexture = sisDDDeleteTexture; - ctx->Driver.IsTextureResident = sisDDIsTextureResident; - ctx->Driver.PrioritizeTexture = NULL; + functions->TexEnv = sisTexEnv; + functions->ChooseTextureFormat = sisChooseTextureFormat; + functions->TexImage1D = sisTexImage1D; + functions->TexSubImage1D = sisTexSubImage1D; + functions->TexImage2D = sisTexImage2D; + functions->TexSubImage2D = sisTexSubImage2D; + functions->TexParameter = sisTexParameter; + functions->BindTexture = sisBindTexture; + functions->NewTextureObject = sisNewTextureObject; + functions->DeleteTexture = sisDeleteTexture; + functions->IsTextureResident = sisIsTextureResident; } diff --git a/src/mesa/drivers/dri/sis/sis_tex.h b/src/mesa/drivers/dri/sis/sis_tex.h index b2f2ba0cbd..2349824885 100644 --- a/src/mesa/drivers/dri/sis/sis_tex.h +++ b/src/mesa/drivers/dri/sis/sis_tex.h @@ -34,7 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #ifdef GLX_DIRECT_RENDERING -extern void sisDDInitTextureFuncs( GLcontext *ctx ); +extern void sisInitTextureFuncs( struct dd_function_table *table ); extern void sisUpdateTextureState( GLcontext *ctx ); #endif /* GLX_DIRECT_RENDERING */ diff --git a/src/mesa/drivers/dri/tdfx/Makefile.solo b/src/mesa/drivers/dri/tdfx/Makefile.solo index 99a1b88209..6b3a4cd78d 100644 --- a/src/mesa/drivers/dri/tdfx/Makefile.solo +++ b/src/mesa/drivers/dri/tdfx/Makefile.solo @@ -24,6 +24,7 @@ DEFINES += \ # MINIGLX_SOURCES = server/tdfx_dri.c DRIVER_SOURCES = tdfx_context.c \ + ../../common/driverfuncs.c \ ../common/mm.c \ ../common/utils.c \ ../common/texmem.c \ diff --git a/src/mesa/drivers/dri/tdfx/tdfx_context.c b/src/mesa/drivers/dri/tdfx/tdfx_context.c index ae79c55b39..973aa6cff2 100644 --- a/src/mesa/drivers/dri/tdfx/tdfx_context.c +++ b/src/mesa/drivers/dri/tdfx/tdfx_context.c @@ -40,13 +40,13 @@ #include "tdfx_dd.h" #include "tdfx_state.h" #include "tdfx_vb.h" +#include "tdfx_tex.h" #include "tdfx_tris.h" #include "tdfx_render.h" #include "tdfx_span.h" #include "tdfx_texman.h" #include "extensions.h" - #include "swrast/swrast.h" #include "swrast_setup/swrast_setup.h" #include "array_cache/acache.h" @@ -54,6 +54,8 @@ #include "tnl/tnl.h" #include "tnl/t_pipeline.h" +#include "drivers/common/driverfuncs.h" + const char __driConfigOptions[] = { 0 }; const GLuint __driNConfigOptions = 0; @@ -115,19 +117,29 @@ GLboolean tdfxCreateContext( const __GLcontextModes *mesaVis, tdfxScreenPrivate *fxScreen = (tdfxScreenPrivate *) sPriv->private; TDFXSAREAPriv *saPriv = (TDFXSAREAPriv *) ((char *) sPriv->pSAREA + sizeof(XF86DRISAREARec)); + struct dd_function_table functions; /* Allocate tdfx context */ fxMesa = (tdfxContextPtr) CALLOC( sizeof(tdfxContextRec) ); if (!fxMesa) return GL_FALSE; + /* Init default driver functions then plug in our tdfx-specific functions + * (the texture functions are especially important) + */ + _mesa_init_driver_functions(&functions); + tdfxDDInitDriverFuncs(mesaVis, &functions); + tdfxInitTextureFuncs(&functions); + tdfxInitRenderFuncs(&functions); + /* Allocate the Mesa context */ if (sharedContextPrivate) shareCtx = ((tdfxContextPtr) sharedContextPrivate)->glCtx; else shareCtx = NULL; - fxMesa->glCtx = _mesa_create_context(mesaVis, shareCtx, (void *) fxMesa, GL_TRUE); + fxMesa->glCtx = _mesa_create_context(mesaVis, shareCtx, + &functions, (void *) fxMesa); if (!fxMesa->glCtx) { FREE(fxMesa); return GL_FALSE; @@ -246,10 +258,9 @@ GLboolean tdfxCreateContext( const __GLcontextModes *mesaVis, _swrast_allow_vertex_fog( ctx, GL_FALSE ); tdfxDDInitExtensions( ctx ); - tdfxDDInitDriverFuncs( ctx ); - tdfxDDInitStateFuncs( ctx ); - tdfxDDInitRenderFuncs( ctx ); + /* XXX these should really go right after _mesa_init_driver_functions() */ tdfxDDInitSpanFuncs( ctx ); + tdfxDDInitStateFuncs( ctx ); tdfxDDInitTriFuncs( ctx ); tdfxInitVB( ctx ); tdfxInitState( fxMesa ); diff --git a/src/mesa/drivers/dri/tdfx/tdfx_dd.c b/src/mesa/drivers/dri/tdfx/tdfx_dd.c index 79fc6d9e26..367b0d241e 100644 --- a/src/mesa/drivers/dri/tdfx/tdfx_dd.c +++ b/src/mesa/drivers/dri/tdfx/tdfx_dd.c @@ -243,47 +243,38 @@ static GLboolean tdfxDDGetIntegerv( GLcontext *ctx, GLenum pname, #define VISUAL_EQUALS_RGBA(vis, r, g, b, a) \ - ((vis.redBits == r) && \ - (vis.greenBits == g) && \ - (vis.blueBits == b) && \ - (vis.alphaBits == a)) + ((vis->redBits == r) && \ + (vis->greenBits == g) && \ + (vis->blueBits == b) && \ + (vis->alphaBits == a)) -void tdfxDDInitDriverFuncs( GLcontext *ctx ) +void tdfxDDInitDriverFuncs( const __GLcontextModes *visual, + struct dd_function_table *functions ) { if ( MESA_VERBOSE & VERBOSE_DRIVER ) { fprintf( stderr, "tdfx: %s()\n", __FUNCTION__ ); } - ctx->Driver.GetString = tdfxDDGetString; - ctx->Driver.GetBufferSize = tdfxDDGetBufferSize; - ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; - ctx->Driver.Error = NULL; - - /* Pixel path fallbacks. - */ - ctx->Driver.Accum = _swrast_Accum; - ctx->Driver.Bitmap = _swrast_Bitmap; - ctx->Driver.CopyPixels = _swrast_CopyPixels; - ctx->Driver.DrawPixels = _swrast_DrawPixels; - ctx->Driver.ReadPixels = _swrast_ReadPixels; + functions->GetString = tdfxDDGetString; + functions->GetBufferSize = tdfxDDGetBufferSize; + functions->ResizeBuffers = _swrast_alloc_buffers; /* Accelerated paths */ - if ( VISUAL_EQUALS_RGBA(ctx->Visual, 8, 8, 8, 8) ) + if ( VISUAL_EQUALS_RGBA(visual, 8, 8, 8, 8) ) { - ctx->Driver.DrawPixels = tdfx_drawpixels_R8G8B8A8; - ctx->Driver.ReadPixels = tdfx_readpixels_R8G8B8A8; + functions->DrawPixels = tdfx_drawpixels_R8G8B8A8; + functions->ReadPixels = tdfx_readpixels_R8G8B8A8; } - else if ( VISUAL_EQUALS_RGBA(ctx->Visual, 5, 6, 5, 0) ) + else if ( VISUAL_EQUALS_RGBA(visual, 5, 6, 5, 0) ) { - ctx->Driver.ReadPixels = tdfx_readpixels_R5G6B5; + functions->ReadPixels = tdfx_readpixels_R5G6B5; } - ctx->Driver.GetBooleanv = tdfxDDGetBooleanv; - ctx->Driver.GetDoublev = tdfxDDGetDoublev; - ctx->Driver.GetFloatv = tdfxDDGetFloatv; - ctx->Driver.GetIntegerv = tdfxDDGetIntegerv; - ctx->Driver.GetPointerv = NULL; + functions->GetBooleanv = tdfxDDGetBooleanv; + functions->GetDoublev = tdfxDDGetDoublev; + functions->GetFloatv = tdfxDDGetFloatv; + functions->GetIntegerv = tdfxDDGetIntegerv; } diff --git a/src/mesa/drivers/dri/tdfx/tdfx_dd.h b/src/mesa/drivers/dri/tdfx/tdfx_dd.h index dbb585e3b2..e49d8e2a33 100644 --- a/src/mesa/drivers/dri/tdfx/tdfx_dd.h +++ b/src/mesa/drivers/dri/tdfx/tdfx_dd.h @@ -41,7 +41,8 @@ #include "context.h" -extern void tdfxDDInitDriverFuncs( GLcontext *ctx ); +extern void tdfxDDInitDriverFuncs( const __GLcontextModes *visual, + struct dd_function_table *functions ); #endif #endif diff --git a/src/mesa/drivers/dri/tdfx/tdfx_render.c b/src/mesa/drivers/dri/tdfx/tdfx_render.c index 1cb3eeddbc..84d919591b 100644 --- a/src/mesa/drivers/dri/tdfx/tdfx_render.c +++ b/src/mesa/drivers/dri/tdfx/tdfx_render.c @@ -43,7 +43,7 @@ /* Clear the color and/or depth buffers. */ -static void tdfxDDClear( GLcontext *ctx, +static void tdfxClear( GLcontext *ctx, GLbitfield mask, GLboolean all, GLint x, GLint y, GLint width, GLint height ) { @@ -315,7 +315,7 @@ static void tdfxDDClear( GLcontext *ctx, -static void tdfxDDFinish( GLcontext *ctx ) +static void tdfxFinish( GLcontext *ctx ) { tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); @@ -326,7 +326,7 @@ static void tdfxDDFinish( GLcontext *ctx ) UNLOCK_HARDWARE( fxMesa ); } -static void tdfxDDFlush( GLcontext *ctx ) +static void tdfxFlush( GLcontext *ctx ) { tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); @@ -794,9 +794,9 @@ void tdfxEmitHwStateLocked( tdfxContextPtr fxMesa ) -void tdfxDDInitRenderFuncs( GLcontext *ctx ) +void tdfxInitRenderFuncs( struct dd_function_table *functions ) { - ctx->Driver.Clear = tdfxDDClear; - ctx->Driver.Finish = tdfxDDFinish; - ctx->Driver.Flush = tdfxDDFlush; + functions->Clear = tdfxClear; + functions->Finish = tdfxFinish; + functions->Flush = tdfxFlush; } diff --git a/src/mesa/drivers/dri/tdfx/tdfx_render.h b/src/mesa/drivers/dri/tdfx/tdfx_render.h index 146120bc05..395e09f7e9 100644 --- a/src/mesa/drivers/dri/tdfx/tdfx_render.h +++ b/src/mesa/drivers/dri/tdfx/tdfx_render.h @@ -41,7 +41,7 @@ #include "tdfx_context.h" -extern void tdfxDDInitRenderFuncs( GLcontext *ctx ); +extern void tdfxInitRenderFuncs( struct dd_function_table *functions ); extern void tdfxEmitHwStateLocked( tdfxContextPtr fxMesa ); diff --git a/src/mesa/drivers/dri/tdfx/tdfx_state.c b/src/mesa/drivers/dri/tdfx/tdfx_state.c index 5372558cdf..53e331f69b 100644 --- a/src/mesa/drivers/dri/tdfx/tdfx_state.c +++ b/src/mesa/drivers/dri/tdfx/tdfx_state.c @@ -1388,12 +1388,10 @@ void tdfxDDInitStateFuncs( GLcontext *ctx ) /* State notification callbacks: */ - ctx->Driver.ClearIndex = NULL; ctx->Driver.ClearColor = tdfxDDClearColor; ctx->Driver.DrawBuffer = tdfxDDDrawBuffer; ctx->Driver.ReadBuffer = tdfxDDReadBuffer; - ctx->Driver.IndexMask = NULL; ctx->Driver.ColorMask = tdfxDDColorMask; ctx->Driver.AlphaFunc = tdfxDDAlphaFunc; @@ -1401,7 +1399,6 @@ void tdfxDDInitStateFuncs( GLcontext *ctx ) ctx->Driver.BlendFunc = tdfxDDBlendFunc; ctx->Driver.BlendFuncSeparate = tdfxDDBlendFuncSeparate; ctx->Driver.ClearDepth = tdfxDDClearDepth; - ctx->Driver.ClearStencil = NULL; ctx->Driver.CullFace = tdfxDDCullFace; ctx->Driver.FrontFace = tdfxDDFrontFace; ctx->Driver.DepthFunc = tdfxDDDepthFunc; @@ -1409,39 +1406,13 @@ void tdfxDDInitStateFuncs( GLcontext *ctx ) ctx->Driver.DepthRange = tdfxDDDepthRange; ctx->Driver.Enable = tdfxDDEnable; ctx->Driver.Fogfv = tdfxDDFogfv; - ctx->Driver.Hint = NULL; - ctx->Driver.Lightfv = NULL; ctx->Driver.LightModelfv = tdfxDDLightModelfv; - ctx->Driver.LineStipple = NULL; ctx->Driver.LineWidth = tdfxDDLineWidth; ctx->Driver.PolygonStipple = tdfxDDPolygonStipple; ctx->Driver.RenderMode = tdfxDDRenderMode; ctx->Driver.Scissor = tdfxDDScissor; ctx->Driver.ShadeModel = tdfxDDShadeModel; - ctx->Driver.BindTexture = tdfxDDBindTexture; - ctx->Driver.DeleteTexture = tdfxDDDeleteTexture; - ctx->Driver.TexEnv = tdfxDDTexEnv; - ctx->Driver.TexParameter = tdfxDDTexParameter; - ctx->Driver.ChooseTextureFormat = tdfxDDChooseTextureFormat; - ctx->Driver.TexImage2D = tdfxDDTexImage2D; - ctx->Driver.TexSubImage2D = tdfxDDTexSubImage2D; - /* - ctx->Driver.TexImage2D = _mesa_store_teximage2d; - ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d; - */ - - ctx->Driver.TexImage1D = _mesa_store_teximage1d; - ctx->Driver.TexImage3D = _mesa_store_teximage3d; - ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d; - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; - ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; - ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; - ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; - ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; - ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; - ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; - /* ctx->Driver.GetTexImage = tdfxDDGetTexImage; */ ctx->Driver.UpdateTexturePalette = tdfxDDTexturePalette; @@ -1449,15 +1420,10 @@ void tdfxDDInitStateFuncs( GLcontext *ctx ) ctx->Driver.StencilFunc = tdfxDDStencilFunc; ctx->Driver.StencilMask = tdfxDDStencilMask; ctx->Driver.StencilOp = tdfxDDStencilOp; - } else { - ctx->Driver.StencilFunc = NULL; - ctx->Driver.StencilMask = NULL; - ctx->Driver.StencilOp = NULL; } ctx->Driver.Viewport = tdfxDDViewport; - /* Swrast hooks for imaging extensions: */ ctx->Driver.CopyColorTable = _swrast_CopyColorTable; diff --git a/src/mesa/drivers/dri/tdfx/tdfx_tex.c b/src/mesa/drivers/dri/tdfx/tdfx_tex.c index d18812faaa..d25a03da9c 100644 --- a/src/mesa/drivers/dri/tdfx/tdfx_tex.c +++ b/src/mesa/drivers/dri/tdfx/tdfx_tex.c @@ -200,42 +200,11 @@ static void RevalidateTexture(GLcontext *ctx, struct gl_texture_object *tObj) } -static tdfxTexInfo * -fxAllocTexObjData(tdfxContextPtr fxMesa) -{ - tdfxTexInfo *ti; - - if (!(ti = CALLOC(sizeof(tdfxTexInfo)))) { - _mesa_problem(NULL, "tdfx driver: out of memory"); - return NULL; - } - - ti->isInTM = GL_FALSE; - - ti->whichTMU = TDFX_TMU_NONE; - - ti->tm[TDFX_TMU0] = NULL; - ti->tm[TDFX_TMU1] = NULL; - - ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED; - ti->magFilt = GR_TEXTUREFILTER_BILINEAR; - - ti->sClamp = GR_TEXTURECLAMP_WRAP; - ti->tClamp = GR_TEXTURECLAMP_WRAP; - - ti->mmMode = GR_MIPMAP_NEAREST; - ti->LODblend = FXFALSE; - - return ti; -} - - /* * Called via glBindTexture. */ - -void -tdfxDDBindTexture(GLcontext * ctx, GLenum target, +static void +tdfxBindTexture(GLcontext * ctx, GLenum target, struct gl_texture_object *tObj) { tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); @@ -249,11 +218,8 @@ tdfxDDBindTexture(GLcontext * ctx, GLenum target, if (target != GL_TEXTURE_2D) return; - if (!tObj->DriverData) { - tObj->DriverData = fxAllocTexObjData(fxMesa); - } - ti = TDFX_TEXTURE_DATA(tObj); + assert(ti); ti->lastTimeUsed = fxMesa->texBindNumber++; fxMesa->new_state |= TDFX_NEW_TEXTURE; @@ -263,8 +229,8 @@ tdfxDDBindTexture(GLcontext * ctx, GLenum target, /* * Called via glTexEnv. */ -void -tdfxDDTexEnv(GLcontext * ctx, GLenum target, GLenum pname, +static void +tdfxTexEnv(GLcontext * ctx, GLenum target, GLenum pname, const GLfloat * param) { tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); @@ -289,8 +255,8 @@ tdfxDDTexEnv(GLcontext * ctx, GLenum target, GLenum pname, /* * Called via glTexParameter. */ -void -tdfxDDTexParameter(GLcontext * ctx, GLenum target, +static void +tdfxTexParameter(GLcontext * ctx, GLenum target, struct gl_texture_object *tObj, GLenum pname, const GLfloat * params) { @@ -306,10 +272,8 @@ tdfxDDTexParameter(GLcontext * ctx, GLenum target, if (target != GL_TEXTURE_2D) return; - if (!tObj->DriverData) - tObj->DriverData = fxAllocTexObjData(fxMesa); - ti = TDFX_TEXTURE_DATA(tObj); + assert(ti); switch (pname) { case GL_TEXTURE_MIN_FILTER: @@ -444,7 +408,7 @@ tdfxDDTexParameter(GLcontext * ctx, GLenum target, * Here, we delete the Glide data associated with the texture. */ void -tdfxDDDeleteTexture(GLcontext * ctx, struct gl_texture_object *tObj) +tdfxDeleteTexture(GLcontext * ctx, struct gl_texture_object *tObj) { if (ctx && ctx->DriverCtx) { tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); @@ -460,7 +424,7 @@ tdfxDDDeleteTexture(GLcontext * ctx, struct gl_texture_object *tObj) * Return true if texture is resident, false otherwise. */ GLboolean -tdfxDDIsTextureResident(GLcontext *ctx, struct gl_texture_object *tObj) +tdfxIsTextureResident(GLcontext *ctx, struct gl_texture_object *tObj) { tdfxTexInfo *ti = TDFX_TEXTURE_DATA(tObj); return (GLboolean) (ti && ti->isInTM); @@ -538,7 +502,7 @@ convertPalette(FxU32 data[256], const struct gl_color_table *table) void -tdfxDDTexturePalette(GLcontext * ctx, struct gl_texture_object *tObj) +tdfxTexturePalette(GLcontext * ctx, struct gl_texture_object *tObj) { tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); @@ -550,9 +514,8 @@ tdfxDDTexturePalette(GLcontext * ctx, struct gl_texture_object *tObj) if (!tObj->Palette.Table) return; - if (!tObj->DriverData) - tObj->DriverData = fxAllocTexObjData(fxMesa); ti = TDFX_TEXTURE_DATA(tObj); + assert(ti); convertPalette(ti->palette.data, &tObj->Palette); /*tdfxTexInvalidate(ctx, tObj);*/ } @@ -587,8 +550,8 @@ fxTexusError(const char *string, FxBool fatal) #endif -const struct gl_texture_format * -tdfxDDChooseTextureFormat( GLcontext *ctx, GLint internalFormat, +static const struct gl_texture_format * +tdfxChooseTextureFormat( GLcontext *ctx, GLint internalFormat, GLenum srcFormat, GLenum srcType ) { tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); @@ -658,7 +621,7 @@ tdfxDDChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_COLOR_INDEX16_EXT: return &_mesa_texformat_ci8; default: - _mesa_problem(ctx, "unexpected format in tdfxDDChooseTextureFormat"); + _mesa_problem(ctx, "unexpected format in tdfxChooseTextureFormat"); return NULL; } } @@ -897,8 +860,8 @@ fxFetchFunction(GLint mesaFormat) } -void -tdfxDDTexImage2D(GLcontext *ctx, GLenum target, GLint level, +static void +tdfxTexImage2D(GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLint width, GLint height, GLint border, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, @@ -917,14 +880,7 @@ tdfxDDTexImage2D(GLcontext *ctx, GLenum target, GLint level, */ ti = TDFX_TEXTURE_DATA(texObj); - if (!ti) { - texObj->DriverData = fxAllocTexObjData(fxMesa); - if (!texObj->DriverData) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); - return; - } - ti = TDFX_TEXTURE_DATA(texObj); - } + assert(ti); mml = TDFX_TEXIMAGE_DATA(texImage); if (!mml) { @@ -1015,8 +971,8 @@ tdfxDDTexImage2D(GLcontext *ctx, GLenum target, GLint level, } -void -tdfxDDTexSubImage2D(GLcontext *ctx, GLenum target, GLint level, +static void +tdfxTexSubImage2D(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, @@ -1030,11 +986,6 @@ tdfxDDTexSubImage2D(GLcontext *ctx, GLenum target, GLint level, tdfxMipMapLevel *mml; GLint texelBytes; - if (!texObj->DriverData) { - _mesa_problem(ctx, "problem in fxDDTexSubImage2D"); - return; - } - ti = TDFX_TEXTURE_DATA(texObj); assert(ti); mml = TDFX_TEXIMAGE_DATA(texImage); @@ -1112,7 +1063,7 @@ tdfxDDTexSubImage2D(GLcontext *ctx, GLenum target, GLint level, #if 0000 GLboolean -tdfxDDCompressedTexImage2D( GLcontext *ctx, GLenum target, +tdfxCompressedTexImage2D( GLcontext *ctx, GLenum target, GLint level, GLsizei imageSize, const GLvoid *data, struct gl_texture_object *texObj, @@ -1132,10 +1083,8 @@ tdfxDDCompressedTexImage2D( GLcontext *ctx, GLenum target, if (target != GL_TEXTURE_2D || texImage->Border > 0) return GL_FALSE; - if (!texObj->DriverData) - texObj->DriverData = fxAllocTexObjData(fxMesa); - ti = TDFX_TEXTURE_DATA(texObj); + assert(ti); mml = &ti->mipmapLevel[level]; isCompressedFormat = tdfxDDIsCompressedGlideFormatMacro(texImage->IntFormat); @@ -1207,7 +1156,7 @@ tdfxDDCompressedTexImage2D( GLcontext *ctx, GLenum target, } GLboolean -tdfxDDCompressedTexSubImage2D( GLcontext *ctx, GLenum target, +tdfxCompressedTexSubImage2D( GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLint height, GLenum format, @@ -1265,7 +1214,7 @@ PrintTexture(int w, int h, int c, const GLubyte * data) GLboolean -tdfxDDTestProxyTexImage(GLcontext *ctx, GLenum target, +tdfxTestProxyTexImage(GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLenum format, GLenum type, GLint width, GLint height, @@ -1285,9 +1234,8 @@ tdfxDDTestProxyTexImage(GLcontext *ctx, GLenum target, int memNeeded; tObj = ctx->Texture.Proxy2D; - if (!tObj->DriverData) - tObj->DriverData = fxAllocTexObjData(fxMesa); ti = TDFX_TEXTURE_DATA(tObj); + assert(ti); /* assign the parameters to test against */ tObj->Image[level]->Width = width; @@ -1349,7 +1297,7 @@ tdfxDDTestProxyTexImage(GLcontext *ctx, GLenum target, * copy out the compressed data. */ void -tdfxDDGetCompressedTexImage( GLcontext *ctx, GLenum target, +tdfxGetCompressedTexImage( GLcontext *ctx, GLenum target, GLint lod, void *image, const struct gl_texture_object *texObj, struct gl_texture_image *texImage ) @@ -1360,10 +1308,8 @@ tdfxDDGetCompressedTexImage( GLcontext *ctx, GLenum target, if (target != GL_TEXTURE_2D) return; - if (!texObj->DriverData) - return; - ti = TDFX_TEXTURE_DATA(texObj); + assert(ti); mml = &ti->mipmapLevel[lod]; if (mml->data) { MEMCPY(image, mml->data, mml->dataSize); @@ -1376,7 +1322,7 @@ tdfxDDGetCompressedTexImage( GLcontext *ctx, GLenum target, * texture format. */ GLint -tdfxDDSpecificCompressedTexFormat(GLcontext *ctx, +tdfxSpecificCompressedTexFormat(GLcontext *ctx, GLint internalFormat, GLint numDimensions) { @@ -1410,7 +1356,7 @@ tdfxDDSpecificCompressedTexFormat(GLcontext *ctx, * texture format. */ GLint -tdfxDDBaseCompressedTexFormat(GLcontext *ctx, +tdfxBaseCompressedTexFormat(GLcontext *ctx, GLint internalFormat) { switch (internalFormat) { @@ -1474,3 +1420,60 @@ tdfxDDCompressedImageSize(GLcontext *ctx, } return 0; } + + + +/** + * Allocate a new texture object. + * Called via ctx->Driver.NewTextureObject. + * Note: this function will be called during context creation to + * allocate the default texture objects. + */ +static struct gl_texture_object * +tdfxNewTextureObject( GLcontext *ctx, GLuint name, GLenum target ) +{ + struct gl_texture_object *obj; + tdfxTexInfo *ti; + obj = _mesa_new_texture_object(ctx, name, target); + if (!obj) + return NULL; + + if (!(ti = CALLOC(sizeof(tdfxTexInfo)))) { + _mesa_delete_texture_object(ctx, obj); + return NULL; + } + + ti->isInTM = GL_FALSE; + + ti->whichTMU = TDFX_TMU_NONE; + + ti->tm[TDFX_TMU0] = NULL; + ti->tm[TDFX_TMU1] = NULL; + + ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED; + ti->magFilt = GR_TEXTUREFILTER_BILINEAR; + + ti->sClamp = GR_TEXTURECLAMP_WRAP; + ti->tClamp = GR_TEXTURECLAMP_WRAP; + + ti->mmMode = GR_MIPMAP_NEAREST; + ti->LODblend = FXFALSE; + + obj->DriverData = ti; + + return obj; +} + + +void tdfxInitTextureFuncs( struct dd_function_table *functions ) +{ + functions->BindTexture = tdfxBindTexture; + functions->NewTextureObject = tdfxNewTextureObject; + functions->DeleteTexture = tdfxDeleteTexture; + functions->TexEnv = tdfxTexEnv; + functions->TexParameter = tdfxTexParameter; + functions->ChooseTextureFormat = tdfxChooseTextureFormat; + functions->TexImage2D = tdfxTexImage2D; + functions->TexSubImage2D = tdfxTexSubImage2D; +} + diff --git a/src/mesa/drivers/dri/tdfx/tdfx_tex.h b/src/mesa/drivers/dri/tdfx/tdfx_tex.h index 5fc7c740bf..29872e7647 100644 --- a/src/mesa/drivers/dri/tdfx/tdfx_tex.h +++ b/src/mesa/drivers/dri/tdfx/tdfx_tex.h @@ -53,9 +53,6 @@ extern void tdfxTexValidate(GLcontext * ctx, struct gl_texture_object *tObj); -extern void -tdfxDDBindTexture(GLcontext * ctx, GLenum target, - struct gl_texture_object *tObj); extern void tdfxDDDeleteTexture(GLcontext * ctx, struct gl_texture_object *tObj); @@ -71,57 +68,6 @@ extern void fxDDTexUseGlobalPalette(GLcontext * ctx, GLboolean state); #endif -extern void -tdfxDDTexEnv(GLcontext * ctx, GLenum target, GLenum pname, - const GLfloat * param); - -extern void -tdfxDDTexParameter(GLcontext * ctx, GLenum target, - struct gl_texture_object *tObj, - GLenum pname, const GLfloat * params); - -extern const struct gl_texture_format * -tdfxDDChooseTextureFormat( GLcontext *ctx, GLint internalFormat, - GLenum srcFormat, GLenum srcType ); - -extern void -tdfxDDTexImage2D(GLcontext * ctx, GLenum target, GLint level, - GLint internalFormat, GLint width, GLint height, - GLint border, - GLenum format, GLenum type, const GLvoid * pixels, - const struct gl_pixelstore_attrib * packing, - struct gl_texture_object * texObj, - struct gl_texture_image * texImage); - -extern void -tdfxDDTexSubImage2D(GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage ); - -#if 000 -extern GLboolean -tdfxDDCompressedTexImage2D( GLcontext *ctx, GLenum target, - GLint level, GLsizei imageSize, - const GLvoid *data, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage, - GLboolean *retainInternalCopy); - -extern GLboolean -tdfxDDCompressedTexSubImage2D( GLcontext *ctx, GLenum target, - GLint level, GLint xoffset, - GLint yoffset, GLsizei width, - GLint height, GLenum format, - GLsizei imageSize, const GLvoid *data, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage ); -#endif - extern GLboolean tdfxDDTestProxyTexImage(GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, @@ -162,4 +108,7 @@ tdfxDDCompressedImageSize(GLcontext *ctx, GLuint depth); +extern void +tdfxInitTextureFuncs( struct dd_function_table *functions ); + #endif diff --git a/src/mesa/drivers/fbdev/glfbdev.c b/src/mesa/drivers/fbdev/glfbdev.c index 6d3ed01d7b..15ddbca9ed 100644 --- a/src/mesa/drivers/fbdev/glfbdev.c +++ b/src/mesa/drivers/fbdev/glfbdev.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 5.1 + * Version: 6.1 * - * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -57,6 +57,7 @@ #include "tnl/tnl.h" #include "tnl/t_context.h" #include "tnl/t_pipeline.h" +#include "drivers/common/driverfuncs.h" #define PF_B8G8R8 1 @@ -170,50 +171,6 @@ set_buffer( GLcontext *ctx, GLframebuffer *buffer, GLuint bufferBit ) } -static void -init_core_functions( GLcontext *ctx ) -{ - ctx->Driver.GetString = get_string; - ctx->Driver.UpdateState = update_state; - ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; - ctx->Driver.GetBufferSize = get_buffer_size; - - ctx->Driver.Accum = _swrast_Accum; - ctx->Driver.Bitmap = _swrast_Bitmap; - ctx->Driver.Clear = _swrast_Clear; /* would be good to optimize */ - ctx->Driver.CopyPixels = _swrast_CopyPixels; - ctx->Driver.DrawPixels = _swrast_DrawPixels; - ctx->Driver.ReadPixels = _swrast_ReadPixels; - ctx->Driver.DrawBuffer = _swrast_DrawBuffer; - - ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format; - ctx->Driver.TexImage1D = _mesa_store_teximage1d; - ctx->Driver.TexImage2D = _mesa_store_teximage2d; - ctx->Driver.TexImage3D = _mesa_store_teximage3d; - ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d; - ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d; - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; - ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; - - ctx->Driver.CompressedTexImage1D = _mesa_store_compressed_teximage1d; - ctx->Driver.CompressedTexImage2D = _mesa_store_compressed_teximage2d; - ctx->Driver.CompressedTexImage3D = _mesa_store_compressed_teximage3d; - ctx->Driver.CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d; - ctx->Driver.CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d; - ctx->Driver.CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d; - - ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; - ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; - ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; - ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; - ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; - ctx->Driver.CopyColorTable = _swrast_CopyColorTable; - ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable; - ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D; - ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D; -} - - /* * Generate code for span functions. */ @@ -669,6 +626,7 @@ glFBDevCreateContext( const GLFBDevVisualPtr visual, GLFBDevContextPtr share ) { GLFBDevContextPtr ctx; GLcontext *glctx; + struct dd_function_table functions; ASSERT(visual); @@ -676,9 +634,15 @@ glFBDevCreateContext( const GLFBDevVisualPtr visual, GLFBDevContextPtr share ) if (!ctx) return NULL; + /* build table of device driver functions */ + _mesa_init_driver_functions(&functions); + functions.GetString = get_string; + functions.UpdateState = update_state; + functions.GetBufferSize = get_buffer_size; + if (!_mesa_initialize_context(&ctx->glcontext, &visual->glvisual, share ? &share->glcontext : NULL, - (void *) ctx, GL_FALSE)) { + &functions, (void *) ctx)) { _mesa_free(ctx); return NULL; } @@ -687,7 +651,6 @@ glFBDevCreateContext( const GLFBDevVisualPtr visual, GLFBDevContextPtr share ) /* Create module contexts */ glctx = (GLcontext *) &ctx->glcontext; - init_core_functions( glctx ); _swrast_CreateContext( glctx ); _ac_CreateContext( glctx ); _tnl_CreateContext( glctx ); diff --git a/src/mesa/drivers/glide/fxapi.c b/src/mesa/drivers/glide/fxapi.c index 6ed9453c9b..75629cbd3f 100644 --- a/src/mesa/drivers/glide/fxapi.c +++ b/src/mesa/drivers/glide/fxapi.c @@ -257,6 +257,7 @@ fxMesaCreateContext(GLuint win, { fxMesaContext fxMesa = NULL; GLcontext *ctx = NULL, *shareCtx = NULL; + struct dd_function_table functions; int i; const char *str; @@ -651,9 +652,10 @@ fxMesaCreateContext(GLuint win, goto errorhandler; } - ctx = fxMesa->glCtx = _mesa_create_context(fxMesa->glVis, - shareCtx, - (void *) fxMesa, GL_TRUE); + _mesa_init_driver_functions(&functions); + ctx->Driver. + ctx = fxMesa->glCtx = _mesa_create_context(fxMesa->glVis, shareCtx, + &functions, (void *) fxMesa); if (!ctx) { str = "_mesa_create_context"; goto errorhandler; diff --git a/src/mesa/drivers/glide/fxddtex.c b/src/mesa/drivers/glide/fxddtex.c index eaca8401b8..9081f470dd 100644 --- a/src/mesa/drivers/glide/fxddtex.c +++ b/src/mesa/drivers/glide/fxddtex.c @@ -90,9 +90,8 @@ static void fxTexInvalidate(GLcontext * ctx, struct gl_texture_object *tObj) { fxMesaContext fxMesa = FX_CONTEXT(ctx); - tfxTexInfo *ti; - - ti = fxTMGetTexInfo(tObj); + tfxTexInfo *ti = fxTMGetTexInfo(tObj); + assert(ti); if (ti->isInTM) fxTMMoveOutTM(fxMesa, tObj); /* TO DO: SLOW but easy to write */ @@ -100,37 +99,6 @@ fxTexInvalidate(GLcontext * ctx, struct gl_texture_object *tObj) fxMesa->new_state |= FX_NEW_TEXTURING; } -static tfxTexInfo * -fxAllocTexObjData(fxMesaContext fxMesa) -{ - tfxTexInfo *ti; - - if (!(ti = CALLOC(sizeof(tfxTexInfo)))) { - fprintf(stderr, "fxAllocTexObjData: ERROR: out of memory !\n"); - fxCloseHardware(); - exit(-1); - } - - ti->validated = GL_FALSE; - ti->isInTM = GL_FALSE; - - ti->whichTMU = FX_TMU_NONE; - - ti->tm[FX_TMU0] = NULL; - ti->tm[FX_TMU1] = NULL; - - ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED; - ti->maxFilt = GR_TEXTUREFILTER_BILINEAR; - - ti->sClamp = GR_TEXTURECLAMP_WRAP; - ti->tClamp = GR_TEXTURECLAMP_WRAP; - - ti->mmMode = GR_MIPMAP_NEAREST; - ti->LODblend = FXFALSE; - - return ti; -} - void fxDDTexBind(GLcontext * ctx, GLenum target, struct gl_texture_object *tObj) { @@ -144,11 +112,8 @@ fxDDTexBind(GLcontext * ctx, GLenum target, struct gl_texture_object *tObj) if (target != GL_TEXTURE_2D) return; - if (!tObj->DriverData) { - tObj->DriverData = fxAllocTexObjData(fxMesa); - } - ti = fxTMGetTexInfo(tObj); + assert(ti); fxMesa->texBindNumber++; ti->lastTimeUsed = fxMesa->texBindNumber; @@ -200,13 +165,10 @@ fxDDTexParam(GLcontext * ctx, GLenum target, struct gl_texture_object *tObj, if (target != GL_TEXTURE_2D) return; - if (!tObj->DriverData) - tObj->DriverData = fxAllocTexObjData(fxMesa); - ti = fxTMGetTexInfo(tObj); + assert(ti); switch (pname) { - case GL_TEXTURE_MIN_FILTER: switch (param) { case GL_NEAREST: @@ -359,8 +321,7 @@ fxDDTexDel(GLcontext * ctx, struct gl_texture_object *tObj) fprintf(stderr, "fxDDTexDel(%d, %p)\n", tObj->Name, (void *) ti); } - if (!ti) - return; + assert(ti); fxTMFreeTexture(fxMesa, tObj); @@ -371,14 +332,60 @@ fxDDTexDel(GLcontext * ctx, struct gl_texture_object *tObj) _mesa_delete_texture_object(ctx, tObj); } + +/** + * Allocate a new texture object. + * Called via ctx->Driver.NewTextureObject. + * Note: this function will be called during context creation to + * allocate the default texture objects. + */ +struct gl_texture_object * +fxDDNewTextureObject( GLcontext *ctx, GLuint name, GLenum target ) +{ + struct gl_texture_object *obj; + fxTexInfo *ti; + + obj = _mesa_new_texture_object(ctx, name, target); + if (!obj) + return NULL; + + ti = CALLOC(sizeof(tfxTexInfo)); + if (!ti) { + _mesa_delete_texture_object(ctx, obj); + return NULL; + } + + ti->validated = GL_FALSE; + ti->isInTM = GL_FALSE; + + ti->whichTMU = FX_TMU_NONE; + + ti->tm[FX_TMU0] = NULL; + ti->tm[FX_TMU1] = NULL; + + ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED; + ti->maxFilt = GR_TEXTUREFILTER_BILINEAR; + + ti->sClamp = GR_TEXTURECLAMP_WRAP; + ti->tClamp = GR_TEXTURECLAMP_WRAP; + + ti->mmMode = GR_MIPMAP_NEAREST; + ti->LODblend = FXFALSE; + + obj->DriverData = ti; + + return obj; +} + + /* * Return true if texture is resident, false otherwise. */ GLboolean fxDDIsTextureResident(GLcontext *ctx, struct gl_texture_object *tObj) { - tfxTexInfo *ti = fxTMGetTexInfo(tObj); - return (ti && ti->isInTM); + tfxTexInfo *ti = fxTMGetTexInfo(tObj); + return (ti && ti->isInTM); } @@ -464,9 +471,8 @@ fxDDTexPalette(GLcontext * ctx, struct gl_texture_object *tObj) fprintf(stderr, "fxDDTexPalette(%d, %x)\n", tObj->Name, (GLuint) tObj->DriverData); } - if (!tObj->DriverData) - tObj->DriverData = fxAllocTexObjData(fxMesa); ti = fxTMGetTexInfo(tObj); + assert(ti); ti->paltype = convertPalette(fxMesa, ti->palette.data, &tObj->Palette); fxTexInvalidate(ctx, tObj); } @@ -501,10 +507,7 @@ fxDDTexUseGlbPalette(GLcontext * ctx, GLboolean state) if ((ctx->Texture.Unit[0]._Current == ctx->Texture.Unit[0].Current2D) && (ctx->Texture.Unit[0]._Current != NULL)) { struct gl_texture_object *tObj = ctx->Texture.Unit[0]._Current; - - if (!tObj->DriverData) - tObj->DriverData = fxAllocTexObjData(fxMesa); - + assert(tObj->DriverData); fxTexInvalidate(ctx, tObj); } } @@ -1218,14 +1221,8 @@ fxDDTexImage2D(GLcontext * ctx, GLenum target, GLint level, return; } - if (!texObj->DriverData) { - texObj->DriverData = fxAllocTexObjData(fxMesa); - if (!texObj->DriverData) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); - return; - } - } ti = fxTMGetTexInfo(texObj); + assert(ti); if (!texImage->DriverData) { texImage->DriverData = CALLOC(sizeof(tfxMipMapLevel)); @@ -1423,11 +1420,6 @@ fxDDTexSubImage2D(GLcontext * ctx, GLenum target, GLint level, fprintf(stderr, "fxDDTexSubImage2D: id=%d\n", texObj->Name); } - if (!texObj->DriverData) { - _mesa_problem(ctx, "problem in fxDDTexSubImage2D"); - return; - } - ti = fxTMGetTexInfo(texObj); assert(ti); mml = FX_MIPMAP_DATA(texImage); @@ -1520,14 +1512,8 @@ fxDDCompressedTexImage2D (GLcontext *ctx, GLenum target, return; } - if (!texObj->DriverData) { - texObj->DriverData = fxAllocTexObjData(fxMesa); - if (!texObj->DriverData) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D"); - return; - } - } ti = fxTMGetTexInfo(texObj); + assert(ti); if (!texImage->DriverData) { texImage->DriverData = CALLOC(sizeof(tfxMipMapLevel)); diff --git a/src/mesa/drivers/glide/fxdrv.h b/src/mesa/drivers/glide/fxdrv.h index e6320441d0..ff9e02b3eb 100644 --- a/src/mesa/drivers/glide/fxdrv.h +++ b/src/mesa/drivers/glide/fxdrv.h @@ -59,6 +59,8 @@ #include "math/m_vector.h" +#include "drivers/common/driverfuncs.h" + /* Define some shorter names for these things. */ @@ -611,6 +613,7 @@ extern void fxDDTexEnv(GLcontext *, GLenum, GLenum, const GLfloat *); extern void fxDDTexParam(GLcontext *, GLenum, struct gl_texture_object *, GLenum, const GLfloat *); extern void fxDDTexBind(GLcontext *, GLenum, struct gl_texture_object *); +extern struct gl_texture_object *fxDDNewTextureObject( GLcontext *ctx, GLuint name, GLenum target ); extern void fxDDTexDel(GLcontext *, struct gl_texture_object *); extern GLboolean fxDDIsTextureResident(GLcontext *, struct gl_texture_object *); extern void fxDDTexPalette(GLcontext *, struct gl_texture_object *); diff --git a/src/mesa/drivers/osmesa/osmesa.c b/src/mesa/drivers/osmesa/osmesa.c index 67d72446b8..8faf143372 100644 --- a/src/mesa/drivers/osmesa/osmesa.c +++ b/src/mesa/drivers/osmesa/osmesa.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 5.1 + * Version: 6.1 * - * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -59,6 +59,7 @@ #include "tnl/tnl.h" #include "tnl/t_context.h" #include "tnl/t_pipeline.h" +#include "drivers/common/driverfuncs.h" @@ -629,6 +630,7 @@ osmesa_choose_line( GLcontext *ctx ) _NEW_RENDERMODE | \ _SWRAST_NEW_RASTERMASK) + /* one-time, per-context initialization */ static void hook_in_driver_functions( GLcontext *ctx ) @@ -643,45 +645,6 @@ hook_in_driver_functions( GLcontext *ctx ) /* use default TCL pipeline */ tnl->Driver.RunPipeline = _tnl_run_pipeline; - ctx->Driver.GetString = get_string; - ctx->Driver.UpdateState = osmesa_update_state; - ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; - ctx->Driver.GetBufferSize = get_buffer_size; - - ctx->Driver.Accum = _swrast_Accum; - ctx->Driver.Bitmap = _swrast_Bitmap; - ctx->Driver.Clear = clear; /* uses _swrast_Clear */ - ctx->Driver.CopyPixels = _swrast_CopyPixels; - ctx->Driver.DrawPixels = _swrast_DrawPixels; - ctx->Driver.ReadPixels = _swrast_ReadPixels; - ctx->Driver.DrawBuffer = _swrast_DrawBuffer; - - ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format; - ctx->Driver.TexImage1D = _mesa_store_teximage1d; - ctx->Driver.TexImage2D = _mesa_store_teximage2d; - ctx->Driver.TexImage3D = _mesa_store_teximage3d; - ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d; - ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d; - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; - ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; - - ctx->Driver.CompressedTexImage1D = _mesa_store_compressed_teximage1d; - ctx->Driver.CompressedTexImage2D = _mesa_store_compressed_teximage2d; - ctx->Driver.CompressedTexImage3D = _mesa_store_compressed_teximage3d; - ctx->Driver.CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d; - ctx->Driver.CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d; - ctx->Driver.CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d; - - ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; - ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; - ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; - ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; - ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; - ctx->Driver.CopyColorTable = _swrast_CopyColorTable; - ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable; - ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D; - ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D; - swdd->SetBuffer = set_buffer; /* RGB(A) span/pixel functions */ @@ -800,6 +763,7 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, OSMesaContext sharelist ) { OSMesaContext osmesa; + struct dd_function_table functions; GLint rshift, gshift, bshift, ashift; GLint rind, gind, bind, aind; GLint indexBits = 0, redBits = 0, greenBits = 0, blueBits = 0, alphaBits =0; @@ -961,20 +925,19 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits, return NULL; } - /* Setup these pointers here since they're using for making the default - * and proxy texture objects. Actually, we don't really need to do - * this since we're using the default fallback functions which - * _mesa_initialize_context() would plug in if needed. - */ - osmesa->mesa.Driver.NewTextureObject = _mesa_new_texture_object; - osmesa->mesa.Driver.DeleteTexture = _mesa_delete_texture_object; + /* Initialize device driver function table */ + _mesa_init_driver_functions(&functions); + /* override with our functions */ + functions.GetString = get_string; + functions.UpdateState = osmesa_update_state; + functions.GetBufferSize = get_buffer_size; + functions.Clear = clear; if (!_mesa_initialize_context(&osmesa->mesa, osmesa->gl_visual, sharelist ? &sharelist->mesa : (GLcontext *) NULL, - (void *) osmesa, - GL_FALSE)) { + &functions, (void *) osmesa)) { _mesa_destroy_visual( osmesa->gl_visual ); FREE(osmesa); return NULL; diff --git a/src/mesa/drivers/windows/gdi/wmesa.c b/src/mesa/drivers/windows/gdi/wmesa.c index 74c6caab69..4627354626 100644 --- a/src/mesa/drivers/windows/gdi/wmesa.c +++ b/src/mesa/drivers/windows/gdi/wmesa.c @@ -53,6 +53,7 @@ #include "tnl/tnl.h" #include "tnl/t_context.h" #include "tnl/t_pipeline.h" +#include "drivers/common/driverfuncs.h" /* Dither not tested for Mesa 4.0 */ #ifdef DITHER @@ -1031,54 +1032,25 @@ static const GLubyte *get_string(GLcontext *ctx, GLenum name) static void wmesa_update_state( GLcontext *ctx, GLuint new_state ); -static void SetFunctionPointers(GLcontext *ctx) +static void SetFunctionPointers( struct dd_function_table *functions ) { - struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference( ctx ); - ctx->Driver.GetString = get_string; - ctx->Driver.UpdateState = wmesa_update_state; - ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; - ctx->Driver.GetBufferSize = buffer_size; - - ctx->Driver.Accum = _swrast_Accum; - ctx->Driver.Bitmap = _swrast_Bitmap; - ctx->Driver.Clear = clear; - - ctx->Driver.Flush = flush; - ctx->Driver.ClearIndex = clear_index; - ctx->Driver.ClearColor = clear_color; - ctx->Driver.Enable = enable; + functions->GetString = get_string; + functions->UpdateState = wmesa_update_state; + functions->ResizeBuffers = _swrast_alloc_buffers; + functions->GetBufferSize = buffer_size; - ctx->Driver.CopyPixels = _swrast_CopyPixels; - ctx->Driver.DrawPixels = _swrast_DrawPixels; - ctx->Driver.ReadPixels = _swrast_ReadPixels; - ctx->Driver.DrawBuffer = _swrast_DrawBuffer; + functions->Clear = clear; - ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format; - ctx->Driver.TexImage1D = _mesa_store_teximage1d; - ctx->Driver.TexImage2D = _mesa_store_teximage2d; - ctx->Driver.TexImage3D = _mesa_store_teximage3d; - ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d; - ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d; - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; - ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; - - ctx->Driver.CompressedTexImage1D = _mesa_store_compressed_teximage1d; - ctx->Driver.CompressedTexImage2D = _mesa_store_compressed_teximage2d; - ctx->Driver.CompressedTexImage3D = _mesa_store_compressed_teximage3d; - ctx->Driver.CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d; - ctx->Driver.CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d; - ctx->Driver.CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d; + functions->Flush = flush; + functions->ClearIndex = clear_index; + functions->ClearColor = clear_color; + functions->Enable = enable; +} - ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; - ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; - ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; - ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; - ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; - ctx->Driver.CopyColorTable = _swrast_CopyColorTable; - ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable; - ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D; - ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D; +static void SetSWrastPointers(GLcontext *ctx) +{ + struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference( ctx ); swdd->SetBuffer = set_buffer; /* Pixel/span writing functions: */ @@ -1097,8 +1069,8 @@ static void SetFunctionPointers(GLcontext *ctx) swdd->ReadRGBASpan = read_rgba_span; swdd->ReadCI32Pixels = read_ci32_pixels; swdd->ReadRGBAPixels = read_rgba_pixels; - } + static void wmesa_update_state( GLcontext *ctx, GLuint new_state ) { @@ -1112,7 +1084,8 @@ static void wmesa_update_state( GLcontext *ctx, GLuint new_state ) * would be good to minimize setting all this when not needed. */ #ifndef SET_FPOINTERS_ONCE - SetFunctionPointers(ctx); + SetFunctionPointers(&ctx->Driver); + SetSWrastPointers(ctx); #if 0 ctx->Driver.GetString = get_string; ctx->Driver.UpdateState = wmesa_update_state; @@ -1262,6 +1235,7 @@ WMesaContext WMesaCreateContext( HWND hWnd, HPALETTE* Pal, RECT CR; WMesaContext c; GLboolean true_color_flag; + struct dd_function_table functions; c = (struct wmesa_context * ) calloc(1,sizeof(struct wmesa_context)); if (!c) @@ -1348,9 +1322,13 @@ WMesaContext WMesaCreateContext( HWND hWnd, HPALETTE* Pal, if (!c->gl_visual) { return NULL; } + + _mesa_init_driver_functions(&functions); + SetFunctionPointers(&functions); /* allocate a new Mesa context */ - c->gl_ctx = _mesa_create_context( c->gl_visual, NULL, (void *) c, GL_FALSE ); + c->gl_ctx = _mesa_create_context( c->gl_visual, NULL, + &functions, (void *) c ); if (!c->gl_ctx) { _mesa_destroy_visual( c->gl_visual ); @@ -1384,7 +1362,8 @@ WMesaContext WMesaCreateContext( HWND hWnd, HPALETTE* Pal, _swsetup_CreateContext( ctx ); #ifdef SET_FPOINTERS_ONCE - SetFunctionPointers(ctx); + /*SetFunctionPointers(ctx);*/ + SetSWrastPointers(ctx); #endif // SET_FPOINTERS_ONCE _swsetup_Wakeup( ctx ); } diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c index f25c3e3bc6..9a852d9e4c 100644 --- a/src/mesa/drivers/x11/xm_api.c +++ b/src/mesa/drivers/x11/xm_api.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 5.1 + * Version: 6.1 * - * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -77,6 +77,10 @@ #include "swrast_setup/swrast_setup.h" #include "array_cache/acache.h" #include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" +#include "drivers/common/driverfuncs.h" + #ifndef GLX_NONE_EXT #define GLX_NONE_EXT 0x8000 @@ -1583,43 +1587,39 @@ void XMesaDestroyVisual( XMesaVisual v ) -/* +/** * Create a new XMesaContext. - * Input: v - XMesaVisual - * share_list - another XMesaContext with which to share display - * lists or NULL if no sharing is wanted. - * Return: an XMesaContext or NULL if error. + * \param v the XMesaVisual + * \param share_list another XMesaContext with which to share display + * lists or NULL if no sharing is wanted. + * \return an XMesaContext or NULL if error. */ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) { static GLboolean firstTime = GL_TRUE; XMesaContext c; - GLboolean direct = GL_TRUE; /* not really */ GLcontext *mesaCtx; + struct dd_function_table functions; + TNLcontext *tnl; if (firstTime) { _glthread_INIT_MUTEX(_xmesa_lock); firstTime = GL_FALSE; } + /* Note: the XMesaContext contains a Mesa GLcontext struct (inheritance) */ c = (XMesaContext) CALLOC_STRUCT(xmesa_context); - if (!c) { + if (!c) return NULL; - } mesaCtx = &(c->mesa); - /* Setup these pointers here since they're using for making the default - * and proxy texture objects. Actually, we don't really need to do - * this since we're using the default fallback functions which - * _mesa_initialize_context() would plug in if needed. - */ - mesaCtx->Driver.NewTextureObject = _mesa_new_texture_object; - mesaCtx->Driver.DeleteTexture = _mesa_delete_texture_object; - + /* initialize with default driver functions, then plug in XMesa funcs */ + _mesa_init_driver_functions(&functions); + xmesa_init_driver_functions(v, &functions); if (!_mesa_initialize_context(mesaCtx, &v->mesa_visual, share_list ? &(share_list->mesa) : (GLcontext *) NULL, - (void *) c, direct)) { + &functions, (void *) c)) { FREE(c); return NULL; } @@ -1629,13 +1629,8 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) _mesa_enable_1_4_extensions(mesaCtx); _mesa_enable_1_5_extensions(mesaCtx); - if (CHECK_BYTE_ORDER(v)) { - c->swapbytes = GL_FALSE; - } - else { - c->swapbytes = GL_TRUE; - } - + /* finish up xmesa context initializations */ + c->swapbytes = CHECK_BYTE_ORDER(v) ? GL_FALSE : GL_TRUE; c->xm_visual = v; c->xm_draw_buffer = NULL; /* set later by XMesaMakeCurrent */ c->xm_read_buffer = NULL; /* set later by XMesaMakeCurrent */ @@ -1643,8 +1638,6 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) c->display = v->display; c->pixelformat = v->dithered_pf; /* Dithering is enabled by default */ - mesaCtx->Driver.UpdateState = xmesa_update_state; - /* Initialize the software rasterizer and helper modules. */ _swrast_CreateContext( mesaCtx ); @@ -1652,18 +1645,18 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) _tnl_CreateContext( mesaCtx ); _swsetup_CreateContext( mesaCtx ); + /* tnl setup */ + tnl = TNL_CONTEXT(mesaCtx); + tnl->Driver.RunPipeline = _tnl_run_pipeline; + /* swrast setup */ xmesa_register_swrast_functions( mesaCtx ); - - /* Set up some constant pointers: - */ - xmesa_init_pointers( mesaCtx ); + _swsetup_Wakeup(mesaCtx); return c; } - void XMesaDestroyContext( XMesaContext c ) { GLcontext *mesaCtx = &c->mesa; diff --git a/src/mesa/drivers/x11/xm_dd.c b/src/mesa/drivers/x11/xm_dd.c index 8dd7f9f90a..9f4302b188 100644 --- a/src/mesa/drivers/x11/xm_dd.c +++ b/src/mesa/drivers/x11/xm_dd.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 5.1 + * Version: 6.1 * - * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -47,7 +47,6 @@ #include "swrast_setup/swrast_setup.h" #include "tnl/tnl.h" #include "tnl/t_context.h" -#include "tnl/t_pipeline.h" /* @@ -114,8 +113,8 @@ finish_or_flush( GLcontext *ctx ) * This chooses the color buffer for reading and writing spans, points, * lines, and triangles. */ -static void -set_buffer( GLcontext *ctx, GLframebuffer *buffer, GLuint bufferBit ) +void +xmesa_set_buffer( GLcontext *ctx, GLframebuffer *buffer, GLuint bufferBit ) { /* We can make this cast since the XMesaBuffer wraps GLframebuffer. * GLframebuffer is the first member in a XMesaBuffer struct. @@ -1099,102 +1098,39 @@ test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level, } - - -/* Setup pointers and other driver state that is constant for the life - * of a context. +/** + * Initialize the device driver function table with the functions + * we implement in this driver. */ -void xmesa_init_pointers( GLcontext *ctx ) +void xmesa_init_driver_functions( XMesaVisual xmvisual, + struct dd_function_table *driver ) { - TNLcontext *tnl; - struct swrast_device_driver *dd = _swrast_GetDeviceDriverReference( ctx ); - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - - /* Plug in our driver-specific functions here */ - ctx->Driver.GetString = get_string; - ctx->Driver.GetBufferSize = get_buffer_size; - ctx->Driver.Flush = finish_or_flush; - ctx->Driver.Finish = finish_or_flush; - ctx->Driver.ClearIndex = clear_index; - ctx->Driver.ClearColor = clear_color; - ctx->Driver.IndexMask = index_mask; - ctx->Driver.ColorMask = color_mask; - ctx->Driver.Enable = enable; - - /* Software rasterizer pixel paths: - */ - ctx->Driver.Accum = _swrast_Accum; - ctx->Driver.Bitmap = _swrast_Bitmap; - ctx->Driver.Clear = clear_buffers; - ctx->Driver.ResizeBuffers = xmesa_resize_buffers; -#ifdef XFree86Server - ctx->Driver.DrawPixels = _swrast_DrawPixels; - ctx->Driver.CopyPixels = _swrast_CopyPixels; -#else - ctx->Driver.CopyPixels = /*_swrast_CopyPixels;*/xmesa_CopyPixels; - if (xmesa->xm_visual->undithered_pf == PF_8R8G8B && - xmesa->xm_visual->dithered_pf == PF_8R8G8B) { - ctx->Driver.DrawPixels = xmesa_DrawPixels_8R8G8B; - } - else if (xmesa->xm_visual->undithered_pf == PF_5R6G5B) { - ctx->Driver.DrawPixels = xmesa_DrawPixels_5R6G5B; + driver->GetString = get_string; + driver->UpdateState = xmesa_update_state; + driver->GetBufferSize = get_buffer_size; + driver->Flush = finish_or_flush; + driver->Finish = finish_or_flush; + driver->ClearIndex = clear_index; + driver->ClearColor = clear_color; + driver->IndexMask = index_mask; + driver->ColorMask = color_mask; + driver->Enable = enable; + driver->Clear = clear_buffers; + driver->ResizeBuffers = xmesa_resize_buffers; +#ifndef XFree86Server + driver->CopyPixels = /*_swrast_CopyPixels;*/xmesa_CopyPixels; + if (xmvisual->undithered_pf == PF_8R8G8B && + xmvisual->dithered_pf == PF_8R8G8B) { + driver->DrawPixels = xmesa_DrawPixels_8R8G8B; } - else { - ctx->Driver.DrawPixels = _swrast_DrawPixels; + else if (xmvisual->undithered_pf == PF_5R6G5B) { + driver->DrawPixels = xmesa_DrawPixels_5R6G5B; } #endif - ctx->Driver.ReadPixels = _swrast_ReadPixels; - ctx->Driver.DrawBuffer = _swrast_DrawBuffer; - - /* Software texture functions: - */ - ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format; - ctx->Driver.TexImage1D = _mesa_store_teximage1d; - ctx->Driver.TexImage2D = _mesa_store_teximage2d; - ctx->Driver.TexImage3D = _mesa_store_teximage3d; - ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d; - ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d; - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; - ctx->Driver.TestProxyTexImage = test_proxy_teximage; - - ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; - ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; - ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; - ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; - ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; - - ctx->Driver.CompressedTexImage1D = _mesa_store_compressed_teximage1d; - ctx->Driver.CompressedTexImage2D = _mesa_store_compressed_teximage2d; - ctx->Driver.CompressedTexImage3D = _mesa_store_compressed_teximage3d; - ctx->Driver.CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d; - ctx->Driver.CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d; - ctx->Driver.CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d; - - /* Swrast hooks for imaging extensions: - */ - ctx->Driver.CopyColorTable = _swrast_CopyColorTable; - ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable; - ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D; - ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D; - - /* Initialize the TNL driver interface: - */ - tnl = TNL_CONTEXT(ctx); - tnl->Driver.RunPipeline = _tnl_run_pipeline; - - dd->SetBuffer = set_buffer; - - /* Install swsetup for tnl->Driver.Render.*: - */ - _swsetup_Wakeup(ctx); - - (void) DitherValues; /* silenced unused var warning */ + driver->TestProxyTexImage = test_proxy_teximage; } - - - #define XMESA_NEW_POINT (_NEW_POINT | \ _NEW_RENDERMODE | \ _SWRAST_NEW_RASTERMASK) @@ -1220,6 +1156,9 @@ void xmesa_init_pointers( GLcontext *ctx ) void xmesa_register_swrast_functions( GLcontext *ctx ) { SWcontext *swrast = SWRAST_CONTEXT( ctx ); + struct swrast_device_driver *dd = _swrast_GetDeviceDriverReference(ctx); + + dd->SetBuffer = xmesa_set_buffer; swrast->choose_point = xmesa_choose_point; swrast->choose_line = xmesa_choose_line; diff --git a/src/mesa/drivers/x11/xmesaP.h b/src/mesa/drivers/x11/xmesaP.h index 36a610a4f9..ee1f4add1a 100644 --- a/src/mesa/drivers/x11/xmesaP.h +++ b/src/mesa/drivers/x11/xmesaP.h @@ -1,9 +1,8 @@ - /* * Mesa 3-D graphics library - * Version: 5.0.1 + * Version: 6.1 * - * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -513,11 +512,15 @@ xmesa_color_to_pixel( XMesaContext xmesa, extern void xmesa_alloc_back_buffer( XMesaBuffer b ); -extern void xmesa_init_pointers( GLcontext *ctx ); +extern void xmesa_init_driver_functions( XMesaVisual xmvisual, + struct dd_function_table *driver ); extern void xmesa_update_state( GLcontext *ctx, GLuint new_state ); extern void xmesa_update_span_funcs( GLcontext *ctx ); +extern void xmesa_set_buffer( GLcontext *ctx, GLframebuffer *buffer, + GLuint bufferBit ); + /* Plugged into the software rasterizer. Try to use internal * swrast-style point, line and triangle functions. */ diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index 0f70829ff4..2545718343 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -347,18 +347,6 @@ _mesa_init_buffer_objects( GLcontext *ctx ) for (i = 0; i < VERT_ATTRIB_MAX; i++) { ctx->Array.VertexAttrib[i].BufferObj = ctx->Array.NullBufferObj; } - - /* Device drivers might override these assignments after the Mesa - * context is initialized. - */ - ctx->Driver.NewBufferObject = _mesa_new_buffer_object; - ctx->Driver.DeleteBuffer = _mesa_delete_buffer_object; - ctx->Driver.BindBuffer = NULL; - ctx->Driver.BufferData = _mesa_buffer_data; - ctx->Driver.BufferSubData = _mesa_buffer_subdata; - ctx->Driver.GetBufferSubData = _mesa_buffer_get_subdata; - ctx->Driver.MapBuffer = _mesa_buffer_map; - ctx->Driver.UnmapBuffer = NULL; } diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index e554f7508e..b2ab491610 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -387,7 +387,8 @@ __glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes) return NULL; } - _mesa_initialize_context(ctx, modes, NULL, imports, GL_FALSE); + /* XXX doesn't work at this time */ + _mesa_initialize_context(ctx, modes, NULL, NULL, NULL); ctx->imports = *imports; return ctx; @@ -858,14 +859,6 @@ alloc_shared_state( GLcontext *ctx ) if (!ss->DefaultRect) goto cleanup; -#if 0 - _mesa_save_texture_object(ctx, ss->Default1D); - _mesa_save_texture_object(ctx, ss->Default2D); - _mesa_save_texture_object(ctx, ss->Default3D); - _mesa_save_texture_object(ctx, ss->DefaultCubeMap); - _mesa_save_texture_object(ctx, ss->DefaultRect); -#endif - /* Effectively bind the default textures to all texture units */ ss->Default1D->RefCount += MAX_TEXTURE_IMAGE_UNITS; ss->Default2D->RefCount += MAX_TEXTURE_IMAGE_UNITS; @@ -1335,12 +1328,15 @@ add_newer_entrypoints(void) /** - * Initialize a GLcontext struct. + * Initialize a GLcontext struct (rendering context). * * This includes allocating all the other structs and arrays which hang off of * the context by pointers. + * Note that the driver needs to pass in its dd_function_table here since + * we need to at least call driverFunctions->NewTextureObject to create the + * default texture objects. * - * \sa _mesa_create_context() for the parameter description. + * Called by _mesa_create_context(). * * Performs the imports and exports callback tables initialization, and * miscellaneous one-time initializations. If no shared context is supplied one @@ -1349,23 +1345,30 @@ add_newer_entrypoints(void) * Finally queries the \c MESA_DEBUG and \c MESA_VERBOSE environment variables * for debug flags. * - * \note the direct parameter is ignored (obsolete). + * \param ctx the context to initialize + * \param visual describes the visual attributes for this context + * \param share_list points to context to share textures, display lists, + * etc with, or NULL + * \param driverFunctions table of device driver functions for this context + * to use + * \param driverContext pointer to driver-specific context data */ GLboolean _mesa_initialize_context( GLcontext *ctx, const GLvisual *visual, GLcontext *share_list, - void *driver_ctx, - GLboolean direct ) + const struct dd_function_table *driverFunctions, + void *driverContext ) { GLuint dispatchSize; - ASSERT(driver_ctx); + ASSERT(driverContext); + assert(driverFunctions->NewTextureObject); /* If the driver wants core Mesa to use special imports, it'll have to * override these defaults. */ - _mesa_init_default_imports( &(ctx->imports), driver_ctx ); + _mesa_init_default_imports( &(ctx->imports), driverContext ); /* initialize the exports (Mesa functions called by the window system) */ _mesa_init_default_exports( &(ctx->exports) ); @@ -1373,20 +1376,17 @@ _mesa_initialize_context( GLcontext *ctx, /* misc one-time initializations */ one_time_init(ctx); - ctx->DriverCtx = driver_ctx; ctx->Visual = *visual; ctx->DrawBuffer = NULL; ctx->ReadBuffer = NULL; - /* Set these pointers to defaults now in case they're not set since - * we need them while creating the default textures. + /* Plug in driver functions and context pointer here. + * This is important because when we call alloc_shared_state() below + * we'll call ctx->Driver.NewTextureObject() to create the default + * textures. */ - if (!ctx->Driver.NewTextureObject) - ctx->Driver.NewTextureObject = _mesa_new_texture_object; - if (!ctx->Driver.DeleteTexture) - ctx->Driver.DeleteTexture = _mesa_delete_texture_object; - if (!ctx->Driver.NewTextureImage) - ctx->Driver.NewTextureImage = _mesa_new_texture_image; + ctx->Driver = *driverFunctions; + ctx->DriverCtx = driverContext; if (share_list) { /* share state with another context */ @@ -1443,33 +1443,39 @@ _mesa_initialize_context( GLcontext *ctx, return GL_TRUE; } + /** * Allocate and initialize a GLcontext structure. + * Note that the driver needs to pass in its dd_function_table here since + * we need to at least call driverFunctions->NewTextureObject to initialize + * the rendering context. * * \param visual a GLvisual pointer (we copy the struct contents) * \param share_list another context to share display lists with or NULL - * \param driver_ctx pointer to device driver's context state struct - * \param direct obsolete, ignored + * \param driverFunctions points to the dd_function_table into which the + * driver has plugged in all its special functions. + * \param driverCtx points to the device driver's private context state * * \return pointer to a new __GLcontextRec or NULL if error. */ GLcontext * _mesa_create_context( const GLvisual *visual, GLcontext *share_list, - void *driver_ctx, - GLboolean direct ) + const struct dd_function_table *driverFunctions, + void *driverContext ) { GLcontext *ctx; ASSERT(visual); - ASSERT(driver_ctx); + ASSERT(driverContext); ctx = (GLcontext *) _mesa_calloc(sizeof(GLcontext)); if (!ctx) return NULL; - if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) { + if (_mesa_initialize_context(ctx, visual, share_list, + driverFunctions, driverContext)) { return ctx; } else { @@ -1478,6 +1484,7 @@ _mesa_create_context( const GLvisual *visual, } } + /** * Free the data associated with the given context. * @@ -1531,12 +1538,13 @@ _mesa_free_context_data( GLcontext *ctx ) FREE(ctx->Save); } + /** * Destroy a GLcontext structure. * * \param ctx GL context. * - * Calls _mesa_free_context_data() and free the structure. + * Calls _mesa_free_context_data() and frees the GLcontext structure itself. */ void _mesa_destroy_context( GLcontext *ctx ) @@ -1547,6 +1555,7 @@ _mesa_destroy_context( GLcontext *ctx ) } } + #if _HAVE_FULL_GL /** * Copy attribute groups from one context to another. diff --git a/src/mesa/main/context.h b/src/mesa/main/context.h index d6d7920bb4..e55b383dec 100644 --- a/src/mesa/main/context.h +++ b/src/mesa/main/context.h @@ -133,15 +133,15 @@ _mesa_destroy_framebuffer( GLframebuffer *buffer ); extern GLcontext * _mesa_create_context( const GLvisual *visual, GLcontext *share_list, - void *driver_ctx, - GLboolean direct ); + const struct dd_function_table *driverFunctions, + void *driverContext ); extern GLboolean _mesa_initialize_context( GLcontext *ctx, const GLvisual *visual, GLcontext *share_list, - void *driver_ctx, - GLboolean direct ); + const struct dd_function_table *driverFunctions, + void *driverContext ); extern void _mesa_free_context_data( GLcontext *ctx ); diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h index e9826abd6d..60b16db10f 100644 --- a/src/mesa/main/dd.h +++ b/src/mesa/main/dd.h @@ -58,6 +58,9 @@ struct gl_pixelstore_attrib; * * Vertex transformation/clipping/lighting is patched into the T&L module. * Rasterization functions are patched into the swrast module. + * + * Note: when new functions are added here, the drivers/common/driverfuncs.c + * file should be updated too!!! */ struct dd_function_table { /** @@ -76,36 +79,6 @@ struct dd_function_table { */ void (*UpdateState)( GLcontext *ctx, GLuint new_state ); - /** - * Clear the color/depth/stencil/accum buffer(s). - * - * \param mask a bitmask of the DD_*_BIT values defined above that indicates - * which buffers need to be cleared. - * \param all if true then clear the whole buffer, else clear only the - * region defined by (x, y, width, height). - * - * This function must obey the glColorMask(), glIndexMask() and glStencilMask() - * settings! - * Software Mesa can do masked clears if the device driver can't. - */ - void (*Clear)( GLcontext *ctx, GLbitfield mask, GLboolean all, - GLint x, GLint y, GLint width, GLint height ); - - /** - * Specify the current buffer for writing. - * - * Called via glDrawBuffer(). Note the driver must organize fallbacks (e.g. - * with swrast) if it cannot implement the requested mode. - */ - void (*DrawBuffer)( GLcontext *ctx, GLenum buffer ); - - /** - * Specifies the current buffer for reading. - * - * Called via glReadBuffer(). - */ - void (*ReadBuffer)( GLcontext *ctx, GLenum buffer ); - /** * Get the width and height of the named buffer/window. * @@ -122,6 +95,13 @@ struct dd_function_table { */ void (*ResizeBuffers)( GLframebuffer *buffer ); + /** + * Called whenever an error is generated. + * + * __GLcontextRec::ErrorValue contains the error value. + */ + void (*Error)( GLcontext *ctx ); + /** * This is called whenever glFinish() is called. */ @@ -133,11 +113,19 @@ struct dd_function_table { void (*Flush)( GLcontext *ctx ); /** - * Called whenever an error is generated. + * Clear the color/depth/stencil/accum buffer(s). * - * __GLcontextRec::ErrorValue contains the error value. + * \param mask a bitmask of the DD_*_BIT values defined above that indicates + * which buffers need to be cleared. + * \param all if true then clear the whole buffer, else clear only the + * region defined by (x, y, width, height). + * + * This function must obey the glColorMask(), glIndexMask() and + * glStencilMask() settings! + * Software Mesa can do masked clears if the device driver can't. */ - void (*Error)( GLcontext *ctx ); + void (*Clear)( GLcontext *ctx, GLbitfield mask, GLboolean all, + GLint x, GLint y, GLint width, GLint height ); /** @@ -504,24 +492,18 @@ struct dd_function_table { void (*BindTexture)( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj ); - /** - * Called when a texture object is created. - */ - void (*CreateTexture)( GLcontext *ctx, struct gl_texture_object *tObj ); - /** * Called to allocate a new texture object. - * - * \note This function pointer should be initialized by drivers \e before - * calling _mesa_initialize_context() since context initialization involves - * allocating some texture objects! + * A new gl_texture_object should be returned. The driver should + * attach to it any device-specific info it needs. */ struct gl_texture_object * (*NewTextureObject)( GLcontext *ctx, GLuint name, GLenum target ); /** * Called when a texture object is about to be deallocated. * - * Driver should free anything attached to the DriverData pointers. + * Driver should delete the gl_texture_object object and anything + * hanging off of it. */ void (*DeleteTexture)( GLcontext *ctx, struct gl_texture_object *tObj ); @@ -627,6 +609,8 @@ struct dd_function_table { void (*DepthMask)(GLcontext *ctx, GLboolean flag); /** Specify mapping of depth values from normalized device coordinates to window coordinates */ void (*DepthRange)(GLcontext *ctx, GLclampd nearval, GLclampd farval); + /** Specify the current buffer for writing */ + void (*DrawBuffer)( GLcontext *ctx, GLenum buffer ); /** Enable or disable server-side gl capabilities */ void (*Enable)(GLcontext *ctx, GLenum cap, GLboolean state); /** Specify fog parameters */ @@ -656,6 +640,8 @@ struct dd_function_table { void (*PolygonOffset)(GLcontext *ctx, GLfloat factor, GLfloat units); /** Set the polygon stippling pattern */ void (*PolygonStipple)(GLcontext *ctx, const GLubyte *mask ); + /* Specifies the current buffer for reading */ + void (*ReadBuffer)( GLcontext *ctx, GLenum buffer ); /** Set rasterization mode */ void (*RenderMode)(GLcontext *ctx, GLenum mode ); /** Define the scissor box */ @@ -708,6 +694,11 @@ struct dd_function_table { void (*EdgeFlagPointer)(GLcontext *ctx, GLsizei stride, const GLvoid *ptr); void (*VertexAttribPointer)(GLcontext *ctx, GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr); + void (*LockArraysEXT)( GLcontext *ctx, GLint first, GLsizei count ); + void (*UnlockArraysEXT)( GLcontext *ctx ); + /*@}*/ + + /*@}*/ @@ -846,6 +837,12 @@ struct dd_function_table { */ void (*LightingSpaceChange)( GLcontext *ctx ); + /** + * Let the T&L component know when the context becomes current. + */ + void (*MakeCurrent)( GLcontext *ctx, GLframebuffer *drawBuffer, + GLframebuffer *readBuffer ); + /** * Called by glNewList(). * @@ -874,22 +871,6 @@ struct dd_function_table { */ void (*EndCallList)( GLcontext *ctx ); - /** - * Let the T&L component know when the context becomes current. - */ - void (*MakeCurrent)( GLcontext *ctx, GLframebuffer *drawBuffer, - GLframebuffer *readBuffer ); - - /** - * Called by glLockArraysEXT(). - */ - void (*LockArraysEXT)( GLcontext *ctx, GLint first, GLsizei count ); - /** - * Called by UnlockArraysEXT(). - */ - void (*UnlockArraysEXT)( GLcontext *ctx ); - /*@}*/ - }; diff --git a/src/mesa/sources b/src/mesa/sources index 2cfe9034ec..11f168cc88 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -166,6 +166,9 @@ SPARC_SOURCES = \ sparc/norm.S \ sparc/xform.S +COMMON_DRIVER_SOURCES = \ + drivers/common/driverfuncs.c + X11_DRIVER_SOURCES = \ drivers/x11/glxapi.c \ drivers/x11/fakeglx.c \ -- cgit v1.2.3