[Renderer] Rename OpenGLRenderer source directory to OpenGL

This commit is contained in:
Eryn Wells 2015-11-13 22:41:47 -08:00
parent 1485060712
commit 6fc2cd0a10
3 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015 Eryn Wells. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

View file

@ -0,0 +1,19 @@
//
// OpenGLRenderer.h
// OpenGLRenderer
//
// Created by Eryn Wells on 11/12/15.
// Copyright © 2015 Eryn Wells. All rights reserved.
//
#import <Cocoa/Cocoa.h>
//! Project version number for OpenGLRenderer.
FOUNDATION_EXPORT double OpenGLRendererVersionNumber;
//! Project version string for OpenGLRenderer.
FOUNDATION_EXPORT const unsigned char OpenGLRendererVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <OpenGLRenderer/PublicHeader.h>

View file

@ -0,0 +1,104 @@
//
// OpenGLView.swift
// OpenGLRenderer
//
// Created by Eryn Wells on 11/12/15.
// Copyright © 2015 Eryn Wells. All rights reserved.
//
import Foundation
import Cocoa
import OpenGL
import CoreVideo
class OpenGLView: NSOpenGLView {
private var didSetupOpenGL = false
private var displayLink: CVDisplayLink? = nil
override func viewWillMoveToSuperview(newSuperview: NSView?) {
if newSuperview != nil {
setupOpenGL()
startRenderingLoop()
} else {
stopRenderingLoop()
}
}
private func setupOpenGL() {
if didSetupOpenGL {
return
}
defer { didSetupOpenGL = true }
let attrs = [NSOpenGLPFAAccelerated,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFADepthSize, 24,
NSOpenGLPFAOpenGLProfile,
NSOpenGLProfileVersion4_1Core]
let format = NSOpenGLPixelFormat(attributes: UnsafePointer<UInt32>(attrs))
guard format != nil else {
// TODO: Throw an error?
return
}
let context = NSOpenGLContext(format: format!, shareContext: nil)
guard context != nil else {
// TODO: Throw an error?
return
}
CGLEnable(context!.CGLContextObj, kCGLCECrashOnRemovedFunctions)
pixelFormat = format
openGLContext = context
wantsBestResolutionOpenGLSurface = true
}
private func startRenderingLoop() {
var success = kCVReturnSuccess
success = CVDisplayLinkCreateWithActiveCGDisplays(&displayLink)
guard success == kCVReturnSuccess && displayLink != nil else {
// TODO: Throw an error?
return
}
success = CVDisplayLinkSetOutputHandler(displayLink!) {
(displayLink: CVDisplayLink,
currentTime: UnsafePointer<CVTimeStamp>,
displayTime: UnsafePointer<CVTimeStamp>,
optionsIn: CVOptionFlags,
optionsOut: UnsafeMutablePointer<CVOptionFlags>) -> CVReturn in
var result = kCVReturnSuccess
autoreleasepool {
result = self._renderAtTime(currentTime.memory)
}
return result
}
guard success == kCVReturnSuccess else {
// TODO: Throw an error?
return
}
if let context = self.openGLContext?.CGLContextObj, format = self.pixelFormat?.CGLPixelFormatObj {
CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink!, context, format)
} else {
// TODO: Throw an error?
return
}
CVDisplayLinkStart(displayLink!)
}
private func stopRenderingLoop() {
guard displayLink != nil else { return }
CVDisplayLinkStop(displayLink!)
displayLink = nil
}
private func _renderAtTime(time: CVTimeStamp) -> CVReturn {
return kCVReturnSuccess
}
}