From 7c179193e6acf0c3fed97964ebcd1fabcd69dcd7 Mon Sep 17 00:00:00 2001 From: Matthew Szekely Date: Tue, 14 Jul 2015 11:38:39 -0400 Subject: [PATCH] Fixed RenderTexture::clear() not always working on certain hardware --- include/SFML/Graphics/Texture.hpp | 1 + src/SFML/Graphics/RenderTarget.cpp | 5 +++++ src/SFML/Graphics/RenderTexture.cpp | 3 +++ src/SFML/Graphics/Texture.cpp | 4 ++++ 4 files changed, 13 insertions(+) diff --git a/include/SFML/Graphics/Texture.hpp b/include/SFML/Graphics/Texture.hpp index 29260d18b..247153136 100644 --- a/include/SFML/Graphics/Texture.hpp +++ b/include/SFML/Graphics/Texture.hpp @@ -509,6 +509,7 @@ private: bool m_isSmooth; ///< Status of the smooth filter bool m_isRepeated; ///< Is the texture in repeat mode? mutable bool m_pixelsFlipped; ///< To work around the inconsistency in Y orientation + bool m_fboAttachment; ///< Is this texture owned by a framebuffer object? Uint64 m_cacheId; ///< Unique number that identifies the texture to the render target's cache }; diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index 19e1d505c..7bb9be8d4 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -281,6 +281,11 @@ void RenderTarget::draw(const Vertex* vertices, std::size_t vertexCount, if (states.shader) applyShader(NULL); + // If the texture we used to draw belonged to a RenderTexture, then forcibly unbind that texture. + // This prevents a bug where some drivers do not clear RenderTextures properly. + if (states.texture && states.texture->m_fboAttachment) + applyTexture(NULL); + // Update the cache m_cache.useVertexCache = useVertexCache; } diff --git a/src/SFML/Graphics/RenderTexture.cpp b/src/SFML/Graphics/RenderTexture.cpp index e80aa4cd4..4602beb31 100644 --- a/src/SFML/Graphics/RenderTexture.cpp +++ b/src/SFML/Graphics/RenderTexture.cpp @@ -67,6 +67,9 @@ bool RenderTexture::create(unsigned int width, unsigned int height, bool depthBu { // Use frame-buffer object (FBO) m_impl = new priv::RenderTextureImplFBO; + + // Mark the texture as being a framebuffer object attachment + m_texture.m_fboAttachment = true; } else { diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 610dfa2cd..4be52e7bb 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -78,6 +78,7 @@ m_texture (0), m_isSmooth (false), m_isRepeated (false), m_pixelsFlipped(false), +m_fboAttachment(false), m_cacheId (getUniqueId()) { } @@ -91,6 +92,7 @@ m_texture (0), m_isSmooth (copy.m_isSmooth), m_isRepeated (copy.m_isRepeated), m_pixelsFlipped(false), +m_fboAttachment(false), m_cacheId (getUniqueId()) { if (copy.m_texture) @@ -141,6 +143,7 @@ bool Texture::create(unsigned int width, unsigned int height) m_size.y = height; m_actualSize = actualSize; m_pixelsFlipped = false; + m_fboAttachment = false; ensureGlContext(); @@ -592,6 +595,7 @@ Texture& Texture::operator =(const Texture& right) std::swap(m_isSmooth, temp.m_isSmooth); std::swap(m_isRepeated, temp.m_isRepeated); std::swap(m_pixelsFlipped, temp.m_pixelsFlipped); + std::swap(m_fboAttachment, temp.m_fboAttachment); m_cacheId = getUniqueId(); return *this;