package org.lwjgl.util.vma;

import java.nio.ByteBuffer;
import javax.annotation.Nullable;
import org.lwjgl.BufferUtils;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;
import org.lwjgl.system.NativeResource;
import org.lwjgl.system.NativeType;
import org.lwjgl.system.Struct;
import org.lwjgl.system.StructBuffer;

public class VmaDefragmentationStats extends Struct<VmaDefragmentationStats> implements NativeResource {
   public static final int SIZEOF;
   public static final int ALIGNOF;
   public static final int BYTESMOVED;
   public static final int BYTESFREED;
   public static final int ALLOCATIONSMOVED;
   public static final int DEVICEMEMORYBLOCKSFREED;

   protected VmaDefragmentationStats(long address, @Nullable ByteBuffer container) {
      super(address, container);
   }

   protected VmaDefragmentationStats create(long address, @Nullable ByteBuffer container) {
      return new VmaDefragmentationStats(address, container);
   }

   public VmaDefragmentationStats(ByteBuffer container) {
      super(MemoryUtil.memAddress(container), __checkContainer(container, SIZEOF));
   }

   public int sizeof() {
      return SIZEOF;
   }

   @NativeType("VkDeviceSize")
   public long bytesMoved() {
      return nbytesMoved(this.address());
   }

   @NativeType("VkDeviceSize")
   public long bytesFreed() {
      return nbytesFreed(this.address());
   }

   @NativeType("uint32_t")
   public int allocationsMoved() {
      return nallocationsMoved(this.address());
   }

   @NativeType("uint32_t")
   public int deviceMemoryBlocksFreed() {
      return ndeviceMemoryBlocksFreed(this.address());
   }

   public static VmaDefragmentationStats malloc() {
      return new VmaDefragmentationStats(MemoryUtil.nmemAllocChecked((long)SIZEOF), (ByteBuffer)null);
   }

   public static VmaDefragmentationStats calloc() {
      return new VmaDefragmentationStats(MemoryUtil.nmemCallocChecked(1L, (long)SIZEOF), (ByteBuffer)null);
   }

   public static VmaDefragmentationStats create() {
      ByteBuffer container = BufferUtils.createByteBuffer(SIZEOF);
      return new VmaDefragmentationStats(MemoryUtil.memAddress(container), container);
   }

   public static VmaDefragmentationStats create(long address) {
      return new VmaDefragmentationStats(address, (ByteBuffer)null);
   }

   @Nullable
   public static VmaDefragmentationStats createSafe(long address) {
      return address == 0L ? null : new VmaDefragmentationStats(address, (ByteBuffer)null);
   }

   public static Buffer malloc(int capacity) {
      return new Buffer(MemoryUtil.nmemAllocChecked(__checkMalloc(capacity, SIZEOF)), capacity);
   }

   public static Buffer calloc(int capacity) {
      return new Buffer(MemoryUtil.nmemCallocChecked((long)capacity, (long)SIZEOF), capacity);
   }

   public static Buffer create(int capacity) {
      ByteBuffer container = __create(capacity, SIZEOF);
      return new Buffer(MemoryUtil.memAddress(container), container, -1, 0, capacity, capacity);
   }

   public static Buffer create(long address, int capacity) {
      return new Buffer(address, capacity);
   }

   @Nullable
   public static Buffer createSafe(long address, int capacity) {
      return address == 0L ? null : new Buffer(address, capacity);
   }

   /** @deprecated */
   @Deprecated
   public static VmaDefragmentationStats mallocStack() {
      return malloc(MemoryStack.stackGet());
   }

   /** @deprecated */
   @Deprecated
   public static VmaDefragmentationStats callocStack() {
      return calloc(MemoryStack.stackGet());
   }

   /** @deprecated */
   @Deprecated
   public static VmaDefragmentationStats mallocStack(MemoryStack stack) {
      return malloc(stack);
   }

   /** @deprecated */
   @Deprecated
   public static VmaDefragmentationStats callocStack(MemoryStack stack) {
      return calloc(stack);
   }

