Drawing many stimuli of arbitrary shape

I would like to be able to draw many stimuli of potentially arbitrary shape fast enough that they can be rendered without dropping frames.

I’m aware of ElementArrays and their demo, but it’s not clear to me from that documentation what shapes/objects they work for. My stimuli are arbitrary numpy arrays, which can be added to the screen with visual.ImageStim. Can these be used with ElementArray?

If not, is there a better way to render these quickly than with something like:

object_list = []
for i in range(n_objects):

for f in range(n_frames):
    for i in range(n_objects):

As the worst case scenario I can pre-render all the frames, save them as images which are loaded into a big array from disk, then just iterate through the big array for each frame. I’m hoping there’s a better way. Thanks!

Related but different question here.

I talked with @jon at VSS about this; here is a sketch of his creative suggestion for posterity (we have not yet implemented this):

You could render all the shapes to a big texture in video memory, then index the part of the texture corresponding to the desired shape using the frequency and phase arguments of GratingStim. This is approximately also how fast rendering of text works – all the glyphs are stored in a big texture, which is then indexed in real-time.

@jon please correct anything I got wrong here. Thanks!