Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a way to access frame texture #70

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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