Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove position argument from Batch::draw #53

Merged
merged 2 commits into from
Jun 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
variants can be found. [#29]
- `input::KeyCode` has been moved to `input::keyboard::KeyCode`. [#29]
- `input::MouseButton` has been moved to `input::mouse::Button`. [#29]
- `Batch::draw` and `texture_array::Batch::draw` do not take a `position`
argument anymore. Using `Target::transform` before drawing is preferred. [#53]
- The performance of the particles example has been improved considerably on all
platforms. [#37]

Expand All @@ -86,6 +88,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#35]: https://github.com/hecrj/coffee/pull/35
[#37]: https://github.com/hecrj/coffee/pull/37
[#50]: https://github.com/hecrj/coffee/pull/50
[#53]: https://github.com/hecrj/coffee/pull/53
[Elm]: https://elm-lang.org
[The Elm Architecture]: https://guide.elm-lang.org/architecture/
[`stretch`]: https://github.com/vislyhq/stretch
Expand Down
3 changes: 1 addition & 2 deletions examples/particles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ impl Game for Particles {
self.batch.par_extend(sprites);

// Draw particles all at once!
self.batch
.draw(Point::new(0.0, 0.0), &mut frame.as_target());
self.batch.draw(&mut frame.as_target());
}
}

Expand Down
12 changes: 4 additions & 8 deletions src/graphics/batch.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rayon::prelude::*;

use crate::graphics::gpu;
use crate::graphics::{Image, IntoQuad, Point, Target, Transformation, Vector};
use crate::graphics::{Image, IntoQuad, Target};

/// A collection of quads that will be drawn all at once using the same
/// [`Image`].
Expand Down Expand Up @@ -42,15 +42,11 @@ impl Batch {
self.instances.push(instance);
}

/// Draw the [`Batch`] at the given position.
/// Draw the [`Batch`].
///
/// [`Batch`]: struct.Batch.html
pub fn draw(&self, position: Point, target: &mut Target<'_>) {
let mut translated = target.transform(Transformation::translate(
Vector::new(position.x, position.y),
));

translated.draw_texture_quads(&self.image.texture, &self.instances[..]);
pub fn draw(&self, target: &mut Target<'_>) {
target.draw_texture_quads(&self.image.texture, &self.instances[..]);
}

/// Clear the [`Batch`] contents.
Expand Down
12 changes: 4 additions & 8 deletions src/graphics/texture_array/batch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Index, TextureArray};
use crate::graphics::{gpu, IntoQuad, Point, Target, Transformation, Vector};
use crate::graphics::{gpu, IntoQuad, Target};

/// A collection of quads that can be drawn with a [`TextureArray`] all at once.
///
Expand Down Expand Up @@ -42,15 +42,11 @@ impl Batch {
self.instances.push(instance);
}

/// Draw the [`Batch`] at the given position.
/// Draw the [`Batch`].
///
/// [`Batch`]: struct.Batch.html
pub fn draw(&self, position: Point, target: &mut Target<'_>) {
let mut translated = target.transform(Transformation::translate(
Vector::new(position.x, position.y),
));

translated.draw_texture_quads(
pub fn draw(&self, target: &mut Target<'_>) {
target.draw_texture_quads(
&self.texture_array.texture,
&self.instances[..],
);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod radio;
mod slider;
mod text;

use crate::graphics::{Batch, Color, Font, Frame, Image, Mesh, Point, Shape};
use crate::graphics::{Batch, Color, Font, Frame, Image, Mesh, Shape};
use crate::load::{Join, Task};
use crate::ui::core;

Expand Down Expand Up @@ -58,7 +58,7 @@ impl core::Renderer for Renderer {
fn flush(&mut self, frame: &mut Frame<'_>) {
let target = &mut frame.as_target();

self.sprites.draw(Point::new(0.0, 0.0), target);
self.sprites.draw(target);
self.sprites.clear();

self.font.borrow_mut().draw(target);
Expand Down