New compact texture type for OGL/D3D: IA8

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2233 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
XTra.KrazzY 2009-02-13 14:14:45 +00:00
parent a55e672493
commit acb3d1b23d
5 changed files with 61 additions and 35 deletions

View File

@ -274,13 +274,6 @@ inline void decodebytesIA4(u32 *dst, const u8 *src)
} }
} }
//inline void decodebytesIA8(u32 *dst, const u16 *src, int numpixels)
inline void decodebytesIA8(u32 *dst, const u16 *src)
{
for (int x = 0; x < 4; x++)
dst[x] = decodeIA8(Common::swap16(src[x]));
}
//inline void decodebytesRGB5A3(u32 *dst, const u16 *src, int numpixels) //inline void decodebytesRGB5A3(u32 *dst, const u16 *src, int numpixels)
inline void decodebytesRGB5A3(u32 *dst, const u16 *src) inline void decodebytesRGB5A3(u32 *dst, const u16 *src)
{ {
@ -414,11 +407,15 @@ PC_TexFormat TexDecoder_Decode(u8 *dst, const u8 *src, int width, int height, in
{ {
for (int y = 0; y < height; y += 4) for (int y = 0; y < height; y += 4)
for (int x = 0; x < width; x += 4) for (int x = 0; x < width; x += 4)
for (int iy = 0; iy < 4; iy++, src += 8) for (int iy = 0; iy < 4; iy++, src += 8) {
//decodebytesIA8((u32*)dst+(y+iy)*width+x, (u16*)src, 4); u16 *ptr = (u16 *)dst+(y+iy)*width+x;
decodebytesIA8((u32*)dst+(y+iy)*width+x, (u16*)src); u16 *s = (u16 *)src;
for(int j = 0; j < 4; j++)
*ptr++ = Common::swap16(*s++);
} }
return PC_TEX_FMT_BGRA32;
}
return PC_TEX_FMT_IA8;
case GX_TF_C14X2: case GX_TF_C14X2:
{ {
for (int y = 0; y < height; y += 4) for (int y = 0; y < height; y += 4)

View File

@ -74,6 +74,7 @@ enum PC_TexFormat
PC_TEX_FMT_NONE = 0, PC_TEX_FMT_NONE = 0,
PC_TEX_FMT_BGRA32, PC_TEX_FMT_BGRA32,
PC_TEX_FMT_I8, PC_TEX_FMT_I8,
PC_TEX_FMT_IA8,
PC_TEX_FMT_RGB565, PC_TEX_FMT_RGB565,
}; };

View File

@ -28,6 +28,12 @@ LPDIRECT3DTEXTURE9 CreateTexture2D(const u8* buffer, const int width, const int
// crazy bitmagic, sorry :) // crazy bitmagic, sorry :)
bool isPow2 = !((width&(width-1)) || (height&(height-1))); bool isPow2 = !((width&(width-1)) || (height&(height-1)));
bool bExpand = false;
if(fmt == D3DFMT_A8P8) {
fmt = D3DFMT_A8L8;
bExpand = true;
}
HRESULT hr; HRESULT hr;
// TODO(ector): allow mipmaps for non-pow textures on newer cards? // TODO(ector): allow mipmaps for non-pow textures on newer cards?
@ -71,7 +77,9 @@ LPDIRECT3DTEXTURE9 CreateTexture2D(const u8* buffer, const int width, const int
break; break;
case D3DFMT_A8L8: case D3DFMT_A8L8:
{ {
if(bExpand) { // I8
const u8 *pIn = buffer; const u8 *pIn = buffer;
// TODO(XK): Find a better way that does not involve either unpacking // TODO(XK): Find a better way that does not involve either unpacking
// or downsampling (i.e. A4L4) // or downsampling (i.e. A4L4)
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
@ -83,6 +91,16 @@ LPDIRECT3DTEXTURE9 CreateTexture2D(const u8* buffer, const int width, const int
} }
pIn += pitch; pIn += pitch;
} }
} else { // IA8
const u16 *pIn = (u16*)buffer;
for (int y = 0; y < height; y++)
{
u16* pBits = (u16*)((u8*)Lock.pBits + (y * Lock.Pitch));
memcpy(pBits, pIn, width * 2);
pIn += pitch;
}
}
} }
break; break;
case D3DFMT_A8R8G8B8: case D3DFMT_A8R8G8B8:

View File

@ -180,6 +180,9 @@ void TextureCache::Load(int stage, u32 address, int width, int height, int forma
d3d_fmt = D3DFMT_R5G6B5; d3d_fmt = D3DFMT_R5G6B5;
break; break;
case PC_TEX_FMT_I8: case PC_TEX_FMT_I8:
d3d_fmt = D3DFMT_A8P8;
break;
case PC_TEX_FMT_IA8:
d3d_fmt = D3DFMT_A8L8; d3d_fmt = D3DFMT_A8L8;
break; break;
} }

View File

@ -346,6 +346,7 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
int gl_iformat; int gl_iformat;
int gl_type; int gl_type;
switch (dfmt) { switch (dfmt) {
default:
case PC_TEX_FMT_NONE: case PC_TEX_FMT_NONE:
PanicAlert("Invalid PC texture format %i", dfmt); PanicAlert("Invalid PC texture format %i", dfmt);
case PC_TEX_FMT_BGRA32: case PC_TEX_FMT_BGRA32:
@ -358,6 +359,11 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
gl_iformat = GL_INTENSITY; gl_iformat = GL_INTENSITY;
gl_type = GL_UNSIGNED_BYTE; gl_type = GL_UNSIGNED_BYTE;
break; break;
case PC_TEX_FMT_IA8:
gl_format = GL_LUMINANCE_ALPHA;
gl_iformat = GL_LUMINANCE8_ALPHA8;
gl_type = GL_UNSIGNED_BYTE;
break;
case PC_TEX_FMT_RGB565: case PC_TEX_FMT_RGB565:
gl_format = GL_RGB; gl_format = GL_RGB;
gl_iformat = GL_RGB; gl_iformat = GL_RGB;
@ -367,6 +373,7 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
if (!entry.isNonPow2 && ((tm0.min_filter & 3) == 1 || (tm0.min_filter & 3) == 2)) { if (!entry.isNonPow2 && ((tm0.min_filter & 3) == 1 || (tm0.min_filter & 3) == 2)) {
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, 0, gl_iformat, width, height, 0, gl_format, gl_type, temp); glTexImage2D(GL_TEXTURE_2D, 0, gl_iformat, width, height, 0, gl_format, gl_type, temp);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
entry.bHaveMipMaps = true; entry.bHaveMipMaps = true;
} }