render

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 43 Imported by: 0

Documentation

Overview

Package render wraps the gogpu backend and provides drawing primitives used by game.

Image is CPU texture data. Frame is a per-frame command buffer consumed by the gogpu renderer. The package should draw submitted data without owning Ragnarok map, actor, input, or UI behavior.

Index

Constants

View Source
const (
	CursorModeNormal = 0
	CursorModeHidden = 1
)
View Source
const BackendName = "gogpu-wgpu"

Variables

This section is empty.

Functions

func BitmapTextSize

func BitmapTextSize(text string) (int, int)

func DrawActorUILabels

func DrawActorUILabels(dst *Frame, labels []string, emblem *Image, centerX, y float64, foreground, outline color.RGBA)

func DrawBitmapTextAtColor

func DrawBitmapTextAtColor(dst *Frame, text string, x, y int, c color.RGBA)

func DrawCenteredUIOutlinedTextAt

func DrawCenteredUIOutlinedTextAt(dst *Frame, text string, centerX, y float64, foreground, outline color.RGBA)

func DrawCenteredUITextAt

func DrawCenteredUITextAt(dst *Frame, text string, centerX, y float64, foreground color.RGBA)

func DrawCenteredUITextAtSize added in v0.8.0

func DrawCenteredUITextAtSize(dst *Frame, text string, centerX, y float64, foreground color.RGBA, size float32, bold bool)

func DrawImageBitmapTextAtColor

func DrawImageBitmapTextAtColor(dst *Image, text string, x, y int, c color.RGBA)

func DrawOutlinedTextAt

func DrawOutlinedTextAt(dst *Frame, text string, x, y int, foreground, outline color.RGBA)

func DrawRect

func DrawRect(dst *Frame, x, y, w, h float64, c color.Color)

func DrawUISpeechBubble

func DrawUISpeechBubble(dst *Frame, text string, centerX, bottomY, maxWidth float64)

func DrawUITextAt

func DrawUITextAt(dst *Frame, text string, x, y float64, foreground color.RGBA)

func DrawUITextBanner added in v0.13.0

func DrawUITextBanner(dst *Frame, text string, centerX, y, maxWidth float64, foreground color.RGBA, size float32, bold bool)

DrawUITextBanner wraps and draws text together with its translucent background using the same font metrics, cached at the display's resolution.

func DrawUITooltipBox

func DrawUITooltipBox(dst *Frame, text string, centerX, belowY, aboveY, maxWidth float64, maxLines int, colorCodes bool)

func Run

func Run(game Game, cfg config.WindowConfig, renderCfg config.RenderConfig) error

func RunHeadless added in v0.13.0

func RunHeadless(ctx context.Context, game Game, cfg config.WindowConfig) error

RunHeadless runs the normal frame lifecycle without a window or GPU. Frame records CPU-side commands; the headless renderer discards them.

func SetCursorMode

func SetCursorMode(mode int)

func SetUIFont

func SetUIFont(regular, bold []byte) error

SetUIFont installs the client UI font used for ordinary window text and, when provided, the bold face used by outlined actor names. It is intended for RO clients that ship System/Font/SCDream4.otf and SCDream6.otf.

func SnapScreenPoint

func SnapScreenPoint(dst *Frame, x, y float64) (float64, float64)

func UpscaleTexture2x added in v0.20.0

func UpscaleTexture2x(src image.Image) image.Image

UpscaleTexture2x reconstructs low-resolution texture edges with xBR. Run it during asset loading, before mipmap generation. Textures larger than 1024 on either axis stay unchanged to bound the memory and loading cost on mobile.

Types

type Address

type Address int
const (
	AddressUnsafe Address = iota
	AddressClampToZero
	AddressClampToEdge
	AddressRepeat
)

type Blend

type Blend int
const (
	BlendSourceOver Blend = iota
	BlendLighter
	BlendSrcAlphaDstAlpha
)

type Camera3D

type Camera3D struct {
	Enabled        bool
	ViewProjection [16]float32
	Fog            Fog3D
}

type ColorScale

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

func (*ColorScale) Scale

func (c *ColorScale) Scale(r, g, b, a float32)

func (*ColorScale) ScaleAlpha

func (c *ColorScale) ScaleAlpha(a float32)

