change byte offset to offset in number of buffer elements

This commit is contained in:
nek0 2020-12-05 10:40:07 +01:00
parent 0fb10b0981
commit a9165b852a
3 changed files with 10 additions and 7 deletions

View file

@ -37,7 +37,7 @@ class (Bindable a, Storable (StoreType a)) =>
write
:: a
-> Word
-- ^ write offset from beginning of buffer in bytes
-- ^ write offset from beginning of buffer in number of data elements
-> StoreContainer a (StoreType a)
-- ^ Data to write
-> IO ()

View file

@ -52,7 +52,8 @@ instance Buffer IndexBuffer where
write buf offset dat = do
currentBufSize <- readTVarIO (iBufSize buf)
whileM_
(pure $ offset + VS.length dat * sizeOf (undefined :: StoreType IndexBuffer)
(pure $ (offset + VS.length dat) *
sizeOf (undefined :: StoreType IndexBuffer)
> currentBufSize) $ do
allocaArray
(currentBufSize `div` sizeOf (undefined :: StoreType IndexBuffer))
@ -77,9 +78,10 @@ instance Buffer IndexBuffer where
GL.bufferSubData
(target buf)
GL.WriteToBuffer
(CPtrdiff $ fromIntegral offset)
(CPtrdiff $ fromIntegral offset *
sizeOf (undefined :: StoreType IndexBuffer))
(CPtrdiff $ fromIntegral $
VS.length dat * sizeOf (undefined ::StoreType IndexBuffer))
VS.length dat * sizeOf (undefined :: StoreType IndexBuffer))
ptr
expand buf = do

View file

@ -90,8 +90,8 @@ instance Buffer VertexBuffer where
write buf offset dat = do
currentBufSize <- readTVarIO (vBufSize buf)
whileM_
(pure $ fromIntegral offset +
VS.length dat * sizeOf (undefined :: StoreType VertexBuffer)
(pure $ (fromIntegral offset + VS.length dat) *
sizeOf (undefined :: StoreType VertexBuffer)
> fromIntegral currentBufSize) $ do
allocaArray
(fromIntegral currentBufSize `div`
@ -119,7 +119,8 @@ instance Buffer VertexBuffer where
-- target buffer type
GL.WriteToBuffer
-- data access direction
(CPtrdiff $ fromIntegral offset)
(CPtrdiff $ fromIntegral offset *
fromIntegral (sizeOf (undefined :: StoreType VertexBuffer)))
-- offset from buffer start
(CPtrdiff $ fromIntegral $
VS.length dat * sizeOf (undefined :: StoreType VertexBuffer))