Help us shape the future of Go! Take the 2026 Go Developer Survey

render

package
v0.11.0 Latest Latest
Warning

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

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

Documentation

Overview

Package render defines fluo's abstract 2D drawing surface: the Renderer interface (FillRect/FillRoundedRect/StrokeRoundedRect/DrawShadow/ DrawBackdropBlur/DrawQuad/DrawSDFQuads plus texture management and clip push/pop) and the plain-data geometry types every other package builds on — Point, Size, Rect (with Thickness-based Inset), and Color (0..1 float components, with RGB/RGBA byte-based constructors). It has no dependency on any particular graphics API; render/gl is the OpenGL 3.3 implementation of Renderer that the app package wires up, and core's layout engine, text's glyph drawing, and every controls widget speak only in terms of the types and interface defined here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Color

type Color struct {
	R, G, B, A float32
}

Color represents an RGBA color with components in the range [0, 1].

func RGB

func RGB(r, g, b uint8) Color

RGB creates a color from 8-bit red, green, and blue components with full alpha.

func RGBA

func RGBA(r, g, b, a uint8) Color

RGBA creates a color from 8-bit red, green, blue, and alpha components.

type GlyphQuad

type GlyphQuad struct {
	Dst, Src Rect
}

GlyphQuad represents a glyph quad with destination and source rectangles.

type Point

type Point struct {
	X, Y float32
}

Point represents a 2D point with X and Y coordinates.

type Rect

type Rect struct {
	X, Y, W, H float32
}

Rect represents a rectangle with top-left position and size.

func (Rect) Bottom

func (r Rect) Bottom() float32

Bottom returns the y-coordinate of the bottom edge.

func (Rect) Contains

func (r Rect) Contains(p Point) bool

Contains checks if a point is inside the rectangle (half-open interval [X, Right) × [Y, Bottom)).

func (Rect) Empty

func (r Rect) Empty() bool

Empty checks if the rectangle has zero or negative width or height.

func (Rect) Inflate

func (r Rect) Inflate(d float32) Rect

Inflate returns a new rectangle with all sides grown by the given amount.

func (Rect) Inset

func (r Rect) Inset(t Thickness) Rect

Inset returns a new rectangle inset by the given thickness.

func (Rect) Intersect

func (r Rect) Intersect(o Rect) Rect

Intersect computes the intersection of two rectangles. Returns an empty rectangle (W/H=0) if the rectangles do not overlap.

func (Rect) Right

func (r Rect) Right() float32

Right returns the x-coordinate of the right edge.

type Renderer

type Renderer interface {
	// Begin starts a new frame with the given framebuffer dimensions (in device pixels) and scale factor.
	Begin(fbWidth, fbHeight int, scale float32)

	// End flushes the current frame.
	End()

	// FillRect fills a rectangle with a solid color.
	FillRect(r Rect, c Color)

	// FillRoundedRect fills a rectangle with rounded corners with a solid color.
	FillRoundedRect(r Rect, radius float32, c Color)

	// DrawGradientRect fills r with a linear gradient from `from` to `to`:
	// horizontal (left->right) when horizontal is true, else vertical (top->bottom).
	DrawGradientRect(r Rect, from, to Color, horizontal bool)

	// StrokeRoundedRect draws the stroke of a rectangle with rounded corners (stroke inside edge).
	StrokeRoundedRect(r Rect, radius, width float32, c Color)

	// DrawShadow draws a soft shadow of a rounded rectangle.
	DrawShadow(r Rect, radius, blur float32, c Color)

	// DrawBackdropBlur draws an acrylic/mica-style backdrop-blur surface:
	// it snapshots whatever has already been drawn beneath r, blurs it, and
	// composites the result back into r (rounded by radius) tinted by c —
	// approximating WinUI's acrylic material. Because it samples already-
	// rendered content, callers must invoke it AFTER painting whatever
	// should show through, and BEFORE drawing anything meant to sit on top
	// of the acrylic surface (e.g. its children). An implementation that
	// cannot obtain a true mid-frame snapshot may instead degrade to a
	// flat, tinted, translucent rounded fill (equivalent to
	// FillRoundedRect(r, radius, c)); any such degrade must be prominently
	// documented at the implementation site.
	DrawBackdropBlur(r Rect, radius float32, tint Color)

	// CreateTexture creates a new texture from RGBA8 data.
	// The rgba slice must have length w*h*4; if rgba is non-nil and shorter
	// than that, implementations panic. A nil rgba allocates storage without
	// uploading pixels.
	CreateTexture(w, h int, rgba []byte) TextureID

	// UpdateTexture updates a region of an existing texture.
	// The rgba slice must have length w*h*4; implementations panic if it is
	// shorter (rgba must not be nil here, unlike CreateTexture).
	UpdateTexture(id TextureID, x, y, w, h int, rgba []byte)

	// DeleteTexture frees a texture created by CreateTexture; NoTexture is a
	// no-op.
	DeleteTexture(id TextureID)

	// DrawQuad draws a textured quad with the source rectangle in UV coordinates (0..1) and a tint color.
	DrawQuad(dst, src Rect, tex TextureID, tint Color)

	// DrawSDFQuads draws glyphs from an SDF alpha atlas with the given color.
	// Retained for future scaled/animated text; text.Face.Draw's default
	// (HD) path uses DrawGlyphs instead.
	DrawSDFQuads(quads []GlyphQuad, tex TextureID, c Color)

	// DrawGlyphs draws grayscale-coverage glyph quads from a coverage atlas
	// (alpha = texture.r) tinted with c. Quads' Dst is in logical px (the
	// vertex shader applies uScale); Src is 0..1 atlas UV. Used by
	// text.Face for crisp, direct grayscale-AA UI text. Distinct from
	// DrawSDFQuads (SDF path, retained for future scaled/animated text).
	DrawGlyphs(quads []GlyphQuad, tex TextureID, c Color)

	// Scale returns the current frame's device-pixels-per-logical-pixel
	// factor (as passed to Begin). Valid between Begin and End. The text
	// layer uses it to rasterize glyphs at device resolution and to
	// pixel-snap; no other code should multiply by scale (the vertex
	// shader applies uScale exactly once).
	Scale() float32

	// PushClip pushes a new clip rectangle that intersects with the current clip.
	PushClip(r Rect)

	// PopClip pops the current clip rectangle.
	PopClip()
}

Renderer is the interface for rendering graphics operations.

type Size

type Size struct {
	W, H float32
}

Size represents a 2D size with width and height.

type TextureID

type TextureID uint32

TextureID uniquely identifies a texture, with 0 meaning no texture.

const NoTexture TextureID = 0

NoTexture is a TextureID representing no texture.

type Thickness

type Thickness struct {
	Left, Top, Right, Bottom float32
}

Thickness represents insets on all four sides.

func Uniform

func Uniform(v float32) Thickness

Uniform creates a thickness with the same value on all sides.

Directories

Path Synopsis
gl
Package gl implements render.Renderer on top of OpenGL 3.3 core.
Package gl implements render.Renderer on top of OpenGL 3.3 core.
gltest
Package gltest is a golden-image test harness for OpenGL rendering code.
Package gltest is a golden-image test harness for OpenGL rendering code.

Jump to

Keyboard shortcuts

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