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

Compile time improvement: depend on subcrates #319

Merged
merged 5 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ jobs:
restore-keys: |
cache-doc-cargo-${{ hashFiles('**/Cargo.toml') }}
cache-doc-cargo
- run: cargo doc --all --features "bevy/x11"
- run: cargo doc --all --features "bevy_winit/x11"
env:
RUSTDOCFLAGS: -D warnings

Expand Down
69 changes: 47 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bevy_egui"
version = "0.30.0"
rust-version = "1.80.0" # needed for LazyLock https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html
version = "0.30.1"
rust-version = "1.80.0" # needed for LazyLock https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html
authors = ["mvlabat <[email protected]>"]
description = "A plugin for Egui integration into Bevy"
license = "MIT"
Expand All @@ -20,7 +20,14 @@ immutable_ctx = []
manage_clipboard = ["arboard", "thread_local"]
open_url = ["webbrowser"]
default_fonts = ["egui/default_fonts"]
render = ["bevy/bevy_render"]
render = [
"bevy_render",
"bevy_asset",
"encase",
"bytemuck",
"egui/bytemuck",
"wgpu-types",
]
serde = ["egui/serde"]
# The enabled logs will print with the info log level, to make it less cumbersome to debug in browsers.
log_input_events = []
Expand Down Expand Up @@ -51,15 +58,31 @@ name = "render_egui_to_texture"
required-features = ["render"]

[dependencies]
bevy = { version = "0.14.0", default-features = false, features = [
"bevy_asset",
"bevy_winit",
] }
egui = { version = "0.29", default-features = false, features = ["bytemuck"] }
bytemuck = "1"
egui = { version = "0.29", default-features = false }

bevy_app = "0.14"
bevy_derive = "0.14"
bevy_ecs = "0.14"
bevy_input = "0.14"
bevy_log = "0.14"
bevy_math = "0.14"
bevy_reflect = "0.14"
bevy_time = "0.14"
bevy_utils = "0.14"
bevy_winit = "0.14"
bevy_window = "0.14"

# `open_url` feature
webbrowser = { version = "1.0.1", optional = true }
wgpu-types = "0.20"

# `render` feature
bytemuck = { version = "1", optional = true }
bevy_asset = { version = "0.14", optional = true }
bevy_render = { version = "0.14", optional = true }
encase = { version = "0.8", optional = true }
wgpu-types = { version = "0.20", optional = true }

