On 06/30/2010 07:04 AM, Nick Sonneveld wrote:
> (Full disclosure: I actually posted this on stackoverflow a few months
> ago but I didn't really receive a good response. url:
> http://bit.ly/a8W5hR )
> I have a series of sprite objects rendering to textured quads. Right
> now they all have individual render() methods which return an
> interleaved buffer. I call them all in order and batch these vertices
> and texture coords before sending to pyOpengl's
> glInterleavedArrays/glDrawArrays. Is there a better way to be doing
> this? The fastest way seems to be generating a python list and
> converting to a numpy array later which doesn't seem right.
> Thankyou for any help?
I think the answer to improving performance here is actually in one of
the responses to the stackoverflow question you posted: "The real
savings will be realized by a recasting of the render routine so that
you don't have to create a python object for every value that ends up
being placed in the buffer."
In other words, don't create a separate object for each sprite, and
don't call a render() function once for each sprite. Structure your code
so that it's more data oriented rather than object oriented: Fill up a
NumPy array all at once with all of your sprites, trying to avoid any
looping in Python. Then send that array (interleaved or not) to a