Struct webrender::device::gl::Texture

source ·
pub struct Texture {
    id: GLuint,
    target: GLuint,
    format: ImageFormat,
    size: DeviceIntSize,
    filter: TextureFilter,
    flags: TextureFlags,
    active_swizzle: Cell<Swizzle>,
    fbo: Option<FBOId>,
    fbo_with_depth: Option<FBOId>,
    last_frame_used: GpuFrameId,
}
Expand description

WebRender interface to an OpenGL texture.

Because freeing a texture requires various device handles that are not reachable from this struct, manual destruction via Device is required. Our Drop implementation asserts that this has happened.

Fields§

§id: GLuint§target: GLuint§format: ImageFormat§size: DeviceIntSize§filter: TextureFilter§flags: TextureFlags§active_swizzle: Cell<Swizzle>

An internally mutable swizzling state that may change between batches.

§fbo: Option<FBOId>

Framebuffer Object allowing this texture to be rendered to.

Empty if this texture is not used as a render target or if a depth buffer is needed.

§fbo_with_depth: Option<FBOId>

Same as the above, but with a depth buffer attached.

FBOs are cheap to create but expensive to reconfigure (since doing so invalidates framebuffer completeness caching). Moreover, rendering with a depth buffer attached but the depth write+test disabled relies on the driver to optimize it out of the rendering pass, which most drivers probably do but, according to jgilbert, is best not to rely on.

So we lazily generate a second list of FBOs with depth. This list is empty if this texture is not used as a render target or if it is, but the depth buffer has never been requested.

Note that we always fill fbo, and then lazily create fbo_with_depth when needed. We could make both lazy (i.e. render targets would have one or the other, but not both, unless they were actually used in both configurations). But that would complicate a lot of logic in this module, and FBOs are cheap enough to create.

§last_frame_used: GpuFrameId

Implementations§

source§

impl Texture

source

pub fn get_dimensions(&self) -> DeviceIntSize

source

pub fn get_format(&self) -> ImageFormat

source

pub fn get_filter(&self) -> TextureFilter

source

pub fn get_target(&self) -> ImageBufferKind

source

pub fn supports_depth(&self) -> bool

source

pub fn last_frame_used(&self) -> GpuFrameId

source

pub fn used_in_frame(&self, frame_id: GpuFrameId) -> bool

source

pub fn is_render_target(&self) -> bool

source

pub fn used_recently( &self, current_frame_id: GpuFrameId, threshold: usize, ) -> bool

Returns true if this texture was used within threshold frames of the current frame.

source

pub fn flags(&self) -> &TextureFlags

Returns the flags for this texture.

source

pub fn flags_mut(&mut self) -> &mut TextureFlags

Returns a mutable borrow of the flags for this texture.

source

pub fn size_in_bytes(&self) -> usize

Returns the number of bytes (generally in GPU memory) that this texture consumes.

Trait Implementations§

source§

impl Debug for Texture

source§

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

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

impl Drop for Texture

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.