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

Add support for GL_POINTS and gl_PointSize #334

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions crates/notan_glow/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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_available {
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 {
Expand Down
1 change: 1 addition & 0 deletions crates/notan_glow/src/to_glow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions crates/notan_graphics/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_available = enabled;
self
}

/// Build the pipeline with the data set on the builder
pub fn build(self) -> Result<Pipeline, String> {
match self.shaders {
Expand Down Expand Up @@ -358,6 +364,7 @@ pub struct PipelineOptions {
pub color_mask: ColorMask,
pub stencil: Option<StencilOptions>,
pub srgb_space: bool,
pub point_size_available: bool,
}

impl Default for PipelineOptions {
Expand All @@ -370,6 +377,7 @@ impl Default for PipelineOptions {
color_mask: Default::default(),
stencil: None,
srgb_space: false,
point_size_available: true,
}
}
}
Expand Down Expand Up @@ -444,6 +452,7 @@ impl Default for StencilOptions {

#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
pub enum DrawPrimitive {
Points,
Lines,
LineStrip,
#[default]
Expand Down