Skip to content

Commit

Permalink
Add main_texture_other (bevyengine#7343)
Browse files Browse the repository at this point in the history
# Objective

## Use Case

A render node which calls `post_process_write()` on a `ViewTarget` multiple times during a single run of the node means both main textures of this view target is accessed.

If the source texture (which alternate between main textures **a** and **b**) is accessed in a shader during those iterations it means that those textures have to be bound using bind groups.

Preparing bind groups for both main textures ahead of time is desired, which means having access to the _other_ main texture is needed.

## Solution

Add a method on `ViewTarget` for accessing the other main texture.

---

## Changelog

### Added

- `main_texture_other` API on `ViewTarget`
  • Loading branch information
torsteingrindvik authored and ItsDoot committed Feb 1, 2023
1 parent b1009b3 commit 1b1dc15
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/bevy_render/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,20 @@ impl ViewTarget {
}
}

/// The _other_ "main" unsampled texture.
/// In most cases you should use [`Self::main_texture`] instead and never this.
/// The textures will naturally be swapped when [`Self::post_process_write`] is called.
///
/// A use case for this is to be able to prepare a bind group for all main textures
/// ahead of time.
pub fn main_texture_other(&self) -> &TextureView {
if self.main_texture.load(Ordering::SeqCst) == 0 {
&self.main_textures.b
} else {
&self.main_textures.a
}
}

/// The "main" sampled texture.
pub fn sampled_main_texture(&self) -> Option<&TextureView> {
self.main_textures.sampled.as_ref()
Expand Down

0 comments on commit 1b1dc15

Please sign in to comment.