diff --git a/src/Types/Graphics/IndexBuffer.hs b/src/Types/Graphics/IndexBuffer.hs index 7dc7d1d..ba01478 100644 --- a/src/Types/Graphics/IndexBuffer.hs +++ b/src/Types/Graphics/IndexBuffer.hs @@ -59,30 +59,33 @@ instance Buffer IndexBuffer where unbind buf write buf offset dat = do - currentBufSize <- readTVarIO (iBufSize buf) whileM_ - (pure $ (fromIntegral offset + VS.length dat) * - sizeOf (undefined :: StoreType IndexBuffer) - > fromIntegral currentBufSize) $ do - allocaArray - (fromIntegral currentBufSize `div` - sizeOf (undefined :: StoreType IndexBuffer)) - $ \ (ptr :: Ptr (StoreType IndexBuffer)) -> do - bind buf - GL.bufferSubData - (target buf) - GL.ReadFromBuffer - 0 - currentBufSize - ptr - expand buf - bind buf - GL.bufferSubData - (target buf) - GL.WriteToBuffer - 0 - currentBufSize - ptr + (do + currentSize <- readTVarIO (iBufSize buf) + pure $ (fromIntegral offset + VS.length dat) * + sizeOf (undefined :: StoreType IndexBuffer) + > fromIntegral currentSize) + $ do + currentBufSize <- readTVarIO (iBufSize buf) + allocaArray + (fromIntegral currentBufSize `div` + sizeOf (undefined :: StoreType IndexBuffer)) + $ \ (ptr :: Ptr (StoreType IndexBuffer)) -> do + bind buf + GL.bufferSubData + (target buf) + GL.ReadFromBuffer + 0 + currentBufSize + ptr + expand buf + bind buf + GL.bufferSubData + (target buf) + GL.WriteToBuffer + 0 + currentBufSize + ptr -- bind buffer, just to be safe bind buf let elemCount = fromIntegral offset + VS.length dat diff --git a/src/Types/Graphics/VertexBuffer.hs b/src/Types/Graphics/VertexBuffer.hs index 34fc34d..bc5590e 100644 --- a/src/Types/Graphics/VertexBuffer.hs +++ b/src/Types/Graphics/VertexBuffer.hs @@ -89,30 +89,33 @@ instance Buffer VertexBuffer where unbind buf write buf offset dat = do - currentBufSize <- readTVarIO (vBufSize buf) whileM_ - (pure $ (fromIntegral offset + VS.length dat) * - sizeOf (undefined :: StoreType VertexBuffer) - > fromIntegral currentBufSize) $ do - allocaArray - (fromIntegral currentBufSize `div` - sizeOf (undefined :: StoreType VertexBuffer)) - $ \ (ptr :: Ptr (StoreType VertexBuffer)) -> do - bind buf - GL.bufferSubData - (target buf) - GL.ReadFromBuffer - 0 - currentBufSize - ptr - expand buf - bind buf - GL.bufferSubData - (target buf) - GL.WriteToBuffer - 0 - currentBufSize - ptr + (do + currentSize <- readTVarIO (vBufSize buf) + pure $ (fromIntegral offset + VS.length dat) * + sizeOf (undefined :: StoreType VertexBuffer) + > fromIntegral currentSize) + $ do + currentBufSize <- readTVarIO (vBufSize buf) + allocaArray + (fromIntegral currentBufSize `div` + sizeOf (undefined :: StoreType VertexBuffer)) + $ \ (ptr :: Ptr (StoreType VertexBuffer)) -> do + bind buf + GL.bufferSubData + (target buf) + GL.ReadFromBuffer + 0 + currentBufSize + ptr + expand buf + bind buf + GL.bufferSubData + (target buf) + GL.WriteToBuffer + 0 + currentBufSize + ptr -- bind buffer, just to be safe bind buf VS.unsafeWith dat $ \ ptr ->