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)
This commit is contained in:
Vladimir Kravets 2018-12-05 10:27:02 +02:00
parent 06c5ca65b1
commit 731fcf5b08
3 changed files with 43 additions and 10 deletions

28
gui/darwin_opengl.go Normal file
View File

@ -0,0 +1,28 @@
//+build darwin
package gui
/*
#cgo darwin CFLAGS: -x objective-c -Wno-deprecated-declarations
#cgo darwin LDFLAGS: -framework Foundation
#include <Cocoa/Cocoa.h>
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++
}
}

View File

@ -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()
}

9
gui/opengl.go Normal file
View File

@ -0,0 +1,9 @@
// +build !darwin
package gui
import "github.com/go-gl/glfw/v3.2/glfw"
func UpdateNSGLContext(window *glfw.Window) {
}