The ffunction glMultiDrawElements
requires a pointer to a pointer as 开发者_开发知识库one of its arguments. How might one obtain a Ptr(Ptr a)
from a StorableArray Int a
?
You need to first marshal your lists of indices into Ptr
's, then marshal those Ptr
's into a Ptr (Ptr Int))
You can do something like this
import Foreign.Marshal.Array
indices :: [[Int]]
do
ixPtrs <- mapM newArray indices
sizes <- newArray $ map (fromIntegral . length) indices
ixPtrPtr <- newArray ixPtrs
glMultiDrawElements enumType sizes iType ixPtrPtr (fromIntegral $ length indices)
mapM_ free ixPtrs
free ixPtrPtr
free sizes
Here the list of Ptr
s is still in scope, so we can mapM over it to free each pointer. If you want to free the memory later, you can either retain the list or keep the ixPtrPtr and use peekArray
to get the original pointers back.
精彩评论