Struct glium::texture::Texture2d

source ·
pub struct Texture2d(_);
Expand description

A two-dimensional texture containing floating-point data.

Implementations§

source§

impl Texture2d

source

pub fn sampled(&self) -> Sampler<'_, Texture2d>

Builds a Sampler marker object that allows you to indicate how the texture should be sampled from inside a shader.

Example
let uniforms = uniform! {
    color_texture: texture.sampled().magnify_filter(glium::uniforms::MagnifySamplerFilter::Nearest)
};
source§

impl Texture2d

source

pub fn image_unit( &self, format: ImageUnitFormat ) -> Result<ImageUnit<'_, Texture2d>, ImageUnitError>

Builds an image unit marker object that allows you to indicate how the texture should be bound to an image unit.

source§

impl Texture2d

source

pub fn get_internal_format(&self) -> Result<InternalFormat, GetFormatError>

Determines the internal format of this texture.

The backend may not support querying the actual format, in which case an error is returned.

source

pub fn new<'a, F, T>( facade: &F, data: T ) -> Result<Texture2d, TextureCreationError>where T: Texture2dDataSource<'a>, F: Facade + ?Sized,

Builds a new texture by uploading data.

This function will automatically generate all mipmaps of the texture.

source

pub fn with_mipmaps<'a, F, T>( facade: &F, data: T, mipmaps: MipmapsOption ) -> Result<Texture2d, TextureCreationError>where T: Texture2dDataSource<'a>, F: Facade + ?Sized,

Builds a new texture by uploading data.

source

pub fn with_format<'a, F, T>( facade: &F, data: T, format: UncompressedFloatFormat, mipmaps: MipmapsOption ) -> Result<Texture2d, TextureCreationError>where T: Texture2dDataSource<'a>, F: Facade + ?Sized,

Builds a new texture with a specific format.

source

pub fn empty<F>( facade: &F, width: u32, height: u32 ) -> Result<Texture2d, TextureCreationError>where F: Facade + ?Sized,

Creates an empty texture.

No mipmap level (except for the main level) will be allocated or generated.

The texture will contain undefined data.

source

pub fn empty_with_format<F>( facade: &F, format: UncompressedFloatFormat, mipmaps: MipmapsOption, width: u32, height: u32 ) -> Result<Texture2d, TextureCreationError>where F: Facade + ?Sized,

Creates an empty texture with a specific format.

The texture (and its mipmaps) will contain undefined data.

source

pub fn empty_with_mipmaps<F>( facade: &F, mipmaps: MipmapsOption, width: u32, height: u32 ) -> Result<Texture2d, TextureCreationError>where F: Facade + ?Sized,

Creates an empty texture. Specifies whether is has mipmaps.

The texture (and its mipmaps) will contain undefined data.

source

pub unsafe fn from_id<F: Facade + ?Sized>( facade: &F, format: UncompressedFloatFormat, id: c_uint, owned: bool, mipmap: MipmapsOption, ty: Dimensions ) -> Texture2d

Builds a new texture reference from an existing, externally created OpenGL texture. If owned is true, this reference will take ownership of the texture and be responsible for cleaning it up. Otherwise, the texture must be cleaned up externally, but only after this reference’s lifetime has ended.

source

pub unsafe fn new_from_fd<F: Facade + ?Sized>( facade: &F, format: UncompressedFloatFormat, mipmaps: MipmapsOption, ty: Dimensions, params: ImportParameters, fd: File ) -> Result<Texture2d, TextureImportError>

Builds a new texture reference from an existing texture, externally created by a foreign API like Vulkan. The texture is imported via an opaque file descriptor. You must make sure all of the texture parameters match those used to create the texture in Vulkan.

source

pub fn width(&self) -> u32

Returns the width of that image.

source

pub fn height(&self) -> u32

Returns the height of that image.

source

pub fn dimensions(&self) -> (u32, u32)

Returns the width and height of that image.

source

pub fn as_surface<'a>(&'a self) -> SimpleFrameBuffer<'a>

Starts drawing on the texture.

All the function calls to the framebuffer will draw on the texture instead of the screen.

Low-level information

The first time that this function is called, a FrameBuffer Object will be created and cached. The following calls to as_surface will load the existing FBO and re-use it. When the texture is destroyed, the FBO is destroyed too.

source

pub fn sync_shader_writes_for_surface(&self)

Call this function if you write to this texture in a shader with Image Store operations, and you want to use the texture as a Surface or Framebuffer Object.

This function issues a memory barrier if the texture has been written to in a shader via Image Store operations.

source

pub fn get_mipmap_levels(&self) -> u32

Returns the number of mipmap levels of the texture.

The minimum value is 1, since there is always a main texture.

source

pub fn read<T>(&self) -> Twhere T: Texture2dDataSink<(u8, u8, u8, u8)>,

Reads the content of the texture to RAM. This method may only read U8U8U8U8 data, as it is the only format guaranteed to be supported across all OpenGL versions.

You should avoid doing this at all cost during performance-critical operations (for example, while you’re drawing). Use read_to_pixel_buffer instead.

