removed tfxMipMapLevel's used and translate fields, initial teximage clean-up

This commit is contained in:
Brian Paul 2000-03-27 19:08:40 +00:00
parent de5c19d139
commit ba3d9d0ce9
3 changed files with 156 additions and 318 deletions

View file

@ -50,6 +50,9 @@
#if defined(FX) #if defined(FX)
#include "fxdrv.h" #include "fxdrv.h"
#include "image.h"
#include "texutil.h"
void fxPrintTextureData(tfxTexInfo *ti) void fxPrintTextureData(tfxTexInfo *ti)
{ {
@ -129,7 +132,6 @@ static tfxTexInfo *fxAllocTexObjData(fxMesaContext fxMesa)
ti->LODblend=FXFALSE; ti->LODblend=FXFALSE;
for(i=0;i<MAX_TEXTURE_LEVELS;i++) { for(i=0;i<MAX_TEXTURE_LEVELS;i++) {
ti->mipmapLevel[i].used=GL_FALSE;
ti->mipmapLevel[i].data=NULL; 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, static GLboolean fxIsTexSupported(GLenum target, GLint internalFormat,
const struct gl_texture_image *image) const struct gl_texture_image *image)
{ {
if(target!=GL_TEXTURE_2D) if(target!=GL_TEXTURE_2D)
return GL_FALSE; return GL_FALSE;
#if 0
/* mesa will have already checked this */
switch(internalFormat) { switch(internalFormat) {
case GL_INTENSITY: case GL_INTENSITY:
case GL_INTENSITY4: case GL_INTENSITY4:
@ -841,6 +845,7 @@ static int fxIsTexSupported(GLenum target, GLint internalFormat,
if(image->Height>256) if(image->Height>256)
return GL_FALSE; return GL_FALSE;
#endif
if(!fxTexGetInfo(image->Width,image->Height,NULL,NULL,NULL,NULL,NULL,NULL, if(!fxTexGetInfo(image->Width,image->Height,NULL,NULL,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, static void fxTexBuildImageMap(const struct gl_texture_image *image,
GLint internalFormat, unsigned short **dest, GLint internalFormat, unsigned short **dest)
GLboolean *istranslate)
{ {
unsigned short *src; int w, h, wscale, hscale;
unsigned char *data; int texelSize; /* in bytes */
int x,y,w,h,wscale,hscale,idx; MesaIntTexFormat intFormat;
fxTexGetInfo(image->Width,image->Height,NULL,NULL,NULL,NULL,NULL,NULL, fxTexGetInfo(image->Width,image->Height,NULL,NULL,NULL,NULL,NULL,NULL,
&wscale,&hscale); &wscale,&hscale);
w=image->Width*wscale; w = image->Width * wscale;
h=image->Height*hscale; h = image->Height * hscale;
data=image->Data; switch (internalFormat) {
switch(internalFormat) { case GL_INTENSITY:
case GL_INTENSITY: case GL_INTENSITY4:
case GL_INTENSITY4: case GL_INTENSITY8:
case GL_INTENSITY8: case GL_INTENSITY12:
case GL_INTENSITY12: case GL_INTENSITY16:
case GL_INTENSITY16: texelSize = 1;
case 1: intFormat = MESA_I8;
case GL_LUMINANCE: break;
case GL_LUMINANCE4: case 1:
case GL_LUMINANCE8: case GL_LUMINANCE:
case GL_LUMINANCE12: case GL_LUMINANCE4:
case GL_LUMINANCE16: case GL_LUMINANCE8:
case GL_ALPHA: case GL_LUMINANCE12:
case GL_ALPHA4: case GL_LUMINANCE16:
case GL_ALPHA8: texelSize = 1;
case GL_ALPHA12: intFormat = MESA_L8;
case GL_ALPHA16: break;
case GL_COLOR_INDEX: case GL_ALPHA:
case GL_COLOR_INDEX1_EXT: case GL_ALPHA4:
case GL_COLOR_INDEX2_EXT: case GL_ALPHA8:
case GL_COLOR_INDEX4_EXT: case GL_ALPHA12:
case GL_COLOR_INDEX8_EXT: case GL_ALPHA16:
case GL_COLOR_INDEX12_EXT: texelSize = 1;
case GL_COLOR_INDEX16_EXT: intFormat = MESA_A8;
/* Optimized for GLQuake */ break;
case GL_COLOR_INDEX:
if(wscale==hscale==1) { case GL_COLOR_INDEX1_EXT:
(*istranslate)=GL_FALSE; case GL_COLOR_INDEX2_EXT:
case GL_COLOR_INDEX4_EXT:
(*dest)=(unsigned short *)data; case GL_COLOR_INDEX8_EXT:
} else { case GL_COLOR_INDEX12_EXT:
unsigned char *srcb; case GL_COLOR_INDEX16_EXT:
texelSize = 1;
(*istranslate)=GL_TRUE; intFormat = MESA_C8;
break;
if(!(*dest)) { case 2:
if(!((*dest)=src=(unsigned short *)MALLOC(sizeof(unsigned char)*w*h))) { case GL_LUMINANCE_ALPHA:
fprintf(stderr,"fx Driver: out of memory !\n"); case GL_LUMINANCE4_ALPHA4:
fxCloseHardware(); case GL_LUMINANCE6_ALPHA2:
exit(-1); case GL_LUMINANCE8_ALPHA8:
} case GL_LUMINANCE12_ALPHA4:
} else case GL_LUMINANCE12_ALPHA12:
src=(*dest); case GL_LUMINANCE16_ALPHA16:
texelSize = 2;
srcb=(unsigned char *)src; intFormat = MESA_L8_A8;
break;
for(y=0;y<h;y++) case 3:
for(x=0;x<w;x++) { case GL_RGB:
idx=(x/wscale+(y/hscale)*(w/wscale)); case GL_R3_G3_B2:
srcb[x+y*w]=data[idx]; case GL_RGB4:
} case GL_RGB5:
} case GL_RGB8:
break; case GL_RGB10:
case 2: case GL_RGB12:
case GL_LUMINANCE_ALPHA: case GL_RGB16:
case GL_LUMINANCE4_ALPHA4: texelSize = 2;
case GL_LUMINANCE6_ALPHA2: intFormat = MESA_R5_G6_B5;
case GL_LUMINANCE8_ALPHA8: break;
case GL_LUMINANCE12_ALPHA4: case 4:
case GL_LUMINANCE12_ALPHA12: case GL_RGBA:
case GL_LUMINANCE16_ALPHA16: case GL_RGBA2:
(*istranslate)=GL_TRUE; case GL_RGBA4:
case GL_RGBA8:
if(!(*dest)) { case GL_RGB10_A2:
if(!((*dest)=src=(unsigned short *)MALLOC(sizeof(unsigned short)*w*h))) { case GL_RGBA12:
fprintf(stderr,"fx Driver: out of memory !\n"); case GL_RGBA16:
fxCloseHardware(); texelSize = 2;
exit(-1); intFormat = MESA_A4_R4_G4_B4;
} break;
} else case GL_RGB5_A1:
src=(*dest); texelSize = 2;
intFormat = MESA_A1_R5_G5_B5;
if(wscale==hscale==1) { break;
int i=0; default:
int lenght=h*w; fprintf(stderr,"tdfx driver: texbuildimagemap() bad format\n");
unsigned short a,l; return;
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];
src[x+y*w]=(a << 8) | l;
}
}
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;
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;
} }
/* alloc teximage memory */
if (!(*dest)) {
*dest = (GLushort *) MALLOC(w * h * texelSize);
if (!(*dest)) {
return; /* out of memory */
}
}
/* 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);
} }
void fxDDTexImg(GLcontext *ctx, GLenum target, 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) const struct gl_texture_image *image)
{ {
fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
@ -1129,59 +977,55 @@ void fxDDTexImg(GLcontext *ctx, GLenum target,
image->Height); image->Height);
} }
if(target!=GL_TEXTURE_2D) if (target!=GL_TEXTURE_2D)
return; return;
if (!tObj->DriverData) if (!tObj->DriverData)
tObj->DriverData=fxAllocTexObjData(fxMesa); tObj->DriverData=fxAllocTexObjData(fxMesa);
ti=fxTMGetTexInfo(tObj); ti = fxTMGetTexInfo(tObj);
if(fxIsTexSupported(target,internalFormat,image)) { if (fxIsTexSupported(target,internalFormat,image)) {
GrTextureFormat_t gldformat; 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) &&
if((mml->glideFormat==gldformat) && (mml->width == image->Width) &&
(mml->width==image->Width) && (mml->height == image->Height)) {
(mml->height==image->Height)) { /* overwrite existing texture image of same size and format */
fxTexBuildImageMap(image,internalFormat,&(mml->data), fxTexBuildImageMap(image, internalFormat, &(mml->data));
&(mml->translated));
if(ti->validated && ti->isInTM) if(ti->validated && ti->isInTM)
fxTMReloadMipMapLevel(fxMesa,tObj,level); fxTMReloadMipMapLevel(fxMesa, tObj, level);
else else
fxTexInvalidate(ctx,tObj); fxTexInvalidate(ctx,tObj);
return;
} else {
if(mml->translated)
FREE(mml->data);
mml->data=NULL;
}
} }
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; /* make new texture image */
mml->width=image->Width; fxTexBuildImageMap(image, internalFormat, &(mml->data));
mml->height=image->Height; fxTexInvalidate(ctx, tObj);
mml->used=GL_TRUE; }
}
fxTexBuildImageMap(image,internalFormat,&(mml->data), else {
&(mml->translated)); gl_problem(NULL, "fx Driver: unsupported texture in fxDDTexImg()\n");
fxTexInvalidate(ctx,tObj);
} }
#ifndef FX_SILENT
else
fprintf(stderr,"fx Driver: unsupported texture in fxDDTexImg()\n");
#endif
} }
static void fxTexBuildSubImageMap(const struct gl_texture_image *image, static void fxTexBuildSubImageMap(const struct gl_texture_image *image,
GLint internalFormat, GLint internalFormat,
GLint xoffset, GLint yoffset, GLint width, GLint height, GLint xoffset, GLint yoffset,
GLint width, GLint height,
unsigned short *destimg) unsigned short *destimg)
{ {
fxTexGetInfo(image->Width,image->Height,NULL,NULL,NULL,NULL,NULL,NULL, 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_INDEX12_EXT:
case GL_COLOR_INDEX16_EXT: case GL_COLOR_INDEX16_EXT:
{ {
int y; int y;
unsigned char *bsrc,*bdst; unsigned char *bdst;
const unsigned char *bsrc;
bsrc=(unsigned char *)(image->Data+(yoffset*image->Width+xoffset)); bsrc=(unsigned char *)(image->Data+(yoffset*image->Width+xoffset));
bdst=((unsigned char *)destimg)+(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; break;
default: default:
fprintf(stderr,"fx Driver: wrong internalFormat in fxTexBuildSubImageMap()\n"); fprintf(stderr,"tdfx driver: fxTexBuildSubImageMap() bad format\n");
fxCloseHardware();
exit(-1);
break; break;
} }
} }
@ -1396,13 +1238,12 @@ void fxDDTexSubImg(GLcontext *ctx, GLenum target,
fxTexGetFormat(internalFormat,&gldformat,NULL); fxTexGetFormat(internalFormat,&gldformat,NULL);
if(mml->glideFormat!=gldformat) { if (mml->glideFormat != gldformat) {
if (MESA_VERBOSE&VERBOSE_DRIVER) { 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); fxDDTexImg(ctx,target,tObj,level,internalFormat,image);
return;
return;
} }
fxTexGetInfo(image->Width,image->Height,NULL,NULL,NULL,NULL,NULL,NULL,&wscale,&hscale); fxTexGetInfo(image->Width,image->Height,NULL,NULL,NULL,NULL,NULL,NULL,&wscale,&hscale);
@ -1416,9 +1257,9 @@ void fxDDTexSubImg(GLcontext *ctx, GLenum target,
return; return;
} }
if(mml->translated) assert(mml->data); /* must have an existing texture image! */
fxTexBuildSubImageMap(image,internalFormat,xoffset,yoffset, fxTexBuildSubImageMap(image,internalFormat,xoffset,yoffset,
width,height,mml->data); width,height,mml->data);
if(ti->validated && ti->isInTM) if(ti->validated && ti->isInTM)
fxTMReloadSubMipMapLevel(fxMesa,tObj,level,yoffset,height); fxTMReloadSubMipMapLevel(fxMesa,tObj,level,yoffset,height);

View file

@ -274,9 +274,7 @@ typedef struct MemRange_t {
typedef struct { typedef struct {
GLsizei width, height; /* image size */ GLsizei width, height; /* image size */
GrTextureFormat_t glideFormat; /* Glide image format */ GrTextureFormat_t glideFormat; /* Glide image format */
unsigned short *data; /* Glide-formated texture image */ 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 */
} tfxMipMapLevel; } tfxMipMapLevel;
typedef struct tfxTexInfo_t { typedef struct tfxTexInfo_t {

View file

@ -651,12 +651,11 @@ void fxTMFreeTexture(fxMesaContext fxMesa, struct gl_texture_object *tObj)
fxTMMoveOutTM(fxMesa, tObj); fxTMMoveOutTM(fxMesa, tObj);
for(i=0; i<MAX_TEXTURE_LEVELS; i++) { for (i=0; i<MAX_TEXTURE_LEVELS; i++) {
if (ti->mipmapLevel[i].used && if (ti->mipmapLevel[i].data) {
ti->mipmapLevel[i].translated)
FREE(ti->mipmapLevel[i].data); FREE(ti->mipmapLevel[i].data);
ti->mipmapLevel[i].data = NULL;
(void)ti->mipmapLevel[i].data; }
} }
switch (ti->whichTMU) { switch (ti->whichTMU) {
case FX_TMU0: case FX_TMU0: