Thread: [PyOpenGL-Users] Zipping and rendering numpy arrays
Brought to you by:
mcfletch
From: Martin B. <bl...@fu...> - 2007-05-30 01:49:30
|
Hi I have 2 or 3 long numpy arrays to send to the vertex pipeline. This is actually most of my rendering time. Here is what I do in Python: def gliVertexArrays(a1, a2, a3=None): """ Zip and output the given numpy arrays of floats through the GL vertex pipeline. """ if a3 is None: list(starmap(glVertex2f, izip(a1, a2))) else: list(starmap(glVertex3f, izip(a1, a2, a3))) Is there a C function that does this? I saw glVertexPointer, but it seems I would have to create a temporary array that would contain both my arrays just to call this function. I'd rather avoid the memory allocation and zip-loop in C. This seems pretty basic and reasonable to me... is it already in PyOpenGL? If not, is there another way I'm not thinking of? Any idea welcome. cheers, |
From: Erik J. <ejo...@fa...> - 2007-05-31 19:46:23
|
On Tue, 29 May 2007 18:49:29 -0700, "Martin Blais" said: > Hi > > I have 2 or 3 long numpy arrays to send to the vertex pipeline. > This is actually most of my rendering time. > > Here is what I do in Python: > > def gliVertexArrays(a1, a2, a3=None): > """ > Zip and output the given numpy arrays of floats through the GL vertex > pipeline. > """ > if a3 is None: > list(starmap(glVertex2f, izip(a1, a2))) > else: > list(starmap(glVertex3f, izip(a1, a2, a3))) > > Is there a C function that does this? If I correctly understand your code, you are interleaving individual x y and z coordinate arrays, and then calling glVertex on each set of vertices. I think that the function call overhead to do this is very expensive. > I saw glVertexPointer, but it seems I would have to create a temporary > array that would contain both my arrays just to call this function. > I'd rather avoid the memory allocation and zip-loop in C. Using OpenGL vertex arrays to directly render a Numeric array can be very fast, as long as you don't need to create the Numeric array every frame. Changing large portions of the array can also be slow. If your vertices stay mostly fixed relative to each other, then you should be able to get huge speed ups with vertex arrays using glVertexPointer. Display lists might also be worth investigating. > This seems pretty basic and reasonable to me... is it already in > PyOpenGL? Storing your x, y and z coordinates in separate arrays strikes me as a bit unusual, but then I'm not the most experienced OpenGL programmer in the world. > If not, is there another way I'm not thinking of? If what I suggested above doesn't help, provide some more info about what you are trying to do, and I'll see if I can offer any advice. Erik |