switch to stable rustup
This commit is contained in:
parent
6b68aedc2a
commit
ebca8d2c31
19
Cargo.lock
generated
19
Cargo.lock
generated
@ -1760,7 +1760,6 @@ dependencies = [
|
||||
"geo-macros",
|
||||
"glow",
|
||||
"glsl",
|
||||
"glsl-quasiquote",
|
||||
"glutin",
|
||||
"glutin-winit",
|
||||
"image 0.25.2",
|
||||
@ -2011,18 +2010,6 @@ dependencies = [
|
||||
"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]]
|
||||
name = "glue"
|
||||
version = "0.8.7"
|
||||
@ -3913,12 +3900,6 @@ dependencies = [
|
||||
"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]]
|
||||
name = "proc-macro-hack"
|
||||
version = "0.5.20+deprecated"
|
||||
|
||||
@ -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)]
|
||||
pub fn module_ref_macro(input: TokenStream) -> TokenStream {
|
||||
let struct_item = parse_macro_input!(input as ItemStruct);
|
||||
|
||||
@ -37,7 +37,7 @@ thiserror = "1.0.61"
|
||||
tinyfiledialogs = "3.0"
|
||||
tracker = "0.2.2"
|
||||
glsl = "7.0.0"
|
||||
glsl-quasiquote = "7.0.0"
|
||||
# glsl-quasiquote = "7.0.0"
|
||||
toml = "0.8.19"
|
||||
femtovg = "0.9.2"
|
||||
rust-embed = "8.5.0"
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
#![feature(proc_macro_hygiene)]
|
||||
#![feature(concat_idents)]
|
||||
#![allow(unused)]
|
||||
mod camera;
|
||||
mod components;
|
||||
|
||||
146
gi/src/pg/mod.rs
146
gi/src/pg/mod.rs
@ -55,16 +55,63 @@ pub enum SideBarInputMsg {
|
||||
}
|
||||
|
||||
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 {
|
||||
$(
|
||||
pub fn $name(&mut self) -> $module {
|
||||
<$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 {
|
||||
($({$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>{
|
||||
$(
|
||||
@ -130,11 +129,9 @@ macro_rules! impl_module_package {
|
||||
)+
|
||||
}
|
||||
|
||||
#[derive(Clone,Copy)]
|
||||
pub enum ModuleRefs<'b, 'gl:'b>{
|
||||
$(
|
||||
$b($module_ref<'b,'gl>),
|
||||
)+
|
||||
#[derive(Clone,Copy, Debug)]
|
||||
pub struct ModuleRefs {
|
||||
pub id: &'static str
|
||||
}
|
||||
|
||||
impl Modules<'_, '_> {
|
||||
@ -150,16 +147,18 @@ macro_rules! impl_module_package {
|
||||
}
|
||||
}
|
||||
|
||||
impl ModuleRefs<'_, '_> {
|
||||
pub fn name(&self) -> &'static str {
|
||||
match self {
|
||||
impl Programs {
|
||||
pub fn module(&mut self, r: &ModuleRefs) -> Modules {
|
||||
match r.id {
|
||||
$(
|
||||
ModuleRefs::$b(m) => m.name(),
|
||||
<$module as Module>::NAME => Modules::$b(self.$method()),
|
||||
)+
|
||||
_ => panic!("Module not found"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #[derive(Debug)]
|
||||
pub enum _ModulePackage {
|
||||
$(
|
||||
@ -279,9 +278,10 @@ macro_rules! impl_module_package {
|
||||
for (k, d) in data.iter() {
|
||||
$(
|
||||
{
|
||||
if self.$ref_method().supported(d) {
|
||||
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)]);
|
||||
if self.$method().supported(d) {
|
||||
// let _ref = self.$ref_method();
|
||||
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!(
|
||||
{ppi | ppi_ref, PPIModule | PPIModuleRef, (_ppi, _text, _line)},
|
||||
{geo_quad_mesh | geo_quad_mesh_ref, GeoQuadMeshModule | GeoQuadMeshModuleRef, (_geo_quad_mesh,_text, _line)},
|
||||
{earth | earth_ref, EarthModule | EarthModuleRef, (_earth)},
|
||||
{terrain | terrain_ref, TerrainModule | TerrainModuleRef, (_terrain)}
|
||||
{ppi, PPIModule,(_ppi, _text, _line)},
|
||||
{geo_quad_mesh , GeoQuadMeshModule , (_geo_quad_mesh,_text, _line)},
|
||||
{earth, EarthModule , (_earth)},
|
||||
{terrain , TerrainModule , (_terrain)}
|
||||
);
|
||||
|
||||
impl_module_package!(
|
||||
{ppi|ppi_ref,PPIPackage => PPI | PPIModule | PPIModuleRef | PPIModuleConfigComponent},
|
||||
{geo_quad_mesh|geo_quad_mesh_ref,GeoQuadMeshPackage => GeoQuadMesh | GeoQuadMeshModule | GeoQuadMeshModuleRef | GeoQuadMeshModuleConfigComponent},
|
||||
{earth|earth_ref, EarthModulePackage => Earth| EarthModule | EarthModuleRef | EarthModuleConfigComponent},
|
||||
{terrain|terrain_ref, TerrainModulePackage => Terrain | TerrainModule | TerrainModuleRef | TerrainModuleConfigComponent}
|
||||
{ppi,PPIPackage => PPI | PPIModule | PPIModuleConfigComponent},
|
||||
{geo_quad_mesh,GeoQuadMeshPackage => GeoQuadMesh | GeoQuadMeshModule |GeoQuadMeshModuleConfigComponent},
|
||||
{earth, EarthModulePackage => Earth| EarthModule |EarthModuleConfigComponent},
|
||||
{terrain, TerrainModulePackage => Terrain | TerrainModule | TerrainModuleConfigComponent}
|
||||
);
|
||||
|
||||
impl ModulePackage {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use geo_macros::{module_ref_impl, ModuleRef};
|
||||
use geo_macros::{module_ref_impl, Module, ModuleRef};
|
||||
use glow::HasContext;
|
||||
use relm4::{
|
||||
adw::{self, prelude::*},
|
||||
@ -18,44 +18,17 @@ use crate::{
|
||||
|
||||
use super::{Module, ModuleCursor};
|
||||
|
||||
#[derive(ModuleRef)]
|
||||
pub struct EarthModule<'b, 'gl: 'b> {
|
||||
gl: &'gl GL,
|
||||
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> {
|
||||
pub fn new(gl: &'gl GL, earth: &'b mut Earth) -> Self {
|
||||
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 {}
|
||||
|
||||
impl<'b, 'gl: 'b> Module for EarthModule<'b, 'gl> {
|
||||
|
||||
@ -44,61 +44,6 @@ pub struct GeoQuadMeshModule<'b, 'gl: 'b> {
|
||||
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> {
|
||||
pub fn new(
|
||||
gl: &'a GL,
|
||||
|
||||
@ -21,7 +21,7 @@ mod terrain;
|
||||
use crate::errors::*;
|
||||
pub use geoquadmesh::{
|
||||
GeoQuadMeshModule, GeoQuadMeshModuleConfig, GeoQuadMeshModuleConfigComponent,
|
||||
GeoQuadMeshModuleConfigComponentWidgets, GeoQuadMeshModuleRef, GeoQuadMeshPackage,
|
||||
GeoQuadMeshModuleConfigComponentWidgets, GeoQuadMeshPackage,
|
||||
};
|
||||
pub use ppi::{
|
||||
PPIModule, PPIModuleConfigComponent, PPIModuleConfigComponentWidgets, PPIModuleRef, PPIPackage,
|
||||
@ -29,12 +29,9 @@ pub use ppi::{
|
||||
|
||||
pub use earth::{
|
||||
EarthModule, EarthModuleConfigComponent, EarthModuleConfigComponentWidgets, EarthModulePackage,
|
||||
EarthModuleRef,
|
||||
};
|
||||
|
||||
pub use terrain::{
|
||||
TerrainModule, TerrainModuleConfigComponent, TerrainModulePackage, TerrainModuleRef,
|
||||
};
|
||||
pub use terrain::{TerrainModule, TerrainModuleConfigComponent, TerrainModulePackage};
|
||||
|
||||
use relm4::Component as RComponent;
|
||||
|
||||
|
||||
@ -18,7 +18,6 @@ use crate::{
|
||||
|
||||
use super::{Module, ModuleCursor};
|
||||
|
||||
#[derive(ModuleRef)]
|
||||
pub struct TerrainModule<'b, 'gl: 'b> {
|
||||
gl: &'gl GL,
|
||||
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> {
|
||||
pub fn new(gl: &'gl GL, terrain: &'b mut Terrain) -> Self {
|
||||
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 {
|
||||
conf: TerrainModulePackageConfig,
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use glsl::parser::Parse;
|
||||
use glsl::syntax::ShaderStage;
|
||||
use glsl::syntax::TranslationUnit;
|
||||
use glsl::transpiler::glsl::show_translation_unit;
|
||||
use glsl_quasiquote::glsl;
|
||||
|
||||
use crate::impl_code_piece;
|
||||
|
||||
@ -14,7 +14,8 @@ pub struct AggPathFragment(ShaderStage);
|
||||
impl AggPathVertex {
|
||||
pub fn new() -> Self {
|
||||
let mut transform = Trackball::new().0;
|
||||
let raw = glsl! {
|
||||
let raw = {
|
||||
"
|
||||
|
||||
layout(location = 0) in vec3 prev;
|
||||
layout(location = 1) in vec3 curr;
|
||||
@ -72,9 +73,10 @@ impl AggPathVertex {
|
||||
// Back to NDC coordinates
|
||||
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)
|
||||
}
|
||||
@ -82,7 +84,8 @@ impl AggPathVertex {
|
||||
|
||||
impl AggPathFragment {
|
||||
pub fn new() -> Self {
|
||||
let raw = glsl! {
|
||||
let raw = {
|
||||
"
|
||||
uniform float antialias;
|
||||
uniform float thickness;
|
||||
|
||||
@ -117,8 +120,9 @@ impl AggPathFragment {
|
||||
if (v_color.a == 0) {discard;}
|
||||
fragColor = stroke(v_distance, thickness, antialias, v_color);
|
||||
}
|
||||
"
|
||||
};
|
||||
Self(raw)
|
||||
Self(ShaderStage::parse(raw).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,15 +1,16 @@
|
||||
use super::CodePiece;
|
||||
use crate::impl_code_piece;
|
||||
use glsl::parser::Parse;
|
||||
use glsl::syntax::ShaderStage;
|
||||
use glsl::syntax::TranslationUnit;
|
||||
use glsl::transpiler::glsl::show_translation_unit;
|
||||
use glsl_quasiquote::glsl;
|
||||
|
||||
pub struct ColorMap(pub ShaderStage);
|
||||
|
||||
impl ColorMap {
|
||||
pub fn new() -> Self {
|
||||
let raw = glsl! {
|
||||
let raw = {
|
||||
"
|
||||
uniform sampler1D colormap;
|
||||
uniform vec4 colormap_conf;
|
||||
|
||||
@ -41,9 +42,10 @@ impl ColorMap {
|
||||
vec4 result = texture(colormap, idx);
|
||||
return vec4(result.rgb, 1.0);
|
||||
}
|
||||
"
|
||||
};
|
||||
|
||||
Self(raw)
|
||||
Self(ShaderStage::parse(raw).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,31 +1,34 @@
|
||||
use super::trackball::Trackball;
|
||||
use super::CodePiece;
|
||||
use crate::impl_code_piece;
|
||||
use glsl::parser::Parse;
|
||||
use glsl::syntax::ShaderStage;
|
||||
use glsl::syntax::TranslationUnit;
|
||||
use glsl::transpiler::glsl::show_translation_unit;
|
||||
use glsl_quasiquote::glsl;
|
||||
|
||||
pub struct EarthVertex(pub ShaderStage);
|
||||
pub struct EarthFragment(pub ShaderStage);
|
||||
|
||||
impl EarthVertex {
|
||||
pub fn new() -> Self {
|
||||
let raw = glsl! {
|
||||
let raw = {
|
||||
"
|
||||
layout(location = 0) in vec3 in_position;
|
||||
void main() {
|
||||
gl_Position = vec4(in_position, 1.0);
|
||||
}
|
||||
|
||||
"
|
||||
};
|
||||
|
||||
Self(raw)
|
||||
Self(ShaderStage::parse(raw).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl EarthFragment {
|
||||
pub fn new() -> Self {
|
||||
let raw = glsl! {
|
||||
let raw = {
|
||||
"
|
||||
|
||||
uniform vec3 camera_location;
|
||||
uniform float focal_length;
|
||||
@ -141,9 +144,10 @@ impl EarthFragment {
|
||||
FragColor = vec4(col, 1.0);
|
||||
}
|
||||
|
||||
"
|
||||
};
|
||||
|
||||
Self(raw)
|
||||
Self(ShaderStage::parse(raw).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
use super::trackball::Trackball;
|
||||
use super::CodePiece;
|
||||
use crate::components::Shader;
|
||||
use crate::impl_code_piece;
|
||||
use glsl::parser::Parse;
|
||||
use glsl::syntax::ShaderStage;
|
||||
use glsl::syntax::TranslationUnit;
|
||||
use glsl::transpiler::glsl::show_translation_unit;
|
||||
use glsl_quasiquote::glsl;
|
||||
|
||||
pub struct FontVertex(pub ShaderStage);
|
||||
|
||||
@ -14,7 +15,8 @@ pub struct FontGeometry(pub ShaderStage);
|
||||
|
||||
impl FontVertex {
|
||||
pub fn new() -> Self {
|
||||
let raw = glsl! {
|
||||
let raw = {
|
||||
"
|
||||
|
||||
// texcoord (left top, right bottom)
|
||||
layout(location = 0) in vec4 texcoord;
|
||||
@ -31,16 +33,18 @@ impl FontVertex {
|
||||
vs_out.texcoord = texcoord;
|
||||
vs_out.pos = relative_position;
|
||||
}
|
||||
"
|
||||
};
|
||||
|
||||
Self(raw)
|
||||
Self(ShaderStage::parse(raw).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl FontGeometry {
|
||||
pub fn new() -> Self {
|
||||
let mut transform = Trackball::new().0;
|
||||
let raw = glsl! {
|
||||
let raw = {
|
||||
"
|
||||
|
||||
layout(points) in;
|
||||
layout(triangle_strip, max_vertices = 4) out;
|
||||
@ -123,9 +127,10 @@ impl FontGeometry {
|
||||
EndPrimitive();
|
||||
}
|
||||
|
||||
"
|
||||
};
|
||||
|
||||
transform.extend(raw);
|
||||
transform.extend(ShaderStage::parse(raw).unwrap());
|
||||
|
||||
Self(transform)
|
||||
}
|
||||
@ -133,7 +138,8 @@ impl FontGeometry {
|
||||
|
||||
impl FontFragment {
|
||||
pub fn new() -> Self {
|
||||
let raw = glsl! {
|
||||
let raw = {
|
||||
"
|
||||
uniform sampler2D atlas_data;
|
||||
in vec2 v_texCoord;
|
||||
in vec2 UV_coord;
|
||||
@ -202,9 +208,10 @@ impl FontFragment {
|
||||
|
||||
|
||||
}
|
||||
"
|
||||
};
|
||||
|
||||
Self(raw)
|
||||
Self(ShaderStage::parse(raw).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
use super::colormap::ColorMap;
|
||||
use super::trackball::Trackball;
|
||||
use super::CodePiece;
|
||||
use crate::components::Shader;
|
||||
use crate::impl_code_piece;
|
||||
use glsl::parser::Parse;
|
||||
use glsl::syntax::{ShaderStage, TranslationUnit};
|
||||
use glsl::transpiler::glsl::show_translation_unit;
|
||||
use glsl_quasiquote::glsl;
|
||||
|
||||
use super::proj::Mercator;
|
||||
|
||||
@ -16,7 +17,8 @@ impl GeoQuadMeshVertex {
|
||||
pub fn new() -> Self {
|
||||
let mut mercator = Mercator::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.
|
||||
layout(location = 0) in vec3 in_position;
|
||||
layout(location = 1) in vec3 relative_position;
|
||||
@ -29,10 +31,11 @@ impl GeoQuadMeshVertex {
|
||||
gl_Position = transform(position(relative_position));
|
||||
}
|
||||
|
||||
"
|
||||
};
|
||||
|
||||
mercator.extend(trackball);
|
||||
mercator.extend(raw);
|
||||
mercator.extend(ShaderStage::parse(raw).unwrap());
|
||||
Self(mercator)
|
||||
}
|
||||
}
|
||||
@ -43,7 +46,8 @@ impl GeoQuadMeshFragment {
|
||||
|
||||
let color_map = ColorMap::new().0;
|
||||
|
||||
let raw = glsl! {
|
||||
let raw = {
|
||||
"
|
||||
// lon_s,lon_e, lat_s, lat_e
|
||||
uniform vec4 tex_conf;
|
||||
// hgt, lat, lon
|
||||
@ -122,10 +126,11 @@ impl GeoQuadMeshFragment {
|
||||
fragColor = color;
|
||||
|
||||
}
|
||||
"
|
||||
};
|
||||
|
||||
mercator.extend(color_map);
|
||||
mercator.extend(raw);
|
||||
mercator.extend(ShaderStage::parse(raw).unwrap());
|
||||
|
||||
Self(mercator)
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use glsl::parser::Parse;
|
||||
use glsl::syntax::ShaderStage;
|
||||
use glsl_quasiquote::glsl;
|
||||
|
||||
use super::CodePiece;
|
||||
use glsl::syntax::TranslationUnit;
|
||||
@ -13,7 +13,8 @@ pub struct Constants {
|
||||
|
||||
impl Constants {
|
||||
pub fn new() -> Constants {
|
||||
let raw = glsl! {
|
||||
let raw = {
|
||||
"
|
||||
|
||||
#ifndef _GLUMPY__CONSTANTS__
|
||||
#define _GLUMPY__CONSTANTS__
|
||||
@ -64,8 +65,11 @@ impl Constants {
|
||||
const float radian = M_PI/180.0;
|
||||
|
||||
#endif
|
||||
"
|
||||
};
|
||||
|
||||
let raw = ShaderStage::parse(raw).unwrap();
|
||||
|
||||
Constants { raw }
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,37 +14,9 @@ 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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
use super::CodePiece;
|
||||
use crate::components::Shader;
|
||||
use crate::impl_code_piece;
|
||||
use glsl::parser::Parse;
|
||||
use glsl::syntax::ShaderStage;
|
||||
use glsl::syntax::TranslationUnit;
|
||||
use glsl::transpiler::glsl::show_translation_unit;
|
||||
|
||||
use super::math::Constants;
|
||||
use glsl_quasiquote::glsl;
|
||||
|
||||
pub struct PolarTransform {
|
||||
pub raw: ShaderStage,
|
||||
@ -13,7 +14,8 @@ pub struct PolarTransform {
|
||||
|
||||
impl PolarTransform {
|
||||
pub fn new() -> PolarTransform {
|
||||
let raw = glsl! {
|
||||
let raw = {
|
||||
"
|
||||
|
||||
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(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); }
|
||||
"
|
||||
};
|
||||
|
||||
let mut constant = Constants::new().raw;
|
||||
|
||||
constant.extend(raw);
|
||||
constant.extend(ShaderStage::parse(raw).unwrap());
|
||||
|
||||
PolarTransform { raw: constant }
|
||||
}
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
use super::trackball::Trackball;
|
||||
use super::CodePiece;
|
||||
use crate::impl_code_piece;
|
||||
use glsl::parser::Parse;
|
||||
use glsl::syntax::ShaderStage;
|
||||
use glsl::syntax::TranslationUnit;
|
||||
use glsl::transpiler::glsl::show_translation_unit;
|
||||
use glsl_quasiquote::glsl;
|
||||
|
||||
pub struct PPIVertex(pub ShaderStage);
|
||||
pub struct PPIGeom(pub ShaderStage);
|
||||
@ -12,7 +12,8 @@ pub struct PPIFragment(pub ShaderStage);
|
||||
|
||||
impl PPIVertex {
|
||||
pub fn new() -> Self {
|
||||
let raw = glsl! {
|
||||
let raw = {
|
||||
"
|
||||
layout(location = 0) in vec4 position;
|
||||
out float in_value;
|
||||
|
||||
@ -20,9 +21,10 @@ impl PPIVertex {
|
||||
gl_Position = vec4(position.x * 10.0, position.y, position.z, 1.0);
|
||||
in_value = position.w;
|
||||
}
|
||||
"
|
||||
};
|
||||
|
||||
Self(raw)
|
||||
Self(ShaderStage::parse(raw).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +32,8 @@ impl PPIGeom {
|
||||
pub fn new() -> Self {
|
||||
let mut trackball = Trackball::new().0;
|
||||
let polar = super::polar::PolarTransform::new().raw;
|
||||
let raw = glsl! {
|
||||
let raw = {
|
||||
"
|
||||
layout(points) in;
|
||||
layout(triangle_strip, max_vertices = 4) out;
|
||||
|
||||
@ -93,10 +96,11 @@ impl PPIGeom {
|
||||
|
||||
}
|
||||
|
||||
"
|
||||
};
|
||||
|
||||
trackball.extend(polar);
|
||||
trackball.extend(raw);
|
||||
trackball.extend(ShaderStage::parse(raw).unwrap());
|
||||
|
||||
Self(trackball)
|
||||
}
|
||||
@ -107,7 +111,8 @@ impl PPIFragment {
|
||||
use super::polar::PolarTransform;
|
||||
let mut include = PolarTransform::new().raw;
|
||||
let mut colormap = super::colormap::ColorMap::new().0;
|
||||
let raw = glsl! {
|
||||
let raw = {
|
||||
"
|
||||
in float x;
|
||||
in float y;
|
||||
|
||||
@ -133,10 +138,11 @@ impl PPIFragment {
|
||||
|
||||
FragColor = result;
|
||||
}
|
||||
"
|
||||
};
|
||||
|
||||
include.extend(colormap);
|
||||
include.extend(raw);
|
||||
include.extend(ShaderStage::parse(raw).unwrap());
|
||||
|
||||
Self(include)
|
||||
}
|
||||
|
||||
@ -1,15 +1,16 @@
|
||||
use super::CodePiece;
|
||||
use crate::impl_code_piece;
|
||||
use glsl::parser::Parse;
|
||||
use glsl::syntax::ShaderStage;
|
||||
use glsl::syntax::TranslationUnit;
|
||||
use glsl::transpiler::glsl::show_translation_unit;
|
||||
use glsl_quasiquote::glsl;
|
||||
|
||||
pub struct Mercator(pub ShaderStage);
|
||||
|
||||
impl Mercator {
|
||||
pub fn new() -> Self {
|
||||
let raw = glsl! {
|
||||
let raw = {
|
||||
"
|
||||
|
||||
uniform float R;
|
||||
|
||||
@ -36,9 +37,10 @@ impl Mercator {
|
||||
|
||||
return vec2(lon, lat); // 返回经纬度 (lon, lat)
|
||||
}
|
||||
"
|
||||
};
|
||||
|
||||
Self(raw)
|
||||
Self(ShaderStage::parse(raw).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,24 +1,25 @@
|
||||
use super::trackball::Trackball;
|
||||
use super::CodePiece;
|
||||
use crate::impl_code_piece;
|
||||
use glsl::parser::Parse;
|
||||
use glsl::syntax::ShaderStage;
|
||||
use glsl::syntax::TranslationUnit;
|
||||
use glsl::transpiler::glsl::show_translation_unit;
|
||||
use glsl_quasiquote::glsl;
|
||||
|
||||
pub struct TerrainVertex(pub ShaderStage);
|
||||
pub struct TerrainFragment(pub ShaderStage);
|
||||
|
||||
impl TerrainVertex {
|
||||
pub fn new() -> Self {
|
||||
let raw = glsl! {
|
||||
let raw = {
|
||||
"
|
||||
layout(location = 0) in vec4 in_position;
|
||||
void main() {
|
||||
gl_Position = in_position;
|
||||
}
|
||||
"
|
||||
};
|
||||
|
||||
Self(raw)
|
||||
Self(ShaderStage::parse(raw).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,7 +28,8 @@ impl TerrainFragment {
|
||||
use super::polar::PolarTransform;
|
||||
let mut include = PolarTransform::new().raw;
|
||||
let mut colormap = super::colormap::ColorMap::new().0;
|
||||
let raw = glsl! {
|
||||
let raw = {
|
||||
"
|
||||
|
||||
// Perspective Camera
|
||||
uniform vec2 projection_params;
|
||||
@ -128,10 +130,11 @@ impl TerrainFragment {
|
||||
FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
"
|
||||
};
|
||||
|
||||
include.extend(colormap);
|
||||
include.extend(raw);
|
||||
include.extend(ShaderStage::parse(raw).unwrap());
|
||||
|
||||
Self(include)
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use super::CodePiece;
|
||||
use glsl::parser::Parse;
|
||||
use glsl::syntax::ShaderStage;
|
||||
use glsl::syntax::TranslationUnit;
|
||||
use glsl::transpiler::glsl::show_translation_unit;
|
||||
@ -9,7 +10,8 @@ pub struct Trackball(pub ShaderStage);
|
||||
|
||||
impl Trackball {
|
||||
pub fn new() -> Self {
|
||||
let raw = glsl_quasiquote::glsl! {
|
||||
let raw = {
|
||||
"
|
||||
uniform mat4 trackball_view;
|
||||
uniform mat4 trackball_model;
|
||||
uniform mat4 trackball_projection;
|
||||
@ -61,9 +63,10 @@ impl Trackball {
|
||||
{
|
||||
return vec4(x, yz, 1.0);
|
||||
}
|
||||
"
|
||||
};
|
||||
|
||||
Self(raw)
|
||||
Self(ShaderStage::parse(raw).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -24,6 +24,7 @@ use crate::widgets;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ItemInfo {
|
||||
pub module_ref: ModuleRefs,
|
||||
pub module_name: &'static str,
|
||||
pub module_icon: &'static str,
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use gi::pg::{ModulePackage, Modules};
|
||||
use gi::pg::{ModulePackage, ModuleRefs, Modules};
|
||||
use gtk::Widget;
|
||||
use radarg_core::datapool::Value;
|
||||
use radarg_core::Data;
|
||||
@ -7,7 +7,7 @@ use std::{cell::RefCell, fmt::Debug, rc::Rc, sync::Arc};
|
||||
pub enum MonitorInputMsg {
|
||||
Start,
|
||||
PushData(Value<Data>),
|
||||
Draw(&'static str, Arc<Data>),
|
||||
Draw(ModuleRefs, Arc<Data>),
|
||||
Prepare(Vec<Arc<Data>>),
|
||||
KeyPress(u32),
|
||||
KeyRelease(u32),
|
||||
|
||||
@ -29,44 +29,6 @@ use slippy_map_tiles::Tile;
|
||||
use tokio::task;
|
||||
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)]
|
||||
pub enum MonitorCommand {
|
||||
LoadedTile,
|
||||
@ -135,6 +97,8 @@ impl Component for MonitorModel {
|
||||
MonitorInputMsg::Start => {
|
||||
// Init Earth
|
||||
}
|
||||
|
||||
// Get the supported modules for the data
|
||||
MonitorInputMsg::PushData(data) => {
|
||||
widgets.renderer.get_gi(|gi| {
|
||||
let supported_modules = gi.supported_modules(&data);
|
||||
@ -143,8 +107,10 @@ impl Component for MonitorModel {
|
||||
for (data, modules) in supported_modules {
|
||||
let mut module_packages = vec![];
|
||||
for module in modules {
|
||||
let name = module.id;
|
||||
module_packages.push(ItemInfo {
|
||||
module_name: module.name(),
|
||||
module_ref: module,
|
||||
module_name: name,
|
||||
module_icon: "plus",
|
||||
});
|
||||
}
|
||||
@ -153,7 +119,7 @@ impl Component for MonitorModel {
|
||||
|
||||
if result.len() == 1 && result.values().next().unwrap().len() == 1 {
|
||||
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(),
|
||||
));
|
||||
} else {
|
||||
@ -190,6 +156,8 @@ impl Component for MonitorModel {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Redraw
|
||||
MonitorInputMsg::QueueDraw => {
|
||||
widgets.renderer.queue_render();
|
||||
}
|
||||
@ -224,15 +192,24 @@ impl Component for MonitorModel {
|
||||
sender.output(MonitorOutputMsg::DialogClose);
|
||||
}),
|
||||
MonitorInputMsg::Draw(module, ref data) => {
|
||||
impl_draw!(
|
||||
self,
|
||||
module,
|
||||
widgets,
|
||||
data,
|
||||
sender,
|
||||
{ PPIModule | ppi },
|
||||
{ GeoQuadMeshModule | geo_quad_mesh } // { EarthModule | earth }
|
||||
);
|
||||
widgets.renderer.get_gi(|gi| {
|
||||
match gi.program().module(&module).load_data(&*data, &SETTING) {
|
||||
Ok(package) => {
|
||||
let package = Rc::new(RefCell::new(package.into()));
|
||||
|
||||
self.update_module_packages(|p| {
|
||||
p.clear();
|
||||
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) => {
|
||||
widgets.renderer.set_key_pressed(key);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user