开发者

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. 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 Ptrs 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