Re: [PyOpenGL-Users] glMapBuffer with GL_WRITE_ONLY
Brought to you by:
mcfletch
From: Mike C. F. <mcf...@vr...> - 2009-04-04 00:30:47
|
Colin Caufield wrote: > Hi everyone, > > I've managed to get VBOs working in my PyOpenGL application, but I've > hit a wall trying to update the data in them. My VBOs contain > position and texcoord data only (not interleaved). Every few frames I > need to change some of the texcoord data. I know this is done with > glMapBuffer, but I can't wrap my head around the python bindings for > this function. glMapBuffer returns a ctypes.c_void_p. I'm very > comfortable with C, but not with ctypes. I want to treat this > c_void_p like a python list of floats, and use slicing to change the > values at particular locations. Is this possible? I'm also very > worried about performance; I don't want any of the texcoord buffer to > be copied back into main memory. I've spent a lot of time hunting > around with Google, but I'm still lost. Any help is greatly > appreciated. > There are actually two ways to update the data, the first is to map the buffer, update it and then unmap it. The second is to copy a subset of the data explicitly into the new data-set. Given your use case, it sounds like you want to use the second method. However, to use the first method, the secret is that you want to use either a numpy array or a ctypes array mapped to the data-set and then update it. For numpy this looks something like this: pbfm = pythonapi.PyBuffer_FromMemory pbfm.restype = py_object buffer = pbfm( pointer, size_of_data ) array = numpy.frombuffer( buffer, dtype ) http://www.mail-archive.com/num...@li.../msg01161.html I can't claim to have done this myself, I'm guessing that people who use this approach will come up with suggestions for better wrappers for the mapping API. But for the second approach: the OpenGL buffer api also includes glBufferSubData(self.target, start, size, dataptr) which lets you update a subset of the data without mapping the data into your memory space, i.e. it just sends a block of data over to the card to replace the current set of data. This is a nice, discrete API that does not rely on having the data in shared memory space, you just say what you want to replace and with what and the data is passed to the card. This obviously avoids any concerns about having to copy the data back or the like. You'll see an implementation of this in the OpenGL.arrays.vbo module, though I'm not sure I'm currently testing it, as my current tests tend to replace the whole of the vbo when there's an update. HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com |