From be94cec078e86e643f52f0f3041a98b36e43ec8b Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 28 Aug 2026 18:32:58 +0200 Subject: feat(engine): add ability to create textures without images --- engine/src/ui/dear_imgui.rs | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) (limited to 'engine/src/ui/dear_imgui.rs') diff --git a/engine/src/ui/dear_imgui.rs b/engine/src/ui/dear_imgui.rs index b9214d8..d3ca4dc 100644 --- a/engine/src/ui/dear_imgui.rs +++ b/engine/src/ui/dear_imgui.rs @@ -22,13 +22,7 @@ use ecs::time::Time; use ecs::{Component, Query, Sole}; use crate::asset::{Assets, Handle as AssetHandle, Label as AssetLabel}; -use crate::data_types::color::Rgba; use crate::data_types::dimens::Dimens; -use crate::image::{ - Image, - PixelBuffer as ImagePixelBuffer, - PixelBufferLenIncorrectForSize as ImagePixelBufferLenIncorrectForSize, -}; use crate::input::keyboard::{Key, Keyboard}; use crate::input::mouse::{Button as MouseButton, Buttons as MouseButtons, Mouse}; use crate::mesh::vertex_buffer::{ @@ -72,11 +66,12 @@ use crate::rendering::{ SrgbaTextureDataType, Surface, SurfaceId, + TextureCreation, TexturePixelDataFormat, TextureUpdate, PRE_RENDER_PHASE, }; -use crate::texture::{Properties as TextureProperties, Tex2D, Texture}; +use crate::texture::Properties as TextureProperties; use crate::util::MapVec; use crate::vector::Vec2; use crate::windowing::dpi::PhysicalSize; @@ -546,27 +541,19 @@ fn add_drawing_render_pass( "Performing texture operation: Create" ); - let image = - match Image::from_pixels(ImagePixelBuffer::, _>::new( - pixels.as_slice(), - Dimens { width: *width, height: *height }, - )) { - Ok(image) => image, - Err(ImagePixelBufferLenIncorrectForSize) => { - tracing::error!("Not enough texture pixels for texture size"); - continue; - } - }; - let texture_object_id = RenderingObjectId::new_sequential(); - render_pass.commands.push(RenderingCommand::CreateTexture( - texture_object_id, - AssetOrValue::Value(Texture::Texture2D(Tex2D { - image, - properties: TextureProperties::default(), - })), - )); + render_pass.commands.push(RenderingCommand::CreateTexture { + obj_id: texture_object_id, + pixel_data_format: TexturePixelDataFormat::Srgba( + SrgbaTextureDataType::UnsignedByte, + ), + creation: TextureCreation::Texture2D { + size: Dimens { width: *width, height: *height }, + image: Some(pixels.clone().into_boxed_slice()), + }, + properties: TextureProperties::default(), + }); texture_lookup.insert(texture_lookup_id, texture_object_id); -- cgit v1.2.3-18-g5258