reorganize texture and mesh

This commit is contained in:
Carter Anderson 2020-03-14 12:56:37 -07:00
parent 0c3e83452d
commit 56e79d5225
22 changed files with 104 additions and 37 deletions

View file

@ -167,7 +167,7 @@ pub fn derive_uniforms(input: TokenStream) -> TokenStream {
}
}
fn get_uniform_texture(&self, name: &str) -> Option<bevy::asset::Handle<bevy::asset::Texture>> {
fn get_uniform_texture(&self, name: &str) -> Option<bevy::asset::Handle<bevy::render::texture::Texture>> {
use bevy::render::shader::GetTexture;
match name {
#(#texture_and_sampler_name_strings => self.#texture_and_sampler_name_idents.get_texture(),)*

57
examples/ui_bench.rs Normal file
View file

@ -0,0 +1,57 @@
use bevy::prelude::*;
fn main() {
AppBuilder::new()
.add_defaults()
.setup_world(setup)
.add_system(build_move_system())
.add_system(bevy::diagnostics::build_fps_printer_system())
.run();
}
fn build_move_system() -> Box<dyn Schedulable> {
SystemBuilder::new("Move")
.read_resource::<Time>()
.with_query(<Write<Node>>::query())
.build(move |_, world, time, query| {
for (i, mut node) in query.iter_mut(world).enumerate() {
if node.color.r > 0.2 {
node.position += Vec2::new(0.1 * time.delta_seconds, 0.0);
// println!("{}", node.position.x());
}
}
})
}
fn setup(world: &mut World, _resources: &mut Resources) {
let mut builder = world.build().add_entity(Camera2dEntity {
camera: Camera::new(CameraType::Orthographic {
left: 0.0,
right: 0.0,
bottom: 0.0,
top: 0.0,
near: 0.0,
far: 1.0,
}),
active_camera_2d: ActiveCamera2d,
});
let mut prev = Vec2::default();
let count = 1000;
for i in 0..count {
// 2d camera
let cur = Vec2::new(1.0, 1.0) * 1.0 + prev;
builder = builder.add_entity(UiEntity {
node: Node::new(
math::vec2(75.0, 75.0) + cur,
Anchors::new(0.5, 0.5, 0.5, 0.5),
Margins::new(0.0, 100.0, 0.0, 100.0),
Color::rgb(0.0 + i as f32 / count as f32, 0.1, 0.1),
),
});
prev = cur;
}
builder.build();
}

View file

@ -6,8 +6,8 @@ use crate::{
plugin::load_plugin,
prelude::StandardMaterial,
render::{
draw_target::draw_targets::*, pass::passes::*, pipeline::pipelines::*,
render_resource::resource_providers::*, renderer::Renderer, *,
draw_target::draw_targets::*, mesh::Mesh, pass::passes::*, pipeline::pipelines::*,
render_resource::resource_providers::*, renderer::Renderer, texture::Texture, *,
},
ui,
};
@ -186,7 +186,9 @@ impl AppBuilder {
#[cfg(feature = "wgpu")]
pub fn add_wgpu_renderer(mut self) -> Self {
self.renderer = Some(Box::new(renderer::renderers::wgpu_renderer::WgpuRenderer::new()));
self.renderer = Some(Box::new(
renderer::renderers::wgpu_renderer::WgpuRenderer::new(),
));
self
}
@ -202,8 +204,6 @@ impl AppBuilder {
.add_wgpu_renderer()
}
pub fn load_plugin(mut self, path: &str) -> Self {
let (_lib, plugin) = load_plugin(path);
self = plugin.build(self);

View file

@ -1,14 +1,10 @@
mod gltf;
mod mesh;
mod texture;
pub use self::gltf::load_gltf;
pub use mesh::*;
use std::{
fmt::Debug,
hash::{Hash, Hasher},
};
pub use texture::*;
use std::{collections::HashMap, marker::PhantomData};

View file

@ -1,7 +1,4 @@
use crate::{
asset::{Handle, Texture},
math::Vec4,
};
use crate::{asset::Handle, math::Vec4, render::texture::Texture};
use zerocopy::AsBytes;
pub trait GetBytes {

View file

@ -1,13 +1,15 @@
pub use crate::{
app::{App, AppBuilder},
asset::{Asset, AssetStorage, Handle, Mesh, MeshType, Texture, TextureType},
asset::{Asset, AssetStorage, Handle},
core::Time,
ecs,
ecs::{default_archetypes::*, EntityArchetype, WorldBuilder, WorldBuilderSource},
render::{
mesh::{Mesh, MeshType},
pipeline::PipelineDescriptor,
render_resource::{resource_name, resource_providers::UniformResourceProvider},
shader::{uniforms::StandardMaterial, Shader, ShaderDefSuffixProvider, ShaderStage},
texture::{Texture, TextureType},
ActiveCamera, ActiveCamera2d, Camera, CameraType, Color, ColorSource, Instanced, Light,
Renderable,
},

View file

@ -1,9 +1,5 @@
use crate::{
asset::{Handle, Texture},
core::GetBytes,
math::Vec4,
render::shader::ShaderDefSuffixProvider,
};
use super::texture::Texture;
use crate::{asset::Handle, core::GetBytes, math::Vec4, render::shader::ShaderDefSuffixProvider};
use std::ops::Add;
use zerocopy::AsBytes;

View file

@ -1,8 +1,9 @@
use crate::{
asset::{AssetStorage, Handle, Mesh},
asset::{AssetStorage, Handle},
legion::prelude::*,
render::{
draw_target::DrawTarget,
mesh::Mesh,
pipeline::PipelineDescriptor,
render_resource::{resource_name, ResourceInfo},
renderer::{RenderPass, Renderer},

View file

@ -1,8 +1,9 @@
use crate::{
asset::{Handle, Mesh},
asset::Handle,
legion::prelude::*,
render::{
draw_target::DrawTarget,
mesh::Mesh,
pipeline::PipelineDescriptor,
render_resource::{resource_name, ResourceInfo},
renderer::RenderPass,

View file

@ -1,8 +1,9 @@
use crate::{
asset::{AssetStorage, Handle, Mesh},
asset::{AssetStorage, Handle},
legion::prelude::*,
render::{
draw_target::DrawTarget,
mesh::Mesh,
pipeline::PipelineDescriptor,
render_resource::{resource_name, BufferUsage, RenderResource, ResourceInfo},
renderer::{RenderPass, Renderer},

View file

@ -1,4 +1,5 @@
pub mod camera;
mod camera;
pub mod mesh;
pub mod render_graph;
pub mod shader;

View file

@ -1,4 +1,7 @@
use crate::asset::{Handle, Mesh, Texture};
use crate::{
asset::Handle,
render::{mesh::Mesh, texture::Texture},
};
use std::collections::HashMap;
#[derive(Copy, Clone, Hash, Debug, Eq, PartialEq)]

View file

@ -1,9 +1,10 @@
use crate::{
asset::{AssetStorage, Handle, Mesh},
asset::{AssetStorage, Handle},
prelude::Renderable,
render::{
render_resource::{BufferUsage, ResourceProvider},
renderer::Renderer,
mesh::Mesh,
},
};
use legion::{filter::*, prelude::*};

View file

@ -1,8 +1,9 @@
use crate::{
asset::{Asset, AssetStorage, Handle, Mesh, MeshType},
asset::{Asset, AssetStorage, Handle},
ecs, math,
prelude::Node,
render::{
mesh::{Mesh, MeshType},
render_resource::{resource_name, BufferUsage, RenderResource, ResourceProvider},
renderer::Renderer,
},

View file

@ -1,11 +1,11 @@
use crate::{
asset::{AssetStorage, Texture},
asset::AssetStorage,
render::{
pipeline::BindType,
render_resource::{BufferUsage, RenderResource, ResourceProvider},
renderer::Renderer,
shader::{AsUniforms, DynamicUniformBufferInfo, UniformInfoIter},
texture::{SamplerDescriptor, TextureDescriptor},
texture::{SamplerDescriptor, Texture, TextureDescriptor},
Renderable,
},
};

View file

@ -1,7 +1,11 @@
use crate::{
asset::{Handle, Texture},
asset::Handle,
core::GetBytes,
render::{color::ColorSource, pipeline::BindType, texture::TextureViewDimension},
render::{
color::ColorSource,
pipeline::BindType,
texture::{Texture, TextureViewDimension},
},
};
use legion::prelude::Entity;
use std::collections::HashMap;

View file

@ -1,6 +1,9 @@
use crate::{
asset::{Handle, Texture},
render::shader::{AsUniforms, FieldBindType, FieldUniformName},
asset::Handle,
render::{
shader::{AsUniforms, FieldBindType, FieldUniformName},
texture::Texture,
},
};
use zerocopy::AsBytes;

View file

@ -1,7 +1,9 @@
mod texture;
mod sampler_descriptor;
mod texture_descriptor;
mod texture_dimension;
pub use texture::*;
pub use sampler_descriptor::*;
pub use texture_descriptor::*;
pub use texture_dimension::*;

View file

@ -1,4 +1,5 @@
use crate::{asset::Texture, render::pipeline::state_descriptors::CompareFunction};
use super::Texture;
use crate::render::pipeline::state_descriptors::CompareFunction;
#[derive(Copy, Clone)]
pub struct SamplerDescriptor {

View file

@ -1,5 +1,5 @@
use super::{Extent3d, TextureDimension, TextureFormat};
use crate::{asset::Texture, render::texture::TextureUsage};
use super::{Extent3d, Texture, TextureDimension, TextureFormat};
use crate::render::texture::TextureUsage;
#[derive(Copy, Clone)]
pub struct TextureDescriptor {