Skip to content

Commit

Permalink
0.15-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tychedelia committed Sep 6, 2024
1 parent 829acb2 commit 33d727a
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 88 deletions.
2 changes: 1 addition & 1 deletion bevy_nannou_isf/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl AssetLoader for IsfLoader {

async fn load<'a>(
&'a self,
reader: &'a mut Reader<'_>,
reader: &'a mut dyn Reader,
settings: &'a Self::Settings,
load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
Expand Down
181 changes: 100 additions & 81 deletions bevy_nannou_isf/src/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,59 +205,59 @@ impl GetTypeRegistration for IsfInputs {
}

impl Struct for IsfInputs {
fn field(&self, name: &str) -> Option<&dyn Reflect> {
fn field(&self, name: &str) -> Option<&dyn PartialReflect> {
self.get(name).map(|v| match v {
IsfInputValue::Event(b) => b as &dyn Reflect,
IsfInputValue::Bool(b) => b as &dyn Reflect,
IsfInputValue::Long(l) => l as &dyn Reflect,
IsfInputValue::Float(f) => f as &dyn Reflect,
IsfInputValue::Point2d(v) => v as &dyn Reflect,
IsfInputValue::Color(c) => c as &dyn Reflect,
IsfInputValue::Image(h) => h as &dyn Reflect,
IsfInputValue::Audio(a) => a as &dyn Reflect,
IsfInputValue::AudioFft(a) => a as &dyn Reflect,
IsfInputValue::Event(b) => b as &dyn PartialReflect,
IsfInputValue::Bool(b) => b as &dyn PartialReflect,
IsfInputValue::Long(l) => l as &dyn PartialReflect,
IsfInputValue::Float(f) => f as &dyn PartialReflect,
IsfInputValue::Point2d(v) => v as &dyn PartialReflect,
IsfInputValue::Color(c) => c as &dyn PartialReflect,
IsfInputValue::Image(h) => h as &dyn PartialReflect,
IsfInputValue::Audio(a) => a as &dyn PartialReflect,
IsfInputValue::AudioFft(a) => a as &dyn PartialReflect,
})
}

fn field_mut(&mut self, name: &str) -> Option<&mut dyn Reflect> {
fn field_mut(&mut self, name: &str) -> Option<&mut dyn PartialReflect> {
self.get_mut(name).map(|v| match v {
IsfInputValue::Event(b) => b as &mut dyn Reflect,
IsfInputValue::Bool(b) => b as &mut dyn Reflect,
IsfInputValue::Long(l) => l as &mut dyn Reflect,
IsfInputValue::Float(f) => f as &mut dyn Reflect,
IsfInputValue::Point2d(v) => v as &mut dyn Reflect,
IsfInputValue::Color(c) => c as &mut dyn Reflect,
IsfInputValue::Image(h) => h as &mut dyn Reflect,
IsfInputValue::Audio(a) => a as &mut dyn Reflect,
IsfInputValue::AudioFft(a) => a as &mut dyn Reflect,
IsfInputValue::Event(b) => b as &mut dyn PartialReflect,
IsfInputValue::Bool(b) => b as &mut dyn PartialReflect,
IsfInputValue::Long(l) => l as &mut dyn PartialReflect,
IsfInputValue::Float(f) => f as &mut dyn PartialReflect,
IsfInputValue::Point2d(v) => v as &mut dyn PartialReflect,
IsfInputValue::Color(c) => c as &mut dyn PartialReflect,
IsfInputValue::Image(h) => h as &mut dyn PartialReflect,
IsfInputValue::Audio(a) => a as &mut dyn PartialReflect,
IsfInputValue::AudioFft(a) => a as &mut dyn PartialReflect,
})
}

fn field_at(&self, index: usize) -> Option<&dyn Reflect> {
fn field_at(&self, index: usize) -> Option<&dyn PartialReflect> {
self.values().nth(index).map(|v| match v {
IsfInputValue::Event(b) => b as &dyn Reflect,
IsfInputValue::Bool(b) => b as &dyn Reflect,
IsfInputValue::Long(l) => l as &dyn Reflect,
IsfInputValue::Float(f) => f as &dyn Reflect,
IsfInputValue::Point2d(v) => v as &dyn Reflect,
IsfInputValue::Color(c) => c as &dyn Reflect,
IsfInputValue::Image(h) => h as &dyn Reflect,
IsfInputValue::Audio(a) => a as &dyn Reflect,
IsfInputValue::AudioFft(a) => a as &dyn Reflect,
IsfInputValue::Event(b) => b as &dyn PartialReflect,
IsfInputValue::Bool(b) => b as &dyn PartialReflect,
IsfInputValue::Long(l) => l as &dyn PartialReflect,
IsfInputValue::Float(f) => f as &dyn PartialReflect,
IsfInputValue::Point2d(v) => v as &dyn PartialReflect,
IsfInputValue::Color(c) => c as &dyn PartialReflect,
IsfInputValue::Image(h) => h as &dyn PartialReflect,
IsfInputValue::Audio(a) => a as &dyn PartialReflect,
IsfInputValue::AudioFft(a) => a as &dyn PartialReflect,
})
}

fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn Reflect> {
fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect> {
self.values_mut().nth(index).map(|v| match v {
IsfInputValue::Event(b) => b as &mut dyn Reflect,
IsfInputValue::Bool(b) => b as &mut dyn Reflect,
IsfInputValue::Long(l) => l as &mut dyn Reflect,
IsfInputValue::Float(f) => f as &mut dyn Reflect,
IsfInputValue::Point2d(v) => v as &mut dyn Reflect,
IsfInputValue::Color(c) => c as &mut dyn Reflect,
IsfInputValue::Image(h) => h as &mut dyn Reflect,
IsfInputValue::Audio(a) => a as &mut dyn Reflect,
IsfInputValue::AudioFft(a) => a as &mut dyn Reflect,
IsfInputValue::Event(b) => b as &mut dyn PartialReflect,
IsfInputValue::Bool(b) => b as &mut dyn PartialReflect,
IsfInputValue::Long(l) => l as &mut dyn PartialReflect,
IsfInputValue::Float(f) => f as &mut dyn PartialReflect,
IsfInputValue::Point2d(v) => v as &mut dyn PartialReflect,
IsfInputValue::Color(c) => c as &mut dyn PartialReflect,
IsfInputValue::Image(h) => h as &mut dyn PartialReflect,
IsfInputValue::Audio(a) => a as &mut dyn PartialReflect,
IsfInputValue::AudioFft(a) => a as &mut dyn PartialReflect,
})
}

Expand All @@ -282,43 +282,13 @@ impl Struct for IsfInputs {
}
}

impl Reflect for IsfInputs {
impl PartialReflect for IsfInputs {
#[inline]
fn get_represented_type_info(&self) -> Option<&'static TypeInfo> {
Some(Self::type_info())
}

#[inline]
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}

#[inline]
fn as_any(&self) -> &dyn Any {
self
}

#[inline]
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}

#[inline]
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect> {
self
}

#[inline]
fn as_reflect(&self) -> &dyn Reflect {
self
}

#[inline]
fn as_reflect_mut(&mut self) -> &mut dyn Reflect {
self
}

fn try_apply(&mut self, value: &dyn Reflect) -> Result<(), ApplyError> {
fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> {
if let ReflectRef::Struct(struct_value) = value.reflect_ref() {
for (i, value) in struct_value.iter_fields().enumerate() {
let name = struct_value.name_at(i).unwrap();
Expand All @@ -335,12 +305,6 @@ impl Reflect for IsfInputs {
Ok(())
}

#[inline]
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
*self = value.take()?;
Ok(())
}

#[inline]
fn reflect_kind(&self) -> ReflectKind {
ReflectKind::Struct
Expand All @@ -362,11 +326,11 @@ impl Reflect for IsfInputs {
}

#[inline]
fn clone_value(&self) -> Box<dyn Reflect> {
fn clone_value(&self) -> Box<dyn PartialReflect> {
Box::new(self.clone_dynamic())
}

fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool> {
fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option<bool> {
struct_partial_eq(self, value)
}

Expand All @@ -385,10 +349,65 @@ impl Reflect for IsfInputs {
fn is_dynamic(&self) -> bool {
true
}

fn into_partial_reflect(self: Box<Self>) -> Box<dyn PartialReflect> {
self
}

fn as_partial_reflect(&self) -> &dyn PartialReflect {
self
}

fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect {
self
}

fn try_into_reflect(self: Box<Self>) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>> {
Ok(self)
}

fn try_as_reflect(&self) -> Option<&dyn Reflect> {
Some(self)
}

fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> {
Some(self)
}
}

impl Reflect for IsfInputs {
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}

fn as_any(&self) -> &dyn Any {
self
}

fn as_any_mut(&mut self) -> &mut dyn Any {
self
}

fn into_reflect(self: Box<Self>) -> Box<dyn Reflect> {
self
}

fn as_reflect(&self) -> &dyn Reflect {
self
}

fn as_reflect_mut(&mut self) -> &mut dyn Reflect {
self
}

fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
*self = value.take()?;
Ok(())
}
}

#[inline]
pub fn struct_partial_eq(a: &IsfInputs, b: &dyn Reflect) -> Option<bool> {
pub fn struct_partial_eq(a: &IsfInputs, b: &dyn PartialReflect) -> Option<bool> {
let ReflectRef::Struct(struct_value) = b.reflect_ref() else {
return Some(false);
};
Expand Down
5 changes: 2 additions & 3 deletions bevy_nannou_isf/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,12 @@ fn queue_isf(
pipeline_cache: Res<PipelineCache>,
mut isf_pipeline: ResMut<IsfPipeline>,
isf_assets: Res<RenderAssets<GpuIsf>>,
msaa: Res<Msaa>,
isf_inputs: Res<IsfInputs>,
isf_render_targets: Res<IsfRenderTargets>,
mut specialized_render_pipelines: ResMut<SpecializedRenderPipelines<IsfPipeline>>,
views: Query<(Entity, &ExtractedView, &Handle<Isf>)>,
views: Query<(Entity, &ExtractedView, &Handle<Isf>, &Msaa)>,
) {
for (view_entity, extracted_view, isf) in views.iter() {
for (view_entity, extracted_view, isf, msaa) in views.iter() {
let isf = isf_assets.get(isf).unwrap();

// Prepare any new layouts
Expand Down
2 changes: 1 addition & 1 deletion bevy_nannou_video/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl AssetLoader for VideoLoader {

async fn load<'a>(
&'a self,
_reader: &'a mut Reader<'_>,
_reader: &'a mut dyn Reader,
settings: &'a Self::Settings,
load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
Expand Down
36 changes: 35 additions & 1 deletion nannou/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use bevy::reflect::{
ApplyError, DynamicTypePath, GetTypeRegistration, ReflectMut, ReflectOwned, ReflectRef,
TypeInfo,
};
use bevy::render::extract_resource::ExtractResource;
use bevy::render::render_graph::ViewNodeRunner;
use bevy::window::{
ExitCondition, Monitor, PrimaryMonitor, PrimaryWindow, WindowClosed, WindowEvent,
WindowFocused, WindowResized,
Expand Down Expand Up @@ -448,7 +450,7 @@ where
#[cfg(feature = "egui")]
pub fn model_ui(mut self) -> Self {
self.app
.add_plugins((ResourceInspectorPlugin::<ModelHolder<M>>::default(),));
.add_plugins(ResourceInspectorPlugin::<ModelHolder<M>>::default());
self
}
}
Expand Down Expand Up @@ -581,6 +583,38 @@ where
}
}

impl<M> Reflect for ModelHolder<M>
where
M: Reflect + DynamicTypePath + Any + GetTypeRegistration + 'static, {
fn into_any(self: Box<Self>) -> Box<dyn Any> {
Box::new(self.0).into_any()
}

fn as_any(&self) -> &dyn Any {
self.0.as_any()
}

fn as_any_mut(&mut self) -> &mut dyn Any {
self.0.as_any_mut()
}

fn into_reflect(self: Box<Self>) -> Box<dyn Reflect> {
Box::new(self.0).into_reflect()
}

fn as_reflect(&self) -> &dyn Reflect {
self.0.as_reflect()
}

fn as_reflect_mut(&mut self) -> &mut dyn Reflect {
self.0.as_reflect_mut()
}

fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
self.0.set(value)
}
}

impl<'w> App<'w> {
pub const DEFAULT_EXIT_ON_ESCAPE: bool = true;
pub const DEFAULT_FULLSCREEN_ON_SHORTCUT: bool = true;
Expand Down
16 changes: 15 additions & 1 deletion nannou/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use std::path::{Path, PathBuf};
use bevy::input::mouse::MouseWheel;
use bevy::prelude::*;
use bevy::render::camera::RenderTarget;
use bevy::render::extract_component::ExtractComponent;
use bevy::render::renderer::{RenderDevice, RenderQueue};
use bevy::render::view::cursor::CursorIcon;
use bevy::render::view::screenshot::{save_to_disk, Screenshot};
use bevy::render::view::RenderLayers;
Expand Down Expand Up @@ -942,7 +944,19 @@ impl<'a, 'w> Window<'a, 'w> {
}

pub fn msaa_samples(&self) -> u32 {
self.app.resource_world().resource::<Msaa>().samples()
let mut msaa_q = self
.app
.component_world_mut()
.query_filtered::<(&Camera, &Msaa), With<NannouCamera>>();
for (camera, msaa) in msaa_q.iter(&*self.app.component_world()) {
if let RenderTarget::Window(WindowRef::Entity(entity)) = camera.target {
if entity == self.entity {
return msaa.samples();
}
}
}

panic!("No camera found for window");
}
}

Expand Down
2 changes: 2 additions & 0 deletions nannou_wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub use wgpu::{
PUSH_CONSTANT_ALIGNMENT, QUERY_RESOLVE_BUFFER_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE,
VERTEX_STRIDE_ALIGNMENT,
};
use wgpu::MemoryHints;

/// The default power preference used for requesting the WGPU adapter.
pub const DEFAULT_POWER_PREFERENCE: PowerPreference = PowerPreference::HighPerformance;
Expand Down Expand Up @@ -131,6 +132,7 @@ pub fn default_device_descriptor() -> DeviceDescriptor<'static> {
label: Some("nannou_device"),
required_features,
required_limits,
memory_hints: MemoryHints::default(),
}
}

Expand Down
1 change: 1 addition & 0 deletions nannou_wgpu/src/render_pipeline_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ fn build(
multisample,
fragment,
multiview: None,
cache: None,
};

device.create_render_pipeline(&pipeline_desc)
Expand Down

0 comments on commit 33d727a

Please sign in to comment.