From 0a2c9719a8d2729b482aa65f53d9194dfaba287a Mon Sep 17 00:00:00 2001 From: h-isthebestletter Date: Mon, 28 Oct 2024 19:10:11 +0800 Subject: [PATCH 1/4] Add support for GL_POINTS and gl_PointSize --- crates/notan_glow/src/pipeline.rs | 12 ++++++++++++ crates/notan_glow/src/to_glow.rs | 1 + crates/notan_graphics/src/pipeline.rs | 9 +++++++++ 3 files changed, 22 insertions(+) diff --git a/crates/notan_glow/src/pipeline.rs b/crates/notan_glow/src/pipeline.rs index 574d4b77..272201f6 100644 --- a/crates/notan_glow/src/pipeline.rs +++ b/crates/notan_glow/src/pipeline.rs @@ -88,6 +88,7 @@ impl InnerPipeline { set_blend_mode(gl, options); #[cfg(not(target_arch = "wasm32"))] set_srgb_space(gl, options); + set_point_size_available(gl, options); } } } @@ -257,6 +258,17 @@ fn set_srgb_space(gl: &Context, opts: &PipelineOptions) { } } +#[inline(always)] +fn set_point_size_available(gl: &Context, opts: &PipelineOptions) { + unsafe { + if opts.point_size { + gl.enable(glow::VERTEX_PROGRAM_POINT_SIZE); + } else { + gl.disable(glow::VERTEX_PROGRAM_POINT_SIZE); + } + } +} + #[inline(always)] fn clean_pipeline(gl: &Context, pip: InnerPipeline) { let InnerPipeline { diff --git a/crates/notan_glow/src/to_glow.rs b/crates/notan_glow/src/to_glow.rs index 2b4aa629..873fe1ae 100644 --- a/crates/notan_glow/src/to_glow.rs +++ b/crates/notan_glow/src/to_glow.rs @@ -136,6 +136,7 @@ impl ToGlow for TextureFilter { impl ToGlow for DrawPrimitive { fn to_glow(&self) -> u32 { match self { + DrawPrimitive::Points => glow::POINTS, DrawPrimitive::Triangles => glow::TRIANGLES, DrawPrimitive::TriangleStrip => glow::TRIANGLE_STRIP, DrawPrimitive::Lines => glow::LINES, diff --git a/crates/notan_graphics/src/pipeline.rs b/crates/notan_graphics/src/pipeline.rs index 6a1ef20d..8de9949b 100644 --- a/crates/notan_graphics/src/pipeline.rs +++ b/crates/notan_graphics/src/pipeline.rs @@ -162,6 +162,12 @@ impl<'a, 'b> PipelineBuilder<'a, 'b> { self } + /// Enable the availability of gl_PointSize in the vertex shader + pub fn with_point_size_available(mut self, enabled: bool) -> Self { + self.options.point_size = enabled; + self + } + /// Build the pipeline with the data set on the builder pub fn build(self) -> Result { match self.shaders { @@ -358,6 +364,7 @@ pub struct PipelineOptions { pub color_mask: ColorMask, pub stencil: Option, pub srgb_space: bool, + pub point_size: bool, } impl Default for PipelineOptions { @@ -370,6 +377,7 @@ impl Default for PipelineOptions { color_mask: Default::default(), stencil: None, srgb_space: false, + point_size: false, } } } @@ -444,6 +452,7 @@ impl Default for StencilOptions { #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)] pub enum DrawPrimitive { + Points, Lines, LineStrip, #[default] From 7a6dcd076a04adac1d733ca1e2417f276b3b88fb Mon Sep 17 00:00:00 2001 From: h-isthebestletter Date: Mon, 28 Oct 2024 19:56:44 +0800 Subject: [PATCH 2/4] Change point_size to point_size_enabled --- crates/notan_glow/src/pipeline.rs | 2 +- crates/notan_graphics/src/pipeline.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/notan_glow/src/pipeline.rs b/crates/notan_glow/src/pipeline.rs index 272201f6..7cc1fb24 100644 --- a/crates/notan_glow/src/pipeline.rs +++ b/crates/notan_glow/src/pipeline.rs @@ -261,7 +261,7 @@ fn set_srgb_space(gl: &Context, opts: &PipelineOptions) { #[inline(always)] fn set_point_size_available(gl: &Context, opts: &PipelineOptions) { unsafe { - if opts.point_size { + if opts.point_size_enabled { gl.enable(glow::VERTEX_PROGRAM_POINT_SIZE); } else { gl.disable(glow::VERTEX_PROGRAM_POINT_SIZE); diff --git a/crates/notan_graphics/src/pipeline.rs b/crates/notan_graphics/src/pipeline.rs index 8de9949b..588ed0f7 100644 --- a/crates/notan_graphics/src/pipeline.rs +++ b/crates/notan_graphics/src/pipeline.rs @@ -164,7 +164,7 @@ impl<'a, 'b> PipelineBuilder<'a, 'b> { /// Enable the availability of gl_PointSize in the vertex shader pub fn with_point_size_available(mut self, enabled: bool) -> Self { - self.options.point_size = enabled; + self.options.point_size_enabled = enabled; self } @@ -364,7 +364,7 @@ pub struct PipelineOptions { pub color_mask: ColorMask, pub stencil: Option, pub srgb_space: bool, - pub point_size: bool, + pub point_size_enabled: bool, } impl Default for PipelineOptions { @@ -377,7 +377,7 @@ impl Default for PipelineOptions { color_mask: Default::default(), stencil: None, srgb_space: false, - point_size: false, + point_size_enabled: false, } } } From f5e6d8efe10394d2ad990ad888e245f242ad71b6 Mon Sep 17 00:00:00 2001 From: h-isthebestletter Date: Mon, 28 Oct 2024 20:11:06 +0800 Subject: [PATCH 3/4] Change point_size_enabled to point_size_available --- crates/notan_glow/src/pipeline.rs | 2 +- crates/notan_graphics/src/pipeline.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/notan_glow/src/pipeline.rs b/crates/notan_glow/src/pipeline.rs index 7cc1fb24..aefa6147 100644 --- a/crates/notan_glow/src/pipeline.rs +++ b/crates/notan_glow/src/pipeline.rs @@ -261,7 +261,7 @@ fn set_srgb_space(gl: &Context, opts: &PipelineOptions) { #[inline(always)] fn set_point_size_available(gl: &Context, opts: &PipelineOptions) { unsafe { - if opts.point_size_enabled { + if opts.point_size_available { gl.enable(glow::VERTEX_PROGRAM_POINT_SIZE); } else { gl.disable(glow::VERTEX_PROGRAM_POINT_SIZE); diff --git a/crates/notan_graphics/src/pipeline.rs b/crates/notan_graphics/src/pipeline.rs index 588ed0f7..6fffbe2c 100644 --- a/crates/notan_graphics/src/pipeline.rs +++ b/crates/notan_graphics/src/pipeline.rs @@ -164,7 +164,7 @@ impl<'a, 'b> PipelineBuilder<'a, 'b> { /// Enable the availability of gl_PointSize in the vertex shader pub fn with_point_size_available(mut self, enabled: bool) -> Self { - self.options.point_size_enabled = enabled; + self.options.point_size_available = enabled; self } @@ -364,7 +364,7 @@ pub struct PipelineOptions { pub color_mask: ColorMask, pub stencil: Option, pub srgb_space: bool, - pub point_size_enabled: bool, + pub point_size_available: bool, } impl Default for PipelineOptions { @@ -377,7 +377,7 @@ impl Default for PipelineOptions { color_mask: Default::default(), stencil: None, srgb_space: false, - point_size_enabled: false, + point_size_available: false, } } } From 4faf225a2fae029f120e6fa29f966fad3805ee47 Mon Sep 17 00:00:00 2001 From: h-isthebestletter Date: Tue, 29 Oct 2024 09:16:34 +0800 Subject: [PATCH 4/4] Change default point_size_available to true --- crates/notan_graphics/src/pipeline.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/notan_graphics/src/pipeline.rs b/crates/notan_graphics/src/pipeline.rs index 6fffbe2c..bb63d2ac 100644 --- a/crates/notan_graphics/src/pipeline.rs +++ b/crates/notan_graphics/src/pipeline.rs @@ -377,7 +377,7 @@ impl Default for PipelineOptions { color_mask: Default::default(), stencil: None, srgb_space: false, - point_size_available: false, + point_size_available: true, } } }