Fixed RenderTexture::clear() not always working on certain hardware

This commit is contained in:
Matthew Szekely 2015-07-14 11:38:39 -04:00 committed by Lukas Dürrenberger
parent 7fba68ac52
commit 7c179193e6
4 changed files with 13 additions and 0 deletions

View File

@ -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
};

View File

@ -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;
}

View File

@ -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
{

View File

@ -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;