mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-20 16:06:27 +00:00
Some improvements and bux fix related to OpenGL
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@28032 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7c2e8efcd8
commit
74bcdbdd94
7 changed files with 98 additions and 15 deletions
|
@ -35,6 +35,7 @@
|
|||
// Declare a private method of NSView
|
||||
@interface NSView (Private)
|
||||
- (void) _lockFocusInContext: (NSGraphicsContext *)ctxt inRect: (NSRect)rect;
|
||||
- (void) _viewWillMoveToWindow: (NSWindow*)newWindow;
|
||||
@end
|
||||
|
||||
/**
|
||||
|
@ -100,16 +101,17 @@ static NSOpenGLPixelFormatAttribute attrs[] =
|
|||
{
|
||||
[glcontext clearDrawable];
|
||||
DESTROY(glcontext);
|
||||
prepared = NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) setOpenGLContext: (NSOpenGLContext*)context
|
||||
{
|
||||
[self clearGLContext];
|
||||
ASSIGN(glcontext, context);
|
||||
[glcontext setView: self];
|
||||
[glcontext makeCurrentContext];
|
||||
[self prepareOpenGL];
|
||||
if ( context != glcontext )
|
||||
{
|
||||
[self clearGLContext];
|
||||
ASSIGN(glcontext, context);
|
||||
}
|
||||
}
|
||||
|
||||
- (void) prepareOpenGL
|
||||
|
@ -128,6 +130,8 @@ static NSOpenGLPixelFormatAttribute attrs[] =
|
|||
shareContext: nil];
|
||||
|
||||
[self setOpenGLContext: context];
|
||||
[context setView: self];
|
||||
|
||||
RELEASE(context);
|
||||
}
|
||||
return glcontext;
|
||||
|
@ -152,6 +156,12 @@ static NSOpenGLPixelFormatAttribute attrs[] =
|
|||
|
||||
ASSIGN(pixel_format, format);
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver: self
|
||||
selector: @selector(_frameChanged:)
|
||||
name: NSViewGlobalFrameDidChangeNotification
|
||||
object: self];
|
||||
|
||||
[self setPostsFrameChangedNotifications: YES];
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver: self
|
||||
|
@ -165,8 +175,8 @@ static NSOpenGLPixelFormatAttribute attrs[] =
|
|||
- (void) dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
[self clearGLContext];
|
||||
RELEASE(pixel_format);
|
||||
RELEASE(glcontext);
|
||||
NSDebugMLLog(@"GL", @"deallocating");
|
||||
[super dealloc];
|
||||
}
|
||||
|
@ -187,12 +197,22 @@ static NSOpenGLPixelFormatAttribute attrs[] =
|
|||
|
||||
- (void) update
|
||||
{
|
||||
[glcontext update];
|
||||
NSOpenGLContext *context;
|
||||
context = [self openGLContext];
|
||||
if ([context view] == self)
|
||||
{
|
||||
[context update];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) isOpaque
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) _frameChanged: (NSNotification *) aNot
|
||||
{
|
||||
NSDebugMLLog(@"GL", @"our frame has changed");
|
||||
[[self openGLContext] makeCurrentContext];
|
||||
[self update];
|
||||
[self reshape];
|
||||
}
|
||||
|
@ -201,8 +221,32 @@ static NSOpenGLPixelFormatAttribute attrs[] =
|
|||
*/
|
||||
- (void) _lockFocusInContext: (NSGraphicsContext *)ctxt inRect: (NSRect)rect
|
||||
{
|
||||
NSOpenGLContext *context;
|
||||
context = [self openGLContext];
|
||||
|
||||
[super _lockFocusInContext: ctxt inRect: rect];
|
||||
[[self openGLContext] makeCurrentContext];
|
||||
[context makeCurrentContext];
|
||||
if ([context view] != self)
|
||||
{
|
||||
[context setView:self];
|
||||
}
|
||||
if (!prepared)
|
||||
{
|
||||
[self prepareOpenGL];
|
||||
prepared = YES;
|
||||
[self reshape];
|
||||
}
|
||||
}
|
||||
|
||||
-(void) _viewWillMoveToWindow: (NSWindow *) newWindow
|
||||
{
|
||||
[super _viewWillMoveToWindow: newWindow];
|
||||
|
||||
if ([self window] != newWindow)
|
||||
{
|
||||
// the context will be recreated in the new window if needed
|
||||
[[self openGLContext] clearDrawable];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue