Skip to content

Commit 12f3400

Browse files
authored
Avoid taking mutable references when filling/creating render targets from textures (asny#555)
* Avoid &mut self in textures * Remove muts * Fix headless lint
1 parent 3d967a6 commit 12f3400

File tree

18 files changed

+35
-35
lines changed

18 files changed

+35
-35
lines changed

examples/headless/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn main() {
3939
);
4040

4141
// Create a color texture to render into
42-
let mut texture = Texture2D::new_empty::<[u8; 4]>(
42+
let texture = Texture2D::new_empty::<[u8; 4]>(
4343
&context,
4444
viewport.width,
4545
viewport.height,
@@ -51,7 +51,7 @@ fn main() {
5151
);
5252

5353
// Also create a depth texture to support depth testing
54-
let mut depth_texture = DepthTexture2D::new::<f32>(
54+
let depth_texture = DepthTexture2D::new::<f32>(
5555
&context,
5656
viewport.width,
5757
viewport.height,

examples/image/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub async fn run() {
8888
..Default::default()
8989
};
9090

91-
let mut target = Texture2D::new_empty::<[f16; 4]>(
91+
let target = Texture2D::new_empty::<[f16; 4]>(
9292
&context,
9393
viewport.width,
9494
viewport.height,

examples/multisample/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub fn main() {
134134

135135
RenderMethod::ToTexture => {
136136
// Render the shapes to a non-multisample texture, and copy the color texture to the screen.
137-
let mut color_texture = Texture2D::new_empty::<[u8; 4]>(
137+
let color_texture = Texture2D::new_empty::<[u8; 4]>(
138138
&context,
139139
frame_input.viewport.width,
140140
frame_input.viewport.height,
@@ -144,7 +144,7 @@ pub fn main() {
144144
Wrapping::ClampToEdge,
145145
Wrapping::ClampToEdge,
146146
);
147-
let mut depth_texture = DepthTexture2D::new::<f32>(
147+
let depth_texture = DepthTexture2D::new::<f32>(
148148
&context,
149149
frame_input.viewport.width,
150150
frame_input.viewport.height,

src/core/render_target/color_target_multisample.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<C: TextureDataType> ColorTargetMultisample<C> {
108108
/// Use [ColorTargetMultisample::resolve_to] to resolve to a custom non-multisample texture.
109109
///
110110
pub fn resolve(&self) -> Texture2D {
111-
let mut color_texture = Texture2D::new_empty::<C>(
111+
let color_texture = Texture2D::new_empty::<C>(
112112
&self.context,
113113
self.width(),
114114
self.height(),

src/core/render_target/depth_target_multisample.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<D: DepthTextureDataType> DepthTargetMultisample<D> {
105105
/// Use [DepthTargetMultisample::resolve_to] to resolve to a custom non-multisample texture.
106106
///
107107
pub fn resolve(&self) -> DepthTexture2D {
108-
let mut depth_texture = DepthTexture2D::new::<D>(
108+
let depth_texture = DepthTexture2D::new::<D>(
109109
&self.context,
110110
self.width(),
111111
self.height(),

src/core/render_target/multisample.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<C: TextureDataType, D: DepthTextureDataType> RenderTargetMultisample<C, D>
129129
/// Use [RenderTargetMultisample::resolve_color_to] to resolve to a custom non-multisample texture.
130130
///
131131
pub fn resolve_color(&self) -> Texture2D {
132-
let mut color_texture = Texture2D::new_empty::<C>(
132+
let color_texture = Texture2D::new_empty::<C>(
133133
&self.context,
134134
self.color.width(),
135135
self.color.height(),
@@ -148,7 +148,7 @@ impl<C: TextureDataType, D: DepthTextureDataType> RenderTargetMultisample<C, D>
148148
/// Use [RenderTargetMultisample::resolve_depth_to] to resolve to a custom non-multisample texture.
149149
///
150150
pub fn resolve_depth(&self) -> DepthTexture2D {
151-
let mut depth_texture = DepthTexture2D::new::<D>(
151+
let depth_texture = DepthTexture2D::new::<D>(
152152
&self.context,
153153
self.width(),
154154
self.height(),
@@ -164,7 +164,7 @@ impl<C: TextureDataType, D: DepthTextureDataType> RenderTargetMultisample<C, D>
164164
/// Use [RenderTargetMultisample::resolve_to] to resolve to custom non-multisample textures.
165165
///
166166
pub fn resolve(&self) -> (Texture2D, DepthTexture2D) {
167-
let mut color_texture = Texture2D::new_empty::<C>(
167+
let color_texture = Texture2D::new_empty::<C>(
168168
&self.context,
169169
self.color.width(),
170170
self.color.height(),
@@ -174,7 +174,7 @@ impl<C: TextureDataType, D: DepthTextureDataType> RenderTargetMultisample<C, D>
174174
Wrapping::ClampToEdge,
175175
Wrapping::ClampToEdge,
176176
);
177-
let mut depth_texture = DepthTexture2D::new::<D>(
177+
let depth_texture = DepthTexture2D::new::<D>(
178178
&self.context,
179179
self.width(),
180180
self.height(),

src/core/texture/depth_texture2d.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl DepthTexture2D {
5555
/// Returns a [DepthTarget] which can be used to clear, write to and read from this texture.
5656
/// Combine this together with a [ColorTarget] with [RenderTarget::new] to be able to write to both a depth and color target at the same time.
5757
///
58-
pub fn as_depth_target(&mut self) -> DepthTarget<'_> {
58+
pub fn as_depth_target(&self) -> DepthTarget<'_> {
5959
DepthTarget::new_texture2d(&self.context, self)
6060
}
6161

src/core/texture/depth_texture2d_array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl DepthTexture2DArray {
5959
/// Returns a [DepthTarget] which can be used to clear, write to and read from the given layer of this texture.
6060
/// Combine this together with a [ColorTarget] with [RenderTarget::new] to be able to write to both a depth and color target at the same time.
6161
///
62-
pub fn as_depth_target(&mut self, layer: u32) -> DepthTarget<'_> {
62+
pub fn as_depth_target(&self, layer: u32) -> DepthTarget<'_> {
6363
DepthTarget::new_texture_2d_array(&self.context, self, layer)
6464
}
6565

src/core/texture/depth_texture_cube_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl DepthTextureCubeMap {
5656
/// Returns a [DepthTarget] which can be used to clear, write to and read from the given side of this texture.
5757
/// Combine this together with a [ColorTarget] with [RenderTarget::new] to be able to write to both a depth and color target at the same time.
5858
///
59-
pub fn as_depth_target(&mut self, side: CubeMapSide) -> DepthTarget<'_> {
59+
pub fn as_depth_target(&self, side: CubeMapSide) -> DepthTarget<'_> {
6060
DepthTarget::new_texture_cube_map(&self.context, self, side)
6161
}
6262

src/core/texture/texture2d.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl Texture2D {
130130
///
131131
/// **Note:** [DepthTest] is disabled if not also writing to a depth texture.
132132
///
133-
pub fn as_color_target(&mut self, mip_level: Option<u32>) -> ColorTarget<'_> {
133+
pub fn as_color_target(&self, mip_level: Option<u32>) -> ColorTarget<'_> {
134134
ColorTarget::new_texture2d(&self.context, self, mip_level)
135135
}
136136

0 commit comments

Comments
 (0)