improve window doc + improve window mutex handling

This commit is contained in:
faiface 2016-11-24 16:16:00 +01:00
parent ea2ed1bcd5
commit 3b589b96bc
1 changed files with 40 additions and 18 deletions

View File

@ -9,23 +9,41 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
//TODO: better doc
// WindowConfig is convenience structure for specifying all possible properties of a window. // WindowConfig is convenience structure for specifying all possible properties of a window.
// Properties are chosen in such a way, that you usually only need to set a few of them - defaults // Properties are chosen in such a way, that you usually only need to set a few of them - defaults
// (zeros) should usually be sensible. // (zeros) should usually be sensible.
// //
// Note that you always need to set the width and the height of a window. // Note that you always need to set the width and the height of a window.
type WindowConfig struct { type WindowConfig struct {
Title string // Title at the top of a window.
Width float64 Title string
Height float64
Resizable bool // Width of a window in pixels.
Hidden bool Width float64
// Height of a window in pixels.
Height float64
// Whether a window is resizable.
Resizable bool
// If set to true, the window will be initially invisible.
Hidden bool
// Undecorated window ommits the borders and decorations (close button, etc.).
Undecorated bool Undecorated bool
Unfocused bool
Maximized bool // If set to true, a window will not get focused upon showing up.
VSync bool Unfocused bool
// Whether a window is maximized.
Maximized bool
// VSync (vertical synchronization) synchronizes window's framerate with the framerate of the monitor.
VSync bool
// Number of samples for multi-sample anti-aliasing (edge-smoothing).
// Usual values are 0, 2, 4, 8 (powers of 2 and not much more than this).
MSAASamples int MSAASamples int
} }
@ -93,24 +111,28 @@ func (w *Window) Update() {
w.End() w.End()
} }
var ( var currentWindow struct {
windowMutex sync.Mutex sync.Mutex
currentWindow *Window handler *Window
) }
// Begin makes the context of this window current. // Begin makes the context of this window current.
//
// Note that you only need to use this function if you're designing a low-level technical plugin (such as an effect).
func (w *Window) Begin() { func (w *Window) Begin() {
windowMutex.Lock() currentWindow.Lock()
if currentWindow != w { if currentWindow.handler != w {
pixelgl.Do(func() { pixelgl.Do(func() {
w.window.MakeContextCurrent() w.window.MakeContextCurrent()
pixelgl.Init() pixelgl.Init()
}) })
currentWindow = w currentWindow.handler = w
} }
} }
// End makes it possible for other windows to make their context current. // End makes it possible for other windows to make their context current.
//
// Note that you only need to use this function if you're designing a low-level technical plugin (such as an effect).
func (w *Window) End() { func (w *Window) End() {
windowMutex.Unlock() currentWindow.Unlock()
} }