- change around texture coordinate logic; this removes the necessity for a hack in texcoordgen mode 1 which had always bugged me (which was necessary to get scrolling textures to work). I don't know of any test cases offhand, but this should fix other texcoordgen modes as well.

- change texture palette decoding logic to be more correct. no known test cases for this, but it was clearly broken. this was a necessary step towards more correct texture memory mapping
This commit is contained in:
zeromus 2009-01-09 01:47:40 +00:00
parent 86aa5d9800
commit 175418bb21
4 changed files with 38 additions and 40 deletions

View File

@ -4,7 +4,7 @@ Graphics:
bug: 3d compositing integrated into GPU engine (more precision and speed in cases where no compositing needed) [luigi__] bug: 3d compositing integrated into GPU engine (more precision and speed in cases where no compositing needed) [luigi__]
bug: Add optional fragment shading pipeline (more precision) [luigi__] bug: Add optional fragment shading pipeline (more precision) [luigi__]
bug: fix texture mapping across texture banks [zeromus] bug: fix texture mapping across texture banks [zeromus]
bug: fix texture handling for texels with MSB set (fixes texture corruption) [zeromus] bug: fix texture handling for texels with MSB set (fixes some texture corruption) [zeromus]
enh: dont memcmp for texcache validity when the texture banks arent unmapping [zeromus] enh: dont memcmp for texcache validity when the texture banks arent unmapping [zeromus]
0.8 -> 0.9 0.8 -> 0.9

View File

@ -660,9 +660,9 @@ static inline void MMU_VRAMmapControl(u8 block, u8 VRAMBankCnt)
break; break;
case 4: // E case 4: // E
ARM9Mem.texPalSlot[0] = LCD_addr; ARM9Mem.texPalSlot[0] = LCD_addr;
ARM9Mem.texPalSlot[1] = LCD_addr+0x2000; ARM9Mem.texPalSlot[1] = LCD_addr+0x4000;
ARM9Mem.texPalSlot[2] = LCD_addr+0x4000; ARM9Mem.texPalSlot[2] = LCD_addr+0x8000;
ARM9Mem.texPalSlot[3] = LCD_addr+0x6000; ARM9Mem.texPalSlot[3] = LCD_addr+0xC000;
gpu3D->NDS_3D_VramReconfigureSignal(); gpu3D->NDS_3D_VramReconfigureSignal();
break; break;
case 5: // F case 5: // F

View File

@ -227,7 +227,6 @@ struct ALIGN(8) TextureCache
GLenum id; GLenum id;
unsigned int frm; unsigned int frm;
unsigned int mode; unsigned int mode;
unsigned int numcolors;
unsigned int pal; unsigned int pal;
unsigned int sizeX; unsigned int sizeX;
unsigned int sizeY; unsigned int sizeY;
@ -529,7 +528,7 @@ static void DebugDumpTexture(int which)
glBindTexture(GL_TEXTURE_2D,texcache[which].id); glBindTexture(GL_TEXTURE_2D,texcache[which].id);
glGetTexImage( GL_TEXTURE_2D , glGetTexImage( GL_TEXTURE_2D ,
0, 0,
GL_RGBA, GL_BGRA_EXT,
GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE,
texMAP); texMAP);
@ -544,7 +543,12 @@ static int lastTexture = -1;
static bool hasTexture = false; static bool hasTexture = false;
static void setTexture(unsigned int format, unsigned int texpal) static void setTexture(unsigned int format, unsigned int texpal)
{ {
int palSize[7]={32,4,16,256,0,8,32768}; //BIG TODO -
//none of this is capable of spanning bank boundaries. this is an obscure bug waiting to happen.
//each texel, palette, and 4x4 lookup need to be memory mapped.
//since we're caching textures, this cost is not too severe.
const int palSize[]={8,32,512,0,64,16,0};
unsigned int x=0, y=0, i; unsigned int x=0, y=0, i;
unsigned int palZeroTransparent; unsigned int palZeroTransparent;
@ -584,31 +588,28 @@ static void setTexture(unsigned int format, unsigned int texpal)
txt_slot_current=(format>>14)&0x03; txt_slot_current=(format>>14)&0x03;
adr=(unsigned char *)(ARM9Mem.textureSlotAddr[txt_slot_current]+((format&0x3FFF)<<3)); adr=(unsigned char *)(ARM9Mem.textureSlotAddr[txt_slot_current]+((format&0x3FFF)<<3));
u32 paletteAddress;
switch (textureMode) switch (textureMode)
{ {
case 1: //a3i5 case 1: //a3i5
pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4));
break;
case 2: //i2
pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<3));
break;
case 3: //i4 case 3: //i4
pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4));
break;
case 4: //i8 case 4: //i8
pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4));
break;
case 5: //4x4
pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4));
break;
case 6: //a5i3 case 6: //a5i3
pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4));
break;
case 7: //16bpp case 7: //16bpp
pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4)); case 5: //4x4
break; paletteAddress = texturePalette<<4;
break;
case 2: //i2
paletteAddress = texturePalette<<3;
break;
} }
u32 paletteSlot = paletteAddress>>14;
u32 paletteOffset = paletteAddress&0x3FFF;
pal = (unsigned short *)(ARM9Mem.texPalSlot[paletteSlot] + (paletteOffset));
i=texcache_start; i=texcache_start;
//if(false) //if(false)
@ -664,18 +665,17 @@ static void setTexture(unsigned int format, unsigned int texpal)
texcache[i].sizeX=sizeX; texcache[i].sizeX=sizeX;
texcache[i].sizeY=sizeY; texcache[i].sizeY=sizeY;
texcache[i].coord=(format>>30); texcache[i].coord=(format>>30);
texcache[i].invSizeX=1.0f/((float)(sizeX*(1<<4))); texcache[i].invSizeX=1.0f/((float)(sizeX));
texcache[i].invSizeY=1.0f/((float)(sizeY*(1<<4))); texcache[i].invSizeY=1.0f/((float)(sizeY));
memcpy(texcache[i].texture,adr,std::min((size_t)imageSize,sizeof(texcache[i].texture))); memcpy(texcache[i].texture,adr,std::min((size_t)imageSize,sizeof(texcache[i].texture)));
texcache[i].palSize = 0; texcache[i].palSize = palSize[textureMode];
if ( (textureMode != 5) || (textureMode != 7) ) if ( texcache[i].palSize != 0 )
{ {
texcache[i].palSize = 256*2; //TODO - the 4x4 lookup table should probably be checked also.
//but maybe we could concatenate that to the texture
memcpy(texcache[i].palette, pal, texcache[i].palSize); memcpy(texcache[i].palette, pal, texcache[i].palSize);
} }
texcache[i].numcolors=palSize[texcache[i].mode];
texcache[i].frm=format; texcache[i].frm=format;
glMatrixMode (GL_TEXTURE); glMatrixMode (GL_TEXTURE);

