Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
tychedelia committed Jan 26, 2024
1 parent 6806d12 commit 9ec050f
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 169 deletions.
22 changes: 0 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions bevy_nannou_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ bevy_nannou_wgpu = { path = "../bevy_nannou_wgpu" }
nannou_core = { path = "../nannou_core" }
nannou_mesh = { path = "../nannou_mesh" }
rusttype = { version = "0.8", features = ["gpu_cache"] }
lyon = "0.17"
bevy_mod_debugdump = "0.9.0"
lyon = "0.17"
72 changes: 48 additions & 24 deletions bevy_nannou_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@ use bevy::asset::load_internal_asset;
use bevy::core_pipeline::core_3d;
use bevy::core_pipeline::core_3d::CORE_3D;
use bevy::prelude::*;
use bevy::render::{Extract, render_resource as wgpu, RenderSet};
use bevy::render::{Render, RenderApp};
use bevy::render::extract_component::ExtractComponentPlugin;
use bevy::render::render_asset::RenderAsset;
use bevy::render::render_graph::{RenderGraphApp, ViewNode, ViewNodeRunner};
use bevy::render::render_phase::{
AddRenderCommand, PhaseItem, RenderCommand,
};
use bevy::render::render_phase::{AddRenderCommand, PhaseItem, RenderCommand};
use bevy::render::render_resource::{
ShaderType, SpecializedRenderPipeline,
SpecializedRenderPipelines,
ShaderType, SpecializedRenderPipeline, SpecializedRenderPipelines,
};
use bevy::render::renderer::RenderDevice;
use bevy::render::view::ViewUniforms;
use bevy::render::{render_resource as wgpu, RenderSet};
use bevy::render::{Render, RenderApp};

use mesh::ViewMesh;
use pipeline::queue_pipelines;
Expand All @@ -25,7 +22,6 @@ use crate::pipeline::{NannouPipeline, NannouViewNode};
pub mod mesh;
mod pipeline;
mod text;
// mod reshaper;

pub struct NannouRenderPlugin;

Expand All @@ -41,36 +37,33 @@ impl Plugin for NannouRenderPlugin {
);

app
// TODO: We should extract Draw and compute the mesh from the Draw component
// in the render world
.add_plugins(ExtractComponentPlugin::<ViewMesh>::default());


println!("NannouRenderPlugin::build");
app.get_sub_app_mut(RenderApp)
.unwrap()
.init_resource::<SpecializedRenderPipelines<NannouPipeline>>()
.add_systems(
Render,
prepare_view_uniform.in_set(RenderSet::PrepareBindGroups),
)
.add_systems(
Render,
queue_pipelines
.in_set(RenderSet::PrepareAssets)
)
.add_systems(Render, queue_pipelines.in_set(RenderSet::PrepareAssets))

// 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>>(
core_3d::graph::NAME,
NannouViewNode::NAME,
)
.add_render_graph_edges(
CORE_3D,
&[
core_3d::graph::node::MAIN_TRANSPARENT_PASS,
NannouViewNode::NAME,
core_3d::graph::node::END_MAIN_PASS,
],
);

bevy_mod_debugdump::print_render_graph(app);
CORE_3D,
&[
core_3d::graph::node::MAIN_TRANSPARENT_PASS,
NannouViewNode::NAME,
core_3d::graph::node::END_MAIN_PASS,
],
);
}

fn finish(&self, app: &mut App) {
Expand All @@ -82,6 +75,7 @@ impl Plugin for NannouRenderPlugin {
}
}

// Prepare our uniform bind group from Bevy's view uniforms
fn prepare_view_uniform(
mut commands: Commands,
render_device: Res<RenderDevice>,
Expand All @@ -96,6 +90,8 @@ fn prepare_view_uniform(
));
}
}

// Resource wrapper for our view uniform bind group
#[derive(Resource)]
struct ViewUniformBindGroup {
bind_group: wgpu::BindGroup,
Expand Down Expand Up @@ -128,3 +124,31 @@ pub enum VertexMode {
/// Uses the color values, but multiplies the alpha by the glyph cache texture's red value.
Text = 2,
}

pub struct GlyphCache {
/// Tracks glyphs and their location within the cache.
pub cache: text::GlyphCache<'static>,
/// The buffer used to store the pixels of the glyphs.
pub pixel_buffer: Vec<u8>,
/// Will be set to `true` after the cache has been updated if the texture requires re-uploading.
pub requires_upload: bool,
}

impl GlyphCache {
fn new(size: [u32; 2], scale_tolerance: f32, position_tolerance: f32) -> Self {
let [w, h] = size;
let cache = text::GlyphCache::builder()
.dimensions(w, h)
.scale_tolerance(scale_tolerance)
.position_tolerance(position_tolerance)
.build()
.into();
let pixel_buffer = vec![0u8; w as usize * h as usize];
let requires_upload = false;
GlyphCache {
cache,
pixel_buffer,
requires_upload,
}
}
}
Loading

0 comments on commit 9ec050f

Please sign in to comment.