From: Brian Paul Date: Mon, 27 Mar 2000 19:08:40 +0000 (+0000) Subject: removed tfxMipMapLevel's used and translate fields, initial teximage clean-up X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ba3d9d0ce958dfc6161de41d9423a4b9547fb35c;p=mesa.git removed tfxMipMapLevel's used and translate fields, initial teximage clean-up --- diff --git a/src/mesa/drivers/glide/fxddtex.c b/src/mesa/drivers/glide/fxddtex.c index 0b2eb10a9a5..779591addc6 100644 --- a/src/mesa/drivers/glide/fxddtex.c +++ b/src/mesa/drivers/glide/fxddtex.c @@ -50,6 +50,9 @@ #if defined(FX) #include "fxdrv.h" +#include "image.h" +#include "texutil.h" + void fxPrintTextureData(tfxTexInfo *ti) { @@ -129,7 +132,6 @@ static tfxTexInfo *fxAllocTexObjData(fxMesaContext fxMesa) ti->LODblend=FXFALSE; for(i=0;imipmapLevel[i].used=GL_FALSE; ti->mipmapLevel[i].data=NULL; } @@ -775,12 +777,14 @@ void fxTexGetFormat(GLenum glformat, GrTextureFormat_t *tfmt, GLint *ifmt) } } -static int fxIsTexSupported(GLenum target, GLint internalFormat, - const struct gl_texture_image *image) +static GLboolean fxIsTexSupported(GLenum target, GLint internalFormat, + const struct gl_texture_image *image) { if(target!=GL_TEXTURE_2D) return GL_FALSE; +#if 0 + /* mesa will have already checked this */ switch(internalFormat) { case GL_INTENSITY: case GL_INTENSITY4: @@ -841,6 +845,7 @@ static int fxIsTexSupported(GLenum target, GLint internalFormat, if(image->Height>256) return GL_FALSE; +#endif if(!fxTexGetInfo(image->Width,image->Height,NULL,NULL,NULL,NULL,NULL,NULL, NULL,NULL)) @@ -850,273 +855,116 @@ static int fxIsTexSupported(GLenum target, GLint internalFormat, } static void fxTexBuildImageMap(const struct gl_texture_image *image, - GLint internalFormat, unsigned short **dest, - GLboolean *istranslate) + GLint internalFormat, unsigned short **dest) { - unsigned short *src; - unsigned char *data; - int x,y,w,h,wscale,hscale,idx; + int w, h, wscale, hscale; + int texelSize; /* in bytes */ + MesaIntTexFormat intFormat; fxTexGetInfo(image->Width,image->Height,NULL,NULL,NULL,NULL,NULL,NULL, &wscale,&hscale); - w=image->Width*wscale; - h=image->Height*hscale; - - data=image->Data; - switch(internalFormat) { - case GL_INTENSITY: - case GL_INTENSITY4: - case GL_INTENSITY8: - case GL_INTENSITY12: - case GL_INTENSITY16: - case 1: - case GL_LUMINANCE: - case GL_LUMINANCE4: - case GL_LUMINANCE8: - case GL_LUMINANCE12: - case GL_LUMINANCE16: - case GL_ALPHA: - case GL_ALPHA4: - case GL_ALPHA8: - case GL_ALPHA12: - case GL_ALPHA16: - case GL_COLOR_INDEX: - case GL_COLOR_INDEX1_EXT: - case GL_COLOR_INDEX2_EXT: - case GL_COLOR_INDEX4_EXT: - case GL_COLOR_INDEX8_EXT: - case GL_COLOR_INDEX12_EXT: - case GL_COLOR_INDEX16_EXT: - /* Optimized for GLQuake */ - - if(wscale==hscale==1) { - (*istranslate)=GL_FALSE; - - (*dest)=(unsigned short *)data; - } else { - unsigned char *srcb; - - (*istranslate)=GL_TRUE; - - if(!(*dest)) { - if(!((*dest)=src=(unsigned short *)MALLOC(sizeof(unsigned char)*w*h))) { - fprintf(stderr,"fx Driver: out of memory !\n"); - fxCloseHardware(); - exit(-1); - } - } else - src=(*dest); - - srcb=(unsigned char *)src; - - for(y=0;yWidth * wscale; + h = image->Height * hscale; - if(wscale==hscale==1) { - int i=0; - int lenght=h*w; - unsigned short a,l; - - while(i++> 3); - } - } else { - unsigned int r,g,b; - - for(y=0;y> 3); - } - } - break; - case 4: - case GL_RGBA: - case GL_RGBA2: - case GL_RGBA4: - case GL_RGBA8: - case GL_RGB10_A2: - case GL_RGBA12: - case GL_RGBA16: - (*istranslate)=GL_TRUE; + /* convert image to internal format */ + _mesa_convert_teximage(intFormat, w, h, *dest, + image->Width, image->Height, + image->Format, GL_UNSIGNED_BYTE, + image->Data, &_mesa_native_packing); +} - if(!(*dest)) { - if(!((*dest)=src=(unsigned short *)MALLOC(sizeof(unsigned short)*w*h))) { - fprintf(stderr,"fx Driver: out of memory !\n"); - fxCloseHardware(); - exit(-1); - } - } else - src=(*dest); - - if(wscale==hscale==1) { - int i=0; - int lenght=h*w; - unsigned int r,g,b,a; - - while(i++> 4); - } - } else { - unsigned int r,g,b,a; - - for(y=0;y> 4); - } - } - break; - case GL_RGB5_A1: - (*istranslate)=GL_TRUE; - if(!(*dest)) { - if(!((*dest)=src=(unsigned short *)malloc(sizeof(unsigned short)*w*h))) { - fprintf(stderr,"fx Driver: out of memory !\n"); - fxCloseHardware(); - exit(-1); - } - } else - src=(*dest); - - if(wscale==hscale==1) { - int i=0; - int lenght=h*w; - unsigned r,g,b,a; - - while(i++> 3); - } - } else { - unsigned r,g,b,a; - - for(y=0;y> 3); - } - } - break; - default: - fprintf(stderr,"fx Driver: wrong internalFormat in texbuildimagemap()\n"); - fxCloseHardware(); - exit(-1); - break; - } -} void fxDDTexImg(GLcontext *ctx, GLenum target, - struct gl_texture_object *tObj, GLint level, GLint internalFormat, + struct gl_texture_object *tObj, GLint level, + GLint internalFormat, const struct gl_texture_image *image) { fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; @@ -1129,59 +977,55 @@ void fxDDTexImg(GLcontext *ctx, GLenum target, image->Height); } - if(target!=GL_TEXTURE_2D) + if (target!=GL_TEXTURE_2D) return; if (!tObj->DriverData) tObj->DriverData=fxAllocTexObjData(fxMesa); - ti=fxTMGetTexInfo(tObj); + ti = fxTMGetTexInfo(tObj); - if(fxIsTexSupported(target,internalFormat,image)) { + if (fxIsTexSupported(target,internalFormat,image)) { GrTextureFormat_t gldformat; - tfxMipMapLevel *mml=&ti->mipmapLevel[level]; + tfxMipMapLevel *mml = &ti->mipmapLevel[level]; - fxTexGetFormat(internalFormat,&gldformat,NULL); + fxTexGetFormat(internalFormat, &gldformat, NULL); - if(mml->used) { - if((mml->glideFormat==gldformat) && - (mml->width==image->Width) && - (mml->height==image->Height)) { - fxTexBuildImageMap(image,internalFormat,&(mml->data), - &(mml->translated)); - - if(ti->validated && ti->isInTM) - fxTMReloadMipMapLevel(fxMesa,tObj,level); - else - fxTexInvalidate(ctx,tObj); - - return; - } else { - if(mml->translated) - FREE(mml->data); - mml->data=NULL; - } + if ((mml->glideFormat == gldformat) && + (mml->width == image->Width) && + (mml->height == image->Height)) { + /* overwrite existing texture image of same size and format */ + fxTexBuildImageMap(image, internalFormat, &(mml->data)); + + if(ti->validated && ti->isInTM) + fxTMReloadMipMapLevel(fxMesa, tObj, level); + else + fxTexInvalidate(ctx,tObj); } + else { + /* deallocate existing texture image, if any */ + if (mml->data) { + FREE(mml->data); + mml->data = NULL; + } + mml->glideFormat = gldformat; + mml->width = image->Width; + mml->height = image->Height; - mml->glideFormat=gldformat; - mml->width=image->Width; - mml->height=image->Height; - mml->used=GL_TRUE; - - fxTexBuildImageMap(image,internalFormat,&(mml->data), - &(mml->translated)); - - fxTexInvalidate(ctx,tObj); + /* make new texture image */ + fxTexBuildImageMap(image, internalFormat, &(mml->data)); + fxTexInvalidate(ctx, tObj); + } + } + else { + gl_problem(NULL, "fx Driver: unsupported texture in fxDDTexImg()\n"); } -#ifndef FX_SILENT - else - fprintf(stderr,"fx Driver: unsupported texture in fxDDTexImg()\n"); -#endif } static void fxTexBuildSubImageMap(const struct gl_texture_image *image, GLint internalFormat, - GLint xoffset, GLint yoffset, GLint width, GLint height, + GLint xoffset, GLint yoffset, + GLint width, GLint height, unsigned short *destimg) { fxTexGetInfo(image->Width,image->Height,NULL,NULL,NULL,NULL,NULL,NULL, @@ -1212,9 +1056,9 @@ static void fxTexBuildSubImageMap(const struct gl_texture_image *image, case GL_COLOR_INDEX12_EXT: case GL_COLOR_INDEX16_EXT: { - int y; - unsigned char *bsrc,*bdst; + unsigned char *bdst; + const unsigned char *bsrc; bsrc=(unsigned char *)(image->Data+(yoffset*image->Width+xoffset)); bdst=((unsigned char *)destimg)+(yoffset*image->Width+xoffset); @@ -1359,9 +1203,7 @@ static void fxTexBuildSubImageMap(const struct gl_texture_image *image, } break; default: - fprintf(stderr,"fx Driver: wrong internalFormat in fxTexBuildSubImageMap()\n"); - fxCloseHardware(); - exit(-1); + fprintf(stderr,"tdfx driver: fxTexBuildSubImageMap() bad format\n"); break; } } @@ -1396,13 +1238,12 @@ void fxDDTexSubImg(GLcontext *ctx, GLenum target, fxTexGetFormat(internalFormat,&gldformat,NULL); - if(mml->glideFormat!=gldformat) { + if (mml->glideFormat != gldformat) { if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: ti->info.format!=format in fxDDTexSubImg()\n"); + gl_problem(NULL, "glide texture format mismatch in fxDDTexSubImg"); } - fxDDTexImg(ctx,target,tObj,level,internalFormat,image); - - return; + fxDDTexImg(ctx,target,tObj,level,internalFormat,image); + return; } fxTexGetInfo(image->Width,image->Height,NULL,NULL,NULL,NULL,NULL,NULL,&wscale,&hscale); @@ -1416,9 +1257,9 @@ void fxDDTexSubImg(GLcontext *ctx, GLenum target, return; } - if(mml->translated) - fxTexBuildSubImageMap(image,internalFormat,xoffset,yoffset, - width,height,mml->data); + assert(mml->data); /* must have an existing texture image! */ + fxTexBuildSubImageMap(image,internalFormat,xoffset,yoffset, + width,height,mml->data); if(ti->validated && ti->isInTM) fxTMReloadSubMipMapLevel(fxMesa,tObj,level,yoffset,height); diff --git a/src/mesa/drivers/glide/fxdrv.h b/src/mesa/drivers/glide/fxdrv.h index 4b416968a72..042048d4d89 100644 --- a/src/mesa/drivers/glide/fxdrv.h +++ b/src/mesa/drivers/glide/fxdrv.h @@ -274,9 +274,7 @@ typedef struct MemRange_t { typedef struct { GLsizei width, height; /* image size */ GrTextureFormat_t glideFormat; /* Glide image format */ - unsigned short *data; /* Glide-formated texture image */ - GLboolean translated; /* True if data points to a reformated image */ - GLboolean used; /* True if we've given the image to Glide */ + unsigned short *data; /* Glide-formated texture image */ } tfxMipMapLevel; typedef struct tfxTexInfo_t { diff --git a/src/mesa/drivers/glide/fxtexman.c b/src/mesa/drivers/glide/fxtexman.c index 87f309adc35..bc20fa10bce 100644 --- a/src/mesa/drivers/glide/fxtexman.c +++ b/src/mesa/drivers/glide/fxtexman.c @@ -651,12 +651,11 @@ void fxTMFreeTexture(fxMesaContext fxMesa, struct gl_texture_object *tObj) fxTMMoveOutTM(fxMesa, tObj); - for(i=0; imipmapLevel[i].used && - ti->mipmapLevel[i].translated) + for (i=0; imipmapLevel[i].data) { FREE(ti->mipmapLevel[i].data); - - (void)ti->mipmapLevel[i].data; + ti->mipmapLevel[i].data = NULL; + } } switch (ti->whichTMU) { case FX_TMU0: