From ecd57152f91bc65d4ed2530b9baa7949d0ab40db Mon Sep 17 00:00:00 2001 From: Fedor Logachev Date: Tue, 20 Feb 2024 11:24:39 -0600 Subject: [PATCH] Rename new_render_pass into new_render_pass_mrt This way there is no unneccesary breaking API changes --- examples/blobs.rs | 1 + examples/instancing.rs | 1 + examples/offscreen.rs | 2 +- examples/post_processing.rs | 3 ++- examples/triangle.rs | 1 + src/graphics.rs | 27 ++++++++++++++++++++++++--- src/graphics/gl.rs | 16 ++++++++-------- src/graphics/metal.rs | 10 +++++----- 8 files changed, 43 insertions(+), 18 deletions(-) diff --git a/examples/blobs.rs b/examples/blobs.rs index ba429bcf..c3014ec1 100644 --- a/examples/blobs.rs +++ b/examples/blobs.rs @@ -73,6 +73,7 @@ impl Stage { VertexAttribute::new("in_uv", VertexFormat::Float2), ], shader, + PipelineParams::default() ); let uniforms = shader::Uniforms { diff --git a/examples/instancing.rs b/examples/instancing.rs index 93721d38..4084aad3 100644 --- a/examples/instancing.rs +++ b/examples/instancing.rs @@ -91,6 +91,7 @@ impl Stage { VertexAttribute::with_buffer("in_inst_pos", VertexFormat::Float3, 1), ], shader, + PipelineParams::default(), ); Stage { diff --git a/examples/offscreen.rs b/examples/offscreen.rs index 3fff1181..f8c32957 100644 --- a/examples/offscreen.rs +++ b/examples/offscreen.rs @@ -30,7 +30,7 @@ impl Stage { ..Default::default() }); - let offscreen_pass = ctx.new_render_pass(vec![color_img], Some(depth_img)); + let offscreen_pass = ctx.new_render_pass(color_img, Some(depth_img)); #[rustfmt::skip] let vertices: &[f32] = &[ diff --git a/examples/post_processing.rs b/examples/post_processing.rs index 5dd12e74..2795ad3c 100644 --- a/examples/post_processing.rs +++ b/examples/post_processing.rs @@ -144,6 +144,7 @@ impl Stage { VertexAttribute::new("uv", VertexFormat::Float2), ], default_shader, + PipelineParams::default() ); let offscreen_shader = ctx @@ -156,7 +157,7 @@ impl Stage { ) .unwrap(); - let offscreen_pipeline = ctx.new_pipeline_with_params( + let offscreen_pipeline = ctx.new_pipeline( &[BufferLayout { stride: 36, ..Default::default() diff --git a/examples/triangle.rs b/examples/triangle.rs index b46faaec..383dbf48 100644 --- a/examples/triangle.rs +++ b/examples/triangle.rs @@ -63,6 +63,7 @@ impl Stage { VertexAttribute::new("in_color", VertexFormat::Float4), ], shader, + PipelineParams::default(), ); Stage { diff --git a/src/graphics.rs b/src/graphics.rs index d8763d90..3b5b1d61 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -1162,11 +1162,32 @@ pub trait RenderingBackend { ); fn new_render_pass( &mut self, - color_img: Vec, + color_img: TextureId, + depth_img: Option, + ) -> RenderPass { + self.new_render_pass_mrt(&[color_img], depth_img) + } + /// Same as "new_render_pass", but allows multiple color attachments. + fn new_render_pass_mrt( + &mut self, + color_img: &[TextureId], depth_img: Option, ) -> RenderPass; - /// for depth-only render pass returns None - fn render_pass_texture(&self, render_pass: RenderPass) -> Vec; + /// panics for depth-only or multiple color attachment render pass + /// This function is, mostly, legacy. Using "render_pass_color_attachments" + /// is recommended instead. + fn render_pass_texture(&self, render_pass: RenderPass) -> TextureId { + let textures = self.render_pass_color_attachments(render_pass); + if textures.len() == 0 { + panic!("depth-only render pass"); + } + if textures.len() != 1 { + panic!("multiple render target render pass"); + } + return textures[0]; + } + /// For depth-only render pass returns empty slice. + fn render_pass_color_attachments(&self, render_pass: RenderPass) -> &[TextureId]; fn delete_render_pass(&mut self, render_pass: RenderPass); fn new_pipeline( &mut self, diff --git a/src/graphics/gl.rs b/src/graphics/gl.rs index eed2ef52..f111bae3 100644 --- a/src/graphics/gl.rs +++ b/src/graphics/gl.rs @@ -424,7 +424,7 @@ fn get_uniform_location(program: GLuint, name: &str) -> Option { pub(crate) struct RenderPassInternal { gl_fb: GLuint, - texture: Vec, + color_textures: Vec, depth_texture: Option, } @@ -912,9 +912,9 @@ impl RenderingBackend for GlContext { RawId::OpenGl(texture.raw) } - fn new_render_pass( + fn new_render_pass_mrt( &mut self, - color_img: Vec, + color_img: &[TextureId], depth_img: Option, ) -> RenderPass { if color_img.is_empty() && depth_img.is_none() { @@ -955,7 +955,7 @@ impl RenderingBackend for GlContext { } let pass = RenderPassInternal { gl_fb, - texture: color_img, + color_textures: color_img.to_vec(), depth_texture: depth_img, }; @@ -963,15 +963,15 @@ impl RenderingBackend for GlContext { RenderPass(self.passes.len() - 1) } - fn render_pass_texture(&self, render_pass: RenderPass) -> Vec { - self.passes[render_pass.0].texture.clone() + fn render_pass_color_attachments(&self, render_pass: RenderPass) -> &[TextureId] { + &self.passes[render_pass.0].color_textures } fn delete_render_pass(&mut self, render_pass: RenderPass) { let render_pass = &mut self.passes[render_pass.0]; unsafe { glDeleteFramebuffers(1, &mut render_pass.gl_fb as *mut _) } - for color_texture in &render_pass.texture { + for color_texture in &render_pass.color_textures { self.textures.get(*color_texture).delete(); } if let Some(depth_texture) = render_pass.depth_texture { @@ -1431,7 +1431,7 @@ impl RenderingBackend for GlContext { // new_render_pass will panic with both color and depth components none // so unwrap is safe here let texture = pass - .texture + .color_textures .first() .copied() .or(pass.depth_texture) diff --git a/src/graphics/metal.rs b/src/graphics/metal.rs index b7714f73..e4614502 100644 --- a/src/graphics/metal.rs +++ b/src/graphics/metal.rs @@ -530,9 +530,9 @@ impl RenderingBackend for MetalContext { self.end_render_pass(); } - fn new_render_pass( + fn new_render_pass_mrt( &mut self, - color_img: Vec, + color_img: &[TextureId], depth_img: Option, ) -> RenderPass { unsafe { @@ -561,7 +561,7 @@ impl RenderingBackend for MetalContext { } let pass = RenderPassInternal { render_pass_desc, - texture: color_img, + texture: color_img.to_vec(), _depth_texture: depth_img, }; @@ -578,8 +578,8 @@ impl RenderingBackend for MetalContext { } } - fn render_pass_texture(&self, render_pass: RenderPass) -> Vec { - self.passes[render_pass.0].texture.clone() + fn render_pass_color_attachments(&self, render_pass: RenderPass) -> &[TextureId] { + &self.passes[render_pass.0].texture } fn new_buffer(&mut self, _: BufferType, _usage: BufferUsage, data: BufferSource) -> BufferId {