Skip to content

Commit

Permalink
Merge pull request #70 from mycrl/main
Browse files Browse the repository at this point in the history
Added a way to access frame texture
  • Loading branch information
NiiightmareXD authored Aug 5, 2024
2 parents e025aed + b44a711 commit fa261c7
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FrameBuffer, Error> {
/// The ID3D11Texture2D representing the raw texture of the frame.
pub fn texture(&self) -> Result<ID3D11Texture2D, Error> {
// Texture Settings
let texture_desc = D3D11_TEXTURE2D_DESC {
Width: self.width,
Expand All @@ -185,13 +185,25 @@ impl<'a> Frame<'a> {
self.d3d_device
.CreateTexture2D(&texture_desc, None, Some(&mut texture))?;
};

let texture = texture.unwrap();

// Copy the real texture to copy texture
unsafe {
self.context.CopyResource(&texture, &self.frame_texture);
};

Ok(texture)
}

/// Get the frame buffer.
///
/// # Returns
///
/// The FrameBuffer containing the frame data.
pub fn buffer(&mut self) -> Result<FrameBuffer, Error> {
let texture = self.texture()?;

// Map the texture to enable CPU access
let mut mapped_resource = D3D11_MAPPED_SUBRESOURCE::default();
unsafe {
Expand Down

0 comments on commit fa261c7

Please sign in to comment.