View File

@ -99,7 +99,7 @@ static CACHE_ALIGN float scale[4] = {0.0, 0.0, 0.0, 0.0};
static int scaleind = 0; static int scaleind = 0;
//various other registers //various other registers
static int _t=0, _s=0; static float _t=0, _s=0;
static float last_t, last_s; static float last_t, last_s;
static u32 clCmd = 0; static u32 clCmd = 0;
static u32 clInd = 0; static u32 clInd = 0;
@ -547,6 +547,7 @@ static void SetVertex()
//record the vertex //record the vertex
//VERT &vert = tempVertList.list[tempVertList.count]; //VERT &vert = tempVertList.list[tempVertList.count];
VERT &vert = vertlist->list[vertlist->count + tempVertInfo.count]; VERT &vert = vertlist->list[vertlist->count + tempVertInfo.count];
vert.texcoord[0] = last_s; vert.texcoord[0] = last_s;
vert.texcoord[1] = last_t; vert.texcoord[1] = last_t;
vert.coord[0] = coordTransformed[0]; vert.coord[0] = coordTransformed[0];
@ -817,18 +818,15 @@ void gfx3d_glTexCoord(unsigned long val)
_t = (s16)(val>>16); _t = (s16)(val>>16);
_s = (s16)(val&0xFFFF); _s = (s16)(val&0xFFFF);
_s /= 16.0f;
_t /= 16.0f;
if (texCoordinateTransform == 1) if (texCoordinateTransform == 1)
{ {
//last_s =_s*mtxCurrent[3][0] + _t*mtxCurrent[3][4] +
// 0.0625f*mtxCurrent[3][8] + 0.0625f*mtxCurrent[3][12];
//last_t =_s*mtxCurrent[3][1] + _t*mtxCurrent[3][5] +
// 0.0625f*mtxCurrent[3][9] + 0.0625f*mtxCurrent[3][13];
//zero 9/11/08 - I dunno... I think it needs to be like this to make things look right
last_s =_s*mtxCurrent[3][0] + _t*mtxCurrent[3][4] + last_s =_s*mtxCurrent[3][0] + _t*mtxCurrent[3][4] +
mtxCurrent[3][8] + mtxCurrent[3][12]; 0.0625f*mtxCurrent[3][8] + 0.0625f*mtxCurrent[3][12];
last_t =_s*mtxCurrent[3][1] + _t*mtxCurrent[3][5] + last_t =_s*mtxCurrent[3][1] + _t*mtxCurrent[3][5] +
mtxCurrent[3][9] + mtxCurrent[3][13]; 0.0625f*mtxCurrent[3][9] + 0.0625f*mtxCurrent[3][13];
} }
else else
{ {