From 442e1fb724a5c03482270dfc587ddb4102c6a143 Mon Sep 17 00:00:00 2001 From: jmkiley Date: Wed, 7 Feb 2018 13:34:33 -0800 Subject: [ios] Added debug code --- platform/ios/app/LimeGreenStyleLayer.h | 8 ++++ platform/ios/app/LimeGreenStyleLayer.m | 64 ++++++++++++++++++++++++++++++ platform/ios/app/MBXViewController.m | 30 +++++++++++++- platform/ios/ios.xcodeproj/project.pbxproj | 6 +++ 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 platform/ios/app/LimeGreenStyleLayer.h create mode 100644 platform/ios/app/LimeGreenStyleLayer.m diff --git a/platform/ios/app/LimeGreenStyleLayer.h b/platform/ios/app/LimeGreenStyleLayer.h new file mode 100644 index 0000000000..857b39ab37 --- /dev/null +++ b/platform/ios/app/LimeGreenStyleLayer.h @@ -0,0 +1,8 @@ + + +#import + + +@interface LimeGreenStyleLayer : MGLOpenGLStyleLayer + +@end diff --git a/platform/ios/app/LimeGreenStyleLayer.m b/platform/ios/app/LimeGreenStyleLayer.m new file mode 100644 index 0000000000..63cc7c8d4d --- /dev/null +++ b/platform/ios/app/LimeGreenStyleLayer.m @@ -0,0 +1,64 @@ + + +#import "LimeGreenStyleLayer.h" + +#import "LimeGreenStyleLayer.h" +@import OpenGLES; +//#include +//#include + +@implementation LimeGreenStyleLayer { + GLuint _program; + GLuint _vertexShader; + GLuint _fragmentShader; + GLuint _buffer; + GLuint _aPos; +} + +- (void)didMoveToMapView:(MGLMapView *)mapView { + static const GLchar *vertexShaderSource = "attribute vec2 a_pos; void main() { gl_Position = vec4(a_pos, 0, 1); }"; + static const GLchar *fragmentShaderSource = "void main() { gl_FragColor = vec4(0, 1, 0, 1); }"; + + _program = glCreateProgram(); + _vertexShader = glCreateShader(GL_VERTEX_SHADER); + _fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); + + glShaderSource(_vertexShader, 1, &vertexShaderSource, NULL); + glCompileShader(_vertexShader); + glAttachShader(_program, _vertexShader); + glShaderSource(_fragmentShader, 1, &fragmentShaderSource, NULL); + glCompileShader(_fragmentShader); + glAttachShader(_program, _fragmentShader); + glLinkProgram(_program); + _aPos = glGetAttribLocation(_program, "a_pos"); + + GLfloat background[] = { -1,-1, 1,-1, -1,1, 1,1 }; + glGenBuffers(1, &_buffer); + glBindBuffer(GL_ARRAY_BUFFER, _buffer); + glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(GLfloat), background, GL_STATIC_DRAW); +} + +- (void)drawInMapView:(MGLMapView *)mapView withContext:(MGLStyleLayerDrawingContext)context { + glUseProgram(_program); + glBindBuffer(GL_ARRAY_BUFFER, _buffer); + glEnableVertexAttribArray(_aPos); + glVertexAttribPointer(_aPos, 2, GL_FLOAT, GL_FALSE, 0, NULL); + glDisable(GL_STENCIL_TEST); + glDisable(GL_DEPTH_TEST); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); +} + +- (void)willMoveFromMapView:(MGLMapView *)mapView { + if (!_program) { + return; + } + + glDeleteBuffers(1, &_buffer); + glDetachShader(_program, _vertexShader); + glDetachShader(_program, _fragmentShader); + glDeleteShader(_vertexShader); + glDeleteShader(_fragmentShader); + glDeleteProgram(_program); +} + +@end diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 0f617188b9..e5a3aba482 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -6,7 +6,7 @@ #import "MBXAnnotationView.h" #import "MBXUserLocationAnnotationView.h" #import "MBXEmbeddedMapViewController.h" - +#import "LimeGreenStyleLayer.h" #import #import @@ -124,6 +124,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { @property (nonatomic) BOOL usingLocaleBasedCountryLabels; @property (nonatomic) BOOL reuseQueueStatsEnabled; @property (nonatomic) BOOL showZoomLevelEnabled; +@property (nonatomic, strong) LimeGreenStyleLayer *greenLayer; +@property (nonatomic) BOOL layerOn; @end @@ -1882,8 +1884,34 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { // that a device with an English-language locale is already effectively // using locale-based country labels. _usingLocaleBasedCountryLabels = [[self bestLanguageForUser] isEqualToString:@"en"]; + self.greenLayer = [[LimeGreenStyleLayer alloc] initWithIdentifier:@"LimeGreenLayer"]; + [mapView.style addLayer:self.greenLayer]; + [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(toggleLayer) userInfo:nil repeats:YES]; + self.layerOn = YES; +// [self toggleLayer]; } +- (void) toggleLayer { + +// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + // NSLog(@"%@", [[self.mapView.style layers] containsObject:self.greenLayer] ? @"YES" : @"NO"); + // NSLog(@"%@", self.greenLayer.debugDescription); + if (self.layerOn) { + + [self.mapView.style removeLayer:self.greenLayer]; + + self.layerOn = NO; + } + else { + // self.greenLayer = [[LimeGreenStyleLayer alloc] initWithIdentifier:@"LimeGreenLayer"]; + [self.mapView.style addLayer:self.greenLayer]; + self.layerOn = YES; + } + +// [self toggleLayer]; +// }); + +} - (void)mapViewRegionIsChanging:(MGLMapView *)mapView { [self updateHUD]; diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index d44fee3430..91ddcf7962 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -161,6 +161,7 @@ 35E79F201D41266300957B9E /* MGLStyleLayer_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 35E79F1F1D41266300957B9E /* MGLStyleLayer_Private.h */; }; 35E79F211D41266300957B9E /* MGLStyleLayer_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 35E79F1F1D41266300957B9E /* MGLStyleLayer_Private.h */; }; 36F1153D1D46080700878E1A /* libmbgl-core.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 36F1153B1D46080700878E1A /* libmbgl-core.a */; }; + 3E13828B202BA5AF00A44C98 /* LimeGreenStyleLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E13828A202BA5AF00A44C98 /* LimeGreenStyleLayer.m */; }; 3EA93369F61CF70AFA50465D /* MGLRendererConfiguration.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3EA931BC4F087E166D538F21 /* MGLRendererConfiguration.mm */; }; 3EA934623AD0000B7D99C3FB /* MGLRendererConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 3EA9337830C7738BF7F5493C /* MGLRendererConfiguration.h */; }; 3EA9363147E77DD29FA06063 /* MGLRendererConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 3EA9337830C7738BF7F5493C /* MGLRendererConfiguration.h */; }; @@ -746,6 +747,8 @@ 35E79F1F1D41266300957B9E /* MGLStyleLayer_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLStyleLayer_Private.h; sourceTree = ""; }; 36F1153B1D46080700878E1A /* libmbgl-core.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libmbgl-core.a"; path = "build/Debug-iphoneos/libmbgl-core.a"; sourceTree = ""; }; 36F1153C1D46080700878E1A /* libmbgl-platform-ios.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libmbgl-platform-ios.a"; path = "build/Debug-iphoneos/libmbgl-platform-ios.a"; sourceTree = ""; }; + 3E138289202BA5AE00A44C98 /* LimeGreenStyleLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LimeGreenStyleLayer.h; sourceTree = ""; }; + 3E13828A202BA5AF00A44C98 /* LimeGreenStyleLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LimeGreenStyleLayer.m; sourceTree = ""; }; 3EA931BC4F087E166D538F21 /* MGLRendererConfiguration.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLRendererConfiguration.mm; sourceTree = ""; }; 3EA9337830C7738BF7F5493C /* MGLRendererConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLRendererConfiguration.h; sourceTree = ""; }; 400532FF1DB0862B0069F638 /* NSArray+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+MGLAdditions.h"; sourceTree = ""; }; @@ -1415,6 +1418,8 @@ DA1DC94C1CB6C1C2006E619F /* Demo App */ = { isa = PBXGroup; children = ( + 3E138289202BA5AE00A44C98 /* LimeGreenStyleLayer.h */, + 3E13828A202BA5AF00A44C98 /* LimeGreenStyleLayer.m */, DA1DC9501CB6C1C2006E619F /* MBXAppDelegate.h */, DA1DC9981CB6E054006E619F /* MBXAppDelegate.m */, 40FDA7691CCAAA6800442548 /* MBXAnnotationView.h */, @@ -2518,6 +2523,7 @@ 927FBCFC1F4DAA8300F8BF1F /* MBXSnapshotsViewController.m in Sources */, DA1DC99B1CB6E064006E619F /* MBXViewController.m in Sources */, 40FDA76B1CCAAA6800442548 /* MBXAnnotationView.m in Sources */, + 3E13828B202BA5AF00A44C98 /* LimeGreenStyleLayer.m in Sources */, 632281DF1E6F855900D75A5D /* MBXEmbeddedMapViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; -- cgit v1.2.1