开发者

How to call the function glMultiDrawElements :: GLenum -> GHC.Ptr.Ptr GLsizei -> GLenum -> GHC.Ptr.Ptr (GHC.Ptr.Ptr a) -> GLsizei -> IO ()

开发者 https://www.devze.com 2023-03-19 18:14 出处:网络
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

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

精彩评论

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