parent
3fde410ecb
commit
7f21832b5d
|
@ -217,12 +217,12 @@ static void _xglDisable(GLenum cap) {
|
|||
|
||||
//================================================= Textures
|
||||
#define MAX_TEXTURE 500
|
||||
struct TextureCache
|
||||
#ifdef SSE2
|
||||
typedef ALIGN(16) struct
|
||||
#else
|
||||
typedef ALIGN(8) struct
|
||||
#endif
|
||||
{
|
||||
TextureCache()
|
||||
: suspectedInvalid(true)
|
||||
{}
|
||||
|
||||
GLenum id;
|
||||
unsigned int frm;
|
||||
unsigned int mode;
|
||||
|
@ -233,16 +233,14 @@ struct TextureCache
|
|||
int coord;
|
||||
float invSizeX;
|
||||
float invSizeY;
|
||||
#ifdef SSE2
|
||||
ALIGN(16) unsigned char texture[128*1024]; // 128Kb texture slot
|
||||
#else
|
||||
unsigned char texture[128*1024]; // 128Kb texture slot
|
||||
#endif
|
||||
u8 palette[256*2];
|
||||
u16 palSize;
|
||||
|
||||
//set if this texture is suspected be invalid due to a vram reconfigure
|
||||
bool suspectedInvalid;
|
||||
|
||||
} ;
|
||||
} TextureCache;
|
||||
|
||||
TextureCache texcache[MAX_TEXTURE+1];
|
||||
u32 texcache_count;
|
||||
|
@ -366,9 +364,13 @@ static void OGLReset()
|
|||
texcache_start=0;
|
||||
texcache_stop=MAX_TEXTURE<<1;
|
||||
|
||||
for(int i=0;i<MAX_TEXTURE+1;i++)
|
||||
texcache[i].suspectedInvalid = true;
|
||||
|
||||
//clear the framebuffers
|
||||
// memset(GPU_screenStencil,0,sizeof(GPU_screenStencil));
|
||||
memset(GPU_screen3D,0,sizeof(GPU_screen3D));
|
||||
|
||||
}
|
||||
|
||||
static char OGLInit(void)
|
||||
|
@ -573,6 +575,31 @@ static void setTexture(unsigned int format, unsigned int texpal)
|
|||
txt_slot_current=(format>>14)&0x03;
|
||||
adr=(unsigned char *)(ARM9Mem.textureSlotAddr[txt_slot_current]+((format&0x3FFF)<<3));
|
||||
|
||||
switch (textureMode)
|
||||
{
|
||||
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
|
||||
pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4));
|
||||
break;
|
||||
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
|
||||
pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4));
|
||||
break;
|
||||
case 7: //16bpp
|
||||
pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4));
|
||||
break;
|
||||
}
|
||||
|
||||
i=texcache_start;
|
||||
|
||||
//if(false)
|
||||
|
@ -582,9 +609,13 @@ static void setTexture(unsigned int format, unsigned int texpal)
|
|||
if (texcache[i].frm==0) break;
|
||||
if ( (texcache[i].frm == format) && (texcache[i].pal == texpal) )
|
||||
{
|
||||
//TODO - we need to compare the palette also.
|
||||
|
||||
if ((texcache[i].mode == 5) ||
|
||||
(texcache[i].mode == 7) ||
|
||||
!memcmp(texcache[i].palette, pal, texcache[i].palSize) )
|
||||
{
|
||||
//TODO - this doesnt correctly span bank boundaries. in fact, it seems quite dangerous.
|
||||
if (!texcache[i].suspectedInvalid || !memcmp(adr,texcache[i].texture,std::min((size_t)imageSize,sizeof(texcache[i].texture))))
|
||||
if (!memcmp(adr, texcache[i].texture, std::min((size_t)imageSize,sizeof(texcache[i].texture))) )
|
||||
{
|
||||
texcache[i].suspectedInvalid = false;
|
||||
texcache_count=i;
|
||||
|
@ -599,6 +630,23 @@ static void setTexture(unsigned int format, unsigned int texpal)
|
|||
return;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
if (!texcache[i].suspectedInvalid)
|
||||
{
|
||||
texcache[i].suspectedInvalid = false;
|
||||
texcache_count=i;
|
||||
if(lastTexture == -1 || (int)i != lastTexture)
|
||||
{
|
||||
lastTexture = i;
|
||||
glBindTexture(GL_TEXTURE_2D,texcache[i].id);
|
||||
glMatrixMode (GL_TEXTURE);
|
||||
glLoadIdentity ();
|
||||
glScaled (texcache[i].invSizeX, texcache[i].invSizeY, 1.0f);
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
i++;
|
||||
if (i>MAX_TEXTURE)
|
||||
{
|
||||
|
@ -626,6 +674,13 @@ static void setTexture(unsigned int format, unsigned int texpal)
|
|||
texcache[i].invSizeX=1.0f/((float)(sizeX*(1<<4)));
|
||||
texcache[i].invSizeY=1.0f/((float)(sizeY*(1<<4)));
|
||||
memcpy(texcache[i].texture,adr,std::min((size_t)imageSize,sizeof(texcache[i].texture)));
|
||||
texcache[i].palSize = 0;
|
||||
if ( (textureMode != 5) || (textureMode != 7) )
|
||||
{
|
||||
texcache[i].palSize = 256*2;
|
||||
memcpy(texcache[i].palette, pal, texcache[i].palSize);
|
||||
}
|
||||
|
||||
texcache[i].numcolors=palSize[texcache[i].mode];
|
||||
|
||||
texcache[i].frm=format;
|
||||
|
@ -645,7 +700,6 @@ static void setTexture(unsigned int format, unsigned int texpal)
|
|||
{
|
||||
case 1: //a3i5
|
||||
{
|
||||
pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4));
|
||||
for(x = 0; x < imageSize; x++, dst += 4)
|
||||
{
|
||||
u16 c = pal[adr[x]&31];
|
||||
|
@ -657,7 +711,6 @@ static void setTexture(unsigned int format, unsigned int texpal)
|
|||
}
|
||||
case 2: //i2
|
||||
{
|
||||
pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<3));
|
||||
for(x = 0; x < imageSize>>2; ++x)
|
||||
{
|
||||
unsigned short c = pal[(adr[x])&0x3];
|
||||
|
@ -693,7 +746,6 @@ static void setTexture(unsigned int format, unsigned int texpal)
|
|||
}
|
||||
case 3: //i4
|
||||
{
|
||||
pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4));
|
||||
for(x = 0; x < (imageSize>>1); x++)
|
||||
{
|
||||
unsigned short c = pal[adr[x]&0xF];
|
||||
|
@ -715,7 +767,6 @@ static void setTexture(unsigned int format, unsigned int texpal)
|
|||
}
|
||||
case 4: //i8
|
||||
{
|
||||
pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4));
|
||||
for(x = 0; x < imageSize; ++x)
|
||||
{
|
||||
u16 c = pal[adr[x]];
|
||||
|
@ -726,7 +777,6 @@ static void setTexture(unsigned int format, unsigned int texpal)
|
|||
break;
|
||||
case 5: //4x4
|
||||
{
|
||||
pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4));
|
||||
unsigned short * slot1;
|
||||
unsigned int * map = (unsigned int *)adr;
|
||||
unsigned int d = 0;
|
||||
|
@ -737,12 +787,14 @@ static void setTexture(unsigned int format, unsigned int texpal)
|
|||
slot1=(unsigned short*)&ARM9Mem.textureSlotAddr[1][(texcache[i].frm&0x3FFF)<<2];
|
||||
|
||||
bool dead = false;
|
||||
u16 yTmpSize = (texcache[i].sizeY>>2);
|
||||
u16 xTmpSize = (texcache[i].sizeX>>2);
|
||||
|
||||
for (y = 0; y < (texcache[i].sizeY>>2); y ++)
|
||||
for (y = 0; y < yTmpSize; y ++)
|
||||
{
|
||||
u32 tmpPos[4]={(y<<2)*texcache[i].sizeX,((y<<2)+1)*texcache[i].sizeX,
|
||||
((y<<2)+2)*texcache[i].sizeX,((y<<2)+3)*texcache[i].sizeX};
|
||||
for (x = 0; x < (texcache[i].sizeX>>2); x ++, d++)
|
||||
for (x = 0; x < xTmpSize; x ++, d++)
|
||||
{
|
||||
u32 currBlock = map[d], sy;
|
||||
u16 pal1 = slot1[d];
|
||||
|
@ -829,7 +881,6 @@ static void setTexture(unsigned int format, unsigned int texpal)
|
|||
}
|
||||
case 6: //a5i3
|
||||
{
|
||||
pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4));
|
||||
for(x = 0; x < imageSize; x++)
|
||||
{
|
||||
u16 c = pal[adr[x]&0x07];
|
||||
|
@ -842,7 +893,6 @@ static void setTexture(unsigned int format, unsigned int texpal)
|
|||
case 7: //16bpp
|
||||
{
|
||||
unsigned short * map = ((unsigned short *)adr);
|
||||
pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4));
|
||||
|
||||
for(x = 0; x < imageSize; ++x)
|
||||
{
|
||||
|
@ -863,7 +913,6 @@ static void setTexture(unsigned int format, unsigned int texpal)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
|
||||
texcache[i].sizeX, texcache[i].sizeY, 0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, texMAP);
|
||||
|
|
Loading…
Reference in New Issue