type DrawCommand

type DrawCommand struct {
	Vertices []Vertex
	Indices  []uint16
	Texture  *Image
	Options  DrawTrianglesOptions
}

type DrawImageOptions

type DrawImageOptions struct {
	GeoM       GeoM
	ColorScale ColorScale
	Filter     Filter
	Blend      Blend
}

type DrawTrianglesOptions

type DrawTrianglesOptions struct {
	Filter     Filter
	Address    Address
	Blend      Blend
	DepthTest  bool
	DepthWrite bool
	DepthBias  float32
	DisableFog bool
}

type Filter

type Filter int
const (
	FilterNearest Filter = iota
	FilterLinear
	// FilterSprite follows the world sprite smoothing setting on the GPU.
	// CPU image composition uses linear sampling, independent of this setting.
	FilterSprite
)

type Fog3D

type Fog3D struct {
	Enabled  bool
	Near     float32
	Far      float32
	Strength float32
	ColorR   float32
	ColorG   float32
	ColorB   float32
}

type Frame

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

Frame is the per-frame screen target. It owns draw command buffers and frame-only state; Image is only CPU texture data.

func NewFrame

func NewFrame(width, height int) *Frame

func (*Frame) BeginFrame

func (f *Frame) BeginFrame()

func (*Frame) Bounds

func (f *Frame) Bounds() image.Rectangle

func (*Frame) DrawImage

func (f *Frame) DrawImage(src *Image, opts *DrawImageOptions)

func (*Frame) DrawTriangles

func (f *Frame) DrawTriangles(vertices []Vertex, indices []uint16, texture *Image, opts *DrawTrianglesOptions)

func (*Frame) DrawTriangles3D

func (f *Frame) DrawTriangles3D(vertices []Vertex3D, indices []uint16, texture *Image, opts *DrawTrianglesOptions)

func (*Frame) DrawTriangles3DOwned

func (f *Frame) DrawTriangles3DOwned(vertices []Vertex3D, indices []uint16, texture *Image, opts *DrawTrianglesOptions)

func (*Frame) DrawTrianglesOwned

func (f *Frame) DrawTrianglesOwned(vertices []Vertex, indices []uint16, texture *Image, opts *DrawTrianglesOptions)

func (*Frame) DrawWorldBillboard

func (f *Frame) DrawWorldBillboard(cmd WorldBillboardCommand)

func (*Frame) DrawWorldMesh

func (f *Frame) DrawWorldMesh(mesh *WorldMesh)

func (*Frame) Fill

func (f *Frame) Fill(c color.Color)

func (*Frame) PrepareImage added in v0.15.0

func (f *Frame) PrepareImage(img *Image)

PrepareImage uploads a texture with this frame without drawing it. Callers wait for FrameSubmitted before considering the upload complete.

func (*Frame) SetCamera3D

func (f *Frame) SetCamera3D(camera Camera3D)

func (*Frame) SetScreenScale

func (f *Frame) SetScreenScale(x, y float32)

type Game

type Game interface {
	Update() error
	Draw(*Frame)
	Resize(width, height int)
	InputState() *input.State
}

type GeoM

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

func (*GeoM) Rotate

func (g *GeoM) Rotate(theta float64)

func (*GeoM) Scale

func (g *GeoM) Scale(sx, sy float64)

func (*GeoM) Translate

func (g *GeoM) Translate(tx, ty float64)

type Image

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

func NewImage

func NewImage(width, height int) *Image

func NewImageFromImage

func NewImageFromImage(src image.Image) *Image

func NewImageFromStraightAlpha

func NewImageFromStraightAlpha(src image.Image) *Image

func NewImageWithMipmaps added in v0.19.0

func NewImageWithMipmaps(src image.Image) *Image

NewImageWithMipmaps prepares a static texture for minification. Call it while loading assets, before uploading to the GPU. Drawing into it drops the mipmaps.

func OutlinedTextImage

func OutlinedTextImage(text string, foreground, outline color.RGBA) *Image

func WhiteImage

func WhiteImage() *Image

func (*Image) Bounds

func (i *Image) Bounds() image.Rectangle

func (*Image) ByteSize added in v0.19.0

func (i *Image) ByteSize() int

