Class SsboBufferImpl

java.lang.Object
cz.fidentis.analyst.glsl.buffers.impl.AbstractBuffer
cz.fidentis.analyst.glsl.buffers.impl.SsboBufferImpl
All Implemented Interfaces:
GlslBuffer, SsboBuffer
Direct Known Subclasses:
AtomicCounterBufferImpl

public class SsboBufferImpl extends AbstractBuffer implements SsboBuffer
Shader storage buffer objects (SSBO) for the GL_SHADER_STORAGE_BUFFER target. In the buffer definition enum, you must specify on which SSBO binding index should your buffer be bound to when used. (this is the same binding index as defined in your shader source code)
  • Constructor Details

    • SsboBufferImpl

      public SsboBufferImpl(BufferDef bufferName, com.jogamp.opengl.GLContext glContext, int usage, long itemSize)
      Constructor.
      Parameters:
      bufferName - buffer name
      glContext - OpenGL context
      usage - OpenGL usage type
      itemSize - The size of buffer's items
    • SsboBufferImpl

      protected SsboBufferImpl(BufferDef bufferName, com.jogamp.opengl.GLContext glContext, int usage, long itemSize, int target)
      Constructor.
      Parameters:
      bufferName - buffer name
      glContext - OpenGL context
      usage - OpenGL usage type
      itemSize - The size of buffer's items
      target - OpenGL target
  • Method Details

    • bind

      public void bind()
      Description copied from interface: GlslBuffer
      Binds this buffer to the OpenGL context (binding points of GPU rendering pipeline), so it become visible for shaders. Buffers can be bound to their binding points even unallocated. Do not use this method directly. As every buffer should be included in a GlslBufferGroup, use GlslBufferGroup.bindBuffer(cz.fidentis.analyst.glsl.buffers.BufferDef) to bind buffers individually or GlslBufferGroup.bindSsboBuffers() to allocate all SSBO buffers at once.
      Specified by:
      bind in interface GlslBuffer
    • allocate

      public void allocate(long items, boolean reset)
      Description copied from interface: SsboBuffer
      Allocates memory for this SSBO buffer on GPU. Can be used multiple times to resize the buffer. You can allocate space for unbound buffer and vice versa. Resulting buffer will occupy items * SsboBuffer.getItemSize() bytes.
      Specified by:
      allocate in interface SsboBuffer
      Parameters:
      items - how many items are going to be stored in the buffer
      reset - if true, then the buffer is filled with zeros
    • allocate

      public void allocate(long items, long extraSpace, boolean reset)
      Description copied from interface: SsboBuffer
      Allocates memory for this SSBO buffer on GPU. Can be used multiple times to resize the buffer. You can allocate space for unbound buffer and vice versa. Resulting buffer will occpy items * SsboBuffer.getItemSize() + extraSpace bytes.
      Specified by:
      allocate in interface SsboBuffer
      Parameters:
      items - how many items are going to be stored in the buffer. Can be zero.
      extraSpace - extra space. Can be zero.
      reset - if true, then the buffer is filled with zeros
    • writeItemsTo

      public void writeItemsTo(long offset, long numItems, Consumer<ByteBuffer> filler)
      Description copied from interface: SsboBuffer
      Writes data to the buffer. The size of written data is numItemes * SsboBuffer.getItemSize(). Buffer must be already allocated and have sufficient size, otherwise GL error is thrown.
      Specified by:
      writeItemsTo in interface SsboBuffer
      Parameters:
      offset - numItems offset (numItems to be skipped). Can be zero
      numItems - how many numItems we want to write
      filler - filler that writes data to the buffer
    • writeBytesTo

      public void writeBytesTo(long offset, long size, Consumer<ByteBuffer> filler)
      Description copied from interface: SsboBuffer
      Writes data to the buffer. Buffer must be already allocated and have sufficient size, otherwise GL error is thrown.
      Specified by:
      writeBytesTo in interface SsboBuffer
      Parameters:
      offset - number of bytes to be skipped. Can be zero
      size - how many bytes to write
      filler - filler that writes data to the buffer
    • readFrom

      public void readFrom(long offset, long items, Consumer<ByteBuffer> reader)
      Description copied from interface: SsboBuffer
      Reads data from the buffer. Buffer must be already allocated and have sufficient size, otherwise GL error is thrown.
      Specified by:
      readFrom in interface SsboBuffer
      Parameters:
      offset - items offset (items to be skipped). Can be zero
      items - how many items we want to read
      reader - reader that reads the data from the buffer
    • getUsage

      public int getUsage()
      Description copied from interface: SsboBuffer
      Returns buffer's usage type
      Specified by:
      getUsage in interface SsboBuffer
      Returns:
      usage type
    • getItemSize

      public long getItemSize()
      Description copied from interface: SsboBuffer
      SSBO buffers typically store some amount of items of the same type (integers, floats, etc.). This method returns the size (number of bytes) of a single item.
      Specified by:
      getItemSize in interface SsboBuffer
      Returns:
      items' size