On Oct 12, 2009, at 1:17 PM, Rob Barris wrote:

Within a single thread of execution, if you are about to do some GL drawing and you are unsure of the current context, you should set it, and it will stay set.

If I knew what it was I could set it. My model object knows nothing of the glContext. Also I do not think storing the context in the model is appropriate. That would seem to violate the MVC design pattern. (Although having the draw method in the model class is technically a violation of MVC but one that seems to be generally accepted and necessary.)

I think Kyle Sluder's remarks of putting the OpenGL resource creation and disposal stuff in the controller-layer might be the way to go. I am currently using off the shelf NSObjectController and NSArrayController classes to add and remove model objects from the managed object context. I could subclass these and put the OpenGL resource code in there.

My model object code looks something like this.

@interface ModelObject : NSManagedObject
{
     // OpenGL resource objects needed to draw the model object
     ...
}

@end

@implementation ModelObject

- (void)awakeFromInsert
{
     [super awakeFromInsert];
     [self prepareOpenGL];
}

- (void)awakeFromFetch
{
     [super awakeFromFetch];
     [self prepareOpenGL];
}

- (void)didTurnIntoFault
{
     [self cleanupOpenGL];
     [super didTurnIntoFault];
}

- (void)prepareOpenGL { ... }

- (void)cleanupOpenGL { ... }

- (void)draw // current glContext set by the caller
{
     // Draw to OpenGL context.
     ...
}

@end

Thanks for your help and comments.

Richard

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to