packages feed

GLUtil 0.2.2 → 0.3.0

raw patch · 2 files changed

+22/−3 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Graphics.GLUtil.BufferObjects: replaceBuffer :: Storable a => BufferTarget -> [a] -> IO ()
+ Graphics.GLUtil.BufferObjects: replaceVector :: Storable a => BufferTarget -> Vector a -> IO ()

Files

GLUtil.cabal view
@@ -1,5 +1,5 @@ Name:                GLUtil-Version:             0.2.2+Version:             0.3.0 Synopsis:            Miscellaneous OpenGL utilities. License:             BSD3 License-file:        LICENSE
src/Graphics/GLUtil/BufferObjects.hs view
@@ -16,16 +16,27 @@ -- |Allocate and fill a 'BufferObject' from a list of 'Storable's -- whose length is explicitly given. This is useful when the list is -- of known length, as it avoids a traversal to find the length.-makeBufferLen :: Storable a => BufferTarget -> Int -> [a] -> IO BufferObject+makeBufferLen :: forall a. Storable a => +                 BufferTarget -> Int -> [a] -> IO BufferObject makeBufferLen target len elems =      do [buffer] <- genObjectNames 1        bindBuffer target $= Just buffer-       let n = fromIntegral $ len * sizeOf (head elems)+       let n = fromIntegral $ len * sizeOf (undefined::a)        arr <- newListArray (0, len - 1) elems        withStorableArray arr $ \ptr ->           bufferData target $= (n, ptr, StaticDraw)        return buffer +-- |@replaceBuffer target elements@ replaces the buffer data attached+-- to the buffer object currently bound to @target@ with the supplied+-- list. Any previous data is deleted.+replaceBuffer :: forall a. Storable a => BufferTarget -> [a] -> IO ()+replaceBuffer target elems = do arr <- newListArray (0, len - 1) elems+                                withStorableArray arr $ \ptr ->+                                  bufferData target $= (n, ptr, StaticDraw)+  where len = length elems+        n = fromIntegral $ len * sizeOf (undefined::a)+ -- |Allocate and fill a 'BufferObject' with the given number of bytes -- from the supplied pointer. fromPtr :: BufferTarget -> Int -> Ptr a -> IO BufferObject@@ -51,6 +62,14 @@ fromVector :: forall a. Storable a =>                BufferTarget -> V.Vector a -> IO BufferObject fromVector target v = V.unsafeWith v $ fromPtr target numBytes+  where numBytes = fromIntegral $ V.length v * sizeOf (undefined::a)++-- |@replaceVector target v@ replaces the buffer data attached to the+-- buffer object currently bound to @target@ with the supplied+-- 'V.Vector'. Any previous data is deleted.+replaceVector :: forall a. Storable a => BufferTarget -> V.Vector a -> IO ()+replaceVector target v = V.unsafeWith v $ \ptr ->+                           bufferData target $= (numBytes, ptr, StaticDraw)   where numBytes = fromIntegral $ V.length v * sizeOf (undefined::a)  -- |Produce a 'Ptr' value to be used as an offset of the given number