Merge branch 'master' into color_types
This commit is contained in:
commit
a7567b8c0f
|
@ -41,6 +41,10 @@ harness = false
|
|||
name = "loading"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "primitives"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "triangles"
|
||||
harness = false
|
||||
|
|
157
ggdt/benches/primitives.rs
Normal file
157
ggdt/benches/primitives.rs
Normal file
|
@ -0,0 +1,157 @@
|
|||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
|
||||
use ggdt::prelude::*;
|
||||
|
||||
pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
let width = 320;
|
||||
let height = 240;
|
||||
|
||||
let mut dest = RgbaBitmap::new(width, height).unwrap();
|
||||
|
||||
// note that none of these are all-inclusive benchmarks that cover all kinds of different scenarios and such
|
||||
// where the rendering logic might change based on the actual arguments given (e.g. i am not benchmarking
|
||||
// anything which does clipping as of yet).
|
||||
// maybe i will eventually add that kind of detailed benchmarking, but this for now is to just get a very,
|
||||
// very, VERY, basic idea about general performance ... moreso so that i can easily compare before/after
|
||||
// as i change other things in the future
|
||||
|
||||
c.bench_function("rgbabitmap_primitives_set_pixel", |b| {
|
||||
dest.clear(0xff000000);
|
||||
b.iter(|| dest.set_pixel(black_box(100), black_box(100), black_box(0xffff00ff)))
|
||||
});
|
||||
|
||||
c.bench_function("rgbabitmap_primitives_set_blended_pixel", |b| {
|
||||
dest.clear(0xff000000);
|
||||
b.iter(|| {
|
||||
dest.set_blended_pixel(
|
||||
black_box(100),
|
||||
black_box(100),
|
||||
black_box(0x7fff00ff),
|
||||
black_box(BlendFunction::Blend),
|
||||
)
|
||||
})
|
||||
});
|
||||
|
||||
c.bench_function("rgbabitmap_primitives_set_pixel_unchecked", |b| {
|
||||
dest.clear(0xff000000);
|
||||
b.iter(|| unsafe { dest.set_pixel_unchecked(black_box(100), black_box(100), black_box(0xffff00ff)) })
|
||||
});
|
||||
|
||||
c.bench_function("rgbabitmap_primitives_set_blended_pixel_unchecked", |b| {
|
||||
dest.clear(0xff000000);
|
||||
b.iter(|| unsafe {
|
||||
dest.set_blended_pixel_unchecked(
|
||||
black_box(100),
|
||||
black_box(100),
|
||||
black_box(0x7fff00ff),
|
||||
black_box(BlendFunction::Blend),
|
||||
)
|
||||
})
|
||||
});
|
||||
|
||||
c.bench_function("rgbabitmap_primitives_line", |b| {
|
||||
dest.clear(0xff000000);
|
||||
b.iter(|| dest.line(black_box(10), black_box(50), black_box(310), black_box(120), black_box(0xffff00ff)))
|
||||
});
|
||||
|
||||
c.bench_function("rgbabitmap_primitives_blended_line", |b| {
|
||||
dest.clear(0xff000000);
|
||||
b.iter(|| {
|
||||
dest.blended_line(
|
||||
black_box(10),
|
||||
black_box(50),
|
||||
black_box(310),
|
||||
black_box(120),
|
||||
black_box(0x7fff00ff),
|
||||
black_box(BlendFunction::Blend),
|
||||
)
|
||||
})
|
||||
});
|
||||
|
||||
c.bench_function("rgbabitmap_primitives_horiz_line", |b| {
|
||||
dest.clear(0xff000000);
|
||||
b.iter(|| dest.horiz_line(black_box(10), black_box(310), black_box(70), black_box(0xffff00ff)))
|
||||
});
|
||||
|
||||
c.bench_function("rgbabitmap_primitives_blended_horiz_line", |b| {
|
||||
dest.clear(0xff000000);
|
||||
b.iter(|| {
|
||||
dest.blended_horiz_line(
|
||||
black_box(10),
|
||||
black_box(310),
|
||||
black_box(70),
|
||||
black_box(0x7fff00ff),
|
||||
black_box(BlendFunction::Blend),
|
||||
)
|
||||
})
|
||||
});
|
||||
|
||||
c.bench_function("rgbabitmap_primitives_vert_line", |b| {
|
||||
dest.clear(0xff000000);
|
||||
b.iter(|| dest.vert_line(black_box(90), black_box(10), black_box(230), black_box(0xffff00ff)))
|
||||
});
|
||||
|
||||
c.bench_function("rgbabitmap_primitives_blended_vert_line", |b| {
|
||||
dest.clear(0xff000000);
|
||||
b.iter(|| {
|
||||
dest.blended_vert_line(
|
||||
black_box(90),
|
||||
black_box(10),
|
||||
black_box(230),
|
||||
black_box(0x7fff00ff),
|
||||
black_box(BlendFunction::Blend),
|
||||
)
|
||||
})
|
||||
});
|
||||
|
||||
c.bench_function("rgbabitmap_primitives_rect", |b| {
|
||||
dest.clear(0xff000000);
|
||||
b.iter(|| dest.rect(black_box(10), black_box(10), black_box(310), black_box(230), black_box(0xffff00ff)))
|
||||
});
|
||||
|
||||
c.bench_function("rgbabitmap_primitives_blended_rect", |b| {
|
||||
dest.clear(0xff000000);
|
||||
b.iter(|| {
|
||||
dest.blended_rect(
|
||||
black_box(10),
|
||||
black_box(10),
|
||||
black_box(310),
|
||||
black_box(230),
|
||||
black_box(0x7fff00ff),
|
||||
black_box(BlendFunction::Blend),
|
||||
)
|
||||
})
|
||||
});
|
||||
|
||||
c.bench_function("rgbabitmap_primitives_filled_rect", |b| {
|
||||
dest.clear(0xff000000);
|
||||
b.iter(|| dest.filled_rect(black_box(10), black_box(10), black_box(310), black_box(230), black_box(0xffff00ff)))
|
||||
});
|
||||
|
||||
c.bench_function("rgbabitmap_primitives_blended_filled_rect", |b| {
|
||||
dest.clear(0xff000000);
|
||||
b.iter(|| {
|
||||
dest.blended_filled_rect(
|
||||
black_box(10),
|
||||
black_box(10),
|
||||
black_box(310),
|
||||
black_box(230),
|
||||
black_box(0x7fff00ff),
|
||||
black_box(BlendFunction::Blend),
|
||||
)
|
||||
})
|
||||
});
|
||||
|
||||
c.bench_function("rgbabitmap_primitives_circle", |b| {
|
||||
dest.clear(0xff000000);
|
||||
b.iter(|| dest.circle(black_box(160), black_box(120), black_box(80), black_box(0xffff00ff)))
|
||||
});
|
||||
|
||||
c.bench_function("rgbabitmap_primitives_filled_circle", |b| {
|
||||
dest.clear(0xff000000);
|
||||
b.iter(|| dest.filled_circle(black_box(160), black_box(120), black_box(80), black_box(0xffff00ff)))
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
|
@ -40,6 +40,7 @@ impl IndexedBitmap {
|
|||
|
||||
/// Draws a line from x1,y1 to x2,y2 by blending the drawn pixels using the given blend map,
|
||||
/// or the color specified if the blend map does not include this color.
|
||||
#[inline]
|
||||
pub fn blended_line(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: u8, blend_map: &BlendMap) {
|
||||
if let Some(blend_mapping) = blend_map.get_mapping(color) {
|
||||
self.line_custom(
|
||||
|
@ -56,6 +57,7 @@ impl IndexedBitmap {
|
|||
|
||||
/// Draws a horizontal line from x1,y to x2,y by blending the drawn pixels using the given
|
||||
/// blend map, or the color specified if the blend map does not include this color.
|
||||
#[inline]
|
||||
pub fn blended_horiz_line(&mut self, x1: i32, x2: i32, y: i32, color: u8, blend_map: &BlendMap) {
|
||||
if let Some(blend_mapping) = blend_map.get_mapping(color) {
|
||||
self.horiz_line_custom(
|
||||
|
@ -71,6 +73,7 @@ impl IndexedBitmap {
|
|||
|
||||
/// Draws a vertical line from x,y1 to x,y2 by blending the drawn pixels using the given blend
|
||||
/// map, or the color specified if the blend map does not include this color.
|
||||
#[inline]
|
||||
pub fn blended_vert_line(&mut self, x: i32, y1: i32, y2: i32, color: u8, blend_map: &BlendMap) {
|
||||
if let Some(blend_mapping) = blend_map.get_mapping(color) {
|
||||
self.vert_line_custom(
|
||||
|
@ -88,6 +91,7 @@ impl IndexedBitmap {
|
|||
/// drawn, assuming they are specifying the top-left and bottom-right corners respectively.
|
||||
/// The box is drawn by blending the drawn pixels using the given blend map, or the color
|
||||
/// specified if the blend map does not include this color.
|
||||
#[inline]
|
||||
pub fn blended_rect(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: u8, blend_map: &BlendMap) {
|
||||
if let Some(blend_mapping) = blend_map.get_mapping(color) {
|
||||
self.rect_custom(
|
||||
|
@ -106,6 +110,7 @@ impl IndexedBitmap {
|
|||
/// drawn, assuming they are specifying the top-left and bottom-right corners respectively. The
|
||||
/// filled box is draw by blending the drawn pixels using the given blend map, or the color
|
||||
/// specified if the blend map does not include this color.
|
||||
#[inline]
|
||||
pub fn blended_filled_rect(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: u8, blend_map: &BlendMap) {
|
||||
if let Some(blend_mapping) = blend_map.get_mapping(color) {
|
||||
self.filled_rect_custom(
|
||||
|
|
|
@ -25,6 +25,7 @@ impl RgbaBitmap {
|
|||
}
|
||||
|
||||
/// Draws a line from x1,y1 to x2,y2 by blending the drawn pixels using the given blend function.
|
||||
#[inline]
|
||||
pub fn blended_line(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: u32, blend: BlendFunction) {
|
||||
self.line_custom(
|
||||
x1, //
|
||||
|
@ -37,6 +38,7 @@ impl RgbaBitmap {
|
|||
|
||||
/// Draws a horizontal line from x1,y to x2,y by blending the drawn pixels using the given
|
||||
/// blend function.
|
||||
#[inline]
|
||||
pub fn blended_horiz_line(&mut self, x1: i32, x2: i32, y: i32, color: u32, blend: BlendFunction) {
|
||||
self.horiz_line_custom(
|
||||
x1, //
|
||||
|
@ -48,6 +50,7 @@ impl RgbaBitmap {
|
|||
|
||||
/// Draws a vertical line from x,y1 to x,y2 by blending the drawn pixels using the given blend
|
||||
/// function.
|
||||
#[inline]
|
||||
pub fn blended_vert_line(&mut self, x: i32, y1: i32, y2: i32, color: u32, blend: BlendFunction) {
|
||||
self.vert_line_custom(
|
||||
x, //
|
||||
|
@ -60,6 +63,7 @@ impl RgbaBitmap {
|
|||
/// Draws an empty box (rectangle) using the points x1,y1 and x2,y2 to form the box to be
|
||||
/// drawn, assuming they are specifying the top-left and bottom-right corners respectively.
|
||||
/// The box is drawn by blending the drawn pixels using the given blend function.
|
||||
#[inline]
|
||||
pub fn blended_rect(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: u32, blend: BlendFunction) {
|
||||
self.rect_custom(
|
||||
x1, //
|
||||
|
@ -73,6 +77,7 @@ impl RgbaBitmap {
|
|||
/// Draws a filled box (rectangle) using the points x1,y1 and x2,y2 to form the box to be
|
||||
/// drawn, assuming they are specifying the top-left and bottom-right corners respectively. The
|
||||
/// filled box is draw by blending the drawn pixels using the given blend function.
|
||||
#[inline]
|
||||
pub fn blended_filled_rect(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: u32, blend: BlendFunction) {
|
||||
self.filled_rect_custom(
|
||||
x1, //
|
||||
|
|
Loading…
Reference in a new issue