Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Update the dependencies to target the latest baseview and egui versions #4

Closed
wants to merge 10 commits into from
18 changes: 7 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@ readme = "README.md"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["opengl"]
opengl = ["raw-gl-context", "gl"]

[dependencies]
egui = "0.15"
raw-gl-context = { version = "0.1", optional = true }
gl = { version = "0.14", optional = true }
keyboard-types = { version = "0.5", default-features = false }
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "f6e99e9aa6f5aeb6b721cb05e4d882a51d995909" }
raw-window-handle = "0.3"
copypasta = "0.7.1"
egui = "0.17"
gl = { version = "0.14" }
keyboard-types = { version = "0.6.1", default-features = false }
# TODO: Move this back to RustAudio/baseview once the PR gets merged
baseview = { git = "https://github.com/robbert-vdh/baseview.git", branch = "feature/mouse-event-modifiers", features = ["opengl"] }
raw-window-handle = "0.4"
copypasta = "0.7.1"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A [`baseview`] backend for [`egui`].

```rust
use baseview::{Size, WindowOpenOptions, WindowScalePolicy};
use egui::CtxRef;
use egui::Context;
use egui_baseview::{EguiWindow, Queue, RenderSettings, Settings};

fn main() {
Expand All @@ -33,10 +33,10 @@ fn main() {
state,
// Called once before the first frame. Allows you to do setup code and to
// call `ctx.set_fonts()`. Optional.
|_egui_ctx: &CtxRef, _queue: &mut Queue, _state: &mut State| {},
|_egui_ctx: &Context, _queue: &mut Queue, _state: &mut State| {},
// Called before each frame. Here you should update the state of your
// application and build the UI.
|egui_ctx: &CtxRef, _queue: &mut Queue, state: &mut State| {
|egui_ctx: &Context, _queue: &mut Queue, state: &mut State| {
egui::Window::new("egui-baseview simple demo").show(&egui_ctx, |ui| {
ui.heading("My Egui Application");
ui.horizontal(|ui| {
Expand Down
20 changes: 9 additions & 11 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
use baseview::{Size, WindowOpenOptions, WindowScalePolicy};
use egui::CtxRef;
use egui_baseview::{EguiWindow, Queue, RenderSettings, Settings};
use egui::Context;
use egui_baseview::{EguiWindow, Queue};

fn main() {
let settings = Settings {
window: WindowOpenOptions {
title: String::from("egui-baseview hello world"),
size: Size::new(300.0, 110.0),
scale: WindowScalePolicy::SystemScaleFactor,
},
render_settings: RenderSettings::default(),
let settings = WindowOpenOptions {
title: String::from("egui-baseview hello world"),
size: Size::new(300.0, 110.0),
scale: WindowScalePolicy::SystemScaleFactor,
gl_config: Some(baseview::gl::GlConfig::default()),
};

let state = ();

EguiWindow::open_blocking(
settings,
state,
|_egui_ctx: &CtxRef, _queue: &mut Queue, _state: &mut ()| {},
|egui_ctx: &CtxRef, _queue: &mut Queue, _state: &mut ()| {
|_egui_ctx: &Context, _queue: &mut Queue, _state: &mut ()| {},
|egui_ctx: &Context, _queue: &mut Queue, _state: &mut ()| {
egui::Window::new("egui-baseview hello world").show(&egui_ctx, |ui| {
ui.label("Hello World!");
});
Expand Down
20 changes: 9 additions & 11 deletions examples/simple_demo.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use baseview::{Size, WindowOpenOptions, WindowScalePolicy};
use egui::CtxRef;
use egui_baseview::{EguiWindow, Queue, RenderSettings, Settings};
use egui::Context;
use egui_baseview::{EguiWindow, Queue};

fn main() {
let settings = Settings {
window: WindowOpenOptions {
title: String::from("egui-baseview simple demo"),
size: Size::new(400.0, 200.0),
scale: WindowScalePolicy::SystemScaleFactor,
},
render_settings: RenderSettings::default(),
let settings = WindowOpenOptions {
title: String::from("egui-baseview simple demo"),
size: Size::new(400.0, 200.0),
scale: WindowScalePolicy::SystemScaleFactor,
gl_config: Some(baseview::gl::GlConfig::default()),
};

let state = State::new();
Expand All @@ -19,10 +17,10 @@ fn main() {
state,
// Called once before the first frame. Allows you to do setup code and to
// call `ctx.set_fonts()`. Optional.
|_egui_ctx: &CtxRef, _queue: &mut Queue, _state: &mut State| {},
|_egui_ctx: &Context, _queue: &mut Queue, _state: &mut State| {},
// Called before each frame. Here you should update the state of your
// application and build the UI.
|egui_ctx: &CtxRef, queue: &mut Queue, state: &mut State| {
|egui_ctx: &Context, queue: &mut Queue, state: &mut State| {
egui::Window::new("egui-baseview simple demo").show(&egui_ctx, |ui| {
ui.heading("My Egui Application");
ui.horizontal(|ui| {
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mod renderer;
mod settings;
mod window;

pub use renderer::RenderSettings;
pub use settings::Settings;
pub use window::{EguiWindow, Queue};
3 changes: 0 additions & 3 deletions src/renderer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[cfg(feature = "opengl")]
mod opengl_renderer;
#[cfg(feature = "opengl")]
pub use opengl_renderer::RenderSettings;
#[cfg(feature = "opengl")]
pub(crate) use opengl_renderer::Renderer;
28 changes: 15 additions & 13 deletions src/renderer/opengl_renderer.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
use baseview::gl::GlContext;
use baseview::Window;
use egui::{Color32, Rgba};
use raw_gl_context::GlContext;

pub use raw_gl_context::GlConfig as RenderSettings;
pub use baseview::gl::GlConfig as RenderSettings;

mod painter;
use painter::Painter;

pub struct Renderer {
context: GlContext,
painter: Painter,
}

// TODO: This API is mostly unchanged from when the renderer owned the context. Now it's owned by
// the window.
impl Renderer {
pub fn new(window: &Window, render_settings: RenderSettings, canvas_size: (u32, u32)) -> Self {
let context = GlContext::create(window, render_settings).unwrap();
pub fn new(window: &Window, canvas_size: (u32, u32)) -> Option<Self> {
let context = window.gl_context()?;

context.make_current();
unsafe { context.make_current() };

gl::load_with(|s| context.get_proc_address(s) as _);

let painter = Painter::new(canvas_size.0, canvas_size.1);

context.make_not_current();
unsafe { context.make_not_current() };

Self { context, painter }
Some(Self { painter })
}

pub fn render(
&mut self,
context: &GlContext,
bg_color: Rgba,
clipped_meshes: Vec<egui::ClippedMesh>,
egui_texture: &egui::Texture,
texture_delta: &egui::TexturesDelta,
pixels_per_point: f32,
) {
self.context.make_current();
unsafe { context.make_current() };

self.painter
.paint_meshes(bg_color, clipped_meshes, egui_texture, pixels_per_point);
.paint_meshes(bg_color, clipped_meshes, texture_delta, pixels_per_point);

self.context.swap_buffers();
self.context.make_not_current();
context.swap_buffers();
unsafe { context.make_not_current() };
}

pub fn new_user_texture(
Expand Down
Loading