Re: [PyOpenGL-Users] mixing C++ and python w/ opengl
Brought to you by:
mcfletch
From: Mike C. F. <mcf...@vr...> - 2011-01-31 15:34:31
|
On 11-01-25 06:48 PM, Philip Winston wrote: ... > > > Rather than pull it into Python and then push it > > back with pyopengl, it seems like we could just draw it from C, > if that > > is allowed. > > well, I don't know that I'd do it for this reason -- if you pull/push > the data as numpy arrays, you can do all that without data copying, so > keeping it in Python may be fine. > > > You might be right. > > How do you completely avoid the copy? I do something really > simple/dumb when right now when I need to return an array from C to > Python. I do use numpy, but I do the allocation in Python and then > hand the empty array to C to copy the values into. By default, numpy arrays only copy if they need to have their data-format changed. There's a flag in OpenGL.__init__ which, if set on import, will raise errors when that copying occurs. You can do the same by registering an array data-format handler for your C-provided types, but Numpy is probably a better/easier option. Under the covers, PyOpenGL is examining the type of the numpy array and, if it is compatible, just pulling out the data-pointer from the underlying memory area. Your data-array class could do the same thing, but again, it is probably easier to just use Numpy for this kind of work. > > I saw some stuff about defining an allocator but it looked complicated. > > I wonder if my simplistic approach if the copy would hurt me. I > wonder if I should be using a better no-copy approach instead. Moving the drawing to C/C++ is certainly supported and easy if you already have the C/C++ rendering code. Avoiding copying is *always* a good approach to speeding things up. > Anyway probably I should start by keeping drawing in Python and > if/when I measure a real performance problem consider pushing it to C. > This is how we operate with other stuff, resorting to C only to solve > a specific performance issue. Sounds like a good plan. Good luck, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com |