ByteSize includes all pixels that must be uploaded, including mip levels.

func (*Image) DrawImage

func (i *Image) DrawImage(src *Image, opts *DrawImageOptions)

func (*Image) DrawTriangles

func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, texture *Image, opts *DrawTrianglesOptions)

func (*Image) DrawTriangles3D

func (i *Image) DrawTriangles3D(vertices []Vertex3D, indices []uint16, texture *Image, opts *DrawTrianglesOptions)

func (*Image) DrawTriangles3DOwned

func (i *Image) DrawTriangles3DOwned(vertices []Vertex3D, indices []uint16, texture *Image, opts *DrawTrianglesOptions)

func (*Image) DrawTrianglesOwned

func (i *Image) DrawTrianglesOwned(vertices []Vertex, indices []uint16, texture *Image, opts *DrawTrianglesOptions)

func (*Image) Fill

func (i *Image) Fill(c color.Color)

func (*Image) RGBA

func (i *Image) RGBA() *image.RGBA

type ImageGroup added in v0.15.0

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

ImageGroup owns images with a common lifetime, such as a map's textures. Like Image and Frame, it is used on the game/render thread.

func (*ImageGroup) Add added in v0.15.0

func (g *ImageGroup) Add(img *Image) *Image

Add takes ownership of a newly created image. An image belongs to at most one group and must not be used after that group is released.

func (*ImageGroup) Release added in v0.15.0

func (g *ImageGroup) Release()

Release drops CPU pixels immediately. The renderer destroys uploaded textures and their bind groups before its next frame, on the GPU thread.

type UIActorLabelCommand

type UIActorLabelCommand struct {
	Labels     []string
	Emblem     *Image
	CenterX    float64
	Y          float64
	Foreground color.RGBA
	Outline    color.RGBA
	Size       float32
}

type UITextBoxAnchor

type UITextBoxAnchor int
const (
	UITextBoxAnchorTopLeft UITextBoxAnchor = iota
	UITextBoxAnchorBottomCenter
	UITextBoxAnchorTooltipCenter
	UITextBoxAnchorTopCenter
)

type UITextBoxCommand

type UITextBoxCommand struct {
	Text     string
	X        float64
	Y        float64
	AltY     float64
	Anchor   UITextBoxAnchor
	MaxWidth float64
	MaxLines int
	// contains filtered or unexported fields
}

type UITextLabelCommand

type UITextLabelCommand struct {
	Text       string
	X          float64
	Y          float64
	Foreground color.RGBA
	Outline    color.RGBA
	Centered   bool
	Bold       bool
	Size       float32
}

type Vertex

type Vertex struct {
	DstX, DstY     float32
	SrcX, SrcY     float32
	ColorR, ColorG float32
	ColorB, ColorA float32
}

type Vertex3D

type Vertex3D struct {
	X, Y, Z                float32
	SrcX, SrcY             float32
	ColorR, ColorG         float32
	ColorB, ColorA         float32
	DepthX, DepthY, DepthZ float32
	LightSrcX, LightSrcY   float32
}

type WorldBillboardCommand

type WorldBillboardCommand struct {
	Texture     *Image
	Options     DrawTrianglesOptions
	Center      [3]float32
	RightAxis   [3]float32
	UpAxis      [3]float32
	DepthUpAxis [3]float32
	Width       float32
	Height      float32
	AnchorX     float32
	AnchorY     float32
	ColorR      float32
	ColorG      float32
	ColorB      float32
	ColorA      float32
	DepthBias   float32
}

type WorldCommand

type WorldCommand struct {
	Vertices     []Vertex3D
	Indices      []uint16
	Texture      *Image
	LightTexture *Image
	Options      DrawTrianglesOptions
}

type WorldMesh

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

func NewWorldMeshWithLightmap

func NewWorldMeshWithLightmap(vertices []Vertex3D, indices []uint16, texture, lightTexture *Image, opts *DrawTrianglesOptions) *WorldMesh

func (*WorldMesh) IndexCount

func (m *WorldMesh) IndexCount() int

func (*WorldMesh) VertexCount

func (m *WorldMesh) VertexCount() int

type WorldMeshCommand

type WorldMeshCommand struct {
	Mesh *WorldMesh
}

Jump to

Keyboard shortcuts

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