switch to stable rustup

This commit is contained in:
Tsuki 2024-09-25 15:57:15 +08:00
parent 6b68aedc2a
commit ebca8d2c31
24 changed files with 245 additions and 343 deletions

19
Cargo.lock generated
View File

@ -1760,7 +1760,6 @@ dependencies = [
"geo-macros", "geo-macros",
"glow", "glow",
"glsl", "glsl",
"glsl-quasiquote",
"glutin", "glutin",
"glutin-winit", "glutin-winit",
"image 0.25.2", "image 0.25.2",
@ -2011,18 +2010,6 @@ dependencies = [
"nom", "nom",
] ]
[[package]]
name = "glsl-quasiquote"
version = "7.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "165f0276eb5b572678e2658b357d669aa08eca35032ca20381c24d58b46cca62"
dependencies = [
"glsl",
"proc-macro-faithful-display",
"proc-macro2 1.0.86",
"quote 1.0.37",
]
[[package]] [[package]]
name = "glue" name = "glue"
version = "0.8.7" version = "0.8.7"
@ -3913,12 +3900,6 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "proc-macro-faithful-display"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5bdf93a22e0e7b3d52e42837f111845a69957294d23671efeeb8d1baef4773a"
[[package]] [[package]]
name = "proc-macro-hack" name = "proc-macro-hack"
version = "0.5.20+deprecated" version = "0.5.20+deprecated"

View File

