Commit edb2e172 by Nicolas Capens

Implement glReadPixels() for RGBA formats.

Change-Id: Ia2f7d1db3b2a0f075326c3331125ca347f42932d Reviewed-on: https://swiftshader-review.googlesource.com/2756Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent ef77ac10
...@@ -1952,9 +1952,14 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, ...@@ -1952,9 +1952,14 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
unsigned short *dest16 = (unsigned short*)dest; unsigned short *dest16 = (unsigned short*)dest;
unsigned int *dest32 = (unsigned int*)dest; unsigned int *dest32 = (unsigned int*)dest;
if(renderTarget->getInternalFormat() == sw::FORMAT_A8R8G8B8 && if(renderTarget->getInternalFormat() == sw::FORMAT_A8B8G8R8 &&
format == GL_RGBA && type == GL_UNSIGNED_BYTE) format == GL_RGBA && type == GL_UNSIGNED_BYTE)
{ {
memcpy(dest, source, (rect.x1 - rect.x0) * 4);
}
else if(renderTarget->getInternalFormat() == sw::FORMAT_A8R8G8B8 &&
format == GL_RGBA && type == GL_UNSIGNED_BYTE)
{
for(int i = 0; i < rect.x1 - rect.x0; i++) for(int i = 0; i < rect.x1 - rect.x0; i++)
{ {
unsigned int argb = *(unsigned int*)(source + 4 * i); unsigned int argb = *(unsigned int*)(source + 4 * i);
...@@ -2038,6 +2043,16 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, ...@@ -2038,6 +2043,16 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
r = (argb & 0x00FF0000) * (1.0f / 0x00FF0000); r = (argb & 0x00FF0000) * (1.0f / 0x00FF0000);
} }
break; break;
case sw::FORMAT_A8B8G8R8:
{
unsigned int abgr = *(unsigned int*)(source + 4 * i);
a = (abgr & 0xFF000000) * (1.0f / 0xFF000000);
b = (abgr & 0x00FF0000) * (1.0f / 0x00FF0000);
g = (abgr & 0x0000FF00) * (1.0f / 0x0000FF00);
r = (abgr & 0x000000FF) * (1.0f / 0x000000FF);
}
break;
case sw::FORMAT_X8R8G8B8: case sw::FORMAT_X8R8G8B8:
{ {
unsigned int xrgb = *(unsigned int*)(source + 4 * i); unsigned int xrgb = *(unsigned int*)(source + 4 * i);
...@@ -2048,6 +2063,16 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, ...@@ -2048,6 +2063,16 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
r = (xrgb & 0x00FF0000) * (1.0f / 0x00FF0000); r = (xrgb & 0x00FF0000) * (1.0f / 0x00FF0000);
} }
break; break;
case sw::FORMAT_X8B8G8R8:
{
unsigned int xbgr = *(unsigned int*)(source + 4 * i);
a = 1.0f;
b = (xbgr & 0x00FF0000) * (1.0f / 0x00FF0000);
g = (xbgr & 0x0000FF00) * (1.0f / 0x0000FF00);
r = (xbgr & 0x000000FF) * (1.0f / 0x000000FF);
}
break;
case sw::FORMAT_A2R10G10B10: case sw::FORMAT_A2R10G10B10:
{ {
unsigned int argb = *(unsigned int*)(source + 4 * i); unsigned int argb = *(unsigned int*)(source + 4 * i);
......
...@@ -2597,9 +2597,14 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, ...@@ -2597,9 +2597,14 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
unsigned short *dest16 = (unsigned short*)dest; unsigned short *dest16 = (unsigned short*)dest;
unsigned int *dest32 = (unsigned int*)dest; unsigned int *dest32 = (unsigned int*)dest;
if(renderTarget->getInternalFormat() == sw::FORMAT_A8R8G8B8 && if(renderTarget->getInternalFormat() == sw::FORMAT_A8B8G8R8 &&
format == GL_RGBA && type == GL_UNSIGNED_BYTE) format == GL_RGBA && type == GL_UNSIGNED_BYTE)
{ {
memcpy(dest, source, (rect.x1 - rect.x0) * 4);
}
else if(renderTarget->getInternalFormat() == sw::FORMAT_A8R8G8B8 &&
format == GL_RGBA && type == GL_UNSIGNED_BYTE)
{
for(int i = 0; i < rect.x1 - rect.x0; i++) for(int i = 0; i < rect.x1 - rect.x0; i++)
{ {
unsigned int argb = *(unsigned int*)(source + 4 * i); unsigned int argb = *(unsigned int*)(source + 4 * i);
...@@ -2693,6 +2698,16 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, ...@@ -2693,6 +2698,16 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
r = (argb & 0x00FF0000) * (1.0f / 0x00FF0000); r = (argb & 0x00FF0000) * (1.0f / 0x00FF0000);
} }
break; break;
case sw::FORMAT_A8B8G8R8:
{
unsigned int abgr = *(unsigned int*)(source + 4 * i);
a = (abgr & 0xFF000000) * (1.0f / 0xFF000000);
b = (abgr & 0x00FF0000) * (1.0f / 0x00FF0000);
g = (abgr & 0x0000FF00) * (1.0f / 0x0000FF00);
r = (abgr & 0x000000FF) * (1.0f / 0x000000FF);
}
break;
case sw::FORMAT_X8R8G8B8: case sw::FORMAT_X8R8G8B8:
{ {
unsigned int xrgb = *(unsigned int*)(source + 4 * i); unsigned int xrgb = *(unsigned int*)(source + 4 * i);
...@@ -2703,6 +2718,16 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, ...@@ -2703,6 +2718,16 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
r = (xrgb & 0x00FF0000) * (1.0f / 0x00FF0000); r = (xrgb & 0x00FF0000) * (1.0f / 0x00FF0000);
} }
break; break;
case sw::FORMAT_X8B8G8R8:
{
unsigned int xbgr = *(unsigned int*)(source + 4 * i);
a = 1.0f;
b = (xbgr & 0x00FF0000) * (1.0f / 0x00FF0000);
g = (xbgr & 0x0000FF00) * (1.0f / 0x0000FF00);
r = (xbgr & 0x000000FF) * (1.0f / 0x000000FF);
}
break;
case sw::FORMAT_A2R10G10B10: case sw::FORMAT_A2R10G10B10:
{ {
unsigned int argb = *(unsigned int*)(source + 4 * i); unsigned int argb = *(unsigned int*)(source + 4 * i);
...@@ -2792,7 +2817,7 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, ...@@ -2792,7 +2817,7 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
switch(type) switch(type)
{ {
case GL_UNSIGNED_SHORT_5_6_5: case GL_UNSIGNED_SHORT_5_6_5:
dest16[i] = dest16[i] =
((unsigned short)(31 * b + 0.5f) << 0) | ((unsigned short)(31 * b + 0.5f) << 0) |
((unsigned short)(63 * g + 0.5f) << 5) | ((unsigned short)(63 * g + 0.5f) << 5) |
((unsigned short)(31 * r + 0.5f) << 11); ((unsigned short)(31 * r + 0.5f) << 11);
......
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