Package icyllis.arc3d.granite

# Class DrawBufferManager

java.lang.Object
icyllis.arc3d.granite.DrawBufferManager

public class DrawBufferManager extends Object
Manages dynamic and streaming GPU buffers.

This prefers to create a large ring buffer that is host visible and device visible. If not available, creates a large staging buffer and a device local buffer.

For streaming buffers: use persistent mapped host-visible buffers for Vulkan and OpenGL 4.4; use mutable buffer and CPU staging buffer for OpenGL 4.3 and below.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `INDEX_BUFFER_SIZE`
  `static final int`
  `UNIFORM_BUFFER_SIZE`
  `static final int`
  `VERTEX_BUFFER_SIZE`
  We expect buffers for meshes to be at least 128KB.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DrawBufferManager(Caps caps, ResourceProvider resourceProvider)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `alignUniformBlockSize(int dataSize)`
  `void`
  `flush(Consumer<@SharedPtr Task> outTasks, List<@SharedPtr Resource> outResourceRefs)`
  Finalizes all buffers and transfers ownership of them to given list.
  `long`
  `getUniformPointer(int requiredBytes, BufferViewInfo outInfo)`
  Allocate write-combining buffer and return a host coherent memory address.
  `long`
  `getVertexPointer(int requiredBytes, BufferViewInfo outInfo)`
  Allocate write-combining buffer and return a host coherent memory address.
  `boolean`
  `hasMappingFailed()`
  `void`
  `putBackVertexBytes(int unusedBytes)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### VERTEX_BUFFER_SIZE

    public static final int VERTEX_BUFFER_SIZE
    We expect buffers for meshes to be at least 128KB.
    See Also:
      - Constant Field Values

  - ### INDEX_BUFFER_SIZE

    public static final int INDEX_BUFFER_SIZE
    See Also:
      - Constant Field Values

  - ### UNIFORM_BUFFER_SIZE

    public static final int UNIFORM_BUFFER_SIZE
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### DrawBufferManager

    public DrawBufferManager(Caps caps, ResourceProvider resourceProvider)

- ## Method Details

  - ### getVertexPointer

    public long getVertexPointer(int requiredBytes, BufferViewInfo outInfo)
    Allocate write-combining buffer and return a host coherent memory address. Return pointer is 4-byte aligned, if NULL then allocation is failed.
    Parameters:
      `requiredBytes` - vertex stride (4-byte aligned) * count
      `outInfo` - buffer bind info
    Returns:
      write-only address, or NULL

  - ### getUniformPointer

    public long getUniformPointer(int requiredBytes, BufferViewInfo outInfo)
    Allocate write-combining buffer and return a host coherent memory address. The buffer can be used only for uniform buffer. Return pointer is 4-byte aligned according to GPU requirements, if NULL then allocation is failed.
    Parameters:
      `requiredBytes` - uniform buffer size (aligned) * count
      `outInfo` - buffer bind info
    Returns:
      write-only address, or NULL
    See Also:
      - `alignUniformBlockSize(int)`

  - ### putBackVertexBytes

    public void putBackVertexBytes(int unusedBytes)

  - ### alignUniformBlockSize

    public int alignUniformBlockSize(int dataSize)

  - ### hasMappingFailed

    public boolean hasMappingFailed()

  - ### flush

    public void flush(Consumer<@SharedPtr Task> outTasks, List<@SharedPtr Resource> outResourceRefs)
    Finalizes all buffers and transfers ownership of them to given list. Should not call if hasMappingFailed() returns true.
    Parameters:
      `outTasks` - receive tasks
      `outResourceRefs` - receive ownership of resources