Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphics: Add render_target_ex #835

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 66 additions & 31 deletions src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,25 @@ pub struct RenderPass {
pub(crate) render_pass: Arc<miniquad::RenderPass>,
}

#[derive(Debug, Clone)]
pub struct RenderTargetParams {
/// 1 means no multi sampling.
/// Note that sample_count > 1 is not supported on GL2, GLES2 and WebGL1
pub sample_count: i32,

/// depth: true creates a depth render target attachment and allows
/// such a render target being used for a depth-testing cameras
pub depth: bool,
}
impl Default for RenderTargetParams {
fn default() -> RenderTargetParams {
RenderTargetParams {
sample_count: 1,
depth: false,
}
}
}

impl RenderPass {
/// Returns the miniquad handle for this render pass.
pub fn raw_miniquad_id(&self) -> miniquad::RenderPass {
Expand All @@ -369,55 +388,71 @@ pub struct RenderTarget {
}

pub fn render_target(width: u32, height: u32) -> RenderTarget {
let context = get_context();
let texture_id = get_quad_context().new_render_texture(miniquad::TextureParams {
render_target_ex(width, height, RenderTargetParams::default())
}

pub fn render_target_msaa(width: u32, height: u32, sample_count: i32) -> RenderTarget {
render_target_ex(
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,
}
RenderTargetParams {
sample_count,
..Default::default()
},
)
}

pub fn render_target_msaa(width: u32, height: u32, sample_count: i32) -> RenderTarget {
pub fn render_target_ex(width: u32, height: u32, params: RenderTargetParams) -> 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,
sample_count: params.sample_count,
..Default::default()
});
let render_pass = get_quad_context().new_render_pass_mrt(
&[color_texture],
Some(&[color_resolve_texture]),
None,
);
let depth_texture = if params.depth {
Some(
get_quad_context().new_render_texture(miniquad::TextureParams {
width,
height,
format: miniquad::TextureFormat::Depth,
sample_count: params.sample_count,
..Default::default()
}),
)
} else {
None
};
let render_pass;
let texture;
if params.sample_count != 0 {
let color_resolve_texture =
get_quad_context().new_render_texture(miniquad::TextureParams {
width,
height,
..Default::default()
});
render_pass = get_quad_context().new_render_pass_mrt(
&[color_texture],
Some(&[color_resolve_texture]),
depth_texture,
);
texture = color_resolve_texture;
} else {
render_pass = get_quad_context().new_render_pass_mrt(&[color_texture], None, depth_texture);
texture = color_texture;
}

let texture = Texture2D {
texture: context.textures.store_texture(color_resolve_texture),
texture: context.textures.store_texture(texture),
};

let render_pass = RenderPass {
color_texture: texture.clone(),
depth_texture: None,
render_pass: Arc::new(render_pass),
};

RenderTarget {
texture,
render_pass,
Expand Down
Loading