@ -210,6 +210,53 @@ fn litstr_to_format(
}); });
} }
#[proc_macro_derive(Module)]
pub fn module_macro(input: TokenStream) -> TokenStream {
let struct_item = parse_macro_input!(input as ItemStruct);
let stru_name = struct_item.ident;
let generics = struct_item.generics;
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
match struct_item.fields {
Named(fields) => {
let names: Vec<_> = fields
.named
.iter()
.map(|field| {
let field_name = field.ident.clone().unwrap();
field_name
})
.collect();
let typs: Vec<_> = fields
.named
.iter()
.map(|field| {
let field_ty = &field.ty;
field_ty.clone()
})
.collect();
quote! {
impl #impl_generics #stru_name #ty_generics #where_clause {
pub fn new(#(#names: #typs),*) -> Self {
Self {
#(#names),*
}
}
}
}
.into()
}
_ => quote!(
struct A {}
)
.into(),
}
}
#[proc_macro_derive(ModuleRef)] #[proc_macro_derive(ModuleRef)]
pub fn module_ref_macro(input: TokenStream) -> TokenStream { pub fn module_ref_macro(input: TokenStream) -> TokenStream {
let struct_item = parse_macro_input!(input as ItemStruct); let struct_item = parse_macro_input!(input as ItemStruct);

View File

@ -37,7 +37,7 @@ thiserror = "1.0.61"
tinyfiledialogs = "3.0" tinyfiledialogs = "3.0"
tracker = "0.2.2" tracker = "0.2.2"
glsl = "7.0.0" glsl = "7.0.0"
glsl-quasiquote = "7.0.0" # glsl-quasiquote = "7.0.0"
toml = "0.8.19" toml = "0.8.19"
femtovg = "0.9.2" femtovg = "0.9.2"
rust-embed = "8.5.0" rust-embed = "8.5.0"
@ -62,4 +62,4 @@ name = "gi"
path = "../radarg_core" path = "../radarg_core"
[dependencies.geo-macros] [dependencies.geo-macros]
path = "../geo-macros" path = "../geo-macros"

View File

@ -1,5 +1,3 @@
#![feature(proc_macro_hygiene)]
#![feature(concat_idents)]
#![allow(unused)] #![allow(unused)]
mod camera; mod camera;
mod components; mod components;

View File

@ -55,16 +55,63 @@ pub enum SideBarInputMsg {
} }
macro_rules! program_impl { macro_rules! program_impl {
($({$name:ident | $name_ref:ident, $module: ty | $module_ref: ty, ($($m:ident),*)}),+) => { ($({$name:ident ,$module: ty , ($($m:ident),*)}),+) => {
pub struct Programs {
gl: GL,
_ppi: PPI,
_text: Text,
_line: AggFastPath,
_geo_quad_mesh: GeoQuadMesh,
_earth: Earth,
_terrain: Terrain,
}
impl Programs {
fn new(gl: GL) -> Result<Self> {
let font_manager = FontManager::new()?;
let earth = Earth::new(&gl)?;
let _terrain = Terrain::new(&gl)?;
Ok(Self {
gl: gl.clone(),
_ppi: PPI::new()?,
_text: Text::new(gl, font_manager)?,
_line: AggFastPath::new()?,
_geo_quad_mesh: GeoQuadMesh::new()?,
_earth: earth,
_terrain,
})
}
fn prepare(&mut self) -> Result<()> {
self._ppi.program().compile(&self.gl)?;
self._line.program().compile(&self.gl)?;
self._text.program_mut().compile(&self.gl)?;
self._geo_quad_mesh.program().compile(&self.gl)?;
self._earth.program_mut().compile(&self.gl)?;
self._terrain.program_mut().compile(&self.gl)?;
Ok(())
}
fn destroy(&mut self) -> Result<()> {
self._ppi.destroy(&self.gl)?;
self._text.destroy(&self.gl)?;
self._line.destroy(&self.gl)?;
self._geo_quad_mesh.destroy(&self.gl)?;
self._earth.destroy(&self.gl)?;
self._terrain.destroy(&self.gl)?;
Ok(())
}
}
impl Programs { impl Programs {
$( $(
pub fn $name(&mut self) -> $module { pub fn $name(&mut self) -> $module {
<$module>::new(&self.gl, $(&mut self.$m),*) <$module>::new(&self.gl, $(&mut self.$m),*)
} }
pub fn $name_ref(&self) -> $module_ref {
<$module_ref>::new(&self.gl, $(&self.$m),*)
}
)+ )+
@ -73,56 +120,8 @@ macro_rules! program_impl {
}; };
} }
pub struct Programs {
gl: GL,
_ppi: PPI,
_text: Text,
_line: AggFastPath,
_geo_quad_mesh: GeoQuadMesh,
_earth: Earth,
_terrain: Terrain,
}
impl Programs {
fn new(gl: GL) -> Result<Self> {
let font_manager = FontManager::new()?;
let earth = Earth::new(&gl)?;
let _terrain = Terrain::new(&gl)?;
Ok(Self {
gl: gl.clone(),
_ppi: PPI::new()?,
_text: Text::new(gl, font_manager)?,
_line: AggFastPath::new()?,
_geo_quad_mesh: GeoQuadMesh::new()?,
_earth: earth,
_terrain,
})
}
fn prepare(&mut self) -> Result<()> {
self._ppi.program().compile(&self.gl)?;
self._line.program().compile(&self.gl)?;
self._text.program_mut().compile(&self.gl)?;
self._geo_quad_mesh.program().compile(&self.gl)?;
self._earth.program_mut().compile(&self.gl)?;
self._terrain.program_mut().compile(&self.gl)?;
Ok(())
}
fn destroy(&mut self) -> Result<()> {
self._ppi.destroy(&self.gl)?;
self._text.destroy(&self.gl)?;
self._line.destroy(&self.gl)?;
self._geo_quad_mesh.destroy(&self.gl)?;
self._earth.destroy(&self.gl)?;
self._terrain.destroy(&self.gl)?;
Ok(())
}
}
macro_rules! impl_module_package { macro_rules! impl_module_package {
($({$method:ident|$ref_method:ident ,$t:ty => $b: tt | $module:tt | $module_ref:tt | $c: ty}),+) => { ($({$method:ident ,$t:ty => $b: tt | $module:tt | $c: ty}),+) => {
pub enum Modules<'b, 'gl: 'b>{ pub enum Modules<'b, 'gl: 'b>{
$( $(
@ -130,11 +129,9 @@ macro_rules! impl_module_package {
)+ )+
} }
#[derive(Clone,Copy)] #[derive(Clone,Copy, Debug)]
pub enum ModuleRefs<'b, 'gl:'b>{ pub struct ModuleRefs {
$( pub id: &'static str
$b($module_ref<'b,'gl>),
)+
} }
impl Modules<'_, '_> { impl Modules<'_, '_> {
@ -150,16 +147,18 @@ macro_rules! impl_module_package {
} }
} }
impl ModuleRefs<'_, '_> { impl Programs {
pub fn name(&self) -> &'static str { pub fn module(&mut self, r: &ModuleRefs) -> Modules {
match self { match r.id {
$( $(
ModuleRefs::$b(m) => m.name(), <$module as Module>::NAME => Modules::$b(self.$method()),
)+ )+
_ => panic!("Module not found"),
} }
} }
} }
// #[derive(Debug)] // #[derive(Debug)]
pub enum _ModulePackage { pub enum _ModulePackage {
$( $(
@ -279,9 +278,10 @@ macro_rules! impl_module_package {
for (k, d) in data.iter() { for (k, d) in data.iter() {
$( $(
{ {
if self.$ref_method().supported(d) { if self.$method().supported(d) {
let _ref = self.$ref_method(); // let _ref = self.$ref_method();
result.entry(d).and_modify(|v:&mut Vec<ModuleRefs>| v.push(ModuleRefs::$b(_ref))).or_insert_with(|| vec![ModuleRefs::$b(_ref)]); let _ref = ModuleRefs {id: <$module as Module>::NAME};
result.entry(d).and_modify(|v:&mut Vec<ModuleRefs>| v.push(_ref)).or_insert_with(|| vec![_ref]);
} }
} }
@ -297,17 +297,17 @@ macro_rules! impl_module_package {
} }
program_impl!( program_impl!(
{ppi | ppi_ref, PPIModule | PPIModuleRef, (_ppi, _text, _line)}, {ppi, PPIModule,(_ppi, _text, _line)},
{geo_quad_mesh | geo_quad_mesh_ref, GeoQuadMeshModule | GeoQuadMeshModuleRef, (_geo_quad_mesh,_text, _line)}, {geo_quad_mesh , GeoQuadMeshModule , (_geo_quad_mesh,_text, _line)},
{earth | earth_ref, EarthModule | EarthModuleRef, (_earth)}, {earth, EarthModule , (_earth)},
{terrain | terrain_ref, TerrainModule | TerrainModuleRef, (_terrain)} {terrain , TerrainModule , (_terrain)}
); );
impl_module_package!( impl_module_package!(
{ppi|ppi_ref,PPIPackage => PPI | PPIModule | PPIModuleRef | PPIModuleConfigComponent}, {ppi,PPIPackage => PPI | PPIModule | PPIModuleConfigComponent},
{geo_quad_mesh|geo_quad_mesh_ref,GeoQuadMeshPackage => GeoQuadMesh | GeoQuadMeshModule | GeoQuadMeshModuleRef | GeoQuadMeshModuleConfigComponent}, {geo_quad_mesh,GeoQuadMeshPackage => GeoQuadMesh | GeoQuadMeshModule |GeoQuadMeshModuleConfigComponent},
{earth|earth_ref, EarthModulePackage => Earth| EarthModule | EarthModuleRef | EarthModuleConfigComponent}, {earth, EarthModulePackage => Earth| EarthModule |EarthModuleConfigComponent},
{terrain|terrain_ref, TerrainModulePackage => Terrain | TerrainModule | TerrainModuleRef | TerrainModuleConfigComponent} {terrain, TerrainModulePackage => Terrain | TerrainModule | TerrainModuleConfigComponent}
); );
impl ModulePackage { impl ModulePackage {

View File

@ -1,4 +1,4 @@
use geo_macros::{module_ref_impl, ModuleRef}; use geo_macros::{module_ref_impl, Module, ModuleRef};
use glow::HasContext; use glow::HasContext;
use relm4::{ use relm4::{
adw::{self, prelude::*}, adw::{self, prelude::*},
@ -18,44 +18,17 @@ use crate::{
use super::{Module, ModuleCursor}; use super::{Module, ModuleCursor};
#[derive(ModuleRef)]
pub struct EarthModule<'b, 'gl: 'b> { pub struct EarthModule<'b, 'gl: 'b> {
gl: &'gl GL, gl: &'gl GL,
earth: &'b mut Earth, earth: &'b mut Earth,
} }
impl<'b, 'gl: 'b> EarthModule<'b, 'gl> {
pub fn name(&self) -> &'static str {
"Earth"
}
pub fn supported(&self, data: &Arc<radarg_core::Data>) -> bool {
false
}
}
impl<'b, 'gl: 'b> EarthModuleRef<'b, 'gl> {
pub fn name(&self) -> &'static str {
"Earth"
}
pub fn supported(&self, data: &Arc<radarg_core::Data>) -> bool {
false
}
}
impl<'b, 'gl: 'b> EarthModule<'b, 'gl> { impl<'b, 'gl: 'b> EarthModule<'b, 'gl> {
pub fn new(gl: &'gl GL, earth: &'b mut Earth) -> Self { pub fn new(gl: &'gl GL, earth: &'b mut Earth) -> Self {
Self { gl, earth } Self { gl, earth }
} }
} }
impl<'b, 'gl: 'b> EarthModuleRef<'b, 'gl> {
pub fn new(gl: &'gl GL, earth: &'b Earth) -> Self {
Self { gl, earth }
}
}
pub struct EarthModulePackage {} pub struct EarthModulePackage {}
impl<'b, 'gl: 'b> Module for EarthModule<'b, 'gl> { impl<'b, 'gl: 'b> Module for EarthModule<'b, 'gl> {

View File

@ -44,61 +44,6 @@ pub struct GeoQuadMeshModule<'b, 'gl: 'b> {
text_program: &'b mut Text, text_program: &'b mut Text,
} }
#[derive(Copy, Clone)]
pub struct GeoQuadMeshModuleRef<'b, 'gl: 'b> {
gl: &'gl GL,
geo_quad_mesh_program: &'b GeoQuadMesh,
line_program: &'b AggFastPath,
text_program: &'b Text,
}
impl<'b, 'a: 'b> GeoQuadMeshModuleRef<'b, 'a> {
pub fn new(gl: &'a GL, quad: &'b GeoQuadMesh, text: &'b Text, line: &'b AggFastPath) -> Self {
let config = PPIConfig::default();
Self {
gl,
geo_quad_mesh_program: quad,
text_program: text,
line_program: line,
}
}
fn bind_line_pg(
&self,
attach: &mut Attach,
data: &RadarGridData,
config: &GeoQuadMeshModuleConfig,
) -> Result<()> {
Ok(())
}
fn bind_tick(
&self,
attach: &mut Attach,
data: &RadarGridData,
config: &GeoQuadMeshModuleConfig,
) -> Result<()> {
Ok(())
}
pub fn name(&self) -> &'static str {
"GeoQuadMesh"
}
pub fn supported(&self, data: &Data) -> bool {
let data: std::result::Result<&RadarGridData, radarg_core::errors::DataError> =
data.try_into();
if let Ok(data) = data {
match data.coord_type() {
Some(CoordType::Cartesian { .. }) => true,
_ => false,
}
} else {
false
}
}
}
impl<'b, 'a: 'b> GeoQuadMeshModule<'b, 'a> { impl<'b, 'a: 'b> GeoQuadMeshModule<'b, 'a> {
pub fn new( pub fn new(
gl: &'a GL, gl: &'a GL,

View File

@ -21,7 +21,7 @@ mod terrain;
use crate::errors::*; use crate::errors::*;
pub use geoquadmesh::{ pub use geoquadmesh::{
GeoQuadMeshModule, GeoQuadMeshModuleConfig, GeoQuadMeshModuleConfigComponent, GeoQuadMeshModule, GeoQuadMeshModuleConfig, GeoQuadMeshModuleConfigComponent,
GeoQuadMeshModuleConfigComponentWidgets, GeoQuadMeshModuleRef, GeoQuadMeshPackage, GeoQuadMeshModuleConfigComponentWidgets, GeoQuadMeshPackage,
}; };
pub use ppi::{ pub use ppi::{
PPIModule, PPIModuleConfigComponent, PPIModuleConfigComponentWidgets, PPIModuleRef, PPIPackage, PPIModule, PPIModuleConfigComponent, PPIModuleConfigComponentWidgets, PPIModuleRef, PPIPackage,
@ -29,12 +29,9 @@ pub use ppi::{
pub use earth::{ pub use earth::{
EarthModule, EarthModuleConfigComponent, EarthModuleConfigComponentWidgets, EarthModulePackage, EarthModule, EarthModuleConfigComponent, EarthModuleConfigComponentWidgets, EarthModulePackage,
EarthModuleRef,
}; };
pub use terrain::{ pub use terrain::{TerrainModule, TerrainModuleConfigComponent, TerrainModulePackage};
TerrainModule, TerrainModuleConfigComponent, TerrainModulePackage, TerrainModuleRef,
};
use relm4::Component as RComponent; use relm4::Component as RComponent;

View File

@ -18,7 +18,6 @@ use crate::{
use super::{Module, ModuleCursor}; use super::{Module, ModuleCursor};
#[derive(ModuleRef)]
pub struct TerrainModule<'b, 'gl: 'b> { pub struct TerrainModule<'b, 'gl: 'b> {
gl: &'gl GL, gl: &'gl GL,
terrain: &'b mut Terrain, terrain: &'b mut Terrain,
@ -34,28 +33,12 @@ impl<'b, 'gl: 'b> TerrainModule<'b, 'gl> {
} }
} }
impl<'b, 'gl: 'b> TerrainModuleRef<'b, 'gl> {
pub fn name(&self) -> &'static str {
"Terrain"
}
pub fn supported(&self, data: &Arc<radarg_core::Data>) -> bool {
false
}
}
impl<'b, 'gl: 'b> TerrainModule<'b, 'gl> { impl<'b, 'gl: 'b> TerrainModule<'b, 'gl> {
pub fn new(gl: &'gl GL, terrain: &'b mut Terrain) -> Self { pub fn new(gl: &'gl GL, terrain: &'b mut Terrain) -> Self {
Self { gl, terrain } Self { gl, terrain }
} }
} }
impl<'b, 'gl: 'b> TerrainModuleRef<'b, 'gl> {
pub fn new(gl: &'gl GL, terrain: &'b Terrain) -> Self {
Self { gl, terrain }
}
}
pub struct TerrainModulePackage { pub struct TerrainModulePackage {
conf: TerrainModulePackageConfig, conf: TerrainModulePackageConfig,
} }

View File

@ -1,7 +1,7 @@
use glsl::parser::Parse;
use glsl::syntax::ShaderStage; use glsl::syntax::ShaderStage;
use glsl::syntax::TranslationUnit; use glsl::syntax::TranslationUnit;
use glsl::transpiler::glsl::show_translation_unit; use glsl::transpiler::glsl::show_translation_unit;
use glsl_quasiquote::glsl;
use crate::impl_code_piece; use crate::impl_code_piece;
@ -14,7 +14,8 @@ pub struct AggPathFragment(ShaderStage);
impl AggPathVertex { impl AggPathVertex {
pub fn new() -> Self { pub fn new() -> Self {
let mut transform = Trackball::new().0; let mut transform = Trackball::new().0;
let raw = glsl! { let raw = {
"
layout(location = 0) in vec3 prev; layout(location = 0) in vec3 prev;
layout(location = 1) in vec3 curr; layout(location = 1) in vec3 curr;
@ -72,9 +73,10 @@ impl AggPathVertex {
// Back to NDC coordinates // Back to NDC coordinates
gl_Position = vec4(2.0*P/viewport-1.0, ndc_curr.z / ndc_curr.w, 1.0); gl_Position = vec4(2.0*P/viewport-1.0, ndc_curr.z / ndc_curr.w, 1.0);
} }
"
}; };
transform.extend(raw); transform.extend(ShaderStage::parse(raw).unwrap());
Self(transform) Self(transform)
} }
@ -82,7 +84,8 @@ impl AggPathVertex {
impl AggPathFragment { impl AggPathFragment {
pub fn new() -> Self { pub fn new() -> Self {
let raw = glsl! { let raw = {
"
uniform float antialias; uniform float antialias;
uniform float thickness; uniform float thickness;
@ -117,8 +120,9 @@ impl AggPathFragment {
if (v_color.a == 0) {discard;} if (v_color.a == 0) {discard;}
fragColor = stroke(v_distance, thickness, antialias, v_color); fragColor = stroke(v_distance, thickness, antialias, v_color);
} }
"
}; };
Self(raw) Self(ShaderStage::parse(raw).unwrap())
} }
} }

View File

@ -1,15 +1,16 @@
use super::CodePiece; use super::CodePiece;
use crate::impl_code_piece; use crate::impl_code_piece;
use glsl::parser::Parse;
use glsl::syntax::ShaderStage; use glsl::syntax::ShaderStage;
use glsl::syntax::TranslationUnit; use glsl::syntax::TranslationUnit;
use glsl::transpiler::glsl::show_translation_unit; use glsl::transpiler::glsl::show_translation_unit;
use glsl_quasiquote::glsl;
pub struct ColorMap(pub ShaderStage); pub struct ColorMap(pub ShaderStage);
impl ColorMap { impl ColorMap {
pub fn new() -> Self { pub fn new() -> Self {
let raw = glsl! { let raw = {
"
uniform sampler1D colormap; uniform sampler1D colormap;
uniform vec4 colormap_conf; uniform vec4 colormap_conf;
@ -41,9 +42,10 @@ impl ColorMap {
vec4 result = texture(colormap, idx); vec4 result = texture(colormap, idx);
return vec4(result.rgb, 1.0); return vec4(result.rgb, 1.0);
} }
"
}; };
Self(raw) Self(ShaderStage::parse(raw).unwrap())
} }
} }

View File

@ -1,31 +1,34 @@
use super::trackball::Trackball; use super::trackball::Trackball;
use super::CodePiece; use super::CodePiece;
use crate::impl_code_piece; use crate::impl_code_piece;
use glsl::parser::Parse;
use glsl::syntax::ShaderStage; use glsl::syntax::ShaderStage;
use glsl::syntax::TranslationUnit; use glsl::syntax::TranslationUnit;
use glsl::transpiler::glsl::show_translation_unit; use glsl::transpiler::glsl::show_translation_unit;
use glsl_quasiquote::glsl;
pub struct EarthVertex(pub ShaderStage); pub struct EarthVertex(pub ShaderStage);
pub struct EarthFragment(pub ShaderStage); pub struct EarthFragment(pub ShaderStage);
impl EarthVertex { impl EarthVertex {
pub fn new() -> Self { pub fn new() -> Self {
let raw = glsl! { let raw = {
"
layout(location = 0) in vec3 in_position; layout(location = 0) in vec3 in_position;
void main() { void main() {
gl_Position = vec4(in_position, 1.0); gl_Position = vec4(in_position, 1.0);
} }
"
}; };
Self(raw) Self(ShaderStage::parse(raw).unwrap())
} }
} }
impl EarthFragment { impl EarthFragment {
pub fn new() -> Self { pub fn new() -> Self {
let raw = glsl! { let raw = {
"
uniform vec3 camera_location; uniform vec3 camera_location;
uniform float focal_length; uniform float focal_length;
@ -141,9 +144,10 @@ impl EarthFragment {
FragColor = vec4(col, 1.0); FragColor = vec4(col, 1.0);
} }
"
}; };
Self(raw) Self(ShaderStage::parse(raw).unwrap())
} }
} }

View File

@ -1,10 +1,11 @@
use super::trackball::Trackball; use super::trackball::Trackball;
use super::CodePiece; use super::CodePiece;
use crate::components::Shader;
use crate::impl_code_piece; use crate::impl_code_piece;
use glsl::parser::Parse;
use glsl::syntax::ShaderStage; use glsl::syntax::ShaderStage;
use glsl::syntax::TranslationUnit; use glsl::syntax::TranslationUnit;
use glsl::transpiler::glsl::show_translation_unit; use glsl::transpiler::glsl::show_translation_unit;
use glsl_quasiquote::glsl;
pub struct FontVertex(pub ShaderStage); pub struct FontVertex(pub ShaderStage);
@ -14,7 +15,8 @@ pub struct FontGeometry(pub ShaderStage);
impl FontVertex { impl FontVertex {
pub fn new() -> Self { pub fn new() -> Self {
let raw = glsl! { let raw = {
"
// texcoord (left top, right bottom) // texcoord (left top, right bottom)
layout(location = 0) in vec4 texcoord; layout(location = 0) in vec4 texcoord;
@ -31,16 +33,18 @@ impl FontVertex {
vs_out.texcoord = texcoord; vs_out.texcoord = texcoord;
vs_out.pos = relative_position; vs_out.pos = relative_position;
} }
"
}; };
Self(raw) Self(ShaderStage::parse(raw).unwrap())
} }
} }
impl FontGeometry { impl FontGeometry {
pub fn new() -> Self { pub fn new() -> Self {
let mut transform = Trackball::new().0; let mut transform = Trackball::new().0;
let raw = glsl! { let raw = {
"
layout(points) in; layout(points) in;
layout(triangle_strip, max_vertices = 4) out; layout(triangle_strip, max_vertices = 4) out;
@ -123,9 +127,10 @@ impl FontGeometry {
EndPrimitive(); EndPrimitive();
} }
"
}; };
transform.extend(raw); transform.extend(ShaderStage::parse(raw).unwrap());
Self(transform) Self(transform)
} }
@ -133,7 +138,8 @@ impl FontGeometry {
impl FontFragment { impl FontFragment {
pub fn new() -> Self { pub fn new() -> Self {
let raw = glsl! { let raw = {
"
uniform sampler2D atlas_data; uniform sampler2D atlas_data;
in vec2 v_texCoord; in vec2 v_texCoord;
in vec2 UV_coord; in vec2 UV_coord;
@ -202,9 +208,10 @@ impl FontFragment {
} }
"
}; };
Self(raw) Self(ShaderStage::parse(raw).unwrap())
} }
} }

View File

@ -1,10 +1,11 @@
use super::colormap::ColorMap; use super::colormap::ColorMap;
use super::trackball::Trackball; use super::trackball::Trackball;
use super::CodePiece; use super::CodePiece;
use crate::components::Shader;
use crate::impl_code_piece; use crate::impl_code_piece;
use glsl::parser::Parse;
use glsl::syntax::{ShaderStage, TranslationUnit}; use glsl::syntax::{ShaderStage, TranslationUnit};
use glsl::transpiler::glsl::show_translation_unit; use glsl::transpiler::glsl::show_translation_unit;
use glsl_quasiquote::glsl;
use super::proj::Mercator; use super::proj::Mercator;
@ -16,7 +17,8 @@ impl GeoQuadMeshVertex {
pub fn new() -> Self { pub fn new() -> Self {
let mut mercator = Mercator::new().0; let mut mercator = Mercator::new().0;
let mut trackball = Trackball::new().0; let mut trackball = Trackball::new().0;
let raw = glsl! { let raw = {
"
// Position (x, y, z) --- x, y are longitude and latitude, z is the Altitude. // Position (x, y, z) --- x, y are longitude and latitude, z is the Altitude.
layout(location = 0) in vec3 in_position; layout(location = 0) in vec3 in_position;
layout(location = 1) in vec3 relative_position; layout(location = 1) in vec3 relative_position;
@ -29,10 +31,11 @@ impl GeoQuadMeshVertex {
gl_Position = transform(position(relative_position)); gl_Position = transform(position(relative_position));
} }
"
}; };
mercator.extend(trackball); mercator.extend(trackball);
mercator.extend(raw); mercator.extend(ShaderStage::parse(raw).unwrap());
Self(mercator) Self(mercator)
} }
} }
@ -43,7 +46,8 @@ impl GeoQuadMeshFragment {
let color_map = ColorMap::new().0; let color_map = ColorMap::new().0;
let raw = glsl! { let raw = {
"
// lon_s,lon_e, lat_s, lat_e // lon_s,lon_e, lat_s, lat_e
uniform vec4 tex_conf; uniform vec4 tex_conf;
// hgt, lat, lon // hgt, lat, lon
@ -122,10 +126,11 @@ impl GeoQuadMeshFragment {
fragColor = color; fragColor = color;
} }
"
}; };
mercator.extend(color_map); mercator.extend(color_map);
mercator.extend(raw); mercator.extend(ShaderStage::parse(raw).unwrap());
Self(mercator) Self(mercator)
} }

