radar-g/gi/src/shaders/mod.rs
2024-09-13 09:53:17 +08:00

104 lines
2.1 KiB
Rust

pub mod agg_path;
pub mod colormap;
pub mod earth;
pub mod font;
pub mod geoquadmesh;
pub mod math;
pub mod polar;
pub mod ppi;
pub mod proj;
pub mod trackball;
use glsl::{
syntax::{ShaderStage, TranslationUnit},
transpiler::glsl::{show_struct, show_translation_unit},
};
use glsl_quasiquote::glsl;
use crate::components::Shader;
struct PPI {
vertex: ShaderStage,
}
impl PPI {
fn new() -> Self {
let vertex: ShaderStage = glsl! {
layout(location = 0) in vec3 position;
out float in_value;
void main() {
gl_Position = vec4(position.x, position.y, 0.5, 1.0);
in_value = position.z;
}
};
Self { vertex }
}
}
impl std::fmt::Display for PPI {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
show_translation_unit(f, &self.vertex);
Ok(())
}
}
#[derive(std::fmt::Debug)]
pub struct EmptyPiece(pub TranslationUnit);
pub trait CodePiece: std::fmt::Display {
fn raw(&self) -> &TranslationUnit;
fn include<T: CodePiece>(i: T, raw: TranslationUnit) -> TranslationUnit {
let mut s = i.raw().clone();
s.extend(raw);
s
}
}
impl CodePiece for EmptyPiece {
fn raw(&self) -> &TranslationUnit {
&self.0
}
}
impl std::fmt::Display for EmptyPiece {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Ok(())
}
}
#[macro_export]
macro_rules! impl_code_piece {
($t:ty, $c:tt) => {
impl CodePiece for $t {
fn raw(&self) -> &TranslationUnit {
&self.$c
}
}
impl std::fmt::Display for $t {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
show_translation_unit(f, &self.$c);
Ok(())
}
}
};
}
mod test {
use glsl::transpiler::glsl::show_translation_unit;
use super::math::Constants;
use super::polar::PolarTransform;
use super::PPI;
#[test]
fn test() {
let polar = PolarTransform::new();
println!("{}", polar);
}
}