# `manage_clipboard` feature
[target.'cfg(not(any(target_arch = "wasm32", target_os = "android")))'.dependencies]
arboard = { version = "3.2.0", optional = true }
thread_local = { version = "1.1.0", optional = true }
Expand All @@ -71,6 +94,8 @@ bevy = { version = "0.14.0", default-features = false, features = [
"png",
"bevy_pbr",
"bevy_core_pipeline",
"bevy_asset",
"bevy_winit",
"tonemapping_luts",
"webgl2",
] }
Expand All @@ -79,18 +104,18 @@ egui = { version = "0.29", default-features = false, features = ["bytemuck"] }
[target.'cfg(target_arch = "wasm32")'.dependencies]
winit = "0.30"
web-sys = { version = "0.3.63", features = [
"Clipboard",
"ClipboardEvent",
"CompositionEvent",
"DataTransfer",
"Document",
"EventTarget",
"HtmlInputElement",
"InputEvent",
"KeyboardEvent",
"Navigator",
"TouchEvent",
"Window",
"Clipboard",
"ClipboardEvent",
"CompositionEvent",
"DataTransfer",
"Document",
"EventTarget",
"HtmlInputElement",
"InputEvent",
"KeyboardEvent",
"Navigator",
"TouchEvent",
"Window",
] }
js-sys = "0.3.63"
wasm-bindgen = "0.2.84"
Expand Down
70 changes: 33 additions & 37 deletions src/egui_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ use crate::{
},
EguiRenderOutput, EguiSettings, RenderTargetSize,
};
use bevy::{
ecs::world::{FromWorld, World},
prelude::{Entity, Handle, Resource},
render::{
render_asset::RenderAssetUsages,
render_graph::{Node, NodeRunError, RenderGraphContext},
render_phase::TrackedRenderPass,
render_resource::{
BindGroupLayout, BindGroupLayoutEntry, BindingType, BlendComponent, BlendFactor,
BlendOperation, BlendState, Buffer, BufferAddress, BufferBindingType, BufferDescriptor,
BufferUsages, ColorTargetState, ColorWrites, Extent3d, FragmentState, FrontFace,
IndexFormat, LoadOp, MultisampleState, Operations, PipelineCache, PrimitiveState,
RenderPassColorAttachment, RenderPassDescriptor, RenderPipelineDescriptor,
SamplerBindingType, Shader, ShaderStages, ShaderType, SpecializedRenderPipeline,
StoreOp, TextureDimension, TextureFormat, TextureSampleType, TextureViewDimension,
VertexBufferLayout, VertexFormat, VertexState, VertexStepMode,
},
renderer::{RenderContext, RenderDevice, RenderQueue},
texture::{
GpuImage, Image, ImageAddressMode, ImageFilterMode, ImageSampler,
ImageSamplerDescriptor,
},
view::{ExtractedWindow, ExtractedWindows},
use bevy_asset::prelude::*;
use bevy_ecs::{
prelude::*,
world::{FromWorld, World},
};
use bevy_render::{
render_asset::RenderAssetUsages,
render_graph::{Node, NodeRunError, RenderGraphContext},
render_phase::TrackedRenderPass,
render_resource::{
BindGroupLayout, BindGroupLayoutEntry, BindingType, BlendComponent, BlendFactor,
BlendOperation, BlendState, Buffer, BufferAddress, BufferBindingType, BufferDescriptor,
BufferUsages, ColorTargetState, ColorWrites, Extent3d, FragmentState, FrontFace,
IndexFormat, LoadOp, MultisampleState, Operations, PipelineCache, PrimitiveState,
RenderPassColorAttachment, RenderPassDescriptor, RenderPipelineDescriptor,
SamplerBindingType, Shader, ShaderStages, ShaderType, SpecializedRenderPipeline, StoreOp,
TextureDimension, TextureFormat, TextureSampleType, TextureViewDimension,
VertexBufferLayout, VertexFormat, VertexState, VertexStepMode,
},
renderer::{RenderContext, RenderDevice, RenderQueue},
texture::{
GpuImage, Image, ImageAddressMode, ImageFilterMode, ImageSampler, ImageSamplerDescriptor,
},
view::{ExtractedWindow, ExtractedWindows},
};
use bytemuck::cast_slice;
use egui::{TextureFilter, TextureOptions};
Expand Down Expand Up @@ -262,19 +262,19 @@ impl Node for EguiNode {
primitive,
} in paint_jobs
{
let clip_urect = bevy::math::URect {
min: bevy::math::UVec2 {
let clip_urect = bevy_math::URect {
min: bevy_math::UVec2 {
x: (clip_rect.min.x * self.pixels_per_point).round() as u32,
y: (clip_rect.min.y * self.pixels_per_point).round() as u32,
},
max: bevy::math::UVec2 {
max: bevy_math::UVec2 {
x: (clip_rect.max.x * self.pixels_per_point).round() as u32,
y: (clip_rect.max.y * self.pixels_per_point).round() as u32,
},
};

if clip_urect
.intersect(bevy::math::URect::new(
.intersect(bevy_math::URect::new(
0,
0,
window_size.physical_width as u32,
Expand Down Expand Up @@ -498,23 +498,19 @@ impl Node for EguiNode {
requires_reset = false;
}

let clip_urect = bevy::math::URect {
min: bevy::math::UVec2 {
let clip_urect = bevy_math::URect {
min: bevy_math::UVec2 {
x: (draw_command.clip_rect.min.x * self.pixels_per_point).round() as u32,
y: (draw_command.clip_rect.min.y * self.pixels_per_point).round() as u32,
},
max: bevy::math::UVec2 {
max: bevy_math::UVec2 {
x: (draw_command.clip_rect.max.x * self.pixels_per_point).round() as u32,
y: (draw_command.clip_rect.max.y * self.pixels_per_point).round() as u32,
},
};

let scrissor_rect = clip_urect.intersect(bevy::math::URect::new(
0,
0,
physical_width,
physical_height,
));
let scrissor_rect =
clip_urect.intersect(bevy_math::URect::new(0, 0, physical_width, physical_height));
if scrissor_rect.is_empty() {
continue;
}
Expand Down Expand Up @@ -660,7 +656,7 @@ pub(crate) fn texture_options_as_sampler_descriptor(
///
/// Rendering can be implemented using for example:
/// * native wgpu rendering libraries,
/// * or with [`bevy::render::render_phase`] approach.
/// * or with [`bevy_render::render_phase`] approach.
pub struct EguiBevyPaintCallback(Box<dyn EguiBevyPaintCallbackImpl>);

impl EguiBevyPaintCallback {
Expand Down
44 changes: 21 additions & 23 deletions src/egui_render_to_texture_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@ use crate::{
render_systems::{EguiPipelines, EguiTextureBindGroups, EguiTextureId, EguiTransforms},
EguiRenderOutput, EguiRenderToTextureHandle, EguiSettings, RenderTargetSize,
};
use bevy::{
ecs::world::World,
prelude::Entity,
render::{
render_asset::RenderAssets,
render_graph::{Node, NodeRunError, RenderGraphContext, RenderLabel},
render_phase::TrackedRenderPass,
render_resource::{
Buffer, BufferAddress, BufferDescriptor, BufferUsages, IndexFormat, LoadOp, Operations,
PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, StoreOp,
},
renderer::{RenderContext, RenderDevice, RenderQueue},
texture::GpuImage,
use bevy_ecs::{prelude::*, world::World};
use bevy_render::{
render_asset::RenderAssets,
render_graph::{Node, NodeRunError, RenderGraphContext, RenderLabel},
render_phase::TrackedRenderPass,
render_resource::{
Buffer, BufferAddress, BufferDescriptor, BufferUsages, IndexFormat, LoadOp, Operations,
PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, StoreOp,
},
renderer::{RenderContext, RenderDevice, RenderQueue},
texture::GpuImage,
};

use bytemuck::cast_slice;

/// [`RenderLabel`] type for the Egui Render to Texture pass.
Expand Down Expand Up @@ -108,19 +106,19 @@ impl Node for EguiRenderToTextureNode {
primitive,
} in paint_jobs
{
let clip_urect = bevy::math::URect {
min: bevy::math::UVec2 {
let clip_urect = bevy_math::URect {
min: bevy_math::UVec2 {
x: (clip_rect.min.x * self.pixels_per_point).round() as u32,
y: (clip_rect.min.y * self.pixels_per_point).round() as u32,
},
max: bevy::math::UVec2 {
max: bevy_math::UVec2 {
x: (clip_rect.max.x * self.pixels_per_point).round() as u32,
y: (clip_rect.max.y * self.pixels_per_point).round() as u32,
},
};

if clip_urect
.intersect(bevy::math::URect::new(
.intersect(bevy_math::URect::new(
0,
0,
render_target_size.physical_width as u32,
Expand Down Expand Up @@ -307,7 +305,7 @@ impl Node for EguiRenderToTextureNode {
let mut render_pass = TrackedRenderPass::new(device, render_pass);

let Some(pipeline_id) = egui_pipelines.get(&self.render_to_texture_target) else {
bevy::log::error!("no egui_pipeline");
bevy_log::error!("no egui_pipeline");
return Ok(());
};
let Some(pipeline) = pipeline_cache.get_render_pipeline(*pipeline_id) else {
Expand Down Expand Up @@ -341,18 +339,18 @@ impl Node for EguiRenderToTextureNode {
requires_reset = false;
}

let clip_urect = bevy::math::URect {
min: bevy::math::UVec2 {
let clip_urect = bevy_math::URect {
min: bevy_math::UVec2 {
x: (draw_command.clip_rect.min.x * self.pixels_per_point).round() as u32,
y: (draw_command.clip_rect.min.y * self.pixels_per_point).round() as u32,
},
max: bevy::math::UVec2 {
max: bevy_math::UVec2 {
x: (draw_command.clip_rect.max.x * self.pixels_per_point).round() as u32,
y: (draw_command.clip_rect.max.y * self.pixels_per_point).round() as u32,
},
};
let scrissor_rect = clip_urect.intersect(bevy::math::URect::from_corners(
bevy::math::UVec2::ZERO,
let scrissor_rect = clip_urect.intersect(bevy_math::URect::from_corners(
bevy_math::UVec2::ZERO,
gpu_image.size,
));
if scrissor_rect.is_empty() {
Expand Down
Loading
Loading