Documentation
¶
Overview ¶
Package gl draws scenes with OpenGL 3.3, OpenGL ES 3.0 or WebGL 2 into the framebuffer bound when Render is called: the one GTK's GtkGLArea binds while it emits its render signal, or a canvas's (package web). Every op of a scene is an instanced quad drawn by one shader (shader.glsl, compiled when the renderer starts), from the instances package gpu builds; clips are scissor rectangles, with the innermost rounded clip computed in the shader, as in packages d3d11 and metal. GL functions come from libepoxy on Linux, which GTK resolves its own through, called with purego (no cgo), and from the current WebGL 2 context in browsers (load_js.go), through syscall/js.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EffectSource ¶ added in v0.2.10
EffectSource returns the source of an effect's fragment shader, after the version header: shader.glsl with EFFECT defined, the head of effect.glsl, the effect's shader (see scene.Effect), and the tail, which draws its instances with it.
func MakeAreaCurrent ¶ added in v0.6.4
MakeAreaCurrent makes the context of a GtkGLArea current again, with the area's framebuffer bound, when it no longer is during the area's render signal, and reports whether OpenGL has a current context after. GTK makes the area's context current before the signal, but what a frame runs before it draws, as a window that a button's action creates, shows or hides, can leave another context current, or none: GDK's gdk_window_hide clears the current context of the window it hides, and disposing a context makes EGL's current one none. GDK remembers the context it last made current and does nothing when asked for it again, so the area's context is made current again past that memory: cleared first, then made current.
func ReadFramebuffer ¶
ReadFramebuffer returns the pixels of the bound framebuffer, width×height, as the CPU renderer draws them: premultiplied BGRA rows from the top. Tests compare them.
Types ¶
type Offscreen ¶ added in v0.2.10
type Offscreen struct {
// contains filtered or unexported fields
}
Offscreen is a GL context without a window, current on the thread that made it, which must stay locked to it, with a framebuffer bound: for drawing scenes in tests, as packages drawing effects do. EGL makes it with Mesa's surfaceless platform, which draws with llvmpipe without a GPU.
func NewOffscreen ¶ added in v0.2.10
NewOffscreen makes an OpenGL 3.3 context, or with es an OpenGL ES 3.0 one, current on the calling thread, and binds a framebuffer of w×h pixels.
type Presenter ¶
type Presenter struct {
// contains filtered or unexported fields
}
Presenter shows frames drawn in memory in the bound framebuffer: what a GtkGLArea shows when its content draws on the CPU after all, as when the GL renderer fails. GTK shows only what OpenGL draws into a GtkGLArea.
type Renderer ¶
type Renderer struct {
// Partial has frames draw only what changed since the last one, into
// a framebuffer that keeps what was drawn (a GtkGLArea's, between
// reallocations, which Invalidate tells): diff finds what changed, and
// pipelines what the ops draw with; held tells that the framebuffer
// holds the last frame drawn. redrew is how much of it was drawn, for
// FrameInfo.
Partial bool
// contains filtered or unexported fields
}
Renderer draws scenes into the framebuffer bound when Render is called, with the GL context that was current when New was called. All its methods must be called with that context current.
func (*Renderer) FrameInfo ¶ added in v0.5.0
FrameInfo describes the last frame for MYGO_FRAME_STATS.
func (*Renderer) Invalidate ¶ added in v0.6.0
func (r *Renderer) Invalidate()
Invalidate tells that the framebuffer no longer holds the last frame drawn, as a GtkGLArea makes its buffers anew as it is allocated, at the same size too: the next frame draws whole.
func (*Renderer) Release ¶
func (r *Renderer) Release()
Release deletes the renderer's objects when its context is current, and otherwise leaves them to the context, which deletes them with itself.