Added missing code to reset the parameters of the target texture after copying using FBOs and make sure to flip the source data back into non-flipped orientation when blitting from a flipped texture. (Fixes #1319)

This commit is contained in:
binary1248 2017-11-19 01:33:57 +01:00
parent 013d053277
commit 3871e01a9f
No known key found for this signature in database
GPG Key ID: E5E52A5D6082224A

View File

@ -502,7 +502,11 @@ void Texture::update(const Texture& texture, unsigned int x, unsigned int y)
if ((sourceStatus == GLEXT_GL_FRAMEBUFFER_COMPLETE) && (destStatus == GLEXT_GL_FRAMEBUFFER_COMPLETE)) if ((sourceStatus == GLEXT_GL_FRAMEBUFFER_COMPLETE) && (destStatus == GLEXT_GL_FRAMEBUFFER_COMPLETE))
{ {
// Blit the texture contents from the source to the destination texture // Blit the texture contents from the source to the destination texture
glCheck(GLEXT_glBlitFramebuffer(0, 0, texture.m_size.x, texture.m_size.y, x, y, x + texture.m_size.x, y + texture.m_size.y, GL_COLOR_BUFFER_BIT, GL_NEAREST)); glCheck(GLEXT_glBlitFramebuffer(
0, texture.m_pixelsFlipped ? texture.m_size.y : 0, texture.m_size.x, texture.m_pixelsFlipped ? 0 : texture.m_size.y, // Source rectangle, flip y if source is flipped
x, y, x + texture.m_size.x, y + texture.m_size.y, // Destination rectangle
GL_COLOR_BUFFER_BIT, GL_NEAREST
));
} }
else else
{ {
@ -517,6 +521,20 @@ void Texture::update(const Texture& texture, unsigned int x, unsigned int y)
glCheck(GLEXT_glDeleteFramebuffers(1, &sourceFrameBuffer)); glCheck(GLEXT_glDeleteFramebuffers(1, &sourceFrameBuffer));
glCheck(GLEXT_glDeleteFramebuffers(1, &destFrameBuffer)); glCheck(GLEXT_glDeleteFramebuffers(1, &destFrameBuffer));
// Make sure that the current texture binding will be preserved
priv::TextureSaver save;
// Set the parameters of this texture
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
m_hasMipmap = false;
m_pixelsFlipped = false;
m_cacheId = getUniqueId();
// Force an OpenGL flush, so that the texture data will appear updated
// in all contexts immediately (solves problems in multi-threaded apps)
glCheck(glFlush());
return; return;
} }