mirror of
https://github.com/libretro/ppsspp.git
synced 2025-02-17 15:37:39 +00:00
Merge branch 'master' of github.com:hrydgard/ppsspp
This commit is contained in:
commit
91cb6197e8
@ -86,7 +86,21 @@ SceUID sceKernelCreateMbx(const char *name, int memoryPartition, SceUInt attr, i
|
||||
|
||||
int sceKernelDeleteMbx(SceUID id)
|
||||
{
|
||||
DEBUG_LOG(HLE, "sceKernelDeleteMbx(%i)", id);
|
||||
u32 error;
|
||||
Mbx *m = kernelObjects.Get<Mbx>(id, error);
|
||||
if (m)
|
||||
{
|
||||
DEBUG_LOG(HLE, "sceKernelDeleteMbx(%i)", id);
|
||||
for (size_t i = 0; i < m->waitingThreads.size(); i++)
|
||||
{
|
||||
Memory::Write_U32(0, m->waitingThreads[i].second);
|
||||
__KernelResumeThreadFromWait(m->waitingThreads[i].first);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR_LOG(HLE, "sceKernelDeleteMbx(%i): invalid mbx id", id);
|
||||
}
|
||||
return kernelObjects.Destroy<Mbx>(id);
|
||||
}
|
||||
|
||||
@ -176,8 +190,8 @@ void sceKernelReceiveMbx(SceUID id, u32 packetAddrPtr, u32 timeoutPtr)
|
||||
|
||||
void sceKernelReceiveMbxCB(SceUID id, u32 packetAddrPtr, u32 timeoutPtr)
|
||||
{
|
||||
u32 error;
|
||||
Mbx *m = kernelObjects.Get<Mbx>(id, error);
|
||||
u32 error;
|
||||
Mbx *m = kernelObjects.Get<Mbx>(id, error);
|
||||
__KernelCheckCallbacks();
|
||||
|
||||
if (!m)
|
||||
@ -190,9 +204,9 @@ void sceKernelReceiveMbxCB(SceUID id, u32 packetAddrPtr, u32 timeoutPtr)
|
||||
if (!m->messageQueue.empty())
|
||||
{
|
||||
DEBUG_LOG(HLE, "sceKernelReceiveMbxCB(%i, %08x, %08x): sending first queue message", id, packetAddrPtr, timeoutPtr);
|
||||
Memory::Write_U32(m->messageQueue.front(), packetAddrPtr);
|
||||
m->messageQueue.erase(m->messageQueue.begin());
|
||||
RETURN(0);
|
||||
Memory::Write_U32(m->messageQueue.front(), packetAddrPtr);
|
||||
m->messageQueue.erase(m->messageQueue.begin());
|
||||
RETURN(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -205,8 +219,8 @@ void sceKernelReceiveMbxCB(SceUID id, u32 packetAddrPtr, u32 timeoutPtr)
|
||||
|
||||
int sceKernelPollMbx(SceUID id, u32 packetAddrPtr)
|
||||
{
|
||||
u32 error;
|
||||
Mbx *m = kernelObjects.Get<Mbx>(id, error);
|
||||
u32 error;
|
||||
Mbx *m = kernelObjects.Get<Mbx>(id, error);
|
||||
|
||||
if (!m)
|
||||
{
|
||||
|
@ -48,7 +48,11 @@ struct TexCacheEntry
|
||||
typedef std::map<u32, TexCacheEntry> TexCache;
|
||||
static TexCache cache;
|
||||
|
||||
u8 *tempArea;
|
||||
u32 tmpTexBuf32[1024 * 1024];
|
||||
u16 tmpTexBuf16[1024 * 1024];
|
||||
|
||||
u32 clutBuf32[4096];
|
||||
u16 clutBuf16[4096];
|
||||
|
||||
void TextureCache_Clear(bool delete_them)
|
||||
{
|
||||
@ -66,54 +70,290 @@ void TextureCache_Clear(bool delete_them)
|
||||
}
|
||||
}
|
||||
|
||||
u32 PaletteLoad(int index)
|
||||
u32 GetClutAddr(u32 clutEntrySize)
|
||||
{
|
||||
int pf = gstate.clutformat & 3;
|
||||
int shift = (gstate.clutformat >> 2) & 31;
|
||||
int mask = (gstate.clutformat >> 8) & 255;
|
||||
int start = ((gstate.clutformat >> 16) & 31) * 16;
|
||||
|
||||
if (pf<3)
|
||||
{
|
||||
//16-bit
|
||||
u16 *p = (u16*)gstate.paletteMem;
|
||||
u16 col = p[((start+index)>>shift) & mask];
|
||||
int r,g,b,a;
|
||||
|
||||
// TODO: properly expand the lower bits.
|
||||
switch (pf)
|
||||
{
|
||||
case 0:
|
||||
r = (col&0x1f)*8;
|
||||
g = ((col>>5)&0x3f)*4;
|
||||
b = ((col>>11)&0x1f)*8;
|
||||
a = 255;
|
||||
break;
|
||||
case 1:
|
||||
r = (col&0x1f)*8;
|
||||
g = ((col>>5)&0x1f)*8;
|
||||
b = ((col>>10)&0x1f)*8;
|
||||
a = (col>>15)*255;
|
||||
break;
|
||||
case 2:
|
||||
r = (col&0xf)*16;
|
||||
g = ((col>>4)&0xf)*16;
|
||||
b = ((col>>8)&0xf)*16;
|
||||
a = ((col>>12)&0xF)*16;
|
||||
break;
|
||||
}
|
||||
|
||||
// We now use OpenGL ES 2.0 style colors.
|
||||
return (a << 24) | (b<<16) | (g<<8) | (r<<0);
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 *p = (u32*)gstate.paletteMem;
|
||||
u32 col = p[((start + index) >> shift) & mask];
|
||||
return col;
|
||||
}
|
||||
return ((gstate.clutaddr & 0xFFFFFF) | ((gstate.clutaddrupper << 8) & 0x0F000000)) + ((gstate.clutformat >> 16) & 0x1f) * clutEntrySize;
|
||||
}
|
||||
|
||||
u32 GetClutIndex(u32 index)
|
||||
{
|
||||
return ((((gstate.clutformat >> 16) & 0x1f) + index) >> ((gstate.clutformat >> 2) & 0x1f)) & ((gstate.clutformat >> 8) & 0xff);
|
||||
}
|
||||
|
||||
u16 *ReadClut16()
|
||||
{
|
||||
u32 clutNumEntries = (gstate.loadclut & 0x3f) * 16;
|
||||
u32 clutAddr = GetClutAddr(2);
|
||||
for (u32 i = ((gstate.clutformat >> 16) & 0x1f); i < clutNumEntries; i++)
|
||||
clutBuf16[i] = Memory::Read_U16(clutAddr + i * 2);
|
||||
return clutBuf16;
|
||||
}
|
||||
|
||||
u32 *ReadClut32()
|
||||
{
|
||||
u32 clutNumEntries = (gstate.loadclut & 0x3f) * 8;
|
||||
u32 clutAddr = GetClutAddr(4);
|
||||
for (u32 i = ((gstate.clutformat >> 16) & 0x1f); i < clutNumEntries; i++)
|
||||
clutBuf32[i] = Memory::Read_U32(clutAddr + i * 4);
|
||||
return clutBuf32;
|
||||
}
|
||||
|
||||
void *UnswizzleFromMem(u32 texaddr, u32 bytesPerPixel, u32 level)
|
||||
{
|
||||
u32 addr = texaddr;
|
||||
u32 rowWidth = (bytesPerPixel > 0) ? ((gstate.texbufwidth[level] & 0x3FF) * bytesPerPixel) : ((gstate.texbufwidth[level] & 0x3FF) / 2);
|
||||
u32 pitch = rowWidth / 4;
|
||||
u32 bxc = rowWidth / 16;
|
||||
u32 byc = ((1 << ((gstate.texsize[level] >> 8) & 0xf)) + 7) / 8;
|
||||
if (byc == 0)
|
||||
byc = 1;
|
||||
|
||||
u32 ydest = 0;
|
||||
|
||||
u32 by;
|
||||
for (by = 0; by < byc; by++)
|
||||
{
|
||||
if (rowWidth >= 16)
|
||||
{
|
||||
u32 xdest = ydest;
|
||||
u32 bx;
|
||||
for (bx = 0; bx < bxc; bx++)
|
||||
{
|
||||
u32 dest = xdest;
|
||||
u8 n;
|
||||
for (n = 0; n < 8; n++)
|
||||
{
|
||||
u32 k;
|
||||
for (k = 0; k < 4; k++) {
|
||||
tmpTexBuf32[dest + k] = Memory::Read_U32(addr);
|
||||
addr += 4;
|
||||
}
|
||||
dest += pitch;
|
||||
}
|
||||
xdest += 4;
|
||||
}
|
||||
ydest += (rowWidth * 8) / 4;
|
||||
}
|
||||
else if (rowWidth == 8)
|
||||
{
|
||||
u32 n;
|
||||
for (n = 0; n < 8; n++, ydest += 2)
|
||||
{
|
||||
tmpTexBuf32[ydest + 0] = Memory::Read_U32(addr + 0);
|
||||
tmpTexBuf32[ydest + 1] = Memory::Read_U32(addr + 4);
|
||||
addr += 16; // skip two u32
|
||||
}
|
||||
}
|
||||
else if (rowWidth == 4)
|
||||
{
|
||||
u32 n;
|
||||
for (n = 0; n < 8; n++, ydest++) {
|
||||
tmpTexBuf32[ydest] = Memory::Read_U32(addr);
|
||||
addr += 16;
|
||||
}
|
||||
}
|
||||
else if (rowWidth == 2)
|
||||
{
|
||||
u32 n;
|
||||
for (n = 0; n < 4; n++, ydest++)
|
||||
{
|
||||
u16 n1 = Memory::Read_U32(addr + 0) & 0xffff;
|
||||
u16 n2 = Memory::Read_U32(addr + 16) & 0xffff;
|
||||
tmpTexBuf32[ydest] = (u32)n1 | ((u32)n2 << 16);
|
||||
addr += 32;
|
||||
}
|
||||
}
|
||||
else if (rowWidth == 1)
|
||||
{
|
||||
u32 n;
|
||||
for (n = 0; n < 2; n++, ydest++)
|
||||
{
|
||||
u8 n1 = Memory::Read_U32(addr + 0) & 0xf;
|
||||
u8 n2 = Memory::Read_U32(addr + 16) & 0xf;
|
||||
u8 n3 = Memory::Read_U32(addr + 32) & 0xf;
|
||||
u8 n4 = Memory::Read_U32(addr + 48) & 0xf;
|
||||
|
||||
tmpTexBuf32[ydest] = (u32)n1 | ((u32)n2 << 8) | ((u32)n3 << 16) | ((u32)n4 << 24);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tmpTexBuf32;
|
||||
}
|
||||
|
||||
void *readIndexedTex(u32 level, u32 texaddr, u32 bytesPerIndex)
|
||||
{
|
||||
u32 length = (gstate.texbufwidth[level] & 0x3FF) * (1 << ((gstate.texsize[level] >> 8) & 0xf));
|
||||
void *buf = NULL;
|
||||
|
||||
switch ((gstate.clutformat & 3))
|
||||
{
|
||||
case GE_CMODE_16BIT_BGR5650:
|
||||
case GE_CMODE_16BIT_ABGR5551:
|
||||
case GE_CMODE_16BIT_ABGR4444:
|
||||
{
|
||||
u16 *clut = ReadClut16();
|
||||
if (!(gstate.texmode & 1))
|
||||
{
|
||||
u32 i;
|
||||
switch (bytesPerIndex)
|
||||
{
|
||||
case 1:
|
||||
for (i = 0; i < length; i++) {
|
||||
u8 index = Memory::Read_U8(texaddr + i);
|
||||
tmpTexBuf16[i] = clut[GetClutIndex(index)];
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
for (i = 0; i < length; i++) {
|
||||
u16 index = Memory::Read_U16(texaddr + i * 2);
|
||||
tmpTexBuf16[i] = clut[GetClutIndex(index)];
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
for (i = 0; i < length; i++) {
|
||||
u32 index = Memory::Read_U32(texaddr + i * 4);
|
||||
tmpTexBuf16[i] = clut[GetClutIndex(index)];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 i, j;
|
||||
UnswizzleFromMem(texaddr, bytesPerIndex, level);
|
||||
switch (bytesPerIndex)
|
||||
{
|
||||
case 1:
|
||||
for (i = 0, j = 0; i < length; i += 4, j++)
|
||||
{
|
||||
u32 n = tmpTexBuf32[j];
|
||||
u32 k;
|
||||
for (k = 0; k < 4; k++) {
|
||||
u8 index = (n >> (k * 4)) & 0xff;
|
||||
tmpTexBuf16[i + k] = clut[GetClutIndex(index)];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
for (i = 0, j = 0; i < length; i += 2, j++)
|
||||
{
|
||||
u32 n = tmpTexBuf32[j];
|
||||
tmpTexBuf16[i + 0] = clut[GetClutIndex(n & 0xffff)];
|
||||
tmpTexBuf16[i + 1] = clut[GetClutIndex(n >> 16)];
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
for (i = 0; i < length; i++) {
|
||||
u32 n = tmpTexBuf32[i];
|
||||
tmpTexBuf16[i] = clut[GetClutIndex(n)];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
buf = tmpTexBuf16;
|
||||
}
|
||||
break;
|
||||
|
||||
case GE_CMODE_32BIT_ABGR8888:
|
||||
{
|
||||
u32 *clut = ReadClut32();
|
||||
if (!(gstate.texmode & 1))
|
||||
{
|
||||
u32 i;
|
||||
switch (bytesPerIndex)
|
||||
{
|
||||
case 1:
|
||||
for (i = 0; i < length; i++) {
|
||||
u8 index = Memory::Read_U8(texaddr + i);
|
||||
tmpTexBuf32[i] = clut[GetClutIndex(index)];
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
for (i = 0; i < length; i++) {
|
||||
u16 index = Memory::Read_U16(texaddr + i * 2);
|
||||
tmpTexBuf32[i] = clut[GetClutIndex(index)];
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
for (i = 0; i < length; i++) {
|
||||
u32 index = Memory::Read_U32(texaddr + i * 4);
|
||||
tmpTexBuf32[i] = clut[GetClutIndex(index)];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 j;
|
||||
s32 i;
|
||||
UnswizzleFromMem(texaddr, bytesPerIndex, level);
|
||||
switch (bytesPerIndex)
|
||||
{
|
||||
case 1:
|
||||
for (i = length - 4, j = (length / 4) - 1; i >= 0; i -= 4, j--)
|
||||
{
|
||||
u32 n = tmpTexBuf32[j];
|
||||
u32 k;
|
||||
for (k = 0; k < 4; k++) {
|
||||
u32 index = (n >> (k * 8)) & 0xff;
|
||||
tmpTexBuf32[i + k] = clut[GetClutIndex(index)];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
for (i = length - 2, j = (length / 2) - 1; i >= 0; i -= 2, j--)
|
||||
{
|
||||
u32 n = tmpTexBuf32[j];
|
||||
tmpTexBuf32[i + 0] = clut[GetClutIndex(n & 0xffff)];
|
||||
tmpTexBuf32[i + 1] = clut[GetClutIndex(n >> 16)];
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
for (i = 0; (u32)i < length; i++) {
|
||||
u32 n = tmpTexBuf32[i];
|
||||
tmpTexBuf32[i] = clut[GetClutIndex(n)];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
buf = tmpTexBuf32;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ERROR_LOG(G3D, "Unhandled clut texture mode %d!!!", (gstate.clutformat & 3));
|
||||
break;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
GLenum getClutDestFormat(GEPaletteFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case GE_CMODE_16BIT_ABGR4444:
|
||||
return GL_UNSIGNED_SHORT_4_4_4_4_REV;
|
||||
case GE_CMODE_16BIT_ABGR5551:
|
||||
return GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
||||
case GE_CMODE_16BIT_BGR5650:
|
||||
return GL_UNSIGNED_SHORT_5_6_5_REV;
|
||||
case GE_CMODE_32BIT_ABGR8888:
|
||||
return GL_UNSIGNED_BYTE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 texByteAlignMap[] = {2, 2, 2, 4};
|
||||
|
||||
// This should not have to be done per texture! OpenGL is silly yo
|
||||
// TODO: Dirty-check this against the current texture.
|
||||
void UpdateSamplingParams()
|
||||
@ -133,7 +373,7 @@ void UpdateSamplingParams()
|
||||
|
||||
// Convert from PSP bit order to GLES bit order
|
||||
u16 convert565(u16 c) {
|
||||
return (c >> 11) | (c & 0x07E0) | (c << 11);
|
||||
return (c >> 11) | (c & 0x07E0) | (c << 11);
|
||||
}
|
||||
|
||||
// Convert from PSP bit order to GLES bit order
|
||||
@ -146,7 +386,6 @@ u16 convert5551(u16 c) {
|
||||
return ((c & 0x8000) >> 15) | (c << 1);
|
||||
}
|
||||
|
||||
|
||||
struct DXT1Block
|
||||
{
|
||||
u8 lines[4];
|
||||
@ -192,7 +431,7 @@ void decodeDXT1Block(u32 *dst, const DXT1Block *src, int pitch)
|
||||
int green3 = ((green2 - green1) >> 1) - ((green2 - green1) >> 3);
|
||||
int red3 = ((red2 - red1) >> 1) - ((red2 - red1) >> 3);
|
||||
colors[2] = makecol(red1 + red3, green1 + green3, blue1 + blue3, 255);
|
||||
colors[3] = makecol(red2 - red3, green2 - green3, blue2 - blue3, 255);
|
||||
colors[3] = makecol(red2 - red3, green2 - green3, blue2 - blue3, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -203,7 +442,7 @@ void decodeDXT1Block(u32 *dst, const DXT1Block *src, int pitch)
|
||||
}
|
||||
|
||||
for (int y = 0; y < 4; y++)
|
||||
{
|
||||
{
|
||||
int val = src->lines[y];
|
||||
for (int x = 0; x < 4; x++)
|
||||
{
|
||||
@ -216,14 +455,13 @@ void decodeDXT1Block(u32 *dst, const DXT1Block *src, int pitch)
|
||||
|
||||
void PSPSetTexture()
|
||||
{
|
||||
if (!tempArea)
|
||||
tempArea = new u8[512*512*4*4]; // PSP maximum texture size
|
||||
|
||||
u32 texaddr = (gstate.texaddr[0] & 0xFFFFF0) | ((gstate.texbufwidth[0]<<8) & 0xFF000000);
|
||||
texaddr &= 0xFFFFFFF;
|
||||
|
||||
if (!texaddr) return;
|
||||
|
||||
u8 level = 0;
|
||||
|
||||
DEBUG_LOG(G3D,"Texture at %08x",texaddr);
|
||||
u8 *texptr = Memory::GetPointer(texaddr);
|
||||
|
||||
@ -271,16 +509,19 @@ void PSPSetTexture()
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, entry.texture);
|
||||
|
||||
int bufw = gstate.texbufwidth[0] & 0x3ff;
|
||||
u32 bufw = gstate.texbufwidth[0] & 0x3ff;
|
||||
|
||||
entry.dim = gstate.texsize[0] & 0xF0F;
|
||||
|
||||
int w = 1 << (gstate.texsize[0] & 0xf);
|
||||
int h = 1 << ((gstate.texsize[0]>>8) & 0xf);
|
||||
u32 w = 1 << (gstate.texsize[0] & 0xf);
|
||||
u32 h = 1 << ((gstate.texsize[0]>>8) & 0xf);
|
||||
|
||||
gstate.curTextureHeight=h;
|
||||
gstate.curTextureWidth=w;
|
||||
int format = gstate.texformat & 0xF;
|
||||
GLenum dstFmt = 0;
|
||||
u32 texByteAlign = 1;
|
||||
void *finalBuf = NULL;
|
||||
|
||||
DEBUG_LOG(G3D,"Texture Width %04x Height %04x Bufw %d Fmt %d", w, h, bufw, format);
|
||||
|
||||
@ -288,202 +529,180 @@ void PSPSetTexture()
|
||||
|
||||
switch (format)
|
||||
{
|
||||
case GE_TFMT_CLUT4:
|
||||
dstFmt = getClutDestFormat((GEPaletteFormat)(gstate.clutformat & 3));
|
||||
switch ((gstate.clutformat & 3))
|
||||
{
|
||||
case GE_CMODE_16BIT_BGR5650:
|
||||
case GE_CMODE_16BIT_ABGR5551:
|
||||
case GE_CMODE_16BIT_ABGR4444:
|
||||
{
|
||||
u16 *clut = ReadClut16();
|
||||
u32 clutSharingOff = 0;//gstate.mipmapShareClut ? 0 : level * 16;
|
||||
texByteAlign = 2;
|
||||
if (!(gstate.texmode & 1))
|
||||
{
|
||||
u32 i;
|
||||
u32 addr = texaddr;
|
||||
for (i = 0; i < bufw * h; i += 2)
|
||||
{
|
||||
u32 index = Memory::Read_U32(addr);
|
||||
tmpTexBuf16[i + 0] = clut[GetClutIndex((index >> 0) & 0xf) + clutSharingOff];
|
||||
tmpTexBuf16[i + 1] = clut[GetClutIndex((index >> 4) & 0xf) + clutSharingOff];
|
||||
addr++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 i, j;
|
||||
UnswizzleFromMem(texaddr, 0, level);
|
||||
for (i = 0, j = 0; i < bufw * h; i += 8, j++)
|
||||
{
|
||||
u32 n = tmpTexBuf32[j];
|
||||
u32 k, index;
|
||||
for (k = 0; k < 8; k++) {
|
||||
index = (n >> (k * 4)) & 0xf;
|
||||
tmpTexBuf16[i + k] = clut[GetClutIndex(index) + clutSharingOff];
|
||||
}
|
||||
}
|
||||
}
|
||||
finalBuf = tmpTexBuf16;
|
||||
}
|
||||
break;
|
||||
|
||||
case GE_CMODE_32BIT_ABGR8888:
|
||||
{
|
||||
u32 *clut = ReadClut32();
|
||||
u32 clutSharingOff = 0;//gstate.mipmapShareClut ? 0 : level * 16;
|
||||
if (!(gstate.texmode & 1))
|
||||
{
|
||||
u32 i;
|
||||
u32 addr = texaddr;
|
||||
for (i = 0; i < bufw * h; i += 2)
|
||||
{
|
||||
u32 index = Memory::Read_U32(addr);
|
||||
tmpTexBuf32[i + 0] = clut[GetClutIndex((index >> 0) & 0xf) + clutSharingOff];
|
||||
tmpTexBuf32[i + 1] = clut[GetClutIndex((index >> 4) & 0xf) + clutSharingOff];
|
||||
addr++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s32 i;
|
||||
u32 j;
|
||||
u32 pixels = bufw * h;
|
||||
UnswizzleFromMem(texaddr, 0, level);
|
||||
for (i = pixels - 8, j = (pixels / 8) - 1; i >= 0; i -= 8, j--)
|
||||
{
|
||||
u32 n = tmpTexBuf32[j];
|
||||
u32 k, index;
|
||||
for (k = 0; k < 8; k++) {
|
||||
index = (n >> (k * 4)) & 0xf;
|
||||
tmpTexBuf32[i + k] = clut[GetClutIndex(index) + clutSharingOff];
|
||||
}
|
||||
}
|
||||
}
|
||||
finalBuf = tmpTexBuf32;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ERROR_LOG(G3D, "Unknown CLUT4 texture mode %d", (gstate.clutformat & 3));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case GE_TFMT_CLUT8:
|
||||
finalBuf = readIndexedTex(level, texaddr, 1);
|
||||
dstFmt = getClutDestFormat((GEPaletteFormat)(gstate.clutformat & 3));
|
||||
texByteAlign = texByteAlignMap[(gstate.clutformat & 3)];
|
||||
break;
|
||||
|
||||
case GE_TFMT_CLUT16:
|
||||
finalBuf = readIndexedTex(level, texaddr, 2);
|
||||
dstFmt = getClutDestFormat((GEPaletteFormat)(gstate.clutformat & 3));
|
||||
texByteAlign = texByteAlignMap[(gstate.clutformat & 3)];
|
||||
break;
|
||||
|
||||
case GE_TFMT_CLUT32:
|
||||
finalBuf = readIndexedTex(level, texaddr, 4);
|
||||
dstFmt = getClutDestFormat((GEPaletteFormat)(gstate.clutformat & 3));
|
||||
texByteAlign = texByteAlignMap[(gstate.clutformat & 3)];
|
||||
break;
|
||||
|
||||
case GE_TFMT_4444:
|
||||
case GE_TFMT_5551:
|
||||
case GE_TFMT_5650:
|
||||
if (format == GE_TFMT_4444)
|
||||
dstFmt = GL_UNSIGNED_SHORT_4_4_4_4_REV;
|
||||
else if (format == GE_TFMT_5551)
|
||||
dstFmt = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
||||
else if (format == GE_TFMT_5650)
|
||||
dstFmt = GL_UNSIGNED_SHORT_5_6_5_REV;
|
||||
texByteAlign = 2;
|
||||
|
||||
if (!(gstate.texmode & 1))
|
||||
{
|
||||
u16 *dst = (u16*)tempArea;
|
||||
u16 *src = (u16*)texptr;
|
||||
|
||||
int fmt = GL_UNSIGNED_SHORT_5_6_5;
|
||||
int internal_format = GL_RGBA;
|
||||
u16 (*convFunc)(u16);
|
||||
switch (format)
|
||||
{
|
||||
case GE_TFMT_4444: fmt = GL_UNSIGNED_SHORT_4_4_4_4; convFunc = &convert4444; break;
|
||||
case GE_TFMT_5551: fmt = GL_UNSIGNED_SHORT_5_5_5_1; convFunc = &convert5551; break;
|
||||
case GE_TFMT_5650: fmt = GL_UNSIGNED_SHORT_5_6_5; convFunc = &convert565; internal_format = GL_RGB; break;
|
||||
}
|
||||
|
||||
if (gstate.texmode & 1) //Swizzled!
|
||||
{
|
||||
for (int y=0; y<h/8; y++)
|
||||
{
|
||||
for (int x=0; x<w/8; x++)
|
||||
{
|
||||
for (int yy=0; yy<8; yy++)
|
||||
{
|
||||
for (int xx=0; xx<8; xx++)
|
||||
{
|
||||
dst[(y*8+yy)*w + x*8 + xx] = convFunc(src[(y*(bufw/8)+x)*8 + (yy*8+xx)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int y=0; y<h; y++)
|
||||
{
|
||||
const u16 *s = src + bufw * y;
|
||||
u16 *d = dst + y * w;
|
||||
for (int x = 0; x < w; x++)
|
||||
*d++ = convFunc(*s++);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This will have to be redone for OpenGL ES 2.0.
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, internal_format, fmt, (GLvoid*)tempArea);
|
||||
break;
|
||||
}
|
||||
|
||||
case GE_TFMT_CLUT4:
|
||||
{
|
||||
u32 *dst = (u32*)tempArea;
|
||||
u8 *src = (u8*)texptr;
|
||||
if (gstate.texmode & 1) //Swizzled!
|
||||
{
|
||||
for (int y=0; y<h/8; y++)
|
||||
{
|
||||
for (int x=0; x<w/32; x++)
|
||||
{
|
||||
for (int yy=0; yy<8; yy++)
|
||||
{
|
||||
for (int xx=0; xx<32; xx++)
|
||||
{
|
||||
int idx = src[(y*bufw*4+x*16*8) + (yy*16+xx/2)];
|
||||
if (xx&1) idx>>=4; else idx&=0xF;
|
||||
dst[(y*8+yy)*w + x*32 + xx] = PaletteLoad(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int y=0; y<h; y++)
|
||||
{
|
||||
for (int x=0; x<w; x++)
|
||||
{
|
||||
int idx = *src;
|
||||
if (x&1) idx >>= 4; else idx &= 0xF;
|
||||
dst[x] = PaletteLoad(idx);
|
||||
if (x&1)
|
||||
src++;
|
||||
}
|
||||
src -= w/2;
|
||||
src += bufw/2;
|
||||
dst += w;
|
||||
}
|
||||
}
|
||||
int fmt = GL_UNSIGNED_BYTE;
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, fmt, (GLvoid*)tempArea);
|
||||
break;
|
||||
}
|
||||
|
||||
case GE_TFMT_CLUT8:
|
||||
{
|
||||
u32 *dst = (u32*)tempArea;
|
||||
u8 *src = (u8*)texptr;
|
||||
if (gstate.texmode & 1) //Swizzled!
|
||||
{
|
||||
for (int y=0; y<h/8; y++)
|
||||
{
|
||||
for (int x=0; x<w/16; x++)
|
||||
{
|
||||
for (int yy=0; yy<8; yy++)
|
||||
{
|
||||
for (int xx=0; xx<16; xx++)
|
||||
{
|
||||
int idx = src[(y*bufw*8+x*16*8) + (yy*16+xx)];
|
||||
dst[(y*8+yy)*w + x*16 + xx] = PaletteLoad(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int y=0; y<h; y++)
|
||||
{
|
||||
for (int x=0; x<w; x++)
|
||||
{
|
||||
int idx = src[x];
|
||||
dst[x] = PaletteLoad(idx);
|
||||
}
|
||||
src += bufw;
|
||||
dst += w;
|
||||
}
|
||||
}
|
||||
int fmt = GL_UNSIGNED_BYTE;
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, fmt, (GLvoid*)tempArea);
|
||||
break;
|
||||
u32 len = (bufw > w ? bufw : w) * h;
|
||||
u32 i;
|
||||
for (i = 0; i < len; i++)
|
||||
tmpTexBuf16[i] = Memory::Read_U16(texaddr + i * 2);
|
||||
finalBuf = tmpTexBuf16;
|
||||
}
|
||||
else
|
||||
finalBuf = UnswizzleFromMem(texaddr, 2, level);
|
||||
break;
|
||||
|
||||
case GE_TFMT_8888:
|
||||
dstFmt = GL_UNSIGNED_BYTE;
|
||||
if (!(gstate.texmode & 1))
|
||||
{
|
||||
u32 *dst = (u32*)tempArea;
|
||||
u32 *src = (u32*)texptr;
|
||||
if (gstate.texmode & 1) //Swizzled!
|
||||
{
|
||||
for (int y=0; y<h/8; y++)
|
||||
{
|
||||
int i = y*bufw*8;
|
||||
for (int x=0; x<w/4; x++)
|
||||
{
|
||||
for (int yy=0; yy<8; yy++)
|
||||
{
|
||||
for (int xx=0; xx<4; xx++)
|
||||
{
|
||||
dst[(y*8+yy)*w + x*4 + xx] = src[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int y=0; y<h; y++)
|
||||
{
|
||||
memcpy(dst+y*w,src+bufw*y,4*bufw);
|
||||
}
|
||||
}
|
||||
int fmt = GL_UNSIGNED_BYTE;
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, fmt, (GLvoid*)tempArea);
|
||||
break;
|
||||
u32 len = bufw * h;
|
||||
u32 i;
|
||||
for (i = 0; i < len; i++)
|
||||
tmpTexBuf32[i] = Memory::Read_U32(texaddr + i * 4);
|
||||
finalBuf = tmpTexBuf32;
|
||||
}
|
||||
else
|
||||
finalBuf = UnswizzleFromMem(texaddr, 4, level);
|
||||
break;
|
||||
|
||||
case GE_TFMT_DXT1:
|
||||
ERROR_LOG(G3D, "Partial DXT1 texture decoding");
|
||||
dstFmt = GL_UNSIGNED_BYTE;
|
||||
{
|
||||
// THIS IS VERY BROKEN but can be debugged! :)
|
||||
u32 *dst = (u32*)tempArea;
|
||||
u32 *dst = tmpTexBuf32;
|
||||
DXT1Block *src = (DXT1Block*)texptr;
|
||||
|
||||
for (int y=0; y<h/4; y++)
|
||||
for (u32 y=0; y<h/4; y++)
|
||||
{
|
||||
int i = y*w/4;
|
||||
for (int x=0; x<w/4; x++)
|
||||
u32 i = y*w/4;
|
||||
for (u32 x=0; x<w/4; x++)
|
||||
{
|
||||
decodeDXT1Block(dst + w*4 * y * 4 + x * 4, src + i, w);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
int fmt = GL_UNSIGNED_BYTE;
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, fmt, (GLvoid*)tempArea);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case GE_TFMT_DXT3:
|
||||
case GE_TFMT_DXT5:
|
||||
ERROR_LOG(G3D, "Unhandled compressed texture!");
|
||||
break;
|
||||
|
||||
default:
|
||||
ERROR_LOG(G3D, "Unknown Texture Format %i, not setting texture",format);
|
||||
PanicAlert("ANOTHER tex format??");
|
||||
ERROR_LOG(G3D, "Unknown Texture Format %d!!!", format);
|
||||
return;
|
||||
}
|
||||
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, bufw);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, texByteAlign);
|
||||
glPixelStorei(GL_PACK_ROW_LENGTH, bufw);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, texByteAlign);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, dstFmt, finalBuf);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
@ -492,5 +711,10 @@ void PSPSetTexture()
|
||||
// glGenerateMipmap(GL_TEXTURE_2D);
|
||||
UpdateSamplingParams();
|
||||
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
|
||||
cache[texaddr] = entry;
|
||||
}
|
||||
|
@ -444,5 +444,12 @@ enum GELogicOp
|
||||
GE_LOGIC_DRAWINVERTED = 12,
|
||||
};
|
||||
|
||||
enum GEPaletteFormat
|
||||
{
|
||||
GE_CMODE_16BIT_BGR5650,
|
||||
GE_CMODE_16BIT_ABGR5551,
|
||||
GE_CMODE_16BIT_ABGR4444,
|
||||
GE_CMODE_32BIT_ABGR8888
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user