gpu

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPixelFont = &PixelFont{
	Width:   3,
	Height:  5,
	Spacing: 1,
	Glyphs: map[rune][]string{
		' ':  {"...", "...", "...", "...", "..."},
		'0':  {"###", "#.#", "#.#", "#.#", "###"},
		'1':  {".#.", "##.", ".#.", ".#.", "###"},
		'2':  {"###", "..#", "###", "#..", "###"},
		'3':  {"###", "..#", "###", "..#", "###"},
		'4':  {"#.#", "#.#", "###", "..#", "..#"},
		'5':  {"###", "#..", "###", "..#", "###"},
		'6':  {"###", "#..", "###", "#.#", "###"},
		'7':  {"###", "..#", "..#", "..#", "..#"},
		'8':  {"###", "#.#", "###", "#.#", "###"},
		'9':  {"###", "#.#", "###", "..#", "###"},
		'A':  {".#.", "#.#", "###", "#.#", "#.#"},
		'B':  {"##.", "#.#", "##.", "#.#", "##."},
		'C':  {".##", "#..", "#..", "#..", ".##"},
		'D':  {"##.", "#.#", "#.#", "#.#", "##."},
		'E':  {"###", "#..", "##.", "#..", "###"},
		'F':  {"###", "#..", "##.", "#..", "#.."},
		'G':  {".##", "#..", "#.#", "#.#", ".##"},
		'H':  {"#.#", "#.#", "###", "#.#", "#.#"},
		'I':  {"###", ".#.", ".#.", ".#.", "###"},
		'J':  {"..#", "..#", "..#", "#.#", ".#."},
		'K':  {"#.#", "##.", "#..", "##.", "#.#"},
		'L':  {"#..", "#..", "#..", "#..", "###"},
		'M':  {"#.#", "###", "###", "#.#", "#.#"},
		'N':  {"#.#", "##.", "#.#", ".##", "#.#"},
		'O':  {".#.", "#.#", "#.#", "#.#", ".#."},
		'P':  {"##.", "#.#", "##.", "#..", "#.."},
		'Q':  {".#.", "#.#", "#.#", ".##", "..#"},
		'R':  {"##.", "#.#", "##.", "#.#", "#.#"},
		'S':  {".##", "#..", ".#.", "..#", "##."},
		'T':  {"###", ".#.", ".#.", ".#.", ".#."},
		'U':  {"#.#", "#.#", "#.#", "#.#", "###"},
		'V':  {"#.#", "#.#", "#.#", "#.#", ".#."},
		'W':  {"#.#", "#.#", "###", "###", "#.#"},
		'X':  {"#.#", "#.#", ".#.", "#.#", "#.#"},
		'Y':  {"#.#", "#.#", ".#.", ".#.", ".#."},
		'Z':  {"###", "..#", ".#.", "#..", "###"},
		'.':  {"...", "...", "...", "...", ".#."},
		'-':  {"...", "...", "###", "...", "..."},
		':':  {"...", ".#.", "...", ".#.", "..."},
		'!':  {".#.", ".#.", ".#.", "...", ".#."},
		'?':  {"###", "..#", ".#.", "...", ".#."},
		'+':  {"...", ".#.", "###", ".#.", "..."},
		'/':  {"..#", ".#.", "#..", "...", "..."},
		'"':  {"#.#", "#.#", "...", "...", "..."},
		'\'': {".#.", ".#.", "...", "...", "..."},
		'_':  {"...", "...", "...", "...", "###"},
	},
}

DefaultPixelFont is a compact 3x5 pixel font.

View Source
var ErrUnsupported = errors.New("gpu backend unsupported")

ErrUnsupported is returned when a backend is unavailable.

Functions

This section is empty.

Types

type Backend

type Backend int

Backend identifies a driver backend.

const (
	BackendAuto Backend = iota
	BackendOpenGL
	BackendMetal
	BackendSoftware
	BackendWebGL
)

