Skip to content

Commit

Permalink
RenderPass: hold on to both colour and depth attachments, not current…
Browse files Browse the repository at this point in the history
…ly used but at least this way its consistent
  • Loading branch information
profan committed May 2, 2024
1 parent 53a0dc4 commit 0fa5f7d
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,17 +342,24 @@ pub async fn load_texture(path: &str) -> Result<Texture2D, Error> {

#[derive(Debug, Clone)]
pub struct RenderPass {
render_texture: Texture2D,
color_texture: Texture2D,
depth_texture: Option<Texture2D>,
render_pass: Arc<miniquad::RenderPass>,
}

impl RenderPass {
pub fn new(render_texture: Texture2D, render_pass: miniquad::RenderPass) -> RenderPass {
fn new(color_texture: Texture2D, depth_texture: Option<Texture2D>) -> RenderPass {
let render_pass = get_quad_context().new_render_pass(
color_texture.raw_miniquad_id(),
depth_texture.as_ref().map(|t| t.raw_miniquad_id()),
);
RenderPass {
render_texture,
color_texture,
depth_texture: depth_texture.map(|t| t.clone()),
render_pass: Arc::new(render_pass),
}
}
/// Returns the miniquad handle for this render pass.
pub fn raw_miniquad_id(&self) -> miniquad::RenderPass {
*self.render_pass
}
Expand All @@ -373,6 +380,10 @@ pub struct RenderTarget {
pub render_pass: RenderPass,
}

fn render_pass(color_texture: Texture2D, depth_texture: Option<Texture2D>) -> RenderPass {
RenderPass::new(color_texture, depth_texture)
}

pub fn render_target(width: u32, height: u32) -> RenderTarget {
let context = get_context();

Expand All @@ -386,10 +397,7 @@ pub fn render_target(width: u32, height: u32) -> RenderTarget {
texture: context.textures.store_texture(texture_id),
};

let render_pass = RenderPass::new(
texture.clone(),
get_quad_context().new_render_pass(texture_id, None),
);
let render_pass = render_pass(texture.clone(), None);

RenderTarget {
texture,
Expand Down

0 comments on commit 0fa5f7d

Please sign in to comment.