diff options
author | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2017-05-16 14:42:32 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-16 14:42:32 +0300 |
commit | d2f79bd2c7004af2d1459e8d5b7748763f241a54 (patch) | |
tree | 64300bccb750e59f7c3a05800eafcd5c3b3f89cb /drape/framebuffer.cpp | |
parent | aa6703383e8d4c2ff8445e8b3c27728846cdab4b (diff) | |
parent | 086d6f9cf247cea07cff6bc33d5567dc7c64806b (diff) |
Merge pull request #6040 from rokuz/es3-supportbeta-810
Added OpenGL ES3 support
Diffstat (limited to 'drape/framebuffer.cpp')
-rw-r--r-- | drape/framebuffer.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/drape/framebuffer.cpp b/drape/framebuffer.cpp new file mode 100644 index 0000000000..73d79173f5 --- /dev/null +++ b/drape/framebuffer.cpp @@ -0,0 +1,105 @@ +#include "drape/framebuffer.hpp" + +#include "drape/glfunctions.hpp" +#include "drape/oglcontext.hpp" + +#include "base/assert.hpp" +#include "base/logging.hpp" +#include "base/string_utils.hpp" + +namespace dp +{ +Framebuffer::~Framebuffer() { Destroy(); } +void Framebuffer::Destroy() +{ + if (m_colorTextureId != 0) + { + GLFunctions::glDeleteTexture(m_colorTextureId); + m_colorTextureId = 0; + } + + if (m_depthTextureId != 0) + { + GLFunctions::glDeleteTexture(m_depthTextureId); + m_depthTextureId = 0; + } + + if (m_framebufferId != 0) + { + GLFunctions::glDeleteFramebuffer(&m_framebufferId); + m_framebufferId = 0; + } +} + +void Framebuffer::SetDefaultContext(dp::OGLContext * context) { m_defaultContext = context; } +void Framebuffer::SetSize(uint32_t width, uint32_t height) +{ + ASSERT(m_defaultContext, ()); + + if (!m_isSupported) + return; + + if (m_width == width && m_height == height) + return; + + m_height = height; + m_width = width; + + Destroy(); + + m_colorTextureId = GLFunctions::glGenTexture(); + GLFunctions::glBindTexture(m_colorTextureId); + GLFunctions::glTexImage2D(m_width, m_height, gl_const::GLRGBA, gl_const::GLUnsignedByteType, + nullptr); + GLFunctions::glTexParameter(gl_const::GLMagFilter, gl_const::GLLinear); + GLFunctions::glTexParameter(gl_const::GLMinFilter, gl_const::GLLinear); + GLFunctions::glTexParameter(gl_const::GLWrapT, gl_const::GLClampToEdge); + GLFunctions::glTexParameter(gl_const::GLWrapS, gl_const::GLClampToEdge); + + m_depthTextureId = GLFunctions::glGenTexture(); + GLFunctions::glBindTexture(m_depthTextureId); + GLFunctions::glTexImage2D(m_width, m_height, gl_const::GLDepthComponent, + gl_const::GLUnsignedIntType, nullptr); + if (GLFunctions::CurrentApiVersion == dp::ApiVersion::OpenGLES3) + { + GLFunctions::glTexParameter(gl_const::GLMagFilter, gl_const::GLNearest); + GLFunctions::glTexParameter(gl_const::GLMinFilter, gl_const::GLNearest); + GLFunctions::glTexParameter(gl_const::GLWrapT, gl_const::GLClampToEdge); + GLFunctions::glTexParameter(gl_const::GLWrapS, gl_const::GLClampToEdge); + } + + GLFunctions::glBindTexture(0); + + GLFunctions::glGenFramebuffer(&m_framebufferId); + GLFunctions::glBindFramebuffer(m_framebufferId); + + GLFunctions::glFramebufferTexture2D(gl_const::GLColorAttachment, m_colorTextureId); + GLFunctions::glFramebufferTexture2D(gl_const::GLDepthAttachment, m_depthTextureId); + GLFunctions::glFramebufferTexture2D(gl_const::GLStencilAttachment, 0); + + uint32_t const status = GLFunctions::glCheckFramebufferStatus(); + if (status != gl_const::GLFramebufferComplete) + { + m_isSupported = false; + Destroy(); + LOG(LWARNING, ("Framebuffer is unsupported. Framebuffer status =", status)); + } + + m_defaultContext->setDefaultFramebuffer(); +} + +void Framebuffer::Enable() +{ + ASSERT(m_isSupported, ()); + GLFunctions::glBindFramebuffer(m_framebufferId); +} + +void Framebuffer::Disable() +{ + ASSERT(m_defaultContext, ()); + ASSERT(m_isSupported, ()); + m_defaultContext->setDefaultFramebuffer(); +} + +uint32_t Framebuffer::GetTextureId() const { return m_colorTextureId; } +} // namespace dp |