Skip to content

Commit

Permalink
Significantly improved performance
Browse files Browse the repository at this point in the history
I went back to a much simpler traversal algorithm that generates pages
immediately, and fixed texture loading to occur in a separate thread. I
still need to set the initial texture of a new page to the texture of
the parent to avoid the loading flicker.
  • Loading branch information
RossAnderson committed Apr 16, 2012
1 parent 9e1bf5d commit 3732a69
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 114 deletions.
Binary file modified Images/clear256.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/clear256.pxm
Binary file not shown.
Binary file modified Images/grid256.acorn
Binary file not shown.
Binary file modified Images/grid256.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/grid256.pxm
Binary file not shown.
3 changes: 2 additions & 1 deletion Source/RAGeometry.h
Expand Up @@ -20,7 +20,8 @@
@property (assign, nonatomic) NSInteger colorOffset; // GLFloat r, g, b, a
@property (assign, nonatomic) NSInteger textureOffset; // GLFloat s, t

@property (strong, nonatomic) RATextureWrapper * texture;
@property (strong, nonatomic) RATextureWrapper * texture0;
@property (strong, nonatomic) RATextureWrapper * texture1;
@property (assign, nonatomic) GLKVector4 color; // set 1st component to -1 to disable
@property (retain, nonatomic) GLKEffectPropertyMaterial * material;
@property (assign, nonatomic) GLenum elementStyle; // default: GL_TRIANGLES
Expand Down
17 changes: 15 additions & 2 deletions Source/RAGeometry.m
Expand Up @@ -33,13 +33,15 @@ @implementation RAGeometry {

NSMutableData * _indexData;
GLint _indexStride;

BOOL _needsSetup;
}

@synthesize positionOffset = _positionOffset;
@synthesize normalOffset = _normalOffset;
@synthesize colorOffset = _colorOffset;
@synthesize textureOffset = _textureOffset;
@synthesize texture = _texture;
@synthesize texture0 = _texture0, texture1 = _texture1;
@synthesize color = _color;
@synthesize material = _material;
@synthesize elementStyle = _elementStyle;
Expand All @@ -63,6 +65,8 @@ - (id)init

_color = GLKVector4Make(-1, -1, -1, -1);
_elementStyle = GL_TRIANGLES;

_needsSetup = YES;
}
return self;
}
Expand Down Expand Up @@ -144,6 +148,8 @@ - (void)setIndexData:(const void *)data withSize:(NSUInteger)length withStride:(

- (void)setupGL
{
if ( _needsSetup == NO ) return;

// create vertex array if needed
if ( _vertexArray == BUFFER_INVALID ) {
glGenVertexArraysOES(1, &_vertexArray);
Expand Down Expand Up @@ -184,11 +190,16 @@ - (void)setupGL
glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_FALSE, _vertexStride, (const GLvoid *)_colorOffset);
}

if ( _textureOffset >= 0 ) {
if ( _textureOffset >= 0 && _texture0 ) {
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, _vertexStride, (const GLvoid *)_textureOffset);
}

if ( _textureOffset >= 0 && _texture1 ) {
glEnableVertexAttribArray(GLKVertexAttribTexCoord1);
glVertexAttribPointer(GLKVertexAttribTexCoord1, 2, GL_FLOAT, GL_FALSE, _vertexStride, (const GLvoid *)_textureOffset);
}

glBindVertexArrayOES(0);
}

Expand All @@ -201,6 +212,8 @@ - (void)releaseGL
_vertexBuffer = BUFFER_INVALID;
_indexBuffer = BUFFER_INVALID;
_vertexArray = BUFFER_INVALID;

_needsSetup = YES;
}

- (void)renderGL
Expand Down
5 changes: 0 additions & 5 deletions Source/RAPage.h
Expand Up @@ -29,8 +29,6 @@
@property (strong) RAGeometry * geometry;
@property (strong) UIImage * image;

@property (weak) NSOperation * buildOp;
@property (assign) BOOL needsUpdate;
@property (assign) NSTimeInterval lastRequestTime;

