mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 19:40:38 +00:00
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:
parent
c439e20394
commit
c537e70555
3 changed files with 59 additions and 36 deletions
|
@ -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
|
||||||
|
|
|
@ -38,16 +38,19 @@
|
||||||
NSOpenGLPixelFormat *pixel_format;
|
NSOpenGLPixelFormat *pixel_format;
|
||||||
BOOL attached;
|
BOOL attached;
|
||||||
}
|
}
|
||||||
+ (NSOpenGLPixelFormat*)defaultPixelFormat;
|
|
||||||
- (void)clearGLContext;
|
+ (NSOpenGLPixelFormat*) defaultPixelFormat;
|
||||||
- (void)setOpenGLContext:(NSOpenGLContext*)context;
|
- (void) clearGLContext;
|
||||||
- (NSOpenGLContext*)openGLContext;
|
- (void) setOpenGLContext: (NSOpenGLContext*)context;
|
||||||
- (id)initWithFrame:(NSRect)frameRect
|
- (NSOpenGLContext*) openGLContext;
|
||||||
pixelFormat:(NSOpenGLPixelFormat*)format;
|
- (id) initWithFrame: (NSRect)frameRect
|
||||||
- (void) dealloc;
|
pixelFormat: (NSOpenGLPixelFormat*)format;
|
||||||
- (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
|
||||||
|
|
|
@ -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,
|
||||||
|
@ -72,10 +64,20 @@
|
||||||
// NSOpenGLPFADepthSize, 32,
|
// NSOpenGLPFADepthSize, 32,
|
||||||
// 0
|
// 0
|
||||||
// };
|
// };
|
||||||
|
|
||||||
fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes: attrs];
|
@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)
|
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...");
|
||||||
|
@ -87,7 +89,7 @@
|
||||||
detach from the current context. You should call it before releasing this
|
detach from the current context. You should call it before releasing this
|
||||||
object.
|
object.
|
||||||
*/
|
*/
|
||||||
- (void)clearGLContext
|
- (void) clearGLContext
|
||||||
{
|
{
|
||||||
if (glcontext)
|
if (glcontext)
|
||||||
{
|
{
|
||||||
|
@ -96,42 +98,48 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setOpenGLContext:(NSOpenGLContext*)context
|
- (void) setOpenGLContext: (NSOpenGLContext*)context
|
||||||
{
|
{
|
||||||
[self clearGLContext];
|
[self clearGLContext];
|
||||||
ASSIGN(glcontext, context);
|
ASSIGN(glcontext, context);
|
||||||
attached = NO;
|
attached = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) prepareOpenGL
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
return the current gl context associated with this view
|
return the current gl context associated with this view
|
||||||
*/
|
*/
|
||||||
- (NSOpenGLContext*)openGLContext
|
- (NSOpenGLContext*) openGLContext
|
||||||
{
|
{
|
||||||
if (glcontext == nil)
|
if (glcontext == nil)
|
||||||
{
|
{
|
||||||
glcontext = [[NSOpenGLContext alloc] initWithFormat: pixel_format
|
glcontext = [[NSOpenGLContext alloc] initWithFormat: pixel_format
|
||||||
shareContext: nil];
|
shareContext: nil];
|
||||||
attached = NO;
|
attached = NO;
|
||||||
}
|
}
|
||||||
return glcontext;
|
return glcontext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
-(id) initWithFrame: (NSRect)frameRect
|
-(id) initWithFrame: (NSRect)frameRect
|
||||||
{
|
{
|
||||||
return [self initWithFrame: frameRect
|
return [self initWithFrame: frameRect
|
||||||
pixelFormat: [[self class] defaultPixelFormat]];
|
pixelFormat: [[self class] defaultPixelFormat]];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** default initializer. Can be passed [NSOpenGLContext defaultPixelFormat]
|
/** default initializer. Can be passed [NSOpenGLContext defaultPixelFormat]
|
||||||
as second argument
|
as second argument
|
||||||
*/
|
*/
|
||||||
- (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];
|
||||||
|
@ -153,12 +161,12 @@
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSOpenGLPixelFormat*)pixelFormat
|
- (NSOpenGLPixelFormat*) pixelFormat
|
||||||
{
|
{
|
||||||
return pixel_format;
|
return pixel_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setPixelFormat:(NSOpenGLPixelFormat*)pixelFormat
|
- (void) setPixelFormat: (NSOpenGLPixelFormat*)pixelFormat
|
||||||
{
|
{
|
||||||
ASSIGN(pixel_format, pixelFormat);
|
ASSIGN(pixel_format, pixelFormat);
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue