Skip to content

Commit

Permalink
first try on antialiased render targets
Browse files Browse the repository at this point in the history
  • Loading branch information
not-fl3 committed Aug 25, 2024
1 parent 0c160b9 commit 44c9bfa
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
42 changes: 35 additions & 7 deletions src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,24 +383,52 @@ 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_mrt2(&[texture_id], &[], 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,
}
}

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

let render_pass = render_pass(texture.clone(), None);
let texture_id = get_quad_context().new_render_texture(miniquad::TextureParams {
width,
height,
sample_count,
..Default::default()
});
let texture_resolve_id = get_quad_context().new_render_texture(miniquad::TextureParams {
width,
height,
..Default::default()
});
let render_pass =
get_quad_context().new_render_pass_mrt2(&[texture_id], &[texture_resolve_id], None);
let texture = Texture2D {
texture: context.textures.store_texture(texture_resolve_id),
};
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 44c9bfa

Please sign in to comment.