Giter Club home page Giter Club logo

egui-ash's Introduction

egui-ash

Latest version Documentation MIT Apache2.0 egui: 0.24.1 ash: 0.37.3

egui integration for ash (Vulkan).

This crate natively supports the multi-viewports feature added since version 0.24 of egui.

You can use gpu_allocator as the default allocator by the gpu-allocator feature. You can also use your own allocator by implementing the Allocator trait.

Example

simple

simple

cargo run --release --example egui_ash_simple

vulkan

vulkan

cargo run --release --example egui_ash_vulkan

images

images

cargo run --release --example images

multi viewports

multi viewports

cargo run --release --example multi_viewports

native images

native image

cargo run --release --example native_image

scene view

scene view

cargo run --release --example scene_view

tiles

tiles

cargo run --release --example tiles

Usage

// (1) Create a App struct that implements the `egui_ash::App` trait.
struct MyApp;
impl egui_ash::App for MyApp {
    fn ui(
        &mut self,
        ctx: &egui::CtxRef,
        integration_context: &mut egui_ash::IntegrationContext,
    ) {
        // (2) draw ui here
        egui::Window::new("Hello world").show(ctx, |ui| {
            ui.label("Hello world!");
        });
    }

    fn request_redraw(&mut self, _viewport_id: egui::ViewportId) -> HandleRedraw {
      // (3) return `HandleRedraw::Auto` if you want to draw only egui.
      HandleRedraw::Auto
      // (4) ...or return `HandleRedraw::Handle` if you want to draw with ash.
      // NOTE: You must call `egui_cmd.update_swapchain` inside render function
      // when you first render and when you recreate the swapchain.
      HandleRedraw::Handle(Box::new(|size, egui_cmd| render(size, egui_cmd)))
    }
}

// (5) Create a AppCreator struct that implements the `egui_ash::AppCreator` trait.
struct MyAppCreator;
impl egui_ash::AppCreator for MyAppCreator {
    type App = MyApp;

    // (6) new method receives `egui_ash::CreationContext` and
    // returns `Self::App` and `egui_ash::AshRenderState`.
    fn new(&self, cc: CreationContext) -> (Self::App, AshRenderState<Arc<Mutex<Allocator>>>) {
        // create vk objects
        let entry = create_entry();
        let (instance, debug_utils_loader, debug_messenger) =
            create_instance(&cc.required_instance_extensions, &entry);
        let surface_loader = create_surface_loader(&entry, &instance);
        let surface = create_surface(&entry, &instance, cc.main_window);
        let (physical_device, _physical_device_memory_properties, queue_family_index) =
            create_physical_device(
                &instance,
                &surface_loader,
                surface,
                &cc.required_device_extensions,
            );
        let (device, queue) = create_device(
            &instance,
            physical_device,
            queue_family_index,
            &cc.required_device_extensions,
        );
        let swapchain_loader = create_swapchain_loader(&instance, &device);
        let command_pool = create_command_pool(&device, queue_family_index);

        // create allocator
        let allocator = {
            Allocator::new(&AllocatorCreateDesc {
                instance: instance.clone(),
                device: device.clone(),
                physical_device,
                debug_settings: Default::default(),
                buffer_device_address: false,
                allocation_sizes: Default::default(),
            })
            .expect("Failed to create allocator")
        };
        let allocator = Arc::new(Mutex::new(allocator));

        let ash_render_state = AshRenderState {
            entry,
            instance,
            physical_device,
            device,
            surface_loader,
            swapchain_loader,
            queue,
            queue_family_index,
            command_pool,
            allocator,
        };

        (Self, ash_render_state)
    }
}

// (7) Call `egui_ash::run` with `AppCreator` struct.
fn main() {
    egui_ash::run(
        MyAppCreator,
        RunOption {
            viewport_builder: Some(egui::ViewportBuilder::default().with_title("egui-ash")),
            ..Default::default()
        },
    )
}

Full example is in examples directory

Feature flags

gpu-allocator - Enables the gpu-allocator crate.

This feature allows Arc<Mutex<gpu_allocator::vulkan::Allocator>> to be used as an allocator to be used by egui-ash.

persistence - Enables the persistence feature of egui.

With this feature, setting persistent_windows and persistent_egui_memory in RunOption to true will preserve Window size and position, as well as scale factor, etc.

other features

The other features directly control the underlying egui_winit features

License

MIT OR Apache-2.0

egui-ash's People

Contributors

matchachoco010 avatar

Stargazers

PaprikaZ avatar  avatar mochou avatar Raphaël Thériault avatar A. B. Sørensen avatar Khoa Hoang avatar George avatar Roman Nazarov avatar rsp4jack avatar  avatar  avatar Alexandre avatar Danny Le avatar FTE avatar Gil Balsiger avatar Stephen avatar Deepak Rajan avatar Florian avatar toyboot4e avatar  avatar neguse avatar

Watchers

 avatar

egui-ash's Issues

How to exit the application within code

Hello! Thanks a lot for this, I was just struggling with exactly the problem of adding an UI to a game I am making in my spare time with Ash.

However, I can't seem to figure out how to exit the application within the code. For example, when the user presses the Escape key.

From what I've managed to tell from the current documentation and general state of the crate, this currently seems impossible.

Example do not work, out of the box

First of all, thanks for doing this, egui with vulkan could be a nice thing.

Just tried if it work out of the box, but something wrong
image

any idea?

Examples are not Windows HiDPI aware

I'm running 150% HiDPI scaling on my Windows 10 machine and I'm getting a big black border around the UI that is fixed by setting my HiDPI to 100%. Would be nice if the library covered it automatically, otherwise documentation around how to support it might be enough.

image

How does persistence work?

There seem to be no legal way to get storage::Storage to access (get/set)_value outside of the crate. I'd greatly appreciate some pointers in the right direction because docs didn't help a single bit.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.