mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2024-11-28 06:20:24 +00:00
parent
951a1eb617
commit
9bd79ee55e
@ -11,26 +11,26 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
@class NSOpenGLPixelFormat,NSOpenGLContext;
|
||||
|
||||
@interface NSOpenGLView : NSView {
|
||||
NSOpenGLPixelFormat *_pixelFormat;
|
||||
NSOpenGLContext *_context;
|
||||
BOOL _needsPrepare;
|
||||
BOOL _needsReshape;
|
||||
NSOpenGLPixelFormat *_pixelFormat;
|
||||
NSOpenGLContext *_context;
|
||||
BOOL _needsPrepare;
|
||||
BOOL _needsReshape;
|
||||
}
|
||||
|
||||
+(NSOpenGLPixelFormat *)defaultPixelFormat;
|
||||
+ (NSOpenGLPixelFormat *)defaultPixelFormat;
|
||||
|
||||
-initWithFrame:(NSRect)frame pixelFormat:(NSOpenGLPixelFormat *)pixelFormat;
|
||||
- (id)initWithFrame:(NSRect)frame pixelFormat:(NSOpenGLPixelFormat *)pixelFormat;
|
||||
|
||||
-(NSOpenGLPixelFormat *)pixelFormat;
|
||||
-(NSOpenGLContext *)openGLContext;
|
||||
- (NSOpenGLPixelFormat *)pixelFormat;
|
||||
- (NSOpenGLContext *)openGLContext;
|
||||
|
||||
-(void)setPixelFormat:(NSOpenGLPixelFormat *)pixelFormat;
|
||||
-(void)setOpenGLContext:(NSOpenGLContext *)context;
|
||||
- (void)setPixelFormat:(NSOpenGLPixelFormat *)pixelFormat;
|
||||
- (void)setOpenGLContext:(NSOpenGLContext *)context;
|
||||
|
||||
-(void)update;
|
||||
-(void)reshape;
|
||||
- (void)update;
|
||||
- (void)reshape;
|
||||
|
||||
-(void)prepareOpenGL;
|
||||
-(void)clearGLContext;
|
||||
- (void)prepareOpenGL;
|
||||
- (void)clearGLContext;
|
||||
|
||||
@end
|
||||
@end
|
@ -5,6 +5,7 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#import <AppKit/NSOpenGLView.h>
|
||||
#import <AppKit/NSOpenGLContext.h>
|
||||
#import <AppKit/NSOpenGLPixelFormat.h>
|
||||
@ -13,119 +14,124 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
|
||||
@implementation NSOpenGLView
|
||||
|
||||
+(NSOpenGLPixelFormat *)defaultPixelFormat {
|
||||
NSOpenGLPixelFormatAttribute attributes[]={
|
||||
|
||||
0
|
||||
};
|
||||
|
||||
return [[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] autorelease];
|
||||
+ (NSOpenGLPixelFormat *)defaultPixelFormat {
|
||||
NSOpenGLPixelFormatAttribute attributes[] = {
|
||||
0
|
||||
};
|
||||
|
||||
return [[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] autorelease];
|
||||
}
|
||||
|
||||
-initWithFrame:(NSRect)frame pixelFormat:(NSOpenGLPixelFormat *)pixelFormat {
|
||||
[super initWithFrame:frame];
|
||||
_pixelFormat=[pixelFormat retain];
|
||||
_context=nil;
|
||||
return self;
|
||||
- (id)initWithFrame:(NSRect)frame pixelFormat:(NSOpenGLPixelFormat *)pixelFormat {
|
||||
[super initWithFrame:frame];
|
||||
|
||||
_pixelFormat = [pixelFormat retain];
|
||||
_context = nil;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-initWithFrame:(NSRect)frame {
|
||||
[super initWithFrame:frame];
|
||||
_pixelFormat=[isa defaultPixelFormat];
|
||||
_context=nil;
|
||||
return self;
|
||||
- (id)initWithFrame:(NSRect)frame {
|
||||
[super initWithFrame:frame];
|
||||
|
||||
_pixelFormat = [isa defaultPixelFormat];
|
||||
_context = nil;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-initWithCoder:(NSCoder *)coder {
|
||||
[super initWithCoder:coder];
|
||||
|
||||
if([coder allowsKeyedCoding])
|
||||
_pixelFormat=[[coder decodeObjectForKey:@"NSPixelFormat"] retain];
|
||||
else
|
||||
NSUnimplementedMethod();
|
||||
|
||||
return self;
|
||||
- (id)initWithCoder:(NSCoder *)coder {
|
||||
[super initWithCoder:coder];
|
||||
|
||||
if ([coder allowsKeyedCoding])
|
||||
_pixelFormat = [[coder decodeObjectForKey:@"NSPixelFormat"] retain];
|
||||
else
|
||||
NSUnimplementedMethod();
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
-(void)dealloc {
|
||||
[_pixelFormat release];
|
||||
[_context release];
|
||||
[super dealloc];
|
||||
- (void)dealloc {
|
||||
[_pixelFormat release];
|
||||
[_context release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(NSOpenGLPixelFormat *)pixelFormat {
|
||||
return _pixelFormat;
|
||||
- (NSOpenGLPixelFormat *)pixelFormat {
|
||||
return _pixelFormat;
|
||||
}
|
||||
|
||||
-(NSOpenGLContext *)openGLContext {
|
||||
if(_context==nil){
|
||||
_context=[[NSOpenGLContext alloc] initWithFormat:_pixelFormat shareContext:nil];
|
||||
[_context setView:self];
|
||||
_needsPrepare=YES;
|
||||
}
|
||||
|
||||
return _context;
|
||||
- (NSOpenGLContext *)openGLContext {
|
||||
if (_context == nil) {
|
||||
_context = [[NSOpenGLContext alloc] initWithFormat:_pixelFormat shareContext:nil];
|
||||
[_context setView:self];
|
||||
_needsPrepare=YES;
|
||||
}
|
||||
|
||||
return _context;
|
||||
}
|
||||
|
||||
-(void)setPixelFormat:(NSOpenGLPixelFormat *)pixelFormat {
|
||||
pixelFormat=[pixelFormat retain];
|
||||
[_pixelFormat release];
|
||||
_pixelFormat=pixelFormat;
|
||||
- (void)setPixelFormat:(NSOpenGLPixelFormat *)pixelFormat {
|
||||
pixelFormat = [pixelFormat retain];
|
||||
[_pixelFormat release];
|
||||
_pixelFormat = pixelFormat;
|
||||
}
|
||||
|
||||
-(void)setOpenGLContext:(NSOpenGLContext *)context {
|
||||
[_context clearDrawable];
|
||||
context=[context retain];
|
||||
[_context release];
|
||||
_context=context;
|
||||
[_context setView:self];
|
||||
- (void)setOpenGLContext:(NSOpenGLContext *)context {
|
||||
[_context clearDrawable];
|
||||
context = [context retain];
|
||||
[_context release];
|
||||
_context = context;
|
||||
[_context setView:self];
|
||||
}
|
||||
|
||||
-(void)update {
|
||||
// we don't want to create the context if it doesn't exist
|
||||
[_context update];
|
||||
- (void)update {
|
||||
// we don't want to create the context if it doesn't exist
|
||||
[_context update];
|
||||
}
|
||||
|
||||
-(void)reshape {
|
||||
// do nothing
|
||||
- (void)reshape {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
-(void)prepareOpenGL {
|
||||
// do nothing
|
||||
- (void)prepareOpenGL {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
-(BOOL)isOpaque {
|
||||
return YES;
|
||||
- (BOOL)isOpaque {
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(void)lockFocus {
|
||||
[super lockFocus];
|
||||
|
||||
[[self openGLContext] makeCurrentContext];
|
||||
if(_needsPrepare){
|
||||
[self prepareOpenGL];
|
||||
_needsPrepare=NO;
|
||||
}
|
||||
if(_needsReshape)
|
||||
[self reshape];
|
||||
- (void)lockFocus {
|
||||
[super lockFocus];
|
||||
|
||||
[[self openGLContext] makeCurrentContext];
|
||||
|
||||
if (_needsPrepare){
|
||||
[self prepareOpenGL];
|
||||
_needsPrepare = NO;
|
||||
}
|
||||
|
||||
if (_needsReshape){
|
||||
[self reshape];
|
||||
_needsReshape = NO;
|
||||
}
|
||||
}
|
||||
|
||||
-(void)unlockFocus {
|
||||
[[self openGLContext] flushBuffer];
|
||||
[super unlockFocus];
|
||||
- (void)unlockFocus {
|
||||
[[self openGLContext] flushBuffer];
|
||||
[super unlockFocus];
|
||||
}
|
||||
|
||||
-(void)clearGLContext {
|
||||
[_context clearDrawable];
|
||||
[_context release];
|
||||
_context=nil;
|
||||
- (void)clearGLContext {
|
||||
[_context clearDrawable];
|
||||
[_context release];
|
||||
_context=nil;
|
||||
}
|
||||
|
||||
-(void)setFrame:(NSRect)frame {
|
||||
[super setFrame:frame];
|
||||
_needsReshape=YES;
|
||||
[self update];
|
||||
- (void)setFrame:(NSRect)frame {
|
||||
[super setFrame:frame];
|
||||
_needsReshape = YES;
|
||||
[self update];
|
||||
}
|
||||
|
||||
@end
|
||||
@end
|
Loading…
Reference in New Issue
Block a user