Skip to content

Commit

Permalink
All for submission of Frame prior to the end of view
Browse files Browse the repository at this point in the history
This allows the user to ensure that the command buffer responsible for
drawing to the swap chain texture is submitted prior to the end of their
`view` function. This is necessary to allow the user to read back
buffers and textures involved in drawing to the texture at the end of
the `view` function. Without this change, it is not possible to do so in
nannou's current API.

The most significant user-impacting change is that the `view` functions
now take the `Frame` by value, rather than by reference.
  • Loading branch information
mitchmindtree committed Feb 29, 2020
1 parent 92da8bf commit 206479e
Show file tree
Hide file tree
Showing 148 changed files with 262 additions and 218 deletions.
2 changes: 1 addition & 1 deletion examples/all_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn event(_app: &App, _model: &mut Model, event: Event) {

fn update(_app: &App, _model: &mut Model, _update: Update) {}

fn view(_app: &App, _model: &Model, frame: &Frame) {
fn view(_app: &App, _model: &Model, frame: Frame) {
frame.clear(SKYBLUE);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/basics/1_nannou_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ fn event(_app: &App, _model: &mut Model, event: WindowEvent) {
}

// Put your drawing code, called once per frame, per window.
fn view(_app: &App, _model: &Model, frame: &Frame) {
fn view(_app: &App, _model: &Model, frame: Frame) {
frame.clear(DIMGRAY);
}
2 changes: 1 addition & 1 deletion examples/basics/2_variables_window_console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ fn model(app: &App) -> Model {
Model
}

fn view(_app: &App, _model: &Model, frame: &Frame) {
fn view(_app: &App, _model: &Model, frame: Frame) {
frame.clear(DIMGRAY);
}
2 changes: 1 addition & 1 deletion examples/basics/3_variable_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ fn event(_app: &App, model: &mut Model, event: WindowEvent) {
}
}

fn view(_app: &App, _model: &Model, frame: &Frame) {
fn view(_app: &App, _model: &Model, frame: Frame) {
frame.clear(DIMGRAY);
}
2 changes: 1 addition & 1 deletion examples/basics/4_conditionals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fn main() {
nannou::sketch(view);
}

fn view(app: &App, frame: &Frame) {
fn view(app: &App, frame: Frame) {
// Prepare to draw.
let draw = app.draw();

Expand Down
2 changes: 1 addition & 1 deletion examples/basics/5_loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ fn model(_app: &App) -> Model {
Model
}

fn view(_app: &App, _model: &Model, frame: &Frame) {
fn view(_app: &App, _model: &Model, frame: Frame) {
frame.clear(DIMGRAY);
}
2 changes: 1 addition & 1 deletion examples/basics/6_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ fn event(_app: &App, _model: &mut Model, event: WindowEvent) {
}
}

fn view(_app: &App, _model: &Model, frame: &Frame) {
fn view(_app: &App, _model: &Model, frame: Frame) {
frame.clear(DIMGRAY);
}
2 changes: 1 addition & 1 deletion examples/basics/7_modules/7_modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn update(app: &App, model: &mut Model, _update: Update) {
model.ball.position = pt2(app.mouse.x, app.mouse.y);
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
// Begin drawing.
let draw = app.draw();
// Draw dark gray for the background
Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/color/p_1_0_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn main() {
nannou::sketch(view);
}

fn view(app: &App, frame: &Frame) {
fn view(app: &App, frame: Frame) {
app.main_window().set_inner_size_points(720.0, 720.0);

// Prepare to draw.
Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/color/p_1_1_1_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() {
nannou::sketch(view);
}

fn view(app: &App, frame: &Frame) {
fn view(app: &App, frame: Frame) {
app.main_window().set_inner_size_pixels(800, 400);

// Begin drawing
Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/color/p_1_1_2_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn key_pressed(_app: &App, model: &mut Model, key: Key) {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
// Begin drawing
let draw = app.draw();

Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/color/p_1_2_1_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn update(app: &App, model: &mut Model, _update: Update) {
model.tile_count_y = map_range(app.mouse.y, win.top(), win.bottom(), 2, 10) as usize;
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
// Begin drawing
let draw = app.draw();
draw.background().color(BLACK);
Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/color/p_1_2_3_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ fn key_pressed(_app: &App, model: &mut Model, key: Key) {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
// Begin drawing
let draw = app.draw();

Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/color/p_1_2_3_02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn update(app: &App, model: &mut Model, _update: Update) {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
let draw = app.draw();

if model.clicked {
Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/color/p_1_2_3_03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn update(app: &App, model: &mut Model, _update: Update) {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
// Begin drawing
let draw = app.draw();

Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/oscillation_figures/m_2_1_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn update(app: &App, model: &mut Model, _update: Update) {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
let draw = app.draw();
let win = app.window_rect();

Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/oscillation_figures/m_2_2_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn update(app: &App, model: &mut Model, _update: Update) {
model.y *= app.window_rect().h() / 4.0 - model.margin;
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
// Begin drawing
let draw = app.draw();
let win = app.window_rect();
Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/oscillation_figures/m_2_3_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn update(app: &App, model: &mut Model, _update: Update) {
model.point_count = app.window_rect().w() as usize;
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
// Begin drawing
let draw = app.draw();
let win = app.window_rect();
Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/oscillation_figures/m_2_3_02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn update(app: &App, model: &mut Model, _update: Update) {
model.point_count = mx as usize * 2 + 200;
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
// Begin drawing
let draw = app.draw();
let win = app.window_rect();
Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/oscillation_figures/m_2_5_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn update(app: &App, model: &mut Model, _update: Update) {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
let draw = app.draw();

if model.should_draw {
Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/oscillation_figures/m_2_5_02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn update(_app: &App, model: &mut Model, _update: Update) {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
let draw = app.draw();

if app.elapsed_frames() == 1 {
Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/random_and_noise/m_1_1_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn model(app: &App) -> Model {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
let draw = app.draw();
let win = app.window_rect();

Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/random_and_noise/m_1_2_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn model(app: &App) -> Model {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
let draw = app.draw();
let win = app.window_rect();

Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/random_and_noise/m_1_3_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn model(app: &App) -> Model {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
let draw = app.draw();
let win = app.window_rect();

Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/shape/p_2_0_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn main() {
nannou::sketch(view);
}

fn view(app: &App, frame: &Frame) {
fn view(app: &App, frame: Frame) {
app.main_window().set_inner_size_points(550.0, 550.0);

// Prepare to draw.
Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/shape/p_2_0_02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn model(app: &App) -> Model {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
// Prepare to draw.
let draw = app.draw();
let win = app.window_rect();
Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/shape/p_2_0_03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn model(app: &App) -> Model {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
// Prepare to draw.
let draw = app.draw();
let win = app.window_rect();
Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/shape/p_2_1_1_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn model(app: &App) -> Model {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
// Prepare to draw.
let draw = app.draw();
draw.background().color(BLACK);
Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/shape/p_2_1_1_02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn model(app: &App) -> Model {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
// Prepare to draw.
let draw = app.draw();
draw.background().color(WHITE);
Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/shape/p_2_1_1_03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn update(app: &App, model: &mut Model, _update: Update) {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
// Prepare to draw.
let draw = app.draw();
draw.background().color(WHITE);
Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/shape/p_2_1_2_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn model(app: &App) -> Model {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
let draw = app.draw();
let win = app.window_rect();

Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/shape/p_2_1_2_02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn model(app: &App) -> Model {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
let draw = app.draw();
let win = app.window_rect();

Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/shape/p_2_1_2_03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn model(app: &App) -> Model {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
let draw = app.draw();
let win = app.window_rect();

Expand Down
2 changes: 1 addition & 1 deletion examples/generative_design/shape/p_2_1_2_04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn model(app: &App) -> Model {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
let draw = app.draw();
let win = app.window_rect();

Expand Down
2 changes: 1 addition & 1 deletion examples/laser/laser_frame_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,6 @@ fn key_pressed(_app: &App, model: &mut Model, key: Key) {
.unwrap();
}

fn view(_app: &App, _model: &Model, frame: &Frame) {
fn view(_app: &App, _model: &Model, frame: Frame) {
frame.clear(DIMGRAY);
}
2 changes: 1 addition & 1 deletion examples/laser/laser_frame_stream_gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,6 @@ fn key_pressed(_app: &App, model: &mut Model, key: Key) {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
model.ui.draw_to_frame_if_changed(app, &frame).unwrap();
}
2 changes: 1 addition & 1 deletion examples/laser/laser_raw_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn mouse_moved(app: &App, model: &mut Model, pos: Point2) {
.unwrap();
}

fn view(app: &App, _model: &Model, frame: &Frame) {
fn view(app: &App, _model: &Model, frame: Frame) {
// Visualise the point in the window.
let draw = app.draw();
draw.background().color(DIMGRAY);
Expand Down
2 changes: 1 addition & 1 deletion examples/loop_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ fn key_pressed(app: &App, _model: &mut Model, _key: Key) {
app.main_window().set_title(&title);
}

fn view(_app: &App, _model: &Model, frame: &Frame) {
fn view(_app: &App, _model: &Model, frame: Frame) {
frame.clear(DIMGRAY);
}
2 changes: 1 addition & 1 deletion examples/multi_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn event_c(_app: &App, _model: &mut Model, event: WindowEvent) {
println!("window c: {:?}", event);
}

fn view(_app: &App, model: &Model, frame: &Frame) {
fn view(_app: &App, model: &Model, frame: Frame) {
match frame.window_id() {
id if id == model.a => frame.clear(INDIANRED),
id if id == model.b => frame.clear(LIGHTGREEN),
Expand Down
4 changes: 2 additions & 2 deletions examples/multi_window_draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn event_c(_app: &App, _model: &mut Model, event: WindowEvent) {
println!("window c: {:?}", event);
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
let draw = app.draw_for_window(frame.window_id()).unwrap();
match frame.window_id() {
id if id == model.a => {
Expand All @@ -63,5 +63,5 @@ fn view(app: &App, model: &Model, frame: &Frame) {
}
_ => (),
}
draw.to_frame(app, frame).unwrap();
draw.to_frame(app, &frame).unwrap();
}
2 changes: 1 addition & 1 deletion examples/named_color_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn update(app: &App, model: &mut Model, _update: Update) {
}

// Draw the state of your `Model` into the given `Frame` here.
fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
let draw = app.draw();

// Draw the background with the color.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn update(app: &App, m: &mut Model, _update: Update) {
m.mover.update(pt2(app.mouse.x, app.mouse.y));
}

fn view(app: &App, m: &Model, frame: &Frame) {
fn view(app: &App, m: &Model, frame: Frame) {
// Begin drawing
let draw = app.draw();
draw.background().color(WHITE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn update(app: &App, m: &mut Model, _update: Update) {
}
}

fn view(app: &App, m: &Model, frame: &Frame) {
fn view(app: &App, m: &Model, frame: Frame) {
// Begin drawing
let draw = app.draw();
draw.background().color(WHITE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn update(app: &App, model: &mut Model, _update: Update) {
}
}

fn view(app: &App, model: &Model, frame: &Frame) {
fn view(app: &App, model: &Model, frame: Frame) {
// Begin drawing
let draw = app.draw();
draw.background().color(WHITE);
Expand Down
Loading

0 comments on commit 206479e

Please sign in to comment.