Commit 4877ef35 by Jamie Madill Committed by Commit Bot

Ensure deleteTexture preserves correct texture cache.

Also adds a test contributed by jgilbert@mozilla.com. Bug: angleproject:3375 Change-Id: Ibd52daa074bf53b2b213193ccf5a612705a89c67 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1565052Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 0e30681d
...@@ -1144,8 +1144,11 @@ void State::detachTexture(const Context *context, const TextureMap &zeroTextures ...@@ -1144,8 +1144,11 @@ void State::detachTexture(const Context *context, const TextureMap &zeroTextures
// Zero textures are the "default" textures instead of NULL // Zero textures are the "default" textures instead of NULL
Texture *zeroTexture = zeroTextures[type].get(); Texture *zeroTexture = zeroTextures[type].get();
ASSERT(zeroTexture != nullptr); ASSERT(zeroTexture != nullptr);
if (mCompleteTextureBindings[bindingIndex].getSubject() == binding.get())
{
updateActiveTexture(context, bindingIndex, zeroTexture);
}
binding.set(context, zeroTexture); binding.set(context, zeroTexture);
updateActiveTexture(context, bindingIndex, zeroTexture);
} }
} }
} }
......
...@@ -3446,6 +3446,57 @@ TEST_P(ValidationStateChangeTest, MapElementArrayBuffer) ...@@ -3446,6 +3446,57 @@ TEST_P(ValidationStateChangeTest, MapElementArrayBuffer)
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
} }
// Tests that deleting a non-active texture does not reset the current texture cache.
TEST_P(SimpleStateChangeTest, DeleteNonActiveTextureThenDraw)
{
constexpr char kFS[] =
"uniform sampler2D us; void main() { gl_FragColor = texture2D(us, vec2(0)); }";
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS);
glUseProgram(program);
GLint loc = glGetUniformLocation(program, "us");
ASSERT_EQ(0, loc);
auto quadVertices = GetQuadVertices();
GLint posLoc = glGetAttribLocation(program, essl1_shaders::PositionAttrib());
ASSERT_EQ(0, posLoc);
GLBuffer buffer;
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, quadVertices.size() * sizeof(quadVertices[0]),
quadVertices.data(), GL_STATIC_DRAW);
glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
glEnableVertexAttribArray(posLoc);
constexpr size_t kSize = 2;
std::vector<GLColor> red(kSize * kSize, GLColor::red);
GLTexture tex;
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, red.data());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glUniform1i(loc, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
// Deleting TEXTURE_CUBE_MAP[0] should not affect TEXTURE_2D[0].
GLTexture tex2;
glBindTexture(GL_TEXTURE_CUBE_MAP, tex2);
tex2.reset();
glDrawArrays(GL_TRIANGLES, 0, 3);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
// Deleting TEXTURE_2D[0] should start "sampling" from the default/zero texture.
tex.reset();
glDrawArrays(GL_TRIANGLES, 0, 3);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
}
// Tests that deleting a texture successfully binds the zero texture. // Tests that deleting a texture successfully binds the zero texture.
TEST_P(SimpleStateChangeTest, DeleteTextureThenDraw) TEST_P(SimpleStateChangeTest, DeleteTextureThenDraw)
{ {
...@@ -3496,7 +3547,7 @@ ANGLE_INSTANTIATE_TEST(StateChangeRenderTest, ...@@ -3496,7 +3547,7 @@ ANGLE_INSTANTIATE_TEST(StateChangeRenderTest,
ES2_D3D11_FL9_3(), ES2_D3D11_FL9_3(),
ES2_VULKAN()); ES2_VULKAN());
ANGLE_INSTANTIATE_TEST(StateChangeTestES3, ES3_D3D11(), ES3_OPENGL()); ANGLE_INSTANTIATE_TEST(StateChangeTestES3, ES3_D3D11(), ES3_OPENGL());
ANGLE_INSTANTIATE_TEST(SimpleStateChangeTest, ES2_VULKAN(), ES2_OPENGL()); ANGLE_INSTANTIATE_TEST(SimpleStateChangeTest, ES2_D3D11(), ES2_VULKAN(), ES2_OPENGL());
ANGLE_INSTANTIATE_TEST(SimpleStateChangeTestES3, ES3_OPENGL(), ES3_D3D11()); ANGLE_INSTANTIATE_TEST(SimpleStateChangeTestES3, ES3_OPENGL(), ES3_D3D11());
ANGLE_INSTANTIATE_TEST(SimpleStateChangeTestES31, ES31_OPENGL(), ES31_D3D11()); ANGLE_INSTANTIATE_TEST(SimpleStateChangeTestES31, ES31_OPENGL(), ES31_D3D11());
ANGLE_INSTANTIATE_TEST(ValidationStateChangeTest, ES3_D3D11(), ES3_OPENGL()); ANGLE_INSTANTIATE_TEST(ValidationStateChangeTest, ES3_D3D11(), ES3_OPENGL());
......
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