mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 19:01:15 +00:00
Add OpenGL support
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@14997 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6e252938f2
commit
c3bae489b8
9 changed files with 708 additions and 4 deletions
|
@ -68,6 +68,10 @@ APPKIT_EXPORT NSString * GSScreenNumber;
|
|||
- (NSDictionary *) attributes;
|
||||
- (void) closeServer;
|
||||
|
||||
/* GL context */
|
||||
- glContextClass;
|
||||
- glPixelFormatClass;
|
||||
|
||||
/* Drag and drop support. */
|
||||
+ (BOOL) addDragTypes: (NSArray*)types toWindow: (NSWindow *)win;
|
||||
+ (BOOL) removeDragTypes: (NSArray*)types fromWindow: (NSWindow *)win;
|
||||
|
|
139
Headers/gnustep/gui/NSOpenGL.h
Normal file
139
Headers/gnustep/gui/NSOpenGL.h
Normal file
|
@ -0,0 +1,139 @@
|
|||
/* -*-ObjC-*- */
|
||||
/**
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
|
||||
Author: Frederic De Jaeger
|
||||
Date: Nov 2002
|
||||
|
||||
This file is part of the GNU Objective C User interface library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef _NSOpenGL_h_INCLUDE
|
||||
#define _NSOpenGL_h_INCLUDE
|
||||
|
||||
#include <Foundation/NSObject.h>
|
||||
@class NSView;
|
||||
|
||||
typedef enum {
|
||||
NSOpenGLPFAAllRenderers = 1,
|
||||
NSOpenGLPFADoubleBuffer = 5,
|
||||
NSOpenGLPFAStereo = 6,
|
||||
NSOpenGLPFAAuxBuffers = 7,
|
||||
NSOpenGLPFAColorSize = 8,
|
||||
NSOpenGLPFAAlphaSize = 11,
|
||||
NSOpenGLPFADepthSize = 12,
|
||||
NSOpenGLPFAStencilSize = 13,
|
||||
NSOpenGLPFAAccumSize = 14,
|
||||
NSOpenGLPFAMinimumPolicy = 51,
|
||||
NSOpenGLPFAMaximumPolicy = 52,
|
||||
NSOpenGLPFAOffScreen = 53,
|
||||
NSOpenGLPFAFullScreen = 54,
|
||||
NSOpenGLPFASampleBuffers = 55,
|
||||
NSOpenGLPFASamples = 56,
|
||||
NSOpenGLPFAAuxDepthStencil = 57,
|
||||
NSOpenGLPFARendererID = 70,
|
||||
NSOpenGLPFASingleRenderer = 71,
|
||||
NSOpenGLPFANoRecovery = 72,
|
||||
NSOpenGLPFAAccelerated = 73,
|
||||
NSOpenGLPFAClosestPolicy = 74,
|
||||
NSOpenGLPFARobust = 75,
|
||||
NSOpenGLPFABackingStore = 76,
|
||||
NSOpenGLPFAMPSafe = 78,
|
||||
NSOpenGLPFAWindow = 80,
|
||||
NSOpenGLPFAMultiScreen = 81,
|
||||
NSOpenGLPFACompliant = 83,
|
||||
NSOpenGLPFAScreenMask = 84,
|
||||
NSOpenGLPFAVirtualScreenCount = 128
|
||||
} NSOpenGLPixelFormatAttribute;
|
||||
|
||||
typedef enum {
|
||||
NSOpenGLCPSwapRectangle = 200,
|
||||
NSOpenGLCPSwapRectangleEnable = 201,
|
||||
NSOpenGLCPRasterizationEnable = 221,
|
||||
NSOpenGLCPSwapInterval = 222,
|
||||
NSOpenGLCPSurfaceOrder = 235,
|
||||
NSOpenGLCPSurfaceOpacity = 236,
|
||||
NSOpenGLCPStateValidation = 301
|
||||
} NSOpenGLContextParameter;
|
||||
|
||||
typedef enum {
|
||||
NSOpenGLGOFormatCacheSize = 501,
|
||||
NSOpenGLGOClearFormatCache = 502,
|
||||
NSOpenGLGORetainRenderers = 503,
|
||||
NSOpenGLGOResetLibrary = 504
|
||||
} NSOpenGLGlobalOption;
|
||||
|
||||
@interface NSOpenGLPixelFormat : NSObject
|
||||
{
|
||||
}
|
||||
- (void)getValues:(long *)vals
|
||||
forAttribute:(NSOpenGLPixelFormatAttribute)attrib
|
||||
forVirtualScreen:(int)screen;
|
||||
- (id)initWithAttributes:(NSOpenGLPixelFormatAttribute *)attribs;
|
||||
- (int)numberOfVirtualScreens;
|
||||
@end
|
||||
|
||||
@interface NSOpenGLContext : NSObject
|
||||
{
|
||||
}
|
||||
|
||||
+ (void)clearCurrentContext;
|
||||
+ (NSOpenGLContext *)currentContext;
|
||||
- (void)clearDrawable;
|
||||
- (void)copyAttributesFromContext:(NSOpenGLContext *)context
|
||||
withMask:(unsigned long)mask;
|
||||
- (void)createTexture:(unsigned long)target
|
||||
fromView:(NSView*)view
|
||||
internalFormat:(unsigned long)format;
|
||||
|
||||
- (int)currentVirtualScreen;
|
||||
|
||||
- (void)flushBuffer;
|
||||
|
||||
- (void)getValues:(long *)vals
|
||||
forParameter:(NSOpenGLContextParameter)param;
|
||||
|
||||
- (id)initWithFormat:(NSOpenGLPixelFormat *)format
|
||||
shareContext:(NSOpenGLContext *)share;
|
||||
|
||||
|
||||
- (void)makeCurrentContext;
|
||||
|
||||
- (void)setCurrentVirtualScreen:(int)screen;
|
||||
|
||||
- (void)setFullScreen;
|
||||
|
||||
- (void)setOffScreen:(void *)baseaddr
|
||||
width:(long)width
|
||||
height:(long)height
|
||||
rowbytes:(long)rowbytes;
|
||||
|
||||
- (void)setValues:(const long *)vals
|
||||
forParameter:(NSOpenGLContextParameter)param;
|
||||
|
||||
- (void)setView:(NSView *)view;
|
||||
|
||||
- (void)update;
|
||||
|
||||
- (NSView *)view;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
#endif
|
51
Headers/gnustep/gui/NSOpenGLView.h
Normal file
51
Headers/gnustep/gui/NSOpenGLView.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* -*-ObjC-*- */
|
||||
/**
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
|
||||
Author: Frederic De Jaeger
|
||||
Date: Nov 2002
|
||||
|
||||
This file is part of the GNU Objective C User interface library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef _NSOpenGLView_h
|
||||
#define _NSOpenGLView_h
|
||||
|
||||
#include <AppKit/NSView.h>
|
||||
|
||||
@class NSOpenGLContext;
|
||||
@class NSOpenGLPixelFormat;
|
||||
|
||||
@interface NSOpenGLView : NSView
|
||||
{
|
||||
NSOpenGLContext *glcontext;
|
||||
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;
|
||||
@end
|
||||
#endif
|
|
@ -591,6 +591,9 @@ void __dummy_GMAppKit_functionForLinking() {}
|
|||
withName:@"catalogName"];
|
||||
[archiver encodeString:[self colorNameComponent] withName:@"colorName"];
|
||||
}
|
||||
else if ([colorSpaceName isEqual:@"NSPatternColorSpace"]) {
|
||||
[archiver encodeObject: [self patternImage] withName: @"patternImage"];
|
||||
}
|
||||
}
|
||||
|
||||
+ (id)createObjectForModelUnarchiver:(GMUnarchiver*)unarchiver
|
||||
|
@ -644,6 +647,23 @@ void __dummy_GMAppKit_functionForLinking() {}
|
|||
NSString *colornm = [unarchiver decodeStringWithName: @"colorName"];
|
||||
return [self colorWithCatalogName: catalog colorName: colornm];
|
||||
}
|
||||
else if ([colorSpaceName isEqual:@"NSPatternColorSpace"]) {
|
||||
NSImage *image = [unarchiver decodeObjectWithName: @"patternImage"];
|
||||
if (image == nil)
|
||||
{
|
||||
NSLog(@"Internal: No can't decode colorspace %@", colorSpaceName);
|
||||
NSLog(@" creating generic white color");
|
||||
return [NSColor colorWithDeviceWhite: 1.0 alpha: 1.0];
|
||||
}
|
||||
else
|
||||
return [NSColor colorWithPatternImage: image];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"Internal: No decoder for colorspace %@", colorSpaceName);
|
||||
NSLog(@" creating generic white color");
|
||||
return [NSColor colorWithDeviceWhite: 1.0 alpha: 1.0];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
@ -983,7 +1003,7 @@ void __dummy_GMAppKit_functionForLinking() {}
|
|||
|
||||
decodedItems = [unarchiver decodeArrayWithName: @"itemArray"];
|
||||
|
||||
if (decodedItems)
|
||||
if (decodedItems && [decodedItems count])
|
||||
{
|
||||
count = [decodedItems count];
|
||||
for (i = 0; i < count; i++)
|
||||
|
@ -999,10 +1019,15 @@ void __dummy_GMAppKit_functionForLinking() {}
|
|||
[myItem setTag: [item tag]];
|
||||
[myItem setKeyEquivalent: [item keyEquivalent]];
|
||||
}
|
||||
string = [unarchiver decodeStringWithName: @"selectedItem"];
|
||||
[self selectItemWithTitle: string];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* For old gmodels that didn't support popups */
|
||||
[self addItemWithTitle: @"Item 1"];
|
||||
[self selectItemAtIndex: 0];
|
||||
}
|
||||
|
||||
string = [unarchiver decodeStringWithName: @"selectedItem"];
|
||||
[self selectItemWithTitle: string];
|
||||
|
||||
[self setEnabled: [unarchiver decodeBOOLWithName: @"isEnabled"]];
|
||||
[self setTag: [unarchiver decodeIntWithName: @"tag"]];
|
||||
|
|
|
@ -101,6 +101,9 @@ NSMenu.m \
|
|||
NSMenuView.m \
|
||||
NSMenuItem.m \
|
||||
NSMenuItemCell.m \
|
||||
NSOpenGLContext.m \
|
||||
NSOpenGLPixelFormat.m \
|
||||
NSOpenGLView.m \
|
||||
NSOpenPanel.m \
|
||||
NSOutlineView.m \
|
||||
NSPageLayout.m \
|
||||
|
@ -254,6 +257,8 @@ NSMenuItem.h \
|
|||
NSMenuItemCell.h \
|
||||
NSMenuView.h \
|
||||
NSOpenPanel.h \
|
||||
NSOpenGL.h \
|
||||
NSOpenGLView.h \
|
||||
NSOutlineView.h \
|
||||
NSPageLayout.h \
|
||||
NSPanel.h \
|
||||
|
|
|
@ -245,6 +245,17 @@ GSCurrentServer(void)
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
- glContextClass
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- glPixelFormatClass
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
/* Drag and drop support. */
|
||||
/** Convienience method that calls -addDragTypes:toWindow: using the
|
||||
server that controls win.
|
||||
|
|
171
Source/NSOpenGLContext.m
Normal file
171
Source/NSOpenGLContext.m
Normal file
|
@ -0,0 +1,171 @@
|
|||
/** <title>NSOpenGLContext.m </title>
|
||||
|
||||
<abstract>Context for openGL drawing</abstract>
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Frederic De Jaeger
|
||||
Date: 2002
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <AppKit/NSOpenGL.h>
|
||||
#include <AppKit/GSDisplayServer.h>
|
||||
|
||||
|
||||
@implementation NSOpenGLContext
|
||||
+ _classContext
|
||||
{
|
||||
Class glContextClass = [GSCurrentServer() glContextClass];
|
||||
|
||||
if ( glContextClass == nil )
|
||||
{
|
||||
NSWarnMLog(@"Backend doesn't have any gl context");
|
||||
return nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSDebugMLLog(@"GLX", @"found something");
|
||||
return glContextClass;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+ allocWithZone: (NSZone *) z
|
||||
{
|
||||
Class c = [self _classContext];
|
||||
if ( c )
|
||||
return NSAllocateObject(c, 0, z);
|
||||
else
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (void)clearCurrentContext
|
||||
{
|
||||
[[self _classContext] clearCurrentContext];
|
||||
}
|
||||
|
||||
+ (NSOpenGLContext *)currentContext
|
||||
{
|
||||
return [[self _classContext] currentContext];
|
||||
}
|
||||
|
||||
- (void)clearDrawable
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void)copyAttributesFromContext:(NSOpenGLContext *)context
|
||||
withMask:(unsigned long)mask
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void)createTexture:(unsigned long)target
|
||||
fromView:(NSView*)view
|
||||
internalFormat:(unsigned long)format
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
|
||||
- (int)currentVirtualScreen
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
- (void)flushBuffer
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
|
||||
- (void)getValues:(long *)vals
|
||||
forParameter:(NSOpenGLContextParameter)param
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
|
||||
- (id)initWithFormat:(NSOpenGLPixelFormat *)format
|
||||
shareContext:(NSOpenGLContext *)share
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void)makeCurrentContext
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
|
||||
- (void)setCurrentVirtualScreen:(int)screen
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
|
||||
- (void)setFullScreen
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
|
||||
- (void)setOffScreen:(void *)baseaddr
|
||||
width:(long)width
|
||||
height:(long)height
|
||||
rowbytes:(long)rowbytes
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
|
||||
- (void)setValues:(const long *)vals
|
||||
forParameter:(NSOpenGLContextParameter)param
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
|
||||
- (void)setView:(NSView *)view
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
|
||||
- (void)update
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
|
||||
- (NSView *)view
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return nil;
|
||||
}
|
||||
@end
|
||||
|
||||
|
108
Source/NSOpenGLPixelFormat.m
Normal file
108
Source/NSOpenGLPixelFormat.m
Normal file
|
@ -0,0 +1,108 @@
|
|||
/** <title>NSOpenGLPixelFormat.m </title>
|
||||
|
||||
<abstract>use to choose the type of GL context</abstract>
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Frederic De Jaeger
|
||||
Date: 2002
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSString.h>
|
||||
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <AppKit/GSDisplayServer.h>
|
||||
#include <AppKit/NSOpenGL.h>
|
||||
|
||||
|
||||
// @interface GSGLPixelFormat : NSOpenGLPixelFormat
|
||||
// {}
|
||||
// + _classContext;
|
||||
// @end
|
||||
|
||||
// @implementation GSGLPixelFormat
|
||||
// - (id)initWithAttributes:(NSOpenGLPixelFormatAttribute *)attribs
|
||||
// {
|
||||
// self = [[GSGLPixelFormat _classContext] alloc];
|
||||
|
||||
// return [self initWithAttributes: attribs];
|
||||
// }
|
||||
// @end
|
||||
|
||||
//static GSGLPixelFormat *temp;
|
||||
|
||||
@implementation NSOpenGLPixelFormat
|
||||
+ _classPixelFormat
|
||||
{
|
||||
Class glPixelFormatClass = [GSCurrentServer() glPixelFormatClass];
|
||||
|
||||
if ( glPixelFormatClass == nil )
|
||||
{
|
||||
NSWarnMLog(@"Backend doesn't have any glPixelFormatClass");
|
||||
return nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSDebugMLLog(@"GLX", @"found a class %@", glPixelFormatClass);
|
||||
return glPixelFormatClass;
|
||||
}
|
||||
}
|
||||
|
||||
// + (void) initialize
|
||||
// {
|
||||
// if ( self == [NSOpenGLPixelFormat class] )
|
||||
// {
|
||||
// temp = (GSGLPixelFormat *) NSAllocateObject([GSGLPixelFormat class], 0,
|
||||
// NSDefaultMallocZone());
|
||||
// }
|
||||
// }
|
||||
|
||||
+ allocWithZone: (NSZone *) z
|
||||
{
|
||||
Class c = [self _classPixelFormat];
|
||||
if ( c )
|
||||
return NSAllocateObject(c, 0, z);
|
||||
else
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)getValues:(long *)vals
|
||||
forAttribute:(NSOpenGLPixelFormatAttribute)attrib
|
||||
forVirtualScreen:(int)screen
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (id)initWithAttributes:(NSOpenGLPixelFormatAttribute *)attribs
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (int)numberOfVirtualScreens
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
190
Source/NSOpenGLView.m
Normal file
190
Source/NSOpenGLView.m
Normal file
|
@ -0,0 +1,190 @@
|
|||
/** <title>NSOpenGLView.m </title>
|
||||
|
||||
<abstract>Context for openGL drawing</abstract>
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Frederic De Jaeger
|
||||
Date: 2002
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSNotification.h>
|
||||
#include <AppKit/NSOpenGL.h>
|
||||
#include <AppKit/NSOpenGLView.h>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
<unit>
|
||||
<heading>NSOpenGLView</heading>
|
||||
|
||||
<p>
|
||||
This class is simply a view with a NSOpenGLContext attached to it.
|
||||
This is the simplest way to initialize a GL context within GNUstep.
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
There is a mechanism to update the context when the view is moved
|
||||
or resize.
|
||||
</p>
|
||||
|
||||
</unit>
|
||||
*/
|
||||
@implementation NSOpenGLView
|
||||
/**
|
||||
return a standard NSOpenGLPixelFormat you can pass to the
|
||||
initWithFrame: pixelFormat: method
|
||||
*/
|
||||
+ (NSOpenGLPixelFormat*)defaultPixelFormat
|
||||
{
|
||||
NSOpenGLPixelFormat *fmt;
|
||||
NSOpenGLPixelFormatAttribute attrs[] =
|
||||
{
|
||||
NSOpenGLPFADoubleBuffer,
|
||||
NSOpenGLPFADepthSize, 16,
|
||||
NSOpenGLPFAColorSize, 1,
|
||||
0
|
||||
};
|
||||
// NSOpenGLPixelFormatAttribute attrs[] =
|
||||
// {
|
||||
// NSOpenGLPFADoubleBuffer,
|
||||
// NSOpenGLPFADepthSize, 32,
|
||||
// 0
|
||||
// };
|
||||
|
||||
fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes: attrs];
|
||||
if (fmt)
|
||||
return AUTORELEASE(fmt);
|
||||
else
|
||||
{
|
||||
NSWarnMLog(@"could not find a reasonable pixel format...");
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
detach from the current context. You should call it before releasing this
|
||||
object.
|
||||
*/
|
||||
- (void)clearGLContext
|
||||
{
|
||||
if (glcontext)
|
||||
{
|
||||
[glcontext clearDrawable];
|
||||
DESTROY(glcontext);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setOpenGLContext:(NSOpenGLContext*)context
|
||||
{
|
||||
[self clearGLContext];
|
||||
ASSIGN(glcontext, context);
|
||||
attached = NO;
|
||||
}
|
||||
|
||||
/**
|
||||
return the current gl context associated with this view
|
||||
*/
|
||||
- (NSOpenGLContext*)openGLContext
|
||||
{
|
||||
if ( glcontext == nil )
|
||||
{
|
||||
glcontext = [[NSOpenGLContext alloc] initWithFormat: pixel_format
|
||||
shareContext: nil];
|
||||
attached = NO;
|
||||
}
|
||||
return glcontext;
|
||||
}
|
||||
|
||||
/** default initializer. Can be passed [NSOpenGLContext defaultPixelFormat]
|
||||
as second argument
|
||||
*/
|
||||
- (id)initWithFrame:(NSRect)frameRect
|
||||
pixelFormat:(NSOpenGLPixelFormat*)format
|
||||
{
|
||||
[super initWithFrame: frameRect];
|
||||
ASSIGN(pixel_format, format);
|
||||
|
||||
[self setPostsFrameChangedNotifications: YES];
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver: self
|
||||
selector: @selector(_frameChanged:)
|
||||
name: NSViewFrameDidChangeNotification
|
||||
object: self];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
RELEASE(pixel_format);
|
||||
RELEASE(glcontext);
|
||||
NSDebugMLLog(@"GL", @"deallocating");
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSOpenGLPixelFormat*)pixelFormat
|
||||
{
|
||||
return pixel_format;
|
||||
}
|
||||
|
||||
- (void)setPixelFormat:(NSOpenGLPixelFormat*)pixelFormat
|
||||
{
|
||||
ASSIGN(pixel_format, pixelFormat);
|
||||
}
|
||||
|
||||
- (void) reshape
|
||||
{
|
||||
}
|
||||
|
||||
- (void) update
|
||||
{
|
||||
[glcontext update];
|
||||
}
|
||||
|
||||
- (void) _frameChanged: (NSNotification *) aNot
|
||||
{
|
||||
NSDebugMLLog(@"GL", @"our frame has changed");
|
||||
[self update];
|
||||
[self reshape];
|
||||
}
|
||||
|
||||
- (void) lockFocusInRect: (NSRect) aRect
|
||||
{
|
||||
[super lockFocusInRect: aRect];
|
||||
if ( !glcontext )
|
||||
{
|
||||
[self openGLContext];
|
||||
NSAssert(glcontext, NSInternalInconsistencyException);
|
||||
}
|
||||
if ( attached == NO && glcontext != nil )
|
||||
{
|
||||
NSDebugMLLog(@"GL", @"Attaching context to the view");
|
||||
[glcontext setView: self];
|
||||
attached = YES;
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
|
Loading…
Reference in a new issue