From 7f714c6984b3ca0ee49a76cbb46fbeb520519401 Mon Sep 17 00:00:00 2001 From: Akemi Date: Sun, 18 Feb 2018 22:10:34 +0100 Subject: cocoa-cb: fix invalid framebuffer operation error in certain circumstances the returned fbo for drawing is 0, but that fbo is solely used internally by the CAOpenGLLayer for its drawing and should never be used. in that case we fallback to 1 or the last used fbo instead if it was not 0. Fixes #5546 --- osdep/macOS_mpv_helper.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osdep/macOS_mpv_helper.swift b/osdep/macOS_mpv_helper.swift index 39be9cc8c7..15081d0133 100644 --- a/osdep/macOS_mpv_helper.swift +++ b/osdep/macOS_mpv_helper.swift @@ -26,6 +26,7 @@ class MPVHelper: NSObject { var mpvLog: OpaquePointer? var inputContext: OpaquePointer? var mpctx: UnsafeMutablePointer? + var fbo: GLint = 1 init(_ mpv: OpaquePointer) { super.init() @@ -101,8 +102,11 @@ class MPVHelper: NSObject { if mpvGLCBContext != nil { var i: GLint = 0 glGetIntegerv(GLenum(GL_DRAW_FRAMEBUFFER_BINDING), &i) + // CAOpenGLLayer has ownership of FBO zero yet can return it to us, + // so only utilize a newly received FBO ID if it is nonzero. + fbo = i != 0 ? i : fbo - mpv_opengl_cb_draw(mpvGLCBContext, i, Int32(surface.width), Int32(-surface.height)) + mpv_opengl_cb_draw(mpvGLCBContext, fbo, Int32(surface.width), Int32(-surface.height)) } else { glClearColor(0, 0, 0, 1) glClear(GLbitfield(GL_COLOR_BUFFER_BIT)) -- cgit v1.2.3