Skip to content

Commit

Permalink
graphics: Add a "render_target_msaa" function
Browse files Browse the repository at this point in the history
  • Loading branch information
not-fl3 committed Aug 26, 2024
1 parent 0c160b9 commit 02e1746
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ opt-level = 3
all-features = true

[dependencies]
miniquad = { version = "=0.4.5", features = ["log-impl"] }
miniquad = { version = "=0.4.6", features = ["log-impl"] }
quad-rand = "0.2.1"
glam = {version = "0.27", features = ["scalar-math"] }
image = { version = "0.24", default-features = false, features = ["png", "tga"] }
Expand All @@ -51,5 +51,6 @@ macroquad = { path = './' }

#quad-snd = {path = '../quad-snd'}
#miniquad = { path = '../miniquad' }
#miniquad = { git = "https://github.com/not-fl3/miniquad", branch = "msaa_render_texture" }
#quad-gl = {path = './quad-gl'}

2 changes: 1 addition & 1 deletion examples/letterbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const VIRTUAL_HEIGHT: f32 = 720.0;
#[macroquad::main("Letterbox")]
async fn main() {
// Setup 'render_target', used to hold the rendering result so we can resize it
let render_target = render_target(VIRTUAL_WIDTH as u32, VIRTUAL_HEIGHT as u32);
let render_target = render_target_msaa(VIRTUAL_WIDTH as u32, VIRTUAL_HEIGHT as u32, 4);
render_target.texture.set_filter(FilterMode::Linear);

// Setup camera for the virtual screen, that will render to 'render_target'
Expand Down
56 changes: 38 additions & 18 deletions src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,17 +351,6 @@ pub struct RenderPass {
}

impl 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 {
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 @@ -383,24 +372,55 @@ 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();

let texture_id = get_quad_context().new_render_texture(miniquad::TextureParams {
width,
height,
..Default::default()
});

let render_pass = get_quad_context().new_render_pass_mrt(&[texture_id], None, None);
let texture = Texture2D {
texture: context.textures.store_texture(texture_id),
};
let render_pass = RenderPass {
color_texture: texture.clone(),
depth_texture: None,
render_pass: Arc::new(render_pass),
};
RenderTarget {
texture,
render_pass,
}
}

let render_pass = render_pass(texture.clone(), None);
pub fn render_target_msaa(width: u32, height: u32, sample_count: i32) -> RenderTarget {
let context = get_context();

let color_texture = get_quad_context().new_render_texture(miniquad::TextureParams {
width,
height,
sample_count,
..Default::default()
});
let color_resolve_texture = get_quad_context().new_render_texture(miniquad::TextureParams {
width,
height,
..Default::default()
});
let render_pass = get_quad_context().new_render_pass_mrt(
&[color_texture],
Some(&[color_resolve_texture]),
None,
);
let texture = Texture2D {
texture: context.textures.store_texture(color_resolve_texture),
};
let render_pass = RenderPass {
color_texture: texture.clone(),
depth_texture: None,
render_pass: Arc::new(render_pass),
};

RenderTarget {
texture,
Expand Down

0 comments on commit 02e1746

Please sign in to comment.