generated from lks/eframe_template_android
Compare commits
No commits in common. "e37eb169ceb97a4c8211670fce9c0bc3872f2e1d" and "e59f6ce896b8dae6223d61bd9419e304f06cbd33" have entirely different histories.
e37eb169ce
...
e59f6ce896
25
src/app.rs
25
src/app.rs
@ -1,25 +1,11 @@
|
||||
use eframe::{egui_glow, glow};
|
||||
use egui::mutex::Mutex;
|
||||
use std::sync::mpsc;
|
||||
use std::sync::Arc;
|
||||
|
||||
mod waterfall;
|
||||
use waterfall::Waterfall;
|
||||
pub mod turbo_colormap;
|
||||
|
||||
mod deadbeef_rand {
|
||||
static mut RNG_SEED: u32 = 0x3d2faba7;
|
||||
static mut RNG_BEEF: u32 = 0xdeadbeef;
|
||||
pub fn rand() -> u8 {
|
||||
unsafe {
|
||||
RNG_SEED = (RNG_SEED << 7) ^ ((RNG_SEED >> 25).wrapping_add(RNG_BEEF));
|
||||
RNG_BEEF = (RNG_BEEF << 7) ^ ((RNG_BEEF >> 25).wrapping_add(0xdeadbeef));
|
||||
(RNG_SEED & 0xff) as u8
|
||||
}
|
||||
}
|
||||
}
|
||||
use deadbeef_rand::rand;
|
||||
|
||||
/// We derive Deserialize/Serialize so we can persist app state on shutdown.
|
||||
pub struct TemplateApp {
|
||||
// Example stuff:
|
||||
@ -27,7 +13,6 @@ pub struct TemplateApp {
|
||||
value: f32,
|
||||
/// Behind an `Arc<Mutex<…>>` so we can pass it to [`egui::PaintCallback`] and paint later.
|
||||
waterfall: Arc<Mutex<Waterfall>>,
|
||||
fft_sender: mpsc::Sender<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl TemplateApp {
|
||||
@ -39,7 +24,6 @@ impl TemplateApp {
|
||||
// Load previous app state (if any).
|
||||
// Note that you must enable the `persistence` feature for this to work.
|
||||
|
||||
let (tx, rx) = mpsc::channel();
|
||||
let gl = cc
|
||||
.gl
|
||||
.as_ref()
|
||||
@ -49,8 +33,7 @@ impl TemplateApp {
|
||||
// Example stuff:
|
||||
label: "Hello World!".to_owned(),
|
||||
value: 2.7,
|
||||
waterfall: Arc::new(Mutex::new(Waterfall::new(gl, 300, 300, rx))),
|
||||
fft_sender: tx,
|
||||
waterfall: Arc::new(Mutex::new(Waterfall::new(gl, 300, 300))),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -121,12 +104,6 @@ impl eframe::App for TemplateApp {
|
||||
|
||||
let _angle = response.drag_motion().x * 0.01;
|
||||
|
||||
let mut new_data = vec![0_u8; 300];
|
||||
for data in new_data.iter_mut() {
|
||||
*data = rand();
|
||||
}
|
||||
self.fft_sender.send(new_data).unwrap();
|
||||
|
||||
// Clone locals so we can move them into the paint callback:
|
||||
let waterfall = self.waterfall.clone();
|
||||
|
||||
|
||||
@ -1,11 +1,8 @@
|
||||
use eframe::glow::{
|
||||
self, PixelUnpackData, CLAMP_TO_EDGE, TEXTURE0, TEXTURE1, TEXTURE_WRAP_S, UNSIGNED_BYTE,
|
||||
};
|
||||
use eframe::glow::{self, PixelUnpackData, TEXTURE0, TEXTURE1, UNSIGNED_BYTE};
|
||||
use glow::HasContext as _;
|
||||
use glow::{NEAREST, TEXTURE_2D, TEXTURE_MAG_FILTER, TEXTURE_MIN_FILTER};
|
||||
use log;
|
||||
use std::mem::{size_of, transmute};
|
||||
use std::sync::mpsc::Receiver;
|
||||
|
||||
const SIZE_OF_F32: i32 = size_of::<f32>() as i32;
|
||||
|
||||
@ -18,6 +15,19 @@ unsafe fn check_for_gl_errors(gl: &glow::Context, msg: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
mod deadbeef_rand {
|
||||
static mut RNG_SEED: u32 = 0x3d2faba7;
|
||||
static mut RNG_BEEF: u32 = 0xdeadbeef;
|
||||
pub fn rand() -> u8 {
|
||||
unsafe {
|
||||
RNG_SEED = (RNG_SEED << 7) ^ ((RNG_SEED >> 25).wrapping_add(RNG_BEEF));
|
||||
RNG_BEEF = (RNG_BEEF << 7) ^ ((RNG_BEEF >> 25).wrapping_add(0xdeadbeef));
|
||||
(RNG_SEED & 0xff) as u8
|
||||
}
|
||||
}
|
||||
}
|
||||
use deadbeef_rand::rand;
|
||||
|
||||
use crate::app::turbo_colormap;
|
||||
|
||||
pub struct Waterfall {
|
||||
@ -28,8 +38,6 @@ pub struct Waterfall {
|
||||
vbo: glow::Buffer,
|
||||
ebo: glow::Buffer,
|
||||
offset: usize,
|
||||
width: usize,
|
||||
fft_in: Receiver<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl Waterfall {
|
||||
@ -46,6 +54,11 @@ impl Waterfall {
|
||||
pub fn paint(&mut self, gl: &glow::Context, _angle: f32) {
|
||||
use glow::HasContext as _;
|
||||
|
||||
let mut new_data: [u8; 300] = [0; 300];
|
||||
for data in new_data.iter_mut() {
|
||||
*data = rand();
|
||||
}
|
||||
|
||||
unsafe {
|
||||
// Bind our texturs
|
||||
gl.active_texture(TEXTURE1);
|
||||
@ -67,27 +80,22 @@ impl Waterfall {
|
||||
check_for_gl_errors(&gl, "bind vao");
|
||||
|
||||
// Update texture
|
||||
while let Ok(fft) = self.fft_in.try_recv() {
|
||||
if fft.len() != self.width {
|
||||
todo!();
|
||||
}
|
||||
gl.tex_sub_image_2d(
|
||||
glow::TEXTURE_2D,
|
||||
0,
|
||||
0,
|
||||
self.offset as i32,
|
||||
self.width as i32,
|
||||
1,
|
||||
glow::RED,
|
||||
glow::UNSIGNED_BYTE,
|
||||
PixelUnpackData::Slice(&fft),
|
||||
);
|
||||
check_for_gl_errors(&gl, "update texture");
|
||||
self.offset = (self.offset + 1) % self.width;
|
||||
}
|
||||
gl.tex_sub_image_2d(
|
||||
glow::TEXTURE_2D,
|
||||
0,
|
||||
0,
|
||||
self.offset as i32,
|
||||
300,
|
||||
1,
|
||||
glow::RED,
|
||||
glow::UNSIGNED_BYTE,
|
||||
PixelUnpackData::Slice(&new_data),
|
||||
);
|
||||
check_for_gl_errors(&gl, "update texture");
|
||||
self.offset = (self.offset + 1) % 300;
|
||||
|
||||
if let Some(uniform) = gl.get_uniform_location(self.program, "offset") {
|
||||
gl.uniform_1_f32(Some(&uniform), self.offset as f32 / self.width as f32);
|
||||
gl.uniform_1_f32(Some(&uniform), self.offset as f32 / 300.0);
|
||||
}
|
||||
check_for_gl_errors(&gl, "update uniform");
|
||||
|
||||
@ -98,7 +106,7 @@ impl Waterfall {
|
||||
check_for_gl_errors(&gl, "APP PAINT");
|
||||
}
|
||||
}
|
||||
pub fn new(gl: &glow::Context, width: usize, height: usize, fft_in: Receiver<Vec<u8>>) -> Self {
|
||||
pub fn new(gl: &glow::Context, width: usize, height: usize) -> Self {
|
||||
let vertices: [f32; 32] = [
|
||||
// positions // colors // texture coords
|
||||
1.0, 1.0, 0.0, /**/ 1.0, 0.0, 0.0, /**/ 1.0, 1.0, // top right
|
||||
@ -206,8 +214,6 @@ impl Waterfall {
|
||||
check_for_gl_errors(&gl, "Set LUT MIN_FILTER");
|
||||
gl.tex_parameter_i32(TEXTURE_2D, TEXTURE_MAG_FILTER, NEAREST as i32);
|
||||
check_for_gl_errors(&gl, "Set LUT MAG_FILTER");
|
||||
gl.tex_parameter_i32(TEXTURE_2D, TEXTURE_WRAP_S, CLAMP_TO_EDGE as i32);
|
||||
check_for_gl_errors(&gl, "Set LUT wrap mode");
|
||||
gl.tex_image_2d(
|
||||
TEXTURE_2D,
|
||||
0,
|
||||
@ -314,8 +320,6 @@ impl Waterfall {
|
||||
vbo,
|
||||
ebo,
|
||||
offset: 0_usize,
|
||||
width,
|
||||
fft_in,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user