Re: [PyOpenGL-Users] Building an interleaved buffer for pyopengl
Brought to you by:
mcfletch
|
From: Nick S. <ni...@so...> - 2010-07-01 00:53:43
|
Hello, thanks for your response!
On Thu, Jul 1, 2010 at 4:40 AM, Dan Helfman <Dan...@no...> wrote:
> 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."
I believe the point the poster bpowah on stackoverflow was making was
just that I should reduce the number of objects (eg pregenerating
texture coord lists)? At least I guess that's how I interpreted it.
> 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
> PyOpenGL VBO.
The problem is that I can't really see how to do things such as
collision detection and response without doing at least one loop
through all sprite objects. (I step through each sprite individually
and do sprite movement and collision response to ensure no overlapping
sprites). Wouldn't things such as updating sprite position and
adjusting for collision response mean the vertices change on every
update? I can fill up a numpy array but it seems that modifying the
array is slower than just creating a new numpy array from a python
list.
The random() methods may be a red herring. Testing with a dummy
method (that doesn't add data to a list) shows that render() in the
example does take a while to run. It doesn't quite explain why
generating a new numpy array from a list is quicker than just
modifying a preallocated numpy array though.
# dummy array.. just iterate but don't save
def create_array_dummy():
for x in xrange(4096):
render(x)
return []
$ python testing2.py # on another slower machine.
from dummy: 9.96989965439 ms
from list: 16.1171197891 ms
etc...
- Nick
|