Re: [PyOpenGL-Users] Using glDrawElements on C-allocated data
Brought to you by:
mcfletch
From: Gordon L. K. <gl...@uc...> - 2009-06-02 10:35:27
|
On Jun 2, 2009, at 3:24 AM, Mads Ipsen wrote: > Gordon L. Kindlmann wrote: >> Hello, >> >> I've recently started using PyOpenGL as the framework for re- >> writing C/ C++ OpenGL wrappers around an large amount of research >> code in C. Its been a pleasure to have something that allows such >> literal translation from the successful C/C++ OpenGL code to >> Python code; thanks for creating this! ... >> http://people.cs.uchicago.edu/~glk/pglt/ >> ... >> Hopefully someone on this list will be able to spend a little time >> working with these examples, and figure out how to get my >> "pgltDemo.py" to work with vertex arrays. >> >> Thanks very much, >> Gordon >> >> >> > Using ctypes, I wrote the following interface to glMultiDrawElements: > > # Interface to glMultiDrawElements > def multiDrawElements(mode, count, gl_type, index): > """ > """ > # Set up interface for the call > n_count = count.shape[0] > libGL.glMultiDrawElements.restype = ctypes.c_void_p > libGL.glMultiDrawElements.argtypes = [ctypes.c_int32, > > ctypes.POINTER(ctypes.c_int32), > ctypes.c_int32, > > ctypes.POINTER(ctypes.c_int32)*n_count, > ctypes.c_int32, > ] > > # Set pointer to data in the count array > count_ptr = count.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)) > > # Set array of pointers to the index array > iptr = ctypes.POINTER(ctypes.c_int32) > index_ptr = (iptr*len(index))(*[row.ctypes.data_as(iptr) for row > in index]) > > # Do the actual call to glMultiDrawElements > libGL.glMultiDrawElements(int(mode), count_ptr, int(gl_type), > index_ptr, n_count) > > Then, using vertex arrays, I call glMultiDrawElements as follows: > > multiDrawElements(GL_QUAD_STRIP, count, GL_UNSIGNED_INT, index) Okay, this is interesting. However, I'm confused about the types of the arguments that you're passing to multiDrawElements(). "count" looks like it must be a numpy array, since you're using .shape and .ctypes.data_as, right? "index" is a 2-D numpy array, given your use of row.ctypes.data_as for row in index, right? I agree that this is relevant, but I'm still stumped because my data is not coming from numpy. Its coming from a C-allocated array that is being accessed via numpy. There is no .data_as for me. I don't quite understand the relationship between what .data_as returns, how pyopengl's use of ctypes handles that "pointer", and how to communicate the analogous information from array allocated in C, outside of numpy. If you have any spare time, I'd be interested if you can tweak the call to glDrawElements in http://people.cs.uchicago.edu/~glk/pglt/pgltDemo.py so that it works; I've done everything I can to make a self-contained but non-trivial demonstration of the problem I'm having. Thanks, Gordon > > > You should be able to boil this down to a working example for > glDrawElements(), whose arguments are a subset of the arguments to > glMultiDrawElements. > > Best regards, > > Mads > > > |