fix(panel): applying materials works

This commit is contained in:
Nova
2022-08-22 15:59:52 -04:00
parent 7e6705a012
commit a81070a7c9
6 changed files with 42 additions and 28 deletions

View File

@@ -4,7 +4,7 @@ use super::spatial::{get_spatial_parent_flex, get_transform_pose_flex, Spatial};
use crate::core::client::{Client, INTERNAL_CLIENT};
use crate::core::nodelist::LifeLinkedNodeList;
use crate::core::registry::Registry;
use crate::wayland::panel_item::PanelItem;
use crate::wayland::panel_item::{register_panel_item_ui_flex, PanelItem};
use anyhow::{anyhow, ensure, Result};
use lazy_static::lazy_static;
use nanoid::nanoid;
@@ -316,6 +316,7 @@ pub fn create_interface(client: &Arc<Client>) {
"registerEnvironmentItemUI",
register_environment_item_ui_flex,
);
node.add_local_signal("registerPanelItemUI", register_panel_item_ui_flex);
node.add_local_signal(
"createEnvironmentItemAcceptor",
create_environment_item_acceptor_flex,

View File

@@ -24,13 +24,11 @@ impl CompositorHandler for WaylandState {
compositor::with_states(surface, |data| {
if let Some(surface_states) = data.data_map.get::<RendererSurfaceStateUserData>() {
if let Some(core_surface) = data.data_map.get::<CoreSurface>() {
core_surface.wl_tex.replace(
surface_states
.borrow()
.texture(&self.renderer)
.cloned()
.map(SendWrapper::new),
);
*core_surface.wl_tex.lock() = surface_states
.borrow()
.texture(&self.renderer)
.cloned()
.map(SendWrapper::new);
}
}
});

View File

@@ -1,5 +1,5 @@
pub mod panel_item;
pub mod compositor;
pub mod panel_item;
pub mod shaders;
pub mod surface;
pub mod xdg_decoration;

View File

@@ -5,7 +5,7 @@ use crate::{
},
nodes::{
core::Node,
item::{Item, ItemType, TypeInfo},
item::{register_item_ui_flex, Item, ItemType, TypeInfo},
spatial::Spatial,
},
};
@@ -68,7 +68,7 @@ impl PanelItem {
fn apply_surface_material(node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
let flex_vec = flexbuffers::Reader::get_root(data)?.get_vector()?;
let material_idx = flex_vec.idx(0).get_u64()?;
let material_idx = flex_vec.idx(1).get_u64()?;
let model_node = calling_client
.scenegraph
.get_node(flex_vec.idx(0).as_str())
@@ -80,17 +80,29 @@ impl PanelItem {
if let ItemType::Panel(panel_item) = &node.item.get().unwrap().specialization {
compositor::with_states(&panel_item.toplevel_surface, |states| {
if let Some(core_surface) = states.data_map.get::<CoreSurface>() {
if let Some(sk_mat) = core_surface.sk_mat.get() {
model
.pending_material_replacements
.lock()
.insert(material_idx as u32, sk_mat.clone());
}
}
let sk_mat = states
.data_map
.get::<CoreSurface>()
.unwrap()
.sk_mat
.get()
.unwrap()
.clone();
model
.pending_material_replacements
.lock()
.insert(material_idx as u32, sk_mat);
});
}
Ok(())
}
}
pub fn register_panel_item_ui_flex(
_node: &Node,
calling_client: Arc<Client>,
_data: &[u8],
) -> Result<()> {
register_item_ui_flex(calling_client, &ITEM_TYPE_INFO_PANEL)
}

View File

@@ -1,7 +1,8 @@
use std::{cell::RefCell, fmt::Error, sync::Arc};
use std::{fmt::Error, sync::Arc};
use glam::vec2;
use once_cell::sync::OnceCell;
use parking_lot::Mutex;
use send_wrapper::SendWrapper;
use smithay::backend::renderer::{gles2::Gles2Texture, Texture};
use stereokit::{
@@ -14,15 +15,15 @@ use stereokit::{
use super::shaders::SIMULA_SHADER_BYTES;
pub struct CoreSurface {
pub wl_tex: RefCell<Option<SendWrapper<Gles2Texture>>>,
sk_tex: OnceCell<SKTexture>,
pub wl_tex: Mutex<Option<SendWrapper<Gles2Texture>>>,
sk_tex: OnceCell<SendWrapper<SKTexture>>,
pub sk_mat: OnceCell<Arc<SendWrapper<Material>>>,
}
impl CoreSurface {
pub fn new() -> Self {
CoreSurface {
wl_tex: RefCell::new(None),
wl_tex: Mutex::new(None),
sk_tex: OnceCell::new(),
sk_mat: OnceCell::new(),
}
@@ -32,7 +33,9 @@ impl CoreSurface {
let sk_tex = self
.sk_tex
.get_or_try_init(|| {
SKTexture::create(sk, TextureType::ImageNoMips, TextureFormat::RGBA32).ok_or(Error)
SKTexture::create(sk, TextureType::ImageNoMips, TextureFormat::RGBA32)
.ok_or(Error)
.map(SendWrapper::new)
})
.unwrap();
let sk_mat = self
@@ -42,13 +45,13 @@ impl CoreSurface {
Material::create(sk, &shader)
.ok_or(Error)
.map(|mat| {
mat.set_parameter("diffuse", self.sk_tex.get().unwrap());
mat.set_parameter("diffuse", &**self.sk_tex.get().unwrap());
mat
})
.map(|mat| Arc::new(SendWrapper::new(mat)))
})
.unwrap();
if let Some(smithay_tex) = self.wl_tex.borrow().as_ref() {
if let Some(smithay_tex) = self.wl_tex.lock().as_ref() {
unsafe {
sk_tex.set_native(
smithay_tex.tex_id() as usize,

View File

@@ -28,9 +28,9 @@ impl XdgShellHandler for WaylandState {
surface.send_configure();
compositor::with_states(surface.wl_surface(), |data| {
data.data_map.insert_if_missing(CoreSurface::new);
data.data_map.insert_if_missing_threadsafe(CoreSurface::new);
data.data_map
.insert_if_missing(|| PanelItem::create(surface.wl_surface().clone()));
.insert_if_missing_threadsafe(|| PanelItem::create(surface.wl_surface().clone()));
});
}