From 67177ce55c51bef876538ec6af3918460504b8b0 Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Tue, 22 Oct 2013 23:04:10 +0200 Subject: [PATCH] Fixed framebuffer binding messed up after a call to Texture::copyToImage() on OpenGL ES --- src/SFML/Graphics/GLExtensions.hpp | 2 ++ src/SFML/Graphics/Texture.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/SFML/Graphics/GLExtensions.hpp b/src/SFML/Graphics/GLExtensions.hpp index 062a572d4..de12af646 100644 --- a/src/SFML/Graphics/GLExtensions.hpp +++ b/src/SFML/Graphics/GLExtensions.hpp @@ -48,6 +48,7 @@ #define glFramebufferTexture2D glFramebufferTexture2DOES #define glCheckFramebufferStatus glCheckFramebufferStatusOES #define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES + #define GL_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING_OES #define GL_RENDERBUFFER GL_RENDERBUFFER_OES #define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_OES #define GL_DEPTH_ATTACHMENT GL_DEPTH_ATTACHMENT_OES @@ -75,6 +76,7 @@ #define glFramebufferTexture2D glFramebufferTexture2DEXT #define glCheckFramebufferStatus glCheckFramebufferStatusEXT #define GL_FRAMEBUFFER GL_FRAMEBUFFER_EXT + #define GL_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING_EXT #define GL_RENDERBUFFER GL_RENDERBUFFER_EXT #define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_EXT #define GL_DEPTH_ATTACHMENT GL_DEPTH_ATTACHMENT_EXT diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 96cbd3a62..7a5e1a9b0 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -267,17 +267,22 @@ Image Texture::copyToImage() const std::vector pixels(m_size.x * m_size.y * 4); #ifdef SFML_OPENGL_ES - + // OpenGL ES doesn't have the glGetTexImage function, the only way to read // from a texture is to bind it to a FBO and use glReadPixels GLuint frameBuffer = 0; glCheck(glGenFramebuffers(1, &frameBuffer)); if (frameBuffer) { + GLint previousFrameBuffer; + glCheck(glGetIntegerv(GL_FRAMEBUFFER_BINDING, &previousFrameBuffer)); + glCheck(glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer)); glCheck(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture, 0)); glCheck(glReadPixels(0, 0, m_size.x, m_size.y, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0])); glCheck(glDeleteFramebuffers(1, &frameBuffer)); + + glCheck(glBindFramebuffer(GL_FRAMEBUFFER, previousFrameBuffer)); } #else