diff --git a/drape_frontend/framebuffer.cpp b/drape_frontend/framebuffer.cpp index 0939bb5ba6..a525ba80ad 100644 --- a/drape_frontend/framebuffer.cpp +++ b/drape_frontend/framebuffer.cpp @@ -16,7 +16,8 @@ namespace df Framebuffer::Framebuffer() : m_colorTextureId(0) , m_depthTextureId(0) - , m_fbo(0) + , m_framebufferId(0) + , m_defaultContext(0) { } @@ -30,7 +31,7 @@ void Framebuffer::Destroy() { if (m_colorTextureId) { - GLFunctions::glDeleteTexture(m_depthTextureId); + GLFunctions::glDeleteTexture(m_colorTextureId); m_colorTextureId = 0; } if (m_depthTextureId) @@ -38,16 +39,23 @@ void Framebuffer::Destroy() GLFunctions::glDeleteTexture(m_depthTextureId); m_depthTextureId = 0; } - if (m_fbo) + if (m_framebufferId) { - GLFunctions::glDeleteFramebuffer(&m_fbo); - m_fbo = 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(width > 0 && height > 0); + assert(m_defaultContext); + if (m_width == width && m_height == height) return; @@ -61,6 +69,8 @@ void Framebuffer::SetSize(uint32_t width, uint32_t height) GLFunctions::glTexImage2D(m_width, m_height, gl_const::GLRGBA, gl_const::GLUnsignedByteType, NULL); 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); @@ -68,8 +78,8 @@ void Framebuffer::SetSize(uint32_t width, uint32_t height) GLFunctions::glBindTexture(0); - GLFunctions::glGenFramebuffer(&m_fbo); - GLFunctions::glBindFramebuffer(m_fbo); + GLFunctions::glGenFramebuffer(&m_framebufferId); + GLFunctions::glBindFramebuffer(m_framebufferId); GLFunctions::glFramebufferTexture2D(gl_const::GLColorAttachment, m_colorTextureId); GLFunctions::glFramebufferTexture2D(gl_const::GLDepthAttachment, m_depthTextureId); @@ -80,17 +90,18 @@ void Framebuffer::SetSize(uint32_t width, uint32_t height) LOG(LWARNING, ("INCOMPLETE FRAMEBUFFER: ", strings::to_string(status))); //GLFunctions::glFlush(); - GLFunctions::glBindFramebuffer(0); + m_defaultContext->setDefaultFramebuffer(); } void Framebuffer::Enable() { - GLFunctions::glBindFramebuffer(m_fbo); + GLFunctions::glBindFramebuffer(m_framebufferId); } void Framebuffer::Disable() { - GLFunctions::glBindFramebuffer(0); + assert(m_defaultContext); + m_defaultContext->setDefaultFramebuffer(); } uint32_t Framebuffer::GetTextureId() const diff --git a/drape_frontend/framebuffer.hpp b/drape_frontend/framebuffer.hpp index d471230bed..31618bbc7b 100644 --- a/drape_frontend/framebuffer.hpp +++ b/drape_frontend/framebuffer.hpp @@ -1,5 +1,7 @@ #pragma once +#include "drape/oglcontext.hpp" + #include "stdint.h" namespace df @@ -11,6 +13,7 @@ public: Framebuffer(); ~Framebuffer(); + void SetDefaultContext(dp::OGLContext * context); void SetSize(uint32_t width, uint32_t height); void Enable(); @@ -26,7 +29,9 @@ private: uint32_t m_colorTextureId; uint32_t m_depthTextureId; - uint32_t m_fbo; + uint32_t m_framebufferId; + + dp::OGLContext * m_defaultContext; }; } diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 403a137f5b..dae78fe5e5 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -498,6 +498,7 @@ void FrontendRenderer::OnResize(ScreenBase const & screen) m_viewport.SetViewport(0, 0, screen.GetWidth(), screen.GetHeight()); m_myPositionController->SetPixelRect(screen.PixelRect()); m_contextFactory->getDrawContext()->resize(m_viewport.GetWidth(), m_viewport.GetHeight()); + m_framebuffer->SetDefaultContext(m_contextFactory->getDrawContext()); m_framebuffer->SetSize(m_viewport.GetWidth(), m_viewport.GetHeight()); m_renderer3d->SetSize(m_viewport.GetWidth(), m_viewport.GetHeight()); RefreshProjection(); @@ -654,7 +655,10 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView) #endif if (m_useFramebuffer) + { + m_framebuffer->SetDefaultContext(m_contextFactory->getDrawContext()); m_framebuffer->Enable(); + } RenderGroupComparator comparator; sort(m_renderGroups.begin(), m_renderGroups.end(), bind(&RenderGroupComparator::operator (), &comparator, _1, _2));