-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
254 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#![cfg(not(target_family = "wasm"))] | ||
|
||
use { | ||
dunge::{ | ||
color::Rgba, | ||
draw, | ||
format::Format, | ||
sl::{self, Index, Out}, | ||
state::Render, | ||
texture, | ||
}, | ||
glam::Vec4, | ||
helpers::Image, | ||
std::{error, f32::consts, fs}, | ||
}; | ||
|
||
type Error = Box<dyn error::Error>; | ||
|
||
#[test] | ||
fn render() -> Result<(), Error> { | ||
const SIZE: (u32, u32) = (300, 300); | ||
const COLOR: Vec4 = Vec4::new(1., 0., 0., 1.); | ||
const THIRD: f32 = consts::TAU / 3.; | ||
const R_OFFSET: f32 = -consts::TAU / 4.; | ||
const Y_OFFSET: f32 = 0.25; | ||
|
||
let triangle = |Index(index): Index| { | ||
let [x, y] = sl::thunk(sl::f32(index) * THIRD + R_OFFSET); | ||
Out { | ||
place: sl::vec4(sl::cos(x), sl::sin(y) + Y_OFFSET, 0., 1.), | ||
color: COLOR, | ||
} | ||
}; | ||
|
||
let cx = helpers::block_on(dunge::context())?; | ||
let shader = cx.make_shader(triangle); | ||
let layer = cx.make_layer(Format::RgbAlpha, &shader); | ||
let view = { | ||
use texture::Data; | ||
|
||
let data = Data::empty(SIZE, Format::RgbAlpha)?.with_draw().with_copy(); | ||
cx.make_texture(data) | ||
}; | ||
|
||
let buffer = cx.make_copy_buffer(SIZE); | ||
let opts = Rgba::from_standard([0., 0., 0., 1.]); | ||
let draw = draw::from_fn(|mut frame| { | ||
frame.layer(&layer, opts).bind_empty().draw_triangles(1); | ||
frame.copy_texture(&buffer, &view); | ||
}); | ||
|
||
let mut render = Render::default(); | ||
cx.draw_to_texture(&mut render, &view, draw); | ||
|
||
let mapped = helpers::block_on({ | ||
let (tx, rx) = helpers::oneshot(); | ||
cx.map_view(buffer.view(), tx, rx) | ||
}); | ||
|
||
let data = mapped.data(); | ||
let image = Image::from_fn(SIZE, |x, y| { | ||
let (width, _) = buffer.size(); | ||
let idx = x + y * width; | ||
data[idx as usize] | ||
}); | ||
|
||
fs::write("tests/triangle_instance.png", image.encode())?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.