   /** @deprecated */
   @Deprecated
   public static Buffer mallocStack(int capacity) {
      return malloc(capacity, MemoryStack.stackGet());
   }

   /** @deprecated */
   @Deprecated
   public static Buffer callocStack(int capacity) {
      return calloc(capacity, MemoryStack.stackGet());
   }

   /** @deprecated */
   @Deprecated
   public static Buffer mallocStack(int capacity, MemoryStack stack) {
      return malloc(capacity, stack);
   }

   /** @deprecated */
   @Deprecated
   public static Buffer callocStack(int capacity, MemoryStack stack) {
      return calloc(capacity, stack);
   }

   public static VmaDefragmentationStats malloc(MemoryStack stack) {
      return new VmaDefragmentationStats(stack.nmalloc(ALIGNOF, SIZEOF), (ByteBuffer)null);
   }

   public static VmaDefragmentationStats calloc(MemoryStack stack) {
      return new VmaDefragmentationStats(stack.ncalloc(ALIGNOF, 1, SIZEOF), (ByteBuffer)null);
   }

   public static Buffer malloc(int capacity, MemoryStack stack) {
      return new Buffer(stack.nmalloc(ALIGNOF, capacity * SIZEOF), capacity);
   }

   public static Buffer calloc(int capacity, MemoryStack stack) {
      return new Buffer(stack.ncalloc(ALIGNOF, capacity, SIZEOF), capacity);
   }

   public static long nbytesMoved(long struct) {
      return UNSAFE.getLong((Object)null, struct + (long)BYTESMOVED);
   }

   public static long nbytesFreed(long struct) {
      return UNSAFE.getLong((Object)null, struct + (long)BYTESFREED);
   }

   public static int nallocationsMoved(long struct) {
      return UNSAFE.getInt((Object)null, struct + (long)ALLOCATIONSMOVED);
   }

   public static int ndeviceMemoryBlocksFreed(long struct) {
      return UNSAFE.getInt((Object)null, struct + (long)DEVICEMEMORYBLOCKSFREED);
   }

   static {
      Struct.Layout layout = __struct(new Struct.Member[]{__member(8), __member(8), __member(4), __member(4)});
      SIZEOF = layout.getSize();
      ALIGNOF = layout.getAlignment();
      BYTESMOVED = layout.offsetof(0);
      BYTESFREED = layout.offsetof(1);
      ALLOCATIONSMOVED = layout.offsetof(2);
      DEVICEMEMORYBLOCKSFREED = layout.offsetof(3);
   }

   public static class Buffer extends StructBuffer<VmaDefragmentationStats, Buffer> implements NativeResource {
      private static final VmaDefragmentationStats ELEMENT_FACTORY = VmaDefragmentationStats.create(-1L);

      public Buffer(ByteBuffer container) {
         super(container, container.remaining() / VmaDefragmentationStats.SIZEOF);
      }

      public Buffer(long address, int cap) {
         super(address, (ByteBuffer)null, -1, 0, cap, cap);
      }

      Buffer(long address, @Nullable ByteBuffer container, int mark, int pos, int lim, int cap) {
         super(address, container, mark, pos, lim, cap);
      }

      protected Buffer self() {
         return this;
      }

      protected VmaDefragmentationStats getElementFactory() {
         return ELEMENT_FACTORY;
      }

      @NativeType("VkDeviceSize")
      public long bytesMoved() {
         return VmaDefragmentationStats.nbytesMoved(this.address());
      }

      @NativeType("VkDeviceSize")
      public long bytesFreed() {
         return VmaDefragmentationStats.nbytesFreed(this.address());
      }

      @NativeType("uint32_t")
      public int allocationsMoved() {
         return VmaDefragmentationStats.nallocationsMoved(this.address());
      }

      @NativeType("uint32_t")
      public int deviceMemoryBlocksFreed() {
         return VmaDefragmentationStats.ndeviceMemoryBlocksFreed(this.address());
      }
   }
}
