anchor.diff:  #nowarn "51"
   
   
  +module ResizeBuffers =
  +
  +    type ResizeBuffer(ctx : Context, handle : int) =
  +        inherit Buffer(ctx, 0n, handle)
  +
  +        member x.Resize(newCapacity : nativeint) =
  +            let newCapactiy = Fun.NextPowerOfTwo(int64 newCapacity) |> nativeint
  +            if newCapacity <> x.SizeInBytes then
  +                using ctx.ResourceLock (fun _ -> 
  +                    let copyBytes = min newCapacity x.SizeInBytes
  +
  +                    GL.BindBuffer(BufferTarget.CopyReadBuffer, x.Handle)
  +                    if copyBytes <> 0n then
  +                        let tmpBuffer = GL.GenBuffer()
  +                        GL.BindBuffer(BufferTarget.CopyWriteBuffer, tmpBuffer)
  +
  +                        GL.BufferData(BufferTarget.CopyWriteBuffer, copyBytes, 0n, BufferUsageHint.StaticCopy)
  +                        GL.CopyBufferSubData(BufferTarget.CopyReadBuffer, BufferTarget.CopyWriteBuffer, 0n, 0n, copyBytes)
  +
  +                        GL.BufferData(BufferTarget.CopyReadBuffer, newCapacity, 0n, BufferUsageHint.StreamDraw)
  +                        GL.CopyBufferSubData(BufferTarget.CopyWriteBuffer, BufferTarget.CopyReadBuffer, 0n, 0n, copyBytes)
  +
  +                        GL.BindBuffer(BufferTarget.CopyWriteBuffer, 0)
  +                        GL.DeleteBuffer(tmpBuffer)
  +                    else
  +                        GL.BufferData(BufferTarget.CopyReadBuffer, newCapacity, 0n, BufferUsageHint.StreamDraw)
  +
  +                    GL.BindBuffer(BufferTarget.CopyReadBuffer,  0)
  +
  +                    x.SizeInBytes <- newCapacity
  +
  +                )
  +
  +        member x.UseWrite(offset : nativeint, size : nativeint, f : nativeint -> 'a) =
  +            if offset < 0n then failwith "offset < 0n"
  +            if size < 0n then failwith "negative size"
  +            if size + offset > x.SizeInBytes then failwith "insufficient buffer size"
  +
  +            if size = 0n then
  +                f 0n
  +            else
  +                let data = Marshal.AllocHGlobal size
  +
  +                using ctx.ResourceLock (fun _ ->
  +                    GL.BindBuffer(BufferTarget.CopyWriteBuffer, x.Handle)
  +                    GL.Check "[ResizeableBuffer] could not bind buffer"
  +
  +                    let res = f data
  +
  +                    GL.BufferSubData(BufferTarget.CopyWriteBuffer, offset, size, data)
  +                    GL.Check "[ResizeableBuffer] could not upload buffer"
  +
  +                    GL.BindBuffer(BufferTarget.CopyWriteBuffer, 0)
  +                    GL.Check "[ResizeableBuffer] could not unbind buffer"
  +                    
  +                    Marshal.FreeHGlobal data
  +                    res
  +                )
  +
  +        member x.UseRead(offset : nativeint, size : nativeint, f : nativeint -> 'a) =
  +            if offset < 0n then failwith "offset < 0n"
  +            if size < 0n then failwith "negative size"
  +            if size + offset > x.SizeInBytes then failwith "insufficient buffer size"
  +
  +            if size = 0n then
  +                f 0n
  +            else
  +                let data = Marshal.AllocHGlobal size
  +
  +                using ctx.ResourceLock (fun _ ->
  +                    GL.BindBuffer(BufferTarget.CopyWriteBuffer, x.Handle)
  +                    GL.Check "[ResizeableBuffer] could not bind buffer"
  +
  +                    GL.GetBufferSubData(BufferTarget.CopyWriteBuffer, offset, size, data)
  +                    GL.Check "[ResizeableBuffer] could not download buffer"
  +
  +                    let res = f data
  +
  +                    GL.BindBuffer(BufferTarget.CopyWriteBuffer, 0)
  +                    GL.Check "[ResizeableBuffer] could not unbind buffer"
  +
  +                    Marshal.FreeHGlobal data
  +                    res
  +                )
  +
  +
   module MappedBufferImplementations = 
  +
       type MappedBuffer(ctx : Context) =
           inherit Mod.AbstractMod<IBuffer>()
   
  
positive.code:         let locks = ReferenceCountingSet<RenderTaskLock>()
  
          let mutable oldBuffers : list<int> = []
          let mutable buffer = Buffer(ctx, 0n, 0)
          let onDispose = new System.Reactive.Subjects.Subject<unit>()
  
          let resourceLocked f =
  
negative.code:                 )
              )
  
          member x.Read(targetPtr : IntPtr, offset : nativeint, size : nativeint) =
              resourceLocked (fun () -> 
                  if size + offset > buffer.SizeInBytes then failwith "insufficient buffer size"
                  using ctx.ResourceLock (fun _ ->
  