{"modulePath":"github.com/weakpixel/engine","version":"v0.0.0-20261205071607-94fff0387040","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package render\n\nPackage render draws a queue of plain draw items with Ebiten. It does not import ecs: extract systems (package extract) fill the Queue during Update and the Renderer reads it in Draw, so Draw never touches the World.\n\nThe package also holds the Ebiten asset types ([Texture](#Texture), [Sprite](#Sprite), [Atlas](#Atlas), [FontSource](#FontSource), [Font](#Font), [Shader](#Shader)) and their loaders for package asset: [RegisterLoaders](#RegisterLoaders) registers them on an asset.Server. Loaders create every Ebiten object in Finish on the game goroutine; Decode is CPU work only. Items hold handles to these assets and the Renderer resolves them through [Stores](#Stores) in Draw, so a missing, loading or failed asset draws its placeholder instead of failing.\n\nPanics raised by this package are programmer errors and start with \"render: \".\n\n## Constants\n\n```go\nconst (\n\t// AssetKindSprite is a [Sprite]: a whole image or an atlas frame.\n\tAssetKindSprite = \"sprite\"\n\t// AssetKindFont is a [Font] (\"fonts/ui.ttf#16\").\n\tAssetKindFont = \"font\"\n\t// AssetKindShader is a [Shader] (a *.kage file).\n\tAssetKindShader = \"shader\"\n)\n```\nAsset kinds of this package: the names a component field carries in its +game:asset:kind=... marker.\n\n```go\nconst ShaderUniformParams = \"Params\"\n```\nShaderUniformParams is the name of the uniform that carries an item's Params. Declare it as\n\n\tvar Params vec4\n\nto read [Item.Params](#Item.Params) (gfx.Sprite.Params). A shader that does not declare it gets nothing; Ebiten ignores uniforms a shader does not declare.\n\n```go\nconst ShaderUniformTime = \"Time\"\n```\nShaderUniformTime is the name of the uniform that carries the time of the frame in seconds, as set with [Renderer.SetTime](#Renderer.SetTime). Declare it as\n\n\tvar Time float\n\nEvery shader the Renderer runs (sprites, layer groups, post passes and the final pass) gets the same value during one frame.\n\n## Functions\n\n```go\nfunc HoldAtlas(sc *asset.Scope, h AtlasHandle)\n```\nHoldAtlas adds sc as an owner of h, like [asset.Hold](/github.com/weakpixel/asset#Hold).\n\n```go\nfunc HoldFont(sc *asset.Scope, h gfx.FontHandle)\n```\nHoldFont adds sc as an owner of h, like [asset.Hold](/github.com/weakpixel/asset#Hold).\n\n```go\nfunc HoldShader(sc *asset.Scope, h gfx.ShaderHandle)\n```\nHoldShader adds sc as an owner of h, like [asset.Hold](/github.com/weakpixel/asset#Hold).\n\n```go\nfunc HoldSprite(sc *asset.Scope, h gfx.SpriteHandle)\n```\nHoldSprite adds sc as an owner of h, like [asset.Hold](/github.com/weakpixel/asset#Hold).\n\n```go\nfunc LoadFont(sc *asset.Scope, key string) gfx.FontHandle\n```\nLoadFont returns the handle for a font key (\"fonts/ui.ttf#16\") and adds a hold for sc. It never blocks and panics like [asset.Load](/github.com/weakpixel/asset#Load).\n\n```go\nfunc LoadFontSync(sc *asset.Scope, key string) (gfx.FontHandle, error)\n```\nLoadFontSync is LoadFont followed by loading until the font is ready or failed, like [asset.LoadSync](/github.com/weakpixel/asset#LoadSync). It blocks.\n\n```go\nfunc LoadShader(sc *asset.Scope, key string) gfx.ShaderHandle\n```\nLoadShader returns the handle for a shader key (\"fx/flash.kage\") and adds a hold for sc. It never blocks and panics like [asset.Load](/github.com/weakpixel/asset#Load).\n\n```go\nfunc LoadShaderSync(sc *asset.Scope, key string) (gfx.ShaderHandle, error)\n```\nLoadShaderSync is LoadShader followed by loading until the shader is ready or failed, like [asset.LoadSync](/github.com/weakpixel/asset#LoadSync). It blocks.\n\n```go\nfunc LoadSprite(sc *asset.Scope, key string) gfx.SpriteHandle\n```\nLoadSprite returns the handle for a sprite key (\"ui/cursor.png\" or \"chars/hero.atlas.json#idle\\_0\") and adds a hold for sc. It never blocks and panics like [asset.Load](/github.com/weakpixel/asset#Load).\n\n```go\nfunc LoadSpriteSync(sc *asset.Scope, key string) (gfx.SpriteHandle, error)\n```\nLoadSpriteSync is LoadSprite followed by loading until the sprite is ready or failed, like [asset.LoadSync](/github.com/weakpixel/asset#LoadSync). It blocks: use it for boot screens, tests and tools.\n\n```go\nfunc RegisterLoaders(srv *asset.Server, opts LoaderOptions)\n```\nRegisterLoaders registers every render asset type and its loader on srv: [Texture](#Texture), [Sprite](#Sprite) (whole images and atlas frames), [Atlas](#Atlas), [FontSource](#FontSource) and [Font](#Font) and [Shader](#Shader). It creates the placeholder images, so it must run on the game goroutine, and it panics like [asset.Register](/github.com/weakpixel/asset#Register) if a type is already registered.\n\n## Types\n\n```go\ntype Atlas struct {\n\t// Texture is the page the frames are cut from.\n\tTexture TextureID\n\t// Sprites maps frame name to sprite. Read it at load or spawn time, not\n\t// per frame.\n\tSprites map[string]gfx.SpriteHandle\n\t// Order lists the sprites in file order, for index-based frame access.\n\tOrder []gfx.SpriteHandle\n}\n```\nAtlas is a texture cut into named sprites. Load it with [LoadAtlas](#LoadAtlas); its frames are also loadable on their own with [LoadSprite](#LoadSprite) and a \"#name\" key (\"chars/hero.atlas.json#idle\\_0\"), which loads the atlas too.\n\nFrames are children of the atlas: they are unloaded with it, and a held frame keeps the atlas (and so its texture) alive.\n\nFormats, chosen by file name:\n\n\t*.sheet.json  grid sheet: {\"image\", \"frameW\", \"frameH\", \"margin\", \"spacing\"};\n\t              optional \"pivot\": {\"x\", \"y\"}; frames are named \"0\", \"1\", ...\n\t              left to right, top to bottom\n\t*.tsj         single-image Tiled tileset: cut by tilewidth/tileheight,\n\t              margin, spacing and columns into tilecount frames named by\n\t              local tile ID (\"0\", \"1\", ...), see atlas-tiled.go\n\t*.json        TexturePacker JSON (hash or array), see atlas-texturepacker.go\n\n\"image\" is a path relative to the JSON file's directory.\n\n```go\ntype AtlasHandle struct{ asset.Ref }\n```\nAtlasHandle refers to an [Atlas](#Atlas). It is 8 bytes, comparable and pointer-free; the zero value means \"none\". No component holds one (sprites hold the frames' gfx.SpriteHandle), so it lives here rather than in gfx.\n\n```go\nfunc LoadAtlas(sc *asset.Scope, key string) AtlasHandle\n```\nLoadAtlas returns the handle for an atlas key (\"chars/hero.sheet.json\") and adds a hold for sc. It never blocks and panics like [asset.Load](/github.com/weakpixel/asset#Load).\n\n```go\nfunc LoadAtlasSync(sc *asset.Scope, key string) (AtlasHandle, error)\n```\nLoadAtlasSync is LoadAtlas followed by loading until the atlas is ready or failed, like [asset.LoadSync](/github.com/weakpixel/asset#LoadSync). It blocks.\n\n```go\ntype AtlasStore struct {\n\t// contains filtered or unexported fields\n}\n```\nAtlasStore resolves [AtlasHandle](#AtlasHandle) values to atlases. Get one with [AtlasStoreOf](#AtlasStoreOf). It is a small value; copy it freely.\n\n```go\nfunc AtlasStoreOf(srv *asset.Server) AtlasStore\n```\nAtlasStoreOf returns the atlas store of srv. It panics like [asset.StoreOf](/github.com/weakpixel/asset#StoreOf) if [RegisterLoaders](#RegisterLoaders) has not run on srv.\n\n```go\nfunc (s AtlasStore) Err(h AtlasHandle) error\n```\nErr returns why the atlas failed to load, or nil.\n\n```go\nfunc (s AtlasStore) Generic() *asset.Store[Atlas]\n```\nGeneric returns the underlying generic store, for loaders and tools that work with asset.Handle\\[Atlas].\n\n```go\nfunc (s AtlasStore) Get(h AtlasHandle) *Atlas\n```\nGet returns the atlas, or the placeholder (an empty atlas); see [asset.Store.Get](/github.com/weakpixel/asset#Store.Get). It does not allocate.\n\n```go\nfunc (s AtlasStore) Key(h AtlasHandle) asset.Key\n```\nKey returns the key h was loaded from, or the zero Key for a zero or stale handle.\n\n```go\nfunc (s AtlasStore) Lookup(h AtlasHandle) (*Atlas, asset.State)\n```\nLookup is Get plus the load state; see [asset.Store.Lookup](/github.com/weakpixel/asset#Store.Lookup).\n\n```go\nfunc (s AtlasStore) Ready(h AtlasHandle) bool\n```\nReady reports whether h refers to a loaded atlas.\n\n```go\ntype Blend uint8\n```\nBlend selects how an Item is composited onto what is below it.\n\n```go\nconst (\n\tBlendNormal Blend = iota\n\tBlendAdditive\n\t// BlendMultiply multiplies what is below by the source color: white\n\t// keeps it, black darkens it to black. Composite a light map group with\n\t// it.\n\tBlendMultiply\n\t// BlendScreen brightens like BlendAdditive but never exceeds white\n\t// (src + dst*(1-src)): soft glows, light shafts, flashes.\n\tBlendScreen\n\t// BlendSubtract subtracts the source color from what is below\n\t// (dst - src, alpha unchanged): darkening tints, negative light.\n\tBlendSubtract\n\t// BlendLighten keeps the brighter of source and destination per channel\n\t// (max): overlapping glows that do not add up.\n\tBlendLighten\n\t// BlendErase removes what is below by the source's alpha\n\t// (dst*(1-srcAlpha)). Use it for items inside a layer group, where it\n\t// cuts holes (fog of war, flashlight masks); on the screen it erases to\n\t// the window background.\n\tBlendErase\n)\n```\nBlend modes.\n\n```go\ntype Bloom struct {\n\t// contains filtered or unexported fields\n}\n```\nBloom is the handle [PostChain.AddBloom](#PostChain.AddBloom) returns, to retune or switch off the effect it added.\n\n```go\nfunc (b Bloom) Set(p *PostChain, opts BloomOptions)\n```\nSet changes the options of the bloom; zero fields take their defaults.\n\n```go\nfunc (b Bloom) SetOff(p *PostChain, off bool)\n```\nSetOff switches all passes of the bloom off or on.\n\n```go\ntype BloomOptions struct {\n\t// Threshold is the brightness (the largest of red, green and blue, 0..1)\n\t// above which a pixel glows; only the part above it does. Default 0.7.\n\tThreshold float32\n\t// Strength scales the glow that is added to the frame. Default 1.\n\tStrength float32\n\t// Radius is the distance between the taps of the blur, in pixels of the\n\t// quarter-size image: 1 blurs over about 8 frame pixels each way. Default\n\t// 1.\n\tRadius float32\n\t// Src is the image whose bright parts glow. The zero value,\n\t// [TargetChain], is the chain so far: the whole frame. [TargetGroup]\n\t// makes only the layers of one layer group glow (neon signs, magic,\n\t// lasers) while equally bright sprites elsewhere do not; the glow is\n\t// still added to the chain. Any target a pass may read works.\n\tSrc TargetID\n}\n```\nBloomOptions tunes [PostChain.AddBloom](#PostChain.AddBloom). A zero field takes its default, so the zero value is a usable bloom.\n\n```go\ntype Camera struct {\n\t// Pos is the world position at the viewport center for the current\n\t// tick.\n\tPos gfx.Vec2\n\t// Prev is the view (position, zoom, rotation) at the previous tick,\n\t// which Draw blends to the current one (see At). The engine records it\n\t// at the start of every tick (Snapshot). The zero Prev means \"no\n\t// previous view\": frames show the current view, as after Jump.\n\tPrev CameraPose\n\t// Zoom is the scale from world units to pixels. Zero means 1.\n\tZoom float32\n\t// Rotation rotates the view, in radians, clockwise on screen.\n\tRotation float32\n\t// Viewport is the screen region the camera draws into. The zero\n\t// rectangle means the whole screen.\n\tViewport image.Rectangle\n\t// PixelSnap rounds the camera position so that the world sits on whole\n\t// logical pixels: viewport center - Pos*Zoom becomes an integer, which\n\t// moves the view by at most half a pixel per axis. The Renderer rounds\n\t// once per frame, after blending the previous view, and WorldToScreen,\n\t// ScreenToWorld and WorldBounds round the same way, so picking and\n\t// culling match the drawn pixels.\n\t//\n\t// Use it for pixel art. Without it, a camera at a sub-pixel position\n\t// under a non-integer Zoom changes, from frame to frame, which texels of\n\t// a sprite are drawn one pixel wide and which two, and the art shimmers\n\t// while the camera moves. It is ignored while Rotation is not 0.\n\tPixelSnap bool\n}\n```\nCamera is a plain value: a CameraSystem writes it during Update and the Renderer reads a copy in Draw. Pos is the world point shown at the center of the viewport.\n\nAll methods take the logical screen size in pixels (the size passed to Ebiten's Layout), because the camera itself does not know it.\n\n```go\nfunc (c Camera) At(alpha float32) Camera\n```\nAt returns a copy whose view is blended from Prev to the current one by alpha in \\[0,1], for drawing between ticks: position and zoom linearly, rotation along the shorter arc. The copy has no Prev.\n\n```go\nfunc (c *Camera) DrawBounds(screen image.Point) gfx.Rect\n```\nDrawBounds returns the world rectangle that frames drawn during the current tick can show, for culling in extract systems: the union of WorldBounds at the previous view and at the current one. The Renderer blends the view between the two, so culling against the current view alone could drop a sliver at the trailing screen edge while the camera moves or zooms. PixelSnap needs no extra margin: rounding is monotonic, so the rounded blended view lies between the rounded end views, which WorldBounds already returns. A blended rotation can show slightly more than both end views; the bounds of a rotated view are already larger than the view, which covers it for the small turns of one tick.\n\n```go\nfunc (c *Camera) Jump()\n```\nJump clears Prev, so the frames of the rest of the tick show the current view instead of sweeping from the old one: for cuts, snaps and editor camera moves.\n\n```go\nfunc (c *Camera) PrevPose() CameraPose\n```\nPrevPose returns the view at the start of the tick: Prev when it is set, else the current view. The result has Set true.\n\n```go\nfunc (c *Camera) ScreenToWorld(p gfx.Vec2, screen image.Point) gfx.Vec2\n```\nScreenToWorld converts logical screen pixels to a world position, for mouse picking and aiming. It is the inverse of WorldToScreen, PixelSnap included.\n\n```go\nfunc (c *Camera) Snapshot()\n```\nSnapshot records the current view in Prev. game.Engine calls it at the start of every tick; a schedule without the engine calls it in its first stage, before anything moves the camera.\n\n```go\nfunc (c *Camera) ViewportRect(screen image.Point) image.Rectangle\n```\nViewportRect returns the pixel region the camera draws into, given the screen size.\n\n```go\nfunc (c *Camera) WorldBounds(screen image.Point) gfx.Rect\n```\nWorldBounds returns the axis-aligned world rectangle that contains everything the camera can see, for culling. With a rotation it is larger than the view (it bounds the rotated rectangle). With PixelSnap it is the rounded view's rectangle.\n\n```go\nfunc (c *Camera) WorldToScreen(p gfx.Vec2, screen image.Point) gfx.Vec2\n```\nWorldToScreen converts a world position to logical screen pixels. With PixelSnap it uses the rounded position, as the Renderer draws.\n\n```go\ntype CameraPose struct {\n\tPos gfx.Vec2\n\t// Zoom and Rotation are as in Camera (a zero Zoom means 1).\n\tZoom, Rotation float32\n\t// Set reports whether the pose was recorded.\n\tSet bool\n}\n```\nCameraPose is a camera's view at one tick. The zero CameraPose (Set false) means \"none\".\n\n```go\ntype CanvasID struct {\n\t// contains filtered or unexported fields\n}\n```\nCanvasID refers to a canvas of a [Canvases](#Canvases). It is 8 bytes, comparable and pointer-free, so it can live in draw items and components; the zero value means \"none\". Freeing a canvas makes its IDs stale.\n\n```go\nfunc (id CanvasID) IsZero() bool\n```\nIsZero reports whether id is the zero CanvasID.\n\n```go\ntype Canvases struct {\n\t// contains filtered or unexported fields\n}\n```\nCanvases owns offscreen images that code outside this package fills by painting a [Queue](#Queue) into them, and then draws with [KindCanvas](#KindCanvas) items. It is how a system pre-renders something that does not change every frame (the static tiles of a map chunk) into one image, so later frames queue one item instead of hundreds.\n\nCreate it once with [NewCanvases](#NewCanvases), publish it as a World resource and give it to the Renderer with [Renderer.SetCanvases](#Renderer.SetCanvases). Like the Queue, it is used on the game goroutine only: Ebiten allows drawing into offscreen images in Update as well as in Draw.\n\n```go\nfunc NewCanvases(st Stores) *Canvases\n```\nNewCanvases returns an empty set of canvases whose Paint resolves sprite and font handles through st. It allocates no Ebiten image.\n\n```go\nfunc (c *Canvases) Bytes() int64\n```\nBytes returns the GPU memory estimate (4 bytes per pixel) of the canvases that are not freed, not counting the spare images kept for reuse.\n\n```go\nfunc (c *Canvases) Free(id CanvasID)\n```\nFree releases canvas id: its image is kept for reuse by New or deallocated, and id and its copies become stale. Freeing the zero or a stale ID does nothing.\n\n```go\nfunc (c *Canvases) Len() int\n```\nLen returns the number of canvases that are not freed.\n\n```go\nfunc (c *Canvases) New(w, h int) CanvasID\n```\nNew returns a transparent w x h canvas. It reuses the image of a freed canvas of the same size when one is kept, and allocates one otherwise.\n\nPanics with \"render: canvas size\" when w or h is not positive.\n\n```go\nfunc (c *Canvases) Paint(id CanvasID, q *Queue)\n```\nPaint clears canvas id and draws q into it, in q's order (Paint does not sort it). Items are drawn as by [Renderer.Draw](#Renderer.Draw) with an identity camera, so world and screen space are both canvas pixels, (0, 0) being the canvas's top-left corner; interpolation is off (Pos is used). Sprites that are not ready draw their placeholder, so paint once they are ready. Paint draws right away; it allocates nothing once its painter exists and its buffers have grown.\n\nPanics with \"render: stale canvas\" when id is zero or stale.\n\n```go\nfunc (c *Canvases) Size(id CanvasID) image.Point\n```\nSize returns the size of canvas id in pixels, or the zero Point for the zero or a stale ID.\n\n```go\ntype Font struct {\n\t// Face draws and measures text. It is a *text.GoTextFace.\n\tFace text.Face\n\t// LineHeight is the distance between two baselines, in pixels.\n\tLineHeight float64\n}\n```\nFont is a face of a [FontSource](#FontSource) at one size. The key carries the size in pixels after '#': [LoadFont](#LoadFont)(sc, \"fonts/ui.ttf#16\").\n\nA Font is cheap: it depends on the FontSource of the same file, so every size of a font parses the file once. (It is a dependent asset and not an asset child, because a FontSource cannot know which sizes will be asked for.)\n\n```go\ntype FontSource struct {\n\tSource *text.GoTextFaceSource\n}\n```\nFontSource is a parsed TTF or OTF file, shared by every size of that font. Load it with asset.Load\\[FontSource]; you usually load a [Font](#Font) instead.\n\n```go\ntype FontSourceID = asset.Handle[FontSource]\n```\nFontSourceID is a handle to a [FontSource](#FontSource).\n\n```go\ntype FontStore struct {\n\t// contains filtered or unexported fields\n}\n```\nFontStore resolves [gfx.FontHandle](/github.com/weakpixel/engine/gfx#FontHandle) values to fonts. Get one from [StoresOf](#StoresOf) or [FontStoreOf](#FontStoreOf). It is a small value; copy it freely.\n\n```go\nfunc FontStoreOf(srv *asset.Server) FontStore\n```\nFontStoreOf returns the font store of srv. It panics like [asset.StoreOf](/github.com/weakpixel/asset#StoreOf) if [RegisterLoaders](#RegisterLoaders) has not run on srv.\n\n```go\nfunc (s FontStore) Err(h gfx.FontHandle) error\n```\nErr returns why the font failed to load, or nil.\n\n```go\nfunc (s FontStore) Generic() *asset.Store[Font]\n```\nGeneric returns the underlying generic store, for loaders and tools that work with asset.Handle\\[Font].\n\n```go\nfunc (s FontStore) Get(h gfx.FontHandle) *Font\n```\nGet returns the font, or the placeholder; see [asset.Store.Get](/github.com/weakpixel/asset#Store.Get). It does not allocate.\n\n```go\nfunc (s FontStore) Key(h gfx.FontHandle) asset.Key\n```\nKey returns the key h was loaded from, or the zero Key for a zero or stale handle.\n\n```go\nfunc (s FontStore) Lookup(h gfx.FontHandle) (*Font, asset.State)\n```\nLookup is Get plus the load state; see [asset.Store.Lookup](/github.com/weakpixel/asset#Store.Lookup).\n\n```go\nfunc (s FontStore) Ready(h gfx.FontHandle) bool\n```\nReady reports whether h refers to a loaded font.\n\n```go\ntype GroupConfig struct {\n\t// contains filtered or unexported fields\n}\n```\nGroupConfig holds the layer groups of a Renderer (see [Renderer.SetGroups](#Renderer.SetGroups)). The zero value has no groups and is ready to use. Add groups before the first frame; Set may change a group's options at any time between frames, for example to animate Params.\n\n```go\nfunc (c *GroupConfig) Add(opts GroupOptions) GroupID\n```\nAdd adds a group and returns its ID.\n\nPanics with \"render: group From \u003e To\" for an empty range and with \"render: group layers overlap\" when the range shares a layer with another group.\n\n```go\nfunc (c *GroupConfig) Len() int\n```\nLen returns the number of groups.\n\n```go\nfunc (c *GroupConfig) Options(id GroupID) GroupOptions\n```\nOptions returns the options of group id. Panics with \"render: unknown group\" for an id that Add did not return.\n\n```go\nfunc (c *GroupConfig) Set(id GroupID, opts GroupOptions)\n```\nSet replaces the options of group id. Changing only Params, Shader, Blend or Clear does not allocate.\n\nPanics like [GroupConfig.Add](#GroupConfig.Add), and with \"render: unknown group\" for an id that Add did not return.\n\n```go\ntype GroupID int\n```\nGroupID identifies a layer group of a [GroupConfig](#GroupConfig). It is the index returned by [GroupConfig.Add](#GroupConfig.Add).\n\n```go\ntype GroupOptions struct {\n\t// From and To are the first and last render layer of the group,\n\t// inclusive. A one-layer group has From == To.\n\tFrom, To int16\n\t// Shader composites the group image. The zero handle, and a shader that\n\t// is loading or failed, composite it unchanged. The shader gets the\n\t// group image as imageSrc0 (logical screen size, src in pixels),\n\t// Params as its \"Params\" vec4 uniform and, with SampleBelow, a copy of\n\t// what was drawn below the group as imageSrc1.\n\tShader gfx.ShaderHandle\n\t// Params are passed to Shader as its \"Params\" vec4 uniform.\n\tParams [4]float32\n\t// Blend composites the group image onto what is below:\n\t// BlendNormal, BlendAdditive or BlendMultiply (light maps).\n\tBlend Blend\n\t// Clear is what the group image is cleared to every frame. The zero\n\t// value is transparent. A light map clears to the ambient light color.\n\t// A group whose Clear is not transparent is composited even when no\n\t// item falls into it, so the ambient light still applies.\n\tClear color.RGBA\n\t// SampleBelow copies what is on the screen below the group, before the\n\t// group is composited, and passes the copy to Shader as imageSrc1 (for\n\t// refraction or water that distorts the scene behind it). It costs one\n\t// screen-sized copy per frame. Ignored without a shader.\n\tSampleBelow bool\n\t// NoComposite draws the group's layers into its image and never\n\t// composites it onto the scene, not even an empty group with a visible\n\t// Clear. The image is only seen by post passes that read it with\n\t// [TargetGroup] (masks, displacement maps, light maps to blur first).\n\t// Shader, Params, Blend and SampleBelow are ignored, and the group does\n\t// not count in [Stats].Groups. Without a pass that reads it the group\n\t// is drawn for nothing.\n\tNoComposite bool\n}\n```\nGroupOptions configures a layer group: the render layers From..To (inclusive) are drawn into an offscreen image instead of the screen, and that image is then composited onto what is below it, through Shader if one is set. A group is how a shader applies to a whole layer (water distortion, fog, a light map) instead of to one sprite.\n\n```go\ntype Item struct {\n\tKind  Kind\n\tSpace Space\n\t// Layer is the draw order: lower layers draw first.\n\tLayer int16\n\t// SortY orders items inside a layer configured with YSort.\n\tSortY float32\n\t// Insets are the borders of a KindNineSlice item in source pixels. They\n\t// sit here, next to the small fields, to keep Item from growing by\n\t// padding. For this kind Origin is the pivot as a fraction of Size, the\n\t// zero Origin being the top-left corner.\n\tInsets gfx.Insets\n\n\t// Sprite is the image for KindSprite. The zero handle draws the\n\t// placeholder.\n\tSprite gfx.SpriteHandle\n\t// Pos is the position at the current tick. For ScreenSpace items it is\n\t// in logical screen pixels.\n\tPos gfx.Vec2\n\t// PrevPos is the position at the previous tick, used when HasPrev is\n\t// set: the Renderer blends it to Pos by the draw alpha. Rotation and\n\t// scale do not blend; they keep the item small for the copy loops of\n\t// extract and sort.\n\tPrevPos gfx.Vec2\n\t// Rot is the rotation in radians.\n\tRot float32\n\t// Scale multiplies the size. Extract resolves the \"zero means 1\" rule,\n\t// so the Renderer treats a zero Scale as zero.\n\tScale gfx.Vec2\n\t// Origin is the pivot as a fraction of the sprite size. The zero Origin\n\t// means the sprite's own default pivot.\n\tOrigin       gfx.Vec2\n\tFlipX, FlipY bool\n\t// Tile repeats the edges and center of a KindNineSlice item instead of\n\t// stretching them.\n\tTile bool\n\t// HasPrev reports whether PrevPos is set. Without it the item is drawn\n\t// at Pos for every alpha, as static items should be; see\n\t// [Item.MovedFrom]. It sits in padding, so it costs no size.\n\tHasPrev bool\n\n\t// Size is the rect size, the line end offset, in X the circle radius, or\n\t// the size of a KindNineSlice panel (zero is the image's own size).\n\tSize gfx.Vec2\n\n\t// Color tints sprites and colors shapes and text. The zero Color is\n\t// white (see gfx.Color).\n\tColor gfx.Color\n\tBlend Blend\n\n\t// Shader draws the item through a Kage shader instead of the default\n\t// pipeline. The zero handle, and a shader that is loading or failed,\n\t// draw the item normally. The shader gets the item's image as\n\t// imageSrc0, Color (premultiplied) as the color argument of Fragment,\n\t// and Params as the \"Params\" vec4 uniform (see [ShaderUniformParams]).\n\t//\n\t// For KindSprite and KindCanvas the image is the sprite's frame or the\n\t// canvas. A KindText, KindNineSlice, KindRect, KindLine or KindCircle\n\t// item is first drawn white, at scale 1 and unrotated, into an\n\t// offscreen image with a transparent margin of 4 pixels; the shader\n\t// gets that image, so it sees the whole text, panel or shape. Each such\n\t// item is a draw call of its own.\n\tShader gfx.ShaderHandle\n\t// Params are per-item shader parameters (a flash amount, an outline\n\t// color, a dissolve threshold): what they mean is up to the shader.\n\tParams [4]float32\n\t// Aux is a second image for Shader (a noise texture, a mask, a\n\t// palette), which the shader reads as imageSrc1; without Shader it is\n\t// ignored. It may have any size and may be an atlas frame. The zero\n\t// handle, and a sprite that is loading or failed, give no image:\n\t// imageSrc1At returns transparent pixels, never the placeholder. Items\n\t// with different Aux images are different batches.\n\tAux gfx.SpriteHandle\n\n\t// Canvas is the image of a KindCanvas item. Origin is the pivot as a\n\t// fraction of the canvas size, the zero Origin being the top-left\n\t// corner; Shader draws it through a shader like a sprite. A zero or stale ID, or a Renderer without\n\t// canvases (see [Renderer.SetCanvases]), draws nothing.\n\tCanvas CanvasID\n\n\t// Text and Font are used by KindText. The queue lives for one tick, so\n\t// holding a string here is fine.\n\tText string\n\tFont gfx.FontHandle\n}\n```\nItem is one draw command: a plain value written by extract systems and read by the Renderer. Fields that a Kind does not use are ignored.\n\n```go\nfunc (it *Item) MovedFrom(p gfx.Vec2)\n```\nMovedFrom sets the position at the previous tick: the Renderer blends p to Pos.\n\n```go\ntype Kind uint8\n```\nKind selects how an Item is drawn.\n\n```go\nconst (\n\tKindSprite Kind = iota\n\tKindRect\n\tKindLine\n\tKindCircle\n\tKindText\n\t// KindCanvas draws Item.Canvas, an image pre-rendered with\n\t// [Canvases.Paint].\n\tKindCanvas\n\t// KindNineSlice draws Item.Sprite as a nine-slice panel of Item.Size,\n\t// cut by Item.Insets (see gfx.NineSlice).\n\tKindNineSlice\n)\n```\nKinds.\n\n```go\ntype LayerConfig struct {\n\t// contains filtered or unexported fields\n}\n```\nLayerConfig holds per-layer options. The zero value is ready to use and means \"no layer is Y-sorted\". It is read while sorting, so configure it before the first tick rather than during one.\n\n```go\nfunc (c *LayerConfig) Options(layer int16) LayerOptions\n```\nOptions returns the options of layer.\n\n```go\nfunc (c *LayerConfig) Set(layer int16, opts LayerOptions)\n```\nSet applies opts to layer.\n\n```go\ntype LayerOptions struct {\n\t// YSort orders items of the layer by Item.SortY (top-down games: things\n\t// lower on the screen draw in front).\n\tYSort bool\n}\n```\nLayerOptions configures how one layer is sorted.\n\n```go\ntype Layout struct {\n\t// Width and Height are the logical resolution in pixels.\n\tWidth, Height int\n\t// Integer makes the image scale by a whole number (pixel-perfect\n\t// pixel art): the logical size grows to fill the window at the largest\n\t// integer scale that still fits Width x Height.\n\tInteger bool\n}\n```\nLayout computes the logical screen size to return from Ebiten's Layout method.\n\n```go\nfunc (l Layout) Size(outsideW, outsideH int) (w, h int)\n```\nSize returns the logical size for a window of outsideW x outsideH. Pass the result to the Screen resource so extract systems cull against it.\n\n```go\ntype LoaderOptions struct {\n\t// TransparentPlaceholders makes missing, loading and failed assets draw\n\t// nothing (a transparent 1x1 image) instead of the magenta checker. Use it\n\t// in release builds; keep the checker in development so gaps are visible.\n\tTransparentPlaceholders bool\n}\n```\nLoaderOptions configures [RegisterLoaders](#RegisterLoaders).\n\n```go\ntype Pass struct {\n\t// Shader runs once per pixel of Out. It gets Src as imageSrc0, the\n\t// Extra images as imageSrc1 to imageSrc3 and Params as its \"Params\" vec4\n\t// uniform. The zero handle, and a shader that is loading or failed, skip\n\t// the pass.\n\t//\n\t// The shader's src is in Src's pixels: the pass draws one quad over Out,\n\t// with source coordinates spanning all of Src, so a pass that writes a\n\t// smaller image than it reads runs once per small pixel and sees src at\n\t// the center of the block of Src pixels it covers. To read an input of\n\t// another size, map src by the sizes and add imageSrc0Origin(), because\n\t// Kage takes the position of imageSrcNAt in imageSrc0's texture:\n\t// imageSrc1At(imageSrc0Origin() +\n\t// (src-imageSrc0Origin())/imageSrc0Size()*imageSrc1Size()).\n\tShader gfx.ShaderHandle\n\t// Params are passed to Shader as its \"Params\" vec4 uniform.\n\tParams [4]float32\n\t// Off skips the pass (a settings toggle) without removing it.\n\tOff bool\n\n\t// Src is the image the shader reads as imageSrc0: the chain so far\n\t// (zero), TargetFrame, TargetPrevious or a declared target.\n\tSrc TargetID\n\t// Extra are the images read as imageSrc1 to imageSrc3; zero is unused.\n\t// Any input may have any size.\n\tExtra [3]TargetID\n\t// Out is the image the pass writes, replacing its pixels: the chain\n\t// (zero) or a declared target. A pass that writes a target leaves the\n\t// chain as it was. If no running pass writes the chain, the frame is\n\t// shown as it is. Out may not also be read by the pass.\n\t//\n\t// A skipped pass (Off, shader not loaded) writes nothing: its Out keeps\n\t// what it held last frame, or is transparent if it was never written.\n\tOut TargetID\n\t// contains filtered or unexported fields\n}\n```\nPass is one full-screen shader pass of a [PostChain](#PostChain).\n\n```go\ntype PostChain struct {\n\t// Passes run in order on the frame Draw produced. Each one reads the\n\t// output of the previous one; the last one writes the screen. With no\n\t// pass that runs (none, all Off, or shaders not loaded), Draw draws\n\t// straight to the screen and allocates nothing.\n\tPasses []Pass\n\t// Targets are the offscreen images the passes can write and read; the\n\t// target at index i has the ID i+1. Declare them with [PostChain.AddTarget].\n\tTargets []Target\n\t// Final, when set, is drawn by [Renderer.DrawFinal] at window (device)\n\t// resolution: the shader gets the logical frame as imageSrc0 and runs\n\t// once per window pixel, for effects that need real pixels (CRT\n\t// scanlines and masks, smooth upscaling). nil, Off or a shader that is\n\t// not loaded draw the frame with Ebiten's default scaling.\n\tFinal *Pass\n\t// Fade covers the frame with a color after Passes and before Final: a\n\t// screen fade or flash without a shader. Its alpha says how much (255:\n\t// fully covered). Unlike a Sprite tint, a zero alpha byte means no fade,\n\t// so the zero value does nothing; the fade costs one draw while it is on.\n\tFade gfx.Color\n}\n```\nPostChain is the post-processing of a Renderer (see [Renderer.SetPost](#Renderer.SetPost)): full-screen shader passes over the finished frame, at logical resolution, and an optional final pass at window resolution. The zero value does nothing and is ready to use.\n\nGame code owns the chain: set Passes up once and change a pass's Params or Off between frames (from a system: it is a World resource in game.Engine). The renderer reads it in every Draw and never copies or keeps it.\n\n```go\nfunc (p *PostChain) AddBloom(opts BloomOptions) Bloom\n```\nAddBloom appends a bloom to the chain: the bright parts of the chain so far (or of opts.Src) are shrunk to a half and then a quarter of the screen size, blurred there and added back, so bright pixels glow. It declares three targets (half, quarter and a quarter-size scratch image) and appends five passes that run the engine's own shaders, which need no asset and are ready on the first frame.\n\nPasses added later see the bloom; passes added earlier are what it glows. Do not remove or reorder passes before the bloom's: the returned Bloom finds its passes by index. Use [Bloom.Set](#Bloom.Set) to retune and [Bloom.SetOff](#Bloom.SetOff) to switch the effect off.\n\n```go\nfunc (p *PostChain) AddTarget(t Target) TargetID\n```\nAddTarget declares an offscreen image for passes to write and read and returns its ID. Add targets before the first frame that uses them; do not remove or reorder them afterwards, as passes refer to them by ID.\n\n```go\ntype Queue struct {\n\t// contains filtered or unexported fields\n}\n```\nQueue is the frame's command list. Systems Push items during Update, Sort orders them, and the Renderer reads them in Draw.\n\nThe Queue is reused every tick: Reset keeps the capacity, so the steady state allocates nothing. It is not safe for concurrent use.\n\n```go\nfunc (q *Queue) AddCulled(n int)\n```\nAddCulled records that an extract system skipped n items this tick because they were outside the camera bounds. Reset clears the count; the Renderer reports it as [Stats.Culled](#Stats.Culled). Extract systems call it once per Run with their total, not once per item.\n\n```go\nfunc (q *Queue) At(i int) *Item\n```\nAt returns the i-th item in draw order, 0 \\\u003c= i \\\u003c Len. Before Sort (or after a Push that followed it) this is insertion order. The pointer is valid until the next Push or Reset.\n\n```go\nfunc (q *Queue) Culled() int\n```\nCulled returns the number of items culled since the last Reset.\n\n```go\nfunc (q *Queue) Len() int\n```\nLen returns the number of queued items.\n\n```go\nfunc (q *Queue) Push(it Item)\n```\nPush appends a copy of it.\n\n```go\nfunc (q *Queue) Reset()\n```\nReset empties the queue and keeps its capacity. Text strings are cleared so the queue does not keep them alive.\n\n```go\nfunc (q *Queue) SetMinLayer(l int16)\n```\nSetMinLayer makes Sort drop the items on layers below l and count them as culled (see [Queue.Culled](#Queue.Culled)). The engine sets it every tick from the scene stack, so a scene that does not draw the scenes below it hides their layers. math.MinInt16 (or any value no item is below) removes the floor; the zero Queue has none. Reset keeps it.\n\n```go\nfunc (q *Queue) Sort(cfg *LayerConfig, sprites SpriteStore)\n```\nSort puts the items in draw order: by layer, then by SortY inside layers that cfg marks YSort, then (when sprites is not the zero SpriteStore) by shader and then texture, so batches stay together: Ebiten only merges consecutive draws with the same source, shader and uniforms. Items that compare equal keep their insertion order. Items below the layer set by [Queue.SetMinLayer](#Queue.SetMinLayer) are dropped first. Missing, loading and failed sprites share the placeholder's texture, and canvas items sort before the sprites of their layer (in insertion order). cfg may be nil and sprites may be the zero SpriteStore (no shader or texture ordering).\n\n```go\nfunc (q *Queue) Sprite(layer int16, id gfx.SpriteHandle, pos, prev gfx.Vec2) *Item\n```\nSprite appends a world-space sprite item with Scale (1,1) at pos, moved from prev (see Item.MovedFrom), and returns a pointer to the slot for filling in more fields. The pointer is valid until the next Push, Sprite or Reset.\n\n```go\ntype Renderer struct {\n\t// contains filtered or unexported fields\n}\n```\nRenderer turns a sorted Queue into Ebiten draw calls. Sprites and shapes are batched: consecutive unshaded ones that share a target, a source texture and a blend mode become one DrawTriangles call, consecutive shaded ones that share a target, an image, a blend mode, a shader and Params one DrawTrianglesShader call. It owns reused draw options and vertex buffers, so steady-state sprite and shape drawing allocates nothing. It has no access to the ecs World.\n\n```go\nfunc NewRenderer(st Stores) *Renderer\n```\nNewRenderer returns a Renderer that resolves sprite and font handles through st. See [StoresOf](#StoresOf).\n\n```go\nfunc (r *Renderer) Draw(dst *ebiten.Image, q *Queue, cam *Camera, alpha float64)\n```\nDraw renders q onto dst through cam. alpha in \\[0,1] blends the previous position of every item (Item.PrevPos, when HasPrev is set) and the previous view of the camera (Camera.Prev) to the current ones, so that a 60 TPS simulation looks smooth at any frame rate. q should have been sorted. Draw never reads the World and allocates nothing for sprites (shaded or not) and shapes; text may allocate. With a post chain (see [Renderer.SetPost](#Renderer.SetPost)) whose passes run, the frame, including what dst held before Draw, is drawn offscreen and the passes write dst; without one Draw draws straight onto dst. PostChain.Fade is drawn over the result.\n\n```go\nfunc (r *Renderer) DrawFinal(screen ebiten.FinalScreen, offscreen *ebiten.Image, geoM ebiten.GeoM)\n```\nDrawFinal draws the logical frame offscreen onto the window screen, at window resolution: through PostChain.Final if it is set, not Off and loaded, else with ebiten.DefaultDrawFinalScreen. Its arguments are those of ebiten.FinalScreenDrawer, whose DrawFinalScreen should call it; game.Engine does. geoM scales and centers the frame in the window and is applied to the shader's rectangle, so imageSrc0At(src) samples the frame in logical pixels while the shader runs per window pixel (dst).\n\nA final pass adds one to Stats.PostPasses of the frame.\n\n```go\nfunc (r *Renderer) SetCanvases(c *Canvases)\n```\nSetCanvases makes the Renderer draw KindCanvas items from c; nil (the default) means they draw nothing.\n\n```go\nfunc (r *Renderer) SetGroups(g *GroupConfig)\n```\nSetGroups makes the Renderer draw the layer groups of g; nil means no groups. The Renderer reads g in every Draw, so later changes through [GroupConfig.Set](#GroupConfig.Set) apply from the next frame.\n\n```go\nfunc (r *Renderer) SetPost(p *PostChain)\n```\nSetPost sets the post-processing chain Draw and DrawFinal run (nil: none). The renderer keeps the pointer and reads the chain on every frame, so changes to it apply from the next Draw.\n\n```go\nfunc (r *Renderer) SetTime(t time.Duration)\n```\nSetTime sets the value of the Time uniform (see [ShaderUniformTime](#ShaderUniformTime)) for the following Draw and DrawFinal calls: t in seconds, as a float32. It starts at 0 and only changes through SetTime; game.Engine sets it every frame to the interpolated simulation time. It allocates nothing.\n\nA float32 has about 7 significant digits, so after a few hours Time advances in steps of a millisecond or more. Shaders that animate with it should wrap it themselves (mod(Time, period)) rather than rely on long absolute values.\n\n```go\nfunc (r *Renderer) Stats() Stats\n```\nStats returns the statistics of the last Draw.\n\n```go\ntype Shader struct {\n\tShader *ebiten.Shader\n}\n```\nShader is a compiled Kage shader. Load it with [LoadShader](#LoadShader) (or asset.Load\\[Shader]) from a .kage source file. A compile error fails the asset; use [ShaderStore.Err](#ShaderStore.Err) or the Server's OnError to show it.\n\nThe Renderer passes the uniforms [ShaderUniformParams](#ShaderUniformParams) and [ShaderUniformTime](#ShaderUniformTime); a shader declares only the ones it uses. A shader that declares one of them with a different type fails to load, so the mismatch never panics while drawing.\n\nThe placeholder (what a missing, loading or failed handle resolves to) has a nil Shader field, which means \"no shader\": draw code must treat nil as the default pipeline.\n\n```go\ntype ShaderID = asset.Handle[Shader]\n```\nShaderID is the generic handle to a [Shader](#Shader). The zero handle means no shader. Components and items hold the concrete [gfx.ShaderHandle](/github.com/weakpixel/engine/gfx#ShaderHandle); see [LoadShader](#LoadShader).\n\n```go\ntype ShaderStore struct {\n\t// contains filtered or unexported fields\n}\n```\nShaderStore resolves [gfx.ShaderHandle](/github.com/weakpixel/engine/gfx#ShaderHandle) values to shaders. Get one from [StoresOf](#StoresOf) or [ShaderStoreOf](#ShaderStoreOf). It is a small value; copy it freely.\n\n```go\nfunc ShaderStoreOf(srv *asset.Server) ShaderStore\n```\nShaderStoreOf returns the shader store of srv. It panics like [asset.StoreOf](/github.com/weakpixel/asset#StoreOf) if [RegisterLoaders](#RegisterLoaders) has not run on srv.\n\n```go\nfunc (s ShaderStore) Err(h gfx.ShaderHandle) error\n```\nErr returns why the shader failed to load (for example its compile error), or nil.\n\n```go\nfunc (s ShaderStore) Generic() *asset.Store[Shader]\n```\nGeneric returns the underlying generic store, for loaders and tools that work with asset.Handle\\[Shader].\n\n```go\nfunc (s ShaderStore) Get(h gfx.ShaderHandle) *Shader\n```\nGet returns the shader, or the placeholder, whose Shader field is nil (\"no shader\"); see [asset.Store.Get](/github.com/weakpixel/asset#Store.Get). It does not allocate.\n\n```go\nfunc (s ShaderStore) Key(h gfx.ShaderHandle) asset.Key\n```\nKey returns the key h was loaded from, or the zero Key for a zero or stale handle.\n\n```go\nfunc (s ShaderStore) Lookup(h gfx.ShaderHandle) (*Shader, asset.State)\n```\nLookup is Get plus the load state; see [asset.Store.Lookup](/github.com/weakpixel/asset#Store.Lookup).\n\n```go\nfunc (s ShaderStore) Ready(h gfx.ShaderHandle) bool\n```\nReady reports whether h refers to a loaded shader.\n\n```go\ntype Space uint8\n```\nSpace says what coordinates an Item is in.\n\n```go\nconst (\n\t// WorldSpace items are transformed by the camera.\n\tWorldSpace Space = iota\n\t// ScreenSpace items (HUD, UI) are in logical screen pixels and ignore\n\t// the camera.\n\tScreenSpace\n)\n```\nSpaces.\n\n```go\ntype Sprite struct {\n\t// Image is the cached sub-image, created once when the sprite is\n\t// finished: SubImage allocates, so draw code must never call it per frame.\n\t// It is deallocated with the texture, so keep the handle, not the image.\n\tImage *ebiten.Image\n\t// Texture is the texture the sprite is cut from, for batching sort keys.\n\tTexture TextureID\n\t// Rect is the frame's pixel rectangle inside the texture.\n\tRect image.Rectangle\n\t// Origin is the default pivot as a fraction of Size (0..1). A component\n\t// may override it.\n\tOrigin gfx.Vec2\n\t// Size is the size in pixels of the untrimmed frame. It equals the size of\n\t// Rect unless the packer trimmed transparent borders.\n\tSize gfx.Vec2\n\t// Offset is where the trimmed Rect starts inside the untrimmed frame, in\n\t// pixels. Zero when nothing was trimmed.\n\tOffset gfx.Vec2\n\t// contains filtered or unexported fields\n}\n```\nSprite is a drawable rectangle of a texture: either one frame of an [Atlas](#Atlas) (\"chars/hero.atlas.json#idle\\_0\") or a whole image (\"ui/cursor.png\").\n\n```go\ntype SpriteStore struct {\n\t// contains filtered or unexported fields\n}\n```\nSpriteStore resolves [gfx.SpriteHandle](/github.com/weakpixel/engine/gfx#SpriteHandle) values to sprites. Get one from [StoresOf](#StoresOf) or [SpriteStoreOf](#SpriteStoreOf). It is a small value; copy it freely. The zero SpriteStore is \"no store\": only [Queue.Sort](#Queue.Sort) accepts it.\n\n```go\nfunc SpriteStoreOf(srv *asset.Server) SpriteStore\n```\nSpriteStoreOf returns the sprite store of srv. It panics like [asset.StoreOf](/github.com/weakpixel/asset#StoreOf) if [RegisterLoaders](#RegisterLoaders) has not run on srv.\n\n```go\nfunc (s SpriteStore) Err(h gfx.SpriteHandle) error\n```\nErr returns why the sprite failed to load, or nil.\n\n```go\nfunc (s SpriteStore) Generic() *asset.Store[Sprite]\n```\nGeneric returns the underlying generic store, for loaders and tools that work with asset.Handle\\[Sprite].\n\n```go\nfunc (s SpriteStore) Get(h gfx.SpriteHandle) *Sprite\n```\nGet returns the sprite, or the placeholder; see [asset.Store.Get](/github.com/weakpixel/asset#Store.Get) for the pointer validity rule. It does not allocate.\n\n```go\nfunc (s SpriteStore) Key(h gfx.SpriteHandle) asset.Key\n```\nKey returns the key h was loaded from, or the zero Key for a zero or stale handle.\n\n```go\nfunc (s SpriteStore) Lookup(h gfx.SpriteHandle) (*Sprite, asset.State)\n```\nLookup is Get plus the load state; see [asset.Store.Lookup](/github.com/weakpixel/asset#Store.Lookup).\n\n```go\nfunc (s SpriteStore) Ready(h gfx.SpriteHandle) bool\n```\nReady reports whether h refers to a loaded sprite.\n\n```go\ntype Stats struct {\n\t// Items is the number of queue items drawn.\n\tItems int\n\t// DrawCalls is the number of Ebiten draw calls issued (Ebiten may merge\n\t// consecutive calls into fewer GPU batches). A batch of quads (see\n\t// Quads) is one draw call.\n\tDrawCalls int\n\t// Quads is how many unshaded textured quads went into batched draw\n\t// calls: one per unshaded sprite, and one per edge of a rect or line.\n\t// (A circle is a mesh and a draw call of its own, not quads.)\n\t// Consecutive quads with the same target, source texture\n\t// and blend mode share one draw call.\n\tQuads int\n\t// ShadedQuads is how many items were drawn through their shader\n\t// (Item.Shader resolved to a loaded shader), one quad each. Consecutive\n\t// sprites and canvases with the same target, image (atlas frame), blend\n\t// mode, shader and Params share one draw call; a shaded text, nine-slice\n\t// or shape is always a draw call of its own, plus the calls that draw\n\t// it into the scratch image first (counted in DrawCalls and Quads).\n\tShadedQuads int\n\t// ShaderDraws is how many of the draw calls went through a shader: the\n\t// batches of shaded quads, plus shaded layer group composites and post\n\t// passes.\n\tShaderDraws int\n\t// Groups is how many layer groups were composited (see [GroupConfig]).\n\t// Their composite draws count in DrawCalls.\n\tGroups int\n\t// Placeholders is how many sprite items drew the placeholder sprite\n\t// because their handle was zero, stale, loading or failed. A steady\n\t// non-zero value usually means a wrong asset key.\n\tPlaceholders int\n\t// Culled is how many items the extract systems skipped because they\n\t// were outside the camera bounds, as reported by [Queue.Culled]. It is\n\t// not a renderer count: culling happens in extract, not in Draw.\n\tCulled int\n\t// PostPasses is how many post-processing passes ran (see [PostChain]),\n\t// including the final pass of [Renderer.DrawFinal]. Each one is also a\n\t// draw call and a shader draw.\n\tPostPasses int\n}\n```\nStats describes the last Draw call.\n\n```go\ntype StatsOverlay struct {\n\t// Pos is the panel's top-left corner in logical screen pixels.\n\tPos image.Point\n\t// contains filtered or unexported fields\n}\n```\nStatsOverlay draws a [Stats](#Stats) value with the current FPS and TPS as a small text panel, for development builds:\n\n\tFPS 60.0  TPS 60.0\n\titems 1200  draws 12  quads 1190\n\tshaded 3  groups 1\n\tculled 340  placeholders 0\n\nIt uses Ebiten's built-in debug font, so it needs no font asset and works before any asset is loaded. Call Draw at the end of the game's Draw, after [Renderer.Draw](#Renderer.Draw), with [Renderer.Stats](#Renderer.Stats); game.Engine does that when its stats overlay is on.\n\nThe zero StatsOverlay is ready to use and draws at the top-left corner. Draw reuses its text buffer but converts it to a string for Ebiten, which allocates once per frame; that is fine for a debug aid and keeps [Renderer.Draw](#Renderer.Draw) itself allocation-free.\n\n```go\nfunc (o *StatsOverlay) Draw(dst *ebiten.Image, st Stats)\n```\nDraw renders st, ebiten.ActualFPS and ebiten.ActualTPS onto dst. It must run on the game goroutine (inside Draw), like every Ebiten draw call.\n\n```go\ntype Stores struct {\n\tSprites SpriteStore\n\tFonts   FontStore\n\tShaders ShaderStore\n}\n```\nStores are the asset stores the Renderer resolves item handles through. Their placeholders (see [RegisterLoaders](#RegisterLoaders)) are what a zero, stale, loading or failed handle draws, so Draw never sees a nil image or face.\n\n```go\nfunc StoresOf(srv *asset.Server) Stores\n```\nStoresOf returns the render stores of srv. It panics like [asset.StoreOf](/github.com/weakpixel/asset#StoreOf) if [RegisterLoaders](#RegisterLoaders) has not run on srv.\n\n```go\ntype Target struct {\n\t// Scale divides the screen size: 1 (and 0) is the screen size, 2 half,\n\t// 4 a quarter. A size that does not divide evenly is rounded up. The\n\t// image follows screen resizes. It is allocated the first frame a\n\t// running pass uses it, and starts transparent.\n\tScale int\n}\n```\nTarget is an offscreen image a [PostChain](#PostChain) pass can write and later passes can read, declared with [PostChain.AddTarget](#PostChain.AddTarget).\n\n```go\ntype TargetID int\n```\nTargetID names an image a [Pass](#Pass) reads or writes: one of the special values [TargetChain](#TargetChain), [TargetFrame](#TargetFrame) and [TargetPrevious](#TargetPrevious), or a target declared with [PostChain.AddTarget](#PostChain.AddTarget). The zero value is [TargetChain](#TargetChain).\n\n```go\nconst (\n\t// TargetChain is the chain so far. As a pass's Src it is the output of\n\t// the pass before (the frame for the first pass); as its Out it is the\n\t// next chain image, or the screen for the last pass that writes it. The\n\t// zero value of Src and Out, so a pass that sets neither works as it\n\t// always did. As an Extra entry zero means \"unused\".\n\tTargetChain TargetID = 0\n\t// TargetFrame is the frame Draw produced, as the first pass sees it. It\n\t// is an input only.\n\tTargetFrame TargetID = -1\n\t// TargetPrevious is what the chain showed on the previous frame (at\n\t// the first frame, and after a resize, the current frame). It is an\n\t// input only. A chain with a running pass that reads it costs two more\n\t// screen-sized images and one more copy per frame.\n\tTargetPrevious TargetID = -2\n)\n```\n\n```go\nfunc TargetGroup(id GroupID) TargetID\n```\nTargetGroup is the target that names the image of layer group id (see [GroupConfig](#GroupConfig)): the group's items drawn over its Clear color, before its shader and blend, as the logical screen size. It is an input only (Src or an Extra entry); a pass cannot write a group. A group no item fell into reads as its Clear color, never as last frame's pixels. A group that does not exist makes Draw panic with \"unknown post target\".\n\n```go\ntype Texture struct {\n\t// Image is the uploaded image. It is deallocated when the texture is\n\t// unloaded, so don't keep it across Server.Update calls; keep the handle.\n\tImage *ebiten.Image\n\t// Size is the image size in pixels.\n\tSize image.Point\n\t// Bytes is the GPU memory estimate (4 bytes per pixel), for stats.\n\tBytes int64\n}\n```\nTexture is a whole image on the GPU: an atlas page or a standalone picture. It is an asset type: load it with asset.Load\\[Texture] after [RegisterLoaders](#RegisterLoaders). Keys name PNG or JPEG files.\n\n```go\ntype TextureID = asset.Handle[Texture]\n```\nTextureID is a handle to a [Texture](#Texture).\n\n","path":"github.com/weakpixel/engine/render","name":"render","synopsis":"Package render draws a queue of plain draw items with Ebiten.","isRedistributable":true}
