Skip to content

Commit

Permalink
Cargo fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
tychedelia committed Jan 31, 2024
1 parent a37611e commit ec988b9
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 76 deletions.
11 changes: 5 additions & 6 deletions bevy_nannou/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use bevy::prelude::*;
use bevy::prelude::shape::Cube;
use bevy::prelude::*;

use bevy_nannou_render::mesh::ViewMesh;

pub struct NannouPlugin;

impl Plugin for NannouPlugin {
fn build(&self, app: &mut App) {
app
.add_plugins((
bevy_nannou_render::NannouRenderPlugin,
bevy_nannou_draw::NannouDrawPlugin,
));
app.add_plugins((
bevy_nannou_render::NannouRenderPlugin,
bevy_nannou_draw::NannouDrawPlugin,
));
}
}

Expand Down
2 changes: 1 addition & 1 deletion bevy_nannou/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ pub fn main() {
let mut app = bevy::app::App::new();
app.add_plugins((bevy::DefaultPlugins, NannouPlugin));
app.run();
}
}
5 changes: 3 additions & 2 deletions bevy_nannou_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use bevy::prelude::*;
use bevy::render::extract_component::ExtractComponentPlugin;
use bevy::render::render_asset::RenderAsset;
use bevy::render::render_graph::{RenderGraphApp, ViewNode, ViewNodeRunner};
use bevy::render::render_resource::{CachedRenderPipelineId, ShaderType, SpecializedRenderPipeline, SpecializedRenderPipelines};
use bevy::render::render_resource::{
CachedRenderPipelineId, ShaderType, SpecializedRenderPipeline, SpecializedRenderPipelines,
};
use bevy::render::renderer::RenderDevice;
use bevy::render::view::ViewUniforms;
use bevy::render::{render_resource as wgpu, RenderSet};
Expand Down Expand Up @@ -45,7 +47,6 @@ impl Plugin for NannouRenderPlugin {
Render,
prepare_view_uniform.in_set(RenderSet::PrepareBindGroups),
)

