examples: Separate common windowing logic from glupload

This allows to implement more GL-based examples reusing the same
pipeline and rendering logic.
This commit is contained in:
Marijn Suijten 2021-04-16 11:17:29 +02:00 committed by Sebastian Dröge
parent bf1941beee
commit 430d89539e
3 changed files with 20 additions and 17 deletions

View file

@ -158,7 +158,7 @@ name = "ges"
required-features = ["ges"]
[[bin]]
name = "glupload"
name = "glwindow"
required-features = ["gl"]
[[bin]]

View file

@ -0,0 +1,16 @@
#[path = "../glupload.rs"]
mod glupload;
use glupload::*;
#[path = "../examples-common.rs"]
pub mod examples_common;
fn example_main() {
App::new()
.and_then(main_loop)
.unwrap_or_else(|e| eprintln!("Error! {}", e))
}
fn main() {
examples_common::run(example_main);
}

View file

@ -17,9 +17,6 @@ use std::sync;
use anyhow::Error;
use derive_more::{Display, Error};
#[path = "../examples-common.rs"]
mod examples_common;
#[derive(Debug, Display, Error)]
#[display(fmt = "Missing element {}", _0)]
struct MissingElement(#[error(not(source))] &'static str);
@ -319,7 +316,7 @@ enum Message {
BusEvent,
}
struct App {
pub(crate) struct App {
pipeline: gst::Pipeline,
appsink: gst_app::AppSink,
glupload: gst::Element,
@ -330,7 +327,7 @@ struct App {
}
impl App {
fn new() -> Result<App, Error> {
pub(crate) fn new() -> Result<App, Error> {
gst::init()?;
let (pipeline, appsink, glupload) = App::create_pipeline()?;
@ -605,7 +602,7 @@ impl App {
}
}
fn main_loop(app: App) -> Result<(), Error> {
pub(crate) fn main_loop(app: App) -> Result<(), Error> {
app.setup(&app.event_loop)?;
println!(
@ -700,13 +697,3 @@ fn main_loop(app: App) -> Result<(), Error> {
}
})
}
fn example_main() {
App::new()
.and_then(main_loop)
.unwrap_or_else(|e| eprintln!("Error! {}", e))
}
fn main() {
examples_common::run(example_main);
}