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
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 Summary
ConstructorsModifierConstructorDescriptionSsboBufferImpl
(BufferDef bufferName, com.jogamp.opengl.GLContext glContext, int usage, long itemSize) Constructor.protected
SsboBufferImpl
(BufferDef bufferName, com.jogamp.opengl.GLContext glContext, int usage, long itemSize, int target) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
allocate
(long items, boolean reset) Allocates memory for this SSBO buffer on GPU.void
allocate
(long items, long extraSpace, boolean reset) Allocates memory for this SSBO buffer on GPU.void
bind()
Binds this buffer to the OpenGL context (binding points of GPU rendering pipeline), so it become visible for shaders.long
SSBO buffers typically store some amount of items of the same type (integers, floats, etc.).int
getUsage()
Returns buffer's usage typevoid
readFrom
(long offset, long items, Consumer<ByteBuffer> reader) Reads data from the buffer.void
writeBytesTo
(long offset, long size, Consumer<ByteBuffer> filler) Writes data to the buffer.void
writeItemsTo
(long offset, long numItems, Consumer<ByteBuffer> filler) Writes data to the buffer.Methods inherited from class cz.fidentis.analyst.glsl.buffers.impl.AbstractBuffer
getBindingIndex, getBufferName, getGlName, getGlTarget, glContext, setGlName
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface cz.fidentis.analyst.glsl.buffers.GlslBuffer
getBindingIndex, getBufferName, getGlName, getGlTarget, glContext
-
Constructor Details
-
SsboBufferImpl
public SsboBufferImpl(BufferDef bufferName, com.jogamp.opengl.GLContext glContext, int usage, long itemSize) Constructor.- Parameters:
bufferName
- buffer nameglContext
- OpenGL contextusage
- OpenGL usage typeitemSize
- 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 nameglContext
- OpenGL contextusage
- OpenGL usage typeitemSize
- The size of buffer's itemstarget
- 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 aGlslBufferGroup
, useGlslBufferGroup.bindBuffer(cz.fidentis.analyst.glsl.buffers.BufferDef)
to bind buffers individually orGlslBufferGroup.bindSsboBuffers()
to allocate all SSBO buffers at once.- Specified by:
bind
in interfaceGlslBuffer
-
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 occupyitems *
SsboBuffer.getItemSize()
bytes.- Specified by:
allocate
in interfaceSsboBuffer
- Parameters:
items
- how many items are going to be stored in the bufferreset
- iftrue
, 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 occpyitems *
SsboBuffer.getItemSize()
+ extraSpace
bytes.- Specified by:
allocate
in interfaceSsboBuffer
- Parameters:
items
- how many items are going to be stored in the buffer. Can be zero.extraSpace
- extra space. Can be zero.reset
- iftrue
, then the buffer is filled with zeros
-
writeItemsTo
Description copied from interface:SsboBuffer
Writes data to the buffer. The size of written data isnumItemes *
SsboBuffer.getItemSize()
. Buffer must be already allocated and have sufficient size, otherwise GL error is thrown.- Specified by:
writeItemsTo
in interfaceSsboBuffer
- Parameters:
offset
- numItems offset (numItems
to be skipped). Can be zeronumItems
- how many numItems we want to writefiller
- filler that writes data to the buffer
-
writeBytesTo
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 interfaceSsboBuffer
- Parameters:
offset
- number of bytes to be skipped. Can be zerosize
- how many bytes to writefiller
- filler that writes data to the buffer
-
readFrom
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 interfaceSsboBuffer
- Parameters:
offset
- items offset (items to be skipped). Can be zeroitems
- how many items we want to readreader
- 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 interfaceSsboBuffer
- 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 interfaceSsboBuffer
- Returns:
- items' size
-