6. How do QuadBatch work
• Collects quads with the same state(same texture,
same blend mode, same shader program)
• Transforms all vertices to one space
• Packs to one vertex buffer
• Renders
8. Our approach
• Create one vertexBuffer during initialization and
upload initial data, compile programs
• Batch quads and images by the same
state(blendMode, texture) and collect
Vector.<Number> with data
(x,y,width,height,uv,tintcolor)
• transfer data to GPU with
Context3D.setProgramConstantsFromVector
9. How it works
0,00,0 1,0
1,10,1
Initial vertex buffer
data
Process vertex data
in vertex shader with
data from constants
x,y = 100, 100
width, height = 100,200
rotation = 0
uvOffset
uvScale
tintColor
transfer to
fragment shader
100,100 200,100
200,300100,300
Vertex shader
output
10. Limit
• 128 registers for vertex constants, we can batch
around 31 quads into one drawcall. (128 - 4 registers for matrix -
1 register for common vertex constants)/4(data registers for one quad pos, uv, rotation, color)
13. Create init data
• Create vertex and index buffers on the start
• Upload to the GPU once
• Vertex Buffer includes simple mesh x,y and global offset value
in vertex constants array
16. Some Starling advices
• Starling MovieClip should be rendered through
constants
• Use ByteArray instead of Vector.<Number> for
vertices data upload. Also you can use Apparat to
optimize your work with ByteArray
https://github.com/joa/apparat it gives +20%
performance
17. Batch Spine Animations
• All bones are calculated on CPU, so all vertex data in one
space
• How to batch these quads through constants? we can’t
use x,y,rotation,width,height properties for the processing
simple mesh. We have only vertex positions and uvs.
18.
19. Create init data
• now it holds weights for each vertex. the weight is
like a pointer to constant register with vertex data