Implement EXT_texture_format_BGRA8888 and EXT_read_format_bgra

Trac #13050, Issue=21 Original Author: Vladimir Vukicevic Signed-off-by: Daniel Koch git-svn-id: https://angleproject.googlecode.com/svn/trunk@370 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent bc3699da
......@@ -325,6 +325,7 @@ bool Blit::setFormatConvertShaders(GLenum destFormat)
{
default: UNREACHABLE();
case GL_RGBA:
case GL_BGRA_EXT:
case GL_RGB:
case GL_ALPHA:
okay = okay && setPixelShader(SHADER_PS_COMPONENTMASK);
......@@ -351,6 +352,7 @@ bool Blit::setFormatConvertShaders(GLenum destFormat)
{
default: UNREACHABLE();
case GL_RGBA:
case GL_BGRA_EXT:
psConst0[X] = 1;
psConst0[Z] = 1;
break;
......
......@@ -1945,6 +1945,19 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum
for (int j = 0; j < rect.bottom - rect.top; j++)
{
if (desc.Format == D3DFMT_A8R8G8B8 &&
format == GL_BGRA_EXT &&
type == GL_UNSIGNED_BYTE)
{
// Fast path for EXT_read_format_bgra, given
// an RGBA source buffer. Note that buffers with no
// alpha go through the slow path below.
memcpy(dest + j * outputPitch,
source + j * lock.Pitch,
(rect.right - rect.left) * 4);
continue;
}
for (int i = 0; i < rect.right - rect.left; i++)
{
float r;
......@@ -2033,6 +2046,46 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum
default: UNREACHABLE();
}
break;
case GL_BGRA_EXT:
switch (type)
{
case GL_UNSIGNED_BYTE:
dest[4 * i + j * outputPitch + 0] = (unsigned char)(255 * b + 0.5f);
dest[4 * i + j * outputPitch + 1] = (unsigned char)(255 * g + 0.5f);
dest[4 * i + j * outputPitch + 2] = (unsigned char)(255 * r + 0.5f);
dest[4 * i + j * outputPitch + 3] = (unsigned char)(255 * a + 0.5f);
break;
case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
// According to the desktop GL spec in the "Transfer of Pixel Rectangles" section
// this type is packed as follows:
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// --------------------------------------------------------------------------------
// | 4th | 3rd | 2nd | 1st component |
// --------------------------------------------------------------------------------
// in the case of BGRA_EXT, B is the first component, G the second, and so forth.
dest16[i + j * outputPitch / sizeof(unsigned short)] =
((unsigned short)(15 * a + 0.5f) << 12)|
((unsigned short)(15 * r + 0.5f) << 8) |
((unsigned short)(15 * g + 0.5f) << 4) |
((unsigned short)(15 * b + 0.5f) << 0);
break;
case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
// According to the desktop GL spec in the "Transfer of Pixel Rectangles" section
// this type is packed as follows:
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// --------------------------------------------------------------------------------
// | 4th | 3rd | 2nd | 1st component |
// --------------------------------------------------------------------------------
// in the case of BGRA_EXT, B is the first component, G the second, and so forth.
dest16[i + j * outputPitch / sizeof(unsigned short)] =
((unsigned short)( a + 0.5f) << 15) |
((unsigned short)(31 * r + 0.5f) << 10) |
((unsigned short)(31 * g + 0.5f) << 5) |
((unsigned short)(31 * b + 0.5f) << 0);
break;
default: UNREACHABLE();
}
break;
case GL_RGB: // IMPLEMENTATION_COLOR_READ_FORMAT
switch (type)
{
......@@ -2730,6 +2783,8 @@ void Context::setVertexAttrib(GLuint index, const GLfloat *values)
void Context::initExtensionString()
{
mExtensionString += "GL_OES_packed_depth_stencil ";
mExtensionString += "GL_EXT_texture_format_BGRA8888 ";
mExtensionString += "GL_EXT_read_format_bgra ";
if (mBufferBackEnd->supportIntIndices())
{
......
......@@ -198,6 +198,12 @@ void Texture::loadImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei
const unsigned short *source16 = reinterpret_cast<const unsigned short*>(source);
unsigned char *dest = static_cast<unsigned char*>(output) + (y + yoffset) * outputPitch + xoffset * 4;
// fast path for EXT_texture_format_BGRA8888
if (format == GL_BGRA_EXT && type == GL_UNSIGNED_BYTE) {
memcpy(dest, source, width*4);
continue;
}
for (int x = 0; x < width; x++)
{
unsigned char r;
......
......@@ -3491,6 +3491,17 @@ void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLe
return error(GL_INVALID_OPERATION);
}
break;
case GL_BGRA_EXT:
switch (type)
{
case GL_UNSIGNED_BYTE:
case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
break;
default:
return error(GL_INVALID_OPERATION);
}
break;
case gl::IMPLEMENTATION_COLOR_READ_FORMAT:
switch (type)
{
......@@ -3973,6 +3984,15 @@ void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GL
return error(GL_INVALID_ENUM);
}
break;
case GL_BGRA_EXT:
switch (type)
{
case GL_UNSIGNED_BYTE:
break;
default:
return error(GL_INVALID_ENUM);
}
break;
default:
return error(GL_INVALID_VALUE);
}
......
......@@ -196,6 +196,7 @@ int ComputePixelSize(GLenum format, GLenum type)
case GL_LUMINANCE_ALPHA: return sizeof(unsigned char) * 2;
case GL_RGB: return sizeof(unsigned char) * 3;
case GL_RGBA: return sizeof(unsigned char) * 4;
case GL_BGRA_EXT: return sizeof(unsigned char) * 4;
default: UNREACHABLE();
}
break;
......@@ -228,6 +229,7 @@ bool CheckTextureFormatType(GLenum format, GLenum type)
switch (format)
{
case GL_RGBA:
case GL_BGRA_EXT:
case GL_RGB:
case GL_ALPHA:
case GL_LUMINANCE:
......
......@@ -11,6 +11,7 @@
#define GL_APICALL
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <d3d9.h>
namespace gl
......
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