type BlendMode

type BlendMode int

BlendMode controls how source pixels blend with the destination.

const (
	BlendNone BlendMode = iota
	BlendAlpha
	BlendAdditive
)

type BlurEffect

type BlurEffect struct {
	Radius float32
}

BlurEffect applies a box blur.

func (BlurEffect) Apply

func (e BlurEffect) Apply(src Texture, dst Framebuffer, driver Driver)

type ChromaticAberration

type ChromaticAberration struct {
	Amount float32
}

ChromaticAberration offsets color channels.

func (ChromaticAberration) Apply

func (e ChromaticAberration) Apply(src Texture, dst Framebuffer, driver Driver)

type ColorGradeEffect

type ColorGradeEffect struct {
	Brightness float32
	Contrast   float32
	Saturation float32
	Hue        float32
}

ColorGradeEffect adjusts color properties.

func (ColorGradeEffect) Apply

func (e ColorGradeEffect) Apply(src Texture, dst Framebuffer, driver Driver)

type CustomEffect

type CustomEffect struct {
	Shader   Shader
	Uniforms map[string]any
}

CustomEffect applies a custom shader.

func (CustomEffect) Apply

func (e CustomEffect) Apply(src Texture, dst Framebuffer, driver Driver)

type DrawCall

type DrawCall struct {
	Shader   Shader
	Vertices []float32
	Indices  []uint16
	Textures []Texture
	Target   Framebuffer
	Blend    BlendMode
	Scissor  *image.Rectangle
	Layout   *VertexLayout
}

DrawCall describes a batched draw operation.

type Driver

type Driver interface {
	Backend() Backend
	Init() error
	Dispose()

	NewTexture(width, height int) (Texture, error)
	NewFramebuffer(width, height int) (Framebuffer, error)
	NewShader(src ShaderSource) (Shader, error)

	Clear(r, g, b, a float32)
	Draw(call DrawCall)
	ReadPixels(fb Framebuffer, rect image.Rectangle) ([]byte, error)

	MaxTextureSize() int
}

Driver provides low-level rendering operations.

func NewDriver

func NewDriver(backend Backend) (Driver, error)

NewDriver returns a driver for the requested backend.

type Effect

type Effect interface {
	Apply(src Texture, dst Framebuffer, driver Driver)
}

Effect applies a post-processing operation.

type Font

type Font struct {
	Face *PixelFont
}

Font wraps a pixel font face.

func DefaultFont

func DefaultFont() *Font

DefaultFont returns the default pixel font.

type Framebuffer

type Framebuffer interface {
	ID() uint32
	Size() (w, h int)
	Bind()
	Texture() Texture
	Dispose()
}

Framebuffer represents a render target.

type GLSLSource

type GLSLSource struct {
	Vertex   string
	Fragment string
}

GLSLSource contains vertex and fragment shader source.

type GPUCanvas

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

GPUCanvas renders into an offscreen RGBA buffer.

func NewGPUCanvas

func NewGPUCanvas(width, height int) (*GPUCanvas, error)

NewGPUCanvas creates a new GPU canvas.

func NewGPUCanvasWithDriver

func NewGPUCanvasWithDriver(width, height int, driver Driver) (*GPUCanvas, error)

NewGPUCanvasWithDriver creates a canvas with a provided driver.

func (*GPUCanvas) ApplyEffect

func (c *GPUCanvas) ApplyEffect(effect Effect)

ApplyEffect applies a post-processing effect.

func (*GPUCanvas) Begin

func (c *GPUCanvas) Begin()

Begin starts a new frame.

func (*GPUCanvas) BeginPath

func (c *GPUCanvas) BeginPath()

BeginPath starts a new path.

func (*GPUCanvas) BezierTo

func (c *GPUCanvas) BezierTo(c1x, c1y, c2x, c2y, x, y float32)

BezierTo adds a cubic curve.