View File

@ -1,5 +1,5 @@
use glsl::parser::Parse;
use glsl::syntax::ShaderStage; use glsl::syntax::ShaderStage;
use glsl_quasiquote::glsl;
use super::CodePiece; use super::CodePiece;
use glsl::syntax::TranslationUnit; use glsl::syntax::TranslationUnit;
@ -13,7 +13,8 @@ pub struct Constants {
impl Constants { impl Constants {
pub fn new() -> Constants { pub fn new() -> Constants {
let raw = glsl! { let raw = {
"
#ifndef _GLUMPY__CONSTANTS__ #ifndef _GLUMPY__CONSTANTS__
#define _GLUMPY__CONSTANTS__ #define _GLUMPY__CONSTANTS__
@ -64,8 +65,11 @@ impl Constants {
const float radian = M_PI/180.0; const float radian = M_PI/180.0;
#endif #endif
"
}; };
let raw = ShaderStage::parse(raw).unwrap();
Constants { raw } Constants { raw }
} }
} }

View File

@ -14,37 +14,9 @@ use glsl::{
syntax::{ShaderStage, TranslationUnit}, syntax::{ShaderStage, TranslationUnit},
transpiler::glsl::{show_struct, show_translation_unit}, transpiler::glsl::{show_struct, show_translation_unit},
}; };
use glsl_quasiquote::glsl;
use crate::components::Shader; 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)] #[derive(std::fmt::Debug)]
pub struct EmptyPiece(pub TranslationUnit); pub struct EmptyPiece(pub TranslationUnit);
@ -87,18 +59,3 @@ macro_rules! impl_code_piece {
} }
}; };
} }
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);
}
}

