mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-22 12:33:29 +00:00
Performed the bare necessary steps to get my little OpenGL view to create a CVDisplayLink and then repaint itself in time with the display.
This commit is contained in:
parent
1df2c48668
commit
4496493e85
@ -17,9 +17,20 @@
|
|||||||
<rect key="contentRect" x="133" y="235" width="507" height="413"/>
|
<rect key="contentRect" x="133" y="235" width="507" height="413"/>
|
||||||
<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"/>
|
<value key="minSize" type="size" width="94" height="86"/>
|
||||||
<view key="contentView" id="gIp-Ho-8D9" customClass="CSOpenGLView">
|
<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="507" height="413"/>
|
||||||
<autoresizingMask key="autoresizingMask"/>
|
<autoresizingMask key="autoresizingMask"/>
|
||||||
|
<subviews>
|
||||||
|
<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"/>
|
||||||
|
</openGLView>
|
||||||
|
</subviews>
|
||||||
|
<constraints>
|
||||||
|
<constraint firstItem="DEG-fq-cjd" firstAttribute="centerX" secondItem="gIp-Ho-8D9" secondAttribute="centerX" id="ES5-nL-N3h"/>
|
||||||
|
<constraint firstItem="DEG-fq-cjd" firstAttribute="height" secondItem="gIp-Ho-8D9" secondAttribute="height" id="YoB-qI-LFX"/>
|
||||||
|
<constraint firstItem="DEG-fq-cjd" firstAttribute="centerY" secondItem="gIp-Ho-8D9" secondAttribute="centerY" id="d5Y-3a-CEI"/>
|
||||||
|
<constraint firstItem="DEG-fq-cjd" firstAttribute="width" secondItem="gIp-Ho-8D9" secondAttribute="width" id="mYS-bH-DST"/>
|
||||||
|
</constraints>
|
||||||
</view>
|
</view>
|
||||||
<connections>
|
<connections>
|
||||||
<outlet property="delegate" destination="-2" id="0bl-1N-x8E"/>
|
<outlet property="delegate" destination="-2" id="0bl-1N-x8E"/>
|
||||||
|
@ -13,15 +13,38 @@
|
|||||||
CVDisplayLinkRef displayLink;
|
CVDisplayLinkRef displayLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithCoder:(nonnull NSCoder *)coder
|
- (void)prepareOpenGL
|
||||||
{
|
{
|
||||||
self = [super initWithCoder:coder];
|
// Synchronize buffer swaps with vertical refresh rate
|
||||||
|
GLint swapInt = 1;
|
||||||
|
[[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
|
||||||
|
|
||||||
if(self)
|
// Create a display link capable of being used with all active displays
|
||||||
{
|
CVDisplayLinkCreateWithActiveCGDisplays(&displayLink);
|
||||||
}
|
|
||||||
|
// Set the renderer output callback function
|
||||||
|
CVDisplayLinkSetOutputCallback(displayLink, &MyDisplayLinkCallback, (__bridge void * __nullable)(self));
|
||||||
|
|
||||||
|
// Set the display link for the current renderer
|
||||||
|
CGLContextObj cglContext = [[self openGLContext] CGLContextObj];
|
||||||
|
CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj];
|
||||||
|
CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, cglContext, cglPixelFormat);
|
||||||
|
|
||||||
|
// Activate the display link
|
||||||
|
CVDisplayLinkStart(displayLink);
|
||||||
|
}
|
||||||
|
|
||||||
return self;
|
// This is the renderer output callback function
|
||||||
|
static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp* now, const CVTimeStamp* outputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void* displayLinkContext)
|
||||||
|
{
|
||||||
|
[(__bridge CSOpenGLView *)displayLinkContext setNeedsDisplay:YES];
|
||||||
|
return kCVReturnSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)dealloc
|
||||||
|
{
|
||||||
|
// Release the display link
|
||||||
|
CVDisplayLinkRelease(displayLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Loading…
Reference in New Issue
Block a user