func (*GPUCanvas) Clear

func (c *GPUCanvas) Clear(col color.RGBA)

Clear fills the canvas with a color.

func (*GPUCanvas) ClosePath

func (c *GPUCanvas) ClosePath()

ClosePath closes the current path.

func (*GPUCanvas) Dispose

func (c *GPUCanvas) Dispose()

Dispose releases resources.

func (*GPUCanvas) DrawImage

func (c *GPUCanvas) DrawImage(img Texture, x, y float32)

DrawImage draws a texture at the given position.

func (*GPUCanvas) DrawImageScaled

func (c *GPUCanvas) DrawImageScaled(img Texture, x, y, w, h float32)

DrawImageScaled draws a texture scaled to the given size.

func (*GPUCanvas) DrawLine

func (c *GPUCanvas) DrawLine(x1, y1, x2, y2 float32)

DrawLine draws a line.

func (*GPUCanvas) DrawText

func (c *GPUCanvas) DrawText(text string, x, y float32, font *Font)

DrawText draws text using a pixel font.

func (*GPUCanvas) End

func (c *GPUCanvas) End() []byte

End returns the RGBA pixels for the current frame.

func (*GPUCanvas) EndToTexture

func (c *GPUCanvas) EndToTexture() Texture

EndToTexture captures the current frame into a texture.

func (*GPUCanvas) Fill

func (c *GPUCanvas) Fill()

Fill fills the current path.

func (*GPUCanvas) FillCircle

func (c *GPUCanvas) FillCircle(cx, cy, r float32)

FillCircle fills a circle.

func (*GPUCanvas) FillRect

func (c *GPUCanvas) FillRect(x, y, w, h float32)

FillRect fills a rectangle.

func (*GPUCanvas) FillRoundedRect

func (c *GPUCanvas) FillRoundedRect(x, y, w, h, radius float32)

FillRoundedRect fills a rounded rectangle.

func (*GPUCanvas) LineTo

func (c *GPUCanvas) LineTo(x, y float32)

LineTo adds a line segment.

func (*GPUCanvas) MoveTo

func (c *GPUCanvas) MoveTo(x, y float32)

MoveTo moves the current point.

func (*GPUCanvas) PopLayer

func (c *GPUCanvas) PopLayer(effects ...Effect)

PopLayer composites the current layer onto the previous one.

func (*GPUCanvas) PushLayer

func (c *GPUCanvas) PushLayer()

PushLayer starts a new layer.

func (*GPUCanvas) QuadraticTo

func (c *GPUCanvas) QuadraticTo(cx, cy, x, y float32)

QuadraticTo adds a quadratic curve.

func (*GPUCanvas) Resize

func (c *GPUCanvas) Resize(width, height int) error

Resize reallocates the canvas.

func (*GPUCanvas) Restore

func (c *GPUCanvas) Restore()

Restore restores the last transform.

func (*GPUCanvas) Rotate

func (c *GPUCanvas) Rotate(radians float32)

Rotate rotates the current transform.

func (*GPUCanvas) Save

func (c *GPUCanvas) Save()

Save stores the current transform.

func (*GPUCanvas) Scale

func (c *GPUCanvas) Scale(x, y float32)

Scale scales the current transform.

func (*GPUCanvas) SetFillColor

func (c *GPUCanvas) SetFillColor(col color.RGBA)

SetFillColor sets the fill color.

func (*GPUCanvas) SetStrokeColor

func (c *GPUCanvas) SetStrokeColor(col color.RGBA)

SetStrokeColor sets the stroke color.

func (*GPUCanvas) SetStrokeWidth

func (c *GPUCanvas) SetStrokeWidth(w float32)

SetStrokeWidth sets the stroke width.

func (*GPUCanvas) Size

func (c *GPUCanvas) Size() (int, int)

Size returns pixel dimensions.

func (*GPUCanvas) Stroke

func (c *GPUCanvas) Stroke()