// Register the NannouViewNode with the render graph
// The node runs at the last stage of the main 3d pass
.add_render_graph_node::<ViewNodeRunner<NannouViewNode>>(
Expand Down
2 changes: 1 addition & 1 deletion bevy_nannou_render/src/mesh/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use lyon::tessellation::geometry_builder::{
};
use lyon::tessellation::{FillVertex, GeometryBuilderError, StrokeVertex, VertexId};

use nannou_mesh::{Indices, Points, PushIndex, PushVertex};
use bevy::prelude::*;
use nannou_mesh::{Indices, Points, PushIndex, PushVertex};

pub struct MeshBuilder<'a, A> {
/// The mesh that is to be extended.
Expand Down
6 changes: 3 additions & 3 deletions bevy_nannou_render/src/mesh/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Items related to the custom mesh type used by the `Draw` API.

use crate::mesh::vertex::Point;
use crate::RenderCommand;
use bevy::prelude::*;
use bevy::render::extract_component::ExtractComponent;
use nannou_mesh as mesh;
use nannou_mesh::{self, MeshPoints, WithColors, WithIndices, WithTexCoords};
use std::ops::{Deref, DerefMut};
use bevy::render::extract_component::ExtractComponent;
use crate::mesh::vertex::Point;
use crate::RenderCommand;

pub mod builder;
pub mod vertex;
Expand Down
2 changes: 1 addition & 1 deletion bevy_nannou_render/src/mesh/vertex.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use nannou_mesh::vertex::{WithColor, WithTexCoords};
use bevy::prelude::*;
use nannou_mesh::vertex::{WithColor, WithTexCoords};

pub type Point = Vec3;
pub type Color = Vec4;
Expand Down
43 changes: 28 additions & 15 deletions bevy_nannou_render/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ use bevy::render::render_resource::{
SpecializedRenderPipeline, SpecializedRenderPipelines,
};
use bevy::render::renderer::{RenderContext, RenderDevice};
use bevy::render::view::{ExtractedWindows, ViewDepthTexture, ViewTarget, ViewUniform, ViewUniformOffset};
use bevy::render::view::{
ExtractedWindows, ViewDepthTexture, ViewTarget, ViewUniform, ViewUniformOffset,
};
use bevy::utils;

use crate::mesh::vertex::Point;
use crate::mesh::{TexCoords, ViewMesh};
use crate::{GlyphCache, mesh, NANNOU_SHADER_HANDLE, RenderCommand, Scissor, VertexMode, ViewRenderCommands, ViewUniformBindGroup};
use crate::{
mesh, GlyphCache, RenderCommand, Scissor, VertexMode, ViewRenderCommands, ViewUniformBindGroup,
NANNOU_SHADER_HANDLE,
};

#[derive(Resource)]
pub struct NannouPipeline {
Expand Down Expand Up @@ -176,7 +181,10 @@ impl NannouPipeline {
unsafe { std::mem::transmute(id) }
}

fn create_text_bind_group_layout(device: &RenderDevice, filtering: bool) -> wgpu::BindGroupLayout {
fn create_text_bind_group_layout(
device: &RenderDevice,
filtering: bool,
) -> wgpu::BindGroupLayout {
bevy_nannou_wgpu::BindGroupLayoutBuilder::new()
.sampler(wgpu::ShaderStages::FRAGMENT, filtering)
.texture(
Expand Down Expand Up @@ -229,7 +237,8 @@ impl FromWorld for NannouPipeline {
.build(device);

// Bind group for text.
let text_bind_group_layout = Self::create_text_bind_group_layout(device, text_sampler_filtering);
let text_bind_group_layout =
Self::create_text_bind_group_layout(device, text_sampler_filtering);
let text_bind_group = Self::create_text_bind_group(
device,
&text_bind_group_layout,
Expand Down Expand Up @@ -324,18 +333,20 @@ impl ViewNode for NannouViewNode {
&self,
_graph: &mut RenderGraphContext,
render_context: &mut RenderContext,
(entity, target, uniform_offset, mesh, render_commands, depth_texture): QueryItem<Self::ViewQuery>,
(entity, target, uniform_offset, mesh, render_commands, depth_texture): QueryItem<
Self::ViewQuery,
>,
world: &World,
) -> Result<(), NodeRunError> {
let nannou_pipeline = world.resource::<NannouPipeline>();
let pipeline_cache = world.resource::<PipelineCache>();
let bind_group_cache = world.resource::<TextureBindGroupCache>();

// Create render pass builder.
let render_pass_builder = bevy_nannou_wgpu::RenderPassBuilder::new()
.color_attachment(target.main_texture_view(), |color|
color.load_op(wgpu::LoadOp::Load) // TODO: bg color
);
let render_pass_builder = bevy_nannou_wgpu::RenderPassBuilder::new().color_attachment(
target.main_texture_view(),
|color| color.load_op(wgpu::LoadOp::Load), // TODO: bg color
);

let render_device = render_context.render_device();

Expand Down Expand Up @@ -389,7 +400,9 @@ impl ViewNode for NannouViewNode {
for cmd in render_commands.commands.clone() {
match cmd {
RenderCommand::SetPipeline(id) => {
let pipeline = pipeline_cache.get_render_pipeline(id).expect("Expected pipeline to exist");
let pipeline = pipeline_cache
.get_render_pipeline(id)
.expect("Expected pipeline to exist");
render_pass.set_render_pipeline(pipeline);
}

Expand All @@ -401,11 +414,11 @@ impl ViewNode for NannouViewNode {
render_pass.set_bind_group(2, bind_group, &[]);
}
RenderCommand::SetScissor(Scissor {
left,
bottom,
width,
height,
}) => {
left,
bottom,
width,
height,
}) => {
render_pass.set_scissor_rect(left, bottom, width, height);
}
RenderCommand::DrawIndexed {
Expand Down
2 changes: 1 addition & 1 deletion bevy_nannou_render/src/text/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Logic related to the positioning of the cursor within text.

use nannou_core::geom::{Range, Rect};
use crate::text::{self, FontSize, Point, Scalar};
use nannou_core::geom::{Range, Rect};

/// An index representing the position of a cursor within some text.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
Expand Down
2 changes: 1 addition & 1 deletion bevy_nannou_render/src/text/glyph.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Logic and types specific to individual glyph layout.

use nannou_core::geom::{Range, Rect};
use crate::text::{self, FontSize, Scalar, ScaledGlyph};
use nannou_core::geom::{Range, Rect};

/// Some position along the X axis (used within `CharXs`).
pub type X = Scalar;
Expand Down
2 changes: 1 addition & 1 deletion bevy_nannou_render/src/text/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//!
//! This module is the core of multi-line text handling.

use nannou_core::geom::{Range, Rect};
use crate::text::{self, FontSize, Scalar, Wrap};
use nannou_core::geom::{Range, Rect};

/// The two types of **Break** indices returned by the **WrapIndicesBy** iterators.
#[derive(Copy, Clone, Debug, PartialEq)]
Expand Down
46 changes: 23 additions & 23 deletions bevy_nannou_render/src/text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,29 +258,29 @@ impl<'a> Builder<'a> {
/// The given `rect` will be used for applying the layout including text alignment, positioning
/// of text, multi-line wrapping, etc,
pub fn build(self, rect: geom::Rect) -> Text<'a> {
// let text = self.text;
// let layout = self.layout_builder.build();
// #[allow(unreachable_code)]
// let font = layout.font.clone().unwrap_or_else(|| {
// #[cfg(feature = "notosans")]
// {
// return font::default_notosans();
// }
// let assets = nannou_core::app::find_assets_path()
// .expect("failed to detect the assets directory when searching for a default font");
// font::default(&assets).expect("failed to detect a default font")
// });
// let max_width = rect.w();
// let line_infos =
// line::infos_maybe_wrapped(&text, &font, layout.font_size, layout.line_wrap, max_width)
// .collect();
// Text {
// text,
// font,
// layout,
// line_infos,
// rect,
// }
// let text = self.text;
// let layout = self.layout_builder.build();
// #[allow(unreachable_code)]
// let font = layout.font.clone().unwrap_or_else(|| {
// #[cfg(feature = "notosans")]
// {
// return font::default_notosans();
// }
// let assets = nannou_core::app::find_assets_path()
// .expect("failed to detect the assets directory when searching for a default font");
// font::default(&assets).expect("failed to detect a default font")
// });
// let max_width = rect.w();
// let line_infos =
// line::infos_maybe_wrapped(&text, &font, layout.font_size, layout.line_wrap, max_width)
// .collect();
// Text {
// text,
// font,
// layout,
// line_infos,
// rect,
// }
todo!()
}
}
Expand Down
9 changes: 6 additions & 3 deletions bevy_nannou_wgpu/src/bind_group_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ impl BindGroupLayoutBuilder {
entries.push(layout_binding);
}

let label = Some("nannou bind group layout");
let desc = wgpu::BindGroupLayoutDescriptor { label, entries: &entries };
let label = Some("nannou bind group layout");
let desc = wgpu::BindGroupLayoutDescriptor {
label,
entries: &entries,
};
device.create_bind_group_layout(&desc)
}
}
Expand Down Expand Up @@ -177,7 +180,7 @@ impl<'a> BindGroupBuilder<'a> {
/// Type `T` *must* be either `#[repr(C)]` or `#[repr(transparent)]`.
// NOTE: We might want to change this to match the wgpu API by using a NonZeroU64 for size.
pub fn buffer<T>(self, buffer: &'a wgpu::Buffer, range: std::ops::Range<usize>) -> Self
// TODO: why was this necessary?
// TODO: why was this necessary?
// where
// T: Copy,
{
Expand Down
12 changes: 7 additions & 5 deletions bevy_nannou_wgpu/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
mod render_pipeline_builder;
mod bind_group_builder;
mod render_pass;
mod render_pipeline_builder;
mod sampler_builder;
mod texture;
mod render_pass;

pub use render_pipeline_builder::RenderPipelineBuilder;
pub use bind_group_builder::{BindGroupBuilder, BindGroupLayoutBuilder};
pub use render_pass::{
ColorAttachmentDescriptorBuilder, DepthStencilAttachmentDescriptorBuilder, RenderPassBuilder,
};
pub use render_pipeline_builder::RenderPipelineBuilder;
pub use sampler_builder::SamplerBuilder;
pub use texture::TextureBuilder;
pub use sampler_builder::{SamplerBuilder};
pub use render_pass::{RenderPassBuilder, ColorAttachmentDescriptorBuilder, DepthStencilAttachmentDescriptorBuilder};

use bevy::prelude::*;
use bevy::render::render_resource as wgpu;
Expand Down
2 changes: 1 addition & 1 deletion bevy_nannou_wgpu/src/render_pass.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use wgpu_types::Color;
use bevy::prelude::*;
use bevy::render::render_phase::TrackedRenderPass;
use bevy::render::render_resource as wgpu;
use bevy::render::renderer::RenderContext;
use wgpu_types::Color;

/// A builder type to simplify the process of creating a render pass descriptor.
#[derive(Debug, Default)]
Expand Down
3 changes: 1 addition & 2 deletions bevy_nannou_wgpu/src/render_pipeline_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//! Creating a `RenderPipeline` tends to involve a lot of boilerplate that we don't always want to
//! have to consider when writing graphics code. Here we definGe a set of helpers that allow us to
//! simplify the process and fall back to a set of reasonable defaults.
use std::borrow::Cow;
use bevy::prelude::*;
use bevy::render::render_resource as wgpu;
use std::borrow::Cow;

/// Types that may be directly converted into a pipeline layout descriptor.

Expand Down Expand Up @@ -448,7 +448,6 @@ impl<'a> RenderPipelineBuilder<'a> {
self
}


pub fn build(self) -> wgpu::RenderPipelineDescriptor {
let RenderPipelineBuilder {
layout,
Expand Down
19 changes: 9 additions & 10 deletions bevy_nannou_wgpu/src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ impl TextureBuilder {
pub const DEFAULT_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8Unorm;
pub const DEFAULT_USAGE: wgpu::TextureUsages = wgpu::TextureUsages::all(); // TODO: is this the right choice?
pub const DEFAULT_DESCRIPTOR: wgpu::TextureDescriptor<'static> = wgpu::TextureDescriptor {
label: Some("nannou Texture"),
size: Self::DEFAULT_SIZE,
mip_level_count: Self::DEFAULT_MIP_LEVEL_COUNT,
sample_count: Self::DEFAULT_SAMPLE_COUNT,
dimension: Self::DEFAULT_DIMENSION,
format: Self::DEFAULT_FORMAT,
usage: Self::DEFAULT_USAGE,
view_formats: &[],
};
label: Some("nannou Texture"),
size: Self::DEFAULT_SIZE,
mip_level_count: Self::DEFAULT_MIP_LEVEL_COUNT,
sample_count: Self::DEFAULT_SAMPLE_COUNT,
dimension: Self::DEFAULT_DIMENSION,
format: Self::DEFAULT_FORMAT,
usage: Self::DEFAULT_USAGE,
view_formats: &[],
};

/// Creates a new `Default` builder
pub fn new() -> Self {
Expand Down Expand Up @@ -154,7 +154,6 @@ impl Into<wgpu::TextureDescriptor<'static>> for TextureBuilder {
}
}


/// The size of the texture data in bytes as described by the given descriptor.
pub fn data_size_bytes(desc: &wgpu::TextureDescriptor) -> usize {
desc.size.width as usize
Expand Down

0 comments on commit ec988b9

Please sign in to comment.