pub struct TextureData { /* private fields */ }Expand description
Texture data managed by Dear ImGui
This is a wrapper around ImTextureData that provides safe access to texture information and pixel data. It’s used by renderer backends to create, update, and destroy textures.
Lifecycle & Backend Flow (ImGui 1.92+)
- Create an instance (e.g. via
OwnedTextureData::new()+create()) - Mutate pixels, set flags/rects (e.g. call
set_data()or directly writePixelsthen setUpdateRect), and set status toWantCreate/WantUpdates. - Register user-created owned textures once via
Context::register_user_texture(&mut tex). Dear ImGui buildsDrawData::textures()from its internalPlatformIO.Textures[]list (font atlas textures are registered by ImGui itself). - Your renderer backend iterates
DrawData::textures_mut()and performs the requested create/update/destroy operations, then updates status toOK/Destroyed. - You can also set/get a
TexID(e.g., GPU handle) viaset_tex_id()/tex_id()after creation.
Lifetime Note: If using the managed path, you must keep the underlying ImTextureData alive at
least until the end of the frame where it is referenced by UI calls. If you create textures
yourself, use OwnedTextureData to ensure the object is correctly constructed and destroyed
by the C++ side.
Implementations§
Source§impl TextureData
impl TextureData
Sourcepub fn new() -> OwnedTextureData
pub fn new() -> OwnedTextureData
Create a new owned texture data object.
This is kept for convenience. Prefer OwnedTextureData::new() for clarity.
Sourcepub fn as_raw(&self) -> *const ImTextureData
pub fn as_raw(&self) -> *const ImTextureData
Get the raw pointer to the underlying ImTextureData
Sourcepub fn as_raw_mut(&mut self) -> *mut ImTextureData
pub fn as_raw_mut(&mut self) -> *mut ImTextureData
Get the raw mutable pointer to the underlying ImTextureData
Sourcepub fn unique_id(&self) -> ManagedTextureId
pub fn unique_id(&self) -> ManagedTextureId
Get this managed texture’s stable ImGui identity.
Sourcepub fn status(&self) -> TextureStatus
pub fn status(&self) -> TextureStatus
Get the current status of this texture
Sourcepub fn set_status(&mut self, status: TextureStatus)
pub fn set_status(&mut self, status: TextureStatus)
Set the status of this texture
This should only be called by renderer backends after handling a request.
Sourcepub fn backend_user_data(&self) -> *mut c_void
pub fn backend_user_data(&self) -> *mut c_void
Get the backend user data
Sourcepub fn set_backend_user_data(&mut self, data: *mut c_void)
pub fn set_backend_user_data(&mut self, data: *mut c_void)
Set the backend user data
Sourcepub fn set_tex_id(&mut self, tex_id: TextureId)
pub fn set_tex_id(&mut self, tex_id: TextureId)
Set the texture ID
This should only be called by renderer backends after creating or destroying the texture.
Sourcepub fn texture_ref(&mut self) -> TextureRef<'_>
pub fn texture_ref(&mut self) -> TextureRef<'_>
Get the current texture reference for this managed texture.
Sourcepub fn format(&self) -> TextureFormat
pub fn format(&self) -> TextureFormat
Get the texture format
Sourcepub fn bytes_per_pixel(&self) -> usize
pub fn bytes_per_pixel(&self) -> usize
Get the bytes per pixel
Sourcepub fn unused_frames(&self) -> usize
pub fn unused_frames(&self) -> usize
Get the number of unused frames
Sourcepub fn use_colors(&self) -> bool
pub fn use_colors(&self) -> bool
Check if the texture uses colors (rather than just white + alpha)
Sourcepub fn want_destroy_next_frame(&self) -> bool
pub fn want_destroy_next_frame(&self) -> bool
Check if the texture is queued for destruction next frame
Sourcepub fn pixels(&self) -> Option<&[u8]>
pub fn pixels(&self) -> Option<&[u8]>
Get the pixel data
Returns None if no pixel data is available.
Sourcepub fn used_rect(&self) -> TextureRect
pub fn used_rect(&self) -> TextureRect
Get the bounding box of all used pixels in the texture
Sourcepub fn update_rect(&self) -> TextureRect
pub fn update_rect(&self) -> TextureRect
Get the bounding box of all queued updates
Sourcepub fn updates(&self) -> impl Iterator<Item = TextureRect> + '_
pub fn updates(&self) -> impl Iterator<Item = TextureRect> + '_
Iterate over queued update rectangles (copying to safe TextureRect)
Sourcepub fn pixels_at(&self, x: u32, y: u32) -> Option<&[u8]>
pub fn pixels_at(&self, x: u32, y: u32) -> Option<&[u8]>
Get the pixel data at a specific position
Returns None if no pixel data is available or coordinates are out of bounds.
Sourcepub fn create(&mut self, format: TextureFormat, width: u32, height: u32)
pub fn create(&mut self, format: TextureFormat, width: u32, height: u32)
Create a new texture with the specified format and dimensions
This allocates pixel data and sets the status to WantCreate.
Sourcepub fn destroy_pixels(&mut self)
pub fn destroy_pixels(&mut self)
Destroy the pixel data
This frees the CPU-side pixel data but doesn’t affect the GPU texture.
Sourcepub fn set_data(&mut self, data: &[u8])
pub fn set_data(&mut self, data: &[u8])
Set the pixel data for the texture
This copies the provided data into the texture’s pixel buffer.
Sourcepub fn set_height(&mut self, height: u32)
pub fn set_height(&mut self, height: u32)
Set the height of the texture
Sourcepub fn set_format(&mut self, format: TextureFormat)
pub fn set_format(&mut self, format: TextureFormat)
Set the format of the texture