clutter/auto/shader_effect.rs
1use crate::{ActorMeta, Effect, OffscreenEffect, ShaderType};
2use glib::{
3 object as gobject,
4 object::{Cast, IsA},
5 translate::*,
6};
7use std::fmt;
8
9glib_wrapper! {
10 pub struct ShaderEffect(Object<ffi::ClutterShaderEffect, ffi::ClutterShaderEffectClass, ShaderEffectClass>) @extends OffscreenEffect, Effect, ActorMeta, gobject::InitiallyUnowned;
11
12 match fn {
13 get_type => || ffi::clutter_shader_effect_get_type(),
14 }
15}
16
17impl ShaderEffect {
18 /// Creates a new `ShaderEffect`, to be applied to an actor using
19 /// `ActorExt::add_effect`.
20 ///
21 /// The effect will be empty until `ShaderEffectExt::set_shader_source`
22 /// is called.
23 /// ## `shader_type`
24 /// the type of the shader, either `ShaderType::FragmentShader`,
25 /// or `ShaderType::VertexShader`
26 ///
27 /// # Returns
28 ///
29 /// the newly created `ShaderEffect`.
30 /// Use `gobject::ObjectExt::unref` when done.
31 pub fn new(shader_type: ShaderType) -> ShaderEffect {
32 unsafe {
33 Effect::from_glib_none(ffi::clutter_shader_effect_new(shader_type.to_glib()))
34 .unsafe_cast()
35 }
36 }
37}
38
39pub const NONE_SHADER_EFFECT: Option<&ShaderEffect> = None;
40
41/// Trait containing all `ShaderEffect` methods.
42///
43/// # Implementors
44///
45/// [`ShaderEffect`](struct.ShaderEffect.html)
46pub trait ShaderEffectExt: 'static {
47 //fn get_program(&self) -> /*Unimplemented*/Option<cogl::Handle>;
48
49 //fn get_shader(&self) -> /*Unimplemented*/Option<cogl::Handle>;
50
51 /// Sets the source of the GLSL shader used by `self`
52 ///
53 /// This function should only be called by implementations of
54 /// the `ShaderEffect` class, and not by application code.
55 ///
56 /// This function can only be called once; subsequent calls will
57 /// yield no result.
58 /// ## `source`
59 /// the source of a GLSL shader
60 ///
61 /// # Returns
62 ///
63 /// `true` if the source was set
64 fn set_shader_source(&self, source: &str) -> bool;
65
66 //fn set_uniform(&self, name: &str, gtype: glib::types::Type, n_values: usize, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);
67
68 /// Sets `value` as the payload for the uniform `name` inside the shader
69 /// effect
70 ///
71 /// The `glib::Type` of the `value` must be one of: `G_TYPE_INT`, for a single
72 /// integer value; `G_TYPE_FLOAT`, for a single floating point value;
73 /// `CLUTTER_TYPE_SHADER_INT`, for an array of integer values;
74 /// `CLUTTER_TYPE_SHADER_FLOAT`, for an array of floating point values;
75 /// and `CLUTTER_TYPE_SHADER_MATRIX`, for a matrix of floating point
76 /// values. It also accepts `G_TYPE_DOUBLE` for compatibility with other
77 /// languages than C.
78 /// ## `name`
79 /// the name of the uniform to set
80 /// ## `value`
81 /// a `gobject::Value` with the value of the uniform to set
82 fn set_uniform_value(&self, name: &str, value: &glib::Value);
83}
84
85impl<O: IsA<ShaderEffect>> ShaderEffectExt for O {
86 //fn get_program(&self) -> /*Unimplemented*/Option<cogl::Handle> {
87 // unsafe { TODO: call clutter_sys:clutter_shader_effect_get_program() }
88 //}
89
90 //fn get_shader(&self) -> /*Unimplemented*/Option<cogl::Handle> {
91 // unsafe { TODO: call clutter_sys:clutter_shader_effect_get_shader() }
92 //}
93
94 fn set_shader_source(&self, source: &str) -> bool {
95 unsafe {
96 from_glib(ffi::clutter_shader_effect_set_shader_source(
97 self.as_ref().to_glib_none().0,
98 source.to_glib_none().0,
99 ))
100 }
101 }
102
103 //fn set_uniform(&self, name: &str, gtype: glib::types::Type, n_values: usize, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
104 // unsafe { TODO: call clutter_sys:clutter_shader_effect_set_uniform() }
105 //}
106
107 fn set_uniform_value(&self, name: &str, value: &glib::Value) {
108 unsafe {
109 ffi::clutter_shader_effect_set_uniform_value(
110 self.as_ref().to_glib_none().0,
111 name.to_glib_none().0,
112 value.to_glib_none().0,
113 );
114 }
115 }
116}
117
118impl fmt::Display for ShaderEffect {
119 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
120 write!(f, "ShaderEffect")
121 }
122}