diff options
Diffstat (limited to 'src/library.rs')
| -rw-r--r-- | src/library.rs | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/library.rs b/src/library.rs index 3e83e1b..d20a133 100644 --- a/src/library.rs +++ b/src/library.rs @@ -97,6 +97,51 @@ impl<T: FixedNode> ConcreteNode for T { } } +/* +trait ProvideImpl<T> { + type Impl = T; +} + +impl ConcreteNode for ProvideImpl { + ProvideImpl::Impl::inputs(self) +} + + +/// Helper trait for Nodes with a single fixed-type output +trait OutputOnlyNode: fmt::Debug { + fn output_type(&self) -> Type; + + fn compile(&self, out_type: Type, output: &str, f: &mut dyn fmt::Write) -> fmt::Result; +} + +impl<T: OutputOnlyNode> ConcreteNode for T { + fn inputs(&self) -> usize { + 0 + } + fn outputs(&self) -> usize { + 1 + } + + fn signatures_matching(&self, connected: &[Option<Type>]) -> Vec<TypeSignature> { + vec![self.signature(connected)] + } + + fn signature(&self, connected: &[Option<Type>]) -> TypeSignature { + TypeSignature::new([], [self.output_type()]) + } + + fn compile( + &self, + signature: TypeSignature, + inputs: Vec<String>, + outputs: Vec<String>, + f: &mut dyn fmt::Write, + ) -> fmt::Result { + self.compile(signature.outputs[0], &outputs[0], f) + } +} +*/ + /// Arithmetic Operations #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] pub enum BinArithmetic { @@ -390,6 +435,7 @@ impl FixedNode for Output { TypeSignature::new([Vector(Float(Single), D4)], []), TypeSignature::new([Scalar(Float(Single))], []), TypeSignature::new([Scalar(Float(Double))], []), + TypeSignature::new([Vector(Float(Single), D2)], []), ] .into_iter(), ) @@ -403,6 +449,7 @@ impl FixedNode for Output { f: &mut dyn fmt::Write, ) -> fmt::Result { match signature.inputs[0] { + Vector(_, D2) => write!(f, "out_color = vec4({}, 0.0, 1.0);\n", inputs[0]), Vector(_, D3) => write!(f, "out_color = vec4({}, 1.0);\n", inputs[0]), Vector(_, D4) => write!(f, "out_color = {};\n", inputs[0]), Scalar(_) => write!(f, "out_color = vec4(vec3({}), 1.0);\n", inputs[0]), @@ -491,3 +538,60 @@ impl fmt::Display for Constant { write!(f, "Constant {}", self.typ) } } + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub enum Input { + UV, + // Resolution, +} + +impl ConcreteNode for Input { + fn inputs(&self) -> usize { + 0 + } + fn outputs(&self) -> usize { + 1 + } + + fn signatures_matching(&self, connected: &[Option<Type>]) -> Vec<TypeSignature> { + vec![self.signature(connected)] + } + + fn signature(&self, _connected: &[Option<Type>]) -> TypeSignature { + TypeSignature::new([], [Vector(Float(Single), D2)]) + } + + fn compile( + &self, + signature: TypeSignature, + _inputs: Vec<String>, + outputs: Vec<String>, + f: &mut dyn fmt::Write, + ) -> fmt::Result { + let out_typ = &signature.outputs[0]; + let out_name = &outputs[0]; + write!( + f, + "{out_typ} {out_name} = {};\n", + match self { + Input::UV => "in_uv", + } + ) + } +} +impl Input { + pub fn all() -> impl Iterator<Item = Input> { + [ + Input::UV, + // Input::Resolution, + ] + .into_iter() + } +} +impl fmt::Display for Input { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Input::UV => write!(f, "UV Coordinates"), + } + } +} |
