migrated pong

pull/140/head
Ben Hansen 3 years ago
parent d56c73009b
commit c121682bd3

962
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -5,16 +5,16 @@ authors = ["Ben Hansen <bhbenjaminhansen@gmail.com>"]
edition = "2018"
[dependencies]
winit = "0.22"
winit = "0.24"
shaderc = "0.7"
anyhow = "1.0"
bytemuck = { version = "1.4", features = [ "derive" ] }
cgmath = "0.17"
cgmath = "0.18"
futures = "0.3"
wgpu = "0.7"
wgpu_glyph = "0.10"
rand = "0.7"
rodio = "0.11"
wgpu_glyph = "0.11"
rand = "0.8"
rodio = "0.13"
[build-dependencies]
anyhow = "1.0"

@ -42,9 +42,9 @@ impl ShaderData {
fn main() -> Result<()> {
// Collect all shaders recursively within /src/
let mut shader_paths = [
glob("./src/**/*.vert")?,
glob("./src/**/*.frag")?,
glob("./src/**/*.comp")?,
glob("./res/**/*.vert")?,
glob("./res/**/*.frag")?,
glob("./res/**/*.comp")?,
];
// This could be parallelized
@ -80,18 +80,5 @@ fn main() -> Result<()> {
write(shader.spv_path, compiled.as_binary_u8())?;
}
// This tells cargo to rerun this script if something in /res/ changes.
println!("cargo:rerun-if-changed=res/*");
let out_dir = env::var("OUT_DIR")?;
let mut copy_options = CopyOptions::new();
copy_options.overwrite = true;
let mut paths_to_copy = Vec::new();
paths_to_copy.push("res/");
match copy_items(&paths_to_copy, out_dir, &copy_options) {
Ok(_) => {}
Err(e) => eprintln!("{}", e),
}
Ok(())
}

@ -1,6 +1,6 @@
#version 450
layout(location=0) in vec2 vTexCoord;
// layout(location=0) in vec2 vTexCoord;
layout(location=0) out vec4 fColor;

@ -1,11 +1,11 @@
#version 450
layout(location=0) in vec2 aPosition;
layout(location=1) in vec2 aTexCoord;
// layout(location=1) in vec2 aTexCoord;
layout(location=0) out vec2 vTexCoord;
// layout(location=0) out vec2 vTexCoord;
void main() {
gl_Position = vec4(aPosition, 0, 1);
vTexCoord = aTexCoord;
// vTexCoord = aTexCoord;
}

@ -15,7 +15,7 @@ use winit::window::{Fullscreen, WindowBuilder};
fn main() {
let event_loop = EventLoop::new();
let monitor = event_loop.primary_monitor();
let monitor = event_loop.primary_monitor().unwrap();
let video_mode = monitor.video_modes().next().unwrap();
let window = WindowBuilder::new()
.with_visible(false)

@ -142,6 +142,7 @@ impl Render {
match self.swap_chain.get_current_frame() {
Ok(frame) => {
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Main Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.output.view,
resolve_target: None,
@ -153,7 +154,7 @@ impl Render {
if num_indices != 0 {
render_pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
render_pass
.set_index_buffer(self.index_buffer.slice(..), wgpu::IndexFormat::Uint16);
.set_index_buffer(self.index_buffer.slice(..), wgpu::IndexFormat::Uint32);
render_pass.set_pipeline(&self.pipeline);
render_pass.draw_indexed(0..num_indices, 0, 0..1);
}
@ -245,12 +246,18 @@ fn create_render_pipeline(
vertex: wgpu::VertexState {
module: &vs_module,
entry_point: "main",
buffers: &vertex_layouts,
},
fragment: Some(wgpu::FragmentState {
module: &fs_module,
entry_point: "main",
targets: &[wgpu::ColorTargetState {
format: color_format,
color_blend: wgpu::BlendState::REPLACE,
alpha_blend: wgpu::BlendState::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
}),
rasterization_state: None,
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
strip_index_format: None,
@ -259,19 +266,11 @@ fn create_render_pipeline(
// Setting this to anything other than Fill requires Features::NON_FILL_POLYGON_MODE
polygon_mode: wgpu::PolygonMode::Fill,
},
color_states: &[wgpu::ColorStateDescriptor {
format: color_format,
color_blend: wgpu::BlendDescriptor::REPLACE,
alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
depth_stencil: None,
sample_count: 1,
sample_mask: !0,
alpha_to_coverage_enabled: false,
vertex_state: wgpu::VertexStateDescriptor {
index_format: wgpu::IndexFormat::Uint32,
vertex_buffers: vertex_layouts,
multisample: wgpu::MultisampleState {
count: 1,
mask: !0,
alpha_to_coverage_enabled: false,
},
})
}

@ -4,22 +4,25 @@ const BOUNCE_BYTES: &[u8] = include_bytes!("../res/sounds/4362__noisecollector__
pub struct SoundSystem {
#[allow(dead_code)]
device: rodio::Device,
stream: rodio::OutputStream,
#[allow(dead_code)]
stream_handle: rodio::OutputStreamHandle,
sink: rodio::Sink,
spatial_sink: rodio::SpatialSink,
}
impl SoundSystem {
pub fn new() -> Self {
let device = rodio::default_output_device().unwrap();
let sink = rodio::Sink::new(&device);
let (stream, stream_handle) = rodio::OutputStream::try_default().unwrap();
let sink = rodio::Sink::try_new(&stream_handle).unwrap();
sink.set_volume(0.5);
let spatial_sink =
rodio::SpatialSink::new(&device, [0.0, 0.0, 0.0], [-1.0, 0.0, 0.0], [1.0, 0.0, 0.0]);
rodio::SpatialSink::try_new(&stream_handle, [0.0, 0.0, 0.0], [-1.0, 0.0, 0.0], [1.0, 0.0, 0.0]).unwrap();
Self {
device,
stream,
stream_handle,
sink,
spatial_sink,
}

Loading…
Cancel
Save