Skip to content

Commit

Permalink
Experiment with turning Shader into opaque type
Browse files Browse the repository at this point in the history
  • Loading branch information
crumblingstatue committed Oct 24, 2024
1 parent 7b0fe95 commit da4c7de
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 92 deletions.
8 changes: 4 additions & 4 deletions examples/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ trait Effect: Drawable {

struct Pixelate<'t> {
sprite: Sprite<'t>,
shader: Shader<'static>,
shader: FBox<Shader<'static>>,
}

impl<'t> Pixelate<'t> {
Expand Down Expand Up @@ -60,7 +60,7 @@ impl Effect for Pixelate<'_> {

struct WaveBlur<'fo> {
text: Text<'fo>,
shader: Shader<'static>,
shader: FBox<Shader<'static>>,
}

const WAVEBLUR_TEXT: &str = "\
Expand Down Expand Up @@ -124,7 +124,7 @@ impl Effect for WaveBlur<'_> {

struct StormBlink {
points: Vec<Vertex>,
shader: Shader<'static>,
shader: FBox<Shader<'static>>,
}

impl StormBlink {
Expand Down Expand Up @@ -184,7 +184,7 @@ struct Edge<'t> {
surface: FBox<RenderTexture>,
bg_sprite: Sprite<'t>,
entities: Vec<Sprite<'t>>,
shader: Shader<'static>,
shader: FBox<Shader<'static>>,
}

impl<'t> Edge<'t> {
Expand Down
25 changes: 5 additions & 20 deletions src/graphics/render_states.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
use {
crate::{
ffi::graphics as ffi,
graphics::{BlendMode, Shader, Texture, Transform},
},
std::{marker::PhantomData, ptr},
};
use crate::graphics::{BlendMode, Shader, Texture, Transform};

/// Define the states used for drawing to a [`RenderTarget`].
///
Expand Down Expand Up @@ -62,8 +56,7 @@ pub struct RenderStates<'texture, 'shader, 'shader_texture: 'shader> {
/// The transform
pub transform: Transform,
texture: Option<&'texture Texture>,
shader: *const ffi::sfShader,
_shader: PhantomData<&'shader Shader<'shader_texture>>,
shader: Option<&'shader Shader<'shader_texture>>,
}

impl<'texture, 'shader, 'shader_texture> RenderStates<'texture, 'shader, 'shader_texture> {
Expand All @@ -87,11 +80,7 @@ impl<'texture, 'shader, 'shader_texture> RenderStates<'texture, 'shader, 'shader
blend_mode,
transform,
texture,
shader: match shader {
Some(shader) => shader.raw(),
None => ptr::null(),
},
_shader: PhantomData,
shader,
}
}
/// Sets the texture
Expand All @@ -100,10 +89,7 @@ impl<'texture, 'shader, 'shader_texture> RenderStates<'texture, 'shader, 'shader
}
/// Sets the shader
pub fn set_shader(&mut self, shader: Option<&'shader Shader<'shader_texture>>) {
self.shader = match shader {
None => ptr::null(),
Some(shader) => shader.raw(),
};
self.shader = shader;
}
}

Expand All @@ -115,8 +101,7 @@ impl RenderStates<'static, 'static, 'static> {
blend_mode: BlendMode::ALPHA,
transform: Transform::IDENTITY,
texture: None,
shader: ptr::null(),
_shader: PhantomData,
shader: None,
};
}

Expand Down
Loading

0 comments on commit da4c7de

Please sign in to comment.