- (RAPage *)initWithTileID:(TileID)t andParent:(RAPage *)parent;
Expand All @@ -41,7 +39,4 @@

- (void)setCenter:(GLKVector3)center andRadius:(double)radius;

- (void)setupGL;
- (void)releaseGL;

@end
28 changes: 1 addition & 27 deletions Source/RAPage.m
Expand Up @@ -24,7 +24,7 @@ @implementation RAPage {
@synthesize geometry = _geometry;
@synthesize image = _image;
@synthesize parent = _parent, child1, child2, child3, child4;
@synthesize buildOp, needsUpdate, lastRequestTime;
@synthesize lastRequestTime;

- (RAPage *)initWithTileID:(TileID)t andParent:(RAPage *)parent;
{
Expand Down Expand Up @@ -65,30 +65,4 @@ - (BOOL)isLeaf {
return ( child1 == nil && child2 == nil && child3 == nil && child4 == nil );
}

- (void)setupGL {
if ( self.needsUpdate == NO ) return;

// create texture
GLKTextureInfo * textureInfo = nil;
if ( _image ) {
NSError * err = nil;
NSDictionary * options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:GLKTextureLoaderOriginBottomLeft];
textureInfo = [GLKTextureLoader textureWithCGImage:[_image CGImage] options:options error:&err];
if ( err ) NSLog(@"Error loading texture: %@", err);

self.geometry.texture = [[RATextureWrapper alloc] initWithTextureInfo:textureInfo];
} /*else {
NSLog(@"No image available for tile %@.", key);
}*/

self.needsUpdate = NO;
}

- (void)releaseGL {
[self.geometry releaseGL];

// release texture
self.needsUpdate = YES;
}

@end
16 changes: 12 additions & 4 deletions Source/RARenderVisitor.m
Expand Up @@ -89,16 +89,24 @@ - (void)renderWithEffect:(GLKBaseEffect *)effect
effect.useConstantColor = child.geometry.color.x > -1;
effect.constantColor = child.geometry.color;

if (child.geometry.texture != nil) {
if (child.geometry.texture0 != nil) {
effect.texture2d0.envMode = GLKTextureEnvModeModulate;
effect.texture2d0.target = GLKTextureTarget2D;
effect.texture2d0.name = child.geometry.texture.name;
effect.texture2d0.name = child.geometry.texture0.name;
effect.texture2d0.enabled = YES;
} else {
effect.texture2d0.name = child.geometry.texture.name;
effect.texture2d0.enabled = NO;
}


if (child.geometry.texture1 != nil) {
effect.texture2d1.envMode = GLKTextureEnvModeModulate;
effect.texture2d1.target = GLKTextureTarget2D;
effect.texture2d1.name = child.geometry.texture1.name;
effect.texture2d1.enabled = YES;
} else {
effect.texture2d1.enabled = NO;
}

[effect prepareToDraw];
[child.geometry renderGL];
}];
Expand Down
3 changes: 3 additions & 0 deletions Source/RASceneGraphController.m
Expand Up @@ -115,6 +115,9 @@ - (void)viewDidLoad

manipulator.view = self.view;

// create another context to load textures into
pager.loadingContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup:[context sharegroup]];

[self setupGL];
}

Expand Down
3 changes: 2 additions & 1 deletion Source/RATilePager.h
Expand Up @@ -8,7 +8,7 @@

#import <Foundation/Foundation.h>

#import <GLKit/GLKMathTypes.h>
#import <GLKit/GLKit.h>

#import "RATileDatabase.h"
#import "RAGeographicUtils.h"
Expand All @@ -20,6 +20,7 @@
@interface RATilePager : NSObject

@property (strong) RATileDatabase * database;
@property (strong) EAGLContext * loadingContext;

@property (readonly) RAGroup * nodes;
@property (readonly) NSSet * rootPages;
Expand Down

0 comments on commit 3732a69

Please sign in to comment.