app/internal/window: add needVSync() to eglDriver interface

This enables calling eglSwapInterval with an interval value of 0 or 1
on a per driver basis.

Signed-off-by: Denis Bernard <db047h@gmail.com>
This commit is contained in:
Denis Bernard
2019-10-26 15:21:05 +02:00
committed by Elias Naur
parent 2c75f52de6
commit b78d144119
4 changed files with 15 additions and 8 deletions
+9 -8
View File
@@ -28,6 +28,7 @@ type eglDriver interface {
eglDisplay() _EGLNativeDisplayType eglDisplay() _EGLNativeDisplayType
eglWindow(visID int) (_EGLNativeWindowType, int, int, error) eglWindow(visID int) (_EGLNativeWindowType, int, int, error)
eglDestroy() eglDestroy()
needVSync() bool
} }
type eglContext struct { type eglContext struct {
@@ -156,6 +157,14 @@ func (c *context) MakeCurrent() error {
c.eglWin = nilEGLNativeWindowType c.eglWin = nilEGLNativeWindowType
return err return err
} }
// eglSwapInterval 1 leads to erratic frame rates and unnecessary blocking.
// We rely on platform specific frame rate limiting instead, except on Windows
// and X11 where eglSwapInterval is all there is.
if c.driver.needVSync() {
eglSwapInterval(c.eglCtx.disp, 1)
} else {
eglSwapInterval(c.eglCtx.disp, 0)
}
if c.eglCtx.srgb { if c.eglCtx.srgb {
return nil return nil
} }
@@ -269,13 +278,5 @@ func createSurfaceAndMakeCurrent(eglCtx *eglContext, win _EGLNativeWindowType) (
eglDestroySurface(eglCtx.disp, eglSurf) eglDestroySurface(eglCtx.disp, eglSurf)
return nilEGLSurface, fmt.Errorf("eglMakeCurrent error 0x%x", eglGetError()) return nilEGLSurface, fmt.Errorf("eglMakeCurrent error 0x%x", eglGetError())
} }
// eglSwapInterval 1 leads to erratic frame rates and unnecessary blocking.
// We rely on platform specific frame rate limiting instead, except on Windows
// where eglSwapInterval is all there is.
if runtime.GOOS != "windows" {
eglSwapInterval(eglCtx.disp, 0)
} else {
eglSwapInterval(eglCtx.disp, 1)
}
return eglSurf, nil return eglSurf, nil
} }
+2
View File
@@ -18,3 +18,5 @@ func (w *window) eglWindow(visID int) (_EGLNativeWindowType, int, int, error) {
win, width, height := w.nativeWindow(visID) win, width, height := w.nativeWindow(visID)
return _EGLNativeWindowType(win), width, height, nil return _EGLNativeWindowType(win), width, height, nil
} }
func (w *window) needVSync() bool { return false }
+2
View File
@@ -62,3 +62,5 @@ func (w *window) eglWindow(visID int) (_EGLNativeWindowType, int, int, error) {
C.wl_egl_window_resize(eglWin, C.int(width), C.int(height), 0, 0) C.wl_egl_window_resize(eglWin, C.int(width), C.int(height), 0, 0)
return _EGLNativeWindowType(uintptr(unsafe.Pointer(eglWin))), width, height, nil return _EGLNativeWindowType(uintptr(unsafe.Pointer(eglWin))), width, height, nil
} }
func (w *window) needVSync() bool { return false }
+2
View File
@@ -158,3 +158,5 @@ func (w *window) eglWindow(visID int) (_EGLNativeWindowType, int, int, error) {
func (w *window) NewContext() (gl.Context, error) { func (w *window) NewContext() (gl.Context, error) {
return newContext(w) return newContext(w)
} }
func (w *window) needVSync() bool { return true }