[gl] add support for line and point polygon modes (#4836)

Co-authored-by: Nicolas Silva <nical@fastmail.com>
This commit is contained in:
Valaphee The Meerkat 2023-12-06 21:51:27 +01:00 committed by GitHub
parent a1fafe394f
commit 5022a6244b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 16 deletions

View File

@ -60,6 +60,8 @@ Previously, `DeviceExt::create_texture_with_data` only allowed data to be provid
#### OpenGL
- `@builtin(instance_index)` now properly reflects the range provided in the draw call instead of always counting from 0. By @cwfitzgerald in [#4722](https://github.com/gfx-rs/wgpu/pull/4722).
- Desktop GL now supports `POLYGON_MODE_LINE` and `POLYGON_MODE_POINT`. By @valaphee in [#4836](https://github.com/gfx-rs/wgpu/pull/4836)
#### Naga
- Naga's WGSL front and back ends now have experimental support for 64-bit floating-point literals: `1.0lf` denotes an `f64` value. There has been experimental support for an `f64` type for a while, but until now there was no syntax for writing literals with that type. As before, Naga module validation rejects `f64` values unless `naga::valid::Capabilities::FLOAT64` is requested. By @jimblandy in [#4747](https://github.com/gfx-rs/wgpu/pull/4747).

View File

@ -219,10 +219,7 @@ impl super::Adapter {
log::debug!("Version: {}", version);
let full_ver = Self::parse_full_version(&version).ok();
let es_ver = full_ver
.is_none()
.then_some(())
.and_then(|_| Self::parse_version(&version).ok());
let es_ver = full_ver.map_or_else(|| Self::parse_version(&version).ok(), |_| None);
let web_gl = cfg!(target_arch = "wasm32");
if let Some(full_ver) = full_ver {
@ -556,6 +553,10 @@ impl super::Adapter {
|| extensions.contains("OES_texture_float_linear"),
);
if es_ver.is_none() {
features |= wgt::Features::POLYGON_MODE_LINE | wgt::Features::POLYGON_MODE_POINT;
}
// We *might* be able to emulate bgra8unorm-storage but currently don't attempt to.
let mut private_caps = super::PrivateCapabilities::empty();

View File

@ -285,18 +285,6 @@ pub fn map_primitive_topology(topology: wgt::PrimitiveTopology) -> u32 {
}
pub(super) fn map_primitive_state(state: &wgt::PrimitiveState) -> super::PrimitiveState {
match state.polygon_mode {
wgt::PolygonMode::Fill => {}
wgt::PolygonMode::Line => panic!(
"{:?} is not enabled for this backend",
wgt::Features::POLYGON_MODE_LINE
),
wgt::PolygonMode::Point => panic!(
"{:?} is not enabled for this backend",
wgt::Features::POLYGON_MODE_POINT
),
}
super::PrimitiveState {
//Note: we are flipping the front face, so that
// the Y-flip in the generated GLSL keeps the same visibility.
@ -311,6 +299,11 @@ pub(super) fn map_primitive_state(state: &wgt::PrimitiveState) -> super::Primiti
None => 0,
},
unclipped_depth: state.unclipped_depth,
polygon_mode: match state.polygon_mode {
wgt::PolygonMode::Fill => glow::FILL,
wgt::PolygonMode::Line => glow::LINE,
wgt::PolygonMode::Point => glow::POINT,
},
}
}

View File

@ -736,6 +736,7 @@ struct PrimitiveState {
front_face: u32,
cull_face: u32,
unclipped_depth: bool,
polygon_mode: u32,
}
type InvalidatedAttachments = ArrayVec<u32, { crate::MAX_COLOR_ATTACHMENTS + 2 }>;

View File

@ -1330,6 +1330,10 @@ impl super::Queue {
unsafe { gl.disable(glow::DEPTH_CLAMP) };
}
}
// POLYGON_MODE_LINE also implies POLYGON_MODE_POINT
if self.features.contains(wgt::Features::POLYGON_MODE_LINE) {
unsafe { gl.polygon_mode(glow::FRONT_AND_BACK, state.polygon_mode) };
}
}
C::SetBlendConstant(c) => {
unsafe { gl.blend_color(c[0], c[1], c[2], c[3]) };