diff options
author | jmkiley <jordan.kiley@mapbox.com> | 2017-11-30 15:22:50 -0800 |
---|---|---|
committer | jmkiley <jordan.kiley@mapbox.com> | 2017-11-30 15:22:50 -0800 |
commit | 187eef17602cf30cd98efdb58ee882fbfca6d8f4 (patch) | |
tree | fdedbe28de2f98feecfb8061583f2e4075266fcf | |
parent | 8757164ac8f2b033b2b12d4baf075ed18cfeb2b4 (diff) | |
download | qtlocation-mapboxgl-187eef17602cf30cd98efdb58ee882fbfca6d8f4.tar.gz |
[ios] initial testing
-rw-r--r-- | platform/ios/app/MBXOpenGLLayer.h | 13 | ||||
-rw-r--r-- | platform/ios/app/MBXOpenGLLayer.m | 61 | ||||
-rw-r--r-- | platform/ios/app/MBXViewController.m | 8 | ||||
-rw-r--r-- | platform/ios/ios.xcodeproj/project.pbxproj | 6 |
4 files changed, 87 insertions, 1 deletions
diff --git a/platform/ios/app/MBXOpenGLLayer.h b/platform/ios/app/MBXOpenGLLayer.h new file mode 100644 index 0000000000..747c5c1263 --- /dev/null +++ b/platform/ios/app/MBXOpenGLLayer.h @@ -0,0 +1,13 @@ + // +// MBXOpenGLLayer.h +// iosapp +// +// Created by Jordan Kiley on 11/29/17. +// Copyright © 2017 Mapbox. All rights reserved. +// + +#import <Mapbox/Mapbox.h> + +@interface MBXOpenGLLayer : MGLOpenGLStyleLayer + +@end diff --git a/platform/ios/app/MBXOpenGLLayer.m b/platform/ios/app/MBXOpenGLLayer.m new file mode 100644 index 0000000000..db96ed310e --- /dev/null +++ b/platform/ios/app/MBXOpenGLLayer.m @@ -0,0 +1,61 @@ +#import "MBXOpenGLLayer.h" +// +#include <OpenGLES/ES3/gl.h> +#include <OpenGLES/ES3/glext.h> +//#include <MGLOpenGLStyleLayer.h> +@implementation MBXOpenGLLayer { + 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, 0, 1, 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"); +// coordina + GLfloat background[] = { 0,-1, 1,-1, 0,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, 3); + // glEnable(GL_DEPTH_TEST); + // glDepthFunc(GL_LEQUAL); +} + +- (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 4306354030..a49c1d77ba 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -10,7 +10,7 @@ #import <Mapbox/Mapbox.h> #import <objc/runtime.h> - +#import "MBXOpenGLLayer.h" static const CLLocationCoordinate2D WorldTourDestinations[] = { { .latitude = 38.9131982, .longitude = -77.0325453144239 }, { .latitude = 37.7757368, .longitude = -122.4135302 }, @@ -1931,6 +1931,12 @@ 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"]; + + MBXOpenGLLayer *layer = [[MBXOpenGLLayer alloc] initWithIdentifier:@"mbx-custom"]; + MGLSymbolStyleLayer *symbolLayer = [style layerWithIdentifier:@"admin-3-4-boundaries"]; + [style insertLayer:layer belowLayer:symbolLayer]; + + } - (void)mapViewRegionIsChanging:(MGLMapView *)mapView diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index a5e35c5cc7..2a676149cd 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -158,6 +158,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 */; }; + 3E9AD2D41FCF5A5900CF6B14 /* MBXOpenGLLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E9AD2D31FCF5A5900CF6B14 /* MBXOpenGLLayer.m */; }; 400533011DB0862B0069F638 /* NSArray+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 400532FF1DB0862B0069F638 /* NSArray+MGLAdditions.h */; }; 400533021DB0862B0069F638 /* NSArray+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 400533001DB0862B0069F638 /* NSArray+MGLAdditions.mm */; }; 400533031DB086490069F638 /* NSArray+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 400533001DB0862B0069F638 /* NSArray+MGLAdditions.mm */; }; @@ -676,6 +677,8 @@ 35E79F1F1D41266300957B9E /* MGLStyleLayer_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLStyleLayer_Private.h; sourceTree = "<group>"; }; 36F1153B1D46080700878E1A /* libmbgl-core.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libmbgl-core.a"; path = "build/Debug-iphoneos/libmbgl-core.a"; sourceTree = "<group>"; }; 36F1153C1D46080700878E1A /* libmbgl-platform-ios.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libmbgl-platform-ios.a"; path = "build/Debug-iphoneos/libmbgl-platform-ios.a"; sourceTree = "<group>"; }; + 3E9AD2D21FCF5A5800CF6B14 /* MBXOpenGLLayer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBXOpenGLLayer.h; sourceTree = "<group>"; }; + 3E9AD2D31FCF5A5900CF6B14 /* MBXOpenGLLayer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBXOpenGLLayer.m; sourceTree = "<group>"; }; 400532FF1DB0862B0069F638 /* NSArray+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+MGLAdditions.h"; sourceTree = "<group>"; }; 400533001DB0862B0069F638 /* NSArray+MGLAdditions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSArray+MGLAdditions.mm"; sourceTree = "<group>"; }; 4018B1C31CDC277F00F666AF /* MGLAnnotationView_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAnnotationView_Private.h; sourceTree = "<group>"; }; @@ -1296,6 +1299,8 @@ 40FDA76A1CCAAA6800442548 /* MBXAnnotationView.m */, DA1DC9661CB6C6B7006E619F /* MBXCustomCalloutView.h */, DA1DC9671CB6C6B7006E619F /* MBXCustomCalloutView.m */, + 3E9AD2D21FCF5A5800CF6B14 /* MBXOpenGLLayer.h */, + 3E9AD2D31FCF5A5900CF6B14 /* MBXOpenGLLayer.m */, 354B839A1D2E9B48005D9406 /* MBXUserLocationAnnotationView.h */, 354B839B1D2E9B48005D9406 /* MBXUserLocationAnnotationView.m */, DA1DC9681CB6C6B7006E619F /* MBXOfflinePacksTableViewController.h */, @@ -2267,6 +2272,7 @@ files = ( DA1DC9971CB6E046006E619F /* main.m in Sources */, 354B839C1D2E9B48005D9406 /* MBXUserLocationAnnotationView.m in Sources */, + 3E9AD2D41FCF5A5900CF6B14 /* MBXOpenGLLayer.m in Sources */, DA1DC9991CB6E054006E619F /* MBXAppDelegate.m in Sources */, DA1DC96B1CB6C6B7006E619F /* MBXOfflinePacksTableViewController.m in Sources */, DA1DC96A1CB6C6B7006E619F /* MBXCustomCalloutView.m in Sources */, |