pub trait Buffer: Downcast {
// Required methods
fn usage(&self) -> BufferUsage;
fn kind(&self) -> BufferKind;
fn size(&self) -> usize;
fn write_data(&self, data: &[u8]) -> Result<(), FrameworkError>;
fn read_data(&self, data: &mut [u8]) -> Result<(), FrameworkError>;
}
Expand description
Buffer is a type-agnostic data storage located directly in GPU memory. It could be considered as a data block which content is a pile of bytes, whose meaning is defined externally.
§Example
The following example shows how to create a uniform buffer, that could be used for rendering a static object.
use fyrox_graphics::{
buffer::{Buffer, BufferKind, BufferUsage},
core::{algebra::Vector3, color::Color},
error::FrameworkError,
server::GraphicsServer,
uniform::DynamicUniformBuffer,
};
fn create_buffer(server: &dyn GraphicsServer) -> Result<Box<dyn Buffer>, FrameworkError> {
let uniforms = DynamicUniformBuffer::new()
.with(&Vector3::new(1.0, 2.0, 3.0))
.with(&Color::WHITE)
.with(&123.0f32)
.finish();
let buffer =
server.create_buffer(uniforms.len(), BufferKind::Uniform, BufferUsage::StaticDraw)?;
buffer.write_data(&uniforms)?;
Ok(buffer)
}
Required Methods§
Sourcefn usage(&self) -> BufferUsage
fn usage(&self) -> BufferUsage
Returns usage kind of the buffer.
Sourcefn kind(&self) -> BufferKind
fn kind(&self) -> BufferKind
Returns buffer kind.
Sourcefn write_data(&self, data: &[u8]) -> Result<(), FrameworkError>
fn write_data(&self, data: &[u8]) -> Result<(), FrameworkError>
Writes an arbitrary number of bytes from the given slice.
Implementations§
Source§impl dyn Buffer
impl dyn Buffer
Sourcepub fn write_data_of_type<T>(&self, data: &[T]) -> Result<(), FrameworkError>where
T: Pod,
pub fn write_data_of_type<T>(&self, data: &[T]) -> Result<(), FrameworkError>where
T: Pod,
Tries to write typed data to the buffer. The data type must implement Pod
trait for
safe usage.
Sourcepub fn read_data_of_type<T>(&self, data: &mut [T]) -> Result<(), FrameworkError>where
T: Pod,
pub fn read_data_of_type<T>(&self, data: &mut [T]) -> Result<(), FrameworkError>where
T: Pod,
Tries to read data from the buffer and convert them to the given type. The data type must
implement Pod
trait for safe usage. The amount of the data that will be attempted to
read is defined by the length of the given slice.