[英]How to call the function glMultiDrawElements :: GLenum -> GHC.Ptr.Ptr GLsizei -> GLenum -> GHC.Ptr.Ptr (GHC.Ptr.Ptr a) -> GLsizei -> IO ()
The ffunction glMultiDrawElements
requires a pointer to a pointer as one of its arguments. ffunction glMultiDrawElements
需要一个指向指针的指针作为它的 arguments 之一。 How might one obtain a Ptr(Ptr a)
from a StorableArray Int a
?如何从 StorableArray Int a
获得Ptr(Ptr a)
?
You need to first marshal your lists of indices into Ptr
's, then marshal those Ptr
's into a Ptr (Ptr Int))
您需要首先将索引列表编组为Ptr
,然后将这些Ptr
编组为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.这里Ptr
的列表仍然在 scope 中,因此我们可以对其进行 mapM 以释放每个指针。 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.如果您想稍后释放 memory,您可以保留列表或保留 ixPtrPtr 并使用peekArray
取回原始指针。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.