From 9c3488e1071a642cdbe83fd4b8b4d931265ef89a Mon Sep 17 00:00:00 2001 From: Longri Date: Sun, 12 Nov 2017 07:36:04 +0100 Subject: [PATCH] iOS: add POT textures test (#443) --- vtm-ios-example/build.gradle | 1 + .../org/oscim/ios/test/ExampleLauncher.java | 7 +- .../oscim/ios/test/IOSLineTexBucketTest.java | 118 ++++++++++++++++++ ...LineTexTest.java => IOSPathLayerTest.java} | 8 +- 4 files changed, 124 insertions(+), 10 deletions(-) create mode 100644 vtm-ios-example/src/org/oscim/ios/test/IOSLineTexBucketTest.java rename vtm-ios-example/src/org/oscim/ios/test/{IOSLineTexTest.java => IOSPathLayerTest.java} (91%) diff --git a/vtm-ios-example/build.gradle b/vtm-ios-example/build.gradle index 31eaace6..f248e496 100644 --- a/vtm-ios-example/build.gradle +++ b/vtm-ios-example/build.gradle @@ -29,6 +29,7 @@ dependencies { implementation project(':vtm-gdx') implementation project(':vtm-jts') implementation project(':vtm-ios') + implementation project(':vtm-themes') implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios" implementation "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion" implementation "com.mobidevelop.robovm:robovm-rt:$roboVMVersion" diff --git a/vtm-ios-example/src/org/oscim/ios/test/ExampleLauncher.java b/vtm-ios-example/src/org/oscim/ios/test/ExampleLauncher.java index 5fa392f3..0f730871 100644 --- a/vtm-ios-example/src/org/oscim/ios/test/ExampleLauncher.java +++ b/vtm-ios-example/src/org/oscim/ios/test/ExampleLauncher.java @@ -38,11 +38,12 @@ public class ExampleLauncher extends IOSApplication.Delegate { float scale = (float) (getIosVersion() >= 8 ? UIScreen.getMainScreen().getNativeScale() : UIScreen.getMainScreen().getScale()); CanvasAdapter.dpi *= scale; - IOSMapApp iosMapApp = new IOSMapApp(); -// IOSLineTexTest iosMapApp = new IOSLineTexTest(); -// IOSMapAppCluster iosMapApp = new IOSMapAppCluster(); +// IOSMapApp iosMapApp = new IOSMapApp(); +// IOSPathLayerTest iosMapApp = new IOSPathLayerTest(); + IOSLineTexBucketTest iosMapApp = new IOSLineTexBucketTest(); + // iOS needs POT textures for drawing lines with texture Parameters.POT_TEXTURES = true; iosMapApp.init(); diff --git a/vtm-ios-example/src/org/oscim/ios/test/IOSLineTexBucketTest.java b/vtm-ios-example/src/org/oscim/ios/test/IOSLineTexBucketTest.java new file mode 100644 index 00000000..d5e8722f --- /dev/null +++ b/vtm-ios-example/src/org/oscim/ios/test/IOSLineTexBucketTest.java @@ -0,0 +1,118 @@ +/* + * Copyright 2017 Longri + * + * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). + * + * This program is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ +package org.oscim.ios.test; + +import org.oscim.backend.CanvasAdapter; +import org.oscim.backend.GLAdapter; +import org.oscim.core.GeometryBuffer; +import org.oscim.core.Tag; +import org.oscim.core.TagSet; +import org.oscim.gdx.GdxAssets; +import org.oscim.gdx.GdxMap; +import org.oscim.ios.backend.IosGL; +import org.oscim.ios.backend.IosGraphics; +import org.oscim.layers.GenericLayer; +import org.oscim.renderer.BucketRenderer; +import org.oscim.renderer.GLViewport; +import org.oscim.renderer.MapRenderer; +import org.oscim.renderer.bucket.LineTexBucket; +import org.oscim.renderer.bucket.TextureItem; +import org.oscim.theme.IRenderTheme; +import org.oscim.theme.ThemeLoader; +import org.oscim.theme.VtmThemes; +import org.oscim.theme.styles.LineStyle; +import org.oscim.theme.styles.RenderStyle; + +import java.io.IOException; + +public class IOSLineTexBucketTest extends GdxMap { + + public static void init() { + // init globals + IosGraphics.init(); + GdxAssets.init("assets/"); + GLAdapter.init(new IosGL()); + } + + GeometryBuffer mLine = new GeometryBuffer(2, 1); + + LineTest l = new LineTest(); + + @Override + public void createLayers() { + MapRenderer.setBackgroundColor(0xffffffff); + + mMap.setMapPosition(0, 0, 1 << 4); + + GeometryBuffer g = mLine; + g.startLine(); + g.addPoint(-100, 0); + g.addPoint(100, 0); + + addLines(l); + + mMap.layers().add(new GenericLayer(mMap, l)); + } + + void addLines(LineTest l) { + + GeometryBuffer g = mLine; + LineStyle lineStyle; + TextureItem tex = null; + + try { + tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/pike.png")); + tex.mipmap = true; + } catch (IOException e) { + e.printStackTrace(); + } + + + IRenderTheme t = ThemeLoader.load(VtmThemes.DEFAULT); + + TagSet tags = new TagSet(); + tags.add(new Tag("highway", null)); + tags.add(new Tag("oneway", "yes")); + + RenderStyle[] ri = t.matchElement(GeometryBuffer.GeometryType.LINE, tags, 16); + + lineStyle = (LineStyle) ri[0]; + + LineTexBucket lt = l.buckets.getLineTexBucket(20); + lt.line = lineStyle; + lt.addLine(g.translate(0, 10.5f)); + + } + + class LineTest extends BucketRenderer { + + public LineTest() { + mMapPosition.scale = 0; + } + + @Override + public synchronized void update(GLViewport v) { + if (mMapPosition.scale == 0) + mMapPosition.copy(v.pos); + + if (!isReady()) { + compile(); + } + } + } + +} diff --git a/vtm-ios-example/src/org/oscim/ios/test/IOSLineTexTest.java b/vtm-ios-example/src/org/oscim/ios/test/IOSPathLayerTest.java similarity index 91% rename from vtm-ios-example/src/org/oscim/ios/test/IOSLineTexTest.java rename to vtm-ios-example/src/org/oscim/ios/test/IOSPathLayerTest.java index a0f375a1..7b30f755 100644 --- a/vtm-ios-example/src/org/oscim/ios/test/IOSLineTexTest.java +++ b/vtm-ios-example/src/org/oscim/ios/test/IOSPathLayerTest.java @@ -40,7 +40,7 @@ import org.oscim.utils.Utils; import java.util.ArrayList; import java.util.List; -public class IOSLineTexTest extends GdxMap { +public class IOSPathLayerTest extends GdxMap { public static void init() { // init globals @@ -91,12 +91,6 @@ public class IOSLineTexTest extends GdxMap { List pts = new ArrayList<>(); for (double lon = -180; lon <= 180; lon += 2) { - //pts.add(new GeoPoint(lat, lon)); - // double longitude = lon + (pos * 180); - // if (longitude < -180) - // longitude += 360; - // if (longitude > 180) - // longitude -= 360; double longitude = lon; double latitude = lat + (pos * 90);