pub struct ShaderStorageBufferObject { /* private fields */ }
Expand description

The Shader Storage Buffer Object

Implementations§

source§

impl ShaderStorageBufferObject

source

pub fn new(binding: u32) -> Result<ShaderStorageBufferObject, ()>

Creates a new Shader Storage Buffer Object with the specified binding.

Arguments
  • binding - The binding point for the SSBO.
Returns

A new instance of ShaderStorageBufferObject with the specified binding, or Err(()) if the creation failed.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let mut ssbo = cgl_rs::graphics::ShaderStorageBufferObject::new(0).unwrap();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn from(data: &[u8], binding: u32) -> Result<ShaderStorageBufferObject, ()>

Creates a new Shader Storage Buffer Object with the specified binding and sets its data to the provided byte slice.

Arguments
  • data - The byte slice containing the data to be set.
  • binding - The binding point for the SSBO.
Returns

A new instance of ShaderStorageBufferObject with the specified binding and data, or Err(()) if the creation failed.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let data = vec![0u8; 1024];
    let ssbo = cgl_rs::graphics::ShaderStorageBufferObject::from(&data, 0).unwrap();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn destroy(&mut self)

Destroys the ssbo and frees its resources. If it has already been destroyed, this method does nothing.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let mut texture = cgl_rs::graphics::Texture::dummy().unwrap();
    texture.destroy(); // optional
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn bind(&self)

Binds the Shader Storage Buffer Object to the current context.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let ssbo = cgl_rs::graphics::ShaderStorageBufferObject::new(0).unwrap();
  ssbo.bind();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn bind2(&mut self, binding: u32)

Binds the Shader Storage Buffer (Base) to the specified binding point.

Arguments
  • binding - The binding point to bind the Shader Storage Buffer Object to.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let mut ssbo = cgl_rs::graphics::ShaderStorageBufferObject::new(0).unwrap();
   ssbo.bind2(1);
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn set_data(&mut self, size: usize, data: *mut u8, static_draw: bool)

Sets the data of the Shader Storage Buffer Object. This also allocates the memory on the GPU if necessary.

If you only want to update a part of the data, use set_sub_data instead.

Arguments
  • size - The size of the data in bytes.
  • data - A pointer to the data.
  • static_draw - A flag indicating whether the data is static or not.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let mut ssbo = cgl_rs::graphics::ShaderStorageBufferObject::new(0).unwrap();
   let data: [u8; 4] = [0, 1, 2, 3];
   ssbo.set_data(data.len(), data.as_ptr() as *mut u8, true);
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
See also
  • set_sub_data
source

pub fn set_sub_data(&mut self, offset: usize, size: usize, data: *mut u8)

Sets a portion of the data of the Shader Storage Buffer Object.

Note: This does not allocate the memory on the GPU if necessary. So, if the data is not allocated on the GPU, this method will do nothing. To allocate the memory on the GPU, use set_data instead.

Arguments
  • offset - The offset in bytes from the beginning of the buffer where the data should be written.
  • size - The size of the data in bytes.
  • data - A pointer to the data.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let mut ssbo = cgl_rs::graphics::ShaderStorageBufferObject::new(0).unwrap();
   let data: [u8; 4] = [0, 1, 2, 3];
   ssbo.set_data(data.len(), data.as_ptr() as *mut u8, true);
   let sub_data: [u8; 2] = [4, 5];
  ssbo.set_sub_data(2, sub_data.len(), sub_data.as_ptr() as *mut u8);
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
See also
  • set_data
source

pub fn get_data(&self) -> Vec<u8>

Gets the entire data of the Shader Storage Buffer Object.

If you only want to get a part of the data, use get_sub_data instead.

Returns

A vector containing the data of the Shader Storage Buffer Object.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let mut ssbo = cgl_rs::graphics::ShaderStorageBufferObject::new(0).unwrap();
    let data: [u8; 4] = [0, 1, 2, 3];
    ssbo.set_data(data.len(), data.as_ptr() as *mut u8, true);
    let retrieved_data = ssbo.get_data();
    assert_eq!(data, retrieved_data.as_slice());
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
See also
  • get_sub_data
