From a089139e5ca0315a5e7d58ce5f80c2c4200c4668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Sat, 23 Feb 2019 00:29:45 -0800 Subject: [ios, macos] Expose MGLMapView OpenGL context to OpenGL style layers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added a property to MGLOpenGLStyleLayer that contains the map view’s underlying OpenGL rendering context. --- platform/darwin/src/MGLOpenGLStyleLayer.h | 6 ++++++ platform/darwin/src/MGLOpenGLStyleLayer.mm | 10 ++++++++++ platform/ios/src/MGLMapView.mm | 2 +- platform/ios/src/MGLMapView_Private.h | 3 +++ platform/macos/src/MGLMapView.mm | 5 +++++ platform/macos/src/MGLMapView_Private.h | 3 +++ 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/platform/darwin/src/MGLOpenGLStyleLayer.h b/platform/darwin/src/MGLOpenGLStyleLayer.h index df8d2c5365..f699284c32 100644 --- a/platform/darwin/src/MGLOpenGLStyleLayer.h +++ b/platform/darwin/src/MGLOpenGLStyleLayer.h @@ -27,6 +27,12 @@ MGL_EXPORT @property (nonatomic, weak, readonly) MGLStyle *style; +#if TARGET_OS_IPHONE +@property (nonatomic, readonly) EAGLContext *context; +#else +@property (nonatomic, readonly) CGLContextObj context; +#endif + - (instancetype)initWithIdentifier:(NSString *)identifier; - (void)didMoveToMapView:(MGLMapView *)mapView; diff --git a/platform/darwin/src/MGLOpenGLStyleLayer.mm b/platform/darwin/src/MGLOpenGLStyleLayer.mm index 678bf15bfc..945348cb03 100644 --- a/platform/darwin/src/MGLOpenGLStyleLayer.mm +++ b/platform/darwin/src/MGLOpenGLStyleLayer.mm @@ -107,6 +107,16 @@ private: return (mbgl::style::CustomLayer *)super.rawLayer; } +#if TARGET_OS_IPHONE +- (EAGLContext *)context { + return self.style.mapView.context; +} +#else +- (CGLContextObj)context { + return self.style.mapView.context; +} +#endif + #pragma mark - Adding to and removing from a map view - (void)addToStyle:(MGLStyle *)style belowLayer:(MGLStyleLayer *)otherLayer { self.style = style; diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 752a1a780b..f5b51330a0 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -195,7 +195,7 @@ public: MGLMultiPointDelegate, MGLAnnotationImageDelegate> -@property (nonatomic) EAGLContext *context; +@property (nonatomic, readwrite) EAGLContext *context; @property (nonatomic) GLKView *glView; @property (nonatomic) UIImageView *glSnapshotView; diff --git a/platform/ios/src/MGLMapView_Private.h b/platform/ios/src/MGLMapView_Private.h index bddb9b093e..bffccec5fd 100644 --- a/platform/ios/src/MGLMapView_Private.h +++ b/platform/ios/src/MGLMapView_Private.h @@ -13,6 +13,9 @@ FOUNDATION_EXTERN MGL_EXPORT MGLExceptionName const MGLUnderlyingMapUnavailableE @interface MGLMapView (Private) +/// The map view’s OpenGL rendering context. +@property (nonatomic, readonly) EAGLContext *context; + /// Currently shown popover representing the selected annotation. @property (nonatomic) UIView *calloutViewForSelectedAnnotation; diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 482333a26c..5a24524b4a 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -707,6 +707,11 @@ public: return !_isTargetingInterfaceBuilder; } +- (CGLContextObj)context { + MGLOpenGLLayer *layer = _isTargetingInterfaceBuilder ? nil : (MGLOpenGLLayer *)self.layer; + return layer.openGLContext.CGLContextObj; +} + - (void)setFrame:(NSRect)frame { super.frame = frame; if (!_isTargetingInterfaceBuilder) { diff --git a/platform/macos/src/MGLMapView_Private.h b/platform/macos/src/MGLMapView_Private.h index f2d178bc31..986ae1143a 100644 --- a/platform/macos/src/MGLMapView_Private.h +++ b/platform/macos/src/MGLMapView_Private.h @@ -22,6 +22,9 @@ namespace mbgl { /// Center longitude set independently of the center latitude in an inspectable. @property (nonatomic) CLLocationDegrees pendingLongitude; +/// The map view’s OpenGL rendering context. +- (CGLContextObj)context; + /// Asynchronously render a frame of the map. - (void)setNeedsGLDisplay; -- cgit v1.2.1