Featured post
iphone - Marrying Core Animation with OpenGL ES -
edit: suppose instead of long explanation below might ask: sending -setneedsdisplay
instance of caeagllayer
not cause layer redraw (i.e., -drawincontext:
not called). instead, console message:
<gllayer: 0x4d500b0>: calling -display has no effect.
is there way around issue? can invoke -drawincontext:
when -setneedsdisplay
called? long explanation below:
i have opengl scene animate using core animation animations.
following standard approach animate custom properties in calayer, created subclass of caeagllayer
, defined property scenecenterpoint
in value should animated. layer holds reference opengl renderer:
#import <uikit/uikit.h> #import <quartzcore/quartzcore.h> #import "es2renderer.h" @interface gllayer : caeagllayer { es2renderer *renderer; } @property (nonatomic, retain) es2renderer *renderer; @property (nonatomic, assign) cgpoint scenecenterpoint;
i declare property @dynamic
let ca create accessors, override +needsdisplayforkey:
, implement -drawincontext:
pass current value of scenecenterpoint
property renderer , ask render scene:
#import "gllayer.h" @implementation gllayer @synthesize renderer; @dynamic scenecenterpoint; + (bool) needsdisplayforkey:(nsstring *)key { if ([key isequaltostring:@"scenecenterpoint"]) { return yes; } else { return [super needsdisplayforkey:key]; } } - (void) drawincontext:(cgcontextref)ctx { self.renderer.centerpoint = self.scenecenterpoint; [self.renderer render]; } ...
(if have access wwdc 2009 session videos, can review technique in session 303 ("animated drawing")).
now, when create explicit animation layer on keypath @"scenecenterpoint"
, core animation should calculate interpolated values custom properties , call -drawincontext:
each step of animation:
- (ibaction)animatebuttontapped:(id)sender { cabasicanimation *animation = [cabasicanimation animationwithkeypath:@"scenecenterpoint"]; animation.duration = 1.0; animation.fromvalue = [nsvalue valuewithcgpoint:cgpointzero]; animation.tovalue = [nsvalue valuewithcgpoint:cgpointmake(1.0f, 1.0f)]; [self.glview.layer addanimation:animation forkey:nil]; }
at least happen normal calayer
subclass. when subclass caeagllayer
, output on console each step of animation:
2010-12-21 13:59:22.180 coreanimationopengl[7496:207] <gllayer: 0x4e0be20>: calling -display has no effect. 2010-12-21 13:59:22.198 coreanimationopengl[7496:207] <gllayer: 0x4e0be20>: calling -display has no effect. 2010-12-21 13:59:22.216 coreanimationopengl[7496:207] <gllayer: 0x4e0be20>: calling -display has no effect. 2010-12-21 13:59:22.233 coreanimationopengl[7496:207] <gllayer: 0x4e0be20>: calling -display has no effect. ...
so seems that, possibly performance reasons, opengl layers, -drawincontext:
not getting called because these layers not use standard -display
method draw themselves. can confirm that? there way around it?
or can not use technique laid out above? mean have implement animations manually in opengl renderer (which possible not elegant imo).
have tried making parent layer above opengl layer , animating instead?
- Get link
- X
- Other Apps
Comments
Post a Comment