Fix for #22706, make NSOpenGLView usable again.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@26414 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2008-03-31 14:36:22 +00:00
parent c439e20394
commit c537e70555
3 changed files with 59 additions and 36 deletions

View file

@ -1,3 +1,9 @@
2008-03-31 Fred Kiefer <FredKiefer@gmx.de>
* Headers/AppKit/NSOpenGLView.h: Add MacOS 10.3 method.
* Source/NSOpenGLView.m: Clean up. Use canDraw instead of
lockFocusInRect: as the entry point for context attachment.
2008-03-29 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSApplication.m (-terminate:): Initialize termination as

View file

@ -38,16 +38,19 @@
NSOpenGLPixelFormat *pixel_format;
BOOL attached;
}
+ (NSOpenGLPixelFormat*) defaultPixelFormat;
- (void) clearGLContext;
- (void) setOpenGLContext: (NSOpenGLContext*)context;
- (NSOpenGLContext*) openGLContext;
- (id) initWithFrame: (NSRect)frameRect
pixelFormat: (NSOpenGLPixelFormat*)format;
- (void) dealloc;
- (NSOpenGLPixelFormat*) pixelFormat;
- (void) setPixelFormat: (NSOpenGLPixelFormat*)pixelFormat;
- (void) reshape;
- (void) update;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST)
- (void) prepareOpenGL;
#endif
@end
#endif

View file

@ -32,8 +32,6 @@
#include "AppKit/NSOpenGL.h"
#include "AppKit/NSOpenGLView.h"
/**
<unit>
<heading>NSOpenGLView</heading>
@ -51,15 +49,9 @@
</unit>
*/
@implementation NSOpenGLView
/**
return a standard NSOpenGLPixelFormat you can pass to the
initWithFrame: pixelFormat: method
*/
+ (NSOpenGLPixelFormat*)defaultPixelFormat
{
NSOpenGLPixelFormat *fmt;
NSOpenGLPixelFormatAttribute attrs[] =
static NSOpenGLPixelFormat *fmt = nil;
static NSOpenGLPixelFormatAttribute attrs[] =
{
NSOpenGLPFADoubleBuffer,
NSOpenGLPFADepthSize, 16,
@ -73,9 +65,19 @@
// 0
// };
@implementation NSOpenGLView
/**
return a standard NSOpenGLPixelFormat you can pass to the
initWithFrame: pixelFormat: method
*/
+ (NSOpenGLPixelFormat*) defaultPixelFormat
{
// Initialize it once
if (!fmt)
fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes: attrs];
if (fmt)
return AUTORELEASE(fmt);
return fmt;
else
{
NSWarnMLog(@"could not find a reasonable pixel format...");
@ -103,6 +105,10 @@
attached = NO;
}
- (void) prepareOpenGL
{
}
/**
return the current gl context associated with this view
*/
@ -117,7 +123,6 @@
return glcontext;
}
-(id) initWithFrame: (NSRect)frameRect
{
return [self initWithFrame: frameRect
@ -131,7 +136,10 @@
- (id) initWithFrame: (NSRect)frameRect
pixelFormat: (NSOpenGLPixelFormat*)format
{
[super initWithFrame: frameRect];
self = [super initWithFrame: frameRect];
if (!self)
return nil;
ASSIGN(pixel_format, format);
[self setPostsFrameChangedNotifications: YES];
@ -179,9 +187,12 @@
[self reshape];
}
- (void) lockFocusInRect: (NSRect) aRect
/* FIXME: This is a hack to get a chance to attach the current
context before any drawing happens. I think this code should
be moved to openGLContext.
*/
- (BOOL) canDraw
{
[super lockFocusInRect: aRect];
if (!glcontext)
{
[self openGLContext];
@ -192,8 +203,11 @@
NSDebugMLLog(@"GL", @"Attaching context to the view");
[glcontext setView: self];
attached = YES;
[self prepareOpenGL];
}
return [super canDraw];
}
@end