Graphics & WebGL

WebGL 2.0 Sprite Batching: Single Draw Call Rendering for 10,000+ Dynamic Sprites

Dispatching individual draw calls (gl.drawElements) for every sprite on screen creates severe CPU-to-GPU bottlenecking. High-performance 2D engines (like PixiJS and custom WebGL renderers) achieve 60 FPS across tens of thousands of sprites by buffering vertex coordinates, texture coordinates, tint colors, and texture indices into a single interleaved Float32Array.

1. Interleaved Vertex Structure Layout

Attribute NameData TypeBytes per VertexShader Location & Purpose
aPosition2 x Float32 (x, y)8 bytesScreen space quad vertex coordinates.
aTexCoord2 x Float32 (u, v)8 bytesNormalized UV coordinates inside the texture atlas.
aColor4 x Uint8 (r, g, b, a)4 bytesVertex tint and alpha transparency.
aTextureId1 x Float32 (id)4 bytesIndex of the bound sampler2D texture slot in shader.
Robert Baindourov

Written by Robert Baindourov & CodeInFlash Interactive Systems Council

Senior interactive systems architect and graphics engineer specializing in HTML5 Canvas 2D game loops, WebGL shader pipelines, WebAssembly physics integration, and digital game preservation.

Need Custom Game Architecture or Graphics Advisory?

Collaborate with Codeinflash engineers to build resilient, high-speed 60 FPS interactive systems.

Book Consultation