From be87af12cbbf3d72dedd94de52829d41e9177a23 Mon Sep 17 00:00:00 2001 From: Lazy Panda Date: Sun, 4 Aug 2024 18:30:19 +0800 Subject: [PATCH 1/2] Update frame.rs --- src/frame.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/frame.rs b/src/frame.rs index 3bf06f3..a18a78d 100644 --- a/src/frame.rs +++ b/src/frame.rs @@ -156,12 +156,12 @@ impl<'a> Frame<'a> { self.frame_surface.clone() } - /// Get the frame buffer. + /// Get the raw texture of the frame. /// /// # Returns /// - /// The FrameBuffer containing the frame data. - pub fn buffer(&mut self) -> Result { + /// The ID3D11Texture2D representing the raw texture of the frame. + pub fn texture(&self) -> Result { // Texture Settings let texture_desc = D3D11_TEXTURE2D_DESC { Width: self.width, @@ -185,7 +185,18 @@ impl<'a> Frame<'a> { self.d3d_device .CreateTexture2D(&texture_desc, None, Some(&mut texture))?; }; + let texture = texture.unwrap(); + Ok(texture) + } + + /// Get the frame buffer. + /// + /// # Returns + /// + /// The FrameBuffer containing the frame data. + pub fn buffer(&mut self) -> Result { + let texture = self.texture()?; // Copy the real texture to copy texture unsafe { From b44a711d560bc68494602a179f46e1db3ce6ccf6 Mon Sep 17 00:00:00 2001 From: Lazy Panda Date: Mon, 5 Aug 2024 17:26:05 +0800 Subject: [PATCH 2/2] fix: not copy resource; --- src/frame.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/frame.rs b/src/frame.rs index a18a78d..2701a7a 100644 --- a/src/frame.rs +++ b/src/frame.rs @@ -187,6 +187,12 @@ impl<'a> Frame<'a> { }; let texture = texture.unwrap(); + + // Copy the real texture to copy texture + unsafe { + self.context.CopyResource(&texture, &self.frame_texture); + }; + Ok(texture) } @@ -198,11 +204,6 @@ impl<'a> Frame<'a> { pub fn buffer(&mut self) -> Result { let texture = self.texture()?; - // Copy the real texture to copy texture - unsafe { - self.context.CopyResource(&texture, &self.frame_texture); - }; - // Map the texture to enable CPU access let mut mapped_resource = D3D11_MAPPED_SUBRESOURCE::default(); unsafe {