forked from organicmaps/organicmaps
[ios] surface and OGL for ios build with drape renderer
This commit is contained in:
parent
ac9b75c479
commit
16341caa3b
6 changed files with 70 additions and 20 deletions
|
@ -1,7 +1,9 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
||||
#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<iphone::RenderContext> renderContext;
|
||||
shared_ptr<graphics::gl::FrameBuffer> frameBuffer;
|
||||
shared_ptr<iphone::RenderBuffer> renderBuffer;
|
||||
RenderPolicy * renderPolicy;
|
||||
#else
|
||||
dp::MasterPointer<dp::OGLContextFactory> 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;
|
||||
|
|
|
@ -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<iphone::RenderContext>(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<graphics::gl::RenderBuffer>(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<PaintEvent> 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
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#import <OpenGLES/ES2/gl.h>
|
||||
#import <OpenGLES/ES2/glext.h>
|
||||
|
||||
class iosOGLContext : public OGLContext
|
||||
class iosOGLContext : public dp::OGLContext
|
||||
{
|
||||
public:
|
||||
iosOGLContext(CAEAGLLayer * layer, iosOGLContext * contextToShareWith, bool needBuffers = false);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue