Implement create_texture()

This commit is contained in:
Steins7 2024-03-02 21:53:00 +01:00
parent 92e5ff1082
commit f0ab184ea8
2 changed files with 9 additions and 3 deletions

View File

@ -94,10 +94,15 @@ impl Canvas {
unimplemented!(); unimplemented!();
} }
pub fn create_texture(&mut self, _size: Size, _background: Option<Pixel>) pub fn create_texture(&mut self, size: Size, background: Option<Pixel>)
-> Rc<RefCell<Texture>> -> Result<TextureHandle, &'static str>
{ {
unimplemented!(); let buffer = vec!(background.unwrap_or_else(|| Pixel::from(Color::NONE));
(size.w * size.h).try_into().unwrap());
let texture = Texture::create(&self.renderer, &Vec::from(bytemuck::cast_slice(&buffer)),
size);
Ok(TextureHandle::from_texture(texture))
} }
pub fn create_texture_from_file(&mut self, pub fn create_texture_from_file(&mut self,

View File

@ -17,6 +17,7 @@ pub struct Texture {
impl Texture { impl Texture {
//TODO: take buffer's ownership
pub fn create(renderer: &WgpuRenderer, pub fn create(renderer: &WgpuRenderer,
buffer: &[u8], buffer: &[u8],
size: Size) size: Size)