diff options
author | Brian Paul <[email protected]> | 2000-03-27 19:08:40 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2000-03-27 19:08:40 +0000 |
commit | ba3d9d0ce958dfc6161de41d9423a4b9547fb35c (patch) | |
tree | fd622001eb79e8cbde306767915024054fe7a251 | |
parent | de5c19d139f010cf08c05af440ee3c7e5241cead (diff) |
removed tfxMipMapLevel's used and translate fields, initial teximage clean-up
-rw-r--r-- | src/mesa/drivers/glide/fxddtex.c | 457 | ||||
-rw-r--r-- | src/mesa/drivers/glide/fxdrv.h | 4 | ||||
-rw-r--r-- | src/mesa/drivers/glide/fxtexman.c | 9 |
3 files changed, 154 insertions, 316 deletions
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;i<MAX_TEXTURE_LEVELS;i++) { - ti->mipmapLevel[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;y<h;y++) - for(x=0;x<w;x++) { - idx=(x/wscale+(y/hscale)*(w/wscale)); - srcb[x+y*w]=data[idx]; - } - } - break; - case 2: - case GL_LUMINANCE_ALPHA: - case GL_LUMINANCE4_ALPHA4: - case GL_LUMINANCE6_ALPHA2: - case GL_LUMINANCE8_ALPHA8: - case GL_LUMINANCE12_ALPHA4: - case GL_LUMINANCE12_ALPHA12: - case GL_LUMINANCE16_ALPHA16: - (*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); + w = image->Width * wscale; + h = image->Height * hscale; - if(wscale==hscale==1) { - int i=0; - int lenght=h*w; - unsigned short a,l; - - while(i++<lenght) { - l=*data++; - a=*data++; - - *src++=(a << 8) | l; - } - } else { - unsigned short a,l; - - for(y=0;y<h;y++) - for(x=0;x<w;x++) { - idx=(x/wscale+(y/hscale)*(w/wscale))*2; - l=data[idx]; - a=data[idx+1]; + switch (internalFormat) { + case GL_INTENSITY: + case GL_INTENSITY4: + case GL_INTENSITY8: + case GL_INTENSITY12: + case GL_INTENSITY16: + texelSize = 1; + intFormat = MESA_I8; + break; + case 1: + case GL_LUMINANCE: + case GL_LUMINANCE4: + case GL_LUMINANCE8: + case GL_LUMINANCE12: + case GL_LUMINANCE16: + texelSize = 1; + intFormat = MESA_L8; + break; + case GL_ALPHA: + case GL_ALPHA4: + case GL_ALPHA8: + case GL_ALPHA12: + case GL_ALPHA16: + texelSize = 1; + intFormat = MESA_A8; + break; + 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: + texelSize = 1; + intFormat = MESA_C8; + break; + case 2: + case GL_LUMINANCE_ALPHA: + case GL_LUMINANCE4_ALPHA4: + case GL_LUMINANCE6_ALPHA2: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE12_ALPHA4: + case GL_LUMINANCE12_ALPHA12: + case GL_LUMINANCE16_ALPHA16: + texelSize = 2; + intFormat = MESA_L8_A8; + break; + case 3: + case GL_RGB: + case GL_R3_G3_B2: + case GL_RGB4: + case GL_RGB5: + case GL_RGB8: + case GL_RGB10: + case GL_RGB12: + case GL_RGB16: + texelSize = 2; + intFormat = MESA_R5_G6_B5; + 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: + texelSize = 2; + intFormat = MESA_A4_R4_G4_B4; + break; + case GL_RGB5_A1: + texelSize = 2; + intFormat = MESA_A1_R5_G5_B5; + break; + default: + fprintf(stderr,"tdfx driver: texbuildimagemap() bad format\n"); + return; + } - src[x+y*w]=(a << 8) | l; - } + /* alloc teximage memory */ + if (!(*dest)) { + *dest = (GLushort *) MALLOC(w * h * texelSize); + if (!(*dest)) { + return; /* out of memory */ } - break; - case 3: - case GL_RGB: - case GL_R3_G3_B2: - case GL_RGB4: - case GL_RGB5: - case GL_RGB8: - case GL_RGB10: - case GL_RGB12: - case GL_RGB16: - (*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 int r,g,b; - - while(i++<lenght) { - r=*data++; - g=*data++; - b=*data++; - - *src++=((0xf8 & r) << (11-3)) | - ((0xfc & g) << (5-3+1)) | - ((0xf8 & b) >> 3); - } - } else { - unsigned int r,g,b; - - for(y=0;y<h;y++) - for(x=0;x<w;x++) { - idx=(x/wscale+(y/hscale)*(w/wscale))*3; - r=data[idx]; - g=data[idx+1]; - b=data[idx+2]; + } - src[x+y*w]=((0xf8 & r) << (11-3)) | - ((0xfc & g) << (5-3+1)) | - ((0xf8 & b) >> 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++<lenght) { - r=*data++; - g=*data++; - b=*data++; - a=*data++; - - *src++=((0xf0 & a) << 8) | - ((0xf0 & r) << 4) | - (0xf0 & g) | - ((0xf0 & b) >> 4); - } - } else { - unsigned int r,g,b,a; - - for(y=0;y<h;y++) - for(x=0;x<w;x++) { - idx=(x/wscale+(y/hscale)*(w/wscale))*4; - r=data[idx]; - g=data[idx+1]; - b=data[idx+2]; - a=data[idx+3]; - - src[x+y*w]=((0xf0 & a) << 8) | - ((0xf0 & r) << 4) | - (0xf0 & g) | - ((0xf0 & b) >> 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++<lenght) { - r=*data++; - g=*data++; - b=*data++; - a=*data++; - *src++=((0x80 & a) << 8) | - ((0xf8 & r) << 7) | - ((0xf8 & g) << 2) | - ((0xf8 & b) >> 3); - } - } else { - unsigned r,g,b,a; - - for(y=0;y<h;y++) - for(x=0;x<w;x++) { - idx=(x/wscale+(y/hscale)*(w/wscale))*4; - r=data[idx]; - g=data[idx+1]; - b=data[idx+2]; - a=data[idx+3]; - - src[x+y*w]=((0x80 & a) << 8) | - ((0xf8 & r) << 7) | - ((0xf8 & g) << 2) | - ((0xf8 & b) >> 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; i<MAX_TEXTURE_LEVELS; i++) { - if (ti->mipmapLevel[i].used && - ti->mipmapLevel[i].translated) + for (i=0; i<MAX_TEXTURE_LEVELS; i++) { + if (ti->mipmapLevel[i].data) { FREE(ti->mipmapLevel[i].data); - - (void)ti->mipmapLevel[i].data; + ti->mipmapLevel[i].data = NULL; + } } switch (ti->whichTMU) { case FX_TMU0: |