Commit 2b15062b by Mohan Maiya Committed by Commit Bot

Allow more formats as texture attachments in GLES 1

This change allows all formats in the GLES 1.1 spec, table 3.4 to be used as a texture attachment. Also normalize values passed into glColorPointer if the format is of type GL_UNSIGNED_BYTE. These changes are needed for the android app, Kick the Buddy to render correctly. Bug: angleproject:5599 Tests: *DrawTextureTest.ColorArrayDifferentTypes* *FramebufferObjectTest.TextureObjectDifferentFormats* Change-Id: Ie9d27fc24d94106651262cf9b2080dd3f05af1c5 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2690920 Commit-Queue: Mohan Maiya <m.maiya@samsung.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 545d0051
......@@ -100,8 +100,10 @@ void Context::color4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
void Context::colorPointer(GLint size, VertexAttribType type, GLsizei stride, const void *ptr)
{
vertexAttribPointer(vertexArrayIndex(ClientVertexArrayType::Color), size, type, GL_FALSE,
stride, ptr);
// Note that we normalize data for UnsignedByte types. This is to match the behavior
// of current native GLES drivers.
vertexAttribPointer(vertexArrayIndex(ClientVertexArrayType::Color), size, type,
type == VertexAttribType::UnsignedByte, stride, ptr);
}
void Context::depthRangex(GLfixed n, GLfixed f)
......
......@@ -1018,13 +1018,13 @@ static InternalFormatInfoMap BuildInternalFormatInfoMap()
AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>, AlwaysSupported, RequireExt<&Extensions::textureRG>, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, RequireExt<&Extensions::textureNorm16>, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireES<2, 0>, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_RGB, false, 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireES<2, 0>, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireESOrExt<2, 0, &Extensions::framebufferObjectOES>, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_RGB, false, 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireESOrExt<2, 0, &Extensions::framebufferObjectOES>, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_RGB, false, 10, 10, 10, 0, 0, GL_RGB, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormat2101010REV>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_RGBA, false, 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireES<2, 0>, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_RGBA, false, 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireES<2, 0>, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireES<2, 0>, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_RGBA, false, 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireESOrExt<2, 0, &Extensions::framebufferObjectOES>, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_RGBA, false, 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireESOrExt<2, 0, &Extensions::framebufferObjectOES>, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireESOrExt<2, 0, &Extensions::framebufferObjectOES>, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, RequireExt<&Extensions::textureNorm16>, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_RGBA, false, 10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormat2101010REV>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
......
......@@ -133,4 +133,59 @@ TEST_P(DrawTextureTest, ColorArrayNotUsed)
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
// Tests that values of differenty types are properly normalized with glColorPointer
TEST_P(DrawTextureTest, ColorArrayDifferentTypes)
{
constexpr GLubyte kTextureColorData[] = {0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF,
0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF};
constexpr GLfloat kVertexPtrData[] = {-1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f};
constexpr GLfloat kTexCoordPtrData[] = {0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f};
constexpr GLubyte kGLubyteData[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
constexpr GLfloat kGLfloatData[] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
constexpr GLfixed kGLfixedData[] = {0x10000, 0x10000, 0x10000, 0x10000, 0x10000, 0x10000,
0x10000, 0x10000, 0x10000, 0x10000, 0x10000, 0x10000,
0x10000, 0x10000, 0x10000, 0x10000};
// We check a pixel coordinate at the border of where linear interpolation starts as
// we fail to get correct interpolated values when we do not normalize the GLbyte values.
constexpr GLint kCheckedPixelX = 16;
constexpr GLint kCheckedPixelY = 8;
constexpr unsigned int kPixelTolerance = 10u;
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, kTextureColorData);
glVertexPointer(2, GL_FLOAT, 0, kVertexPtrData);
glTexCoordPointer(2, GL_FLOAT, 0, kTexCoordPtrData);
// Ensure the results do not change unexpectedly regardless of the color data format
// Test GLubyte
glColorPointer(4, GL_UNSIGNED_BYTE, 0, kGLubyteData);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_NEAR(kCheckedPixelX, kCheckedPixelY, GLColor::red, kPixelTolerance);
// Test GLfloat
glColorPointer(4, GL_FLOAT, 0, kGLfloatData);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_NEAR(kCheckedPixelX, kCheckedPixelY, GLColor::red, kPixelTolerance);
// Test GLfixed
glColorPointer(4, GL_FIXED, 0, kGLfixedData);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_NEAR(kCheckedPixelX, kCheckedPixelY, GLColor::red, kPixelTolerance);
}
ANGLE_INSTANTIATE_TEST_ES1(DrawTextureTest);
......@@ -76,6 +76,41 @@ TEST_P(FramebufferObjectTest, TextureObject)
glDeleteFramebuffers(1, &fboId);
}
// Checks different formats for a texture object bound to a framebuffer object.
TEST_P(FramebufferObjectTest, TextureObjectDifferentFormats)
{
// http://anglebug.com/5642
ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL());
GLuint fboId;
glGenFramebuffersOES(1, &fboId);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, fboId);
using FormatInfo = std::array<GLenum, 3>;
constexpr std::array<FormatInfo, 5> kFormatArrays = {
{{GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE},
{GL_RGB, GL_RGB, GL_UNSIGNED_BYTE},
{GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4},
{GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1},
{GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}}};
for (const FormatInfo &formatInfo : kFormatArrays)
{
glTexImage2D(GL_TEXTURE_2D, 0, formatInfo[0], 1, 1, 0, formatInfo[1], formatInfo[2],
&GLColor::green);
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D,
mTexture->get(), 0);
ASSERT_EQ(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES),
(GLenum)GL_FRAMEBUFFER_COMPLETE_OES);
}
EXPECT_GL_NO_ERROR();
glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
glDeleteFramebuffersOES(1, &fboId);
}
// Checks that renderbuffer object can be used and can be bound for framebuffer object.
TEST_P(FramebufferObjectTest, RenderbufferObject)
{
......
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