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> 2008-03-29 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSApplication.m (-terminate:): Initialize termination as * Source/NSApplication.m (-terminate:): Initialize termination as

View file

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

View file

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