summaryrefslogtreecommitdiff
path: root/src/SFML/Graphics/RenderTextureImplFBO.cpp
diff options
context:
space:
mode:
authorJames Cowgill <james410@cowgill.org.uk>2014-12-09 20:21:40 +0000
committerJames Cowgill <james410@cowgill.org.uk>2014-12-09 20:21:40 +0000
commitfa21c65d0c764705cfc377bf0d0de08fac26874e (patch)
treedbc9e87bbd8684d15e79fc0c8b7a8985389c3b35 /src/SFML/Graphics/RenderTextureImplFBO.cpp
parentdd835931261c340acd5f0409341d13fa2670423e (diff)
Imported Upstream version 2.2.0+dfsg
Diffstat (limited to 'src/SFML/Graphics/RenderTextureImplFBO.cpp')
-rw-r--r--src/SFML/Graphics/RenderTextureImplFBO.cpp293
1 files changed, 147 insertions, 146 deletions
diff --git a/src/SFML/Graphics/RenderTextureImplFBO.cpp b/src/SFML/Graphics/RenderTextureImplFBO.cpp
index 0e92e0e..dca0240 100644
--- a/src/SFML/Graphics/RenderTextureImplFBO.cpp
+++ b/src/SFML/Graphics/RenderTextureImplFBO.cpp
@@ -1,146 +1,147 @@
-////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/Graphics/RenderTextureImplFBO.hpp>
-#include <SFML/Graphics/Texture.hpp>
-#include <SFML/Graphics/GLCheck.hpp>
-#include <SFML/System/Err.hpp>
-
-
-namespace sf
-{
-namespace priv
-{
-////////////////////////////////////////////////////////////
-RenderTextureImplFBO::RenderTextureImplFBO() :
-m_frameBuffer(0),
-m_depthBuffer(0)
-{
-
-}
-
-
-////////////////////////////////////////////////////////////
-RenderTextureImplFBO::~RenderTextureImplFBO()
-{
- ensureGlContext();
-
- // Destroy the depth buffer
- if (m_depthBuffer)
- {
- GLuint depthBuffer = static_cast<GLuint>(m_depthBuffer);
- glCheck(glDeleteRenderbuffersEXT(1, &depthBuffer));
- }
-
- // Destroy the frame buffer
- if (m_frameBuffer)
- {
- GLuint frameBuffer = static_cast<GLuint>(m_frameBuffer);
- glCheck(glDeleteFramebuffersEXT(1, &frameBuffer));
- }
-
- // Delete the context
- delete m_context;
-}
-
-
-////////////////////////////////////////////////////////////
-bool RenderTextureImplFBO::isAvailable()
-{
- ensureGlContext();
-
- // Make sure that GLEW is initialized
- priv::ensureGlewInit();
-
- return GLEW_EXT_framebuffer_object != 0;
-}
-
-
-////////////////////////////////////////////////////////////
-bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer)
-{
- // Create the context
- m_context = new Context;
-
- // Create the framebuffer object
- GLuint frameBuffer = 0;
- glCheck(glGenFramebuffersEXT(1, &frameBuffer));
- m_frameBuffer = static_cast<unsigned int>(frameBuffer);
- if (!m_frameBuffer)
- {
- err() << "Impossible to create render texture (failed to create the frame buffer object)" << std::endl;
- return false;
- }
- glCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_frameBuffer));
-
- // Create the depth buffer if requested
- if (depthBuffer)
- {
- GLuint depth = 0;
- glCheck(glGenRenderbuffersEXT(1, &depth));
- m_depthBuffer = static_cast<unsigned int>(depth);
- if (!m_depthBuffer)
- {
- err() << "Impossible to create render texture (failed to create the attached depth buffer)" << std::endl;
- return false;
- }
- glCheck(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer));
- glCheck(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height));
- glCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer));
- }
-
- // Link the texture to the frame buffer
- glCheck(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textureId, 0));
-
- // A final check, just to be sure...
- if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT)
- {
- glCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
- err() << "Impossible to create render texture (failed to link the target texture to the frame buffer)" << std::endl;
- return false;
- }
-
- return true;
-}
-
-
-////////////////////////////////////////////////////////////
-bool RenderTextureImplFBO::activate(bool active)
-{
- return m_context->setActive(active);
-}
-
-
-////////////////////////////////////////////////////////////
-void RenderTextureImplFBO::updateTexture(unsigned int)
-{
- glFlush();
-}
-
-} // namespace priv
-
-} // namespace sf
+////////////////////////////////////////////////////////////
+//
+// SFML - Simple and Fast Multimedia Library
+// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////
+// Headers
+////////////////////////////////////////////////////////////
+#include <SFML/Graphics/RenderTextureImplFBO.hpp>
+#include <SFML/Graphics/Texture.hpp>
+#include <SFML/Graphics/GLCheck.hpp>
+#include <SFML/System/Err.hpp>
+
+
+namespace sf
+{
+namespace priv
+{
+////////////////////////////////////////////////////////////
+RenderTextureImplFBO::RenderTextureImplFBO() :
+m_frameBuffer(0),
+m_depthBuffer(0)
+{
+
+}
+
+
+////////////////////////////////////////////////////////////
+RenderTextureImplFBO::~RenderTextureImplFBO()
+{
+ ensureGlContext();
+
+ // Destroy the depth buffer
+ if (m_depthBuffer)
+ {
+ GLuint depthBuffer = static_cast<GLuint>(m_depthBuffer);
+ glCheck(GLEXT_glDeleteRenderbuffers(1, &depthBuffer));
+ }
+
+ // Destroy the frame buffer
+ if (m_frameBuffer)
+ {
+ GLuint frameBuffer = static_cast<GLuint>(m_frameBuffer);
+ glCheck(GLEXT_glDeleteFramebuffers(1, &frameBuffer));
+ }
+
+ // Delete the context
+ delete m_context;
+}
+
+
+////////////////////////////////////////////////////////////
+bool RenderTextureImplFBO::isAvailable()
+{
+ ensureGlContext();
+
+ // Make sure that extensions are initialized
+ priv::ensureExtensionsInit();
+
+ return GLEXT_framebuffer_object != 0;
+}
+
+
+////////////////////////////////////////////////////////////
+bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer)
+{
+ // Create the context
+ m_context = new Context;
+
+ // Create the framebuffer object
+ GLuint frameBuffer = 0;
+ glCheck(GLEXT_glGenFramebuffers(1, &frameBuffer));
+ m_frameBuffer = static_cast<unsigned int>(frameBuffer);
+ if (!m_frameBuffer)
+ {
+ err() << "Impossible to create render texture (failed to create the frame buffer object)" << std::endl;
+ return false;
+ }
+ glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_FRAMEBUFFER, m_frameBuffer));
+
+ // Create the depth buffer if requested
+ if (depthBuffer)
+ {
+ GLuint depth = 0;
+ glCheck(GLEXT_glGenRenderbuffers(1, &depth));
+ m_depthBuffer = static_cast<unsigned int>(depth);
+ if (!m_depthBuffer)
+ {
+ err() << "Impossible to create render texture (failed to create the attached depth buffer)" << std::endl;
+ return false;
+ }
+ glCheck(GLEXT_glBindRenderbuffer(GLEXT_GL_RENDERBUFFER, m_depthBuffer));
+ glCheck(GLEXT_glRenderbufferStorage(GLEXT_GL_RENDERBUFFER, GLEXT_GL_DEPTH_COMPONENT, width, height));
+ glCheck(GLEXT_glFramebufferRenderbuffer(GLEXT_GL_FRAMEBUFFER, GLEXT_GL_DEPTH_ATTACHMENT, GLEXT_GL_RENDERBUFFER, m_depthBuffer));
+ }
+
+ // Link the texture to the frame buffer
+ glCheck(GLEXT_glFramebufferTexture2D(GLEXT_GL_FRAMEBUFFER, GLEXT_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureId, 0));
+
+ // A final check, just to be sure...
+ GLenum status = glCheck(GLEXT_glCheckFramebufferStatus(GLEXT_GL_FRAMEBUFFER));
+ if (status != GLEXT_GL_FRAMEBUFFER_COMPLETE)
+ {
+ glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_FRAMEBUFFER, 0));
+ err() << "Impossible to create render texture (failed to link the target texture to the frame buffer)" << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+
+////////////////////////////////////////////////////////////
+bool RenderTextureImplFBO::activate(bool active)
+{
+ return m_context->setActive(active);
+}
+
+
+////////////////////////////////////////////////////////////
+void RenderTextureImplFBO::updateTexture(unsigned int)
+{
+ glCheck(glFlush());
+}
+
+} // namespace priv
+
+} // namespace sf