Skip to content

add polygon_mode: PolyonMode to RasterizationStateDescriptor to allow drawing wireframes #921

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

Merged
merged 1 commit into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion wgpu-core/src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,11 @@ pub fn map_rasterization_state_descriptor(
use hal::pso;
pso::Rasterizer {
depth_clamping: desc.clamp_depth,
polygon_mode: pso::PolygonMode::Fill,
polygon_mode: match desc.polygon_mode {
wgt::PolygonMode::Fill => pso::PolygonMode::Fill,
wgt::PolygonMode::Line => pso::PolygonMode::Line,
wgt::PolygonMode::Point => pso::PolygonMode::Point,
},
cull_face: match desc.cull_mode {
wgt::CullMode::None => pso::Face::empty(),
wgt::CullMode::Front => pso::Face::FRONT,
Expand Down
8 changes: 8 additions & 0 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2725,6 +2725,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
)
.with_label(&desc.label));
}
if rasterization_state.polygon_mode != wgt::PolygonMode::Fill
&& !device.features.contains(wgt::Features::NON_FILL_POLYGON_MODE)
{
return Err(pipeline::CreateRenderPipelineError::MissingFeature(
wgt::Features::NON_FILL_POLYGON_MODE,
)
.with_label(&desc.label));
}

let (raw_pipeline, layout_id, layout_ref_count, derived_bind_group_count) = {
//TODO: only lock mutable if the layout is derived
Expand Down
4 changes: 4 additions & 0 deletions wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ impl<B: hal::Backend> Adapter<B> {
wgt::Features::MULTI_DRAW_INDIRECT_COUNT,
adapter_features.contains(hal::Features::DRAW_INDIRECT_COUNT),
);
features.set(
wgt::Features::NON_FILL_POLYGON_MODE,
adapter_features.contains(hal::Features::NON_FILL_POLYGON_MODE),
);
#[cfg(not(target_os = "ios"))]
//TODO: https://github.com/gfx-rs/gfx/issues/3346
features.set(wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER, true);
Expand Down
34 changes: 34 additions & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ bitflags::bitflags! {
///
/// This is a web and native feature.
const ADDRESS_MODE_CLAMP_TO_BORDER = 0x0000_0000_0100_0000;
/// Allows the user to set a non-fill polygon mode in [`RasterizationStateDescriptor::polygon_mode`]
///
/// This allows drawing polygons/triangles as lines (wireframe) or points instead of filled
///
/// Supported platforms:
/// - DX12
/// - Vulkan
///
/// This is a native only feature.
const NON_FILL_POLYGON_MODE = 0x0000_0000_0200_0000;
/// Features which are part of the upstream WebGPU standard.
const ALL_WEBGPU = 0x0000_0000_0000_FFFF;
/// Features that are only available when targeting native (not web).
Expand Down Expand Up @@ -603,6 +613,26 @@ impl Default for CullMode {
}
}

/// Type of drawing mode for polygons
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "trace", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub enum PolygonMode {
/// Polygons are filled
Fill = 0,
/// Polygons are draw as line segments
Line = 1,
/// Polygons are draw as points
Point = 2,
}

impl Default for PolygonMode {
fn default() -> Self {
PolygonMode::Fill
}
}

/// Describes the state of the rasterizer in a render pipeline.
#[repr(C)]
#[derive(Clone, Debug, Default, PartialEq)]
Expand All @@ -611,6 +641,10 @@ impl Default for CullMode {
pub struct RasterizationStateDescriptor {
pub front_face: FrontFace,
pub cull_mode: CullMode,
/// Controls the way each polygon is rasterized. Can be either `Fill` (default), `Line` or `Point`
///
/// Setting this to something other than `Fill` requires `Features::NON_FILL_POLYGON_MODE` to be enabled.
pub polygon_mode: PolygonMode,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This member should have a comment on it saying it can only be non-fill with the feature on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I added the docs.

/// If enabled polygon depth is clamped to 0-1 range instead of being clipped.
///
/// Requires `Features::DEPTH_CLAMPING` enabled.
Expand Down