Skip to content

Commit

Permalink
GL: Fix glClearTexImage for LUMA textures
Browse files Browse the repository at this point in the history
We need to transform the format and type before handing it off to the
driver for emulated texture formats.

Bug: angleproject:347047859
Change-Id: Ifa2c92179a49fbd8ae152a365c2915091102e4e6
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5645626
Reviewed-by: Shahbaz Youssefi <[email protected]>
Commit-Queue: Geoff Lang <[email protected]>
  • Loading branch information
vonture authored and Angle LUCI CQ committed Jun 21, 2024
1 parent 3f57290 commit e3c8d57
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/libANGLE/renderer/gl/TextureGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1492,10 +1492,15 @@ angle::Result TextureGL::clearImage(const gl::Context *context,
GLenum type,
const uint8_t *data)
{
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context);
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context);

nativegl::TexSubImageFormat texSubImageFormat =
nativegl::GetTexSubImageFormat(functions, features, format, type);

ANGLE_GL_TRY(context, functions->clearTexImage(mTextureID, level, format, type, data));
ANGLE_GL_TRY(context, functions->clearTexImage(mTextureID, level, texSubImageFormat.format,
texSubImageFormat.type, data));

contextGL->markWorkSubmitted();
return angle::Result::Continue;
Expand All @@ -1508,12 +1513,15 @@ angle::Result TextureGL::clearSubImage(const gl::Context *context,
GLenum type,
const uint8_t *data)
{
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context);
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context);

ANGLE_GL_TRY(context,
functions->clearTexSubImage(mTextureID, level, area.x, area.y, area.z, area.width,
area.height, area.depth, format, type, data));
nativegl::TexSubImageFormat texSubImageFormat =
nativegl::GetTexSubImageFormat(functions, features, format, type);
ANGLE_GL_TRY(context, functions->clearTexSubImage(
mTextureID, level, area.x, area.y, area.z, area.width, area.height,
area.depth, texSubImageFormat.format, texSubImageFormat.type, data));

contextGL->markWorkSubmitted();
return angle::Result::Continue;
Expand Down
32 changes: 32 additions & 0 deletions src/tests/gl_tests/ClearTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3589,6 +3589,38 @@ TEST_P(ClearTextureEXTTest, Clear2D)
EXPECT_PIXEL_COLOR_EQ(12, 12, GLColor::yellow);
}

// Test that luminance alpha textures are cleared correctly with GL_EXT_clear_texture. Regression
// test for emulated luma formats.
TEST_P(ClearTextureEXTTest, Luma)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_clear_texture"));

// Create a 16x16 texture with no data.
GLTexture tex;
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Texture2D(), essl1_shaders::fs::Texture2D());

// Clear the entire texture to transparent black and test
GLubyte luminmanceClearValue = 192;
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 16, 16, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE,
nullptr);
glClearTexImageEXT(tex, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &luminmanceClearValue);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f);
EXPECT_PIXEL_COLOR_EQ(
0, 0, GLColor(luminmanceClearValue, luminmanceClearValue, luminmanceClearValue, 255));

GLubyte lumaClearValue[2] = {128, 64};
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 16, 16, 0, GL_LUMINANCE_ALPHA,
GL_UNSIGNED_BYTE, nullptr);
glClearTexImageEXT(tex, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, &lumaClearValue);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f);
EXPECT_PIXEL_COLOR_EQ(
0, 0, GLColor(lumaClearValue[0], lumaClearValue[0], lumaClearValue[0], lumaClearValue[1]));
}

// Test that interleaving glClearTexImageEXT and glTexSubImage2D calls produces the correct texture
// data
TEST_P(ClearTextureEXTTest, InterleavedUploads)
Expand Down

0 comments on commit e3c8d57

Please sign in to comment.