[Renderer] Add RenderingSurface protocol
The OpenGLView implements RenderingSurface and passes itself in the newly updated renderOntoSurface(_:atTime:) call.
This commit is contained in:
parent
0338f7360d
commit
cae145e0c1
2 changed files with 8 additions and 4 deletions
|
@ -11,15 +11,15 @@ import Cocoa
|
|||
import OpenGL
|
||||
import CoreVideo
|
||||
|
||||
public class OpenGLView: NSOpenGLView {
|
||||
public class OpenGLView: NSOpenGLView, RenderingSurface {
|
||||
private var didSetupOpenGL = false
|
||||
private var displayLink: CVDisplayLink? = nil
|
||||
|
||||
// TODO: Should this be weak?
|
||||
public var renderer: FrameRenderer? = nil
|
||||
|
||||
deinit {
|
||||
stopRenderingLoop()
|
||||
renderer = nil
|
||||
}
|
||||
|
||||
override public func awakeFromNib() {
|
||||
|
@ -120,7 +120,7 @@ public class OpenGLView: NSOpenGLView {
|
|||
defer { CGLUnlockContext(context.CGLContextObj) }
|
||||
|
||||
// Render the frame.
|
||||
renderer!.renderAtTime(time)
|
||||
renderer!.renderOntoSurface(self, atTime: time)
|
||||
context.flushBuffer()
|
||||
|
||||
return kCVReturnSuccess
|
||||
|
|
|
@ -10,6 +10,10 @@ import CoreVideo
|
|||
|
||||
public typealias FrameTimeStamp = CVTimeStamp
|
||||
|
||||
public protocol FrameRenderer {
|
||||
func renderAtTime(time: FrameTimeStamp)
|
||||
public protocol RenderingSurface {
|
||||
var bounds: CGRect { get }
|
||||
}
|
||||
|
||||
public protocol FrameRenderer {
|
||||
func renderOntoSurface(surface: RenderingSurface, atTime time: FrameTimeStamp)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue