Skip to content

Commit

Permalink
Rename new_render_pass into new_render_pass_mrt
Browse files Browse the repository at this point in the history
This way there is no unneccesary breaking API changes
  • Loading branch information
not-fl3 committed Feb 20, 2024
1 parent 979473e commit 24d434e
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 18 deletions.
1 change: 1 addition & 0 deletions examples/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl Stage {
VertexAttribute::new("in_uv", VertexFormat::Float2),
],
shader,
PipelineParams::default()
);

let uniforms = shader::Uniforms {
Expand Down
1 change: 1 addition & 0 deletions examples/instancing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl Stage {
VertexAttribute::with_buffer("in_inst_pos", VertexFormat::Float3, 1),
],
shader,
PipelineParams::default(),
);

Stage {
Expand Down
2 changes: 1 addition & 1 deletion examples/offscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] = &[
Expand Down
3 changes: 2 additions & 1 deletion examples/post_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ impl Stage {
VertexAttribute::new("uv", VertexFormat::Float2),
],
default_shader,
PipelineParams::default()
);

let offscreen_shader = ctx
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions examples/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ impl Stage {
VertexAttribute::new("in_color", VertexFormat::Float4),
],
shader,
PipelineParams::default(),
);

Stage {
Expand Down
14 changes: 11 additions & 3 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,11 +1162,19 @@ pub trait RenderingBackend {
);
fn new_render_pass(
&mut self,
color_img: Vec<TextureId>,
color_img: TextureId,
depth_img: Option<TextureId>,
) -> 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<TextureId>,
) -> RenderPass;
/// for depth-only render pass returns None
fn render_pass_texture(&self, render_pass: RenderPass) -> Vec<TextureId>;
/// for depth-only render pass returns an empty slice
fn render_pass_texture(&self, render_pass: RenderPass) -> &[TextureId];
fn delete_render_pass(&mut self, render_pass: RenderPass);
fn new_pipeline(
&mut self,
Expand Down
16 changes: 8 additions & 8 deletions src/graphics/gl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ fn get_uniform_location(program: GLuint, name: &str) -> Option<i32> {

pub(crate) struct RenderPassInternal {
gl_fb: GLuint,
texture: Vec<TextureId>,
color_textures: Vec<TextureId>,
depth_texture: Option<TextureId>,
}

Expand Down Expand Up @@ -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<TextureId>,
color_img: &[TextureId],
depth_img: Option<TextureId>,
) -> RenderPass {
if color_img.is_empty() && depth_img.is_none() {
Expand Down Expand Up @@ -955,23 +955,23 @@ impl RenderingBackend for GlContext {
}
let pass = RenderPassInternal {
gl_fb,
texture: color_img,
color_textures: color_img.to_vec(),
depth_texture: depth_img,
};

self.passes.push(pass);

RenderPass(self.passes.len() - 1)
}
fn render_pass_texture(&self, render_pass: RenderPass) -> Vec<TextureId> {
self.passes[render_pass.0].texture.clone()
fn render_pass_texture(&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 {
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/graphics/metal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextureId>,
color_img: &[TextureId],
depth_img: Option<TextureId>,
) -> RenderPass {
unsafe {
Expand Down Expand Up @@ -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,
};

Expand All @@ -578,8 +578,8 @@ impl RenderingBackend for MetalContext {
}
}

fn render_pass_texture(&self, render_pass: RenderPass) -> Vec<TextureId> {
self.passes[render_pass.0].texture.clone()
fn render_pass_texture(&self, render_pass: RenderPass) -> &[TextureId] {
&self.passes[render_pass.0].texture
}

fn new_buffer(&mut self, _: BufferType, _usage: BufferUsage, data: BufferSource) -> BufferId {
Expand Down

0 comments on commit 24d434e

Please sign in to comment.