forked from organicmaps/organicmaps
[ios] Optimized glview->framework interaction
This commit is contained in:
parent
a062fb7106
commit
175ec47793
4 changed files with 21 additions and 39 deletions
|
@ -4,9 +4,12 @@
|
|||
#import <OpenGLES/ES1/glext.h>
|
||||
#import <QuartzCore/CADisplayLink.h>
|
||||
#import "MapViewController.h"
|
||||
|
||||
#include "../../std/shared_ptr.hpp"
|
||||
#include "../../map/drawer_yg.hpp"
|
||||
#include"RenderBuffer.hpp"
|
||||
#include "../../map/framework.hpp"
|
||||
#include "../../map/feature_vec_model.hpp"
|
||||
#include "RenderBuffer.hpp"
|
||||
|
||||
namespace iphone
|
||||
{
|
||||
|
@ -23,6 +26,8 @@ namespace yg
|
|||
}
|
||||
}
|
||||
|
||||
typedef Framework<model::FeaturesFetcher> framework_t;
|
||||
|
||||
// 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.
|
||||
|
@ -45,7 +50,7 @@ namespace yg
|
|||
- (void)drawViewOnMainThread;
|
||||
|
||||
@property (nonatomic, assign) CADisplayLink * displayLink;
|
||||
@property (nonatomic, assign) MapViewController * controller;
|
||||
@property (nonatomic, assign) framework_t * framework;
|
||||
@property (nonatomic, assign) shared_ptr<iphone::WindowHandle> windowHandle;
|
||||
@property (nonatomic, assign) shared_ptr<DrawerYG> drawer;
|
||||
@property (nonatomic, assign) shared_ptr<iphone::RenderContext> renderContext;
|
||||
|
|
|
@ -18,7 +18,7 @@ bool _inRepaint = false;
|
|||
|
||||
@implementation EAGLView
|
||||
|
||||
@synthesize controller;
|
||||
@synthesize framework;
|
||||
@synthesize windowHandle;
|
||||
@synthesize drawer;
|
||||
@synthesize renderContext;
|
||||
|
@ -157,6 +157,7 @@ bool _inRepaint = false;
|
|||
|
||||
- (void)onSize:(int)width withHeight:(int)height
|
||||
{
|
||||
framework->OnSize(width, height);
|
||||
/// free old video memory
|
||||
frameBuffer->resetRenderTarget();
|
||||
renderBuffer.reset();
|
||||
|
@ -168,7 +169,6 @@ bool _inRepaint = false;
|
|||
frameBuffer->onSize(width, height);
|
||||
drawer->onSize(width, height);
|
||||
|
||||
|
||||
drawer->screen()->beginFrame();
|
||||
drawer->screen()->clear();
|
||||
drawer->screen()->endFrame();
|
||||
|
@ -176,15 +176,15 @@ bool _inRepaint = false;
|
|||
|
||||
- (void)drawView
|
||||
{
|
||||
[controller drawFrame];
|
||||
/*if (windowHandle->needRedraw())
|
||||
shared_ptr<PaintEvent> pe(new PaintEvent(drawer.get()));
|
||||
if (windowHandle->needRedraw())
|
||||
{
|
||||
windowHandle->setNeedRedraw(false);
|
||||
[controller beginPaint];
|
||||
[controller doPaint];
|
||||
renderBuffer->present();
|
||||
[controller endPaint];
|
||||
}*/
|
||||
framework->BeginPaint(pe);
|
||||
framework->DoPaint(pe);
|
||||
renderBuffer->present();
|
||||
framework->EndPaint(pe);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)drawViewThunk:(id)obj
|
||||
|
@ -201,7 +201,6 @@ bool _inRepaint = false;
|
|||
{
|
||||
CGFloat const scale = self.contentScaleFactor;
|
||||
CGSize const s = self.frame.size;
|
||||
[controller onResize:s.width * scale withHeight:s.height * scale];
|
||||
[self onSize:s.width * scale withHeight:s.height * scale];
|
||||
}
|
||||
|
||||
|
|
|
@ -29,9 +29,6 @@
|
|||
|
||||
- (void) ZoomToRect: (m2::RectD const &) rect;
|
||||
|
||||
- (void) onResize: (GLint)width withHeight: (GLint)height;
|
||||
- (void) drawFrame;
|
||||
|
||||
- (void) SetupMeasurementSystem;
|
||||
|
||||
// called when app is terminated by system
|
||||
|
|
|
@ -118,13 +118,17 @@ storage::Storage m_storage;
|
|||
{
|
||||
if ((self = [super initWithCoder:coder]))
|
||||
{
|
||||
[(EAGLView*)self.view setController : self];
|
||||
// cyclic dependence, @TODO refactor.
|
||||
// Here we're creating view and window handle in it, and later we should pass framework to the view
|
||||
EAGLView * v = (EAGLView *)self.view;
|
||||
|
||||
shared_ptr<iphone::WindowHandle> windowHandle = [(EAGLView*)self.view windowHandle];
|
||||
shared_ptr<yg::ResourceManager> resourceManager = [(EAGLView*)self.view resourceManager];
|
||||
|
||||
m_framework = FrameworkFactory<model::FeaturesFetcher>::CreateFramework(windowHandle, 40);
|
||||
m_framework->InitStorage(m_storage);
|
||||
v.framework = m_framework;
|
||||
|
||||
m_StickyThreshold = 10;
|
||||
|
||||
m_CurrentAction = NOTHING;
|
||||
|
@ -143,11 +147,6 @@ storage::Storage m_storage;
|
|||
return self;
|
||||
}
|
||||
|
||||
- (void)onResize:(GLint) width withHeight:(GLint) height
|
||||
{
|
||||
m_framework->OnSize(width, height);
|
||||
}
|
||||
|
||||
NSInteger compareAddress(id l, id r, void * context)
|
||||
{
|
||||
return l < r;
|
||||
|
@ -281,24 +280,6 @@ NSInteger compareAddress(id l, id r, void * context)
|
|||
m_framework->Scale(0.5);
|
||||
}
|
||||
|
||||
- (void)drawFrame
|
||||
{
|
||||
EAGLView * v = (EAGLView*)self.view;
|
||||
boost::shared_ptr<WindowHandle> wh = [v windowHandle];
|
||||
boost::shared_ptr<iphone::RenderBuffer> rb = [v renderBuffer];
|
||||
shared_ptr<DrawerYG> drawer = [v drawer];
|
||||
shared_ptr<PaintEvent> pe(new PaintEvent(drawer.get()));
|
||||
|
||||
if (wh->needRedraw())
|
||||
{
|
||||
wh->setNeedRedraw(false);
|
||||
m_framework->BeginPaint(pe);
|
||||
m_framework->DoPaint(pe);
|
||||
rb->present();
|
||||
m_framework->EndPaint(pe);
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation
|
||||
{
|
||||
return YES; // We support all orientations
|
||||
|
|
Loading…
Add table
Reference in a new issue