Documentation
¶
Index ¶
- type Window
- func (w *Window) App() *gogpu.App
- func (w *Window) Close()
- func (w *Window) DeviceProvider() gogpu.DeviceProvider
- func (w *Window) OnResize(fn func(width, height int))
- func (w *Window) OnUpdate(fn func(dt float64))
- func (w *Window) RequestRedraw()
- func (w *Window) Run(onDraw func(dc *gogpu.Context)) error
- func (w *Window) ScaleFactor() float64
- func (w *Window) Size() (width, height int)
- type WindowConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window wraps gogpu App on auto mode (GraphicsAPIAuto, RenderModeAuto). It owns the OS surface and app lifecycle. All drawing goes through the render package — Window does not draw.
func NewWindow ¶
func NewWindow(cfg WindowConfig) (*Window, error)
func (*Window) DeviceProvider ¶
func (w *Window) DeviceProvider() gogpu.DeviceProvider
DeviceProvider returns the GPU device provider for the render package.
func (*Window) OnResize ¶
OnResize registers a callback for a change of size, in logical pixels. It fires when the window is resized and when it moves to a display with a different backing scale.
func (*Window) OnUpdate ¶
OnUpdate registers the tick that runs whether or not a frame is drawn: input, simulation, anything that decides there is something new to show.
It matters on an OnDemand window. The loop blocks on OS events when idle, wakes on one, and calls this; OnDraw runs only if something asked for a frame. Polling input from the draw callback instead leaves an idle window deaf, because no frame means no polling and no polling means nothing ever asks for a frame.
GPU work belongs in the draw callback, not here.
func (*Window) RequestRedraw ¶
func (w *Window) RequestRedraw()
RequestRedraw asks for one frame. It is what drives an OnDemand window, and it is harmless on a continuous one.
func (*Window) Run ¶
Run starts the app draw loop. The callback receives the per-frame gogpu.Context and should call render.GPU methods to draw.
func (*Window) ScaleFactor ¶
ScaleFactor is physical pixels per logical pixel, and it changes when the window moves between displays.
func (*Window) Size ¶
Size is the window in logical pixels, which is what a camera and a mouse position are in.
A game has to be able to ask: a window moved to a display with a different backing scale resizes its surface, and a projection built for the old size draws the scene into part of the new one. There was no way to ask before, so every example hard-coded the size it was created with.
type WindowConfig ¶
type WindowConfig struct {
Title string
W, H int
Resizable bool
// OnDemand draws only when a redraw is asked for, rather than every
// vsync. A game whose world is still then costs nothing: the frame that
// would have been identical is never drawn and never presented, which is
// where an idle window's GPU time goes.
//
// Wake something, move the camera, take an input - call RequestRedraw.
OnDemand bool
}