webgl

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 10 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

Rendered for js/wasm

Overview

Package webgl draws scenes with WebGL 2 into a canvas of a web page.

It draws what the Vulkan and Direct3D 11 renderers draw, with their shaders ported to GLSL ES 3.00 (see shaders.go). Each call into WebGL is a call from WebAssembly into JavaScript, so a frame makes few: the instances of the whole frame are written into one float texture with a single upload, and each batch of instances is then drawn with a uniform for where its instances start and one instanced draw. Vertex shaders read their instance with texelFetch, and there are no vertex buffers.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoWebGL2 = errors.New("webgl: the browser has no WebGL 2")

ErrNoWebGL2 is returned by New when the page cannot draw with WebGL 2.

Functions

This section is empty.

Types

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer implements render.Renderer with WebGL 2 for one canvas.

func New

func New(canvas js.Value) (*Renderer, error)

New makes a renderer that draws into canvas. The canvas must have no other context.

func (*Renderer) BeginFrame

func (r *Renderer) BeginFrame(width, height int, clear scene.Color) error

func (*Renderer) CaptureNextFrame

func (r *Renderer) CaptureNextFrame(fn func(*image.RGBA, error))

func (*Renderer) Close

func (r *Renderer) Close()

Close releases the renderer's listeners. The context goes with the canvas.

func (*Renderer) Describe

func (r *Renderer) Describe() string

Describe names what the renderer draws with.

func (*Renderer) DrawGlyphs

func (r *Renderer) DrawGlyphs(run scene.GlyphRun)

DrawGlyphs draws a run's glyphs. A page has grayscale text only (see text.Atlas): a subpixel atlas is drawn as grayscale from its first channel.

func (*Renderer) DrawImages

func (r *Renderer) DrawImages(ims []scene.ImageDraw)

func (*Renderer) DrawQuads

func (r *Renderer) DrawQuads(qs []scene.Quad)

func (*Renderer) EndFrame

func (r *Renderer) EndFrame() error

EndFrame draws the frame. The browser shows it when the page's script returns to the event loop.

func (*Renderer) PopClip

func (r *Renderer) PopClip()

func (*Renderer) PushClip

func (r *Renderer) PushClip(c scene.Rect)

func (*Renderer) PushRoundedClip

func (r *Renderer) PushRoundedClip(c scene.Rect, radii scene.Corners)

func (*Renderer) Recreate

func (r *Renderer) Recreate() error

Recreate makes the programs and textures again after the context was lost, once the browser has restored it.

Jump to

Keyboard shortcuts

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