1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-22 12:33:29 +00:00

Ensured windows start and remain 4:3, made sure I request a GL 3.2 context and that an exception is raised if I call any old-fashioned GL functions.

This commit is contained in:
Thomas Harte 2015-07-23 22:51:53 -04:00
parent 02c786520a
commit 44e8ffd01c
3 changed files with 39 additions and 9 deletions

View File

@ -20,6 +20,8 @@ class Atari2600Document: NSDocument, CSOpenGLViewDelegate, CSAtari2600Delegate {
super.windowControllerDidLoadNib(aController) super.windowControllerDidLoadNib(aController)
openGLView!.delegate = self openGLView!.delegate = self
// bind the content aspect ratio to remain 4:3 from now on
aController.window!.contentAspectRatio = NSSize(width: 4.0, height: 3.0) aController.window!.contentAspectRatio = NSSize(width: 4.0, height: 3.0)
} }
@ -41,9 +43,6 @@ class Atari2600Document: NSDocument, CSOpenGLViewDelegate, CSAtari2600Delegate {
} }
override func readFromData(data: NSData, ofType typeName: String) throws { override func readFromData(data: NSData, ofType typeName: String) throws {
// Insert code here to read your document from the given data of the specified type. If outError != nil, ensure that you create and set an appropriate error when returning false.
// You can also choose to override readFromFileWrapper:ofType:error: or readFromURL:ofType:error: instead.
// If you override either of these, you should also override -isEntireFileLoaded to return false if the contents are lazily loaded.
atari2600 = CSAtari2600() atari2600 = CSAtari2600()
atari2600!.setROM(data) atari2600!.setROM(data)
atari2600!.delegate = self atari2600!.delegate = self

View File

@ -16,15 +16,14 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/> <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowCollectionBehavior key="collectionBehavior" fullScreenPrimary="YES"/> <windowCollectionBehavior key="collectionBehavior" fullScreenPrimary="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/> <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="133" y="235" width="507" height="413"/> <rect key="contentRect" x="133" y="235" width="400" height="300"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/> <rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
<value key="minSize" type="size" width="94" height="86"/>
<view key="contentView" id="gIp-Ho-8D9"> <view key="contentView" id="gIp-Ho-8D9">
<rect key="frame" x="0.0" y="0.0" width="507" height="413"/> <rect key="frame" x="0.0" y="0.0" width="400" height="300"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<subviews> <subviews>
<openGLView useAuxiliaryDepthBufferStencil="NO" allowOffline="YES" wantsBestResolutionOpenGLSurface="YES" translatesAutoresizingMaskIntoConstraints="NO" id="DEG-fq-cjd" customClass="CSOpenGLView"> <openGLView useAuxiliaryDepthBufferStencil="NO" allowOffline="YES" wantsBestResolutionOpenGLSurface="YES" translatesAutoresizingMaskIntoConstraints="NO" id="DEG-fq-cjd" customClass="CSOpenGLView">
<rect key="frame" x="0.0" y="0.0" width="507" height="413"/> <rect key="frame" x="0.0" y="0.0" width="400" height="300"/>
</openGLView> </openGLView>
</subviews> </subviews>
<constraints> <constraints>

View File

@ -48,15 +48,47 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
CVDisplayLinkRelease(displayLink); CVDisplayLinkRelease(displayLink);
} }
- (void)reshape
{
[super reshape];
CGSize viewSize = [self convertSize:self.bounds.size toView:self];
glViewport(0, 0, viewSize.width, viewSize.height);
}
- (void)drawRect:(NSRect)dirtyRect - (void)drawRect:(NSRect)dirtyRect
{ {
[self.openGLContext makeCurrentContext]; [self.openGLContext makeCurrentContext];
CGSize viewSize = [self convertSize:self.bounds.size toView:self];
glViewport((GLint)0, (GLint)0, (GLsizei)viewSize.width, (GLsizei)viewSize.height);
[self.delegate openGLViewDrawView:self]; [self.delegate openGLViewDrawView:self];
glSwapAPPLE(); glSwapAPPLE();
} }
- (void) awakeFromNib
{
NSOpenGLPixelFormatAttribute attributes[] =
{
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
0
};
NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
NSOpenGLContext *context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
#ifdef DEBUG
// When we're using a CoreProfile context, crash if we call a legacy OpenGL function
// This will make it much more obvious where and when such a function call is made so
// that we can remove such calls.
// Without this we'd simply get GL_INVALID_OPERATION error for calling legacy functions
// but it would be more difficult to see where that function was called.
CGLEnable([context CGLContextObj], kCGLCECrashOnRemovedFunctions);
#endif
self.pixelFormat = pixelFormat;
self.openGLContext = context;
self.wantsBestResolutionOpenGLSurface = YES;
}
@end @end