source

pub fn read_to_pixel_buffer(&self) -> PixelBuffer<(u8, u8, u8, u8)>

Reads the content of the texture into a buffer in video memory. This method may only read U8U8U8U8 data, as it is the only format guaranteed to be supported across all OpenGL versions.

This operation copies the texture’s data into a buffer in video memory (a pixel buffer). Contrary to the read function, this operation is done asynchronously and doesn’t need a synchronization.

source

pub unsafe fn unchecked_read<T, P>(&self) -> Twhere T: Texture2dDataSink<P>, P: PixelValue,

Unsafely reads the content of the texture to RAM in the specified pixel format. It is possible that the current OpenGL context does not support the given format, in which case the returned data will be invalid.

You should avoid doing this at all cost during performance-critical operations (for example, while you’re drawing). Use read_to_pixel_buffer instead.

source

pub unsafe fn unchecked_read_to_pixel_buffer<P>(&self) -> PixelBuffer<P>where P: PixelValue,

Unsafely reads the content of the texture into a buffer in video memory. It is possible that the current OpenGL context does not support the given format, in which case the returned data will be invalid.

This operation copies the texture’s data into a buffer in video memory (a pixel buffer). Contrary to the read function, this operation is done asynchronously and doesn’t need a synchronization.

source

pub fn write<'a, T>(&self, rect: Rect, data: T)where T: Texture2dDataSource<'a>,

Uploads some data in the texture.

Note that this may cause a synchronization if you use the texture right before or right after this call. Prefer creating a whole new texture if you change a huge part of it.

Panic

Panics if the the dimensions of data don’t match the Rect.

source

pub fn resident( self ) -> Result<ResidentTexture, BindlessTexturesNotSupportedError>

Turns the texture into a ResidentTexture.

This allows you to use the texture in a much more efficient way by storing a “reference to it” in a buffer (actually not a reference but a raw pointer).

See the documentation of ResidentTexture for more infos.

source

pub fn mipmap(&self, level: u32) -> Option<Texture2dMipmap<'_>>

Access a single mipmap level of this texture.

source

pub fn main_level(&self) -> Texture2dMipmap<'_>

Access the main mipmap level of this texture.

Methods from Deref<Target = TextureAny>§

source

pub fn get_width(&self) -> u32

Returns the width of the texture.

source

pub fn get_height(&self) -> Option<u32>

Returns the height of the texture.

source

pub fn get_depth(&self) -> Option<u32>

Returns the depth of the texture.

source

pub fn kind(&self) -> TextureKind

Returns the kind of texture.

source

pub fn dimensions(&self) -> Dimensions

Returns the dimensions of the texture.

source

pub fn get_array_size(&self) -> Option<u32>

Returns the array size of the texture.

source

pub fn get_samples(&self) -> Option<u32>

Returns the number of samples of the texture if it is a multisampling texture.

source

pub fn first_layer(&self) -> TextureAnyLayer<'_>

Returns a structure that represents the first layer of the texture. All textures have a first layer.

source

pub fn layer(&self, layer: u32) -> Option<TextureAnyLayer<'_>>

Returns a structure that represents a specific layer of the texture.

Non-array textures have only one layer. The number of layers can be queried with get_array_size.

Returns None if out of range.

source

pub fn get_texture_type(&self) -> Dimensions

Returns the type of the texture (1D, 2D, 3D, etc.).

source

pub fn get_internal_format(&self) -> Result<InternalFormat, GetFormatError>

Determines the internal format of this texture.

source

pub fn get_depth_stencil_bits(&self) -> (u16, u16)

Determines the number of depth and stencil bits in the format of this texture.

source

pub fn get_mipmap_levels(&self) -> u32

Returns the number of mipmap levels of the texture.

source

pub fn main_level(&self) -> TextureAnyMipmap<'_>

Returns a structure that represents the main mipmap level of the texture.

source

pub fn mipmap(&self, level: u32) -> Option<TextureAnyMipmap<'_>>

Returns a structure that represents a specific mipmap of the texture.

Returns None if out of range.

source

pub unsafe fn generate_mipmaps(&self)

Binds this texture and generates mipmaps.

Trait Implementations§

source§

impl<'a> AsUniformValue for &'a Texture2d

source§

fn as_uniform_value(&self) -> UniformValue<'_>

Builds a UniformValue.
source§

impl AsUniformValue for Texture2d

source§

fn as_uniform_value(&self) -> UniformValue<'_>

Builds a UniformValue.
source§

impl Debug for Texture2d

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Deref for Texture2d

§

type Target = TextureAny

The resulting type after dereferencing.
source§

fn deref<'a>(&'a self) -> &'a TextureAny

Dereferences the value.
source§

impl GlObject for Texture2d

§

type Id = u32

The type of identifier for this object.
source§

fn get_id(&self) -> c_uint

Returns the id of the object.
source§

impl<'t> ToColorAttachment<'t> for &'t Texture2d

source§

fn to_color_attachment(self) -> ColorAttachment<'t>

Builds the ColorAttachment.

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, 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.