Loading…
Loading…
8 карточек
How does Pixi's batch renderer combine draw calls, and what breaks a batch?
нажми, чтобы перевернуть
baseTexture, blendMode, filter, and shader are packed into one VBO and drawn in a single gl.drawElements. A batch breaks on: texture slots overflowing, any filter/mask/mesh in between, or a blendMode change.The batcher keeps a quad buffer and a texture-slot array sized by the GPU's MAX_TEXTURE_IMAGE_UNITS (commonly 8–16). It appends quads until one of three things happens:
blendMode appears.Mesh, complex Graphics, filtered node, masked node).Each 'flush' is one draw call. Counting draw calls is the single most reliable perf metric.
// Good: all sprites share one atlas -> 1 draw call
for (const e of enemies) {
const s = new Sprite(atlas.textures[e.kind])
world.addChild(s)
}
// Bad: alternating atlases forces per-sprite flushes
world.addChild(fromAtlasA(), fromAtlasB(), fromAtlasA(), fromAtlasB())
// Diagnose
app.ticker.add(() => {
// In dev builds, attach a custom flushing callback via extensions to log.
hud.drawCalls = app.renderer.textureGC?.count ?? 0
})Когда да
When profiling, check renderer.renderGroup().batches or the DevTools draw-call counter. Group children by atlas and keep UI + world layers on separate atlas pages to avoid thrash.
Когда нет
Do not rely on batching for particle systems — use ParticleContainer (fixed shader, purpose-built batcher). Do not assume batching survives a filter — it does not.
Совет на собеседовании
The fastest game loop is one that draws in atlas-order. Sort children by (layer, baseTexture) when possible, not by gameplay order.
Свайп вправо — знаю, влево — не знаю
