mirror of
https://github.com/bevyengine/bevy
synced 2025-02-16 14:08:32 +00:00
use full path in macro references
This commit is contained in:
parent
c96183cf1c
commit
6cf981c610
8 changed files with 52 additions and 53 deletions
|
@ -21,8 +21,8 @@ pub fn derive_entity_archetype(input: TokenStream) -> TokenStream {
|
||||||
let field_name = fields.iter().map(|field| &field.ident);
|
let field_name = fields.iter().map(|field| &field.ident);
|
||||||
|
|
||||||
TokenStream::from(quote! {
|
TokenStream::from(quote! {
|
||||||
impl EntityArchetype for #struct_name {
|
impl bevy::prelude::EntityArchetype for #struct_name {
|
||||||
fn insert(self, world: &mut World) -> Entity {
|
fn insert(self, world: &mut bevy::prelude::World) -> Entity {
|
||||||
*world.insert((), vec![(
|
*world.insert((), vec![(
|
||||||
#(self.#field_name,)*
|
#(self.#field_name,)*
|
||||||
)]).first().unwrap()
|
)]).first().unwrap()
|
||||||
|
@ -115,10 +115,10 @@ pub fn derive_uniforms(input: TokenStream) -> TokenStream {
|
||||||
(0..active_uniform_fields.len()).map(|i| quote!(&#info_ident[#i]));
|
(0..active_uniform_fields.len()).map(|i| quote!(&#info_ident[#i]));
|
||||||
|
|
||||||
TokenStream::from(quote! {
|
TokenStream::from(quote! {
|
||||||
const #info_ident: &[UniformInfo] = &[
|
const #info_ident: &[bevy::render::render_graph::UniformInfo] = &[
|
||||||
#(UniformInfo {
|
#(bevy::render::render_graph::UniformInfo {
|
||||||
name: #uniform_name_uniform_info,
|
name: #uniform_name_uniform_info,
|
||||||
bind_type: BindType::Uniform {
|
bind_type: bevy::render::render_graph::BindType::Uniform {
|
||||||
dynamic: false,
|
dynamic: false,
|
||||||
// TODO: fill this in with properties
|
// TODO: fill this in with properties
|
||||||
properties: Vec::new(),
|
properties: Vec::new(),
|
||||||
|
@ -126,26 +126,27 @@ pub fn derive_uniforms(input: TokenStream) -> TokenStream {
|
||||||
},)*
|
},)*
|
||||||
];
|
];
|
||||||
|
|
||||||
const #layout_ident: &[&[UniformPropertyType]] = &[
|
const #layout_ident: &[&[bevy::render::render_graph::UniformPropertyType]] = &[
|
||||||
#(#layout_arrays,)*
|
#(#layout_arrays,)*
|
||||||
];
|
];
|
||||||
|
|
||||||
impl AsUniforms for #struct_name {
|
impl bevy::render::render_graph::AsUniforms for #struct_name {
|
||||||
fn get_uniform_infos(&self) -> &[UniformInfo] {
|
fn get_uniform_infos(&self) -> &[bevy::render::render_graph::UniformInfo] {
|
||||||
#info_ident
|
#info_ident
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_uniform_layouts(&self) -> &[&[UniformPropertyType]] {
|
fn get_uniform_layouts(&self) -> &[&[bevy::render::render_graph::UniformPropertyType]] {
|
||||||
#layout_ident
|
#layout_ident
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_uniform_bytes(&self, name: &str) -> Option<Vec<u8>> {
|
fn get_uniform_bytes(&self, name: &str) -> Option<Vec<u8>> {
|
||||||
|
use bevy::core::bytes::GetBytes;
|
||||||
match name {
|
match name {
|
||||||
#(#get_uniform_bytes_uniform_name => Some(self.#get_uniform_bytes_field_name.get_bytes()),)*
|
#(#get_uniform_bytes_uniform_name => Some(self.#get_uniform_bytes_field_name.get_bytes()),)*
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn get_uniform_info(&self, name: &str) -> Option<&UniformInfo> {
|
fn get_uniform_info(&self, name: &str) -> Option<&bevy::render::render_graph::UniformInfo> {
|
||||||
match name {
|
match name {
|
||||||
#(#get_uniform_info_uniform_name => Some(#get_uniform_info_array_refs),)*
|
#(#get_uniform_info_uniform_name => Some(#get_uniform_info_array_refs),)*
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -175,7 +176,7 @@ pub fn derive_app_plugin(input: TokenStream) -> TokenStream {
|
||||||
|
|
||||||
TokenStream::from(quote! {
|
TokenStream::from(quote! {
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn _create_plugin() -> *mut AppPlugin {
|
pub extern "C" fn _create_plugin() -> *mut bevy::plugin::AppPlugin {
|
||||||
// TODO: without this the assembly does nothing. why is that the case?
|
// TODO: without this the assembly does nothing. why is that the case?
|
||||||
print!("");
|
print!("");
|
||||||
// make sure the constructor is the correct type.
|
// make sure the constructor is the correct type.
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
use bevy::{
|
use bevy::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
render::{
|
render::{
|
||||||
render_graph::{PipelineDescriptor, resource_name},
|
render_graph::{PipelineDescriptor, resource_name, resource_providers::UniformResourceProvider},
|
||||||
Shader, ShaderStage, Vertex,
|
Shader, ShaderStage, Vertex,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use bevy_derive::Uniforms;
|
use bevy_derive::Uniforms;
|
||||||
|
|
||||||
// #[derive(Uniforms)]
|
#[derive(Uniforms)]
|
||||||
struct MyMaterial {
|
struct MyMaterial {
|
||||||
pub color: Vec4
|
pub color: Vec4
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ fn main() {
|
||||||
.setup_world(setup)
|
.setup_world(setup)
|
||||||
.setup_render_graph(|builder, pipeline_storage, shader_storage| {
|
.setup_render_graph(|builder, pipeline_storage, shader_storage| {
|
||||||
builder
|
builder
|
||||||
// .add_resource_provider(UniformResourceProvider::<MyMaterial>::new())
|
.add_resource_provider(Box::new(UniformResourceProvider::<MyMaterial>::new()))
|
||||||
.add_pipeline_to_pass(
|
.add_pipeline_to_pass(
|
||||||
resource_name::pass::MAIN,
|
resource_name::pass::MAIN,
|
||||||
pipeline_storage,
|
pipeline_storage,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::plugin::AppPlugin;
|
|
||||||
use bevy_derive::RegisterAppPlugin;
|
use bevy_derive::RegisterAppPlugin;
|
||||||
|
|
||||||
#[derive(RegisterAppPlugin)]
|
#[derive(RegisterAppPlugin)]
|
||||||
|
|
29
src/core/bytes.rs
Normal file
29
src/core/bytes.rs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
use zerocopy::AsBytes;
|
||||||
|
use crate::math::Vec4;
|
||||||
|
|
||||||
|
pub trait GetBytes {
|
||||||
|
fn get_bytes(&self) -> Vec<u8>;
|
||||||
|
fn get_bytes_ref(&self) -> Option<&[u8]>;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: might need to add zerocopy to this crate to impl AsBytes for external crates
|
||||||
|
// impl<T> GetBytes for T where T : AsBytes {
|
||||||
|
// fn get_bytes(&self) -> Vec<u8> {
|
||||||
|
// self.as_bytes().into()
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fn get_bytes_ref(&self) -> Option<&[u8]> {
|
||||||
|
// Some(self.as_bytes())
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
impl GetBytes for Vec4 {
|
||||||
|
fn get_bytes(&self) -> Vec<u8> {
|
||||||
|
let vec4_array: [f32; 4] = (*self).into();
|
||||||
|
vec4_array.as_bytes().into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_bytes_ref(&self) -> Option<&[u8]> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,2 +1,5 @@
|
||||||
mod time;
|
pub mod time;
|
||||||
|
pub mod bytes;
|
||||||
|
|
||||||
pub use time::Time;
|
pub use time::Time;
|
||||||
|
pub use bytes::GetBytes;
|
||||||
|
|
|
@ -2,6 +2,8 @@ use crate::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
render::render_graph::{Renderable, StandardMaterial},
|
render::render_graph::{Renderable, StandardMaterial},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate as bevy; // for macro imports
|
||||||
use bevy_derive::EntityArchetype;
|
use bevy_derive::EntityArchetype;
|
||||||
|
|
||||||
#[derive(EntityArchetype, Default)]
|
#[derive(EntityArchetype, Default)]
|
||||||
|
|
|
@ -1,37 +1,8 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
math::Vec4,
|
|
||||||
render::render_graph::{BindType, UniformPropertyType},
|
render::render_graph::{BindType, UniformPropertyType},
|
||||||
};
|
};
|
||||||
use legion::prelude::Entity;
|
use legion::prelude::Entity;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use zerocopy::AsBytes;
|
|
||||||
|
|
||||||
pub trait GetBytes {
|
|
||||||
fn get_bytes(&self) -> Vec<u8>;
|
|
||||||
fn get_bytes_ref(&self) -> Option<&[u8]>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: might need to add zerocopy to this crate to impl AsBytes for external crates
|
|
||||||
// impl<T> GetBytes for T where T : AsBytes {
|
|
||||||
// fn get_bytes(&self) -> Vec<u8> {
|
|
||||||
// self.as_bytes().into()
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn get_bytes_ref(&self) -> Option<&[u8]> {
|
|
||||||
// Some(self.as_bytes())
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
impl GetBytes for Vec4 {
|
|
||||||
fn get_bytes(&self) -> Vec<u8> {
|
|
||||||
let vec4_array: [f32; 4] = (*self).into();
|
|
||||||
vec4_array.as_bytes().into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_bytes_ref(&self) -> Option<&[u8]> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: add ability to specify specific pipeline for uniforms
|
// TODO: add ability to specify specific pipeline for uniforms
|
||||||
pub trait AsUniforms {
|
pub trait AsUniforms {
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
use crate::{
|
use crate::{math, math::Vec4, render::render_graph::ShaderDefSuffixProvider};
|
||||||
math,
|
|
||||||
math::Vec4,
|
|
||||||
render::render_graph::{
|
|
||||||
uniform::{AsUniforms, GetBytes, UniformInfo},
|
|
||||||
BindType, ShaderDefSuffixProvider, UniformPropertyType,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
use crate as bevy; // for macro imports
|
||||||
use bevy_derive::Uniforms;
|
use bevy_derive::Uniforms;
|
||||||
|
|
||||||
#[derive(Uniforms)]
|
#[derive(Uniforms)]
|
||||||
|
|
Loading…
Add table
Reference in a new issue