struct Gloop::Buffer
- Gloop::Buffer
- Gloop::Object
- Struct
- Value
- Object
Overview
GPU-hosted storage for arbitrary data.
Most methods in this type used the "named" OpenGL functions.
These utilize DSA (Direct State Access).
They should be used whenever possible, but require OpenGL 4.5 or higher.
If an older version of OpenGL is required, use corresponding methods in BindTarget
instead.
See: https://www.khronos.org/opengl/wiki/Buffer_Object
Included Modules
- Gloop::Parameters
Defined in:
gloop/buffer.crgloop/buffer/access.cr
gloop/buffer/access_mask.cr
gloop/buffer/bind_target.cr
gloop/buffer/map.cr
gloop/buffer/storage.cr
gloop/buffer/target.cr
gloop/buffer/target_map.cr
gloop/buffer/usage.cr
Constructors
-
.create(context) : self
Creates a new buffer.
-
.generate(context) : self
Generates a new buffer.
Class Method Summary
-
.copy(from read_buffer : self, to write_buffer : self, read_offset : Size, write_offset : Size, size : Size) : Nil
Copies a subset of data from one buffer to another.
-
.delete(buffers : Enumerable(self)) : Nil
Deletes multiple buffers.
Instance Method Summary
-
#[](start : Size, count : Size) : Bytes
Retrieves a subset of data from the buffer.
-
#[](range : Range) : Bytes
Retrieves a range of data from the buffer.
-
#[]=(start : Size, count : Size, data)
Updates a subset of the buffer's data store.
-
#[]=(range : Range, data)
Updates a subset of the buffer's data store.
-
#allocate_data(size : Size, usage : Usage = :static_draw) : Nil
Initializes the buffer of a given size with undefined contents.
-
#allocate_storage(size : Size, flags : Storage) : Nil
Initializes the buffer of a given size with undefined contents.
-
#bind(target : Target | BindTarget) : Nil
Binds this buffer to the specified target.
-
#bind(target : Target, &) : Nil
Binds this buffer to the specified target.
-
#bind(target : BindTarget, &)
Binds this buffer to the specified target.
-
#clear : Nil
Sets the contents of the buffer to zero.
-
#copy_from(buffer : self, read_offset : Size, write_offset : Size, size : Size) : Nil
Copies a subset of another buffer into this one.
-
#copy_to(buffer : self, read_offset : Size, write_offset : Size, size : Size) : Nil
Copies a subset of this buffer into another.
-
#data : Bytes
Retrieves all data in the buffer.
-
#data=(data)
Stores data in this buffer.
-
#delete : Nil
Deletes this buffer.
-
#exists?
Checks if the buffer is known by OpenGL.
-
#fill(value : Int8) : Nil
Fills the contents of the buffer to a single value.
-
#fill(value : UInt8) : Nil
Fills the contents of the buffer to a single value.
-
#fill(value : Int16) : Nil
Fills the contents of the buffer to a single value.
-
#fill(value : UInt16) : Nil
Fills the contents of the buffer to a single value.
-
#fill(value : Int32) : Nil
Fills the contents of the buffer to a single value.
-
#fill(value : UInt32) : Nil
Fills the contents of the buffer to a single value.
-
#fill(value : Float32) : Nil
Fills the contents of the buffer to a single value.
-
#flush(start : Size, count : Size) : Nil
Flushes a subset of the mapped buffer to indicate changes have been made.
-
#flush(range : Range) : Nil
Flushes a subset of the mapped buffer to indicate changes have been made.
-
#flush : Nil
Flushes the entire mapped buffer range to indicate changes have been made.
-
#immutable? : Bool
Indicates whether the buffer is immutable (fixed size).
-
#initialize_data(data, usage : Usage = :static_draw) : Nil
Stores data in this buffer.
-
#initialize_storage(data, flags : Storage) : Nil
Stores data in this buffer.
-
#invalidate(start : Size, count : Size) : Nil
Invalidates a subset of the buffer's content.
-
#invalidate(range : Range) : Nil
Invalidates a subset of the buffer's content.
-
#invalidate : Nil
Invalidates the entire content of the buffer.
-
#map(access : AccessMask, start : Size, count : Size) : Bytes
Maps a subset of the buffer's memory into client space.
-
#map(access : AccessMask, range : Range) : Bytes
Maps a subset of the buffer's memory into client space.
-
#map(access : Access) : Bytes
Maps the buffer's memory into client space.
-
#map(access : AccessMask, start : Size, count : Size, & : Bytes -> _) : Bool
Maps a subset of the buffer's memory into client space.
-
#map(access : AccessMask, range : Range, & : Bytes -> _) : Bool
Maps a subset of the buffer's memory into client space.
-
#map(access : Access, & : Bytes -> _) : Bool
Maps the buffer's memory into the client space.
-
#mapped? : Bool
Indicates whether the buffer is currently mapped.
-
#mapping : Map
Retrieves information about the buffer's current map.
-
#mapping? : Map | Nil
Retrieves information about the buffer's current map.
-
#object_type
Indicates that this is a buffer object.
-
#size : Int64
Size of the buffer's contents in bytes.
-
#storage_flags : Gloop::Buffer::Storage
Retrieves the flags previously set for the buffer's immutable storage.
-
#unmap : Bool
Unmaps the buffer's memory from client space.
-
#update(offset : Size, data) : self
Updates a subset of the buffer's data store.
-
#usage : Gloop::Buffer::Usage
Retrieves the usage hints previously provided for the buffer's data.
Instance methods inherited from struct Gloop::Object
context : Context
context,
name : Name
name,
none?
none?,
object_type
object_type,
to_s(io)
to_s,
to_unsafe : UInt32
to_unsafe
Constructor methods inherited from struct Gloop::Object
new(context : Context, name : Name)
new,
none(context) : self
none
Instance methods inherited from module Gloop::Labelable
label : String
label,
label=(label : Nil)label=(label) label=, max_label_size : Int32 max_label_size, name name, object_type object_type
Constructor Detail
Creates a new buffer.
Unlike .generate
, resources are created in advance instead of on the first binding.
- OpenGL function:
glCreateBuffers
- OpenGL version: 4.5
Generates a new buffer.
This ensures a unique name for a buffer object. Resources are not allocated for the buffer until it is bound.
See: .create
- OpenGL function:
glGenBuffers
- OpenGL version: 2.0
Class Method Detail
Copies a subset of data from one buffer to another.
The read_offset indicates the byte offset to start copying from read_buffer. The write_offset indicates the byte offset to start copying into write_buffer. The size is the number of bytes to copy.
See: BindTarget.copy
- OpenGL function:
glCopyNamedBufferSubData
- OpenGL version: 4.5
Deletes multiple buffers.
- OpenGL function:
glDeleteBuffers
- OpenGL version: 2.0
Instance Method Detail
Retrieves a subset of data from the buffer.
NOTE Modifying the data returned by this method will not update the contents of the buffer.
See: BindTarget#[]
- OpenGL function:
glGetNamedBufferSubData
- OpenGL version: 4.5
Retrieves a range of data from the buffer.
NOTE Modifying the data returned by this method will not update the contents of the buffer.
See: BindTarget#[]
- OpenGL function:
glGetNamedBufferSubData
- OpenGL version: 4.5
Updates a subset of the buffer's data store.
The data must have a #to_unsafe
method or be a Pointer
.
Bytes
, Slice
, and StaticArray
types are ideal for this.
NOTE Any length data might have is ignored. Be sure that count is less than or equal to the byte size of data.
See: BindTarget#[]=
- OpenGL function:
glNamedBufferSubData
- OpenGL version: 4.5
Updates a subset of the buffer's data store.
The data must have a #to_unsafe
method or be a Pointer
.
Bytes
, Slice
, and StaticArray
types are ideal for this.
NOTE Any length data might have is ignored. Be sure that the size of range is less than or equal to the byte size of data.
See: BindTarget#[]=
- OpenGL function:
glNamedBufferSubData
- OpenGL version: 4.5
Initializes the buffer of a given size with undefined contents.
- OpenGL function:
glNamedBufferData
- OpenGL version: 4.5
Initializes the buffer of a given size with undefined contents. This makes the buffer have a fixed size (immutable).
See: BindTarget#allocate_storage
- OpenGL function:
glNamedBufferStorage
- OpenGL version: 4.5
Binds this buffer to the specified target.
See: BindTarget#bind
- OpenGL function:
glBindBuffer
- OpenGL version: 2.0
Binds this buffer to the specified target.
The previously bound buffer (if any) is restored after the block completes.
See: BindTarget#bind
- OpenGL function:
glBindBuffer
- OpenGL version: 2.0
Binds this buffer to the specified target.
The previously bound buffer (if any) is restored after the block completes.
See: BindTarget#bind
- OpenGL function:
glBindBuffer
- OpenGL version: 2.0
Sets the contents of the buffer to zero.
- OpenGL function:
glClearNamedBufferData
- OpenGL version: 4.5
Copies a subset of another buffer into this one.
The read_offset indicates the byte offset to start copying from buffer. The write_offset indicates the byte offset to start copying into this buffer. The size is the number of bytes to copy.
See: BindTarget#copy_from
- OpenGL function:
glCopyNamedBufferSubData
- OpenGL version: 4.5
Copies a subset of this buffer into another.
The read_offset indicates the byte offset to start copying from this buffer. The write_offset indicates the byte offset to start copying into buffer. The size is the number of bytes to copy.
See: BindTarget#copy_to
- OpenGL function:
glCopyNamedBufferSubData
- OpenGL version: 4.5
Retrieves all data in the buffer.
NOTE Modifying the data returned by this method will not update the contents of the buffer.
See: BindTarget#data
- OpenGL function:
glGetNamedBufferSubData
- OpenGL version: 4.5
Stores data in this buffer.
The data must have a #to_slice
method.
Bytes
, Slice
, and StaticArray
types are ideal for this.
Previously set #usage
hint is reapplied for this data.
See: BindTarget#data=
- OpenGL function:
glNamedBufferData
- OpenGL version: 4.5
Checks if the buffer is known by OpenGL.
- OpenGL function:
glIsBuffer
- OpenGL version: 2.0
Fills the contents of the buffer to a single value.
The value is repeated throughout the buffer. Ensure the correct numerical type is used.
- OpenGL function:
glClearNamedBufferData
- OpenGL version: 4.5
Fills the contents of the buffer to a single value.
The value is repeated throughout the buffer. Ensure the correct numerical type is used.
- OpenGL function:
glClearNamedBufferData
- OpenGL version: 4.5
Fills the contents of the buffer to a single value.
The value is repeated throughout the buffer. Ensure the correct numerical type is used.
- OpenGL function:
glClearNamedBufferData
- OpenGL version: 4.5
Fills the contents of the buffer to a single value.
The value is repeated throughout the buffer. Ensure the correct numerical type is used.
- OpenGL function:
glClearNamedBufferData
- OpenGL version: 4.5
Fills the contents of the buffer to a single value.
The value is repeated throughout the buffer. Ensure the correct numerical type is used.
- OpenGL function:
glClearNamedBufferData
- OpenGL version: 4.5
Fills the contents of the buffer to a single value.
The value is repeated throughout the buffer. Ensure the correct numerical type is used.
- OpenGL function:
glClearNamedBufferData
- OpenGL version: 4.5
Fills the contents of the buffer to a single value.
The value is repeated throughout the buffer. Ensure the correct numerical type is used.
- OpenGL function:
glClearNamedBufferData
- OpenGL version: 4.5
Flushes a subset of the mapped buffer to indicate changes have been made.
See: BindTarget#flush
- OpenGL function:
glFlushMappedNamedBufferRange
- OpenGL version: 4.5
Flushes a subset of the mapped buffer to indicate changes have been made.
See: BindTarget#flush
- OpenGL function:
glFlushMappedNamedBufferRange
- OpenGL version: 4.5
Flushes the entire mapped buffer range to indicate changes have been made.
See: BindTarget#flush
- OpenGL function:
glFlushMappedNamedBufferRange
- OpenGL version: 4.5
Indicates whether the buffer is immutable (fixed size).
- OpenGL function:
glGetNamedBufferParameteriv
- OpenGL enum:
GL_BUFFER_IMMUTABLE_STORAGE
- OpenGL version: 4.5
Stores data in this buffer.
The data must have a #to_slice
method.
Bytes
, Slice
, and StaticArray
types are ideal for this.
See: BindTarget#initialize_data
- OpenGL function:
glNamedBufferData
- OpenGL version: 4.5
Stores data in this buffer. This makes the buffer have a fixed size (immutable).
The data must have a #to_slice
method.
Bytes
, Slice
, and StaticArray
types are ideal for this.
See: BindTarget#initialize_storage
- OpenGL function:
glNamedBufferStorage
- OpenGL version: 4.5
Invalidates a subset of the buffer's content.
- OpenGL function:
glInvalidateBufferSubData
- OpenGL version: 4.3
Invalidates a subset of the buffer's content.
- OpenGL function:
glInvalidateBufferSubData
- OpenGL version: 4.3
Invalidates the entire content of the buffer.
- OpenGL function:
glInvalidateBufferData
- OpenGL version: 4.3
Maps a subset of the buffer's memory into client space.
See: BindTarget#map
- OpenGL function:
glMapNamedBufferRange
- OpenGL version: 4.5
Maps a subset of the buffer's memory into client space.
See: BindTarget#map
- OpenGL function:
glMapNamedBufferRange
- OpenGL version: 4.5
Maps the buffer's memory into client space.
See: BindTarget#map
- OpenGL function:
glMapNamedBuffer
- OpenGL version: 4.5
Maps a subset of the buffer's memory into client space.
The buffer is automatically unmapped when the block completes. Returns false if the buffer memory was corrupted while it was mapped.
See: BindTarget#map
Maps a subset of the buffer's memory into client space.
The buffer is automatically unmapped when the block completes. Returns false if the buffer memory was corrupted while it was mapped.
See: BindTarget#map
Maps the buffer's memory into the client space.
The buffer is automatically unmapped when the block completes. Returns false if the buffer memory was corrupted while it was mapped.
See: BindTarget#map
Indicates whether the buffer is currently mapped.
See: BindTarget#mapped?
- OpenGL function:
glGetNamedBufferParameteriv
- OpenGL enum:
GL_BUFFER_MAPPED
- OpenGL version: 4.5
Retrieves information about the buffer's current map.
Raises if the buffer isn't mapped.
See: BindTarget#mapping
Retrieves information about the buffer's current map.
Returns nil if the buffer isn't mapped.
See: BindTarget#mapping?
Size of the buffer's contents in bytes.
See: BindTarget#size
- OpenGL function:
glGetNamedBufferParameteri64v
- OpenGL enum:
GL_BUFFER_SIZE
- OpenGL version: 4.5
Retrieves the flags previously set for the buffer's immutable storage.
See: #storage
- OpenGL function:
glGetNamedBufferParameteriv
- OpenGL enum:
GL_BUFFER_STORAGE_FLAGS
- OpenGL version: 4.5
Unmaps the buffer's memory from client space.
Returns false if the buffer memory was corrupted while it was mapped.
See: BindTarget#unmap
- OpenGL function:
glUnmapNamedBuffer
- OpenGL version: 4.5
Updates a subset of the buffer's data store.
The number of bytes updated in the buffer is equal to the byte size of data.
The data must have a #to_slice
.
Bytes
, Slice
, and StaticArray
types are ideal for this.
See: BindTarget#update
- OpenGL function:
glNamedBufferSubData
- OpenGL version: 4.5
Retrieves the usage hints previously provided for the buffer's data.
See: #data
See: BindTarget#usage
- OpenGL function:
glGetNamedBufferParameteriv
- OpenGL enum:
GL_BUFFER_USAGE
- OpenGL version: 4.5