gl

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func EffectSource(src string) string

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 ReadFramebuffer

func ReadFramebuffer(width, height int) ([]byte, error)

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

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

func NewOffscreen(es bool, w, h int) (o *Offscreen, err error)

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.

func (*Offscreen) Info

func (o *Offscreen) Info() string

Info names the context's version and renderer.

func (*Offscreen) Release

func (o *Offscreen) Release()

Release deletes the context and what it holds.

func (*Offscreen) Render

func (o *Offscreen) Render(s *scene.Scene) ([]byte, error)

Render draws s, which must be as large as the framebuffer, with a renderer of its own, and returns its pixels as the CPU renderer draws them: premultiplied BGRA rows from the top.

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.

func (*Presenter) Present

func (p *Presenter) Present(pix []byte, stride, width, height int) error

Present copies premultiplied BGRA rows of stride bytes, width×height pixels, into the bound framebuffer, which is that size. The context current must be the one of the last call, or a new one.

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 New

func New() (*Renderer, error)

New returns a renderer for the current GL context.

func (*Renderer) FrameInfo

func (r *Renderer) FrameInfo() string

FrameInfo describes the last frame for GOLET_FRAME_STATS.

func (*Renderer) Invalidate

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.

func (*Renderer) Render

func (r *Renderer) Render(s *scene.Scene) error

Render draws s into the bound framebuffer, which is s.Width×s.Height device pixels.

func (*Renderer) Software

func (r *Renderer) Software() bool

Software reports whether the context draws on the CPU, as Mesa's llvmpipe (where GOLET_GPU=1 has Linux draw with OpenGL anyway) and the SwiftShader of browsers without a GPU, for ui's Painter.Accelerated.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL