Renderer

Struct Renderer 

Source
pub struct Renderer<F: Fn()> { /* private fields */ }
Expand description

§Renderer

The main renderer struct that manages the application lifecycle and rendering.

The Renderer is the core component of the Tessera UI framework, responsible for:

  • Managing the application window and WGPU context
  • Handling input events (mouse, touch, keyboard, IME)
  • Coordinating the component tree building and rendering process
  • Managing rendering pipelines and resources

§Type Parameters

  • F: The entry point function type that defines your UI. Must implement Fn().

§Lifecycle

The renderer follows this lifecycle:

  1. Initialization: Create window, initialize WGPU context, register pipelines
  2. Event Loop: Handle window events, input events, and render requests
  3. Frame Rendering: Build component tree → Compute draw commands → Render to surface
  4. Cleanup: Automatic cleanup when the application exits

§Thread Safety

The renderer runs on the main thread and coordinates with other threads for:

  • Component tree building (potentially parallelized)
  • Resource management
  • Event processing

§Usage

§Basic Usage

It’s suggested to use cargo-tessera to create your project from templates which include all necessary setup. However, here’s a minimal example of how to use the renderer through the Renderer::run method:

use tessera_ui::{PipelineContext, RenderModule, Renderer};

#[derive(Debug)]
struct DemoModule;

impl RenderModule for DemoModule {
    fn register_pipelines(&self, _context: &mut PipelineContext<'_>) {}
}

// Define your UI entry point
fn my_app() {
    // Your UI components go here
}

// Run the application
Renderer::run(my_app, vec![Box::new(DemoModule)]).unwrap();

§Android Usage

On android, Renderer::run requires an additional AndroidApp parameter from app context or android_main function.

§Configuration

You can customize the renderer behavior by passing TesseraConfig when using Renderer::run_with_config. instead of Renderer::run.

use tessera_ui::{PipelineContext, RenderModule, Renderer, renderer::TesseraConfig};

#[derive(Debug)]
struct DemoModule;

impl RenderModule for DemoModule {
    fn register_pipelines(&self, _context: &mut PipelineContext<'_>) {}
}

let config = TesseraConfig {
    sample_count: 8,                            // 8x MSAA
    window_title: "My Tessera App".to_string(), // Custom window title
    ..Default::default()
};

Renderer::run_with_config(|| { /* my_app */ }, vec![Box::new(DemoModule)], config)?;

§Performance Monitoring

The renderer includes built-in performance monitoring that logs frame statistics when performance drops below 60 FPS.

Implementations§

Source§

impl<F: Fn()> Renderer<F>

Source

pub fn run( entry_point: F, modules: Vec<Box<dyn RenderModule>>, ) -> Result<(), EventLoopError>

Runs the Tessera application with default configuration on desktop platforms.

This is the most convenient way to start a Tessera application on Windows, Linux, or macOS. It uses the default TesseraConfig settings (4x MSAA).

§Parameters
  • entry_point: A function that defines your UI. This function will be called every frame to build the component tree. It should contain your root UI components.
  • modules: Render modules that register pipelines.
§Returns

Returns Ok(()) when the application exits normally, or an EventLoopError if the event loop fails to start or encounters a critical error.

§Examples
use tessera_ui::{PipelineContext, RenderModule, Renderer};

#[derive(Debug)]
struct DemoModule;

impl RenderModule for DemoModule {
    fn register_pipelines(&self, _context: &mut PipelineContext<'_>) {}
}

fn my_ui() {
    // Your UI components go here
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    Renderer::run(my_ui, vec![Box::new(DemoModule)])?;
    Ok(())
}
Source

pub fn run_with_config( entry_point: F, modules: Vec<Box<dyn RenderModule>>, config: TesseraConfig, ) -> Result<(), EventLoopError>

Runs the Tessera application with custom configuration on desktop platforms.

This method allows you to customize the renderer behavior through TesseraConfig. Use this when you need to adjust settings like MSAA sample count or other rendering parameters.

§Parameters
  • entry_point: A function that defines your UI
  • modules: Render modules that register pipelines
  • config: Custom configuration for the renderer
§Returns

Returns Ok(()) when the application exits normally, or an EventLoopError if the event loop fails to start.

§Examples
use tessera_ui::{PipelineContext, RenderModule, Renderer, renderer::TesseraConfig};

#[derive(Debug)]
struct DemoModule;

impl RenderModule for DemoModule {
    fn register_pipelines(&self, _context: &mut PipelineContext<'_>) {}
}

let config = TesseraConfig {
    sample_count: 8, // 8x MSAA for higher quality
    ..Default::default()
};

Renderer::run_with_config(|| { /* my_ui */ }, vec![Box::new(DemoModule)], config)?;

Auto Trait Implementations§

§

impl<F> !Freeze for Renderer<F>

§

impl<F> !RefUnwindSafe for Renderer<F>

§

impl<F> !Send for Renderer<F>

§

impl<F> !Sync for Renderer<F>

§

impl<F> Unpin for Renderer<F>
where F: Unpin,

§

impl<F> !UnwindSafe for Renderer<F>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more