Skip to content

Commit

Permalink
Fixes for bevy main.
Browse files Browse the repository at this point in the history
  • Loading branch information
exjam committed Jun 5, 2022
1 parent bc06e2e commit 173f2df
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
8 changes: 3 additions & 5 deletions src/egui_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use bevy::{
render::{
render_graph::{Node, NodeRunError, RenderGraphContext},
render_resource::{
std140::AsStd140, BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry,
BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry,
BindingType, BlendComponent, BlendFactor, BlendOperation, BlendState, Buffer,
BufferAddress, BufferBindingType, BufferDescriptor, BufferSize, BufferUsages,
BufferAddress, BufferBindingType, BufferDescriptor, encase::ShaderType, BufferUsages,
ColorTargetState, ColorWrites, Extent3d, FrontFace, IndexFormat, LoadOp,
MultisampleState, Operations, PipelineLayoutDescriptor, PrimitiveState,
RawFragmentState, RawRenderPipelineDescriptor, RawVertexBufferLayout, RawVertexState,
Expand Down Expand Up @@ -52,9 +52,7 @@ impl FromWorld for EguiPipeline {
ty: BindingType::Buffer {
ty: BufferBindingType::Uniform,
has_dynamic_offset: true,
min_binding_size: Some(
BufferSize::new(EguiTransform::std140_size_static() as u64).unwrap(),
),
min_binding_size: Some(EguiTransform::min_size()),
},
count: None,
}],
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,9 @@ impl Plugin for EguiPlugin {
.add_system_to_stage(RenderStage::Queue, render_systems::queue_bind_groups);

let mut render_graph = render_app.world.get_resource_mut::<RenderGraph>().unwrap();
setup_pipeline(&mut *render_graph, RenderGraphConfig::default());
if let Some(graph_3d) = render_graph.get_sub_graph_mut(bevy::core_pipeline::core_3d::graph::NAME) {
setup_pipeline(&mut *graph_3d, RenderGraphConfig::default());
}
}
}
}
Expand Down Expand Up @@ -604,7 +606,7 @@ pub fn setup_pipeline(render_graph: &mut RenderGraph, config: RenderGraphConfig)

render_graph
.add_node_edge(
bevy::core_pipeline::node::MAIN_PASS_DRIVER,
bevy::core_pipeline::core_3d::graph::node::MAIN_PASS,
config.egui_pass,
)
.unwrap();
Expand Down
10 changes: 5 additions & 5 deletions src/render_systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use bevy::{
render::{
render_asset::RenderAssets,
render_resource::{
std140::AsStd140, BindGroup, BindGroupDescriptor, BindGroupEntry, BindingResource,
BufferId, DynamicUniformVec,
BindGroup, BindGroupDescriptor, BindGroupEntry, BindingResource,
BufferId, DynamicUniformBuffer, encase::{ShaderType},
},
renderer::{RenderDevice, RenderQueue},
texture::Image,
Expand Down Expand Up @@ -84,12 +84,12 @@ pub(crate) fn extract_egui_textures(

#[derive(Default)]
pub(crate) struct EguiTransforms {
pub buffer: DynamicUniformVec<EguiTransform>,
pub buffer: DynamicUniformBuffer<EguiTransform>,
pub offsets: HashMap<WindowId, u32>,
pub bind_group: Option<(BufferId, BindGroup)>,
}

#[derive(AsStd140)]
#[derive(ShaderType)]
pub(crate) struct EguiTransform {
scale: Vec2,
translation: Vec2,
Expand Down Expand Up @@ -130,7 +130,7 @@ pub(crate) fn prepare_egui_transforms(
.buffer
.write_buffer(&render_device, &render_queue);

if let Some(buffer) = egui_transforms.buffer.uniform_buffer() {
if let Some(buffer) = egui_transforms.buffer.buffer() {
match egui_transforms.bind_group {
Some((id, _)) if buffer.id() == id => {}
_ => {
Expand Down
15 changes: 7 additions & 8 deletions src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ use crate::{EguiContext, EguiInput, EguiOutput, EguiRenderOutput, EguiSettings,
#[cfg(feature = "open_url")]
use bevy::log;
use bevy::{
core::Time,
ecs::{
event::EventWriter,
system::{Local, Res, ResMut, SystemParam},
},
input::{
keyboard::{KeyCode, KeyboardInput},
mouse::{MouseButton, MouseButtonInput, MouseScrollUnit, MouseWheel},
ElementState, Input,
ButtonState, Input,
},
prelude::EventReader,
prelude::{EventReader, Time},
utils::HashMap,
window::{
CursorEntered, CursorLeft, CursorMoved, ReceivedCharacter, RequestRedraw, WindowCreated,
Expand Down Expand Up @@ -172,8 +171,8 @@ pub fn process_input(
_ => None,
};
let pressed = match mouse_button_event.state {
ElementState::Pressed => true,
ElementState::Released => false,
ButtonState::Pressed => true,
ButtonState::Released => false,
};
if let Some(button) = button {
events.push(egui::Event::PointerButton {
Expand Down Expand Up @@ -233,8 +232,8 @@ pub fn process_input(
for ev in input_events.ev_keyboard_input.iter() {
if let Some(key) = ev.key_code.and_then(bevy_to_egui_key) {
let pressed = match ev.state {
ElementState::Pressed => true,
ElementState::Released => false,
ButtonState::Pressed => true,
ButtonState::Released => false,
};
let egui_event = egui::Event::Key {
key,
Expand All @@ -243,7 +242,7 @@ pub fn process_input(
};
focused_input.raw_input.events.push(egui_event);

// We also check that it's an `ElementState::Pressed` event, as we don't want to
// We also check that it's an `ButtonState::Pressed` event, as we don't want to
// copy, cut or paste on the key release.
#[cfg(feature = "manage_clipboard")]
if command && pressed {
Expand Down

0 comments on commit 173f2df

Please sign in to comment.