pub struct Texture { /* private fields */ }
Expand description
The texture object
Implementations§
source§impl Texture
impl Texture
sourcepub fn blank_i(
width: i32,
height: i32,
format: u32,
internal_format: u32,
data_type: u32
) -> Result<Texture, &'static str>
pub fn blank_i( width: i32, height: i32, format: u32, internal_format: u32, data_type: u32 ) -> Result<Texture, &'static str>
Creates a new blank texture with the specified dimensions and format.
Arguments
width
- The width of the texture in pixels.height
- The height of the texture in pixels.format
- The format of the texture data.internal_format
- The internal format of the texture data.data_type
- The data type of the texture data.
Returns
A Result
containing the newly created Texture
if successful, or an error message if creation failed.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
let texture = cgl_rs::graphics::Texture::blank_i(256, 256, cgl_rs::graphics::TextureFormat::RGBA as u32, cgl_rs::graphics::TextureInternalFormat::RGBA8UI as u32, cgl_rs::graphics::TextureDataType::UNSIGNED_BYTE as u32).unwrap();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
sourcepub fn blank(
width: i32,
height: i32,
format: TextureFormat,
internal_format: TextureInternalFormat,
data_type: TextureDataType
) -> Result<Texture, &'static str>
pub fn blank( width: i32, height: i32, format: TextureFormat, internal_format: TextureInternalFormat, data_type: TextureDataType ) -> Result<Texture, &'static str>
Creates a new blank texture with the specified dimensions and format.
Arguments
width
- The width of the texture in pixels.height
- The height of the texture in pixels.format
- The format of the texture data.internal_format
- The internal format of the texture data.data_type
- The data type of the texture data.
Returns
A Result
containing the newly created Texture
if successful, or an error message if creation failed.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
let texture = cgl_rs::graphics::Texture::blank(256, 256, cgl_rs::graphics::TextureFormat::RGBA, cgl_rs::graphics::TextureInternalFormat::RGBA8UI, cgl_rs::graphics::TextureDataType::UNSIGNED_BYTE).unwrap();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
sourcepub fn dummy() -> Result<Texture, &'static str>
pub fn dummy() -> Result<Texture, &'static str>
Creates a new dummy texture with a single pixel.
Returns
A Result
containing the newly created Texture
if successful, or an error message if creation failed.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
let texture = cgl_rs::graphics::Texture::dummy().unwrap();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
sourcepub fn dummy2(width: i32, height: i32) -> Result<Texture, &'static str>
pub fn dummy2(width: i32, height: i32) -> Result<Texture, &'static str>
Creates a new dummy texture with the specified dimensions.
Arguments
width
- The width of the texture in pixels.height
- The height of the texture in pixels.
Returns
A Result
containing the newly created Texture
if successful, or an error message if creation failed.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
let texture = cgl_rs::graphics::Texture::dummy2(256, 256).unwrap();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
sourcepub fn array_i(
width: i32,
height: i32,
depth: i32,
format: u32,
internal_format: u32,
data_type: u32
) -> Result<Texture, &'static str>
pub fn array_i( width: i32, height: i32, depth: i32, format: u32, internal_format: u32, data_type: u32 ) -> Result<Texture, &'static str>
Creates a new texture array with the specified dimensions and format.
Arguments
width
- The width of the texture in pixels.height
- The height of the texture in pixels.depth
- The depth of the texture array.format
- The format of the texture data.internal_format
- The internal format of the texture data.data_type
- The data type of the texture data.
Returns
A Result
containing the newly created Texture
if successful, or an error message if creation failed.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
let texture = cgl_rs::graphics::Texture::array_i(256, 256, 6, cgl_rs::graphics::TextureFormat::RGBA as u32, cgl_rs::graphics::TextureInternalFormat::RGBA8UI as u32, cgl_rs::graphics::TextureDataType::UNSIGNED_BYTE as u32).unwrap();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
sourcepub fn array(
width: i32,
height: i32,
depth: i32,
format: TextureFormat,
internal_format: TextureInternalFormat,
data_type: TextureDataType
) -> Result<Texture, &'static str>
pub fn array( width: i32, height: i32, depth: i32, format: TextureFormat, internal_format: TextureInternalFormat, data_type: TextureDataType ) -> Result<Texture, &'static str>
Arguments
width
- The width of the texture in pixels.height
- The height of the texture in pixels.depth
- The depth of the texture array.format
- The format of the texture data.internal_format
- The internal format of the texture data.data_type
- The data type of the texture data.
Returns
A Result
containing the newly created Texture
if successful, or an error message if creation failed.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
let texture = cgl_rs::graphics::Texture::array(256, 256, 6, cgl_rs::graphics::TextureFormat::RGBA, cgl_rs::graphics::TextureInternalFormat::RGBA8UI, cgl_rs::graphics::TextureDataType::UNSIGNED_BYTE).unwrap();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
sourcepub fn cubemap() -> Result<Texture, &'static str>
pub fn cubemap() -> Result<Texture, &'static str>
Creates a new cubemap texture.
Returns
A Result
containing the newly created Texture
if successful, or an error message if creation failed.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
let texture = cgl_rs::graphics::Texture::cubemap().unwrap();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
sourcepub fn array_set_layer_data(&self, layer: i32, data: &[u8])
pub fn array_set_layer_data(&self, layer: i32, data: &[u8])
Sets the data for a single layer of a texture array.
Arguments
layer
- The index of the layer to set the data for.data
- A slice containing the data to set for the layer.
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::array(256, 256, 6, cgl_rs::graphics::TextureFormat::RGBA, cgl_rs::graphics::TextureInternalFormat::RGBA8UI, cgl_rs::graphics::TextureDataType::UNSIGNED_BYTE).unwrap();
let data = vec![0u8; 256 * 256 * 4];
texture.array_set_layer_data(0, &data);
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
sourcepub fn bind(&self, unit: u32)
pub fn bind(&self, unit: u32)
Binds the texture to a texture unit.
Arguments
unit
- The texture unit to bind the texture to.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
let texture = cgl_rs::graphics::Texture::dummy().unwrap();
texture.bind(0);
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
sourcepub fn set_data(&self, data: *const u8)
pub fn set_data(&self, data: *const u8)
Sets the data for the texture.
Arguments
data
- A slice containing the data to set for the texture.
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::dummy2(256, 256).unwrap();
let data = vec![0u8; 256 * 256 * 4];
texture.set_data(data.as_ptr());
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
sourcepub fn set_sub_data(
&self,
x: usize,
y: usize,
width: usize,
height: usize,
data: *const u8
)
pub fn set_sub_data( &self, x: usize, y: usize, width: usize, height: usize, data: *const u8 )
Sets a rectangular subregion of the texture with new data.
Arguments
x
- The x-coordinate of the lower left corner of the subregion.y
- The y-coordinate of the lower left corner of the subregion.width
- The width of the subregion.height
- The height of the subregion.data
- A slice containing the new data to set for the subregion.
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::dummy2(256, 256).unwrap();
let data = vec![255u8; 100 * 100 * 4];
texture.set_sub_data(0, 0, 100, 100, data.as_ptr());
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
sourcepub fn get_internal_gl_handle(&self) -> u32
pub fn get_internal_gl_handle(&self) -> u32
Returns the internal OpenGL handle of the texture.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
let texture = cgl_rs::graphics::Texture::dummy().unwrap();
let handle = texture.get_internal_gl_handle();
println!("Internal OpenGL handle: {}", handle);
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
sourcepub fn set_scaling_method_i(&self, method: i32)
pub fn set_scaling_method_i(&self, method: i32)
Sets the scaling method of the texture.
Arguments
method
- The scaling method to use for the texture.
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::dummy2(256, 256).unwrap();
texture.set_scaling_method_i(1);
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
sourcepub fn set_scaling_method(&self, method: TextureScalingMode)
pub fn set_scaling_method(&self, method: TextureScalingMode)
Arguments
method
- The scaling method to use for the texture.
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::dummy2(256, 256).unwrap();
texture.set_scaling_method(cgl_rs::graphics::TextureScalingMode::LINEAR);
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
sourcepub fn set_wrapping_method_i(&self, method: i32)
pub fn set_wrapping_method_i(&self, method: i32)
Sets the wrapping method of the texture.
Arguments
method
- The wrapping method to use for the texture.
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::dummy2(256, 256).unwrap();
texture.set_wrapping_method_i(1);
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
sourcepub fn set_wrapping_method(&self, method: TextureWrappingMode)
pub fn set_wrapping_method(&self, method: TextureWrappingMode)
Sets the wrapping method of the texture.
Arguments
method
- The wrapping method to use for the texture.
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::dummy2(256, 256).unwrap();
texture.set_wrapping_method(cgl_rs::graphics::TextureWrappingMode::CLAMP_TO_EDGE);
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
sourcepub fn destroy(&mut self)
pub fn destroy(&mut self)
Destroys the texture and frees its resources. If the texture 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();
Trait Implementations§
source§impl Clone for Texture
impl Clone for Texture
source§fn clone(&self) -> Self
fn clone(&self) -> Self
Clones the texture.
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 Texture
with the same handle as the original texture.
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more