Skip to content

Commit 79cec8d

Browse files
valapheenical
authored andcommitted
[gl] add support for line and point polygon modes (gfx-rs#4836)
Co-authored-by: Nicolas Silva <nical@fastmail.com>
1 parent 7cdc3e1 commit 79cec8d

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ Previously, `DeviceExt::create_texture_with_data` only allowed data to be provid
6161

6262
#### OpenGL
6363
- `@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).
64+
- Desktop GL now supports `POLYGON_MODE_LINE` and `POLYGON_MODE_POINT`. By @valaphee in [#4836](https://github.com/gfx-rs/wgpu/pull/4836)
65+
6466
#### Naga
6567

6668
- 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).

wgpu-hal/src/gles/adapter.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,7 @@ impl super::Adapter {
219219
log::debug!("Version: {}", version);
220220

221221
let full_ver = Self::parse_full_version(&version).ok();
222-
let es_ver = full_ver
223-
.is_none()
224-
.then_some(())
225-
.and_then(|_| Self::parse_version(&version).ok());
222+
let es_ver = full_ver.map_or_else(|| Self::parse_version(&version).ok(), |_| None);
226223
let web_gl = cfg!(target_arch = "wasm32");
227224

228225
if let Some(full_ver) = full_ver {
@@ -556,6 +553,10 @@ impl super::Adapter {
556553
|| extensions.contains("OES_texture_float_linear"),
557554
);
558555

556+
if es_ver.is_none() {
557+
features |= wgt::Features::POLYGON_MODE_LINE | wgt::Features::POLYGON_MODE_POINT;
558+
}
559+
559560
// We *might* be able to emulate bgra8unorm-storage but currently don't attempt to.
560561

561562
let mut private_caps = super::PrivateCapabilities::empty();

wgpu-hal/src/gles/conv.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -285,18 +285,6 @@ pub fn map_primitive_topology(topology: wgt::PrimitiveTopology) -> u32 {
285285
}
286286

287287
pub(super) fn map_primitive_state(state: &wgt::PrimitiveState) -> super::PrimitiveState {
288-
match state.polygon_mode {
289-
wgt::PolygonMode::Fill => {}
290-
wgt::PolygonMode::Line => panic!(
291-
"{:?} is not enabled for this backend",
292-
wgt::Features::POLYGON_MODE_LINE
293-
),
294-
wgt::PolygonMode::Point => panic!(
295-
"{:?} is not enabled for this backend",
296-
wgt::Features::POLYGON_MODE_POINT
297-
),
298-
}
299-
300288
super::PrimitiveState {
301289
//Note: we are flipping the front face, so that
302290
// 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
311299
None => 0,
312300
},
313301
unclipped_depth: state.unclipped_depth,
302+
polygon_mode: match state.polygon_mode {
303+
wgt::PolygonMode::Fill => glow::FILL,
304+
wgt::PolygonMode::Line => glow::LINE,
305+
wgt::PolygonMode::Point => glow::POINT,
306+
},
314307
}
315308
}
316309

wgpu-hal/src/gles/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ struct PrimitiveState {
736736
front_face: u32,
737737
cull_face: u32,
738738
unclipped_depth: bool,
739+
polygon_mode: u32,
739740
}
740741

741742
type InvalidatedAttachments = ArrayVec<u32, { crate::MAX_COLOR_ATTACHMENTS + 2 }>;

wgpu-hal/src/gles/queue.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,10 @@ impl super::Queue {
13301330
unsafe { gl.disable(glow::DEPTH_CLAMP) };
13311331
}
13321332
}
1333+
// POLYGON_MODE_LINE also implies POLYGON_MODE_POINT
1334+
if self.features.contains(wgt::Features::POLYGON_MODE_LINE) {
1335+
unsafe { gl.polygon_mode(glow::FRONT_AND_BACK, state.polygon_mode) };
1336+
}
13331337
}
13341338
C::SetBlendConstant(c) => {
13351339
unsafe { gl.blend_color(c[0], c[1], c[2], c[3]) };

0 commit comments

Comments
 (0)