Skip to content

Commit

Permalink
Constify SpritePipelineKey implementation. (bevyengine#6976)
Browse files Browse the repository at this point in the history
# Objective

- Describe the objective or issue this PR addresses.
SpritePipelineKey could use more constification.

## Solution
Constify SpritePipelineKey implementation.

## Changelog


Co-authored-by: AxiomaticSemantics <117950168+AxiomaticSemantics@users.noreply.github.com>
  • Loading branch information
2 people authored and alradish committed Jan 22, 2023
1 parent e0cf15d commit 888df77
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions crates/bevy_sprite/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,25 +160,29 @@ impl SpritePipelineKey {
const MSAA_MASK_BITS: u32 = 0b111;
const MSAA_SHIFT_BITS: u32 = 32 - Self::MSAA_MASK_BITS.count_ones();

pub fn from_msaa_samples(msaa_samples: u32) -> Self {
#[inline]
pub const fn from_msaa_samples(msaa_samples: u32) -> Self {
let msaa_bits =
(msaa_samples.trailing_zeros() & Self::MSAA_MASK_BITS) << Self::MSAA_SHIFT_BITS;
Self::from_bits(msaa_bits).unwrap()
Self::from_bits_truncate(msaa_bits)
}

pub fn msaa_samples(&self) -> u32 {
#[inline]
pub const fn msaa_samples(&self) -> u32 {
1 << ((self.bits >> Self::MSAA_SHIFT_BITS) & Self::MSAA_MASK_BITS)
}

pub fn from_colored(colored: bool) -> Self {
#[inline]
pub const fn from_colored(colored: bool) -> Self {
if colored {
SpritePipelineKey::COLORED
} else {
SpritePipelineKey::NONE
}
}

pub fn from_hdr(hdr: bool) -> Self {
#[inline]
pub const fn from_hdr(hdr: bool) -> Self {
if hdr {
SpritePipelineKey::HDR
} else {
Expand Down

0 comments on commit 888df77

Please sign in to comment.