unwrong/Starling-Extension-Graphics — pull request #44 by jarrodmoldrich (2013-05-21 15:05:07+00:00)
Title: Allowing more control over the life-time of material shader programs

First of all: Thanks so much for this extensions. Saved me a huge amount of time for rendering basic primitives - something that's pretty well needed in most games, if only for debugging. Came across a few hurdles in my particular use case that I think might be of benefit for other people. I originally forked from the wrong person - hopefully that doesn't cause any problems (I've adjusted my upstream accordingly).

Problem:

In situations where SEG is used for only dynamically drawn content, it's possible that all primitives will be destroyed and remade for a particular vertex/fragment shader combo. In such a situation the graphics are cleared each frame - where reference counts will drop to zero for the shader program which will automatically destroy it. At render phase, the missing shader will be re-instantiated. This means the shader program will be remade every frame causing poor performance.

Solution:

Provide a flag that defaults for the usual auto-extinction of shader programs but allows this automatic feature to be disabled. An explicit function is provided which can be executed during the most appropriate time in the game loop according to individual project needs. It iterates through all programs and selects any zero-referenced programs for destruction in one batch.