Slightly optimize uploading D3DFMT_A8R8G8B8 data to textures.

This is especially perceptible for "big" textures, so e.g. EFB copies to RAM should be a bit faster now.


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5531 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
NeoBrainX 2010-05-29 09:32:44 +00:00
parent ceabf90bda
commit 4f10ded2b6
1 changed files with 15 additions and 7 deletions

View File

@ -103,12 +103,12 @@ LPDIRECT3DTEXTURE9 CreateTexture2D(const u8* buffer, const int width, const int
break; break;
case D3DFMT_A8R8G8B8: case D3DFMT_A8R8G8B8:
{ {
/*if(Lock.Pitch == width * 4) if(pitch * 4 == Lock.Pitch && !swap_r_b)
{ {
memcpy(Lock.pBits,buffer,width*height*4); memcpy(Lock.pBits,buffer,Lock.Pitch*height);
} }
else else
{*/ {
u32* pIn = pBuffer; u32* pIn = pBuffer;
if (!swap_r_b) { if (!swap_r_b) {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
@ -131,7 +131,7 @@ LPDIRECT3DTEXTURE9 CreateTexture2D(const u8* buffer, const int width, const int
pIn += pitch; pIn += pitch;
} }
} }
//} }
} }
break; break;
case D3DFMT_DXT1: case D3DFMT_DXT1:
@ -179,19 +179,27 @@ void ReplaceTexture2D(LPDIRECT3DTEXTURE9 pTexture, const u8* buffer, const int w
switch (fmt) switch (fmt)
{ {
case D3DFMT_A8R8G8B8: case D3DFMT_A8R8G8B8:
if (!swap_r_b) { if(pitch * 4 == Lock.Pitch && !swap_r_b)
{
memcpy(Lock.pBits, pBuffer, Lock.Pitch*height);
}
else if (!swap_r_b)
{
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
u32 *pBits = (u32*)((u8*)Lock.pBits + (y * Lock.Pitch)); u32 *pBits = (u32*)((u8*)Lock.pBits + (y * Lock.Pitch));
memcpy(pBits, pIn, width * 4); memcpy(pBits, pIn, width * 4);
pIn += pitch; pIn += pitch;
} }
} else { }
else
{
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
u8 *pIn8 = (u8 *)pIn; u8 *pIn8 = (u8 *)pIn;
u8 *pBits = (u8 *)((u8*)Lock.pBits + (y * Lock.Pitch)); u8 *pBits = (u8 *)((u8*)Lock.pBits + (y * Lock.Pitch));
for (int x = 0; x < width * 4; x += 4) { for (int x = 0; x < width * 4; x += 4)
{
pBits[x + 0] = pIn8[x + 2]; pBits[x + 0] = pIn8[x + 2];
pBits[x + 1] = pIn8[x + 1]; pBits[x + 1] = pIn8[x + 1];
pBits[x + 2] = pIn8[x + 0]; pBits[x + 2] = pIn8[x + 0];