source

pub fn get_sub_data(&self, offset: usize, size: usize) -> Vec<u8>

Gets a part of the data of the Shader Storage Buffer Object.

If you want to get the entire data, use get_data instead.

Arguments
  • offset - The offset in bytes from the beginning of the buffer where the data should be read.
  • size - The size of the data in bytes.
Returns

A vector containing the requested part of the data of the Shader Storage Buffer Object.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let mut ssbo = cgl_rs::graphics::ShaderStorageBufferObject::new(0).unwrap();
    let data: [u8; 4] = [0, 1, 2, 3];
    ssbo.set_data(data.len(), data.as_ptr() as *mut u8, true);
    let retrieved_data = ssbo.get_sub_data(1, 2);
    assert_eq!(&data[1..3], retrieved_data.as_slice());
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
See also
  • get_data
source

pub fn size(&self) -> usize

Gets the size of the Shader Storage Buffer Object.

Returns

The size of the Shader Storage Buffer Object in bytes.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let mut ssbo = cgl_rs::graphics::ShaderStorageBufferObject::new(0).unwrap();
   let data: [u8; 4] = [0, 1, 2, 3];
   ssbo.set_data(data.len(), data.as_ptr() as *mut u8, true);
   assert_eq!(data.len(), ssbo.size());
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn copy_to( &self, other: &ShaderStorageBufferObject, src_offset: usize, dst_offset: usize, size: usize )

Copies a part of the data of the Shader Storage Buffer Object to another Shader Storage Buffer Object.

Note: This does not allocate the memory if the destination buffer is not big enough. In such a case nothing will happen.

Arguments
  • other - The destination Shader Storage Buffer Object.
  • src_offset - The offset in bytes from the beginning of the source buffer where the data should be read.
  • dst_offset - The offset in bytes from the beginning of the destination buffer where the data should be written.
  • size - The size of the data in bytes.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let mut ssbo1 = cgl_rs::graphics::ShaderStorageBufferObject::new(0).unwrap();
    let mut ssbo2 = cgl_rs::graphics::ShaderStorageBufferObject::new(0).unwrap();
    let data: [u8; 4] = [0, 1, 2, 3];
    let data2: [u8; 2] = [4, 5];
    ssbo1.set_data(data.len(), data.as_ptr() as *mut u8, true);
    ssbo2.set_data(data2.len(), data2.as_ptr() as *mut u8, true);
    ssbo1.copy_to(&ssbo2, 1, 0, 2);
    let retrieved_data = ssbo2.get_data();
    assert_eq!(&data[1..3], retrieved_data.as_slice());
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn copy_whole_to(&self, other: &ShaderStorageBufferObject)

Copies the entire data of the Shader Storage Buffer Object to another Shader Storage Buffer Object.

Note: This does not allocate the memory if the destination buffer is not big enough. In such a case nothing will happen.

Arguments
  • other - The destination Shader Storage Buffer Object.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let mut ssbo1 = cgl_rs::graphics::ShaderStorageBufferObject::new(0).unwrap();
    let mut ssbo2 = cgl_rs::graphics::ShaderStorageBufferObject::new(0).unwrap();
    let data: [u8; 4] = [0, 1, 2, 3];
    let data2: [u8; 4] = [4, 5, 6, 7];
    ssbo1.set_data(data.len(), data.as_ptr() as *mut u8, true);
    ssbo2.set_data(data2.len(), data2.as_ptr() as *mut u8, true);
    ssbo1.copy_whole_to(&ssbo2);
    let retrieved_data = ssbo2.get_data();
    assert_eq!(data, retrieved_data.as_slice());
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();

Trait Implementations§

source§

impl Clone for ShaderStorageBufferObject

source§

fn clone(&self) -> Self

Clones the ssbo.

NOTE: The new instance will have the same handle, has_been_destroyed flag. This means that the new instance will not be able to receive events nor will the internal window handle be destroyed when the new instance is dropped. The internal window handle will be destroyed when the original instance is dropped.

Returns

A new instance of ShaderStorageBufferObject with the same handle as the original ssbo.

1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Drop for ShaderStorageBufferObject

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.