View File

@ -1,11 +1,12 @@
use super::CodePiece; use super::CodePiece;
use crate::components::Shader;
use crate::impl_code_piece; use crate::impl_code_piece;
use glsl::parser::Parse;
use glsl::syntax::ShaderStage; use glsl::syntax::ShaderStage;
use glsl::syntax::TranslationUnit; use glsl::syntax::TranslationUnit;
use glsl::transpiler::glsl::show_translation_unit; use glsl::transpiler::glsl::show_translation_unit;
use super::math::Constants; use super::math::Constants;
use glsl_quasiquote::glsl;
pub struct PolarTransform { pub struct PolarTransform {
pub raw: ShaderStage, pub raw: ShaderStage,
@ -13,7 +14,8 @@ pub struct PolarTransform {
impl PolarTransform { impl PolarTransform {
pub fn new() -> PolarTransform { pub fn new() -> PolarTransform {
let raw = glsl! { let raw = {
"
uniform float polar_origin; uniform float polar_origin;
@ -45,11 +47,12 @@ impl PolarTransform {
vec4 inverse(vec2 P) { return inverse(P.x, P.y, 0.0, 1.0); } vec4 inverse(vec2 P) { return inverse(P.x, P.y, 0.0, 1.0); }
vec4 inverse(vec3 P) { return inverse(P.x, P.y, P.z, 1.0); } vec4 inverse(vec3 P) { return inverse(P.x, P.y, P.z, 1.0); }
vec4 inverse(vec4 P) { return inverse(P.x, P.y, P.z, P.w); } vec4 inverse(vec4 P) { return inverse(P.x, P.y, P.z, P.w); }
"
}; };
let mut constant = Constants::new().raw; let mut constant = Constants::new().raw;
constant.extend(raw); constant.extend(ShaderStage::parse(raw).unwrap());
PolarTransform { raw: constant } PolarTransform { raw: constant }
} }

View File

@ -1,10 +1,10 @@
use super::trackball::Trackball; use super::trackball::Trackball;
use super::CodePiece; use super::CodePiece;
use crate::impl_code_piece; use crate::impl_code_piece;
use glsl::parser::Parse;
use glsl::syntax::ShaderStage; use glsl::syntax::ShaderStage;
use glsl::syntax::TranslationUnit; use glsl::syntax::TranslationUnit;
use glsl::transpiler::glsl::show_translation_unit; use glsl::transpiler::glsl::show_translation_unit;
use glsl_quasiquote::glsl;
pub struct PPIVertex(pub ShaderStage); pub struct PPIVertex(pub ShaderStage);
pub struct PPIGeom(pub ShaderStage); pub struct PPIGeom(pub ShaderStage);
@ -12,7 +12,8 @@ pub struct PPIFragment(pub ShaderStage);
impl PPIVertex { impl PPIVertex {
pub fn new() -> Self { pub fn new() -> Self {
let raw = glsl! { let raw = {
"
layout(location = 0) in vec4 position; layout(location = 0) in vec4 position;
out float in_value; out float in_value;
@ -20,9 +21,10 @@ impl PPIVertex {
gl_Position = vec4(position.x * 10.0, position.y, position.z, 1.0); gl_Position = vec4(position.x * 10.0, position.y, position.z, 1.0);
in_value = position.w; in_value = position.w;
} }
"
}; };
Self(raw) Self(ShaderStage::parse(raw).unwrap())
} }
} }
@ -30,7 +32,8 @@ impl PPIGeom {
pub fn new() -> Self { pub fn new() -> Self {
let mut trackball = Trackball::new().0; let mut trackball = Trackball::new().0;
let polar = super::polar::PolarTransform::new().raw; let polar = super::polar::PolarTransform::new().raw;
let raw = glsl! { let raw = {
"
layout(points) in; layout(points) in;
layout(triangle_strip, max_vertices = 4) out; layout(triangle_strip, max_vertices = 4) out;
@ -93,10 +96,11 @@ impl PPIGeom {
} }
"
}; };
trackball.extend(polar); trackball.extend(polar);
trackball.extend(raw); trackball.extend(ShaderStage::parse(raw).unwrap());
Self(trackball) Self(trackball)
} }
@ -107,7 +111,8 @@ impl PPIFragment {
use super::polar::PolarTransform; use super::polar::PolarTransform;
let mut include = PolarTransform::new().raw; let mut include = PolarTransform::new().raw;
let mut colormap = super::colormap::ColorMap::new().0; let mut colormap = super::colormap::ColorMap::new().0;
let raw = glsl! { let raw = {
"
in float x; in float x;
in float y; in float y;
@ -133,10 +138,11 @@ impl PPIFragment {
FragColor = result; FragColor = result;
} }
"
}; };
include.extend(colormap); include.extend(colormap);
include.extend(raw); include.extend(ShaderStage::parse(raw).unwrap());
Self(include) Self(include)
} }

View File

@ -1,15 +1,16 @@
use super::CodePiece; use super::CodePiece;
use crate::impl_code_piece; use crate::impl_code_piece;
use glsl::parser::Parse;
use glsl::syntax::ShaderStage; use glsl::syntax::ShaderStage;
use glsl::syntax::TranslationUnit; use glsl::syntax::TranslationUnit;
use glsl::transpiler::glsl::show_translation_unit; use glsl::transpiler::glsl::show_translation_unit;
use glsl_quasiquote::glsl;
pub struct Mercator(pub ShaderStage); pub struct Mercator(pub ShaderStage);
impl Mercator { impl Mercator {
pub fn new() -> Self { pub fn new() -> Self {
let raw = glsl! { let raw = {
"
uniform float R; uniform float R;
@ -36,9 +37,10 @@ impl Mercator {
return vec2(lon, lat); // 返回经纬度 (lon, lat) return vec2(lon, lat); // 返回经纬度 (lon, lat)
} }
"
}; };
Self(raw) Self(ShaderStage::parse(raw).unwrap())
} }
} }

View File

@ -1,24 +1,25 @@
use super::trackball::Trackball; use super::trackball::Trackball;
use super::CodePiece; use super::CodePiece;
use crate::impl_code_piece; use crate::impl_code_piece;
use glsl::parser::Parse;
use glsl::syntax::ShaderStage; use glsl::syntax::ShaderStage;
use glsl::syntax::TranslationUnit; use glsl::syntax::TranslationUnit;
use glsl::transpiler::glsl::show_translation_unit; use glsl::transpiler::glsl::show_translation_unit;
use glsl_quasiquote::glsl;
pub struct TerrainVertex(pub ShaderStage); pub struct TerrainVertex(pub ShaderStage);
pub struct TerrainFragment(pub ShaderStage); pub struct TerrainFragment(pub ShaderStage);
impl TerrainVertex { impl TerrainVertex {
pub fn new() -> Self { pub fn new() -> Self {
let raw = glsl! { let raw = {
"
layout(location = 0) in vec4 in_position; layout(location = 0) in vec4 in_position;
void main() { void main() {
gl_Position = in_position; gl_Position = in_position;
} }
"
}; };
Self(raw) Self(ShaderStage::parse(raw).unwrap())
} }
} }
@ -27,7 +28,8 @@ impl TerrainFragment {
use super::polar::PolarTransform; use super::polar::PolarTransform;
let mut include = PolarTransform::new().raw; let mut include = PolarTransform::new().raw;
let mut colormap = super::colormap::ColorMap::new().0; let mut colormap = super::colormap::ColorMap::new().0;
let raw = glsl! { let raw = {
"
// Perspective Camera // Perspective Camera
uniform vec2 projection_params; uniform vec2 projection_params;
@ -128,10 +130,11 @@ impl TerrainFragment {
FragColor = vec4(1.0, 0.0, 0.0, 1.0); FragColor = vec4(1.0, 0.0, 0.0, 1.0);
} }
"
}; };
include.extend(colormap); include.extend(colormap);
include.extend(raw); include.extend(ShaderStage::parse(raw).unwrap());
Self(include) Self(include)
} }

