setup render textures
This commit is contained in:
1103
Cargo.lock
generated
1103
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -4,4 +4,5 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.16.1"
|
||||
bevy = {version = "0.16.1", features = ["bevy_image"]}
|
||||
bevy-inspector-egui = "0.31.0"
|
||||
|
||||
0
assets/trace.wgsl
Normal file
0
assets/trace.wgsl
Normal file
69
src/app.rs
Normal file
69
src/app.rs
Normal file
@@ -0,0 +1,69 @@
|
||||
use bevy::{
|
||||
asset::RenderAssetUsages,
|
||||
prelude::*,
|
||||
render::{
|
||||
RenderApp,
|
||||
render_resource::{Extent3d, TextureDimension, TextureFormat, TextureUsages},
|
||||
},
|
||||
window::PrimaryWindow,
|
||||
};
|
||||
pub struct Blackhole;
|
||||
|
||||
impl Plugin for Blackhole {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.register_type::<RenderTextures>();
|
||||
|
||||
app.add_systems(Startup, setup);
|
||||
|
||||
let render_app = app.sub_app_mut(RenderApp);
|
||||
|
||||
render_app.add_systems(Startup, init_pipeline);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource, Reflect)]
|
||||
#[reflect(Resource)]
|
||||
struct RenderTextures(pub Handle<Image>, pub Handle<Image>);
|
||||
|
||||
fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>, window: Single<&Window, With<PrimaryWindow>>) {
|
||||
let size = window.physical_size();
|
||||
|
||||
let extent = Extent3d {
|
||||
width: size.x,
|
||||
height: size.y,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
const PIXEL_FORMAT: TextureFormat = TextureFormat::Rgba32Float;
|
||||
const PIXEL_SIZE: usize = 16;
|
||||
let mut image = Image::new_fill(
|
||||
extent,
|
||||
TextureDimension::D2,
|
||||
&[0; PIXEL_SIZE],
|
||||
PIXEL_FORMAT,
|
||||
RenderAssetUsages::RENDER_WORLD,
|
||||
);
|
||||
image.texture_descriptor.usage = TextureUsages::TEXTURE_BINDING
|
||||
| TextureUsages::STORAGE_BINDING
|
||||
| TextureUsages::COPY_DST
|
||||
| TextureUsages::RENDER_ATTACHMENT;
|
||||
|
||||
let img0 = images.add(image.clone());
|
||||
let img1 = images.add(image);
|
||||
|
||||
commands.spawn((
|
||||
Name::new("Render Sprite"),
|
||||
Sprite {
|
||||
image: img0.clone(),
|
||||
custom_size: Some(size.as_vec2()),
|
||||
..default()
|
||||
},
|
||||
Transform::from_translation(Vec3::ZERO),
|
||||
));
|
||||
|
||||
commands.spawn(Camera2d);
|
||||
|
||||
commands.insert_resource(RenderTextures(img0, img1));
|
||||
}
|
||||
|
||||
fn init_pipeline(mut commands: Commands) {}
|
||||
35
src/main.rs
35
src/main.rs
@@ -1,3 +1,36 @@
|
||||
use app::Blackhole;
|
||||
use bevy::prelude::*;
|
||||
use bevy::{prelude::*, window::PresentMode};
|
||||
use bevy_inspector_egui::{bevy_egui::EguiPlugin, quick::WorldInspectorPlugin};
|
||||
|
||||
mod app;
|
||||
|
||||
const NAME: &str = "Black Hole";
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
App::new()
|
||||
.add_plugins((
|
||||
DefaultPlugins
|
||||
.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
title: NAME.into(),
|
||||
name: Some(NAME.into()),
|
||||
resolution: (1920., 1080.).into(),
|
||||
present_mode: PresentMode::AutoNoVsync,
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
})
|
||||
.set(AssetPlugin {
|
||||
#[cfg(not(debug_assertions))]
|
||||
watch_for_changes_override: Some(true),
|
||||
..Default::default()
|
||||
}),
|
||||
EguiPlugin {
|
||||
enable_multipass_for_primary_context: true,
|
||||
},
|
||||
WorldInspectorPlugin::new(),
|
||||
Blackhole,
|
||||
))
|
||||
.run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user