From 731fcf5b08d8cac15034f32973c42e2bdc4a63c3 Mon Sep 17 00:00:00 2001 From: Vladimir Kravets Date: Wed, 5 Dec 2018 10:27:02 +0200 Subject: [PATCH] Add another workaround for darwin SDL blank window bug As for me it's much better then moving window at one pixel (Based on the https://github.com/Noofbiz/glfwMojaveFix) --- gui/darwin_opengl.go | 28 ++++++++++++++++++++++++++++ gui/gui.go | 16 ++++++---------- gui/opengl.go | 9 +++++++++ 3 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 gui/darwin_opengl.go create mode 100644 gui/opengl.go diff --git a/gui/darwin_opengl.go b/gui/darwin_opengl.go new file mode 100644 index 0000000..7c024e9 --- /dev/null +++ b/gui/darwin_opengl.go @@ -0,0 +1,28 @@ +//+build darwin + +package gui + +/* +#cgo darwin CFLAGS: -x objective-c -Wno-deprecated-declarations +#cgo darwin LDFLAGS: -framework Foundation +#include +void cocoa_update_nsgl_context(void* id) { + NSOpenGLContext *ctx = id; + [ctx update]; +} +*/ +import "C" +import ( + "github.com/go-gl/glfw/v3.2/glfw" + "unsafe" +) + +var nsglContextUpdateCounter int + +func UpdateNSGLContext(window *glfw.Window) { + if nsglContextUpdateCounter < 2 { + ctx := window.GetNSGLContext() + C.cocoa_update_nsgl_context(unsafe.Pointer(ctx)) + nsglContextUpdateCounter++ + } +} diff --git a/gui/gui.go b/gui/gui.go index 0df6269..6d33a8d 100644 --- a/gui/gui.go +++ b/gui/gui.go @@ -215,8 +215,6 @@ func (gui *GUI) Render() error { startTime := time.Now() showMessage := true - darwinRenderFixRequired := runtime.GOOS == "darwin" - for !gui.window.ShouldClose() { select { @@ -269,14 +267,7 @@ Buffer Size: %d lines } } - gui.window.SwapBuffers() - - // Workaround for https://github.com/glfw/glfw/issues/1334 - if darwinRenderFixRequired { - darwinRenderFixRequired = false - x, y := gui.window.GetPos() - gui.window.SetPos(x+1, y) - } + gui.SwapBuffers() } } @@ -487,3 +478,8 @@ func (gui *GUI) launchTarget(target string) { gui.logger.Errorf("Failed to launch external command %s: %s", cmd, err) } } + +func (gui *GUI) SwapBuffers() { + UpdateNSGLContext(gui.window) + gui.window.SwapBuffers() +} diff --git a/gui/opengl.go b/gui/opengl.go new file mode 100644 index 0000000..5406861 --- /dev/null +++ b/gui/opengl.go @@ -0,0 +1,9 @@ +// +build !darwin + +package gui + +import "github.com/go-gl/glfw/v3.2/glfw" + +func UpdateNSGLContext(window *glfw.Window) { + +}