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/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 +- 6 files changed, 68 insertions(+), 42 deletions(-) (limited to 'src/mesa/drivers/dri/i830') 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 ); -- cgit v1.2.3