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

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

Merged
merged 5 commits into from
Dec 6, 2023
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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).
Expand Down
9 changes: 5 additions & 4 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
17 changes: 5 additions & 12 deletions wgpu-hal/src/gles/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
},
}
}

Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }>;
Expand Down
4 changes: 4 additions & 0 deletions wgpu-hal/src/gles/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]) };
Expand Down
Loading