Skip to content

Commit

Permalink
- swap chain implementation initially working on macos/metal
Browse files Browse the repository at this point in the history
  • Loading branch information
polymonster committed Jun 5, 2024
1 parent 1e30c09 commit bbc2185
Show file tree
Hide file tree
Showing 12 changed files with 1,065 additions and 511 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ metal = "0.28.0"
winit = "0.29"
objc = "0.2.4"
cocoa = "0.25.0"
core-graphics-types = "0.1.3"

[lib]
crate-type = ["rlib", "dylib"]
Expand Down
8 changes: 5 additions & 3 deletions client/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// currently windows only because here we need a concrete gfx and os implementation
#![cfg(target_os = "windows")]
// #![cfg(target_os = "windows")]

use hotline_rs::*;
use hotline_rs::client::*;
//use hotline_rs::*;
//use hotline_rs::client::*;

fn main() -> Result<(), hotline_rs::Error> {

/*
// create client
let ctx : Client<gfx_platform::Device, os_platform::App> = Client::create(HotlineInfo {
..Default::default()
Expand All @@ -15,6 +16,7 @@ fn main() -> Result<(), hotline_rs::Error> {
if let Err(e) = ctx.run() {
println!("error: {}", e.msg);
};
*/

Ok(())
}
12 changes: 6 additions & 6 deletions examples/resource_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ fn main() -> Result<(), hotline_rs::Error> {
// create resources that are defined in resource_tests.pmfx
pmfx.create_texture(&mut dev, "bear_frame")?;
pmfx.create_texture(&mut dev, "copy_dest")?;

pmfx.create_texture(&mut dev, "compressed_bc1")?;
pmfx.create_texture(&mut dev, "compressed_bc5")?;
pmfx.create_texture(&mut dev, "compressed_bc3")?;

let fmt = swap_chain.get_backbuffer_pass().get_format_hash();
let pso_pmfx = pmfx.get_render_pipeline_for_format("bindful", fmt)?;

Expand All @@ -141,7 +141,7 @@ fn main() -> Result<(), hotline_rs::Error> {
let viewport = gfx::Viewport::from(vp_rect);
let scissor = gfx::ScissorRect::from(vp_rect);

// copy texture region
// copy texture region
cmdbuffer.transition_barrier(&gfx::TransitionBarrier {
texture: Some(textures[1]),
buffer: None,
Expand All @@ -161,8 +161,8 @@ fn main() -> Result<(), hotline_rs::Error> {
0, 0, 0, 0,
textures[0],
Some(gfx::Region{
left: 380,
top: 380,
left: 380,
top: 380,
front: 0,
right: 380 + 512,
bottom: 380 + 512,
Expand Down Expand Up @@ -227,7 +227,7 @@ fn main() -> Result<(), hotline_rs::Error> {
if let Some(t3) = pso_pmfx.get_pipeline_slot(3, 0, gfx::DescriptorType::ShaderResource) {
cmdbuffer.set_binding(pso_pmfx, &pmfx.shader_heap, t3.index, srv3);
}

cmdbuffer.set_index_buffer(&index_buffer);
cmdbuffer.set_vertex_buffer(&vertex_buffer, 0);
cmdbuffer.draw_indexed_instanced(6, 1, 0, 0, 0);
Expand Down
34 changes: 31 additions & 3 deletions examples/gfx_device/main.rs → examples/swap_chain/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use hotline_rs::gfx::SwapChain;
use hotline_rs::*;

use os::App;
Expand All @@ -21,7 +22,7 @@ fn main() -> Result<(), hotline_rs::Error> {
// create an app
println!("create app!");
let mut app = os_platform::App::create(os::AppInfo {
name: String::from("gfx_device"),
name: String::from("swap_chain"),
window: false,
num_buffers: 0,
dpi_aware: true,
Expand All @@ -30,7 +31,7 @@ fn main() -> Result<(), hotline_rs::Error> {
// create a window
println!("create window!");
let mut window = app.create_window(os::WindowInfo {
title: String::from("gfx_device!"),
title: String::from("swap_chain!"),
..Default::default()
});

Expand All @@ -42,10 +43,37 @@ fn main() -> Result<(), hotline_rs::Error> {
..Default::default()
});

// create a swap chain
println!("create swap chain!");
let swap_chain_info = gfx::SwapChainInfo {
num_buffers,
format: gfx::Format::RGBA8n,
clear_colour: Some(gfx::ClearColour {
r: 0.45,
g: 0.55,
b: 0.60,
a: 1.00,
}),
};

let mut swap_chain = device.create_swap_chain::<os_platform::App>(&swap_chain_info, &window)?;
let mut cmd = device.create_cmd_buf(num_buffers);

let mut counter = 0;
while app.run() {
println!("main loop!");
// update the swap chain
swap_chain.update::<os_platform::App>(&mut device, &window, &mut cmd);

// update window and swap chain
window.update(&mut app);

println!("swap {}", counter);
swap_chain.swap(&device);

// sleep?
println!("sleep");
std::thread::sleep(std::time::Duration::from_millis(16));
counter += 1;
}

Ok(())
Expand Down
3 changes: 0 additions & 3 deletions examples/window/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ use os::Window;
#[cfg(target_os = "windows")]
use os::win32 as os_platform;

#[cfg(target_os = "windows")]
use gfx::d3d12 as gfx_platform;

#[cfg(target_os = "macos")]
use os::macos as os_platform;

Expand Down
Loading

0 comments on commit bbc2185

Please sign in to comment.