Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moved label rendering off into a dispatch queue. Cleaned up some of t…

…he vestigal cache management code. The rest will be going away as well. Tweaked the defaults on the globe view to make better use of continuous mode.
  • Loading branch information...
commit e8acf11e239cd65b53e5d9ed236c86860bb0a008 1 parent 6fd9bd7
@mousebird mousebird authored
View
2  WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/private/PanDelegateFixed.h
@@ -26,7 +26,7 @@ typedef enum {PanNone,PanFree,PanSuspended} PanningType;
// Scale factors for the angular velocity
// Used with height
-#define MaxAngularVelocity 1500.0
+#define MaxAngularVelocity 750.0
#define MinAngularVelocity 1.0
// Version of pan delegate specific to this app
View
58 ...yGlobeSrc/WhirlyGlobeComponentTester/WhirlyGlobeComponentTester.xcodeproj/project.pbxproj
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ 2B0A4D92167AF22A000D5786 /* WhirlyGlobeMaplyComponent.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2B0A4D91167AF22A000D5786 /* WhirlyGlobeMaplyComponent.framework */; };
2BB9E02315BFA57600F1DDD8 /* Star.png in Resources */ = {isa = PBXBuildFile; fileRef = 2BB9E02215BFA57600F1DDD8 /* Star.png */; };
2BD4C9681642FF88004C8F67 /* lowres_wtb_0x0.pvrtc in Resources */ = {isa = PBXBuildFile; fileRef = 2BD4C95D1642FF88004C8F67 /* lowres_wtb_0x0.pvrtc */; };
2BD4C9691642FF88004C8F67 /* lowres_wtb_0x1.pvrtc in Resources */ = {isa = PBXBuildFile; fileRef = 2BD4C95E1642FF88004C8F67 /* lowres_wtb_0x1.pvrtc */; };
@@ -284,21 +285,11 @@
2BE849CD15BDFB40006CFD3F /* ConfigViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2BE849CB15BDFB40006CFD3F /* ConfigViewController.m */; };
2BE849CE15BDFB40006CFD3F /* ConfigViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2BE849CC15BDFB40006CFD3F /* ConfigViewController.xib */; };
2BE849D015BE01EE006CFD3F /* map_pin.png in Resources */ = {isa = PBXBuildFile; fileRef = 2BE849CF15BE01EE006CFD3F /* map_pin.png */; };
- 2BFDBA981632115600BB61E6 /* libWhirlyGlobe-MaplyComponent.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2BFDBA951632110D00BB61E6 /* libWhirlyGlobe-MaplyComponent.a */; };
2BFDBA9A16321E1D00BB61E6 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 2BFDBA9916321E1D00BB61E6 /* Default-568h@2x.png */; };
/* End PBXBuildFile section */
-/* Begin PBXContainerItemProxy section */
- 2BFDBA941632110D00BB61E6 /* PBXContainerItemProxy */ = {
- isa = PBXContainerItemProxy;
- containerPortal = 2BFDBA891632110D00BB61E6 /* WhirlyGlobe-MaplyComponent.xcodeproj */;
- proxyType = 2;
- remoteGlobalIDString = 2B11E0DB15B4C030007AAE3F;
- remoteInfo = "WhirlyGlobe-MaplyComponent";
- };
-/* End PBXContainerItemProxy section */
-
/* Begin PBXFileReference section */
+ 2B0A4D91167AF22A000D5786 /* WhirlyGlobeMaplyComponent.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WhirlyGlobeMaplyComponent.framework; path = ../../WhirlyGlobeComponentDistribution_2_1_alpha/WhirlyGlobeMaplyComponent.framework; sourceTree = "<group>"; };
2BB9E02215BFA57600F1DDD8 /* Star.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Star.png; path = resources/Star.png; sourceTree = SOURCE_ROOT; };
2BD4C95D1642FF88004C8F67 /* lowres_wtb_0x0.pvrtc */ = {isa = PBXFileReference; lastKnownFileType = file; path = lowres_wtb_0x0.pvrtc; sourceTree = "<group>"; };
2BD4C95E1642FF88004C8F67 /* lowres_wtb_0x1.pvrtc */ = {isa = PBXFileReference; lastKnownFileType = file; path = lowres_wtb_0x1.pvrtc; sourceTree = "<group>"; };
@@ -583,7 +574,6 @@
2BE849CB15BDFB40006CFD3F /* ConfigViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConfigViewController.m; sourceTree = "<group>"; };
2BE849CC15BDFB40006CFD3F /* ConfigViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ConfigViewController.xib; sourceTree = "<group>"; };
2BE849CF15BE01EE006CFD3F /* map_pin.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = map_pin.png; path = resources/map_pin.png; sourceTree = SOURCE_ROOT; };
- 2BFDBA891632110D00BB61E6 /* WhirlyGlobe-MaplyComponent.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "WhirlyGlobe-MaplyComponent.xcodeproj"; path = "../WhirlyGlobe-MaplyComponent/WhirlyGlobe-MaplyComponent.xcodeproj"; sourceTree = "<group>"; };
2BFDBA9916321E1D00BB61E6 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -592,7 +582,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
- 2BFDBA981632115600BB61E6 /* libWhirlyGlobe-MaplyComponent.a in Frameworks */,
+ 2B0A4D92167AF22A000D5786 /* WhirlyGlobeMaplyComponent.framework in Frameworks */,
2BE849AE15BDF7B6006CFD3F /* OpenGLES.framework in Frameworks */,
2BE849AC15BDF7AF006CFD3F /* QuartzCore.framework in Frameworks */,
2BE849AA15BDF7AB006CFD3F /* libsqlite3.dylib in Frameworks */,
@@ -895,8 +885,8 @@
2BE8496215BDE270006CFD3F = {
isa = PBXGroup;
children = (
+ 2B0A4D91167AF22A000D5786 /* WhirlyGlobeMaplyComponent.framework */,
2BFDBA9916321E1D00BB61E6 /* Default-568h@2x.png */,
- 2BFDBA891632110D00BB61E6 /* WhirlyGlobe-MaplyComponent.xcodeproj */,
2BE849AD15BDF7B5006CFD3F /* OpenGLES.framework */,
2BE849AB15BDF7AF006CFD3F /* QuartzCore.framework */,
2BE849A915BDF7AB006CFD3F /* libsqlite3.dylib */,
@@ -964,14 +954,6 @@
name = resources;
sourceTree = "<group>";
};
- 2BFDBA8A1632110D00BB61E6 /* Products */ = {
- isa = PBXGroup;
- children = (
- 2BFDBA951632110D00BB61E6 /* libWhirlyGlobe-MaplyComponent.a */,
- );
- name = Products;
- sourceTree = "<group>";
- };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -1010,12 +992,6 @@
mainGroup = 2BE8496215BDE270006CFD3F;
productRefGroup = 2BE8496E15BDE270006CFD3F /* Products */;
projectDirPath = "";
- projectReferences = (
- {
- ProductGroup = 2BFDBA8A1632110D00BB61E6 /* Products */;
- ProjectRef = 2BFDBA891632110D00BB61E6 /* WhirlyGlobe-MaplyComponent.xcodeproj */;
- },
- );
projectRoot = "";
targets = (
2BE8496C15BDE270006CFD3F /* WhirlyGlobeComponentTester */,
@@ -1023,16 +999,6 @@
};
/* End PBXProject section */
-/* Begin PBXReferenceProxy section */
- 2BFDBA951632110D00BB61E6 /* libWhirlyGlobe-MaplyComponent.a */ = {
- isa = PBXReferenceProxy;
- fileType = archive.ar;
- path = "libWhirlyGlobe-MaplyComponent.a";
- remoteRef = 2BFDBA941632110D00BB61E6 /* PBXContainerItemProxy */;
- sourceTree = BUILT_PRODUCTS_DIR;
- };
-/* End PBXReferenceProxy section */
-
/* Begin PBXResourcesBuildPhase section */
2BE8496B15BDE270006CFD3F /* Resources */ = {
isa = PBXResourcesBuildPhase;
@@ -1386,9 +1352,15 @@
2BE8498615BDE270006CFD3F /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ FRAMEWORK_SEARCH_PATHS = (
+ "$(inherited)",
+ "\"$(SRCROOT)\"",
+ "\"/Users/sjg/iPhone/WhirlyGlobe2/WhirlyGlobeComponentDistribution_2_1_alpha/WhirlyGlobeMaplyComponent.framework\"",
+ "\"$(SRCROOT)/../../WhirlyGlobeComponentDistribution_2_1_alpha\"",
+ );
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "WhirlyGlobeComponentTester/WhirlyGlobeComponentTester-Prefix.pch";
- HEADER_SEARCH_PATHS = "../WhirlyGlobe-MaplyComponent/include/";
+ HEADER_SEARCH_PATHS = "\"/Users/sjg/iPhone/WhirlyGlobe2/WhirlyGlobeComponentDistribution_2_1_alpha/WhirlyGlobeMaplyComponent.framework/Headers/\"";
INFOPLIST_FILE = "WhirlyGlobeComponentTester/WhirlyGlobeComponentTester-Info.plist";
OTHER_LDFLAGS = "-all_load";
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1399,9 +1371,15 @@
2BE8498715BDE270006CFD3F /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ FRAMEWORK_SEARCH_PATHS = (
+ "$(inherited)",
+ "\"$(SRCROOT)\"",
+ "\"/Users/sjg/iPhone/WhirlyGlobe2/WhirlyGlobeComponentDistribution_2_1_alpha/WhirlyGlobeMaplyComponent.framework\"",
+ "\"$(SRCROOT)/../../WhirlyGlobeComponentDistribution_2_1_alpha\"",
+ );
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "WhirlyGlobeComponentTester/WhirlyGlobeComponentTester-Prefix.pch";
- HEADER_SEARCH_PATHS = "../WhirlyGlobe-MaplyComponent/include/";
+ HEADER_SEARCH_PATHS = "\"/Users/sjg/iPhone/WhirlyGlobe2/WhirlyGlobeComponentDistribution_2_1_alpha/WhirlyGlobeMaplyComponent.framework/Headers/\"";
INFOPLIST_FILE = "WhirlyGlobeComponentTester/WhirlyGlobeComponentTester-Info.plist";
OTHER_LDFLAGS = "-all_load";
PRODUCT_NAME = "$(TARGET_NAME)";
View
6 WhirlyGlobeSrc/WhirlyGlobeLib/include/LabelLayer.h
@@ -200,12 +200,6 @@ static const unsigned int LabelTextureAtlasSizeDefault = 512;
/// You get the ID identifying the whole group for modification or deletion
- (WhirlyKit::SimpleIdentity) addLabels:(NSArray *)labels desc:(NSDictionary *)desc;
-/// Add a group of labels and save them to a render cache
-- (WhirlyKit::SimpleIdentity) addLabels:(NSArray *)labels desc:(NSDictionary *)desc cacheName:(NSString *)cacheName;
-
-/// Add a previously cached group of labels all at once
-- (WhirlyKit::SimpleIdentity) addLabelsFromCache:(NSString *)cacheName;
-
/// Change the display of a given label accordingly to the desc dictionary.
/// Only minVis and maxVis are supported
- (void)changeLabel:(WhirlyKit::SimpleIdentity)labelID desc:(NSDictionary *)dict;
View
3  WhirlyGlobeSrc/WhirlyGlobeLib/include/Scene.h
@@ -61,6 +61,9 @@ class AddTextureReq : public ChangeRequest
/// Add to the renderer. Never call this.
void execute(Scene *scene,WhirlyKitSceneRendererES *renderer,WhirlyKitView *view);
+ /// Only use this if you've thought it out
+ Texture *getTex() { return tex; }
+
protected:
Texture *tex;
};
View
2  WhirlyGlobeSrc/WhirlyGlobeLib/src/GlobeView.mm
@@ -56,7 +56,7 @@ - (id)init
absoluteMinNearPlane = 0.00001;
absoluteMinFarPlane = 0.001;
absoluteMinHeight = 0.00005;
- heightInflection = 0.0011;
+ heightInflection = 0.011;
self.heightAboveGlobe = 1.1;
}
View
412 WhirlyGlobeSrc/WhirlyGlobeLib/src/LabelLayer.mm
@@ -23,7 +23,6 @@
#import "GlobeMath.h"
#import "NSString+Stuff.h"
#import "NSDictionary+Stuff.h"
-#import "RenderCache.h"
#import "ScreenSpaceGenerator.h"
using namespace WhirlyKit;
@@ -35,6 +34,10 @@
selectID = EmptyIdentity;
}
+// We use these for labels that have icons
+// Don't want to give them their own separate drawable, obviously
+typedef std::map<SimpleIdentity,BasicDrawable *> IconDrawables;
+
}
// How a label is justified for display
@@ -57,7 +60,6 @@ @interface LabelInfo : NSObject
int drawPriority;
WhirlyKit::SimpleIdentity labelId;
float fade;
- NSString *cacheName;
UIColor *shadowColor;
float shadowSize;
}
@@ -75,7 +77,6 @@ @interface LabelInfo : NSObject
@property (nonatomic,assign) int drawPriority;
@property (nonatomic,readonly) WhirlyKit::SimpleIdentity labelId;
@property (nonatomic,assign) float fade;
-@property (nonatomic) NSString *cacheName;
@property (nonatomic,strong) UIColor *shadowColor;
@property (nonatomic,assign) float shadowSize;
@@ -281,7 +282,6 @@ @implementation LabelInfo
@synthesize drawPriority;
@synthesize labelId;
@synthesize fade;
-@synthesize cacheName;
@synthesize shadowColor;
@synthesize shadowSize;
@@ -419,118 +419,44 @@ - (UIImage *)renderToImage:(WhirlyKitSingleLabel *)label powOfTwo:(BOOL)usePowOf
@end
-@implementation WhirlyKitLabelLayer
-
-@synthesize selectLayer;
-@synthesize layoutLayer;
-
-- (id)init
-{
- if ((self = [super init]))
- {
- textureAtlasSize = LabelTextureAtlasSizeDefault;
- }
-
- return self;
-}
-
-- (id)initWithTexAtlasSize:(unsigned int)inTextureAtlasSize
+// Used to render a whole bunch of labels in a dispatch queue
+@interface LabelRenderer : NSObject
{
- if ((self = [super init]))
- {
- textureAtlasSize = inTextureAtlasSize;
- }
-
- return self;
-}
+@public
+ LabelInfo *labelInfo;
+ int textureAtlasSize;
+ CoordSystemDisplayAdapter *coordAdapter;
+ LabelSceneRep *labelRep;
+ Scene *scene;
+ SimpleIdentity screenGenId;
+ NSMutableArray *layoutObjects;
+ std::vector<RectSelectable3D> selectables3D;
+ std::vector<RectSelectable2D> selectables2D;
-- (void)clear
-{
- layerThread = nil;
- for (LabelSceneRepMap::iterator it=labelReps.begin();
- it!=labelReps.end(); ++it)
- delete it->second;
- labelReps.clear();
-
- scene = NULL;
-}
-
-- (void)dealloc
-{
- [self clear];
-}
-
-// We only do things when called on, so nothing much to do here
-- (void)startWithThread:(WhirlyKitLayerThread *)inLayerThread scene:(WhirlyKit::Scene *)inScene;
-{
- layerThread = inLayerThread;
- scene = inScene;
- screenGenId = scene->getScreenSpaceGeneratorID();
-}
-
-// Clean out our textures and drawables
-- (void)shutdown
-{
- [NSObject cancelPreviousPerformRequestsWithTarget:self];
std::vector<ChangeRequest *> changeRequests;
-
- for (LabelSceneRepMap::iterator it=labelReps.begin();
- it!=labelReps.end(); ++it)
- {
- LabelSceneRep *labelRep = it->second;
- for (SimpleIDSet::iterator idIt = labelRep->drawIDs.begin();
- idIt != labelRep->drawIDs.end(); ++idIt)
- changeRequests.push_back(new RemDrawableReq(*idIt));
- for (SimpleIDSet::iterator idIt = labelRep->texIDs.begin();
- idIt != labelRep->texIDs.end(); ++idIt)
- changeRequests.push_back(new RemTextureReq(*idIt));
- for (SimpleIDSet::iterator idIt = labelRep->screenIDs.begin();
- idIt != labelRep->screenIDs.end(); ++idIt)
- scene->addChangeRequest(new ScreenSpaceGeneratorRemRequest(screenGenId, *idIt));
-
- if (labelRep->selectID != EmptyIdentity && selectLayer)
- [self.selectLayer removeSelectable:labelRep->selectID];
-
- if (layoutLayer && !labelRep->screenIDs.empty())
- [layoutLayer removeLayoutObjects:labelRep->screenIDs];
- }
- scene->addChangeRequests(changeRequests);
-
- [self clear];
}
-// We use these for labels that have icons
-// Don't want to give them their own separate drawable, obviously
-typedef std::map<SimpleIdentity,BasicDrawable *> IconDrawables;
+@end
// Used to track the rendered image cache
class RenderedImage
{
public:
RenderedImage() : image(NULL) { }
- RenderedImage(const RenderedImage &that) { textSize = that.textSize; image = that.image; }
+ RenderedImage(const RenderedImage &that) : textSize(that.textSize), image(that.image) { }
~RenderedImage() { }
- const RenderedImage &operator = (const RenderedImage &that) { textSize = that.textSize; image = that.image; return *this; }
+ const RenderedImage & operator = (const RenderedImage &that) { textSize = that.textSize; image = that.image; return *this; }
RenderedImage(CGSize textSize,UIImage *image) : textSize(textSize), image(image) { }
CGSize textSize;
UIImage *image;
};
-// Create the label and keep track of it
-// We're in the layer thread here
-// Note: Badly optimized for single label case
-- (void)runAddLabels:(LabelInfo *)labelInfo
+@implementation LabelRenderer
+
+- (void)render
{
NSTimeInterval curTime = CFAbsoluteTimeGetCurrent();
- CoordSystemDisplayAdapter *coordAdapter = scene->getCoordAdapter();
-
- // This lets us set up textures here
- [EAGLContext setCurrentContext:layerThread.glContext];
- LabelSceneRep *labelRep = new LabelSceneRep();
- labelRep->fade = labelInfo.fade;
- labelRep->setId(labelInfo.labelId);
-
// Texture atlases we're building up for the labels
std::vector<TextureAtlas *> texAtlases;
std::vector<BasicDrawable *> drawables;
@@ -539,12 +465,7 @@ - (void)runAddLabels:(LabelInfo *)labelInfo
std::vector<ScreenSpaceGenerator::ConvexShape *> screenObjects;
// Objects to pass to the layout engine
- NSMutableArray *layoutObjects = [NSMutableArray array];;
-
- // If we're writing out to a cache, set that up as well
- RenderCacheWriter *renderCacheWriter=NULL;
- if (labelInfo.cacheName)
- renderCacheWriter = new RenderCacheWriter(labelInfo.cacheName);
+ layoutObjects = [NSMutableArray array];;
// Drawables used for the icons
IconDrawables iconDrawables;
@@ -557,10 +478,10 @@ - (void)runAddLabels:(LabelInfo *)labelInfo
// Work through the labels
for (WhirlyKitSingleLabel *label in labelInfo.strs)
- {
+ {
TexCoord texOrg,texDest;
CGSize textSize;
-
+
// Find the image (if we already rendered it) or create it as needed
UIImage *textImage = nil;
std::string labelStr = [label.text asStdString];
@@ -586,8 +507,8 @@ - (void)runAddLabels:(LabelInfo *)labelInfo
BasicDrawable *drawable = NULL;
TextureAtlas *texAtlas = nil;
- if (texAtlasOn && textSize.width <= textureAtlasSize &&
- textSize.height <= textureAtlasSize)
+ if (texAtlasOn && textSize.width <= textureAtlasSize &&
+ textSize.height <= textureAtlasSize)
{
for (unsigned int ii=0;ii<texAtlases.size();ii++)
{
@@ -629,10 +550,10 @@ - (void)runAddLabels:(LabelInfo *)labelInfo
drawable->addTriangle(BasicDrawable::Triangle(0,1,2));
drawable->addTriangle(BasicDrawable::Triangle(2,3,0));
drawable->setDrawPriority(labelInfo.drawPriority);
- drawable->setVisibleRange(labelInfo.minVis,labelInfo.maxVis);
+ drawable->setVisibleRange(labelInfo.minVis,labelInfo.maxVis);
drawable->setAlpha(true);
}
- }
+ }
// Figure out the extents in 3-space
// Note: Probably won't work at the poles
@@ -658,7 +579,7 @@ - (void)runAddLabels:(LabelInfo *)labelInfo
// If there's an icon, we need to offset the label
float iconSize = (label.iconTexture==EmptyIdentity ? 0.f : 2*height2);
-
+
Point3f norm;
Point3f pts[4],iconPts[4];
ScreenSpaceGenerator::ConvexShape *screenShape = NULL;
@@ -682,8 +603,8 @@ - (void)runAddLabels:(LabelInfo *)labelInfo
if (labelInfo.fade > 0.0)
{
screenShape->fadeDown = curTime;
- screenShape->fadeUp = curTime+labelInfo.fade;
- }
+ screenShape->fadeUp = curTime+labelInfo.fade;
+ }
if (label.isSelectable && label.selectID != EmptyIdentity)
screenShape->setId(label.selectID);
labelRep->screenIDs.insert(screenShape->getId());
@@ -694,15 +615,14 @@ - (void)runAddLabels:(LabelInfo *)labelInfo
smGeom.coords.push_back(Point2f(pts[ii].x(),pts[ii].y()));
smGeom.texCoords.push_back(texCoord[ii]);
}
-// smGeom.color = labelInfo.color;
+ // smGeom.color = labelInfo.color;
if (!texAtlas)
{
// This texture was unique to the object
Texture *tex = new Texture(textImage);
if (labelInfo.screenObject)
tex->setUsesMipmaps(false);
- tex->createInGL(true,scene->getMemManager());
- scene->addChangeRequest(new AddTextureReq(tex));
+ changeRequests.push_back(new AddTextureReq(tex));
smGeom.texID = tex->getId();
labelRep->texIDs.insert(tex->getId());
} else
@@ -726,7 +646,7 @@ - (void)runAddLabels:(LabelInfo *)labelInfo
// Note: Should parse out acceptable placements as well
layoutObj->acceptablePlacement = WhirlyKitLayoutPlacementLeft | WhirlyKitLayoutPlacementRight | WhirlyKitLayoutPlacementAbove | WhirlyKitLayoutPlacementBelow;
[layoutObjects addObject:layoutObj];
-
+
// The shape starts out disabled
screenShape->enable = false;
} else
@@ -740,11 +660,11 @@ - (void)runAddLabels:(LabelInfo *)labelInfo
texCoord[1].u() = texDest.u(); texCoord[1].v() = texOrg.v();
texCoord[2].u() = texDest.u(); texCoord[2].v() = texDest.v();
texCoord[3].u() = texOrg.u(); texCoord[3].v() = texDest.v();
-
+
Point3f ll;
[label calcExtents2:width2 height2:height2 iconSize:iconSize justify:labelInfo.justify corners:pts norm:&norm iconCorners:iconPts coordAdapter:coordAdapter];
-
+
// Add to the drawable we found (corresponding to a texture atlas)
int vOff = drawable->getNumPoints();
for (unsigned int ii=0;ii<4;ii++)
@@ -766,24 +686,16 @@ - (void)runAddLabels:(LabelInfo *)labelInfo
if (!texAtlas)
{
Texture *tex = new Texture(textImage);
- tex->createInGL(true,scene->getMemManager());
drawable->setTexId(tex->getId());
- // Add these to the cache first, before the renderer messes with them
- if (renderCacheWriter)
- {
- renderCacheWriter->addTexture(tex->getId(),textImage);
- renderCacheWriter->addDrawable(drawable);
- }
-
if (labelInfo.fade > 0.0)
{
drawable->setFade(curTime,curTime+labelInfo.fade);
}
-
+
// Pass over to the renderer
- scene->addChangeRequest(new AddTextureReq(tex));
- scene->addChangeRequest(new AddDrawableReq(drawable));
+ changeRequests.push_back(new AddTextureReq(tex));
+ changeRequests.push_back(new AddDrawableReq(drawable));
labelRep->texIDs.insert(tex->getId());
labelRep->drawIDs.insert(drawable->getId());
@@ -791,21 +703,28 @@ - (void)runAddLabels:(LabelInfo *)labelInfo
}
// Register the main label as selectable
- if (selectLayer && label.isSelectable)
+ if (label.isSelectable)
{
// If the marker doesn't already have an ID, it needs one
if (!label.selectID)
label.selectID = Identifiable::genId();
-
+
if (labelInfo.screenObject)
{
- Point2f pts2d[4];
+ RectSelectable2D select2d;
for (unsigned int pp=0;pp<4;pp++)
- pts2d[pp] = Point2f(pts[pp].x(),pts[pp].y());
- [selectLayer addSelectableScreenRect:label.selectID rect:pts2d minVis:labelInfo.minVis maxVis:labelInfo.maxVis];
+ select2d.pts[pp] = Point2f(pts[pp].x(),pts[pp].y());
+ select2d.selectID = label.selectID;
+ select2d.minVis = labelInfo.minVis;
+ select2d.maxVis = labelInfo.maxVis;
+ selectables2D.push_back(select2d);
labelRep->selectID = label.selectID;
- } else {
- [selectLayer addSelectableRect:label.selectID rect:pts];
+ } else {
+ RectSelectable3D select3d;
+ select3d.selectID = label.selectID;
+ for (unsigned int jj=0;jj<4;jj++)
+ select3d.pts[jj] = pts[jj];
+ selectables3D.push_back(select3d);
labelRep->selectID = label.selectID;
}
}
@@ -813,9 +732,6 @@ - (void)runAddLabels:(LabelInfo *)labelInfo
// If there's an icon, let's add that
if (label.iconTexture != EmptyIdentity)
{
- if (renderCacheWriter)
- NSLog(@"LabelLayer: icon textures will not be cached properly.");
-
SubTexture subTex = scene->getSubTexture(label.iconTexture);
std::vector<TexCoord> texCoord;
texCoord.resize(4);
@@ -854,7 +770,7 @@ - (void)runAddLabels:(LabelInfo *)labelInfo
iconDrawables[subTex.texId] = iconDrawable;
} else
iconDrawable = it->second;
-
+
// Add to the drawable we found (corresponding to a texture atlas)
int vOff = iconDrawable->getNumPoints();
for (unsigned int ii=0;ii<4;ii++)
@@ -873,7 +789,7 @@ - (void)runAddLabels:(LabelInfo *)labelInfo
}
}
}
-
+
// Generate textures from the atlases, point the drawables at them
// and hand both over to the rendering thread
// Keep track of all of this stuff for the label representation (for deletion later)
@@ -883,79 +799,196 @@ - (void)runAddLabels:(LabelInfo *)labelInfo
Texture *tex = [texAtlases[ii] createTexture:&theImage];
if (labelInfo.screenObject)
tex->setUsesMipmaps(false);
- tex->createInGL(true,scene->getMemManager());
- scene->addChangeRequest(new AddTextureReq(tex));
+ // tex->createInGL(true,scene->getMemManager());
+ changeRequests.push_back(new AddTextureReq(tex));
labelRep->texIDs.insert(tex->getId());
-
+
if (!labelInfo.screenObject)
{
BasicDrawable *drawable = drawables[ii];
drawable->setTexId(tex->getId());
-
- // And save out to the cache if need be
- if (renderCacheWriter)
- {
- renderCacheWriter->addTexture(tex->getId(),theImage);
- renderCacheWriter->addDrawable(drawable);
- }
-
+
if (labelInfo.fade > 0.0)
{
NSTimeInterval curTime = CFAbsoluteTimeGetCurrent();
drawable->setFade(curTime,curTime+labelInfo.fade);
}
- scene->addChangeRequest(new AddDrawableReq(drawable));
+ changeRequests.push_back(new AddDrawableReq(drawable));
labelRep->drawIDs.insert(drawable->getId());
}
- }
-
+ }
+
// Flush out the icon drawables as well
for (IconDrawables::iterator it = iconDrawables.begin();
it != iconDrawables.end(); ++it)
{
BasicDrawable *iconDrawable = it->second;
-
+
if (labelInfo.fade > 0.0)
{
NSTimeInterval curTime = CFAbsoluteTimeGetCurrent();
iconDrawable->setFade(curTime,curTime+labelInfo.fade);
}
- scene->addChangeRequest(new AddDrawableReq(iconDrawable));
+ changeRequests.push_back(new AddDrawableReq(iconDrawable));
labelRep->drawIDs.insert(iconDrawable->getId());
}
// Send the screen objects to the generator
- scene->addChangeRequest(new ScreenSpaceGeneratorAddRequest(screenGenId,screenObjects));
+ changeRequests.push_back(new ScreenSpaceGeneratorAddRequest(screenGenId,screenObjects));
+}
+
+@end
+
+@implementation WhirlyKitLabelLayer
+
+@synthesize selectLayer;
+@synthesize layoutLayer;
+
+- (id)init
+{
+ if ((self = [super init]))
+ {
+ textureAtlasSize = LabelTextureAtlasSizeDefault;
+ }
- // And any layout constraints to the layout engine
- if (layoutLayer && ([layoutObjects count] > 0))
- [layoutLayer addLayoutObjects:layoutObjects];
+ return self;
+}
+
+- (id)initWithTexAtlasSize:(unsigned int)inTextureAtlasSize
+{
+ if ((self = [super init]))
+ {
+ textureAtlasSize = inTextureAtlasSize;
+ }
- labelReps[labelRep->getId()] = labelRep;
+ return self;
+}
+
+- (void)clear
+{
+ layerThread = nil;
+ for (LabelSceneRepMap::iterator it=labelReps.begin();
+ it!=labelReps.end(); ++it)
+ delete it->second;
+ labelReps.clear();
- if (renderCacheWriter)
- delete renderCacheWriter;
+ scene = NULL;
}
-// Add a group of labels that was previously saved to a cache
-- (void)runAddLabelsFromCache:(LabelInfo *)labelInfo
+- (void)dealloc
{
- RenderCacheReader *renderCacheReader = new RenderCacheReader(labelInfo.cacheName);
+ [self clear];
+}
+
+// We only do things when called on, so nothing much to do here
+- (void)startWithThread:(WhirlyKitLayerThread *)inLayerThread scene:(WhirlyKit::Scene *)inScene;
+{
+ layerThread = inLayerThread;
+ scene = inScene;
+ screenGenId = scene->getScreenSpaceGeneratorID();
+}
+
+// Clean out our textures and drawables
+- (void)shutdown
+{
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
+ std::vector<ChangeRequest *> changeRequests;
- // Load in the textures and drawables
- SimpleIDSet texIDs,drawIDs;
- if (!renderCacheReader->getDrawablesAndTexturesAddToScene(scene,texIDs,drawIDs,labelInfo.fade))
- NSLog(@"LabelLayer failed to load from cache: %@",labelInfo.cacheName);
- else
+ for (LabelSceneRepMap::iterator it=labelReps.begin();
+ it!=labelReps.end(); ++it)
{
- LabelSceneRep *labelRep = new LabelSceneRep();
- labelRep->setId(labelInfo.labelId);
- labelRep->texIDs = texIDs;
- labelRep->drawIDs = drawIDs;
- labelReps[labelRep->getId()] = labelRep;
+ LabelSceneRep *labelRep = it->second;
+ for (SimpleIDSet::iterator idIt = labelRep->drawIDs.begin();
+ idIt != labelRep->drawIDs.end(); ++idIt)
+ changeRequests.push_back(new RemDrawableReq(*idIt));
+ for (SimpleIDSet::iterator idIt = labelRep->texIDs.begin();
+ idIt != labelRep->texIDs.end(); ++idIt)
+ changeRequests.push_back(new RemTextureReq(*idIt));
+ for (SimpleIDSet::iterator idIt = labelRep->screenIDs.begin();
+ idIt != labelRep->screenIDs.end(); ++idIt)
+ scene->addChangeRequest(new ScreenSpaceGeneratorRemRequest(screenGenId, *idIt));
+
+ if (labelRep->selectID != EmptyIdentity && selectLayer)
+ [self.selectLayer removeSelectable:labelRep->selectID];
+
+ if (layoutLayer && !labelRep->screenIDs.empty())
+ [layoutLayer removeLayoutObjects:labelRep->screenIDs];
+ }
+ scene->addChangeRequests(changeRequests);
+
+ [self clear];
+}
+
+// Create the label and keep track of it
+// We're in the layer thread here
+// Note: Badly optimized for single label case
+- (void)runAddLabels:(LabelInfo *)labelInfo
+{
+ // Set up the representation (but then hand it off)
+ LabelSceneRep *labelRep = new LabelSceneRep();
+ labelRep->fade = labelInfo.fade;
+ labelRep->setId(labelInfo.labelId);
+
+ // Set up the label renderer
+ LabelRenderer *labelRenderer = [[LabelRenderer alloc] init];
+ labelRenderer->labelInfo = labelInfo;
+ labelRenderer->textureAtlasSize = textureAtlasSize;
+ labelRenderer->coordAdapter = scene->getCoordAdapter();
+ labelRenderer->labelRep = labelRep;
+ labelRenderer->scene = scene;
+ labelRenderer->screenGenId = screenGenId;
+
+ // Do the render somewhere else and merge in the results back on our thread
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
+ {
+ [labelRenderer render];
+ [self performSelector:@selector(mergeRenderedLabels:) onThread:layerThread withObject:labelRenderer waitUntilDone:NO];
+ });
+
+ // Note: This means we can't delete the labels while they're rendering. Bug.
+// labelReps[labelRep->getId()] = labelRep;
+}
+
+- (void)mergeRenderedLabels:(LabelRenderer *)labelRenderer
+{
+ // We'll run through the textures and create them here
+ [EAGLContext setCurrentContext:layerThread.glContext];
+ for (unsigned int ii=0;ii<labelRenderer->changeRequests.size();ii++)
+ {
+ ChangeRequest *cr = labelRenderer->changeRequests[ii];
+ AddTextureReq *texReq = dynamic_cast<AddTextureReq *>(cr);
+ if (texReq)
+ {
+ Texture *tex = texReq->getTex();
+ tex->createInGL(true, scene->getMemManager());
+ }
}
- delete renderCacheReader;
+ // Flush out the changes
+ scene->addChangeRequests(labelRenderer->changeRequests);
+
+ // And any layout constraints to the layout engine
+ if (layoutLayer && ([labelRenderer->layoutObjects count] > 0))
+ [layoutLayer addLayoutObjects:labelRenderer->layoutObjects];
+
+ // And set up the selectables
+ // [selectLayer addSelectableScreenRect:label.selectID rect:pts2d minVis:labelInfo.minVis maxVis:labelInfo.maxVis];
+ // [selectLayer addSelectableRect:label.selectID rect:pts];
+ if (selectLayer)
+ {
+ for (unsigned int ii=0;ii<labelRenderer->selectables2D.size();ii++)
+ {
+ RectSelectable2D &sel = labelRenderer->selectables2D[ii];
+ [selectLayer addSelectableScreenRect:sel.selectID rect:sel.pts minVis:sel.minVis maxVis:sel.maxVis];
+ }
+ for (unsigned int ii=0;ii<labelRenderer->selectables3D.size();ii++)
+ {
+ RectSelectable3D &sel = labelRenderer->selectables3D[ii];
+ [selectLayer addSelectableRect:sel.selectID rect:sel.pts minVis:sel.minVis maxVis:sel.maxVis];
+ }
+ }
+
+ labelReps[labelRenderer->labelRep->getId()] = labelRenderer->labelRep;
}
// Remove the given label
@@ -1022,19 +1055,13 @@ - (SimpleIdentity) addLabel:(NSString *)str loc:(WhirlyKit::GeoCoord)loc desc:(N
return labelInfo.labelId;
}
-// Pass off creation of a whole bunch of labels
-- (SimpleIdentity) addLabels:(NSArray *)labels desc:(NSDictionary *)desc
-{
- return [self addLabels:labels desc:desc cacheName:nil];
-}
-
- (SimpleIdentity) addLabel:(WhirlyKitSingleLabel *)label
{
return [self addLabels:[NSMutableArray arrayWithObject:label] desc:label.desc];
}
-/// Add a group of labels and save them to a render cache
-- (SimpleIdentity) addLabels:(NSArray *)labels desc:(NSDictionary *)desc cacheName:(NSString *)cacheName
+/// Add a group of labels
+- (SimpleIdentity) addLabels:(NSArray *)labels desc:(NSDictionary *)desc
{
if (!layerThread || !scene)
{
@@ -1043,7 +1070,6 @@ - (SimpleIdentity) addLabels:(NSArray *)labels desc:(NSDictionary *)desc cacheNa
}
LabelInfo *labelInfo = [[LabelInfo alloc] initWithStrs:labels desc:desc];
- labelInfo.cacheName = cacheName;
if (!layerThread || ([NSThread currentThread] == layerThread))
[self runAddLabels:labelInfo];
@@ -1053,20 +1079,6 @@ - (SimpleIdentity) addLabels:(NSArray *)labels desc:(NSDictionary *)desc cacheNa
return labelInfo.labelId;
}
-/// Add a previously cached group of labels all at once
-- (WhirlyKit::SimpleIdentity) addLabelsFromCache:(NSString *)cacheName
-{
- LabelInfo *labelInfo = [[LabelInfo alloc] init];
- labelInfo.cacheName = cacheName;
-
- if (!layerThread || ([NSThread currentThread] == layerThread))
- [self runAddLabelsFromCache:labelInfo];
- else
- [self performSelector:@selector(runAddLabels:) onThread:layerThread withObject:labelInfo waitUntilDone:NO];
-
- return labelInfo.labelId;
-}
-
// Change visual representation for a group of labels
// Only doing min/max vis for now
- (void) runChangeLabel:(LabelInfo *)labelInfo
View
4 WhirlyGlobeSrc/WhirlyGlobeLib/src/WhirlyKitView.mm
@@ -37,9 +37,9 @@ - (id)init
if ((self = [super init]))
{
fieldOfView = 60.0 / 360.0 * 2 * (float)M_PI; // 60 degree field of view
- nearPlane = 0.001;
+ nearPlane = 0.01;
imagePlaneSize = nearPlane * tanf(fieldOfView / 2.0);
- farPlane = 3.25;
+ farPlane = 4.0;
lastChangedTime = CFAbsoluteTimeGetCurrent();
continuousZoom = false;
}
Please sign in to comment.
Something went wrong with that request. Please try again.