Merge pull request #110 from vkravets/native_fix_mojave_darwin

Add another workaround for darwin SDL blank window bug
This commit is contained in:
Liam Galvin 2018-12-05 11:38:02 +00:00 committed by GitHub
commit b960a679b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) {
}