diff --git a/desmume/src/OGLRender.cpp b/desmume/src/OGLRender.cpp index 8f6dda77d..735b862e5 100644 --- a/desmume/src/OGLRender.cpp +++ b/desmume/src/OGLRender.cpp @@ -96,6 +96,7 @@ public: int memcmp(void* buf2, int size=-1) { if(size==-1) size = this->size; + size = std::min(this->size,size); for(int i=0;isize; + size = std::min(this->size,size); u8* bufptr = (u8*)buf; int done = 0; for(int i=0;i>2; + int texSize = (imageSize*texSizes[textureMode])>>2; //shifted because the texSizes multiplier is fixed point MemSpan ms = MemSpan_TexMem((format&0xFFFF)<<3,texSize); MemSpan mspal = MemSpan_TexPalette(paletteAddress,palSize*2); @@ -744,7 +739,7 @@ static void setTexture(unsigned int format, unsigned int texpal) if(textureMode == TEXMODE_4X4) { indexSize = imageSize>>3; - MemSpan_TexMem(indexOffset+indexBase,indexSize); + msIndex = MemSpan_TexMem(indexOffset+indexBase,indexSize); } @@ -756,6 +751,7 @@ static void setTexture(unsigned int format, unsigned int texpal) u32 tx=texcache_start; + //if(false) while (TRUE) { //conditions where we give up and regenerate the texture: @@ -784,8 +780,9 @@ static void setTexture(unsigned int format, unsigned int texpal) if(ms.memcmp(texcache[tx].texture,sizeof(texcache[tx].texture))) goto REJECT; //if the texture is 4x4 then the index data must match - if(textureMode == TEXMODE_4X4) { - if(msIndex.memcmp(texcache[tx].texture + texcache[tx].textureSize,texcache[tx].indexSize)) goto REJECT; + if(textureMode == TEXMODE_4X4) + { + if(msIndex.memcmp(texcache[tx].texture + texcache[tx].textureSize,texcache[tx].indexSize)) goto REJECT; } @@ -832,17 +829,16 @@ REJECT: texcache[tx].textureSize = ms.dump(texcache[tx].texture,sizeof(texcache[tx].texture)); //dump palette data for cache keying - texcache[tx].palSize = mspal.size; - if ( texcache[tx].palSize ) + if ( palSize ) { - memcpy(texcache[tx].palette, pal, texcache[tx].palSize*2); + memcpy(texcache[tx].palette, pal, palSize*2); } //dump 4x4 index data for cache keying texcache[tx].indexSize = 0; if(textureMode == TEXMODE_4X4) { texcache[tx].indexSize = std::min(msIndex.size,(int)sizeof(texcache[tx].texture) - texcache[tx].textureSize); - msIndex.dump(texcache[tx].texture,texcache[tx].indexSize); + msIndex.dump(texcache[tx].texture+texcache[tx].textureSize,texcache[tx].indexSize); } @@ -940,6 +936,8 @@ REJECT: break; case TEXMODE_4X4: { + //RGB16TO32 is used here because the other conversion macros result in broken interpolation logic + if(ms.numItems != 1) { PROGINFO("Your 4x4 texture has overrun its texture slot.\n"); } @@ -989,25 +987,25 @@ REJECT: u8 mode = pal1>>14; u32 tmp_col[4]; - tmp_col[0]=RGB15TO32(PAL4X4(pal1offset),255); - tmp_col[1]=RGB15TO32(PAL4X4(pal1offset+1),255); + tmp_col[0]=RGB16TO32(PAL4X4(pal1offset),255); + tmp_col[1]=RGB16TO32(PAL4X4(pal1offset+1),255); switch (mode) { case 0: - tmp_col[2]=RGB15TO32(PAL4X4(pal1offset+2),255); - tmp_col[3]=RGB15TO32(0x7FFF,0); + tmp_col[2]=RGB16TO32(PAL4X4(pal1offset+2),255); + tmp_col[3]=RGB16TO32(0x7FFF,0); break; case 1: tmp_col[2]=(((tmp_col[0]&0xFF)+(tmp_col[1]&0xff))>>1)| (((tmp_col[0]&(0xFF<<8))+(tmp_col[1]&(0xFF<<8)))>>1)| (((tmp_col[0]&(0xFF<<16))+(tmp_col[1]&(0xFF<<16)))>>1)| (0xff<<24); - tmp_col[3]=RGB15TO32(0x7FFF,0); + tmp_col[3]=RGB16TO32(0x7FFF,0); break; case 2: - tmp_col[2]=RGB15TO32(PAL4X4(pal1offset+2),255); - tmp_col[3]=RGB15TO32(PAL4X4(pal1offset+3),255); + tmp_col[2]=RGB16TO32(PAL4X4(pal1offset+2),255); + tmp_col[3]=RGB16TO32(PAL4X4(pal1offset+3),255); break; case 3: { @@ -1030,8 +1028,8 @@ REJECT: (((green2*5+green1*3)>>6)<<5)| (((blue2*5+blue1*3)>>6)<<10); - tmp_col[2]=RGB15TO32(tmp1,255); - tmp_col[3]=RGB15TO32(tmp2,255); + tmp_col[2]=RGB16TO32(tmp1,255); + tmp_col[3]=RGB16TO32(tmp2,255); break; } } diff --git a/desmume/src/gfx3d.h b/desmume/src/gfx3d.h index b334fd1a3..1784fd577 100644 --- a/desmume/src/gfx3d.h +++ b/desmume/src/gfx3d.h @@ -138,6 +138,9 @@ extern GFX3D gfx3d; //--------------------- +//produce a 32bpp color from a DS RGB16 +#define RGB16TO32(col,alpha) (((alpha)<<24) | ((((col) & 0x7C00)>>7)<<16) | ((((col) & 0x3E0)>>2)<<8) | (((col) & 0x1F)<<3)) + //produce a 32bpp color from a ds RGB15 plus an 8bit alpha, using a table #define RGB15TO32(col,alpha8) ( ((alpha8)<<24) | color_15bit_to_24bit[col&0x7FFF] )