refactor(surface): use 1 static for shader

This commit is contained in:
Nova
2022-09-05 12:32:59 -04:00
parent cd10fda29e
commit 0a4a448ac9
2 changed files with 9 additions and 5 deletions

View File

@@ -1,4 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
pub const GAMMA_SHADER_BYTES: &[u8] = include_bytes!("shader_unlit_gamma.sks"); // Basic gamma correction shader
pub const SIMULA_SHADER_BYTES: &[u8] = include_bytes!("shader_unlit_simula.sks"); pub const PANEL_SHADER_BYTES: &[u8] = include_bytes!("shader_unlit_gamma.sks");
// Simula shader with fancy lanzcos sampling
// pub const PANEL_SHADER_BYTES: &[u8] = include_bytes!("shader_unlit_simula.sks");

View File

@@ -13,7 +13,7 @@ use smithay::{
wayland::compositor::SurfaceData, wayland::compositor::SurfaceData,
}; };
use stereokit::{ use stereokit::{
material::Material, material::{Material, Transparency},
shader::Shader, shader::Shader,
texture::{Texture as SKTexture, TextureAddress, TextureFormat, TextureSample, TextureType}, texture::{Texture as SKTexture, TextureAddress, TextureFormat, TextureSample, TextureType},
StereoKit, StereoKit,
@@ -21,7 +21,7 @@ use stereokit::{
use crate::core::destroy_queue; use crate::core::destroy_queue;
use super::shaders::SIMULA_SHADER_BYTES; use super::shaders::PANEL_SHADER_BYTES;
pub struct CoreSurface { pub struct CoreSurface {
pub wl_tex: Mutex<Option<SendWrapper<Gles2Texture>>>, pub wl_tex: Mutex<Option<SendWrapper<Gles2Texture>>>,
@@ -50,11 +50,12 @@ impl CoreSurface {
let sk_mat = self let sk_mat = self
.sk_mat .sk_mat
.get_or_try_init(|| { .get_or_try_init(|| {
let shader = Shader::from_mem(sk, SIMULA_SHADER_BYTES).unwrap(); let shader = Shader::from_mem(sk, PANEL_SHADER_BYTES).unwrap();
Material::create(sk, &shader) Material::create(sk, &shader)
.ok_or(Error) .ok_or(Error)
.map(|mat| { .map(|mat| {
mat.set_parameter("diffuse", &**self.sk_tex.get().unwrap()); mat.set_parameter("diffuse", &**self.sk_tex.get().unwrap());
mat.set_transparency(Transparency::Blend);
mat mat
}) })
.map(|mat| Arc::new(SendWrapper::new(mat))) .map(|mat| Arc::new(SendWrapper::new(mat)))