View File

@ -1,4 +1,5 @@
use super::CodePiece; use super::CodePiece;
use glsl::parser::Parse;
use glsl::syntax::ShaderStage; use glsl::syntax::ShaderStage;
use glsl::syntax::TranslationUnit; use glsl::syntax::TranslationUnit;
use glsl::transpiler::glsl::show_translation_unit; use glsl::transpiler::glsl::show_translation_unit;
@ -9,7 +10,8 @@ pub struct Trackball(pub ShaderStage);
impl Trackball { impl Trackball {
pub fn new() -> Self { pub fn new() -> Self {
let raw = glsl_quasiquote::glsl! { let raw = {
"
uniform mat4 trackball_view; uniform mat4 trackball_view;
uniform mat4 trackball_model; uniform mat4 trackball_model;
uniform mat4 trackball_projection; uniform mat4 trackball_projection;
@ -61,9 +63,10 @@ impl Trackball {
{ {
return vec4(x, yz, 1.0); return vec4(x, yz, 1.0);
} }
"
}; };
Self(raw) Self(ShaderStage::parse(raw).unwrap())
} }
} }

View File

@ -24,6 +24,7 @@ use crate::widgets;
#[derive(Debug)] #[derive(Debug)]
pub struct ItemInfo { pub struct ItemInfo {
pub module_ref: ModuleRefs,
pub module_name: &'static str, pub module_name: &'static str,
pub module_icon: &'static str, pub module_icon: &'static str,
} }

View File

@ -1,4 +1,4 @@
use gi::pg::{ModulePackage, Modules}; use gi::pg::{ModulePackage, ModuleRefs, Modules};
use gtk::Widget; use gtk::Widget;
use radarg_core::datapool::Value; use radarg_core::datapool::Value;
use radarg_core::Data; use radarg_core::Data;
@ -7,7 +7,7 @@ use std::{cell::RefCell, fmt::Debug, rc::Rc, sync::Arc};
pub enum MonitorInputMsg { pub enum MonitorInputMsg {
Start, Start,
PushData(Value<Data>), PushData(Value<Data>),
Draw(&'static str, Arc<Data>), Draw(ModuleRefs, Arc<Data>),
Prepare(Vec<Arc<Data>>), Prepare(Vec<Arc<Data>>),
KeyPress(u32), KeyPress(u32),
KeyRelease(u32), KeyRelease(u32),

View File

@ -29,44 +29,6 @@ use slippy_map_tiles::Tile;
use tokio::task; use tokio::task;
use tracing::instrument::WithSubscriber; use tracing::instrument::WithSubscriber;
macro_rules! impl_draw {
($slf:ident,$module_name:ident,$widgets:ident,$data:ident, $sender:ident, $({$module:ty | $method:ident }),+) => {
$widgets.renderer.get_gi(|gi| {
let data: &Data = &*$data;
match $module_name {
$(
<$module>::NAME => {
// let data = $data.as_ref().map(|v| &*v).unwrap_or(());
match gi.program().$method().load_data(data.try_into().unwrap(), &SETTING) {
Ok(package) => {
let package = Rc::new(RefCell::new(package.into()));
$slf.update_module_packages(|p| {
p.clear();
p.push((data.description.clone(), package));
});
$sender.output(MonitorOutputMsg::Attached($slf.module_packages.clone()));
}
Err(e) => {
error!("Error loading data: {:?}", e);
$sender.output(MonitorOutputMsg::Alert(e.to_string(), format!("Close")));
}
}
}
)+
_ => {
error!("Unsupported module: {}", $module_name);
$sender.output(MonitorOutputMsg::Alert(
format!("Unsupported module: {}", $module_name),
format!("Close"),
));
}
}
$sender.input(MonitorInputMsg::QueueDraw);
});
};
}
#[derive(Debug)] #[derive(Debug)]
pub enum MonitorCommand { pub enum MonitorCommand {
LoadedTile, LoadedTile,
@ -135,6 +97,8 @@ impl Component for MonitorModel {
MonitorInputMsg::Start => { MonitorInputMsg::Start => {
// Init Earth // Init Earth
} }
// Get the supported modules for the data
MonitorInputMsg::PushData(data) => { MonitorInputMsg::PushData(data) => {
widgets.renderer.get_gi(|gi| { widgets.renderer.get_gi(|gi| {
let supported_modules = gi.supported_modules(&data); let supported_modules = gi.supported_modules(&data);
@ -143,8 +107,10 @@ impl Component for MonitorModel {
for (data, modules) in supported_modules { for (data, modules) in supported_modules {
let mut module_packages = vec![]; let mut module_packages = vec![];
for module in modules { for module in modules {
let name = module.id;
module_packages.push(ItemInfo { module_packages.push(ItemInfo {
module_name: module.name(), module_ref: module,
module_name: name,
module_icon: "plus", module_icon: "plus",
}); });
} }
@ -153,7 +119,7 @@ impl Component for MonitorModel {
if result.len() == 1 && result.values().next().unwrap().len() == 1 { if result.len() == 1 && result.values().next().unwrap().len() == 1 {
sender.input(MonitorInputMsg::Draw( sender.input(MonitorInputMsg::Draw(
result.values().next().unwrap().first().unwrap().module_name, result.values().next().unwrap().first().unwrap().module_ref,
data.values().next().unwrap().clone(), data.values().next().unwrap().clone(),
)); ));
} else { } else {
@ -190,6 +156,8 @@ impl Component for MonitorModel {
} }
}); });
} }
// Redraw
MonitorInputMsg::QueueDraw => { MonitorInputMsg::QueueDraw => {
widgets.renderer.queue_render(); widgets.renderer.queue_render();
} }
@ -224,15 +192,24 @@ impl Component for MonitorModel {
sender.output(MonitorOutputMsg::DialogClose); sender.output(MonitorOutputMsg::DialogClose);
}), }),
MonitorInputMsg::Draw(module, ref data) => { MonitorInputMsg::Draw(module, ref data) => {
impl_draw!( widgets.renderer.get_gi(|gi| {
self, match gi.program().module(&module).load_data(&*data, &SETTING) {
module, Ok(package) => {
widgets, let package = Rc::new(RefCell::new(package.into()));
data,
sender, self.update_module_packages(|p| {
{ PPIModule | ppi }, p.clear();
{ GeoQuadMeshModule | geo_quad_mesh } // { EarthModule | earth } p.push((data.description.clone(), package));
); });
sender.output(MonitorOutputMsg::Attached(self.module_packages.clone()));
}
Err(e) => {
error!("Error loading data: {:?}", e);
sender.output(MonitorOutputMsg::Alert(e.to_string(), format!("Close")));
}
}
});
} }
MonitorInputMsg::KeyPress(key) => { MonitorInputMsg::KeyPress(key) => {
widgets.renderer.set_key_pressed(key); widgets.renderer.set_key_pressed(key);