diff --git a/iphone/Maps/Classes/EAGLView.h b/iphone/Maps/Classes/EAGLView.h index 0f4092af9e..76859df5a3 100644 --- a/iphone/Maps/Classes/EAGLView.h +++ b/iphone/Maps/Classes/EAGLView.h @@ -1,7 +1,9 @@ #import + #include "../../std/shared_ptr.hpp" +#ifndef USE_DRAPE class VideoTimer; class RenderPolicy; @@ -20,16 +22,30 @@ namespace graphics } } +#else + +#include "../../drape/pointers.hpp" +namespace dp +{ + class OGLContextFactory; +} + +#endif + // This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass. // The view content is basically an EAGL surface you render your OpenGL scene into. // Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel. @interface EAGLView : UIView { +#ifndef USE_DRAPE VideoTimer * videoTimer; shared_ptr renderContext; shared_ptr frameBuffer; shared_ptr renderBuffer; RenderPolicy * renderPolicy; +#else + dp::MasterPointer m_factory; +#endif // Do not call onSize from layoutSubViews when real size wasn't changed. // It's possible when we add/remove subviews (bookmark balloons) and it hangs the map without this check CGRect lastViewSize; diff --git a/iphone/Maps/Classes/EAGLView.mm b/iphone/Maps/Classes/EAGLView.mm index a4a7bdc347..60a5045836 100644 --- a/iphone/Maps/Classes/EAGLView.mm +++ b/iphone/Maps/Classes/EAGLView.mm @@ -5,13 +5,17 @@ #import "EAGLView.h" -#include "RenderBuffer.hpp" -#include "RenderContext.hpp" #include "Framework.h" -#include "../../graphics/resource_manager.hpp" -#include "../../graphics/opengl/opengl.hpp" -#include "../../graphics/data_formats.hpp" +#ifndef USE_DRAPE + #include "RenderBuffer.hpp" + #include "RenderContext.hpp" + #include "../../graphics/resource_manager.hpp" + #include "../../graphics/opengl/opengl.hpp" + #include "../../graphics/data_formats.hpp" +#else + #import "../Platform/opengl/iosOGLContextFactory.h" +#endif #include "../../map/render_policy.hpp" @@ -41,7 +45,14 @@ CAEAGLLayer * eaglLayer = (CAEAGLLayer *)self.layer; eaglLayer.opaque = YES; + // ColorFormat : RGB565 + // Backbuffer : YES, (to prevent from loosing content when mixing with ordinary layers). + eaglLayer.drawableProperties = @{kEAGLDrawablePropertyRetainedBacking : @NO, kEAGLDrawablePropertyColorFormat : kEAGLColorFormatRGB565}; + + // Correct retina display support in opengl renderbuffer + self.contentScaleFactor = [self correctContentScale]; +#ifndef USE_DRAPE renderContext = shared_ptr(new iphone::RenderContext()); if (!renderContext.get()) @@ -51,12 +62,10 @@ } renderContext->makeCurrent(); - - // ColorFormat : RGB565 - // Backbuffer : YES, (to prevent from loosing content when mixing with ordinary layers). - eaglLayer.drawableProperties = @{kEAGLDrawablePropertyRetainedBacking : @NO, kEAGLDrawablePropertyColorFormat : kEAGLColorFormatRGB565}; - // Correct retina display support in opengl renderbuffer - self.contentScaleFactor = [self correctContentScale]; +#else + dp::ThreadSafeFactory * factory = new dp::ThreadSafeFactory(new iosOGLContextFactory(eaglLayer)); + m_factory.Reset(factory); +#endif } NSLog(@"EAGLView initWithCoder Ended"); @@ -67,6 +76,7 @@ { NSLog(@"EAGLView initRenderPolicy Started"); +#ifndef USE_DRAPE typedef void (*drawFrameFn)(id, SEL); SEL drawFrameSel = @selector(drawFrame); drawFrameFn drawFrameImpl = (drawFrameFn)[self methodForSelector:drawFrameSel]; @@ -117,12 +127,17 @@ f.OnSize(frameRect.size.width * vs, frameRect.size.height * vs); f.SetRenderPolicy(renderPolicy); f.InitGuiSubsystem(); +#else + CGRect frameRect = [UIScreen mainScreen].applicationFrame; + GetFramework().CreateDrapeEngine(m_factory.GetRefPointer(), self.contentScaleFactor, frameRect.size.width, frameRect.size.height); +#endif NSLog(@"EAGLView initRenderPolicy Ended"); } - (void)onSize:(int)width withHeight:(int)height { +#ifndef USE_DRAPE frameBuffer->onSize(width, height); graphics::Screen * screen = renderPolicy->GetDrawer()->screen(); @@ -142,12 +157,15 @@ screen->setRenderTarget(renderBuffer); screen->setDepthBuffer(make_shared(width, height, true)); +#endif GetFramework().OnSize(width, height); +#ifndef USE_DRAPE screen->beginFrame(); screen->clear(graphics::Screen::s_bgColor); screen->endFrame(); +#endif } - (double)correctContentScale @@ -159,6 +177,7 @@ return uiScreen.nativeScale; } +#ifndef USE_DRAPE - (void)drawFrame { shared_ptr pe(new PaintEvent(renderPolicy->GetDrawer().get())); @@ -173,22 +192,33 @@ f.EndPaint(pe); } } +#endif - (void)layoutSubviews { if (!CGRectEqualToRect(lastViewSize, self.frame)) { lastViewSize = self.frame; +#ifndef USE_DRAPE CGFloat const scale = self.contentScaleFactor; CGSize const s = self.bounds.size; [self onSize:s.width * scale withHeight:s.height * scale]; +#else + CGSize const s = self.bounds.size; + [self onSize:s.width withHeight:s.height]; +#endif } } - (void)dealloc { +#ifndef USE_DRAPE delete videoTimer; [EAGLContext setCurrentContext:nil]; +#else + GetFramework().PrepareToShutdown(); + m_factory.Destroy(); +#endif } - (CGPoint)viewPoint2GlobalPoint:(CGPoint)pt diff --git a/iphone/Maps/Platform/opengl/iosOGLContext.h b/iphone/Maps/Platform/opengl/iosOGLContext.h index 2433ae1d46..7ca8d947ca 100644 --- a/iphone/Maps/Platform/opengl/iosOGLContext.h +++ b/iphone/Maps/Platform/opengl/iosOGLContext.h @@ -6,7 +6,7 @@ #import #import -class iosOGLContext : public OGLContext +class iosOGLContext : public dp::OGLContext { public: iosOGLContext(CAEAGLLayer * layer, iosOGLContext * contextToShareWith, bool needBuffers = false); diff --git a/iphone/Maps/Platform/opengl/iosOGLContext.mm b/iphone/Maps/Platform/opengl/iosOGLContext.mm index bc4f79c952..0217b29909 100644 --- a/iphone/Maps/Platform/opengl/iosOGLContext.mm +++ b/iphone/Maps/Platform/opengl/iosOGLContext.mm @@ -1,5 +1,6 @@ #import "iosOGLContext.h" #import "../../../../base/assert.hpp" +#import "../../../../base/logging.cpp" iosOGLContext::iosOGLContext(CAEAGLLayer * layer, iosOGLContext * contextToShareWith, bool needBuffers) : m_layer(layer) @@ -74,11 +75,13 @@ void iosOGLContext::initBuffers() // Framebuffer glGenFramebuffers(1, &m_frameBufferId); + glBindFramebuffer(GL_FRAMEBUFFER, m_frameBufferId); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_renderBufferId); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthBufferId); - - GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); - ASSERT(fbStatus == GL_FRAMEBUFFER_COMPLETE, ("Incomplete framebuffer:", fbStatus)); + + GLint fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (fbStatus != GL_FRAMEBUFFER_COMPLETE) + LOG(LERROR, ("Incomplete framebuffer:", fbStatus)); // framebuffer m_hasBuffers = true; diff --git a/iphone/Maps/Platform/opengl/iosOGLContextFactory.h b/iphone/Maps/Platform/opengl/iosOGLContextFactory.h index cfbeaced28..2877f57aa3 100644 --- a/iphone/Maps/Platform/opengl/iosOGLContextFactory.h +++ b/iphone/Maps/Platform/opengl/iosOGLContextFactory.h @@ -3,13 +3,14 @@ #import "iosOGLContext.h" #import "../../../../drape/oglcontextfactory.hpp" -class iosOGLContextFactory: public OGLContextFactory +class iosOGLContextFactory: public dp::OGLContextFactory { +public: iosOGLContextFactory(CAEAGLLayer * layer); ~iosOGLContextFactory(); - virtual OGLContext * getDrawContext(); - virtual OGLContext * getResourcesUploadContext(); + virtual dp::OGLContext * getDrawContext(); + virtual dp::OGLContext * getResourcesUploadContext(); private: CAEAGLLayer * m_layer; diff --git a/iphone/Maps/Platform/opengl/iosOGLContextFactory.mm b/iphone/Maps/Platform/opengl/iosOGLContextFactory.mm index ed323522f3..17cdc38ed0 100644 --- a/iphone/Maps/Platform/opengl/iosOGLContextFactory.mm +++ b/iphone/Maps/Platform/opengl/iosOGLContextFactory.mm @@ -13,14 +13,14 @@ iosOGLContextFactory::~iosOGLContextFactory() } -OGLContext * iosOGLContextFactory::getDrawContext() +dp::OGLContext * iosOGLContextFactory::getDrawContext() { if (m_drawContext == NULL) m_drawContext = new iosOGLContext(m_layer, m_uploadContext, true); return m_drawContext; } -OGLContext * iosOGLContextFactory::getResourcesUploadContext() +dp::OGLContext * iosOGLContextFactory::getResourcesUploadContext() { if (m_uploadContext == NULL) m_uploadContext = new iosOGLContext(m_layer, m_drawContext, false);