Fast path for BGRA to RGBA readPixels conversions.

From http://code.google.com/p/angleproject/source/detail?r=1999 TRAC #22825 Signed-off-by: Geoff Lang Signed-off-by: Shannon Woods Author: Jamie Madill git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@2033 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 5d75083a
...@@ -3385,6 +3385,25 @@ void Renderer11::readTextureData(ID3D11Texture2D *texture, unsigned int subResou ...@@ -3385,6 +3385,25 @@ void Renderer11::readTextureData(ID3D11Texture2D *texture, unsigned int subResou
memcpy(dest + j * outputPitch, source + j * inputPitch, area.width * fastPixelSize); memcpy(dest + j * outputPitch, source + j * inputPitch, area.width * fastPixelSize);
} }
} }
else if (textureDesc.Format == DXGI_FORMAT_B8G8R8A8_UNORM &&
format == GL_RGBA &&
type == GL_UNSIGNED_BYTE)
{
// Fast path for swapping red with blue
unsigned char *dest = static_cast<unsigned char*>(pixels);
for (int j = 0; j < area.height; j++)
{
for (int i = 0; i < area.width; i++)
{
unsigned int argb = *(unsigned int*)(source + 4 * i + j * inputPitch);
*(unsigned int*)(dest + 4 * i + j * outputPitch) =
(argb & 0xFF00FF00) | // Keep alpha and green
(argb & 0x00FF0000) >> 16 | // Move red to blue
(argb & 0x000000FF) << 16; // Move blue to red
}
}
}
else else
{ {
gl::Color pixelColor; gl::Color pixelColor;
......
...@@ -2841,6 +2841,21 @@ void Renderer9::readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsiz ...@@ -2841,6 +2841,21 @@ void Renderer9::readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsiz
(rect.right - rect.left) * fastPixelSize); (rect.right - rect.left) * fastPixelSize);
continue; continue;
} }
else if (desc.Format == D3DFMT_A8R8G8B8 &&
format == GL_RGBA &&
type == GL_UNSIGNED_BYTE)
{
// Fast path for swapping red with blue
for (int i = 0; i < rect.right - rect.left; i++)
{
unsigned int argb = *(unsigned int*)(source + 4 * i + j * inputPitch);
*(unsigned int*)(dest + 4 * i + j * outputPitch) =
(argb & 0xFF00FF00) | // Keep alpha and green
(argb & 0x00FF0000) >> 16 | // Move red to blue
(argb & 0x000000FF) << 16; // Move blue to red
}
continue;
}
for (int i = 0; i < rect.right - rect.left; i++) for (int i = 0; i < rect.right - rect.left; i++)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment