[Renderer] Add RenderingSurface protocol

The OpenGLView implements RenderingSurface and passes itself in the newly
updated renderOntoSurface(_:atTime:) call.
This commit is contained in:
Eryn Wells 2015-11-14 23:44:50 -08:00
parent 0338f7360d
commit cae145e0c1
2 changed files with 8 additions and 4 deletions

View file

@ -11,15 +11,15 @@ import Cocoa
import OpenGL import OpenGL
import CoreVideo import CoreVideo
public class OpenGLView: NSOpenGLView { public class OpenGLView: NSOpenGLView, RenderingSurface {
private var didSetupOpenGL = false private var didSetupOpenGL = false
private var displayLink: CVDisplayLink? = nil private var displayLink: CVDisplayLink? = nil
// TODO: Should this be weak?
public var renderer: FrameRenderer? = nil public var renderer: FrameRenderer? = nil
deinit { deinit {
stopRenderingLoop() stopRenderingLoop()
renderer = nil
} }
override public func awakeFromNib() { override public func awakeFromNib() {
@ -120,7 +120,7 @@ public class OpenGLView: NSOpenGLView {
defer { CGLUnlockContext(context.CGLContextObj) } defer { CGLUnlockContext(context.CGLContextObj) }
// Render the frame. // Render the frame.
renderer!.renderAtTime(time) renderer!.renderOntoSurface(self, atTime: time)
context.flushBuffer() context.flushBuffer()
return kCVReturnSuccess return kCVReturnSuccess

View file

@ -10,6 +10,10 @@ import CoreVideo
public typealias FrameTimeStamp = CVTimeStamp public typealias FrameTimeStamp = CVTimeStamp
public protocol RenderingSurface {
var bounds: CGRect { get }
}
public protocol FrameRenderer { public protocol FrameRenderer {
func renderAtTime(time: FrameTimeStamp) func renderOntoSurface(surface: RenderingSurface, atTime time: FrameTimeStamp)
} }