Stroke strokes the current path.

func (*GPUCanvas) StrokeCircle

func (c *GPUCanvas) StrokeCircle(cx, cy, r float32)

StrokeCircle draws a circle outline.

func (*GPUCanvas) StrokeRect

func (c *GPUCanvas) StrokeRect(x, y, w, h float32)

StrokeRect draws a rectangle outline.

func (*GPUCanvas) Translate

func (c *GPUCanvas) Translate(x, y float32)

Translate offsets the current transform.

type GlowEffect

type GlowEffect struct {
	Radius    float32
	Intensity float32
	Color     color.RGBA
}

GlowEffect applies a colored glow.

func (GlowEffect) Apply

func (e GlowEffect) Apply(src Texture, dst Framebuffer, driver Driver)

type Matrix3

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

Matrix3 is a 3x3 matrix for 2D transforms.

func Identity

func Identity() Matrix3

Identity returns the identity matrix.

func Rotate

func Rotate(radians float32) Matrix3

Rotate returns a rotation matrix (radians).

func Scale

func Scale(x, y float32) Matrix3

Scale returns a scale matrix.

func Translate

func Translate(x, y float32) Matrix3

Translate returns a translation matrix.

func (Matrix3) Apply

func (m Matrix3) Apply(x, y float32) (float32, float32)

Apply transforms a point.

func (Matrix3) IsIdentity

func (m Matrix3) IsIdentity() bool

IsIdentity reports whether the matrix is the identity.

func (Matrix3) Mul

func (m Matrix3) Mul(o Matrix3) Matrix3

Mul multiplies two matrices.

type PixelFont

type PixelFont struct {
	Width   int
	Height  int
	Spacing int
	Glyphs  map[rune][]string
}

PixelFont represents a bitmap font used for pixel rendering.

func (*PixelFont) Glyph

func (f *PixelFont) Glyph(r rune) []string

Glyph returns the glyph rows for the rune.

type PixelateEffect

type PixelateEffect struct {
	PixelSize float32
}

PixelateEffect reduces resolution.

func (PixelateEffect) Apply

func (e PixelateEffect) Apply(src Texture, dst Framebuffer, driver Driver)

type Shader

type Shader interface {
	ID() uint32
	SetUniform(name string, value any)
	Dispose()
}

Shader represents a compiled shader program.

type ShaderSource

type ShaderSource struct {
	GLSL  GLSLSource
	Metal string
}

ShaderSource contains shader source for multiple backends.

func LoadShaderSource

func LoadShaderSource(name string) (ShaderSource, error)

LoadShaderSource loads embedded shader source by name (e.g. "solid" or "solid.glsl").

type ShadowEffect

type ShadowEffect struct {
	OffsetX float32
	OffsetY float32
	Blur    float32
	Color   color.RGBA
}

ShadowEffect applies a drop shadow.

func (ShadowEffect) Apply

func (e ShadowEffect) Apply(src Texture, dst Framebuffer, driver Driver)

type Texture

type Texture interface {
	ID() uint32
	Size() (w, h int)
	Upload(pixels []byte, region image.Rectangle)
	Dispose()
}

Texture represents a GPU texture resource.

type VertexAttrib

type VertexAttrib struct {
	Index      uint32
	Size       int32
	Type       uint32
	Normalized bool
	Stride     int
	Offset     int
}

VertexAttrib defines a single vertex attribute.

type VertexLayout

type VertexLayout struct {
	Stride     int
	Attributes []VertexAttrib
}

VertexLayout describes vertex attribute layout in bytes.

type VignetteEffect

type VignetteEffect struct {
	Radius   float32
	Softness float32
}

VignetteEffect darkens edges.

func (VignetteEffect) Apply

func (e VignetteEffect) Apply(src Texture, dst Framebuffer, driver Driver)

Directories

Path Synopsis
mtl
opengl
gl

Jump to

Keyboard shortcuts

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