use log::*; use radarg_core::{datapool::Value, radarg_data::Data}; use std::{cell::RefCell, collections::HashMap, path::PathBuf, rc::Rc, sync::Arc}; use crate::{ errors::*, graphics::{ colormap::linear::LinearColormap, threed::Trackball, transforms::plane::PlaneTrans, AttaWithBuffer, AttaWithProgram, Graphics, }, ui::{ helper::{self, Helper}, operation::{Operation, Operations}, }, utils::resources::{ ManagedResource, RcGlBuffer, RcGlFramebuffer, RcGlRcFramebuffer, RcGlRcRenderbuffer, RcGlRcResource, RcGlRenderbuffer, RcGlResource, RcGlVertexArray, GL, }, }; use glow::HasContext; use super::{ layout_type::{self, ViewPort}, Module, ModuleRefs, }; use super::{ModulePackage, Programs}; use crate::{font_manager::FontManager, graphics::font::Text}; pub struct App { gl: GL, pub context: Context, pub init_modules: Option, } impl App { pub fn new(gl: GL, helper: Helper) -> Result { let programs = Programs::new(gl.clone()).unwrap(); let context = Context::new(gl.clone(), helper, programs); Ok(Self { gl, context, init_modules: None, }) } pub fn prepare(&mut self, setting: &radarg_core::config::Setting) -> Result<()> { if let Err(e) = self.context.programs.prepare() { error!("prepare failed: {:?}", e); } Ok(()) } pub fn set_init_modules>(&mut self, modules: T) { self.init_modules = Some(modules.into()); } pub fn render<'a>( &'a mut self, modules: &mut Vec>>, operation: &Operations, viewport: &ViewPort, ) { if let Some(module) = self.init_modules.as_mut() { let programs = &mut self.context.programs; programs.draw_modules(module, operation, viewport); } for module in modules { let mut module = module.borrow_mut(); self.program() .draw_modules(&mut *module, operation, viewport); } } pub fn destroy(&mut self) { self.context.programs.destroy().unwrap(); } pub fn program(&mut self) -> &mut Programs { &mut self.context.programs } pub fn supported_modules<'a>( &mut self, data: &'a Value, ) -> HashMap<&'a Arc, Vec> { self.program().supported_modules(data) } } pub struct Context { pub gl: GL, pub helper: Helper, pub programs: Programs, } impl Context { fn new(gl: GL, helper: Helper, programs: Programs) -> Self { let context = Context { gl, helper, programs: programs, }; context } }